Re: [PATCH v8 10/14] KVM: selftests: aarch64: Add aarch64/page_fault_test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 27, 2022 at 10:06:23PM +0000, Sean Christopherson wrote:
> On Mon, Sep 26, 2022, Ricardo Koller wrote:
> > On Thu, Sep 22, 2022 at 07:32:42PM +0000, Sean Christopherson wrote:
> > > On Thu, Sep 22, 2022, Ricardo Koller wrote:
> > > > +	void *hva = (void *)region->region.userspace_addr;
> > > > +	uint64_t paging_size = region->region.memory_size;
> > > > +	int ret, fd = region->fd;
> > > > +
> > > > +	if (fd != -1) {
> > > > +		ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
> > > > +				0, paging_size);
> > > > +		TEST_ASSERT(ret == 0, "fallocate failed, errno: %d\n", errno);
> > > > +	} else {
> > > > +		if (is_backing_src_hugetlb(region->backing_src_type))
> > > > +			return false;
> > > 
> > > Why is hugetlb disallowed?  I thought anon hugetlb supports MADV_DONTNEED?
> > > 
> > 
> > It fails with EINVAL (only tried on arm) for both the PAGE_SIZE and the huge
> > page size. And note that the address is aligned as well.
> > 
> > madvise(0xffffb7c00000, 2097152, MADV_DONTNEED) = -1 EINVAL (Invalid argument)
> > 	^^^^^^^^^^^^^^	^^^^^^^
> > 	2M aligned	2M (hugepage size)
> > 			
> > madvise(0xffff9e800000, 4096, MADV_DONTNEED) = -1 EINVAL (Invalid argument)   
> > 			^^^^
> > 			PAGE_SIZE
> 
> I think this needs to be root caused before merging.  Unless I'm getting turned
> around, MADV_DONTEED should work, i.e. there is a test bug lurking somewhere.

Turns out that the failure is documented. Found this in the madvise manpage:

  MADV_DONTNEED cannot be applied to locked pages, Huge TLB pages, or VM_PFNMAP pages.

Was also playing with the following non-selftest program (before checking the
manpage, and I now remember that I actually read the above sentence before).

This fails on both x86 and arm:

	#include <stdio.h>
	#include <stddef.h>
	#include <sys/mman.h>
	#include <linux/mman.h>
	#include <assert.h>

	#define SZ_2M (1 << 21)

	int main()
	{
		void *p = mmap(NULL, SZ_2M, PROT_READ | PROT_WRITE,
			       MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_2MB,
			       -1, 0);
		assert(p != MAP_FAILED);
		assert(madvise(p, 4096, MADV_DONTNEED) == 0); // this fails
		assert(madvise(p, SZ_2M, MADV_DONTNEED) == 0); // this fails
	}

And for completeness, this passes on both:

	int main()
	{
		void *p = mmap(NULL, SZ_2M, PROT_READ | PROT_WRITE,
			       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
		assert(p != MAP_FAILED);
		assert(madvise(p, SZ_2M, MADV_DONTNEED) == 0);
	}
_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm



[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux