From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: Sascha Bischoff <Sascha.Bischoff@arm.com>
Cc: "linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"kvmarm@lists.linux.dev" <kvmarm@lists.linux.dev>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>, nd <nd@arm.com>,
"maz@kernel.org" <maz@kernel.org>,
"oliver.upton@linux.dev" <oliver.upton@linux.dev>,
Joey Gouly <Joey.Gouly@arm.com>,
Suzuki Poulose <Suzuki.Poulose@arm.com>,
"yuzenghui@huawei.com" <yuzenghui@huawei.com>,
"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
"lpieralisi@kernel.org" <lpieralisi@kernel.org>,
Timothy Hayes <Timothy.Hayes@arm.com>
Subject: Re: [PATCH v2 35/36] KVM: arm64: selftests: Introduce a minimal GICv5 PPI selftest
Date: Wed, 7 Jan 2026 16:38:47 +0000 [thread overview]
Message-ID: <20260107163847.00000fe9@huawei.com> (raw)
In-Reply-To: <20251219155222.1383109-36-sascha.bischoff@arm.com>
On Fri, 19 Dec 2025 15:52:48 +0000
Sascha Bischoff <Sascha.Bischoff@arm.com> wrote:
> This basic selftest creates a vgic_v5 device (if supported), and tests
> that one of the PPI interrupts works as expected with a basic
> single-vCPU guest.
>
> Upon starting, the guest enables interrupts. That means that it is
> initialising all PPIs to have reasonable priorities, but marking them
> as disabled. Then the priority mask in the ICC_PCR_EL1 is set, and
> interrupts are enable in ICC_CR0_EL1. At this stage the guest is able
> to recieve interrupts. The first IMPDEF PPI (64) is enabled and
> kvm_irq_line is used to inject the state into the guest.
>
> The guest's interrupt handler has an explicit WFI in order to ensure
> that the guest skips WFI when there are pending and enabled PPI
> interrupts.
>
> Signed-off-by: Sascha Bischoff <sascha.bischoff@arm.com>
Hi Sascha,
A few comments inline.
> diff --git a/tools/testing/selftests/kvm/arm64/vgic_v5.c b/tools/testing/selftests/kvm/arm64/vgic_v5.c
> new file mode 100644
> index 0000000000000..5879fbd71042d
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/arm64/vgic_v5.c
> @@ -0,0 +1,248 @@
> +static void test_vgic_v5_ppis(uint32_t gic_dev_type)
> +{
> + struct ucall uc;
> + struct kvm_vcpu *vcpus[NR_VCPUS];
> + struct vm_gic v;
> + int ret, i;
> +
> + v.gic_dev_type = gic_dev_type;
> + v.vm = __vm_create(VM_SHAPE_DEFAULT, NR_VCPUS, 0);
> +
> + v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
> +
> + for (i = 0; i < NR_VCPUS; ++i)
> + vcpus[i] = vm_vcpu_add(v.vm, i, guest_code);
> +
> + vm_init_descriptor_tables(v.vm);
> + vm_install_exception_handler(v.vm, VECTOR_IRQ_CURRENT, guest_irq_handler);
> +
> + for (i = 0; i < NR_VCPUS; i++)
> + vcpu_init_descriptor_tables(vcpus[i]);
> +
> + kvm_device_attr_set(v.gic_fd, KVM_DEV_ARM_VGIC_GRP_CTRL,
> + KVM_DEV_ARM_VGIC_CTRL_INIT, NULL);
> +
> + while (1) {
> + ret = run_vcpu(vcpus[0]);
> +
> + switch (get_ucall(vcpus[0], &uc)) {
> + case UCALL_SYNC:
> + /*
> + * The guest is ready for the next level
> + * change. Set high if ready, and lower if it
Odd line wrap. Go to 80 chars.
> + * has been consumed.
> + */
> + if (uc.args[1] == GUEST_CMD_IS_READY ||
> + uc.args[1] == GUEST_CMD_IRQ_DIEOI) {
> + u64 irq = 64;
> + bool level = uc.args[1] == GUEST_CMD_IRQ_DIEOI ? 0 : 1;
> +
> + irq &= KVM_ARM_IRQ_NUM_MASK;
Can use FIELD_PREP in tools. Seems likely to be useful here.
> + irq |= KVM_ARM_IRQ_TYPE_PPI << KVM_ARM_IRQ_TYPE_SHIFT;
> +
> + _kvm_irq_line(v.vm, irq, level);
> + } else if (uc.args[1] == GUEST_CMD_IS_AWAKE) {
> + pr_info("Guest skipping WFI due to pending IRQ\n");
> + } else if (uc.args[1] == GUEST_CMD_IRQ_CDIA) {
> + pr_info("Guest acknowledged IRQ\n");
> + }
> +
> + continue;
> + case UCALL_ABORT:
> + REPORT_GUEST_ASSERT(uc);
> + break;
> + case UCALL_DONE:
> + goto done;
> + default:
> + TEST_FAIL("Unknown ucall %lu", uc.cmd);
> + }
> + }
> +
> +done:
> + TEST_ASSERT(ret == 0, "Failed to test GICv5 PPIs");
> +
> + vm_gic_destroy(&v);
> +}
> +
> +/*
> + * Returns 0 if it's possible to create GIC device of a given type (V2 or V3).
Comment needs an update given you pass in v5
Maybe worth pulling this out as a library function for both sets of tests.
If not, rip out the v2, v3 code from here and the type parameter as that is
all code that will bit rot.
> + */
> +int test_kvm_device(uint32_t gic_dev_type)
> +{
> + struct kvm_vcpu *vcpus[NR_VCPUS];
> + struct vm_gic v;
> + uint32_t other;
> + int ret;
> +
> + v.vm = vm_create_with_vcpus(NR_VCPUS, guest_code, vcpus);
> +
> + /* try to create a non existing KVM device */
> + ret = __kvm_test_create_device(v.vm, 0);
> + TEST_ASSERT(ret && errno == ENODEV, "unsupported device");
> +
> + /* trial mode */
> + ret = __kvm_test_create_device(v.vm, gic_dev_type);
> + if (ret)
> + return ret;
> + v.gic_fd = kvm_create_device(v.vm, gic_dev_type);
> +
> + ret = __kvm_create_device(v.vm, gic_dev_type);
> + TEST_ASSERT(ret < 0 && errno == EEXIST, "create GIC device twice");
> +
> + /* try to create the other gic_dev_types */
> + other = KVM_DEV_TYPE_ARM_VGIC_V2;
> + if (!__kvm_test_create_device(v.vm, other)) {
> + ret = __kvm_create_device(v.vm, other);
> + TEST_ASSERT(ret < 0 && (errno == EINVAL || errno == EEXIST),
> + "create GIC device while other version exists");
> + }
> +
> + other = KVM_DEV_TYPE_ARM_VGIC_V3;
> + if (!__kvm_test_create_device(v.vm, other)) {
> + ret = __kvm_create_device(v.vm, other);
> + TEST_ASSERT(ret < 0 && (errno == EINVAL || errno == EEXIST),
> + "create GIC device while other version exists");
> + }
> +
> + other = KVM_DEV_TYPE_ARM_VGIC_V5;
> + if (!__kvm_test_create_device(v.vm, other)) {
> + ret = __kvm_create_device(v.vm, other);
> + TEST_ASSERT(ret < 0 && (errno == EINVAL || errno == EEXIST),
> + "create GIC device while other version exists");
> + }
> +
> + vm_gic_destroy(&v);
> +
> + return 0;
> +}
> +
> +int main(int ac, char **av)
> +{
> + int ret;
> + int pa_bits;
> + int cnt_impl = 0;
> +
> + test_disable_default_vgic();
> +
> + pa_bits = vm_guest_mode_params[VM_MODE_DEFAULT].pa_bits;
> + max_phys_size = 1ULL << pa_bits;
> +
> + ret = test_kvm_device(KVM_DEV_TYPE_ARM_VGIC_V5);
> + if (!ret) {
> + pr_info("Running VGIC_V5 tests.\n");
> + run_tests(KVM_DEV_TYPE_ARM_VGIC_V5);
> + cnt_impl++;
> + } else {
> + pr_info("No GICv5 support; Not running GIC_v5 tests.\n");
> + exit(KSFT_SKIP);
> + }
Flip to exit early on no device.
if (ret) {
pr_info("..);
exit(KSFT_SKIP);
}
pr_info(...);
run_tests(...
..
return 0;
> +
> + return 0;
> +}
> +
> +
Bonus blank line at end of file. One is fine.
> diff --git a/tools/testing/selftests/kvm/include/arm64/gic_v5.h b/tools/testing/selftests/kvm/include/arm64/gic_v5.h
> new file mode 100644
> index 0000000000000..5daaa84318bb1
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/include/arm64/gic_v5.h
> @@ -0,0 +1,148 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __SELFTESTS_GIC_V5_H
> +#define __SELFTESTS_GIC_V5_H
> +
> +#include <asm/barrier.h>
> +#include <asm/sysreg.h>
> +
> +#include <linux/bitfield.h>
> +
> +#include "processor.h"
> +
> +/* Definitions for GICR CDIA */
> +#define GICV5_GIC_CDIA_VALID_MASK BIT_ULL(32)
> +#define GICV5_GICR_CDIA_VALID(r) FIELD_GET(GICV5_GIC_CDIA_VALID_MASK, r)
> +#define GICV5_GIC_CDIA_TYPE_MASK GENMASK_ULL(31, 29)
> +#define GICV5_GIC_CDIA_ID_MASK GENMASK_ULL(23, 0)
> +#define GICV5_GIC_CDIA_INTID GENMASK_ULL(31, 0)
> +
> +/* Definitions for GICR CDNMIA */
> +#define GICV5_GIC_CDNMIA_VALID_MASK BIT_ULL(32)
> +#define GICV5_GICR_CDNMIA_VALID(r) FIELD_GET(GICV5_GIC_CDNMIA_VALID_MASK, r)
> +#define GICV5_GIC_CDNMIA_TYPE_MASK GENMASK_ULL(31, 29)
> +#define GICV5_GIC_CDNMIA_ID_MASK GENMASK_ULL(23, 0)
If we are updating the sysreg.h ones, remember to add R here as well.
next prev parent reply other threads:[~2026-01-07 16:38 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-19 15:52 [PATCH v2 00/36] KVM: arm64: Introduce vGIC-v5 with PPI support Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 02/36] KVM: arm64: gic-v3: Switch vGIC-v3 to use generated ICH_VMCR_EL2 Sascha Bischoff
2026-01-06 18:00 ` Jonathan Cameron
2026-01-07 10:55 ` Sascha Bischoff
2026-01-09 16:57 ` Sascha Bischoff
2026-01-12 12:41 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 03/36] arm64/sysreg: Drop ICH_HFGRTR_EL2.ICC_HAPR_EL1 and make RES1 Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 01/36] KVM: arm64: Account for RES1 bits in DECLARE_FEAT_MAP() and co Sascha Bischoff
2026-01-06 17:23 ` Jonathan Cameron
2026-01-08 16:52 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 05/36] arm64/sysreg: Add GICR CDNMIA encoding Sascha Bischoff
2026-01-06 18:08 ` Jonathan Cameron
2026-01-07 8:39 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 06/36] KVM: arm64: gic-v5: Add ARM_VGIC_V5 device to KVM headers Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 04/36] arm64/sysreg: Add remaining GICv5 ICC_ & ICH_ sysregs for KVM support Sascha Bischoff
2026-01-06 18:28 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 07/36] KVM: arm64: gic: Introduce interrupt type helpers Sascha Bischoff
2026-01-06 14:51 ` Joey Gouly
2026-01-06 18:43 ` Jonathan Cameron
2026-01-08 9:33 ` Sascha Bischoff
2026-01-08 10:25 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 09/36] KVM: arm64: gic-v5: Detect implemented PPIs on boot Sascha Bischoff
2026-01-06 18:34 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 08/36] KVM: arm64: Introduce kvm_call_hyp_nvhe_res() Sascha Bischoff
2026-01-07 10:30 ` Jonathan Cameron
2026-01-08 9:48 ` Sascha Bischoff
2026-01-08 10:26 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 11/36] KVM: arm64: gic-v5: Support GICv5 FGTs & FGUs Sascha Bischoff
2026-01-07 11:19 ` Jonathan Cameron
2026-01-08 10:36 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 10/36] KVM: arm64: gic-v5: Sanitize ID_AA64PFR2_EL1.GCIE Sascha Bischoff
2026-01-07 10:58 ` Jonathan Cameron
2026-01-08 9:54 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 12/36] KVM: arm64: gic-v5: Add emulation for ICC_IAFFIDR_EL1 accesses Sascha Bischoff
2026-01-07 11:10 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 14/36] KVM: arm64: gic-v5: Add vgic-v5 save/restore hyp interface Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 13/36] KVM: arm64: gic: Set vgic_model before initing private IRQs Sascha Bischoff
2026-01-07 11:24 ` Jonathan Cameron
2026-01-08 13:39 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 15/36] KVM: arm64: gic-v5: Implement GICv5 load/put and save/restore Sascha Bischoff
2026-01-07 12:28 ` Jonathan Cameron
2026-01-08 13:40 ` Sascha Bischoff
2026-01-08 16:52 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 16/36] KVM: arm64: gic-v5: Implement direct injection of PPIs Sascha Bischoff
2026-01-07 12:16 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 17/36] KVM: arm64: gic: Introduce irq_queue and set_pending_state to irq_ops Sascha Bischoff
2026-01-07 12:22 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 18/36] KVM: arm64: gic-v5: Implement PPI interrupt injection Sascha Bischoff
2026-01-06 16:06 ` Joey Gouly
2026-01-06 18:04 ` Sascha Bischoff
2026-01-07 12:50 ` Jonathan Cameron
2026-01-08 14:43 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 20/36] KVM: arm64: gic-v5: Init Private IRQs (PPIs) for GICv5 Sascha Bischoff
2026-01-07 15:04 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 19/36] KVM: arm64: gic-v5: Check for pending PPIs Sascha Bischoff
2026-01-07 15:00 ` Jonathan Cameron
2026-01-08 16:23 ` Sascha Bischoff
2026-01-08 16:57 ` Jonathan Cameron
2026-01-08 16:10 ` Joey Gouly
2026-01-08 16:21 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 23/36] KVM: arm64: gic-v5: Support GICv5 interrupts with KVM_IRQ_LINE Sascha Bischoff
2026-01-07 15:29 ` Jonathan Cameron
2026-01-08 16:53 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 22/36] KVM: arm64: gic-v5: Trap and mask guest PPI register accesses Sascha Bischoff
2026-01-07 15:17 ` Jonathan Cameron
2026-01-09 16:59 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 21/36] KVM: arm64: gic-v5: Finalize GICv5 PPIs and generate mask Sascha Bischoff
2026-01-07 15:08 ` Jonathan Cameron
2026-01-08 16:51 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 24/36] KVM: arm64: gic-v5: Create, init vgic_v5 Sascha Bischoff
2026-01-07 15:49 ` Jonathan Cameron
2026-01-08 16:55 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 25/36] KVM: arm64: gic-v5: Reset vcpu state Sascha Bischoff
2026-01-07 15:51 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 28/36] KVM: arm64: gic: Hide GICv5 for protected guests Sascha Bischoff
2026-01-07 16:12 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 27/36] KVM: arm64: gic-v5: Mandate architected PPI for PMU emulation on GICv5 Sascha Bischoff
2026-01-06 15:06 ` Joey Gouly
2026-01-07 9:48 ` Sascha Bischoff
2026-01-07 16:11 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 26/36] KVM: arm64: gic-v5: Bump arch timer for GICv5 Sascha Bischoff
2026-01-07 16:08 ` Jonathan Cameron
2026-01-09 16:56 ` Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 29/36] KVM: arm64: gic-v5: Hide FEAT_GCIE from NV GICv5 guests Sascha Bischoff
2026-01-07 16:13 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 31/36] KVM: arm64: gic-v5: Set ICH_VCTLR_EL2.En on boot Sascha Bischoff
2025-12-19 15:52 ` [PATCH v2 30/36] KVM: arm64: gic-v5: Introduce kvm_arm_vgic_v5_ops and register them Sascha Bischoff
2026-01-07 16:19 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 34/36] Documentation: KVM: Introduce documentation for VGICv5 Sascha Bischoff
2026-01-07 16:27 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 33/36] KVM: arm64: gic-v5: Probe for GICv5 device Sascha Bischoff
2026-01-07 16:25 ` Jonathan Cameron
2026-01-09 15:00 ` Joey Gouly
2025-12-19 15:52 ` [PATCH v2 32/36] irqchip/gic-v5: Check if impl is virt capable Sascha Bischoff
2026-01-07 16:21 ` Jonathan Cameron
2025-12-19 15:52 ` [PATCH v2 35/36] KVM: arm64: selftests: Introduce a minimal GICv5 PPI selftest Sascha Bischoff
2026-01-07 16:38 ` Jonathan Cameron [this message]
2025-12-19 15:52 ` [PATCH v2 36/36] KVM: arm64: gic-v5: Communicate userspace-drivable PPIs via a UAPI Sascha Bischoff
2026-01-07 16:51 ` Jonathan Cameron
2026-01-09 17:00 ` Sascha Bischoff
2025-12-19 16:17 ` [PATCH v2 00/36] KVM: arm64: Introduce vGIC-v5 with PPI support Sascha Bischoff
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=20260107163847.00000fe9@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=Joey.Gouly@arm.com \
--cc=Sascha.Bischoff@arm.com \
--cc=Suzuki.Poulose@arm.com \
--cc=Timothy.Hayes@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=lpieralisi@kernel.org \
--cc=maz@kernel.org \
--cc=nd@arm.com \
--cc=oliver.upton@linux.dev \
--cc=peter.maydell@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.