mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Ackerley Tng <ackerleytng@google.com>,
	Sean Christopherson <seanjc@google.com>
Cc: syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	pbonzini@redhat.com, syzkaller-bugs@googlegroups.com,
	michael.roth@amd.com, vannapurve@google.com,
	kartikey406@gmail.com
Subject: Re: [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND
Date: Mon, 9 Feb 2026 20:38:06 +0100	[thread overview]
Message-ID: <d3df9637-18f6-4143-befd-1550320b4dc8@kernel.org> (raw)
In-Reply-To: <CAEvNRgGjcMY-DMLu1ZaCRXA8uCeueBD9a-a1gh-UEB7nqpfTfg@mail.gmail.com>

On 2/9/26 19:24, Ackerley Tng wrote:
> "David Hildenbrand (Arm)" <david@kernel.org> writes:
> 
>> On 2/8/26 18:34, Ackerley Tng wrote:
>>> Ackerley Tng <ackerleytng@google.com> writes:
>>>
>>>
>>> I trimmed the repro to this:
>>>
>>> static void test_guest_memfd_repro(void)
>>> {
>>> 	struct kvm_vcpu *vcpu;
>>> 	uint8_t *unaligned_mem;
>>> 	struct kvm_vm *vm;
>>> 	uint8_t *mem;
>>> 	int fd;
>>>
>>> 	vm = __vm_create_shape_with_one_vcpu(VM_SHAPE_DEFAULT, &vcpu, 1, guest_code);
>>>
>>> 	fd = vm_create_guest_memfd(vm, SZ_2M * 2, GUEST_MEMFD_FLAG_MMAP |
>>> GUEST_MEMFD_FLAG_INIT_SHARED);
>>>
>>> 	unaligned_mem = mmap(NULL, SZ_2M + SZ_2M, PROT_READ | PROT_WRITE,
>>> MAP_FIXED | MAP_SHARED, fd, 0);
>>> 	mem = align_ptr_up(unaligned_mem, SZ_2M);
>>> 	TEST_ASSERT(((unsigned long)mem & (SZ_2M - 1)) == 0, "returned
>>> address must be aligned to SZ_2M");
>>>
>>> 	TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_HUGEPAGE), 0);
>>>
>>> 	for (int i = 0; i < SZ_2M; i += SZ_4K)
>>> 		READ_ONCE(mem[i]);
>>>
>>> 	TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_COLLAPSE), 0);
>>>
>>> 	TEST_ASSERT_EQ(madvise(mem, SZ_2M, MADV_DONTNEED), 0);
>>>
>>> 	/* This triggers the WARNing. */
>>> 	READ_ONCE(mem[0]);
>>>
>>> 	munmap(unaligned_mem, SZ_2M * 2);
>>>
>>> 	close(fd);
>>> 	kvm_vm_free(vm);
>>> }
>>>
>>> And tried to replace the fd creation the secretmem equivalent
>>>
>>> 	fd = syscall(__NR_memfd_secret, 0);
>>> 	TEST_ASSERT(fd >= 0, "Couldn't create secretmem fd.");
>>> 	TEST_ASSERT_EQ(ftruncate(fd, SZ_2M * 2), 0);
>>>
>>> Should a guest_memfd selftest be added to cover this?
>>>
>>> MADV_COLLAPSE fails with EINVAL, but it does go through to
>>> hpage_collapse_scan_file() -> collapse_file(), before failing because
>>> when collapsing the page, copy_mc_highpage() returns > 0.
>>
>> Just what I suspected. :)
>>
>> Thanks for digging into the details!
>>
> 
> Happy to help :)
> 
> In general, do we want the reproducers added as selftests? Should this
> be added as part of tools/testing/selftests/kvm/guest_memfd_test.c

I guess adding it to guest_memfd_test.c and asserting that MADV_COLLAPSE 
fails as expected could be a reasonable test case. It's not a lot of 
code and easy to verify.

-- 
Cheers,

David

  reply	other threads:[~2026-02-09 19:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30 20:15 [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
2026-02-01  4:57 ` Forwarded: [PATCH] KVM: guest_memfd: Restrict to order-0 folios until large folio support is implemented syzbot
2026-02-01  5:48 ` syzbot
2026-02-01  7:48 ` syzbot
2026-02-01 11:08 ` syzbot
2026-02-02  8:34 ` Forwarded: [PATCH] KVM: guest_memfd: Reject large folios until " syzbot
2026-02-02 15:11 ` syzbot
2026-02-03 20:06 ` Forwarded: [PATCH 1/2] KVM: guest_memfd: Always use order 0 when allocating for guest_memfd syzbot
2026-02-04 17:01 ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
2026-02-04 18:21   ` [syzbot] [kvm?] WARNING in kvm_gmem_fault_user_mapping syzbot
2026-02-04 19:10   ` [PATCH] KVM: guest_memfd: Disable VMA merging with VM_DONTEXPAND Ackerley Tng
2026-02-04 21:37     ` Sean Christopherson
2026-02-04 21:45       ` David Hildenbrand (arm)
2026-02-04 23:17         ` Ackerley Tng
2026-02-08 17:34           ` Ackerley Tng
2026-02-09  3:40             ` Deepanshu Kartikey
2026-02-09 10:38             ` David Hildenbrand (Arm)
2026-02-09 18:24               ` Ackerley Tng
2026-02-09 19:38                 ` David Hildenbrand (Arm) [this message]
2026-02-09  1:55 ` Forwarded: [PATCH] KVM: guest_memfd: Prevent THP collapse of guest_memfd pages syzbot
2026-02-09  2:02 ` Forwarded: [PATCH] mm: thp: Deny THP for guest_memfd and secretmem in file_thp_enabled() syzbot
2026-02-09 13:11 ` syzbot
2026-02-13 15:43 ` Forwarded: [PATCH] mm: thp: deny THP for files on anonymous inodes syzbot

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=d3df9637-18f6-4143-befd-1550320b4dc8@kernel.org \
    --to=david@kernel.org \
    --cc=ackerleytng@google.com \
    --cc=kartikey406@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=syzbot+33a04338019ac7e43a44@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=vannapurve@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome