From: Raghavendra Rao Ananta <rananta@google.com>
To: Oliver Upton <oliver.upton@linux.dev>, Marc Zyngier <maz@kernel.org>
Cc: Raghavendra Rao Anata <rananta@google.com>,
Mingwei Zhang <mizhang@google.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH 3/3] KVM: selftests: Extend vgic_init to test GICv4 config attr
Date: Wed, 14 May 2025 19:21:59 +0000 [thread overview]
Message-ID: <20250514192159.1751538-4-rananta@google.com> (raw)
In-Reply-To: <20250514192159.1751538-1-rananta@google.com>
Extend the arm64 vgic_init test to check KVM_DEV_ARM_VGIC_CONFIG_GICV4
attribute. This includes testing the interface with various
configurations when KVM has vGICv4 enabled (kvm-arm.vgic_v4_enable=1
cmdline) and disabled.
Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
---
tools/testing/selftests/kvm/arm64/vgic_init.c | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/tools/testing/selftests/kvm/arm64/vgic_init.c b/tools/testing/selftests/kvm/arm64/vgic_init.c
index b3b5fb0ff0a9..adcfaf461b2b 100644
--- a/tools/testing/selftests/kvm/arm64/vgic_init.c
+++ b/tools/testing/selftests/kvm/arm64/vgic_init.c
@@ -675,6 +675,63 @@ static void test_v3_its_region(void)
vm_gic_destroy(&v);
}
+static void test_v3_vgicv4_config(void)
+{
+ struct kvm_vcpu *vcpus[NR_VCPUS];
+ uint8_t gicv4_config;
+ struct vm_gic v;
+ int ret;
+
+ v = vm_gic_create_with_vcpus(KVM_DEV_TYPE_ARM_VGIC_V3, NR_VCPUS, vcpus);
+ if (__kvm_has_device_attr(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4))
+ return;
+
+ kvm_device_attr_get(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+
+ if (gicv4_config == KVM_DEV_ARM_VGIC_CONFIG_GICV4_UNAVAILABLE) {
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_DISABLE;
+ ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+ TEST_ASSERT(ret && errno == ENXIO,
+ "vGICv4 allowed to be disabled even though it's unavailable");
+
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_ENABLE;
+ ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+ TEST_ASSERT(ret && errno == ENXIO,
+ "vGICv4 allowed to be enabled even though it's unavailable");
+ } else { /* kvm-arm.vgic_v4_enable=1 */
+ TEST_ASSERT(gicv4_config == KVM_DEV_ARM_VGIC_CONFIG_GICV4_ENABLE,
+ "Expected vGICv4 to be enabled by default");
+
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_DISABLE;
+ kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_ENABLE;
+ kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_ENABLE + 1;
+ ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+ TEST_ASSERT(ret && errno == EINVAL,
+ "vGICv4 allowed to be configured with unknown value");
+
+ kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
+ gicv4_config = KVM_DEV_ARM_VGIC_CONFIG_GICV4_DISABLE;
+ ret = __kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
+ KVM_DEV_ARM_VGIC_CONFIG_GICV4, &gicv4_config);
+ TEST_ASSERT(ret && errno == EBUSY,
+ "Changing vGICv4 config allowed after vGIC initialization");
+ }
+
+ vm_gic_destroy(&v);
+}
+
/*
* Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
*/
@@ -730,6 +787,7 @@ void run_tests(uint32_t gic_dev_type)
test_v3_last_bit_single_rdist();
test_v3_redist_ipa_range_check_at_vcpu_run();
test_v3_its_region();
+ test_v3_vgicv4_config();
}
}
--
2.49.0.1101.gccaa498523-goog
next prev parent reply other threads:[~2025-05-14 19:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 19:21 [PATCH 0/3] KVM: arm64: Allow vGICv4 configuration per VM Raghavendra Rao Ananta
2025-05-14 19:21 ` [PATCH 1/3] kvm: arm64: Add support for KVM_DEV_ARM_VGIC_CONFIG_GICV4 attr Raghavendra Rao Ananta
2025-05-14 19:21 ` [PATCH 2/3] docs: kvm: devices/arm-vgic-v3: Document " Raghavendra Rao Ananta
2025-05-14 19:21 ` Raghavendra Rao Ananta [this message]
2025-05-15 10:30 ` [PATCH 0/3] KVM: arm64: Allow vGICv4 configuration per VM Ben Horgan
2025-05-15 10:48 ` Marc Zyngier
2025-05-15 15:55 ` Raghavendra Rao Ananta
2025-05-15 16:48 ` Ben Horgan
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=20250514192159.1751538-4-rananta@google.com \
--to=rananta@google.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=maz@kernel.org \
--cc=mizhang@google.com \
--cc=oliver.upton@linux.dev \
/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