[PATCH RFC v2 1/2] KVM: arm64: CCA: Add support for configuring the Realm MEC policy

Kohei Enju enju.kohei at fujitsu.com
Tue Nov 24 19:17:38 PST 2026


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 at 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



More information about the linux-arm-kernel mailing list