kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Yuvraj Sakshith <yuvraj.kernel@gmail.com>
Cc: kvmarm@lists.linux.dev, op-tee@lists.trustedfirmware.org,
	kvm@vger.kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com,
	suzuki.poulose@arm.com, yuzenghui@huawei.com,
	catalin.marinas@arm.com, will@kernel.org,
	jens.wiklander@linaro.org, sumit.garg@kernel.org,
	mark.rutland@arm.com, lpieralisi@kernel.org,
	sudeep.holla@arm.com, pbonzini@redhat.com, praan@google.com
Subject: Re: [RFC PATCH 0/7] KVM: optee: Introduce OP-TEE Mediator for exposing secure world to KVM guests
Date: Tue, 01 Apr 2025 19:13:26 +0100	[thread overview]
Message-ID: <87ldsjzr5l.wl-maz@kernel.org> (raw)
In-Reply-To: <20250401170527.344092-1-yuvraj.kernel@gmail.com>

On Tue, 01 Apr 2025 18:05:20 +0100,
Yuvraj Sakshith <yuvraj.kernel@gmail.com> wrote:
> 
> A KVM guest running on an arm64 machine will not be able to interact with a trusted execution environment
> (which supports non-secure guests) like OP-TEE in the secure world. This is because, instructions provided
> by the architecture (such as, SMC)  which switch control to the firmware, are trapped in EL2 when the guest
> is executes them.
> 
> This series adds a feature into the kernel called the TEE mediator abstraction layer, which lets
> a guest interact with the secure world. Additionally, a OP-TEE specific mediator is also implemented, which
> hooks itself to the TEE mediator layer and intercepts guest SMCs targetted at OP-TEE.
> 
> Overview
> =========
> 
> Essentially, if the kernel wants to interact with OP-TEE, it makes an "smc - secure monitor call instruction",
> after loading in arguments into CPU registers. What these arguments consists of and how both these entities 
> communicate can vary. If a guest wants to establish a connection with the secure world, its not possible. 
> This is because of the fact that "smc" by the guest are trapped by the hypervisor in EL2. This is done by setting
> the HCR_EL2.TSC bit before entering the guest.
> 
> Hence, this feature which I we may call TEE mediator, acts as an intermediary between the guest and OP-TEE.
> Instead of denying the guest SMC and jumping back into the guest, the mediator forwards the request to
> OP-TEE.
> 
> OP-TEE supports virtualization in the normal world and expects 6 things from the NS-hypervisor:
> 
> 1. Notify OP-TEE when a VM is created.
> 2. Notify OP-TEE when a VM is destroyed.
> 3. Any SMC to OP-TEE has to contain the VMID in x7. If its the hypervisor sending, then VMID is 0.
> 4. Hypervisor has to perform IPA->PA translations of the memory addresses sent by guest.
> 5. Memory shared by the VM to OP-TEE has to remain pinned.
> 6. The hypervisor has to follow the OP-TEE protocol, so the guest thinks it is directly speaking to OP-TEE.
> 
> Its important to note that, if OP-TEE is built with NS-virtualization support, it can only function if there is 
> a hypervisor with a mediator in normal world.
> 
> This implementation has been heavily inspired by Xen's OP-TEE
> mediator.

[...]

And I think this inspiration is the source of most of the problems in
this series.

Routing Secure Calls from the guest to whatever is on the secure side
should not be the kernel's job at all. It should be the VMM's job. All
you need to do is to route the SMCs from the guest to userspace, and
we already have all the required infrastructure for that.

It is the VMM that should:

- signal the TEE of VM creation/teardown

- translate between IPAs and host VAs without involving KVM

- let the host TEE driver translate between VAs and PAs and deal with
  the pinning as required, just like it would do for any userspace
  (without ever using the KVM memslot interface)

- proxy requests from the guest to the TEE

- in general, bear the complexity of anything related to the TEE

In short, the VMM is just another piece of userspace using the TEE to
do whatever it wants. The TEE driver on the host must obviously know
about VMs, but that's about it.

Crucially, KVM should:

- be completely TEE agnostic and never call into something that is
  TEE-specific

- allow a TEE implementation entirely in userspace, specially for the
  machines that do not have EL3

As it stands, your design looks completely upside-down. Most of this
code should be userspace code and live in (or close to) the VMM, with
the host kernel only providing the basic primitives, most of which
should already be there.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.

  parent reply	other threads:[~2025-04-01 18:13 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 ` [RFC PATCH 7/7] tee: optee: Notify TEE Mediator on OP-TEE driver initialization and release Yuvraj Sakshith
2025-04-01 18:13 ` Marc Zyngier [this message]
2025-04-02  2:58   ` [RFC PATCH 0/7] KVM: optee: Introduce OP-TEE Mediator for exposing secure world to KVM guests 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=87ldsjzr5l.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=jens.wiklander@linaro.org \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=lpieralisi@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=oliver.upton@linux.dev \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=pbonzini@redhat.com \
    --cc=praan@google.com \
    --cc=sudeep.holla@arm.com \
    --cc=sumit.garg@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuvraj.kernel@gmail.com \
    --cc=yuzenghui@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).