From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com> To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org> Cc: "tee-dev@lists.linaro.org" <tee-dev@lists.linaro.org>, Julien Grall <julien.grall@arm.com>, Stefano Stabellini <sstabellini@kernel.org>, Volodymyr Babchuk <Volodymyr_Babchuk@epam.com> Subject: [PATCH v5 04/10] xen/arm: optee: add fast calls handling Date: Tue, 21 May 2019 21:25:56 +0000 [thread overview] Message-ID: <20190521212530.12706-5-volodymyr_babchuk@epam.com> (raw) In-Reply-To: <20190521212530.12706-1-volodymyr_babchuk@epam.com> This patch adds handling for the fast SMCs. As name suggests, those calls can't be preempted and are used for auxiliary tasks such as information retrieval. Most handlers are quite trivial, with exception for capabilities information. Capabilities exchange should be filtered out, so only caps known to mediator are used. Also mediator disables static SHM memory capability, because it can't share OP-TEE memory with a domain. Only domain can share memory with OP-TEE, so it ensures that OP-TEE supports dynamic SHM. Basically, static SHM is a reserved memory region which is always mapped into OP-TEE address space. It belongs to OP-TEE. Normally, NW is allowed to access there, so it can communicate with OP-TEE. On other hand, dynamic SHM is NW's own memory, which it can share with OP-TEE. OP-TEE maps this memory dynamically, when it wants to access it. Because mediator can't share one static SHM region with all guests, it just disables it for all of them. It is possible to make exception for Dom0, but it requires separate handling for buffers allocated from that region. Thus, it is not implemented yet. Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com> --- All the patches to optee.c should be merged together. They were split to ease up review. But they depend heavily on each other. Changes from v4: - Handler does not use forward_call(). Instead it calls OP-TEE directly with arm_smccc_smc(). - Handler modifies only those guest registers that are should be touched according to OP-TEE protocol specification. - Added OPTEE_MEDIATOR_SMC_COUNT definition. Changes from v2: - Defined known capabilities explicitly - Fixed code style --- xen/arch/arm/tee/optee.c | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c index e9b69bd2d2..6c51caa41a 100644 --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -32,9 +32,17 @@ #include <asm/tee/optee_msg.h> #include <asm/tee/optee_smc.h> +/* Number of SMCs known to the mediator */ +#define OPTEE_MEDIATOR_SMC_COUNT 11 + /* Client ID 0 is reserved for the hypervisor itself */ #define OPTEE_CLIENT_ID(domain) ((domain)->domain_id + 1) +#define OPTEE_KNOWN_NSEC_CAPS OPTEE_SMC_NSEC_CAP_UNIPROCESSOR +#define OPTEE_KNOWN_SEC_CAPS (OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM | \ + OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM | \ + OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) + /* Domain context */ struct optee_domain { }; @@ -120,22 +128,111 @@ static int optee_relinquish_resources(struct domain *d) return 0; } +static void handle_exchange_capabilities(struct cpu_user_regs *regs) +{ + struct arm_smccc_res resp; + uint32_t caps; + + /* Filter out unknown guest caps */ + caps = get_user_reg(regs, 1); + caps &= OPTEE_KNOWN_NSEC_CAPS; + + arm_smccc_smc(OPTEE_SMC_EXCHANGE_CAPABILITIES, caps, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + if ( resp.a0 != OPTEE_SMC_RETURN_OK ) { + set_user_reg(regs, 0, resp.a0); + return; + } + + caps = resp.a1; + + /* Filter out unknown OP-TEE caps */ + caps &= OPTEE_KNOWN_SEC_CAPS; + + /* Drop static SHM_RPC cap */ + caps &= ~OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM; + + /* Don't allow guests to work without dynamic SHM */ + if ( !(caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) ) + { + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + return; + } + + set_user_reg(regs, 0, OPTEE_SMC_RETURN_OK); + set_user_reg(regs, 1, caps); +} + static bool optee_handle_call(struct cpu_user_regs *regs) { + struct arm_smccc_res resp; + if ( !current->domain->arch.tee ) return false; switch ( get_user_reg(regs, 0) ) { case OPTEE_SMC_CALLS_COUNT: + set_user_reg(regs, 0, OPTEE_MEDIATOR_SMC_COUNT); + return true; + case OPTEE_SMC_CALLS_UID: + arm_smccc_smc(OPTEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + set_user_reg(regs, 3, resp.a3); + return true; + case OPTEE_SMC_CALLS_REVISION: + arm_smccc_smc(OPTEE_SMC_CALLS_REVISION, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + return true; + case OPTEE_SMC_CALL_GET_OS_UUID: + arm_smccc_smc(OPTEE_SMC_CALL_GET_OS_UUID, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain),&resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + set_user_reg(regs, 3, resp.a3); + return true; + case OPTEE_SMC_CALL_GET_OS_REVISION: + arm_smccc_smc(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + return true; + case OPTEE_SMC_ENABLE_SHM_CACHE: + arm_smccc_smc(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + return true; + case OPTEE_SMC_DISABLE_SHM_CACHE: + arm_smccc_smc(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + if ( resp.a0 == OPTEE_SMC_RETURN_OK ) { + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + } + return true; + case OPTEE_SMC_GET_SHM_CONFIG: + /* No static SHM available for guests */ + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + return true; + case OPTEE_SMC_EXCHANGE_CAPABILITIES: + handle_exchange_capabilities(regs); + return true; + case OPTEE_SMC_CALL_WITH_ARG: case OPTEE_SMC_CALL_RETURN_FROM_RPC: set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); -- 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
WARNING: multiple messages have this Message-ID (diff)
From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com> To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org> Cc: "tee-dev@lists.linaro.org" <tee-dev@lists.linaro.org>, Julien Grall <julien.grall@arm.com>, Stefano Stabellini <sstabellini@kernel.org>, Volodymyr Babchuk <Volodymyr_Babchuk@epam.com> Subject: [Xen-devel] [PATCH v5 04/10] xen/arm: optee: add fast calls handling Date: Tue, 21 May 2019 21:25:56 +0000 [thread overview] Message-ID: <20190521212530.12706-5-volodymyr_babchuk@epam.com> (raw) Message-ID: <20190521212556.47tA1CENeBKgLNo8uP4N41TRSnSxd58H67y2VwhciRw@z> (raw) In-Reply-To: <20190521212530.12706-1-volodymyr_babchuk@epam.com> This patch adds handling for the fast SMCs. As name suggests, those calls can't be preempted and are used for auxiliary tasks such as information retrieval. Most handlers are quite trivial, with exception for capabilities information. Capabilities exchange should be filtered out, so only caps known to mediator are used. Also mediator disables static SHM memory capability, because it can't share OP-TEE memory with a domain. Only domain can share memory with OP-TEE, so it ensures that OP-TEE supports dynamic SHM. Basically, static SHM is a reserved memory region which is always mapped into OP-TEE address space. It belongs to OP-TEE. Normally, NW is allowed to access there, so it can communicate with OP-TEE. On other hand, dynamic SHM is NW's own memory, which it can share with OP-TEE. OP-TEE maps this memory dynamically, when it wants to access it. Because mediator can't share one static SHM region with all guests, it just disables it for all of them. It is possible to make exception for Dom0, but it requires separate handling for buffers allocated from that region. Thus, it is not implemented yet. Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com> --- All the patches to optee.c should be merged together. They were split to ease up review. But they depend heavily on each other. Changes from v4: - Handler does not use forward_call(). Instead it calls OP-TEE directly with arm_smccc_smc(). - Handler modifies only those guest registers that are should be touched according to OP-TEE protocol specification. - Added OPTEE_MEDIATOR_SMC_COUNT definition. Changes from v2: - Defined known capabilities explicitly - Fixed code style --- xen/arch/arm/tee/optee.c | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c index e9b69bd2d2..6c51caa41a 100644 --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -32,9 +32,17 @@ #include <asm/tee/optee_msg.h> #include <asm/tee/optee_smc.h> +/* Number of SMCs known to the mediator */ +#define OPTEE_MEDIATOR_SMC_COUNT 11 + /* Client ID 0 is reserved for the hypervisor itself */ #define OPTEE_CLIENT_ID(domain) ((domain)->domain_id + 1) +#define OPTEE_KNOWN_NSEC_CAPS OPTEE_SMC_NSEC_CAP_UNIPROCESSOR +#define OPTEE_KNOWN_SEC_CAPS (OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM | \ + OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM | \ + OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) + /* Domain context */ struct optee_domain { }; @@ -120,22 +128,111 @@ static int optee_relinquish_resources(struct domain *d) return 0; } +static void handle_exchange_capabilities(struct cpu_user_regs *regs) +{ + struct arm_smccc_res resp; + uint32_t caps; + + /* Filter out unknown guest caps */ + caps = get_user_reg(regs, 1); + caps &= OPTEE_KNOWN_NSEC_CAPS; + + arm_smccc_smc(OPTEE_SMC_EXCHANGE_CAPABILITIES, caps, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + if ( resp.a0 != OPTEE_SMC_RETURN_OK ) { + set_user_reg(regs, 0, resp.a0); + return; + } + + caps = resp.a1; + + /* Filter out unknown OP-TEE caps */ + caps &= OPTEE_KNOWN_SEC_CAPS; + + /* Drop static SHM_RPC cap */ + caps &= ~OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM; + + /* Don't allow guests to work without dynamic SHM */ + if ( !(caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM) ) + { + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + return; + } + + set_user_reg(regs, 0, OPTEE_SMC_RETURN_OK); + set_user_reg(regs, 1, caps); +} + static bool optee_handle_call(struct cpu_user_regs *regs) { + struct arm_smccc_res resp; + if ( !current->domain->arch.tee ) return false; switch ( get_user_reg(regs, 0) ) { case OPTEE_SMC_CALLS_COUNT: + set_user_reg(regs, 0, OPTEE_MEDIATOR_SMC_COUNT); + return true; + case OPTEE_SMC_CALLS_UID: + arm_smccc_smc(OPTEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + set_user_reg(regs, 3, resp.a3); + return true; + case OPTEE_SMC_CALLS_REVISION: + arm_smccc_smc(OPTEE_SMC_CALLS_REVISION, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + return true; + case OPTEE_SMC_CALL_GET_OS_UUID: + arm_smccc_smc(OPTEE_SMC_CALL_GET_OS_UUID, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain),&resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + set_user_reg(regs, 3, resp.a3); + return true; + case OPTEE_SMC_CALL_GET_OS_REVISION: + arm_smccc_smc(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + set_user_reg(regs, 1, resp.a1); + return true; + case OPTEE_SMC_ENABLE_SHM_CACHE: + arm_smccc_smc(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + return true; + case OPTEE_SMC_DISABLE_SHM_CACHE: + arm_smccc_smc(OPTEE_SMC_ENABLE_SHM_CACHE, 0, 0, 0, 0, 0, 0, + OPTEE_CLIENT_ID(current->domain), &resp); + set_user_reg(regs, 0, resp.a0); + if ( resp.a0 == OPTEE_SMC_RETURN_OK ) { + set_user_reg(regs, 1, resp.a1); + set_user_reg(regs, 2, resp.a2); + } + return true; + case OPTEE_SMC_GET_SHM_CONFIG: + /* No static SHM available for guests */ + set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); + return true; + case OPTEE_SMC_EXCHANGE_CAPABILITIES: + handle_exchange_capabilities(regs); + return true; + case OPTEE_SMC_CALL_WITH_ARG: case OPTEE_SMC_CALL_RETURN_FROM_RPC: set_user_reg(regs, 0, OPTEE_SMC_RETURN_ENOTAVAIL); -- 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-05-21 21:26 UTC|newest] Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-21 21:25 [PATCH v5 00/10] TEE mediator (and OP-TEE) support in XEN Volodymyr Babchuk 2019-05-21 21:25 ` [Xen-devel] " Volodymyr Babchuk 2019-05-21 21:25 ` [PATCH v5 01/10] xen/arm: add generic TEE mediator framework Volodymyr Babchuk 2019-05-21 21:25 ` [Xen-devel] " Volodymyr Babchuk 2019-05-22 8:45 ` Jan Beulich 2019-05-22 8:45 ` [Xen-devel] " Jan Beulich 2019-05-22 9:27 ` Julien Grall 2019-05-22 9:27 ` [Xen-devel] " Julien Grall 2019-05-22 10:02 ` Jan Beulich 2019-05-22 10:02 ` [Xen-devel] " Jan Beulich 2019-05-22 12:04 ` Julien Grall 2019-05-22 12:04 ` [Xen-devel] " Julien Grall 2019-06-03 11:46 ` Julien Grall 2019-06-03 11:46 ` [Xen-devel] " Julien Grall 2019-06-03 11:48 ` Julien Grall 2019-06-03 11:48 ` [Xen-devel] " Julien Grall 2019-06-06 16:02 ` Julien Grall 2019-06-07 9:36 ` Julien Grall 2019-06-11 18:18 ` Volodymyr Babchuk 2019-06-11 18:26 ` Julien Grall 2019-05-21 21:25 ` [PATCH v5 02/10] xen/arm: optee: add OP-TEE header files Volodymyr Babchuk 2019-05-21 21:25 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 11:49 ` Julien Grall 2019-06-03 11:49 ` [Xen-devel] " Julien Grall 2019-06-10 18:20 ` Volodymyr Babchuk 2019-06-10 18:53 ` Julien Grall 2019-05-21 21:25 ` [PATCH v5 03/10] xen/arm: optee: add OP-TEE mediator skeleton Volodymyr Babchuk 2019-05-21 21:25 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:34 ` Julien Grall 2019-06-03 12:34 ` [Xen-devel] " Julien Grall 2019-05-21 21:25 ` Volodymyr Babchuk [this message] 2019-05-21 21:25 ` [Xen-devel] [PATCH v5 04/10] xen/arm: optee: add fast calls handling Volodymyr Babchuk 2019-06-03 12:34 ` Julien Grall 2019-06-03 12:34 ` [Xen-devel] " Julien Grall 2019-05-21 21:26 ` [PATCH v5 05/10] xen/arm: optee: add std call handling Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:34 ` Julien Grall 2019-06-03 12:34 ` [Xen-devel] " Julien Grall 2019-05-21 21:26 ` [PATCH v5 06/10] xen/arm: optee: add support for RPC SHM buffers Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:33 ` Julien Grall 2019-06-03 12:33 ` [Xen-devel] " Julien Grall 2019-05-21 21:26 ` [PATCH v5 07/10] xen/arm: optee: add support for arbitrary shared memory Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:29 ` Julien Grall 2019-06-03 12:29 ` [Xen-devel] " Julien Grall 2019-05-21 21:26 ` [PATCH v5 08/10] xen/arm: optee: add support for RPC commands Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:33 ` Julien Grall 2019-06-03 12:33 ` [Xen-devel] " Julien Grall 2019-05-21 21:26 ` [PATCH v5 09/10] tools/arm: tee: add "tee" option for xl.cfg Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 12:44 ` Julien Grall 2019-06-03 12:44 ` [Xen-devel] " Julien Grall 2019-06-03 14:47 ` Ian Jackson 2019-06-03 14:47 ` [Xen-devel] " Ian Jackson 2019-05-21 21:26 ` [PATCH v5 10/10] tools/arm: optee: create optee firmware node in DT if tee=optee Volodymyr Babchuk 2019-05-21 21:26 ` [Xen-devel] " Volodymyr Babchuk 2019-06-03 14:50 ` Ian Jackson 2019-06-03 14:50 ` [Xen-devel] " Ian Jackson 2019-06-01 14:50 ` [PATCH v5 00/10] TEE mediator (and OP-TEE) support in XEN Julien Grall 2019-06-01 14:50 ` [Xen-devel] " Julien Grall 2019-06-01 16:07 ` Volodymyr Babchuk 2019-06-01 16:07 ` [Xen-devel] " Volodymyr Babchuk 2019-06-01 16:55 ` Julien Grall 2019-06-01 16:55 ` [Xen-devel] " Julien Grall 2019-06-04 13:31 ` Volodymyr Babchuk 2019-06-06 15:33 ` Julien Grall
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190521212530.12706-5-volodymyr_babchuk@epam.com \ --to=volodymyr_babchuk@epam.com \ --cc=julien.grall@arm.com \ --cc=sstabellini@kernel.org \ --cc=tee-dev@lists.linaro.org \ --cc=xen-devel@lists.xenproject.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).