All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: "Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Janosch Frank" <frankja@linux.ibm.com>,
	kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH 5/9] KVM: selftests: Align memory region addresses to 1M on s390x
Date: Thu, 23 May 2019 19:40:28 +0200	[thread overview]
Message-ID: <20190523174028.3giefzff3l5eclki@kamzik.brq.redhat.com> (raw)
In-Reply-To: <20190523164309.13345-6-thuth@redhat.com>

On Thu, May 23, 2019 at 06:43:05PM +0200, Thomas Huth wrote:
> On s390x, there is a constraint that memory regions have to be aligned
> to 1M (or running the VM will fail). Introduce a new "alignment" variable
> in the vm_userspace_mem_region_add() function which now can be used for
> both, huge page and s390x alignment requirements.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 08edb8436c47..656df9d5cd4d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -559,6 +559,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	unsigned long pmem_size = 0;
>  	struct userspace_mem_region *region;
>  	size_t huge_page_size = KVM_UTIL_PGS_PER_HUGEPG * vm->page_size;
> +	size_t alignment;
>  
>  	TEST_ASSERT((guest_paddr % vm->page_size) == 0, "Guest physical "
>  		"address not on a page boundary.\n"
> @@ -608,9 +609,20 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	TEST_ASSERT(region != NULL, "Insufficient Memory");
>  	region->mmap_size = npages * vm->page_size;
>  
> -	/* Enough memory to align up to a huge page. */
> +#ifdef __s390x__
> +	/* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
> +	alignment = 0x100000;
> +#else
> +	alignment = 1;
> +#endif
> +
>  	if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
> -		region->mmap_size += huge_page_size;
> +		alignment = huge_page_size;

I guess s390x won't ever support VM_MEM_SRC_ANONYMOUS_THP? If it does,
then we need 'alignment = max(huge_page_size, alignment)'. Actually
that might be a nice way to write this anyway for future-proofing.

> +
> +	/* Add enough memory to align up if necessary */
> +	if (alignment > 1)
> +		region->mmap_size += alignment;
> +
>  	region->mmap_start = mmap(NULL, region->mmap_size,
>  				  PROT_READ | PROT_WRITE,
>  				  MAP_PRIVATE | MAP_ANONYMOUS
> @@ -620,9 +632,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  		    "test_malloc failed, mmap_start: %p errno: %i",
>  		    region->mmap_start, errno);
>  
> -	/* Align THP allocation up to start of a huge page. */
> -	region->host_mem = align(region->mmap_start,
> -				 src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
> +	/* Align host address */
> +	region->host_mem = align(region->mmap_start, alignment);
>  
>  	/* As needed perform madvise */
>  	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> -- 
> 2.21.0
> 

WARNING: multiple messages have this Message-ID (diff)
From: drjones at redhat.com (Andrew Jones)
Subject: [PATCH 5/9] KVM: selftests: Align memory region addresses to 1M on s390x
Date: Thu, 23 May 2019 19:40:28 +0200	[thread overview]
Message-ID: <20190523174028.3giefzff3l5eclki@kamzik.brq.redhat.com> (raw)
In-Reply-To: <20190523164309.13345-6-thuth@redhat.com>

On Thu, May 23, 2019 at 06:43:05PM +0200, Thomas Huth wrote:
> On s390x, there is a constraint that memory regions have to be aligned
> to 1M (or running the VM will fail). Introduce a new "alignment" variable
> in the vm_userspace_mem_region_add() function which now can be used for
> both, huge page and s390x alignment requirements.
> 
> Signed-off-by: Thomas Huth <thuth at redhat.com>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 08edb8436c47..656df9d5cd4d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -559,6 +559,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	unsigned long pmem_size = 0;
>  	struct userspace_mem_region *region;
>  	size_t huge_page_size = KVM_UTIL_PGS_PER_HUGEPG * vm->page_size;
> +	size_t alignment;
>  
>  	TEST_ASSERT((guest_paddr % vm->page_size) == 0, "Guest physical "
>  		"address not on a page boundary.\n"
> @@ -608,9 +609,20 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	TEST_ASSERT(region != NULL, "Insufficient Memory");
>  	region->mmap_size = npages * vm->page_size;
>  
> -	/* Enough memory to align up to a huge page. */
> +#ifdef __s390x__
> +	/* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
> +	alignment = 0x100000;
> +#else
> +	alignment = 1;
> +#endif
> +
>  	if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
> -		region->mmap_size += huge_page_size;
> +		alignment = huge_page_size;

I guess s390x won't ever support VM_MEM_SRC_ANONYMOUS_THP? If it does,
then we need 'alignment = max(huge_page_size, alignment)'. Actually
that might be a nice way to write this anyway for future-proofing.

> +
> +	/* Add enough memory to align up if necessary */
> +	if (alignment > 1)
> +		region->mmap_size += alignment;
> +
>  	region->mmap_start = mmap(NULL, region->mmap_size,
>  				  PROT_READ | PROT_WRITE,
>  				  MAP_PRIVATE | MAP_ANONYMOUS
> @@ -620,9 +632,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  		    "test_malloc failed, mmap_start: %p errno: %i",
>  		    region->mmap_start, errno);
>  
> -	/* Align THP allocation up to start of a huge page. */
> -	region->host_mem = align(region->mmap_start,
> -				 src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
> +	/* Align host address */
> +	region->host_mem = align(region->mmap_start, alignment);
>  
>  	/* As needed perform madvise */
>  	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> -- 
> 2.21.0
> 

WARNING: multiple messages have this Message-ID (diff)
From: drjones@redhat.com (Andrew Jones)
Subject: [PATCH 5/9] KVM: selftests: Align memory region addresses to 1M on s390x
Date: Thu, 23 May 2019 19:40:28 +0200	[thread overview]
Message-ID: <20190523174028.3giefzff3l5eclki@kamzik.brq.redhat.com> (raw)
Message-ID: <20190523174028.PSQ39fObEwMLz2Y3QWnSnV9L4wOiQrU9_Su9dWpTtEA@z> (raw)
In-Reply-To: <20190523164309.13345-6-thuth@redhat.com>

On Thu, May 23, 2019@06:43:05PM +0200, Thomas Huth wrote:
> On s390x, there is a constraint that memory regions have to be aligned
> to 1M (or running the VM will fail). Introduce a new "alignment" variable
> in the vm_userspace_mem_region_add() function which now can be used for
> both, huge page and s390x alignment requirements.
> 
> Signed-off-by: Thomas Huth <thuth at redhat.com>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 08edb8436c47..656df9d5cd4d 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -559,6 +559,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	unsigned long pmem_size = 0;
>  	struct userspace_mem_region *region;
>  	size_t huge_page_size = KVM_UTIL_PGS_PER_HUGEPG * vm->page_size;
> +	size_t alignment;
>  
>  	TEST_ASSERT((guest_paddr % vm->page_size) == 0, "Guest physical "
>  		"address not on a page boundary.\n"
> @@ -608,9 +609,20 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  	TEST_ASSERT(region != NULL, "Insufficient Memory");
>  	region->mmap_size = npages * vm->page_size;
>  
> -	/* Enough memory to align up to a huge page. */
> +#ifdef __s390x__
> +	/* On s390x, the host address must be aligned to 1M (due to PGSTEs) */
> +	alignment = 0x100000;
> +#else
> +	alignment = 1;
> +#endif
> +
>  	if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
> -		region->mmap_size += huge_page_size;
> +		alignment = huge_page_size;

I guess s390x won't ever support VM_MEM_SRC_ANONYMOUS_THP? If it does,
then we need 'alignment = max(huge_page_size, alignment)'. Actually
that might be a nice way to write this anyway for future-proofing.

> +
> +	/* Add enough memory to align up if necessary */
> +	if (alignment > 1)
> +		region->mmap_size += alignment;
> +
>  	region->mmap_start = mmap(NULL, region->mmap_size,
>  				  PROT_READ | PROT_WRITE,
>  				  MAP_PRIVATE | MAP_ANONYMOUS
> @@ -620,9 +632,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  		    "test_malloc failed, mmap_start: %p errno: %i",
>  		    region->mmap_start, errno);
>  
> -	/* Align THP allocation up to start of a huge page. */
> -	region->host_mem = align(region->mmap_start,
> -				 src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
> +	/* Align host address */
> +	region->host_mem = align(region->mmap_start, alignment);
>  
>  	/* As needed perform madvise */
>  	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> -- 
> 2.21.0
> 

  reply	other threads:[~2019-05-23 17:40 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 16:43 [PATCH v1 0/9] KVM selftests for s390x Thomas Huth
2019-05-23 16:43 ` Thomas Huth
2019-05-23 16:43 ` thuth
2019-05-23 16:43 ` [PATCH 1/9] KVM: selftests: Wrap vcpu_nested_state_get/set functions with x86 guard Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 16:43 ` [PATCH 2/9] KVM: selftests: Guard struct kvm_vcpu_events with __KVM_HAVE_VCPU_EVENTS Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 17:57   ` Andrew Jones
2019-05-23 17:57     ` Andrew Jones
2019-05-23 17:57     ` drjones
2019-05-23 16:43 ` [PATCH 3/9] kvm: selftests: aarch64: fix default vm mode Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-24  8:37   ` Christian Borntraeger
2019-05-24  8:37     ` Christian Borntraeger
2019-05-24  8:37     ` borntraeger
2019-05-23 16:43 ` [PATCH 4/9] KVM: selftests: Introduce a VM_MODE_DEFAULT macro for the default bits Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 17:20   ` Andrew Jones
2019-05-23 17:20     ` Andrew Jones
2019-05-23 17:20     ` drjones
2019-05-23 16:43 ` [PATCH 5/9] KVM: selftests: Align memory region addresses to 1M on s390x Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 17:40   ` Andrew Jones [this message]
2019-05-23 17:40     ` Andrew Jones
2019-05-23 17:40     ` drjones
2019-05-24  8:29     ` Christian Borntraeger
2019-05-24  8:29       ` Christian Borntraeger
2019-05-24  8:29       ` borntraeger
2019-05-24 18:17       ` Thomas Huth
2019-05-24 18:17         ` Thomas Huth
2019-05-24 18:17         ` thuth
2019-05-23 16:43 ` [PATCH 6/9] KVM: selftests: Add processor code for s390x Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 16:43 ` [PATCH 7/9] KVM: selftests: Add the sync_regs test " Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 16:43 ` [PATCH 8/9] KVM: s390: Do not report unusabled IDs via KVM_CAP_MAX_VCPU_ID Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 17:56   ` Andrew Jones
2019-05-23 17:56     ` Andrew Jones
2019-05-23 17:56     ` drjones
2019-05-24  9:13   ` Cornelia Huck
2019-05-24  9:13     ` Cornelia Huck
2019-05-24  9:13     ` cohuck
2019-05-24  9:16   ` David Hildenbrand
2019-05-24  9:16     ` David Hildenbrand
2019-05-24  9:16     ` david
2019-05-28 11:00   ` Christian Borntraeger
2019-05-28 11:00     ` Christian Borntraeger
2019-05-28 11:00     ` borntraeger
2019-05-28 12:53     ` Cornelia Huck
2019-05-28 12:53       ` Cornelia Huck
2019-05-28 12:53       ` cohuck
2019-05-28 13:48       ` Christian Borntraeger
2019-05-28 13:48         ` Christian Borntraeger
2019-05-28 13:48         ` borntraeger
2019-05-23 16:43 ` [PATCH 9/9] KVM: selftests: Move kvm_create_max_vcpus test to generic code Thomas Huth
2019-05-23 16:43   ` Thomas Huth
2019-05-23 16:43   ` thuth
2019-05-23 17:56   ` Andrew Jones
2019-05-23 17:56     ` Andrew Jones
2019-05-23 17:56     ` drjones
2019-05-24  9:16   ` David Hildenbrand
2019-05-24  9:16     ` David Hildenbrand
2019-05-24  9:16     ` david
2019-05-24 10:33 ` [PATCH] KVM: selftests: enable pgste option for the linker on s390 Christian Borntraeger
2019-05-24 10:33   ` Christian Borntraeger
2019-05-24 10:33   ` borntraeger
2019-05-24 18:16   ` Thomas Huth
2019-05-24 18:16     ` Thomas Huth
2019-05-24 18:16     ` thuth
2019-05-24 19:07   ` David Hildenbrand
2019-05-24 19:07     ` David Hildenbrand
2019-05-24 19:07     ` david
2019-05-27 11:44   ` Christian Borntraeger
2019-05-27 11:44     ` Christian Borntraeger
2019-05-27 11:44     ` borntraeger
2019-05-24 11:11 ` [PATCH v1 0/9] KVM selftests for s390x Christian Borntraeger
2019-05-24 11:11   ` Christian Borntraeger
2019-05-24 11:11   ` borntraeger
2019-05-24 12:17   ` Christian Borntraeger
2019-05-24 12:17     ` Christian Borntraeger
2019-05-24 12:17     ` borntraeger
2019-05-24 12:29     ` Christian Borntraeger
2019-05-24 12:29       ` Christian Borntraeger
2019-05-24 12:29       ` borntraeger
2019-05-24 12:36       ` David Hildenbrand
2019-05-24 12:36         ` David Hildenbrand
2019-05-24 12:36         ` david
2019-05-24 12:56         ` Christian Borntraeger
2019-05-24 12:56           ` Christian Borntraeger
2019-05-24 12:56           ` borntraeger
2019-05-24 18:33 ` Christian Borntraeger
2019-05-24 18:33   ` Christian Borntraeger
2019-05-24 18:33   ` borntraeger
2019-06-04 17:19 ` Paolo Bonzini
2019-06-04 17:19   ` Paolo Bonzini
2019-06-04 17:19   ` pbonzini
2019-06-04 17:37   ` Christian Borntraeger
2019-06-04 17:37     ` Christian Borntraeger
2019-06-04 17:37     ` borntraeger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190523174028.3giefzff3l5eclki@kamzik.brq.redhat.com \
    --to=drjones@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=shuah@kernel.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.