mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Si-Wei Liu <si-wei.liu@oracle.com>
To: "Tal Zussman" <tz2294@columbia.edu>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowangio@gmail.com>,
	"Eugenio Pérez" <eperezma@redhat.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/2] vhost-vdpa: fix pinned page leak in vhost_vdpa_pa_map() error path
Date: Mon, 2 Nov 2026 17:54:30 -0800	[thread overview]
Message-ID: <655b611e-9b04-4f6e-abd8-3fefcd6e01ab@oracle.com> (raw)
In-Reply-To: <20261031-vhost-vdpa-unpin-v1-1-94ffc9683256@columbia.edu>

Good catch! Thanks for the fix, it looks good to me.

On 10/31/2026 10:45 AM, Tal Zussman wrote:
> When pin_user_pages() or vhost_vdpa_map() fails, vhost_vdpa_pa_map()
> is supposed to unpin the pages pinned after the last successfully
> mapped chunk, i.e. the range [map_pfn, last_pfn]. The unpin is guarded
> by nchunks, but nchunks is reset to 0 every time a chunk is mapped from
> inside the current page list, so a failure after any such boundary
> leaves that pending range pinned forever. With physically scattered
> memory nearly every page list contains a boundary, so the leak happens
> on practically every failed IOTLB update.
>
> The pending range is non-empty exactly when a page has been pinned,
> which last_pfn already tells us, so drop nchunks and test last_pfn.
>
> Fixes: ad89653f79f1 ("vhost-vdpa: fix page pinning leakage in error path (rework)")
> Cc: stable@vger.kernel.org
Acked-by: Si-Wei Liu <si-wei.liu@oracle.com>

> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
> ---
>   drivers/vhost/vdpa.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index ff7d90719171..d9af728942b3 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1151,7 +1151,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   	unsigned long list_size = PAGE_SIZE / sizeof(struct page *);
>   	unsigned int gup_flags = FOLL_LONGTERM;
>   	unsigned long npages, cur_base, map_pfn, last_pfn = 0;
> -	unsigned long lock_limit, sz2pin, nchunks, i;
> +	unsigned long lock_limit, sz2pin, i;
>   	unsigned long page_offset;
>   	u64 start = iova;
>   	long pinned;
> @@ -1187,7 +1187,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   
>   	cur_base = uaddr & PAGE_MASK;
>   	iova &= PAGE_MASK;
> -	nchunks = 0;
>   
>   	while (npages) {
>   		sz2pin = min_t(unsigned long, npages, list_size);
> @@ -1202,7 +1201,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   			}
>   			goto out;
>   		}
> -		nchunks++;
>   
>   		if (!last_pfn)
>   			map_pfn = page_to_pfn(page_list[0]);
> @@ -1233,7 +1231,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   
>   				map_pfn = this_pfn;
>   				iova += csize;
> -				nchunks = 0;
>   			}
>   
>   			last_pfn = this_pfn;
> @@ -1248,7 +1245,7 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   			     PFN_PHYS(map_pfn), perm, NULL);
>   out:
>   	if (ret) {
> -		if (nchunks) {
> +		if (last_pfn) {
>   			unsigned long pfn;
>   
>   			/*
> @@ -1260,7 +1257,6 @@ static int vhost_vdpa_pa_map(struct vhost_vdpa *v,
>   			 * the corresponding unpinning will be handled by
>   			 * vdpa_unmap().
>   			 */
> -			WARN_ON(!last_pfn);
>   			for (pfn = map_pfn; pfn <= last_pfn; pfn++)
>   				unpin_user_page(pfn_to_page(pfn));
>   		}
>
> -- 
> 2.39.5


  reply	other threads:[~2026-11-03  1:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 17:45 [PATCH 0/2] vhost-vdpa: fix a pin leak and unpin mappings by range Tal Zussman
2026-10-31 17:45 ` [PATCH 1/2] vhost-vdpa: fix pinned page leak in vhost_vdpa_pa_map() error path Tal Zussman
2026-11-03  1:54   ` Si-Wei Liu [this message]
2026-10-31 17:45 ` [PATCH 2/2] vhost-vdpa: unpin mappings by range Tal Zussman

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=655b611e-9b04-4f6e-abd8-3fefcd6e01ab@oracle.com \
    --to=si-wei.liu@oracle.com \
    --cc=eperezma@redhat.com \
    --cc=jasowangio@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tz2294@columbia.edu \
    --cc=virtualization@lists.linux.dev \
    /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

all inboxes | Powered by JetHome®