From: Kohei Enju <enju.kohei@fujitsu.com>
To: 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>,
Suzuki K Poulose <suzuki.poulose@arm.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>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
cgroups@vger.kernel.org, Kohei Enju <enju.kohei@fujitsu.com>
Subject: [PATCH RFC v2 2/2] cgroup/misc: Add support for Arm CCA MECIDs
Date: Thu, 12 Nov 2026 12:36:22 +0900 [thread overview]
Message-ID: <20261112-mm-v1-mec-v2-2-0d1dd260a588@fujitsu.com> (raw)
In-Reply-To: <20261112-mm-v1-mec-v2-0-0d1dd260a588@fujitsu.com>
Arm CCA MECIDs are limited platform resources. Add a misc cgroup
resource to allow the system administrator to account for and limit
their use.
The cca_mec resource represents the number of Realm VMs using the
private MEC policy. Each such Realm consumes one MECID. Charge the
resource when the Realm is created, and uncharge it when the Realm is
successfully destroyed.
Realms using the shared MEC policy don't consume this resource.
Signed-off-by: Kohei Enju <enju.kohei@fujitsu.com>
---
arch/arm64/include/asm/kvm_rmi.h | 2 ++
arch/arm64/kvm/rmi.c | 44 +++++++++++++++++++++++++++++++++++++++-
drivers/firmware/arm_rmm/rmi.c | 4 ++++
include/linux/misc_cgroup.h | 4 ++++
kernel/cgroup/misc.c | 4 ++++
5 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/include/asm/kvm_rmi.h b/arch/arm64/include/asm/kvm_rmi.h
index 08c1f6d0671d..658e65454282 100644
--- a/arch/arm64/include/asm/kvm_rmi.h
+++ b/arch/arm64/include/asm/kvm_rmi.h
@@ -60,6 +60,7 @@ enum realm_state {
* @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
+ * @misc_cg: Misc cgroup charged while the Realm owns a private MECID
*/
struct realm {
void *rd;
@@ -75,6 +76,7 @@ struct realm {
unsigned int ia_bits;
bool stage2_unmapped;
unsigned int mec_policy;
+ struct misc_cg *misc_cg;
};
/**
diff --git a/arch/arm64/kvm/rmi.c b/arch/arm64/kvm/rmi.c
index 01ac8d4fec7c..d25d75744042 100644
--- a/arch/arm64/kvm/rmi.c
+++ b/arch/arm64/kvm/rmi.c
@@ -6,6 +6,7 @@
#include <uapi/linux/psci.h>
#include <linux/arm-rmi-cmds.h>
#include <linux/kvm_host.h>
+#include <linux/misc_cgroup.h>
#include <linux/overflow.h>
#include <linux/uaccess.h>
@@ -538,6 +539,36 @@ static int realm_init_sve_param(struct kvm *kvm, struct realm_params *params)
return 0;
}
+static int realm_mec_charge(struct realm *realm)
+{
+ struct misc_cg *misc_cg;
+ int ret;
+
+ if (realm->mec_policy != KVM_ARM_VM_RMI_MEC_POLICY_PRIVATE)
+ return 0;
+
+ misc_cg = get_current_misc_cg();
+
+ ret = misc_cg_try_charge(MISC_CG_RES_CCA_MEC, misc_cg, 1);
+ if (ret) {
+ put_misc_cg(misc_cg);
+ return ret;
+ }
+
+ realm->misc_cg = misc_cg;
+ return 0;
+}
+
+static void realm_mec_uncharge(struct realm *realm)
+{
+ if (!realm->misc_cg)
+ return;
+
+ misc_cg_uncharge(MISC_CG_RES_CCA_MEC, realm->misc_cg, 1);
+ put_misc_cg(realm->misc_cg);
+ realm->misc_cg = NULL;
+}
+
static int realm_create_rd(struct kvm *kvm)
{
struct realm *realm = &kvm->arch.realm;
@@ -594,12 +625,16 @@ static int realm_create_rd(struct kvm *kvm)
if (r)
goto out_undelegate_tables;
+ r = realm_mec_charge(realm);
+ if (r)
+ goto out_undelegate_tables;
+
params_phys = virt_to_phys(params);
rmi_ret = rmi_realm_create(rd_phys, params_phys, realm->sro);
if (rmi_ret) {
r = rmi_ret < 0 ? rmi_ret : -ENXIO;
- goto out_undelegate_tables;
+ goto out_uncharge_misc_cg;
}
realm->rd = rd;
@@ -607,6 +642,8 @@ static int realm_create_rd(struct kvm *kvm)
return 0;
+out_uncharge_misc_cg:
+ realm_mec_uncharge(realm);
out_undelegate_tables:
if (WARN_ON(rmi_undelegate_range(kvm->arch.mmu.pgd_phys,
top_delegated - kvm->arch.mmu.pgd_phys))) {
@@ -1727,10 +1764,15 @@ void kvm_destroy_realm(struct kvm *kvm)
if (WARN_ON(realm_destroy_rtts(kvm)))
return;
+ /*
+ * Keep the misc cgroup charge if RMI_REALM_DESTROY fails, as
+ * the corresponding MECID may still be allocated by the RMM.
+ */
if (WARN_ON(rmi_realm_destroy(rd_phys, realm->sro)))
return;
rmi_free_delegated_page(rd_phys);
realm->rd = NULL;
+ realm_mec_uncharge(realm);
}
if (WARN_ON(rmi_undelegate_range(kvm->arch.mmu.pgd_phys,
diff --git a/drivers/firmware/arm_rmm/rmi.c b/drivers/firmware/arm_rmm/rmi.c
index 27edf060d2d9..ba8a3e9a2603 100644
--- a/drivers/firmware/arm_rmm/rmi.c
+++ b/drivers/firmware/arm_rmm/rmi.c
@@ -7,6 +7,7 @@
#include <linux/cpufeature.h>
#include <linux/memblock.h>
#include <linux/memory.h>
+#include <linux/misc_cgroup.h>
#include <linux/mmzone.h>
#include <linux/slab.h>
@@ -1126,6 +1127,9 @@ static int __init arm64_init_rmi(void)
return ret;
}
+ WARN_ON_ONCE(misc_cg_set_capacity(MISC_CG_RES_CCA_MEC,
+ rmi_mec_count()));
+
/* Mark the RMM is usable */
WRITE_ONCE(arm64_rmi_is_available, true);
pr_info("RMI configured\n");
diff --git a/include/linux/misc_cgroup.h b/include/linux/misc_cgroup.h
index 0cb36a3ffc47..26131677170a 100644
--- a/include/linux/misc_cgroup.h
+++ b/include/linux/misc_cgroup.h
@@ -21,6 +21,10 @@ enum misc_res_type {
#ifdef CONFIG_INTEL_TDX_HOST
/** @MISC_CG_RES_TDX: Intel TDX HKIDs resource */
MISC_CG_RES_TDX,
+#endif
+#ifdef CONFIG_ARM_RMM_RMI
+ /** @MISC_CG_RES_CCA_MEC: ARM64 CCA MECIDs resource */
+ MISC_CG_RES_CCA_MEC,
#endif
/** @MISC_CG_RES_TYPES: count of enum misc_res_type constants */
MISC_CG_RES_TYPES
diff --git a/kernel/cgroup/misc.c b/kernel/cgroup/misc.c
index 4a9e2557141c..989316bcb5f0 100644
--- a/kernel/cgroup/misc.c
+++ b/kernel/cgroup/misc.c
@@ -28,6 +28,10 @@ static const char *const misc_res_name[] = {
/* Intel TDX HKIDs resource */
"tdx",
#endif
+#ifdef CONFIG_ARM_RMM_RMI
+ /* ARM64 CCA MECIDs resource */
+ "cca_mec",
+#endif
};
/* Root misc cgroup */
--
2.43.0
prev parent reply other threads:[~2026-11-12 3:37 UTC|newest]
Thread overview: 4+ 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-12 3:36 ` Kohei Enju [this message]
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=20261112-mm-v1-mec-v2-2-0d1dd260a588@fujitsu.com \
--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®