mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kohei Enju <enju.kohei@fujitsu.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Marc Zyngier <maz@kernel.org>,  Oliver Upton <oupton@kernel.org>,
	Fuad Tabba <fuad.tabba@linux.dev>,
	 Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	 Steven Price <steven.price@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	 Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	 Mark Rutland <mark.rutland@arm.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	cgroups@vger.kernel.org
Subject: Re: [PATCH RFC v2 1/2] KVM: arm64: CCA: Add support for configuring the Realm MEC policy
Date: Wed, 25 Nov 2026 12:17:38 +0900	[thread overview]
Message-ID: <awZR98W3sP9g12wh@FCCLS0092175.localdomain> (raw)
In-Reply-To: <090662ee-0d8d-48b5-83f2-8a4d225bef08@arm.com>

Hi Suzuki,
Thank you for reviewing.

On 11/24 15:08, Suzuki K Poulose wrote:
> On 12/11/2026 03:36, Kohei Enju wrote:
> > Introduce the KVM_ARM_VM_RMI_CTRL device attribute group to allow
> > userspace to configure Realm VM parameters before the Realm is created
> > using KVM_SET_DEVICE_ATTR.
> > 
> > Currently, KVM_ARM_VM_RMI_CTRL_MEC_POLICY is the only supported
> > attribute. Its value can be KVM_ARM_VM_RMI_MEC_POLICY_SHARED or
> > KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE. Reject the private policy if the
> > platform does not support private MECs.
> > 
> > If userspace does not explicitly configure the MEC policy,
> > KVM_ARM_VM_RMI_MEC_POLICY_SHARED is used by default.
> > 
> > Signed-off-by: Kohei Enju <enju.kohei@fujitsu.com>
> > ---
> >   Documentation/virt/kvm/devices/vm.rst   | 25 +++++++++++++++
> >   arch/arm64/include/asm/kvm_rmi.h        |  5 +++
> >   arch/arm64/include/uapi/asm/kvm.h       |  4 +++
> >   arch/arm64/kvm/arm.c                    |  4 +++
> >   arch/arm64/kvm/rmi.c                    | 57 +++++++++++++++++++++++++++++++++
> >   drivers/firmware/arm_rmm/rmi.c          |  6 ++++
> >   include/linux/arm-rmi-cmds.h            |  1 +
> >   tools/arch/arm64/include/uapi/asm/kvm.h |  4 +++
> >   8 files changed, 106 insertions(+)
> > 
> > diff --git a/Documentation/virt/kvm/devices/vm.rst b/Documentation/virt/kvm/devices/vm.rst
> > index 78e63eb9994e..b0bd30750aa1 100644
> > --- a/Documentation/virt/kvm/devices/vm.rst
> > +++ b/Documentation/virt/kvm/devices/vm.rst
> > @@ -418,3 +418,28 @@ will reject attempts to define a filter for any portion of these ranges:
> >           0x8000_0000 0x8000_FFFF
> >           0xC000_0000 0xC000_FFFF
> >           =========== ===============
> > +
> > +7. GROUP: KVM_ARM_VM_RMI_CTRL
> > +=============================
> > +
> > +:Architectures: arm64
> > +
> > +7.1. ATTRIBUTE: KVM_ARM_VM_RMI_CTRL_MEC_POLICY (w/o)
> > +----------------------------------------------------
> > +
> > +:Parameters: Pointer to a ``__u8`` value
> > +
> > +:Returns:
> > +
> > +  =========  ===========================================================
> > +  ENXIO      The VM is not a Realm VM
> > +  EBUSY      The Realm has already been created
> > +  EINVAL     Invalid MEC policy value
> > +  EOPNOTSUPP Private MEC policy is not supported by the platform
> > +  EFAULT     The value could not be copied from userspace
> > +  =========  ===========================================================
> > +
> > +Configures the MEC policy for a Realm VM before the Realm is created. The value
> > +must be either ``KVM_ARM_VM_RMI_MEC_POLICY_SHARED`` or
> > +``KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE``. If userspace does not explicitly set the
> > +MEC policy, ``KVM_ARM_VM_RMI_MEC_POLICY_SHARED`` is used by default.
> > diff --git a/arch/arm64/include/asm/kvm_rmi.h b/arch/arm64/include/asm/kvm_rmi.h
> > index 3933f8d834b8..08c1f6d0671d 100644
> > --- a/arch/arm64/include/asm/kvm_rmi.h
> > +++ b/arch/arm64/include/asm/kvm_rmi.h
> > @@ -59,6 +59,7 @@ enum realm_state {
> >    * @state: The lifetime state machine for the realm
> >    * @ia_bits: Number of valid Input Address bits in the IPA
> >    * @stage2_unmapped: The Realm stage-2 mappings have been removed
> > + * @mec_policy: MEC policy for the Realm VM
> >    */
> >   struct realm {
> >   	void *rd;
> > @@ -73,6 +74,7 @@ struct realm {
> >   	enum realm_state state;
> >   	unsigned int ia_bits;
> >   	bool stage2_unmapped;
> > +	unsigned int mec_policy;
> >   };
> >   /**
> > @@ -109,9 +111,12 @@ int kvm_realm_teardown_stage2(struct kvm *kvm);
> >   void kvm_destroy_rec(struct kvm_vcpu *vcpu);
> >   struct kvm_arm_rmi_populate;
> > +struct kvm_device_attr;
> >   int kvm_arm_rmi_populate(struct kvm *kvm,
> >   			 struct kvm_arm_rmi_populate *arg);
> > +int kvm_vm_rmi_has_attr(struct kvm *kvm, struct kvm_device_attr *attr);
> > +int kvm_vm_rmi_set_attr(struct kvm *kvm, struct kvm_device_attr *attr);
> >   enum kvm_gfn_range_filter;
> > diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
> > index 65ee09bd1463..aa1e6fe6192e 100644
> > --- a/arch/arm64/include/uapi/asm/kvm.h
> > +++ b/arch/arm64/include/uapi/asm/kvm.h
> > @@ -403,6 +403,10 @@ enum {
> >   /* Device Control API on vm fd */
> >   #define KVM_ARM_VM_SMCCC_CTRL		0
> >   #define   KVM_ARM_VM_SMCCC_FILTER	0
> > +#define KVM_ARM_VM_RMI_CTRL		1
> > +#define   KVM_ARM_VM_RMI_CTRL_MEC_POLICY	0
> > +#define     KVM_ARM_VM_RMI_MEC_POLICY_SHARED	0
> > +#define     KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE	1
> >   /* Device Control API: ARM VGIC */
> >   #define KVM_DEV_ARM_VGIC_GRP_ADDR	0
> > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> > index 8e94f1bff830..be676c13e219 100644
> > --- a/arch/arm64/kvm/arm.c
> > +++ b/arch/arm64/kvm/arm.c
> > @@ -2329,6 +2329,8 @@ static int kvm_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
> >   	switch (attr->group) {
> >   	case KVM_ARM_VM_SMCCC_CTRL:
> >   		return kvm_vm_smccc_has_attr(kvm, attr);
> > +	case KVM_ARM_VM_RMI_CTRL:
> > +		return kvm_vm_rmi_has_attr(kvm, attr);
> >   	default:
> >   		return -ENXIO;
> >   	}
> > @@ -2339,6 +2341,8 @@ static int kvm_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr)
> >   	switch (attr->group) {
> >   	case KVM_ARM_VM_SMCCC_CTRL:
> >   		return kvm_vm_smccc_set_attr(kvm, attr);
> > +	case KVM_ARM_VM_RMI_CTRL:
> > +		return kvm_vm_rmi_set_attr(kvm, attr);
> >   	default:
> >   		return -ENXIO;
> >   	}
> > diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
> > index 0d254fb80cde..01ac8d4fec7c 100644
> > --- a/arch/arm64/kvm/rmi.c
> > +++ b/arch/arm64/kvm/rmi.c
> > @@ -7,6 +7,7 @@
> >   #include <linux/arm-rmi-cmds.h>
> >   #include <linux/kvm_host.h>
> >   #include <linux/overflow.h>
> > +#include <linux/uaccess.h>
> >   #include <asm/daifflags.h>
> >   #include <asm/kvm_emulate.h>
> > @@ -586,6 +587,9 @@ static int realm_create_rd(struct kvm *kvm)
> >   		params->flags0 |= RMI_REALM_PARAM_FLAG_PMU;
> >   	}
> > +	params->flags0 |= FIELD_PREP(RMI_REALM_PARAM_FLAG_MEC_POLICY_MASK,
> > +				    realm->mec_policy);
> > +
> >   	r = realm_init_sve_param(kvm, params);
> >   	if (r)
> >   		goto out_undelegate_tables;
> > @@ -1481,6 +1485,57 @@ int kvm_arm_rmi_populate(struct kvm *kvm,
> >   	return ret;
> >   }
> > +static int kvm_vm_rmi_set_mec_policy(struct kvm *kvm, u8 policy)
> > +{
> > +	guard(mutex)(&kvm->arch.config_lock);
> > +
> > +	if (!kvm_vm_is_realm(kvm))
> > +		return -ENXIO;
> > +
> > +	if (kvm_realm_state(kvm) != REALM_STATE_NONE)
> > +		return -EBUSY;
> > +
> > +	if (policy != KVM_ARM_VM_RMI_MEC_POLICY_SHARED &&
> > +	    policy != KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE)
> > +		return -EINVAL;
> > +
> > +	if (policy == KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE &&
> > +	    rmi_mec_count() == 0)
> > +		return -EOPNOTSUPP;
> > +
> > +	kvm->arch.realm.mec_policy = policy;
> > +	return 0;
> > +}
> > +
> > +int kvm_vm_rmi_has_attr(struct kvm *kvm, struct kvm_device_attr *attr)
> > +{
> > +	if (!kvm_vm_is_realm(kvm))
> > +		return -ENXIO;
> > +
> > +	switch (attr->attr) {
> > +	case KVM_ARM_VM_RMI_CTRL_MEC_POLICY:
> 
> minor nit: Could we reject this if the rmi_mec_count() == 0 ?
> Default policy is "shared" mec, as long as it is documented, this
> would work only on a system that supports Private MEC.

With SHARED as the default, how about making this a boolean attribute
named KVM_ARM_VM_RMI_CTRL_MEC_PRIVATE? Then gating its availability on
rmi_mec_count() > 0 would make sense to me.

Thanks,
Kohei

> 
> 
> Suzuki

  reply	other threads:[~2026-11-25  3:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  3:36 [PATCH RFC v2 0/2] KVM: arm64: CCA: Add MEC policy support for CCA Realms Kohei Enju
2026-11-12  3:36 ` [PATCH RFC v2 1/2] KVM: arm64: CCA: Add support for configuring the Realm MEC policy Kohei Enju
2026-11-24 15:08   ` Suzuki K Poulose
2026-11-25  3:17     ` Kohei Enju [this message]
2026-11-12  3:36 ` [PATCH RFC v2 2/2] cgroup/misc: Add support for Arm CCA MECIDs Kohei Enju

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=awZR98W3sP9g12wh@FCCLS0092175.localdomain \
    --to=enju.kohei@fujitsu.com \
    --cc=catalin.marinas@arm.com \
    --cc=cgroups@vger.kernel.org \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seiden@linux.ibm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --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

all inboxes | Powered by JetHome®