Linux Documentation
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jpb@kernel.org>
To: Marc Zyngier <maz@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Oliver Upton <oupton@kernel.org>,
	Alex Williamson <alex@shazbot.org>,
	Jason Gunthorpe <jgg@nvidia.com>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Oded Gabbay <ogabbay@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	kvm@vger.kernel.org, devicetree@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org
Subject: Re: [RFC PATCH v2 11/15] KVM: arm64: Export stage-2 MMU config
Date: Fri, 23 Oct 2026 16:56:46 +0100	[thread overview]
Message-ID: <20261023155646.GA52056@myrica> (raw)
In-Reply-To: <86h5idzqow.wl-maz@kernel.org>

On Thu, Oct 22, 2026 at 04:43:27PM +0100, Marc Zyngier wrote:
> > +struct kvm_arch_guest_mmu *kvm_arch_get_guest_mmu(struct kvm *kvm)
> > +{
> > +	int ret;
> > +	struct kvm_arch_guest_mmu *mmu;
> > +
> > +	guard(mutex)(&kvm->arch.config_lock);
> > +
> > +	if (is_protected_kvm_enabled())
> > +		return ERR_PTR(-EOPNOTSUPP);
> 
> How does this compose with CCA?

This function would reject realm VMs once they're supported. If we
wanted to assign a CLA device to a realm VM, I think it would be managed
entirely outside the host:

* EL3 driver reconfigures the device's accesses to
  physical memory (security state, memory encryption etc),
* RMM driver owns the PL2 registers to program the stage 2 MTC,
* the VM owns the rest of the device.

Lack of interrupts should make this assignment relatively simple.

> Can it be restricted to exclusively running VHE rather than also
> dealing with the lesser configurations?

Yes, I don't think we want to support any nVHE config at this point.


> > +	mmu->vtcr = kvm->arch.mmu.vtcr;
> > +	mmu->vttbr = kvm_get_vttbr(&kvm->arch.mmu);
> > +	mmu->hcr = kvm_mmu_get_hcr(kvm, 0);
> 
> How about the hcrx field in the structure?

It's 0 because HCRX doesn't seem to have bits relevant to MMU
translation, except maybe EnSDERR and EnSNERR that KVM doesn't set.
But it's not entirely clear which bits are relevant to this function,
because other possible users may access memory differently (eg. no
instruction fetch or CMO from a CLA device). Your suggestion below
should simplify this.

> > +
> > +	return mmu;
> > +
> > +err_unpin_vmid:
> > +	kvm_arm_pinned_vmid_put(kvm);
> > +	return ERR_PTR(ret);
> > +}
> > +EXPORT_SYMBOL_GPL(kvm_arch_get_guest_mmu);
> 
> It really feels like this is a bit upside down. Since you are actively
> pinning the S2 MMU context, it should only be a matter of taking a
> reference on the kvm struct (just like KVM devices do), and handing
> off the kvm_s2_mmu structure, rather than copying things. When you're
> done with it, drop the reference.

OK, I'll update this. The reason for this copy was to keep a clear
separation between KVM and the CLA driver, so the driver wouldn't have
to use KVM internals like kvm_get_vttbr() and kvm_has_mte(). I think
those are the only ones at the moment.

> If there is a need to deal with a different value for HCR_EL2 (or
> anything else), it can be done in the code that makes use of it,
> rather than being in the KVM code.

Makes sense

Thanks,
Jean

  reply	other threads:[~2026-10-23 15:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 14:25 [RFC PATCH v2 00/15] Arm Core Local Accelerator Driver Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 01/15] misc/arm-cla: Add driver skeleton and documentation Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 02/15] misc/arm-cla: Add launch operation helpers Ryan Roberts
2026-10-15 16:17   ` Greg Kroah-Hartman
2026-10-15 16:32     ` Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 03/15] dt-bindings: misc: Add Arm Core Local Accelerator Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 04/15] misc/arm-cla: Probe firmware-described devices Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 05/15] misc/arm-cla: Initialize devices on CPU bringup Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 06/15] misc/arm-cla: Accelerator context save and restore Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 07/15] misc/arm-cla: Set up memory translation context Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 08/15] misc/arm-cla: Manage domain contexts Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 09/15] misc/arm-cla: Add userspace interface Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 10/15] KVM: arm64: Introduce support to pin VMIDs Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 11/15] KVM: arm64: Export stage-2 MMU config Ryan Roberts
2026-10-22 15:43   ` Marc Zyngier
2026-10-23 15:56     ` Jean-Philippe Brucker [this message]
2026-10-15 14:25 ` [RFC PATCH v2 12/15] vfio: Support VFIO devices that access the CPU MMU Ryan Roberts
2026-10-15 16:44   ` Jason Gunthorpe
2026-10-20 11:51     ` Ryan Roberts
2026-10-20 14:09       ` Jason Gunthorpe
2026-10-20 15:06         ` Ryan Roberts
2026-10-20 15:13           ` Alex Williamson
2026-10-20 15:55             ` Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 13/15] misc/arm-cla: Add stage-2 MTC and VM context switch Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 14/15] misc/arm-cla: Support exclusive context assignment Ryan Roberts
2026-10-15 14:25 ` [RFC PATCH v2 15/15] misc/arm-cla: Add vfio-mdev user interface Ryan Roberts
2026-10-15 16:41   ` Jason Gunthorpe
2026-10-16 14:22     ` Jean-Philippe Brucker
2026-10-16 14:42       ` Jason Gunthorpe
2026-10-20 10:41         ` Ryan Roberts
2026-10-20 14:15           ` Jason Gunthorpe
2026-10-20 14:27             ` Ryan Roberts

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=20261023155646.GA52056@myrica \
    --to=jpb@kernel.org \
    --cc=alex@shazbot.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jgg@nvidia.com \
    --cc=krzk+dt@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=oupton@kernel.org \
    --cc=robh@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=will@kernel.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