From: Marc Zyngier <maz@kernel.org>
To: Oliver Upton <oliver.upton@linux.dev>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, James Morse <james.morse@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Alexander Potapenko <glider@google.com>
Subject: Re: [PATCH 12/12] KVM: arm64: Add selftest checking how the absence of GICv3 is handled
Date: Wed, 21 Aug 2024 12:17:10 +0100 [thread overview]
Message-ID: <86frqyxgzt.wl-maz@kernel.org> (raw)
In-Reply-To: <ZsUwb2pEUNQt2arR@linux.dev>
On Wed, 21 Aug 2024 01:10:23 +0100,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> On Tue, Aug 20, 2024 at 11:03:49AM +0100, Marc Zyngier wrote:
> > Given how tortuous and fragile the whole lack-of-GICv3 story is,
> > add a selftest checking that we don't regress it.
> >
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > tools/testing/selftests/kvm/Makefile | 1 +
> > .../selftests/kvm/aarch64/no-vgic-v3.c | 170 ++++++++++++++++++
> > 2 files changed, 171 insertions(+)
> > create mode 100644 tools/testing/selftests/kvm/aarch64/no-vgic-v3.c
> >
> > diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
> > index 48d32c5aa3eb..f66b37acc0b0 100644
> > --- a/tools/testing/selftests/kvm/Makefile
> > +++ b/tools/testing/selftests/kvm/Makefile
> > @@ -163,6 +163,7 @@ TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
> > TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq
> > TEST_GEN_PROGS_aarch64 += aarch64/vgic_lpi_stress
> > TEST_GEN_PROGS_aarch64 += aarch64/vpmu_counter_access
> > +TEST_GEN_PROGS_aarch64 += aarch64/no-vgic-v3
> > TEST_GEN_PROGS_aarch64 += access_tracking_perf_test
> > TEST_GEN_PROGS_aarch64 += arch_timer
> > TEST_GEN_PROGS_aarch64 += demand_paging_test
> > diff --git a/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c b/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c
> > new file mode 100644
> > index 000000000000..27169afc94c6
> > --- /dev/null
> > +++ b/tools/testing/selftests/kvm/aarch64/no-vgic-v3.c
> > @@ -0,0 +1,170 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +
> > +// Check that, on a GICv3 system, not configuring GICv3 correctly
> > +// results in all of the sysregs generating an UNDEF exception.
> > +
> > +#include <test_util.h>
> > +#include <kvm_util.h>
> > +#include <processor.h>
> > +
> > +static volatile bool handled;
> > +
> > +#define __check_sr_read(r) \
> > + do { \
> > + uint64_t val; \
> > + \
> > + handled = false; \
> > + dsb(sy); \
> > + val = read_sysreg_s(SYS_ ## r); \
> > + (void)val; \
> > + } while(0)
> > +
> > +#define __check_sr_write(r) \
> > + do { \
> > + handled = false; \
> > + dsb(sy); \
> > + write_sysreg_s(0, SYS_ ## r); \
> > + isb(); \
> > + } while(0)
> > +
> > +/* Fatal checks */
> > +#define check_sr_read(r) \
> > + do { \
> > + __check_sr_read(r); \
> > + __GUEST_ASSERT(handled, #r " no read trap"); \
> > + } while(0)
> > +
> > +#define check_sr_write(r) \
> > + do { \
> > + __check_sr_write(r); \
> > + __GUEST_ASSERT(handled, #r " no write trap"); \
> > + } while(0)
> > +
> > +#define check_sr_rw(r) \
> > + do { \
> > + check_sr_read(r); \
> > + check_sr_write(r); \
> > + } while(0)
> > +
> > +/* Non-fatal checks */
> > +#define check_sr_read_maybe(r) \
> > + do { \
> > + __check_sr_read(r); \
> > + if (!handled) \
> > + GUEST_PRINTF(#r " read not trapping (OK)\n"); \
> > + } while(0)
> > +
> > +#define check_sr_write_maybe(r) \
> > + do { \
> > + __check_sr_write(r); \
> > + if (!handled) \
> > + GUEST_PRINTF(#r " write not trapping (OK)\n"); \
> > + } while(0)
> > +
> > +static void guest_code(void)
> > +{
> > + /*
> > + * Check that we advertise that ID_AA64PFR0_EL1.GIC == 0, having
> > + * hidden the feature at runtime without any other userspace action.
> > + */
> > + __GUEST_ASSERT(FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_GIC),
> > + read_sysreg(id_aa64pfr0_el1)) == 0,
> > + "GICv3 wrongly advertised");
> > +
> > + /*
> > + * Access all GICv3 registers, and fail if we don't get an UNDEF.
> > + * Note that we happily access all the APxRn registers without
> > + * checking their existance, as all we want to see is a failure.
> > + */
> > + check_sr_rw(ICC_PMR_EL1);
> > + check_sr_read(ICC_IAR0_EL1);
> > + check_sr_write(ICC_EOIR0_EL1);
> > + check_sr_rw(ICC_HPPIR0_EL1);
> > + check_sr_rw(ICC_BPR0_EL1);
> > + check_sr_rw(ICC_AP0R0_EL1);
> > + check_sr_rw(ICC_AP0R1_EL1);
> > + check_sr_rw(ICC_AP0R2_EL1);
> > + check_sr_rw(ICC_AP0R3_EL1);
> > + check_sr_rw(ICC_AP1R0_EL1);
> > + check_sr_rw(ICC_AP1R1_EL1);
> > + check_sr_rw(ICC_AP1R2_EL1);
> > + check_sr_rw(ICC_AP1R3_EL1);
> > + check_sr_write(ICC_DIR_EL1);
> > + check_sr_read(ICC_RPR_EL1);
> > + check_sr_write(ICC_SGI1R_EL1);
> > + check_sr_write(ICC_ASGI1R_EL1);
> > + check_sr_write(ICC_SGI0R_EL1);
> > + check_sr_read(ICC_IAR1_EL1);
> > + check_sr_write(ICC_EOIR1_EL1);
> > + check_sr_rw(ICC_HPPIR1_EL1);
> > + check_sr_rw(ICC_BPR1_EL1);
> > + check_sr_rw(ICC_CTLR_EL1);
> > + check_sr_rw(ICC_IGRPEN0_EL1);
> > + check_sr_rw(ICC_IGRPEN1_EL1);
> > +
> > + /*
> > + * ICC_SRE_EL1 may not be trappable, as ICC_SRE_EL2.Enable can
> > + * be RAO/WI
> > + */
> > + check_sr_read_maybe(ICC_SRE_EL1);
> > + check_sr_write_maybe(ICC_SRE_EL1);
>
> In the case that a write does not UNDEF, should we check that
> ICC_SRE_EL1.SRE is also RAO/WI?
Ah, not a bad idea. I'll add that.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
prev parent reply other threads:[~2024-08-21 11:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 10:03 [PATCH 00/12] KVM: arm64: Handle the lack of GICv3 exposed to a guest Marc Zyngier
2024-08-20 10:03 ` [PATCH 01/12] KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3 Marc Zyngier
2024-08-20 21:46 ` Oliver Upton
2024-08-21 10:59 ` Marc Zyngier
2024-08-21 16:53 ` Oliver Upton
2024-08-22 8:15 ` (subset) " Oliver Upton
2024-08-20 10:03 ` [PATCH 02/12] KVM: arm64: Move GICv3 trap configuration to kvm_calculate_traps() Marc Zyngier
2024-08-20 10:03 ` [PATCH 03/12] KVM: arm64: Force SRE traps when SRE access is not enabled Marc Zyngier
2024-08-20 23:19 ` Oliver Upton
2024-08-21 11:05 ` Marc Zyngier
2024-08-20 10:03 ` [PATCH 04/12] KVM: arm64: Force GICv3 traps activa when no irqchip is configured on VHE Marc Zyngier
2024-08-20 23:33 ` Oliver Upton
2024-08-21 11:13 ` Marc Zyngier
2024-08-21 16:52 ` Oliver Upton
2024-08-20 10:03 ` [PATCH 05/12] KVM: arm64: Add helper for last ditch idreg adjustments Marc Zyngier
2024-08-20 10:03 ` [PATCH 06/12] KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guest Marc Zyngier
2024-08-20 23:50 ` Oliver Upton
2024-08-21 11:16 ` Marc Zyngier
2024-08-20 10:03 ` [PATCH 07/12] KVM: arm64: Add ICH_HCR_EL2 to the vcpu state Marc Zyngier
2024-08-20 10:03 ` [PATCH 08/12] KVM: arm64: Add trap routing information for ICH_HCR_EL2 Marc Zyngier
2024-08-21 17:03 ` kernel test robot
2024-08-20 10:03 ` [PATCH 09/12] KVM: arm64: Honor guest requested traps in GICv3 emulation Marc Zyngier
2024-08-20 10:03 ` [PATCH 10/12] KVM: arm64: Make most GICv3 accesses UNDEF if they trap Marc Zyngier
2024-08-20 10:03 ` [PATCH 11/12] KVM: arm64: Unify UNDEF injection helpers Marc Zyngier
2024-08-20 10:03 ` [PATCH 12/12] KVM: arm64: Add selftest checking how the absence of GICv3 is handled Marc Zyngier
2024-08-21 0:10 ` Oliver Upton
2024-08-21 11:17 ` Marc Zyngier [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=86frqyxgzt.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=glider@google.com \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--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.