[V2] SelfTest: KVM: Drop Asserts for madvise MADV_NOHUGEPAGE failure
diff mbox series

Message ID 20181116115055.7415-1-ahmedsoliman0x666@gmail.com
State New
Headers show
Series
  • [V2] SelfTest: KVM: Drop Asserts for madvise MADV_NOHUGEPAGE failure
Related show

Commit Message

Ahmed Abd El Mawgood Nov. 16, 2018, 11:50 a.m. UTC
From: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>

madvise() returns -1 without CONFIG_TRANSPARENT_HUGEPAGE=y. That would
trigger asserts when checking for return value of madvice. Following
similar decision to [1]. I thought it is ok to assume that madvise()
MADV_NOHUGEPAGE failures implies that THP is not supported by host kernel.

Other options was to check for Transparent Huge Page support in
/sys/kernel/mm/transparent_hugepage/enabled.

-- links --
[1] https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg04514.html

Signed-off-by: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>
---
 tools/testing/selftests/kvm/lib/kvm_util.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Andrew Jones Nov. 16, 2018, 12:58 p.m. UTC | #1
On Fri, Nov 16, 2018 at 01:50:55PM +0200, Ahmed Abd El Mawgood wrote:
> From: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>
> 
> madvise() returns -1 without CONFIG_TRANSPARENT_HUGEPAGE=y. That would
> trigger asserts when checking for return value of madvice. Following
> similar decision to [1]. I thought it is ok to assume that madvise()
> MADV_NOHUGEPAGE failures implies that THP is not supported by host kernel.
> 
> Other options was to check for Transparent Huge Page support in
> /sys/kernel/mm/transparent_hugepage/enabled.
> 
> -- links --
> [1] https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg04514.html
> 
> Signed-off-by: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 1b41e71283d5..437c5bb48061 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -586,14 +586,23 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
>  				 src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
>  
>  	/* As needed perform madvise */
> -	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> +	if (src_type == VM_MEM_SRC_ANONYMOUS) {
> +		/*
> +		 * Neglect madvise error because it is ok to not have THP
> +		 * support in this case.
> +		 */
> +		madvise(region->host_mem, npages * vm->page_size,
> +			MADV_NOHUGEPAGE);
> +	} else if (src_type == VM_MEM_SRC_ANONYMOUS_THP) {
>  		ret = madvise(region->host_mem, npages * vm->page_size,
> -			     src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
> +			MADV_HUGEPAGE);
>  		TEST_ASSERT(ret == 0, "madvise failed,\n"
> -			    "  addr: %p\n"
> -			    "  length: 0x%lx\n"
> -			    "  src_type: %x",
> -			    region->host_mem, npages * vm->page_size, src_type);
> +			"Does the kernel have CONFIG_TRANSPARENT_HUGEPAGE=y\n"
> +			"  addr: %p\n"
> +			"  length: 0x%lx\n"
> +			"  src_type: %x\n",
> +			region->host_mem, npages * vm->page_size,
> +			src_type);
>  	}
>  
>  	region->unused_phy_pages = sparsebit_alloc();
> -- 
> 2.18.1
>

Reviewed-by: Andrew Jones <drjones@redhat.com>
Ahmed Abd El Mawgood Dec. 24, 2018, 2:56 p.m. UTC | #2
Kind reminder to merge my patch into next

thanks.

