Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Fuad Tabba <tabba@google.com>
To: kvmarm@lists.linux.dev
Cc: maz@kernel.org, oliver.upton@linux.dev, catalin.marinas@arm.com,
	 joey.gouly@arm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com,  will@kernel.org, christoffer.dall@arm.com,
	tabba@google.com
Subject: [PATCH v1 3/4] KVM: arm64: Convert KVM_ARM_VCPU_* features into an enum
Date: Mon, 14 Oct 2024 17:58:08 +0100	[thread overview]
Message-ID: <20241014165809.984883-4-tabba@google.com> (raw)
In-Reply-To: <20241014165809.984883-1-tabba@google.com>

Instead of using compile time defines, convert the KVM_ARM_VCPU_*
features into an enum. Among other things, this reduces the
chances of missing to update KVM_ARM_VCPU_MAX_FEATURES.

Also rename KVM_VCPU_MAX_FEATURES and KVM_ARM_VCPU_VALID_FEATURES
to KVM_ARM_VCPU_MAX_FEATURES and KVM_ARM_VCPU_VALID_FEATURES in
order to match the features they're counting.

No functional change intended.

Signed-off-by: Fuad Tabba <tabba@google.com>
---
 arch/arm64/include/asm/kvm_host.h |  2 +-
 arch/arm64/include/uapi/asm/kvm.h | 25 ++++++++++++++-----------
 arch/arm64/kvm/arm.c              | 10 +++++-----
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 85901afeb332..9b7bf4ba07a3 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -326,7 +326,7 @@ struct kvm_arch {
 	unsigned long flags;
 
 	/* VM-wide vCPU feature set */
-	DECLARE_BITMAP(vcpu_features, KVM_VCPU_MAX_FEATURES);
+	DECLARE_BITMAP(vcpu_features, KVM_ARM_VCPU_MAX_FEATURES);
 
 	/* MPIDR to vcpu index mapping, optional */
 	struct kvm_mpidr_data *mpidr_data;
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 2d5fd0ed7dff..b6ebd79b8373 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -100,17 +100,20 @@ struct kvm_regs {
 #define KVM_VGIC_V3_REDIST_SIZE		(2 * SZ_64K)
 #define KVM_VGIC_V3_ITS_SIZE		(2 * SZ_64K)
 
-#define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
-#define KVM_ARM_VCPU_EL1_32BIT		1 /* CPU running a 32bit VM */
-#define KVM_ARM_VCPU_PSCI_0_2		2 /* CPU uses PSCI v0.2 */
-#define KVM_ARM_VCPU_PMU_V3		3 /* Support guest PMUv3 */
-#define KVM_ARM_VCPU_SVE		4 /* enable SVE for this CPU */
-#define KVM_ARM_VCPU_PTRAUTH_ADDRESS	5 /* VCPU uses address authentication */
-#define KVM_ARM_VCPU_PTRAUTH_GENERIC	6 /* VCPU uses generic authentication */
-#define KVM_ARM_VCPU_HAS_EL2		7 /* Support nested virtualization */
-
-#define KVM_VCPU_MAX_FEATURES 8
-#define KVM_VCPU_VALID_FEATURES	(BIT(KVM_VCPU_MAX_FEATURES) - 1)
+enum kvm_arm_vcpu_features {
+	KVM_ARM_VCPU_POWER_OFF = 0,	/* CPU is started in OFF state */
+	KVM_ARM_VCPU_EL1_32BIT,		/* CPU running a 32bit VM */
+	KVM_ARM_VCPU_PSCI_0_2,		/* CPU uses PSCI v0.2 */
+	KVM_ARM_VCPU_PMU_V3,		/* Support guest PMUv3 */
+	KVM_ARM_VCPU_SVE,		/* enable SVE for this CPU */
+	KVM_ARM_VCPU_PTRAUTH_ADDRESS,	/* VCPU uses address authentication */
+	KVM_ARM_VCPU_PTRAUTH_GENERIC,	/* VCPU uses generic authentication */
+	KVM_ARM_VCPU_HAS_EL2,		/* Support nested virtualization */
+
+	KVM_ARM_VCPU_MAX_FEATURES,	/* Must be last */
+};
+
+#define KVM_ARM_VCPU_VALID_FEATURES	(BIT(KVM_ARM_VCPU_MAX_FEATURES) - 1)
 
 struct kvm_vcpu_init {
 	__u32 target;
diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
index a0d01c46e408..df17d50887d6 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -211,7 +211,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 
 	kvm_arm_init_hypercalls(kvm);
 
-	bitmap_zero(kvm->arch.vcpu_features, KVM_VCPU_MAX_FEATURES);
+	bitmap_zero(kvm->arch.vcpu_features, KVM_ARM_VCPU_MAX_FEATURES);
 
 	return 0;
 
@@ -1407,7 +1407,7 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
 
 static unsigned long system_supported_vcpu_features(void)
 {
-	unsigned long features = KVM_VCPU_VALID_FEATURES;
+	unsigned long features = KVM_ARM_VCPU_VALID_FEATURES;
 
 	if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
 		clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
@@ -1435,7 +1435,7 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu,
 	unsigned long features = init->features[0];
 	int i;
 
-	if (features & ~KVM_VCPU_VALID_FEATURES)
+	if (features & ~KVM_ARM_VCPU_VALID_FEATURES)
 		return -ENOENT;
 
 	for (i = 1; i < ARRAY_SIZE(init->features); i++) {
@@ -1474,7 +1474,7 @@ static bool kvm_vcpu_init_changed(struct kvm_vcpu *vcpu,
 	unsigned long features = init->features[0];
 
 	return !bitmap_equal(vcpu->kvm->arch.vcpu_features, &features,
-			     KVM_VCPU_MAX_FEATURES);
+			     KVM_ARM_VCPU_MAX_FEATURES);
 }
 
 static int kvm_setup_vcpu(struct kvm_vcpu *vcpu)
@@ -1509,7 +1509,7 @@ static int __kvm_vcpu_set_target(struct kvm_vcpu *vcpu,
 	    kvm_vcpu_init_changed(vcpu, init))
 		goto out_unlock;
 
-	bitmap_copy(kvm->arch.vcpu_features, &features, KVM_VCPU_MAX_FEATURES);
+	bitmap_copy(kvm->arch.vcpu_features, &features, KVM_ARM_VCPU_MAX_FEATURES);
 
 	ret = kvm_setup_vcpu(vcpu);
 	if (ret)
-- 
2.47.0.rc1.288.g06298d1525-goog


  parent reply	other threads:[~2024-10-14 16:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 16:58 [PATCH v1 0/4] KVM: arm64: Update KVM_VCPU_MAX_FEATURES and refactor to avoid same issue Fuad Tabba
2024-10-14 16:58 ` [PATCH v1 1/4] KVM: arm64: Update the value of KVM_VCPU_MAX_FEATURES Fuad Tabba
2024-10-14 16:58 ` [PATCH v1 2/4] KVM: arm64: Move KVM_VCPU_MAX_FEATURES to the features it is counting Fuad Tabba
2024-10-14 16:58 ` Fuad Tabba [this message]
2024-10-14 17:13   ` [PATCH v1 3/4] KVM: arm64: Convert KVM_ARM_VCPU_* features into an enum Marc Zyngier
2024-10-14 16:58 ` [PATCH v1 4/4] KVM: arm64: Convert KVM_ARCH_FLAG_* " Fuad Tabba
2024-10-14 17:17 ` [PATCH v1 0/4] KVM: arm64: Update KVM_VCPU_MAX_FEATURES and refactor to avoid same issue Marc Zyngier
2024-10-14 18:17   ` Fuad Tabba
2024-10-15 10:15     ` Marc Zyngier

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=20241014165809.984883-4-tabba@google.com \
    --to=tabba@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --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