Skip to contentSkip to conversation

kvm: selftests: aarch64: dirty_log_test: fix unaligned memslot size

PATCH Applied Andrew Jones 3 participants 6 messages May 23, 2019 – May 24, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: selftests: aarch64: dirty_log_test: fix unaligned memslot size

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
index f50a15c38f9b..bf85afbf1b5f 100644
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;
 	host_page_size = getpagesize();
 	host_num_pages = (guest_num_pages * guest_page_size) / host_page_size +
 			 !!((guest_num_pages * guest_page_size) % host_page_size);
Signature · 1 line
2.18.1
#1 lore raw
Quoted 23 lines · Andrew Jones

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +0 -0
index f50a15c38f9b..bf85afbf1b5f 100644

tools/testing/selftests/kvm/dirty_log_test.c static void run_test(enum vm_guest_mode mode, unsigned long iterations, · line 295

Quoted 5 lines
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;

Hi, Drew,

Could you help explain what's the error on ARM? Since I still cannot understand how it failed from the first glance...

Also, even if we want to have the alignment, shall we do the math using known host/guest page size rather than another adhoc number or could it still break with some other combinations of host/guest page sizes?

Thanks,

Signature · 1 line
Peter Xu
#2 lore raw
Quoted 32 lines · Peter Xu
Quoted 23 lines · Andrew Jones

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +0 -0
index f50a15c38f9b..bf85afbf1b5f 100644

tools/testing/selftests/kvm/dirty_log_test.c static void run_test(enum vm_guest_mode mode, unsigned long iterations, · line 295

Quoted 5 lines
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;

Hi, Drew,

Quoted 2 lines

Could you help explain what's the error on ARM? Since I still cannot understand how it failed from the first glance...

The KVM_SET_USER_MEMORY_REGION ioctl will fail because of

    if (mem->memory_size & (PAGE_SIZE - 1))
            goto out;

in __kvm_set_memory_region(). And that's because PAGE_SIZE == 64k on the host (kvm), but we're attempting to allocate a size of 3*4k.

Quoted 5 lines

Also, even if we want to have the alignment, shall we do the math using known host/guest page size rather than another adhoc number or could it still break with some other combinations of host/guest page sizes?

I don't think we need to worry too much about > 64k pages being a thing any time soon and I'd rather not change the number of pages allocated based on the page sizes, so other than maybe doing something like

/*
* Comment stating why we have this.
*/
#define GUEST_EXTRA_PAGES 16

then I think we're already fine.

Thanks,
drew

#3 lore raw
Quoted 36 lines · Andrew Jones
Quoted 32 lines · Peter Xu
Quoted 23 lines · Andrew Jones

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +0 -0
index f50a15c38f9b..bf85afbf1b5f 100644

tools/testing/selftests/kvm/dirty_log_test.c static void run_test(enum vm_guest_mode mode, unsigned long iterations, · line 295

Quoted 5 lines
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;

Hi, Drew,

Quoted 2 lines

Could you help explain what's the error on ARM? Since I still cannot understand how it failed from the first glance...

Quoted 7 lines

The KVM_SET_USER_MEMORY_REGION ioctl will fail because of

    if (mem->memory_size & (PAGE_SIZE - 1))
            goto out;

in __kvm_set_memory_region(). And that's because PAGE_SIZE == 64k on the host (kvm), but we're attempting to allocate a size of 3*4k.

Oops yes. I merely forgot we've got two memory regions for the test, sorry.

Quoted 12 lines
Quoted 6 lines

Also, even if we want to have the alignment, shall we do the math using known host/guest page size rather than another adhoc number or could it still break with some other combinations of host/guest page sizes?

I don't think we need to worry too much about > 64k pages being a thing any time soon and I'd rather not change the number of pages allocated based on the page sizes, so other than maybe doing something like

Quoted 6 lines

/*
* Comment stating why we have this.
*/
#define GUEST_EXTRA_PAGES 16

then I think we're already fine.

IMHO it would be as simple as replacing 3 with "3 * host_size / guest_size", but both work for me.

Thanks,

Signature · 1 line
Peter Xu
#4 lore raw
Quoted 65 lines · Peter Xu
Quoted 36 lines · Andrew Jones
Quoted 32 lines · Peter Xu
Quoted 23 lines · Andrew Jones

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +0 -0
index f50a15c38f9b..bf85afbf1b5f 100644

tools/testing/selftests/kvm/dirty_log_test.c static void run_test(enum vm_guest_mode mode, unsigned long iterations, · line 295

Quoted 5 lines
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;

Hi, Drew,

Quoted 2 lines

Could you help explain what's the error on ARM? Since I still cannot understand how it failed from the first glance...

Quoted 7 lines

The KVM_SET_USER_MEMORY_REGION ioctl will fail because of

    if (mem->memory_size & (PAGE_SIZE - 1))
            goto out;

in __kvm_set_memory_region(). And that's because PAGE_SIZE == 64k on the host (kvm), but we're attempting to allocate a size of 3*4k.

Oops yes. I merely forgot we've got two memory regions for the test, sorry.

Quoted 17 lines
Quoted 6 lines

Also, even if we want to have the alignment, shall we do the math using known host/guest page size rather than another adhoc number or could it still break with some other combinations of host/guest page sizes?

I don't think we need to worry too much about > 64k pages being a thing any time soon and I'd rather not change the number of pages allocated based on the page sizes, so other than maybe doing something like

/*
* Comment stating why we have this.
*/
#define GUEST_EXTRA_PAGES 16

Quoted 4 lines
Quoted 1 line

then I think we're already fine.

IMHO it would be as simple as replacing 3 with "3 * host_size / guest_size", but both work for me.

As I said, I'd rather not change the number of pages allocated based on the pages sizes. With this you get 3 4k or 64k pages when both host and guest are the same, 48 4k pages when the host is 64 and guest is 4, and when the host has 4k and the guest has 64k, we would get 0, which we don't want.

Thanks,
drew

maintainer Applied
#5 lore raw
In reply to Andrew Jones
Quoted 9 lines · Andrew Jones

The memory slot size must be aligned to the host's page size. When testing a guest with a 4k page size on a host with a 64k page size, then 3 guest pages are not host page size aligned. Since we just need a nearly arbitrary number of extra pages to ensure the memslot is not aligned to a 64 host-page boundary for this test, then we can use 16, as that's 64k aligned, but not 64 * 64k aligned.

Fixes 76d58e0f07ec ("KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size", 2019-04-17)

Queued, thanks.

Paolo

Quoted 22 lines

---
Note, the commit "KVM: fix KVM_CLEAR_DIRTY_LOG for memory slots of unaligned size" was somehow committed twice. 76d58e0f07ec is the first instance.

 tools/testing/selftests/kvm/dirty_log_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/dirty_log_test.c +1 -1
index f50a15c38f9b..bf85afbf1b5f 100644
@@ -292,7 +292,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	 * A little more than 1G of guest page sized pages.  Cover the
 	 * case where the size is not aligned to 64 pages.
 	 */
-	guest_num_pages = (1ul << (30 - guest_page_shift)) + 3;
+	guest_num_pages = (1ul << (30 - guest_page_shift)) + 16;
 	host_page_size = getpagesize();
 	host_num_pages = (guest_num_pages * guest_page_size) / host_page_size +
 			 !!((guest_num_pages * guest_page_size) % host_page_size);