On Fri, Nov 16, 2018 at 2:59 PM Andrew Jones <drjones@redhat.com> wrote:
>
> On Fri, Nov 16, 2018 at 01:50:55PM +0200, Ahmed Abd El Mawgood wrote:
> > From: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>
> >
> > madvise() returns -1 without CONFIG_TRANSPARENT_HUGEPAGE=y. That would
> > trigger asserts when checking for return value of madvice. Following
> > similar decision to [1]. I thought it is ok to assume that madvise()
> > MADV_NOHUGEPAGE failures implies that THP is not supported by host kernel.
> >
> > Other options was to check for Transparent Huge Page support in
> > /sys/kernel/mm/transparent_hugepage/enabled.
> >
> > -- links --
> > [1] https://lists.gnu.org/archive/html/qemu-devel/2015-11/msg04514.html
> >
> > Signed-off-by: Ahmed Abd El Mawgood <ahmedsoliman@mena.vt.edu>
> > ---
> >  tools/testing/selftests/kvm/lib/kvm_util.c | 21 +++++++++++++++------
> >  1 file changed, 15 insertions(+), 6 deletions(-)
> >
> > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> > index 1b41e71283d5..437c5bb48061 100644
> > --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> > @@ -586,14 +586,23 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
> >                                src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
> >
> >       /* As needed perform madvise */
> > -     if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> > +     if (src_type == VM_MEM_SRC_ANONYMOUS) {
> > +             /*
> > +              * Neglect madvise error because it is ok to not have THP
> > +              * support in this case.
> > +              */
> > +             madvise(region->host_mem, npages * vm->page_size,
> > +                     MADV_NOHUGEPAGE);
> > +     } else if (src_type == VM_MEM_SRC_ANONYMOUS_THP) {
> >               ret = madvise(region->host_mem, npages * vm->page_size,
> > -                          src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
> > +                     MADV_HUGEPAGE);
> >               TEST_ASSERT(ret == 0, "madvise failed,\n"
> > -                         "  addr: %p\n"
> > -                         "  length: 0x%lx\n"
> > -                         "  src_type: %x",
> > -                         region->host_mem, npages * vm->page_size, src_type);
> > +                     "Does the kernel have CONFIG_TRANSPARENT_HUGEPAGE=y\n"
> > +                     "  addr: %p\n"
> > +                     "  length: 0x%lx\n"
> > +                     "  src_type: %x\n",
> > +                     region->host_mem, npages * vm->page_size,
> > +                     src_type);
> >       }
> >
> >       region->unused_phy_pages = sparsebit_alloc();
> > --
> > 2.18.1
> >
>
> Reviewed-by: Andrew Jones <drjones@redhat.com>
shuah Dec. 27, 2018, 12:44 a.m. UTC | #3
Hi Paolo,

On 12/24/18 7:56 AM, Ahmed Soliman wrote:
> Kind reminder to merge my patch into next
> 
> thanks.
> 

I am assuming you will be picking this patch up. Please let me know if 
you want me to take it through kselftest tree.

thanks,
-- Shuah
Paolo Bonzini Jan. 7, 2019, 11:20 p.m. UTC | #4
On 27/12/18 01:44, shuah wrote:
> Hi Paolo,
> 
> On 12/24/18 7:56 AM, Ahmed Soliman wrote:
>> Kind reminder to merge my patch into next
>>
>> thanks.
>>
> 
> I am assuming you will be picking this patch up. Please let me know if
> you want me to take it through kselftest tree.

Yes, I was on vacataion but I'm back now.

Paolo

Patch
diff mbox series

diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
index 1b41e71283d5..437c5bb48061 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -586,14 +586,23 @@  void vm_userspace_mem_region_add(struct kvm_vm *vm,
 				 src_type == VM_MEM_SRC_ANONYMOUS_THP ?  huge_page_size : 1);
 
 	/* As needed perform madvise */
-	if (src_type == VM_MEM_SRC_ANONYMOUS || src_type == VM_MEM_SRC_ANONYMOUS_THP) {
+	if (src_type == VM_MEM_SRC_ANONYMOUS) {
+		/*
+		 * Neglect madvise error because it is ok to not have THP
+		 * support in this case.
+		 */
+		madvise(region->host_mem, npages * vm->page_size,
+			MADV_NOHUGEPAGE);
+	} else if (src_type == VM_MEM_SRC_ANONYMOUS_THP) {
 		ret = madvise(region->host_mem, npages * vm->page_size,
-			     src_type == VM_MEM_SRC_ANONYMOUS ? MADV_NOHUGEPAGE : MADV_HUGEPAGE);
+			MADV_HUGEPAGE);
 		TEST_ASSERT(ret == 0, "madvise failed,\n"
-			    "  addr: %p\n"
-			    "  length: 0x%lx\n"
-			    "  src_type: %x",
-			    region->host_mem, npages * vm->page_size, src_type);
+			"Does the kernel have CONFIG_TRANSPARENT_HUGEPAGE=y\n"
+			"  addr: %p\n"
+			"  length: 0x%lx\n"
+			"  src_type: %x\n",
+			region->host_mem, npages * vm->page_size,
+			src_type);
 	}
 
 	region->unused_phy_pages = sparsebit_alloc();