From 941ebdfe30cf0dffb74acea4ca4c1996ed363038 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 24 Mar 2020 13:44:39 -0700 Subject: [PATCH 1/3] soc: qcom: mem-buf: Do not assume VMID values The mem-buf code currently assumes that the VMID values for the VMs are known up-front, which may not be the case when VMIDs are allocated dynamically. Thus, remove all such assumptions, and query the resource manager driver for VMID values. Also, rename the MEM_BUF_VMID_HLOS identifier to MEM_BUF_VMID_PRIMARY_VM so as to not tie HLOS to the role of primary VM. Change-Id: I4cd79e31d7bda6d1437e690ac0e63b15a69565ef Signed-off-by: Isaac J. Manjarres --- drivers/soc/qcom/mem-buf.c | 20 +++++++++++++++----- include/uapi/linux/mem-buf.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/soc/qcom/mem-buf.c b/drivers/soc/qcom/mem-buf.c index 78e0cfaf21d2..2a9a7a4fc898 100644 --- a/drivers/soc/qcom/mem-buf.c +++ b/drivers/soc/qcom/mem-buf.c @@ -1078,7 +1078,7 @@ static int mem_buf_remove_mem(struct mem_buf_desc *membuf) static bool is_valid_mem_buf_vmid(u32 mem_buf_vmid) { - if ((mem_buf_vmid == MEM_BUF_VMID_HLOS) || + if ((mem_buf_vmid == MEM_BUF_VMID_PRIMARY_VM) || (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_UI)) return true; @@ -1092,11 +1092,21 @@ static bool is_valid_mem_buf_perms(u32 mem_buf_perms) static int mem_buf_vmid_to_vmid(u32 mem_buf_vmid) { - if (mem_buf_vmid == MEM_BUF_VMID_HLOS) - return VMID_HLOS; + int ret; + hh_vmid_t vmid; + enum hh_vm_names vm_name; + + if (mem_buf_vmid == MEM_BUF_VMID_PRIMARY_VM) + vm_name = HH_PRIMARY_VM; else if (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_UI) - return VMID_TRUSTED_UI; - return -EINVAL; + vm_name = HH_TRUSTED_VM; + else + return -EINVAL; + + ret = hh_rm_get_vmid(vm_name, &vmid); + if (!ret) + return vmid; + return ret; } static int mem_buf_perms_to_perms(u32 mem_buf_perms) diff --git a/include/uapi/linux/mem-buf.h b/include/uapi/linux/mem-buf.h index d6ae79982982..20a906acc015 100644 --- a/include/uapi/linux/mem-buf.h +++ b/include/uapi/linux/mem-buf.h @@ -21,7 +21,7 @@ enum mem_buf_mem_type { }; /* The mem-buf values that represent VMIDs for an ACL. */ -#define MEM_BUF_VMID_HLOS 0 +#define MEM_BUF_VMID_PRIMARY_VM 0 #define MEM_BUF_VMID_TRUSTED_UI 1 #define MEM_BUF_PERM_FLAG_READ (1U << 0) From 61f3d669867e89bfcfd76cb9d07ec45e411670da Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 24 Mar 2020 12:47:09 -0700 Subject: [PATCH 2/3] soc: qcom: secure_buffer: Remove support for VMID_TRUSTED_UI The VMID for the trusted VM is not known up-front. Thus, there is no point in exposing VMID_TRUSTED_UI, so remove it. Callers of hyp assign must use the resource manager APIs to deduce the VMID, and pass it to the hyp assign call. Change-Id: I93e2812abffd99bb5b42b7fccead91becc5015fd Signed-off-by: Isaac J. Manjarres --- drivers/soc/qcom/secure_buffer.c | 2 -- include/soc/qcom/secure_buffer.h | 1 - 2 files changed, 3 deletions(-) diff --git a/drivers/soc/qcom/secure_buffer.c b/drivers/soc/qcom/secure_buffer.c index 62f0f2beefbe..e19919583c4d 100644 --- a/drivers/soc/qcom/secure_buffer.c +++ b/drivers/soc/qcom/secure_buffer.c @@ -280,8 +280,6 @@ const char *msm_secure_vmid_to_string(int secure_vmid) return "VMID_CP_SPSS_SP_SHARED"; case VMID_CP_SPSS_HLOS_SHARED: return "VMID_CP_SPSS_HLOS_SHARED"; - case VMID_TRUSTED_UI: - return "VMID_TRUSTED_UI"; case VMID_INVAL: return "VMID_INVAL"; default: diff --git a/include/soc/qcom/secure_buffer.h b/include/soc/qcom/secure_buffer.h index a063a8edc18a..c69a97783a3e 100644 --- a/include/soc/qcom/secure_buffer.h +++ b/include/soc/qcom/secure_buffer.h @@ -33,7 +33,6 @@ enum vmid { VMID_CP_SPSS_SP_SHARED = 0x22, VMID_CP_SPSS_HLOS_SHARED = 0x24, VMID_CP_CDSP = 0x2A, - VMID_TRUSTED_UI = 0x31, VMID_LAST, VMID_INVAL = -1 }; From 5a2d1abc8b76fc37b23a38636e37c9cab37223c6 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 24 Mar 2020 13:49:49 -0700 Subject: [PATCH 3/3] mem-buf: Replace *_TRUSTED_UI with *_TRUSTED_VM Trusted UI is simply a use-case that runs within the trusted VM. The VM can have multiple usecases, and as such, tying a usecase name to the VMID identifiers for the VM is not appropriate. Synchronize with the rest of the kernel, which refers to the trusted VM as TRUSTED_VM. Change-Id: Ia54c3d4f36e8022f639164084a612b35e445209f Signed-off-by: Isaac J. Manjarres --- drivers/soc/qcom/mem-buf.c | 4 ++-- drivers/staging/android/ion/heaps/ion_secure_util.c | 4 ++-- include/uapi/linux/mem-buf.h | 2 +- include/uapi/linux/msm_ion.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/soc/qcom/mem-buf.c b/drivers/soc/qcom/mem-buf.c index 2a9a7a4fc898..7555fa45bb07 100644 --- a/drivers/soc/qcom/mem-buf.c +++ b/drivers/soc/qcom/mem-buf.c @@ -1079,7 +1079,7 @@ static int mem_buf_remove_mem(struct mem_buf_desc *membuf) static bool is_valid_mem_buf_vmid(u32 mem_buf_vmid) { if ((mem_buf_vmid == MEM_BUF_VMID_PRIMARY_VM) || - (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_UI)) + (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_VM)) return true; return false; @@ -1098,7 +1098,7 @@ static int mem_buf_vmid_to_vmid(u32 mem_buf_vmid) if (mem_buf_vmid == MEM_BUF_VMID_PRIMARY_VM) vm_name = HH_PRIMARY_VM; - else if (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_UI) + else if (mem_buf_vmid == MEM_BUF_VMID_TRUSTED_VM) vm_name = HH_TRUSTED_VM; else return -EINVAL; diff --git a/drivers/staging/android/ion/heaps/ion_secure_util.c b/drivers/staging/android/ion/heaps/ion_secure_util.c index 0ddd7edd9d6d..7f871cd768ad 100644 --- a/drivers/staging/android/ion/heaps/ion_secure_util.c +++ b/drivers/staging/android/ion/heaps/ion_secure_util.c @@ -60,7 +60,7 @@ int get_secure_vmid(unsigned long flags) return VMID_CP_SPSS_HLOS_SHARED; if (flags & ION_FLAG_CP_CDSP) return VMID_CP_CDSP; - if (flags & ION_FLAG_CP_TRUSTED_UI) { + if (flags & ION_FLAG_CP_TRUSTED_VM) { ret = hh_rm_get_vmid(HH_TRUSTED_VM, &vmid); if (!ret) return vmid; @@ -103,7 +103,7 @@ int get_ion_flags(u32 vmid) ret = hh_rm_get_vmid(HH_TRUSTED_VM, &trusted_vm_vmid); if (!ret && vmid == trusted_vm_vmid) - return ION_FLAG_CP_TRUSTED_UI; + return ION_FLAG_CP_TRUSTED_VM; return -EINVAL; } EXPORT_SYMBOL(get_ion_flags); diff --git a/include/uapi/linux/mem-buf.h b/include/uapi/linux/mem-buf.h index 20a906acc015..1567e2144018 100644 --- a/include/uapi/linux/mem-buf.h +++ b/include/uapi/linux/mem-buf.h @@ -22,7 +22,7 @@ enum mem_buf_mem_type { /* The mem-buf values that represent VMIDs for an ACL. */ #define MEM_BUF_VMID_PRIMARY_VM 0 -#define MEM_BUF_VMID_TRUSTED_UI 1 +#define MEM_BUF_VMID_TRUSTED_VM 1 #define MEM_BUF_PERM_FLAG_READ (1U << 0) #define MEM_BUF_PERM_FLAG_WRITE (1U << 1) diff --git a/include/uapi/linux/msm_ion.h b/include/uapi/linux/msm_ion.h index 44ed10a462a0..4ec2c1d6eeda 100644 --- a/include/uapi/linux/msm_ion.h +++ b/include/uapi/linux/msm_ion.h @@ -27,7 +27,7 @@ enum msm_ion_heap_types { * Flags to be used when allocating from the secure heap for * content protection */ -#define ION_FLAG_CP_TRUSTED_UI ION_BIT(15) +#define ION_FLAG_CP_TRUSTED_VM ION_BIT(15) /* ION_FLAG_POOL_FORCE_ALLOC uses ION_BIT(16) */ #define ION_FLAG_CP_TOUCH ION_BIT(17) #define ION_FLAG_CP_BITSTREAM ION_BIT(18)