From: Jia He <justin.he@arm.com>
To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Thomas Gleixner <tglx@kernel.org>
Cc: nd@arm.com, Jia He <justin.he@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Fuad Tabba <fuad.tabba@linux.dev>,
Steffen Eiden <seiden@linux.ibm.com>,
Radu Rendec <radu@rendec.net>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <shuah@kernel.org>,
Ricardo Koller <ricarkol@google.com>,
Andrew Jones <andrew.jones@linux.dev>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 08/10] KVM: arm64: selftests: Avoid read-modify-write for GIC write-one registers
Date: Sun, 6 Dec 2026 13:53:52 +0000 [thread overview]
Message-ID: <20261206135354.1519499-9-justin.he@arm.com> (raw)
In-Reply-To: <20261206135354.1519499-1-justin.he@arm.com>
The GICv3 field accessor in the selftest library does a
read-modify-write, which breaks write-one-to-set and write-one-to-clear
registers. For example, disabling SGI1 while SGI2 is enabled reads both
bits from ICENABLER0 and writes both back, disabling SGI2 as well.
Write only the requested bits for enable, pending, and active set/clear
registers, keeping read-modify-write for priority and trigger
configuration. Check the base register offset before adding the
per-INTID offset so SPI registers are covered too.
Fixes: 745068367ccb ("KVM: selftests: aarch64: Add function for accessing GICv3 dist and redist registers")
Signed-off-by: Jia He <justin.he@arm.com>
---
tools/testing/selftests/kvm/lib/arm64/gic_v3.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/lib/arm64/gic_v3.c b/tools/testing/selftests/kvm/lib/arm64/gic_v3.c
index a99a53accfe9..fc9d2a354748 100644
--- a/tools/testing/selftests/kvm/lib/arm64/gic_v3.c
+++ b/tools/testing/selftests/kvm/lib/arm64/gic_v3.c
@@ -173,6 +173,7 @@ static void gicv3_access_reg(u32 intid, u64 offset,
enum gicv3_intid_range intid_range = get_intid_range(intid);
u32 fields_per_reg, index, mask, shift;
u32 cpu_or_dist;
+ bool write_one;
GUEST_ASSERT(bits_per_field <= reg_bits);
GUEST_ASSERT(!write || *val < (1U << bits_per_field));
@@ -182,6 +183,11 @@ static void gicv3_access_reg(u32 intid, u64 offset,
*/
GUEST_ASSERT(reg_bits == 32);
+ /* Writing back the other bits of a W1S/W1C register would change them */
+ write_one = offset == GICD_ISENABLER || offset == GICD_ICENABLER ||
+ offset == GICD_ISPENDR || offset == GICD_ICPENDR ||
+ offset == GICD_ISACTIVER || offset == GICD_ICACTIVER;
+
fields_per_reg = reg_bits / bits_per_field;
index = intid % fields_per_reg;
shift = index * bits_per_field;
@@ -192,8 +198,12 @@ static void gicv3_access_reg(u32 intid, u64 offset,
cpu_or_dist = (intid_range == SPI_RANGE) ? DIST_BIT : cpu;
- if (write)
- gicv3_setl_fields(cpu_or_dist, offset, mask, *val << shift);
+ if (write) {
+ if (write_one)
+ gicv3_reg_writel(cpu_or_dist, offset, *val << shift);
+ else
+ gicv3_setl_fields(cpu_or_dist, offset, mask, *val << shift);
+ }
*val = gicv3_getl_fields(cpu_or_dist, offset, mask) >> shift;
}
--
2.34.1
next prev parent reply other threads:[~2026-12-06 13:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 13:53 [PATCH 00/10] KVM: arm64: GICv4.1 vSGI error handling and VGIC state fixes Jia He
2026-12-06 13:53 ` [PATCH 01/10] KVM: arm64: Preserve vSGI state when pending queries fail Jia He
2026-12-06 13:53 ` [PATCH 02/10] irqchip/gic-v3-its: Propagate vSGI command queue failures Jia He
2026-12-06 13:53 ` [PATCH 03/10] KVM: arm64: Stop vSGI enablement on state transfer errors Jia He
2026-12-06 13:53 ` [PATCH 04/10] KVM: arm64: Check clearing the pending state of vSGIs moved to SW Jia He
2026-12-06 13:53 ` [PATCH 05/10] KVM: arm64: vgic: Queue pending interrupts when the distributor is enabled Jia He
2026-12-06 13:53 ` [PATCH 06/10] KVM: arm64: vgic: Pass the enable state of HW SGIs to the ITS Jia He
2026-12-06 13:53 ` [PATCH 07/10] KVM: arm64: Synchronize vSGI state when restoring GICD_CTLR Jia He
2026-12-06 13:53 ` Jia He [this message]
2026-12-06 13:53 ` [PATCH 09/10] KVM: arm64: selftests: Add vgic_dist_reenable test Jia He
2026-12-06 13:53 ` [PATCH 10/10] KVM: arm64: selftests: Check SGI delivery after VGIC restore Jia He
2026-12-06 16:51 ` [PATCH 00/10] KVM: arm64: GICv4.1 vSGI error handling and VGIC state fixes 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=20261206135354.1519499-9-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=andrew.jones@linux.dev \
--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=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=nd@arm.com \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=radu@rendec.net \
--cc=ricarkol@google.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tglx@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®