From: Michael Roth <michael.roth@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: <kvm@vger.kernel.org>, <linux-coco@lists.linux.dev>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<thomas.lendacky@amd.com>, <pbonzini@redhat.com>,
<vbabka@suse.cz>, <ashish.kalra@amd.com>,
<liam.merwick@oracle.com>, <david@redhat.com>,
<vannapurve@google.com>, <ackerleytng@google.com>, <aik@amd.com>,
<ira.weiny@intel.com>, <yan.y.zhao@intel.com>,
<pankaj.gupta@amd.com>, Kai Huang <kai.huang@intel.com>
Subject: Re: [PATCH v3 6/6] KVM: guest_memfd: GUP source pages prior to populating guest memory
Date: Tue, 13 Jan 2026 15:35:56 -0600 [thread overview]
Message-ID: <20260113213556.rwihf3v3ek3c5kwl@amd.com> (raw)
In-Reply-To: <aWabORpkzEJygYNQ@google.com>
On Tue, Jan 13, 2026 at 11:21:29AM -0800, Sean Christopherson wrote:
> On Thu, Jan 08, 2026, Michael Roth wrote:
> > @@ -842,47 +881,38 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
> > if (!file)
> > return -EFAULT;
> >
> > - filemap_invalidate_lock(file->f_mapping);
> > -
> > npages = min_t(ulong, slot->npages - (start_gfn - slot->base_gfn), npages);
> > for (i = 0; i < npages; i++) {
> > - struct folio *folio;
> > - gfn_t gfn = start_gfn + i;
> > - pgoff_t index = kvm_gmem_get_index(slot, gfn);
> > - kvm_pfn_t pfn;
> > + struct page *src_page = NULL;
> > + void __user *p;
> >
> > if (signal_pending(current)) {
> > ret = -EINTR;
> > break;
> > }
> >
> > - folio = __kvm_gmem_get_pfn(file, slot, index, &pfn, NULL);
> > - if (IS_ERR(folio)) {
> > - ret = PTR_ERR(folio);
> > - break;
> > - }
> > + p = src ? src + i * PAGE_SIZE : NULL;
> >
> > - folio_unlock(folio);
> > + if (p) {
>
> Computing 'p' when src==NULL is unnecessary and makes it hard to see that gup()
> is done if and only if src!=NULL.
>
> Anyone object to this fixup?
No objections here, and it does seem a bit more readable. Will include
this if a new version is needed.
Thanks,
Mike
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 18ae59b92257..66afab8f08a3 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -884,17 +884,16 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long
> npages = min_t(ulong, slot->npages - (start_gfn - slot->base_gfn), npages);
> for (i = 0; i < npages; i++) {
> struct page *src_page = NULL;
> - void __user *p;
>
> if (signal_pending(current)) {
> ret = -EINTR;
> break;
> }
>
> - p = src ? src + i * PAGE_SIZE : NULL;
> + if (src) {
> + unsigned long uaddr = (unsigned long)src + i * PAGE_SIZE;
>
> - if (p) {
> - ret = get_user_pages_fast((unsigned long)p, 1, 0, &src_page);
> + ret = get_user_pages_fast(uaddr, 1, 0, &src_page);
> if (ret < 0)
> break;
> if (ret != 1) {
>
> To end up with:
>
> struct page *src_page = NULL;
>
> if (signal_pending(current)) {
> ret = -EINTR;
> break;
> }
>
> if (src) {
> unsigned long uaddr = (unsigned long)src + i * PAGE_SIZE;
>
> ret = get_user_pages_fast(uaddr, 1, 0, &src_page);
> if (ret < 0)
> break;
> if (ret != 1) {
> ret = -ENOMEM;
> break;
> }
> }
>
> ...
next prev parent reply other threads:[~2026-01-13 21:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 21:46 [PATCH v3 0/6] KVM: guest_memfd: Rework preparation/population flows in prep for in-place conversion Michael Roth
2026-01-08 21:46 ` [PATCH v3 1/6] KVM: SVM: Fix a missing kunmap_local() in sev_gmem_post_populate() Michael Roth
2026-01-08 21:46 ` [PATCH v3 2/6] KVM: guest_memfd: Remove partial hugepage handling from kvm_gmem_populate() Michael Roth
2026-01-12 9:39 ` Yan Zhao
2026-01-08 21:46 ` [PATCH v3 3/6] KVM: guest_memfd: Remove preparation tracking Michael Roth
2026-01-08 21:46 ` [PATCH v3 4/6] KVM: SEV: Document/enforce page-alignment for KVM_SEV_SNP_LAUNCH_UPDATE Michael Roth
2026-01-08 21:46 ` [PATCH v3 5/6] KVM: TDX: Document alignment requirements for KVM_TDX_INIT_MEM_REGION Michael Roth
2026-01-12 9:40 ` Yan Zhao
2026-01-08 21:46 ` [PATCH v3 6/6] KVM: guest_memfd: GUP source pages prior to populating guest memory Michael Roth
2026-01-12 9:41 ` Yan Zhao
2026-01-13 19:21 ` Sean Christopherson
2026-01-13 21:35 ` Michael Roth [this message]
2026-01-13 22:06 ` Sean Christopherson
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=20260113213556.rwihf3v3ek3c5kwl@amd.com \
--to=michael.roth@amd.com \
--cc=ackerleytng@google.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=david@redhat.com \
--cc=ira.weiny@intel.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pankaj.gupta@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vannapurve@google.com \
--cc=vbabka@suse.cz \
--cc=yan.y.zhao@intel.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