diff options
author | Vincent Guittot <vincent.guittot@linaro.org> | 2024-02-09 12:09:40 +0100 |
---|---|---|
committer | Vincent Guittot <vincent.guittot@linaro.org> | 2024-02-15 15:52:21 +0100 |
commit | 7407e7d47678a4fb210f05865a05a1a213930772 (patch) | |
tree | 4b09dbf730bed6da6e86eb7745ce5038fa517160 | |
parent | 067fecf1806fbd2c073cbfbc23d447a56fe445f9 (diff) |
spm/scmi: Fix shared memory attribute
Align SCMI server in SP with
afffe3a45076 ("fix(spm): instruction permissions on memory sharing")
Fix NS bit setting when mapping the memory
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
-rw-r--r-- | spm/scmi/cactus_main.c | 7 | ||||
-rw-r--r-- | spm/scmi/include/ffa_helpers.h | 19 | ||||
-rw-r--r-- | spm/scmi/include/spm_common.h | 2 | ||||
-rw-r--r-- | spm/scmi/spm_common.c | 9 |
4 files changed, 31 insertions, 6 deletions
diff --git a/spm/scmi/cactus_main.c b/spm/scmi/cactus_main.c index 0aee799..3a519fd 100644 --- a/spm/scmi/cactus_main.c +++ b/spm/scmi/cactus_main.c @@ -114,9 +114,8 @@ static void *scmi_memory_retrieve(ffa_id_t source, ffa_id_t vm_id, uint64_t hand unsigned int mem_attrs; void *ptr; ffa_memory_region_flags_t retrv_flags = 0; - bool non_secure = true; - if (!memory_retrieve(mb, &m, handle, source, vm_id, retrv_flags)){ + if (!memory_retrieve(mb, &m, handle, source, vm_id, retrv_flags, FFA_MEM_SHARE_SMC32)){ ERROR("Failed to received memory region!\n"); return 0; } @@ -133,7 +132,9 @@ static void *scmi_memory_retrieve(ffa_id_t source, ffa_id_t vm_id, uint64_t hand mem_attrs = MT_RW_DATA | MT_EXECUTE_NEVER; - if (non_secure) { + if (ffa_get_memory_security_attr(m->attributes) == + FFA_MEMORY_SECURITY_NON_SECURE) { + VERBOSE("Mem security attr non secure\n"); mem_attrs |= MT_NS; } diff --git a/spm/scmi/include/ffa_helpers.h b/spm/scmi/include/ffa_helpers.h index a7cdcb5..149969e 100644 --- a/spm/scmi/include/ffa_helpers.h +++ b/spm/scmi/include/ffa_helpers.h @@ -403,6 +403,17 @@ enum ffa_memory_shareability { typedef uint8_t ffa_memory_access_permissions_t; /** + * FF-A v1.1 REL0 Table 10.18 memory region attributes descriptor NS Bit 6. + * Per section 10.10.4.1, NS bit is reserved for FFA_MEM_DONATE/LEND/SHARE + * and FFA_MEM_RETRIEVE_REQUEST. + */ +enum ffa_memory_security { + FFA_MEMORY_SECURITY_UNSPECIFIED = 0, + FFA_MEMORY_SECURITY_SECURE = 0, + FFA_MEMORY_SECURITY_NON_SECURE, +}; + +/** * This corresponds to table 10.18 of the FF-A v1.1 EAC0 specification, "Memory * region attributes descriptor". */ @@ -417,6 +428,9 @@ typedef uint16_t ffa_memory_attributes_t; #define FFA_MEMORY_TYPE_OFFSET (0x4U) #define FFA_MEMORY_TYPE_MASK ((0x3U) << FFA_MEMORY_TYPE_OFFSET) +#define FFA_MEMORY_SECURITY_OFFSET (0x6U) +#define FFA_MEMORY_SECURITY_MASK ((0x1U) << FFA_MEMORY_SECURITY_OFFSET) + #define FFA_MEMORY_CACHEABILITY_OFFSET (0x2U) #define FFA_MEMORY_CACHEABILITY_MASK ((0x3U) << FFA_MEMORY_CACHEABILITY_OFFSET) @@ -452,6 +466,11 @@ ATTR_FUNCTION_SET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, ATTR_FUNCTION_GET(memory_type, ffa_memory_attributes_t, FFA_MEMORY_TYPE_OFFSET, FFA_MEMORY_TYPE_MASK) +ATTR_FUNCTION_SET(memory_security, ffa_memory_attributes_t, + FFA_MEMORY_SECURITY_OFFSET, FFA_MEMORY_SECURITY_MASK) +ATTR_FUNCTION_GET(memory_security, ffa_memory_attributes_t, + FFA_MEMORY_SECURITY_OFFSET, FFA_MEMORY_SECURITY_MASK) + ATTR_FUNCTION_SET(memory_cacheability, ffa_memory_attributes_t, FFA_MEMORY_CACHEABILITY_OFFSET, FFA_MEMORY_CACHEABILITY_MASK) ATTR_FUNCTION_GET(memory_cacheability, ffa_memory_attributes_t, diff --git a/spm/scmi/include/spm_common.h b/spm/scmi/include/spm_common.h index 3549518..7fcf7a3 100644 --- a/spm/scmi/include/spm_common.h +++ b/spm/scmi/include/spm_common.h @@ -119,7 +119,7 @@ unsigned int get_ffa_feature_test_target(const struct ffa_features_test **test_t bool memory_retrieve(struct mailbox_buffers *mb, struct ffa_memory_region **retrieved, uint64_t handle, ffa_id_t sender, ffa_id_t receiver, - ffa_memory_region_flags_t flags); + ffa_memory_region_flags_t flags, uint32_t mem_func); /** * Helper to conduct a memory relinquish. The caller is usually the receiver, diff --git a/spm/scmi/spm_common.c b/spm/scmi/spm_common.c index 35951e3..8077cb2 100644 --- a/spm/scmi/spm_common.c +++ b/spm/scmi/spm_common.c @@ -15,12 +15,17 @@ bool memory_retrieve(struct mailbox_buffers *mb, struct ffa_memory_region **retrieved, uint64_t handle, ffa_id_t sender, ffa_id_t receiver, - ffa_memory_region_flags_t flags) + ffa_memory_region_flags_t flags, + uint32_t mem_func) { struct ffa_value ret; uint32_t fragment_size; uint32_t total_size; uint32_t descriptor_size; + const enum ffa_instruction_access inst_access = + (mem_func == FFA_MEM_SHARE_SMC32) + ? FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED + : FFA_INSTRUCTION_ACCESS_NX; if (retrieved == NULL || mb == NULL) { ERROR("Invalid parameters!\n"); @@ -30,7 +35,7 @@ bool memory_retrieve(struct mailbox_buffers *mb, descriptor_size = ffa_memory_retrieve_request_init( mb->send, handle, sender, receiver, 0, flags, FFA_DATA_ACCESS_RW, - FFA_INSTRUCTION_ACCESS_NX, + inst_access, FFA_MEMORY_NORMAL_MEM, FFA_MEMORY_CACHE_WRITE_BACK, FFA_MEMORY_INNER_SHAREABLE); |