Skip to content

Commit a24f7af

Browse files
Maximilian DittgenMarc Zyngier
authored andcommitted
KVM: selftests: fix MAPC RDbase target formatting in vgic_lpi_stress
Since GITS_TYPER.PTA == 0, the ITS MAPC command demands a CPU ID, rather than a physical redistributor address, for its RDbase command argument. As such, when MAPC-ing guest ITS collections, vgic_lpi_stress iterates over CPU IDs in the range [0, nr_cpus), passing them as the RDbase vcpu_id argument to its_send_mapc_cmd(). However, its_encode_target() in the its_send_mapc_cmd() selftest handler expects RDbase arguments to be formatted with a 16 bit offset, as shown by the 16-bit target_addr right shift its implementation: its_mask_encode(&cmd->raw_cmd[2], target_addr >> 16, 51, 16) At the moment, all CPU IDs passed into its_send_mapc_cmd() have no offset, therefore becoming 0x0 after the bit shift. Thus, when vgic_its_cmd_handle_mapc() receives the ITS command in vgic-its.c, it always interprets the RDbase target CPU as CPU 0. All interrupts sent to collections will be processed by vCPU 0, which defeats the purpose of this multi-vCPU test. Fix by creating procnum_to_rdbase() helper function, which left-shifts the vCPU parameter received by its_send_mapc_cmd 16 bits before passing it to its_encode_target for encoding. Signed-off-by: Maximilian Dittgen <mdittgen@amazon.de> Link: https://patch.msgid.link/20251020145946.48288-1-mdittgen@amazon.de Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent da88852 commit a24f7af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/testing/selftests/kvm/lib/arm64/gic_v3_its.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "gic_v3.h"
1616
#include "processor.h"
1717

18+
#define GITS_COLLECTION_TARGET_SHIFT 16
19+
1820
static u64 its_read_u64(unsigned long offset)
1921
{
2022
return readq_relaxed(GITS_BASE_GVA + offset);
@@ -163,6 +165,11 @@ static void its_encode_collection(struct its_cmd_block *cmd, u16 col)
163165
its_mask_encode(&cmd->raw_cmd[2], col, 15, 0);
164166
}
165167

168+
static u64 procnum_to_rdbase(u32 vcpu_id)
169+
{
170+
return vcpu_id << GITS_COLLECTION_TARGET_SHIFT;
171+
}
172+
166173
#define GITS_CMDQ_POLL_ITERATIONS 0
167174

168175
static void its_send_cmd(void *cmdq_base, struct its_cmd_block *cmd)
@@ -217,7 +224,7 @@ void its_send_mapc_cmd(void *cmdq_base, u32 vcpu_id, u32 collection_id, bool val
217224

218225
its_encode_cmd(&cmd, GITS_CMD_MAPC);
219226
its_encode_collection(&cmd, collection_id);
220-
its_encode_target(&cmd, vcpu_id);
227+
its_encode_target(&cmd, procnum_to_rdbase(vcpu_id));
221228
its_encode_valid(&cmd, valid);
222229

223230
its_send_cmd(cmdq_base, &cmd);

0 commit comments

Comments
 (0)