[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aTJTvbiXRg/DJlke@yzhao56-desk.sh.intel.com>
Date: Fri, 5 Dec 2025 11:38:37 +0800
From: Yan Zhao <yan.y.zhao@...el.com>
To: Michael Roth <michael.roth@....com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>, "linux-coco@...ts.linux.dev"
<linux-coco@...ts.linux.dev>, "linux-mm@...ck.org" <linux-mm@...ck.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"thomas.lendacky@....com" <thomas.lendacky@....com>, "pbonzini@...hat.com"
<pbonzini@...hat.com>, "seanjc@...gle.com" <seanjc@...gle.com>,
"vbabka@...e.cz" <vbabka@...e.cz>, "ashish.kalra@....com"
<ashish.kalra@....com>, "liam.merwick@...cle.com" <liam.merwick@...cle.com>,
"david@...hat.com" <david@...hat.com>, "Annapurve, Vishal"
<vannapurve@...gle.com>, "ackerleytng@...gle.com" <ackerleytng@...gle.com>,
"aik@....com" <aik@....com>, "Weiny, Ira" <ira.weiny@...el.com>
Subject: Re: [PATCH 3/3] KVM: guest_memfd: GUP source pages prior to
populating guest memory
On Wed, Dec 03, 2025 at 10:26:48PM +0800, Michael Roth wrote:
> Look at your
> changelog for the change above, for instance: it has no relevance in the
> context of this series. What do I put in its place? Bug reports about
> my experimental tree? It's just not the right place to try to justify
> these changes.
The following diff is reasonable to this series(if npages is up to 2MB),
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -878,11 +878,10 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
}
folio_unlock(folio);
- WARN_ON(!IS_ALIGNED(gfn, 1 << max_order) ||
- (npages - i) < (1 << max_order));
ret = -EINVAL;
- while (!kvm_range_has_memory_attributes(kvm, gfn, gfn + (1 << max_order),
+ while (!IS_ALIGNED(gfn, 1 << max_order) || (npages - i) < (1 << max_order) ||
+ !kvm_range_has_memory_attributes(kvm, gfn, gfn + (1 << max_order),
KVM_MEMORY_ATTRIBUTE_PRIVATE,
KVM_MEMORY_ATTRIBUTE_PRIVATE)) {
if (!max_order)
because:
1. kmalloc_array() + GUP 2MB src pages + returning -ENOMEM in "Hunk 1" is a
waste if max_order is always 0.
2. If we allow max_order > 0, then we must remove the WARN_ON().
3. When start_gfn is not 2MB aligned, just allocating 4KB src page each round is
enough (as in Sean's sketch patch).
Hunk 1: -------------------------------------------------------------------
src_npages = IS_ALIGNED((unsigned long)src, PAGE_SIZE) ? npages : npages + 1;
src_pages = kmalloc_array(src_npages, sizeof(struct page *), GFP_KERNEL);
if (!src_pages)
return -ENOMEM;
ret = get_user_pages_fast((unsigned long)src, src_npages, 0, src_pages);
if (ret < 0)
return ret;
if (ret != src_npages)
return -ENOMEM;
Hunk 2: -------------------------------------------------------------------
for (i = 0; i < npages; i += (1 << max_order)) {
...
folio = __kvm_gmem_get_pfn(file, slot, index, &pfn, &max_order);
WARN_ON(!IS_ALIGNED(gfn, 1 << max_order) ||
(npages - i) < (1 << max_order));
ret = post_populate(kvm, gfn, pfn, src ? &src_pages[i] : NULL,
src_offset, max_order, opaque);
...
}
Powered by blists - more mailing lists