diff mbox series

KVM: selftests: s390x: Provide additional num-guest-pages adjustment

Message ID 20200312104055.8558-1-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: selftests: s390x: Provide additional num-guest-pages adjustment | expand

Commit Message

Andrew Jones March 12, 2020, 10:40 a.m. UTC
s390 requires 1M aligned guest sizes. Embedding the rounding in
vm_adjust_num_guest_pages() allows us to remove it from a few
other places.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 tools/testing/selftests/kvm/demand_paging_test.c | 4 ----
 tools/testing/selftests/kvm/dirty_log_test.c     | 5 +----
 tools/testing/selftests/kvm/include/kvm_util.h   | 8 +++++++-
 3 files changed, 8 insertions(+), 9 deletions(-)

Comments

Christian Borntraeger March 12, 2020, 10:48 a.m. UTC | #1
On 12.03.20 11:40, Andrew Jones wrote:
> s390 requires 1M aligned guest sizes. Embedding the rounding in
> vm_adjust_num_guest_pages() allows us to remove it from a few
> other places.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>

Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>

> ---
>  tools/testing/selftests/kvm/demand_paging_test.c | 4 ----
>  tools/testing/selftests/kvm/dirty_log_test.c     | 5 +----
>  tools/testing/selftests/kvm/include/kvm_util.h   | 8 +++++++-
>  3 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index c1e326d3ed7f..ae086c5dc118 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -378,10 +378,6 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
>  	guest_num_pages = (vcpus * vcpu_memory_bytes) / guest_page_size;
>  	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
>  
> -#ifdef __s390x__
> -	/* Round up to multiple of 1M (segment size) */
> -	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
> -#endif
>  	/*
>  	 * If there should be more memory in the guest test region than there
>  	 * can be pages in the guest, it will definitely cause problems.
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> index 518a94a7a8b5..8a79f5d6b979 100644
> --- a/tools/testing/selftests/kvm/dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -296,10 +296,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
>  	guest_num_pages = (1ul << (DIRTY_MEM_BITS -
>  				   vm_get_page_shift(vm))) + 3;
>  	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
> -#ifdef __s390x__
> -	/* Round up to multiple of 1M (segment size) */
> -	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
> -#endif
> +
>  	host_page_size = getpagesize();
>  	host_num_pages = vm_num_host_pages(mode, guest_num_pages);
>  
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index 707b44805149..ade5a40afbee 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -164,7 +164,13 @@ unsigned int vm_num_guest_pages(enum vm_guest_mode mode, unsigned int num_host_p
>  static inline unsigned int
>  vm_adjust_num_guest_pages(enum vm_guest_mode mode, unsigned int num_guest_pages)
>  {
> -	return vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
> +	unsigned int n;
> +	n = vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
> +#ifdef __s390x__
> +	/* s390 requires 1M aligned guest sizes */
> +	n = (n + 255) & ~255;

255 vs. 0xff probably does not matter.


> +#endif
> +	return n;
>  }
>  
>  struct kvm_userspace_memory_region *
>
Paolo Bonzini March 14, 2020, 10:58 a.m. UTC | #2
On 12/03/20 11:40, Andrew Jones wrote:
> s390 requires 1M aligned guest sizes. Embedding the rounding in
> vm_adjust_num_guest_pages() allows us to remove it from a few
> other places.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  tools/testing/selftests/kvm/demand_paging_test.c | 4 ----
>  tools/testing/selftests/kvm/dirty_log_test.c     | 5 +----
>  tools/testing/selftests/kvm/include/kvm_util.h   | 8 +++++++-
>  3 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
> index c1e326d3ed7f..ae086c5dc118 100644
> --- a/tools/testing/selftests/kvm/demand_paging_test.c
> +++ b/tools/testing/selftests/kvm/demand_paging_test.c
> @@ -378,10 +378,6 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
>  	guest_num_pages = (vcpus * vcpu_memory_bytes) / guest_page_size;
>  	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
>  
> -#ifdef __s390x__
> -	/* Round up to multiple of 1M (segment size) */
> -	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
> -#endif
>  	/*
>  	 * If there should be more memory in the guest test region than there
>  	 * can be pages in the guest, it will definitely cause problems.
> diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
> index 518a94a7a8b5..8a79f5d6b979 100644
> --- a/tools/testing/selftests/kvm/dirty_log_test.c
> +++ b/tools/testing/selftests/kvm/dirty_log_test.c
> @@ -296,10 +296,7 @@ static void run_test(enum vm_guest_mode mode, unsigned long iterations,
>  	guest_num_pages = (1ul << (DIRTY_MEM_BITS -
>  				   vm_get_page_shift(vm))) + 3;
>  	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
> -#ifdef __s390x__
> -	/* Round up to multiple of 1M (segment size) */
> -	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
> -#endif
> +
>  	host_page_size = getpagesize();
>  	host_num_pages = vm_num_host_pages(mode, guest_num_pages);
>  
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index 707b44805149..ade5a40afbee 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -164,7 +164,13 @@ unsigned int vm_num_guest_pages(enum vm_guest_mode mode, unsigned int num_host_p
>  static inline unsigned int
>  vm_adjust_num_guest_pages(enum vm_guest_mode mode, unsigned int num_guest_pages)
>  {
> -	return vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
> +	unsigned int n;
> +	n = vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
> +#ifdef __s390x__
> +	/* s390 requires 1M aligned guest sizes */
> +	n = (n + 255) & ~255;
> +#endif
> +	return n;
>  }
>  
>  struct kvm_userspace_memory_region *
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index c1e326d3ed7f..ae086c5dc118 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -378,10 +378,6 @@  static void run_test(enum vm_guest_mode mode, bool use_uffd,
 	guest_num_pages = (vcpus * vcpu_memory_bytes) / guest_page_size;
 	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
 
-#ifdef __s390x__
-	/* Round up to multiple of 1M (segment size) */
-	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
-#endif
 	/*
 	 * If there should be more memory in the guest test region than there
 	 * can be pages in the guest, it will definitely cause problems.
diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c
index 518a94a7a8b5..8a79f5d6b979 100644
--- a/tools/testing/selftests/kvm/dirty_log_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_test.c
@@ -296,10 +296,7 @@  static void run_test(enum vm_guest_mode mode, unsigned long iterations,
 	guest_num_pages = (1ul << (DIRTY_MEM_BITS -
 				   vm_get_page_shift(vm))) + 3;
 	guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
-#ifdef __s390x__
-	/* Round up to multiple of 1M (segment size) */
-	guest_num_pages = (guest_num_pages + 0xff) & ~0xffUL;
-#endif
+
 	host_page_size = getpagesize();
 	host_num_pages = vm_num_host_pages(mode, guest_num_pages);
 
diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index 707b44805149..ade5a40afbee 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -164,7 +164,13 @@  unsigned int vm_num_guest_pages(enum vm_guest_mode mode, unsigned int num_host_p
 static inline unsigned int
 vm_adjust_num_guest_pages(enum vm_guest_mode mode, unsigned int num_guest_pages)
 {
-	return vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
+	unsigned int n;
+	n = vm_num_guest_pages(mode, vm_num_host_pages(mode, num_guest_pages));
+#ifdef __s390x__
+	/* s390 requires 1M aligned guest sizes */
+	n = (n + 255) & ~255;
+#endif
+	return n;
 }
 
 struct kvm_userspace_memory_region *