public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms
@ 2023-12-08  3:35 Shaoqin Huang
  2023-12-08  5:07 ` Gavin Shan
  2023-12-08 16:21 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Shaoqin Huang @ 2023-12-08  3:35 UTC (permalink / raw)
  To: kvm
  Cc: Shaoqin Huang, Paolo Bonzini, Shuah Khan, Sean Christopherson,
	linux-kselftest, linux-kernel

When running the set_memory_region_test on arm64 platform, it causes the
below assert:

==== Test Assertion Failure ====
  set_memory_region_test.c:355: r && errno == EINVAL
  pid=40695 tid=40695 errno=0 - Success
     1	0x0000000000401baf: test_invalid_memory_region_flags at set_memory_region_test.c:355
     2	 (inlined by) main at set_memory_region_test.c:541
     3	0x0000ffff951c879b: ?? ??:0
     4	0x0000ffff951c886b: ?? ??:0
     5	0x0000000000401caf: _start at ??:?
  KVM_SET_USER_MEMORY_REGION should have failed on v2 only flag 0x2

This is because the arm64 platform also support the KVM_MEM_READONLY flag, but
the current implementation add it into the supportd_flags only on x86_64
platform, so this causes assert on other platform which also support the
KVM_MEM_READONLY flag.

Fix it by using the __KVM_HAVE_READONLY_MEM macro to detect if the
current platform support the KVM_MEM_READONLY, thus fix this problem on
all other platform which support KVM_MEM_READONLY.

Fixes: 5d74316466f4 ("KVM: selftests: Add a memory region subtest to validate invalid flags")
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
---
This patch is based on the latest kvm-next[1] branch.

[1] https://git.kernel.org/pub/scm/virt/kvm/kvm.git/log/?h=next
---
 tools/testing/selftests/kvm/set_memory_region_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c
index 6637a0845acf..1ce710fd7a5a 100644
--- a/tools/testing/selftests/kvm/set_memory_region_test.c
+++ b/tools/testing/selftests/kvm/set_memory_region_test.c
@@ -333,9 +333,11 @@ static void test_invalid_memory_region_flags(void)
 	struct kvm_vm *vm;
 	int r, i;
 
-#ifdef __x86_64__
+#ifdef __KVM_HAVE_READONLY_MEM
 	supported_flags |= KVM_MEM_READONLY;
+#endif
 
+#ifdef __x86_64__
 	if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM))
 		vm = vm_create_barebones_protected_vm();
 	else
-- 
2.40.1


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

* Re: [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms
  2023-12-08  3:35 [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms Shaoqin Huang
@ 2023-12-08  5:07 ` Gavin Shan
  2023-12-08 16:21 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Gavin Shan @ 2023-12-08  5:07 UTC (permalink / raw)
  To: Shaoqin Huang, kvm
  Cc: Paolo Bonzini, Shuah Khan, Sean Christopherson, linux-kselftest,
	linux-kernel, kvmarm

On 12/8/23 13:35, Shaoqin Huang wrote:
> When running the set_memory_region_test on arm64 platform, it causes the
> below assert:
> 
> ==== Test Assertion Failure ====
>    set_memory_region_test.c:355: r && errno == EINVAL
>    pid=40695 tid=40695 errno=0 - Success
>       1	0x0000000000401baf: test_invalid_memory_region_flags at set_memory_region_test.c:355
>       2	 (inlined by) main at set_memory_region_test.c:541
>       3	0x0000ffff951c879b: ?? ??:0
>       4	0x0000ffff951c886b: ?? ??:0
>       5	0x0000000000401caf: _start at ??:?
>    KVM_SET_USER_MEMORY_REGION should have failed on v2 only flag 0x2
> 
> This is because the arm64 platform also support the KVM_MEM_READONLY flag, but
> the current implementation add it into the supportd_flags only on x86_64
> platform, so this causes assert on other platform which also support the
> KVM_MEM_READONLY flag.
> 
> Fix it by using the __KVM_HAVE_READONLY_MEM macro to detect if the
> current platform support the KVM_MEM_READONLY, thus fix this problem on
> all other platform which support KVM_MEM_READONLY.
> 
> Fixes: 5d74316466f4 ("KVM: selftests: Add a memory region subtest to validate invalid flags")
> Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
> ---
> This patch is based on the latest kvm-next[1] branch.
> 
> [1] https://git.kernel.org/pub/scm/virt/kvm/kvm.git/log/?h=next
> ---
>   tools/testing/selftests/kvm/set_memory_region_test.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 

Reviewed-by: Gavin Shan <gshan@redhat.com>


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

* Re: [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms
  2023-12-08  3:35 [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms Shaoqin Huang
  2023-12-08  5:07 ` Gavin Shan
@ 2023-12-08 16:21 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2023-12-08 16:21 UTC (permalink / raw)
  To: Shaoqin Huang
  Cc: kvm, Paolo Bonzini, Shuah Khan, linux-kselftest, linux-kernel

On Thu, Dec 07, 2023, Shaoqin Huang wrote:
> When running the set_memory_region_test on arm64 platform, it causes the
> below assert:
> 
> ==== Test Assertion Failure ====
>   set_memory_region_test.c:355: r && errno == EINVAL
>   pid=40695 tid=40695 errno=0 - Success
>      1	0x0000000000401baf: test_invalid_memory_region_flags at set_memory_region_test.c:355
>      2	 (inlined by) main at set_memory_region_test.c:541
>      3	0x0000ffff951c879b: ?? ??:0
>      4	0x0000ffff951c886b: ?? ??:0
>      5	0x0000000000401caf: _start at ??:?
>   KVM_SET_USER_MEMORY_REGION should have failed on v2 only flag 0x2
> 
> This is because the arm64 platform also support the KVM_MEM_READONLY flag, but
> the current implementation add it into the supportd_flags only on x86_64
> platform, so this causes assert on other platform which also support the
> KVM_MEM_READONLY flag.
> 
> Fix it by using the __KVM_HAVE_READONLY_MEM macro to detect if the
> current platform support the KVM_MEM_READONLY, thus fix this problem on
> all other platform which support KVM_MEM_READONLY.
> 
> Fixes: 5d74316466f4 ("KVM: selftests: Add a memory region subtest to validate invalid flags")
> Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
> ---

/facepalm

Reviewed-by: Sean Christopherson <seanjc@google.com>

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

end of thread, other threads:[~2023-12-08 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-08  3:35 [PATCH v1] KVM: selftests: Fix Assertion on non-x86_64 platforms Shaoqin Huang
2023-12-08  5:07 ` Gavin Shan
2023-12-08 16:21 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox