diff mbox series

[2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1

Message ID 20231007124043.626-2-yuzenghui@huawei.com (mailing list archive)
State New, archived
Headers show
Series [1/2] KVM: arm64: selftest: Add the missing .guest_prepare() | expand

Commit Message

Zenghui Yu Oct. 7, 2023, 12:40 p.m. UTC
It looks like a mistake to issue ISB *after* reading PAR_EL1, we should
instead perform it between the AT instruction and the reads of PAR_EL1.

As according to DDI0487J.a IJTYVP,

"When an address translation instruction is executed, explicit
 synchronization is required to guarantee the result is visible to
 subsequent direct reads of PAR_EL1."

Otherwise all guest_at testcases fail on my box with

==== Test Assertion Failure ====
  aarch64/page_fault_test.c:142: par & 1 == 0
  pid=1355864 tid=1355864 errno=4 - Interrupted system call
     1	0x0000000000402853: vcpu_run_loop at page_fault_test.c:681
     2	0x0000000000402cdb: run_test at page_fault_test.c:730
     3	0x0000000000403897: for_each_guest_mode at guest_modes.c:100
     4	0x00000000004019f3: for_each_test_and_guest_mode at page_fault_test.c:1105
     5	 (inlined by) main at page_fault_test.c:1131
     6	0x0000ffffb153c03b: ?? ??:0
     7	0x0000ffffb153c113: ?? ??:0
     8	0x0000000000401aaf: _start at ??:?
  0x1 != 0x0 (par & 1 != 0)

Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
---
 tools/testing/selftests/kvm/aarch64/page_fault_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marc Zyngier Oct. 7, 2023, 4:06 p.m. UTC | #1
On Sat, 07 Oct 2023 13:40:43 +0100,
Zenghui Yu <yuzenghui@huawei.com> wrote:
> 
> It looks like a mistake to issue ISB *after* reading PAR_EL1, we should
> instead perform it between the AT instruction and the reads of PAR_EL1.
> 
> As according to DDI0487J.a IJTYVP,
> 
> "When an address translation instruction is executed, explicit
>  synchronization is required to guarantee the result is visible to
>  subsequent direct reads of PAR_EL1."
> 
> Otherwise all guest_at testcases fail on my box with
> 
> ==== Test Assertion Failure ====
>   aarch64/page_fault_test.c:142: par & 1 == 0
>   pid=1355864 tid=1355864 errno=4 - Interrupted system call
>      1	0x0000000000402853: vcpu_run_loop at page_fault_test.c:681
>      2	0x0000000000402cdb: run_test at page_fault_test.c:730
>      3	0x0000000000403897: for_each_guest_mode at guest_modes.c:100
>      4	0x00000000004019f3: for_each_test_and_guest_mode at page_fault_test.c:1105
>      5	 (inlined by) main at page_fault_test.c:1131
>      6	0x0000ffffb153c03b: ?? ??:0
>      7	0x0000ffffb153c113: ?? ??:0
>      8	0x0000000000401aaf: _start at ??:?
>   0x1 != 0x0 (par & 1 != 0)
> 
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>

Acked-by: Marc Zyngier <maz@kernel.org>

	M.
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
index eb5ead50c0b1..9a3be80e8bc9 100644
--- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c
+++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
@@ -135,8 +135,8 @@  static void guest_at(void)
 	uint64_t par;
 
 	asm volatile("at s1e1r, %0" :: "r" (guest_test_memory));
-	par = read_sysreg(par_el1);
 	isb();
+	par = read_sysreg(par_el1);
 
 	/* Bit 1 indicates whether the AT was successful */
 	GUEST_ASSERT_EQ(par & 1, 0);