From: Yuvraj Sakshith <yuvraj.kernel@gmail.com>
To: op-tee@lists.trustedfirmware.org
Subject: [RFC PATCH 7/7] tee: optee: Notify TEE Mediator on OP-TEE driver initialization and release
Date: Tue, 01 Apr 2025 22:35:27 +0530 [thread overview]
Message-ID: <20250401170527.344092-8-yuvraj.kernel@gmail.com> (raw)
In-Reply-To: <20250401170527.344092-1-yuvraj.kernel@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2547 bytes --]
When host initializes or releases its OP-TEE driver through
optee_core_init()/optee_core_exit(), notify OP-TEE in the secure world
about this change.
If OP-TEE is built with NS-Virtualization support, it will treat SMCs coming
from the host as if it were coming from a VM (as OP-TEE does not understand
the KVM paradigm).
Hence, OPTEE_SMC_VM_CREATED and OPTEE_SMC_VM_DESTROYED SMCs have to be made
for its internal book-keeping.
Signed-off-by: Yuvraj Sakshith <yuvraj.kernel@gmail.com>
---
drivers/tee/optee/core.c | 13 ++++++++++++-
drivers/tee/optee/smc_abi.c | 6 ++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index c75fddc83576..5f2ab0ee0893 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/tee_core.h>
+#include <linux/tee_mediator.h>
#include <linux/types.h>
#include "optee_private.h"
@@ -195,7 +196,13 @@ static bool intf_is_regged;
static int __init optee_core_init(void)
{
int rc;
-
+#ifdef CONFIG_TEE_MEDIATOR
+ if (tee_mediator_is_active()) {
+ rc = tee_mediator_create_host();
+ if (rc < 0)
+ return rc;
+ }
+#endif
/*
* The kernel may have crashed@the same time that all available
* secure world threads were suspended and we cannot reschedule the
@@ -240,6 +247,10 @@ static void __exit optee_core_exit(void)
optee_smc_abi_unregister();
if (!ffa_abi_rc)
optee_ffa_abi_unregister();
+#ifdef CONFIG_TEE_MEDIATOR
+ if (tee_mediator_is_active())
+ tee_mediator_destroy_host();
+#endif
}
module_exit(optee_core_exit);
diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
index f0c3ac1103bb..a930ca8cde23 100644
--- a/drivers/tee/optee/smc_abi.c
+++ b/drivers/tee/optee/smc_abi.c
@@ -25,8 +25,10 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/tee_core.h>
+#include <linux/tee_mediator.h>
#include <linux/types.h>
#include <linux/workqueue.h>
+#include "optee_mediator.h"
#include "optee_private.h"
#include "optee_smc.h"
#include "optee_rpc_cmd.h"
@@ -1396,6 +1398,10 @@ static void optee_smccc_smc(unsigned long a0, unsigned long a1,
unsigned long a6, unsigned long a7,
struct arm_smccc_res *res)
{
+#ifdef CONFIG_TEE_MEDIATOR
+ if (tee_mediator_is_active())
+ a7 = OPTEE_HOST_VMID;
+#endif
arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res);
}
--
2.43.0
next prev parent reply other threads:[~2025-04-01 17:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 17:05 [RFC PATCH 0/7] KVM: optee: Introduce OP-TEE Mediator for exposing secure world to KVM guests Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 1/7] firmware: smccc: Add macros for Trusted OS/App owner check on SMC value Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 2/7] tee: Add TEE Mediator module which aims to expose TEE to a KVM guest Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 3/7] KVM: Notify TEE Mediator when KVM creates and destroys guests Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 4/7] KVM: arm64: Forward guest CPU state to TEE mediator on SMC trap Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 5/7] tee: optee: Add OPTEE_SMC_VM_CREATED and OPTEE_SMC_VM_DESTROYED Yuvraj Sakshith
2025-04-01 17:05 ` [RFC PATCH 6/7] tee: optee: Add OP-TEE Mediator Yuvraj Sakshith
2025-04-01 17:05 ` Yuvraj Sakshith [this message]
2025-04-01 18:13 ` [RFC PATCH 0/7] KVM: optee: Introduce OP-TEE Mediator for exposing secure world to KVM guests Marc Zyngier
2025-04-02 2:58 ` Yuvraj Sakshith
2025-04-02 8:42 ` Marc Zyngier
2025-04-02 11:19 ` Yuvraj Sakshith
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=20250401170527.344092-8-yuvraj.kernel@gmail.com \
--to=yuvraj.kernel@gmail.com \
--cc=op-tee@lists.trustedfirmware.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: link
Be 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