linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare()
@ 2023-10-07 12:40 Zenghui Yu
  2023-10-07 12:40 ` [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1 Zenghui Yu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zenghui Yu @ 2023-10-07 12:40 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel
  Cc: maz, oliver.upton, james.morse, suzuki.poulose, ricarkol,
	wanghaibin.wang, Zenghui Yu

Running page_fault_test on a Cortex A72 fails with

Test: ro_memslot_no_syndrome_guest_cas
Testing guest mode: PA-bits:40,  VA-bits:48,  4K pages
Testing memory backing src type: anonymous
==== Test Assertion Failure ====
  aarch64/page_fault_test.c:117: guest_check_lse()
  pid=1944087 tid=1944087 errno=4 - Interrupted system call
     1	0x00000000004028b3: vcpu_run_loop at page_fault_test.c:682
     2	0x0000000000402d93: run_test at page_fault_test.c:731
     3	0x0000000000403957: for_each_guest_mode at guest_modes.c:100
     4	0x00000000004019f3: for_each_test_and_guest_mode at page_fault_test.c:1108
     5	 (inlined by) main at page_fault_test.c:1134
     6	0x0000ffff868e503b: ?? ??:0
     7	0x0000ffff868e5113: ?? ??:0
     8	0x0000000000401aaf: _start at ??:?
  guest_check_lse()

because we don't have a guest_prepare stage to check the presence of
FEAT_LSE and skip the related guest_cas testing, and we end-up failing in
GUEST_ASSERT(guest_check_lse()).

Add the missing .guest_prepare() where it's indeed required.

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

diff --git a/tools/testing/selftests/kvm/aarch64/page_fault_test.c b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
index 47bb914ab2fa..eb5ead50c0b1 100644
--- a/tools/testing/selftests/kvm/aarch64/page_fault_test.c
+++ b/tools/testing/selftests/kvm/aarch64/page_fault_test.c
@@ -842,6 +842,7 @@ static void help(char *name)
 	.name			= SCAT2(ro_memslot_no_syndrome, _access),	\
 	.data_memslot_flags	= KVM_MEM_READONLY,				\
 	.pt_memslot_flags	= KVM_MEM_READONLY,				\
+	.guest_prepare		= { _PREPARE(_access) },			\
 	.guest_test		= _access,					\
 	.fail_vcpu_run_handler	= fail_vcpu_run_mmio_no_syndrome_handler,	\
 	.expected_events	= { .fail_vcpu_runs = 1 },			\
@@ -865,6 +866,7 @@ static void help(char *name)
 	.name			= SCAT2(ro_memslot_no_syn_and_dlog, _access),	\
 	.data_memslot_flags	= KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES,	\
 	.pt_memslot_flags	= KVM_MEM_READONLY | KVM_MEM_LOG_DIRTY_PAGES,	\
+	.guest_prepare		= { _PREPARE(_access) },			\
 	.guest_test		= _access,					\
 	.guest_test_check	= { _test_check },				\
 	.fail_vcpu_run_handler	= fail_vcpu_run_mmio_no_syndrome_handler,	\
@@ -894,6 +896,7 @@ static void help(char *name)
 	.data_memslot_flags	= KVM_MEM_READONLY,				\
 	.pt_memslot_flags	= KVM_MEM_READONLY,				\
 	.mem_mark_cmd		= CMD_HOLE_DATA | CMD_HOLE_PT,			\
+	.guest_prepare		= { _PREPARE(_access) },			\
 	.guest_test		= _access,					\
 	.uffd_data_handler	= _uffd_data_handler,				\
 	.uffd_pt_handler	= uffd_pt_handler,			\
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1
  2023-10-07 12:40 [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Zenghui Yu
@ 2023-10-07 12:40 ` Zenghui Yu
  2023-10-07 16:06   ` Marc Zyngier
  2023-10-07 16:05 ` [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Marc Zyngier
  2023-10-07 16:50 ` Oliver Upton
  2 siblings, 1 reply; 5+ messages in thread
From: Zenghui Yu @ 2023-10-07 12:40 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel
  Cc: maz, oliver.upton, james.morse, suzuki.poulose, ricarkol,
	wanghaibin.wang, Zenghui Yu

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(-)

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);
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare()
  2023-10-07 12:40 [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Zenghui Yu
  2023-10-07 12:40 ` [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1 Zenghui Yu
@ 2023-10-07 16:05 ` Marc Zyngier
  2023-10-07 16:50 ` Oliver Upton
  2 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2023-10-07 16:05 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: kvmarm, linux-arm-kernel, oliver.upton, james.morse,
	suzuki.poulose, ricarkol, wanghaibin.wang

On Sat, 07 Oct 2023 13:40:42 +0100,
Zenghui Yu <yuzenghui@huawei.com> wrote:
> 
> Running page_fault_test on a Cortex A72 fails with
> 
> Test: ro_memslot_no_syndrome_guest_cas
> Testing guest mode: PA-bits:40,  VA-bits:48,  4K pages
> Testing memory backing src type: anonymous
> ==== Test Assertion Failure ====
>   aarch64/page_fault_test.c:117: guest_check_lse()
>   pid=1944087 tid=1944087 errno=4 - Interrupted system call
>      1	0x00000000004028b3: vcpu_run_loop at page_fault_test.c:682
>      2	0x0000000000402d93: run_test at page_fault_test.c:731
>      3	0x0000000000403957: for_each_guest_mode at guest_modes.c:100
>      4	0x00000000004019f3: for_each_test_and_guest_mode at page_fault_test.c:1108
>      5	 (inlined by) main at page_fault_test.c:1134
>      6	0x0000ffff868e503b: ?? ??:0
>      7	0x0000ffff868e5113: ?? ??:0
>      8	0x0000000000401aaf: _start at ??:?
>   guest_check_lse()
> 
> because we don't have a guest_prepare stage to check the presence of
> FEAT_LSE and skip the related guest_cas testing, and we end-up failing in
> GUEST_ASSERT(guest_check_lse()).
> 
> Add the missing .guest_prepare() where it's indeed required.
> 
> Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>

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

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1
  2023-10-07 12:40 ` [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1 Zenghui Yu
@ 2023-10-07 16:06   ` Marc Zyngier
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Zyngier @ 2023-10-07 16:06 UTC (permalink / raw)
  To: Zenghui Yu
  Cc: kvmarm, linux-arm-kernel, oliver.upton, james.morse,
	suzuki.poulose, ricarkol, wanghaibin.wang

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.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare()
  2023-10-07 12:40 [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Zenghui Yu
  2023-10-07 12:40 ` [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1 Zenghui Yu
  2023-10-07 16:05 ` [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Marc Zyngier
@ 2023-10-07 16:50 ` Oliver Upton
  2 siblings, 0 replies; 5+ messages in thread
From: Oliver Upton @ 2023-10-07 16:50 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, Zenghui Yu
  Cc: Oliver Upton, james.morse, wanghaibin.wang, maz, ricarkol,
	suzuki.poulose

On Sat, 7 Oct 2023 20:40:42 +0800, Zenghui Yu wrote:
> Running page_fault_test on a Cortex A72 fails with
> 
> Test: ro_memslot_no_syndrome_guest_cas
> Testing guest mode: PA-bits:40,  VA-bits:48,  4K pages
> Testing memory backing src type: anonymous
> ==== Test Assertion Failure ====
>   aarch64/page_fault_test.c:117: guest_check_lse()
>   pid=1944087 tid=1944087 errno=4 - Interrupted system call
>      1	0x00000000004028b3: vcpu_run_loop at page_fault_test.c:682
>      2	0x0000000000402d93: run_test at page_fault_test.c:731
>      3	0x0000000000403957: for_each_guest_mode at guest_modes.c:100
>      4	0x00000000004019f3: for_each_test_and_guest_mode at page_fault_test.c:1108
>      5	 (inlined by) main at page_fault_test.c:1134
>      6	0x0000ffff868e503b: ?? ??:0
>      7	0x0000ffff868e5113: ?? ??:0
>      8	0x0000000000401aaf: _start at ??:?
>   guest_check_lse()
> 
> [...]

Applied to kvmarm/next, thanks!

[1/2] KVM: arm64: selftest: Add the missing .guest_prepare()
      https://git.kernel.org/kvmarm/kvmarm/c/45c9683d5ce1
[2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1
      https://git.kernel.org/kvmarm/kvmarm/c/a9c9864f3c2f

--
Best,
Oliver

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-07 16:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-07 12:40 [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Zenghui Yu
2023-10-07 12:40 ` [PATCH 2/2] KVM: arm64: selftest: Perform ISB before reading PAR_EL1 Zenghui Yu
2023-10-07 16:06   ` Marc Zyngier
2023-10-07 16:05 ` [PATCH 1/2] KVM: arm64: selftest: Add the missing .guest_prepare() Marc Zyngier
2023-10-07 16:50 ` Oliver Upton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).