From: Vipin Sharma <vipinsh@google.com>
To: Alex Williamson <alex@shazbot.org>
Cc: Aaron Lewis <aaronlewis@google.com>,
Jason Gunthorpe <jgg@nvidia.com>,
kvm@vger.kernel.org, dmatlack@google.com
Subject: Re: [PATCH 0/3] vfio/type1: Fix pin leaks for reserved GUP-pinned pages
Date: Tue, 1 Dec 2026 16:25:45 -0800 [thread overview]
Message-ID: <20261202002319.GD2554154.vipinsh@google.com> (raw)
In-Reply-To: <20261130165227.5cdba5ad@shazbot.org>
On Mon, Nov 30, 2026 at 04:52:27PM -0700, Alex Williamson wrote:
> On Mon, 30 Nov 2026 06:40:01 -0800
> Aaron Lewis <aaronlewis@google.com> wrote:
>
> > > Are you only suggesting 1 & 2 because the RLIMIT enforcement is user
> > > visible in 3? I'd tend to think we should consider them all, they're
> > > real fixes, even if the usage scope is pretty narrow, currently.
> >
> > No, both patches 2 & 3 charge reserved GUP-pinned pages against
> > RLIMIT_MEMLOCK (I can make that just as explicit in patch 2's commit
> > message in v2). I only suggested 1 & 2 to offer a smaller scope focused
> > on the DMA map/unmap paths, in case there was reluctance to take broader
> > changes to type1. After all, that was my main motivation for putting
> > this patch series together in the first place. I wanted refcounting to
> > work properly for reserved GUP-pinned pages (e.g. DevDax).
> >
> > That said, I would definitely prefer to keep all 3 patches so external
> > page pinning stays consistent as well.
> >
> > >
> > > More reviews would of course be welcome. Thanks,
> >
> > Sounds good, I'll ask a few folks internally to take a look and help
> > review.
>
> I ran a local sashiko review with codex that came up with this issue on
> patch 2 that I haven't been able to dismiss yet:
>
> ---
> > @@ -742,32 +762,20 @@ static long vfio_pin_pages_remote(struct vfio_dma *dma, unsigned long vaddr,
>
> [ ... ]
>
> > nr_pages = num_pages_contiguous(
> > &batch->pages[batch->offset],
> > batch->size);
> > - if (!rsvd) {
> > - acct_pages = nr_pages;
> > - acct_pages -= vpfn_pages(dma, iova, nr_pages);
> > - }
> > + acct_pages = nr_pages - vpfn_pages(dma, iova, nr_pages);
>
> [Severity: Medium]
> Could this introduce a memlock accounting regression in
> vfio_pin_pages_remote() in drivers/vfio/vfio_iommu_type1.c when a single
> registered range contains both reserved pages pinned through /dev/dax and
> pages mapped through /dev/mem, even without external pins?
>
> The reserved pinned pages now contribute to acct_pages. With both
> has_pfnmap and has_gup_pinned set, vfio_unpin_pages_remote() uses put_pfn(),
> which skips reserved pages and returns zero for them. Wouldn't their new
> charges therefore be omitted from unlocked?
>
> vfio_unmap_unpin() subtracts only unlocked, and vfio_remove_dma() frees the
> bookkeeping without reconciling the remaining dma->locked_vm. Could repeated
> map/unmap operations therefore exhaust the process's memlock limit? The
> same imbalance can occur during mapping-failure cleanup and
> vfio_iommu_replay() rollback once both flags are set.
>
> The reserved-page pin leak already existed, but the baseline did not charge
> these pages. The follow-up change to external-pin accounting leaves this
> case unchanged. Could the mixed-mapping cleanup also balance these newly
> introduced charges?
> ---
>
> While the scenario is unlikely, it's a new accounting regression.
> Anything we can do short of disallowing these mixed mappings? Thanks,
>
> Alex
The PFNMAP range tracking I pointed to in my reply to patch 2 should also
cover this: every GUP-pinned page is unpinned and uncharged at unmap, even
when the vfio_dma also has PFNMAP ranges, so mixed mappings stay allowed and
the new charge is balanced. (My sample branch is only build-tested.)
prev parent reply other threads:[~2026-12-02 0:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:56 [PATCH 0/3] vfio/type1: Fix pin leaks for reserved GUP-pinned pages Aaron Lewis
2026-11-19 18:56 ` [PATCH 1/3] vfio/type1: Skip reserved PFNs in vpfn_pages() Aaron Lewis
2026-12-01 23:42 ` Vipin Sharma
2026-11-19 18:56 ` [PATCH 2/3] vfio/type1: Track GUP vs PFNMAP in DMA map/unmap Aaron Lewis
2026-11-19 19:12 ` sashiko-bot
2026-12-02 0:07 ` Vipin Sharma
2026-11-19 18:56 ` [PATCH 3/3] vfio/type1: Track GUP vs PFNMAP in external page pinning Aaron Lewis
2026-11-19 20:27 ` [PATCH 0/3] vfio/type1: Fix pin leaks for reserved GUP-pinned pages Jason Gunthorpe
2026-11-20 16:59 ` Aaron Lewis
2026-11-25 19:34 ` Alex Williamson
2026-11-30 14:40 ` Aaron Lewis
2026-11-30 23:52 ` Alex Williamson
2026-12-02 0:25 ` Vipin Sharma [this message]
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=20261202002319.GD2554154.vipinsh@google.com \
--to=vipinsh@google.com \
--cc=aaronlewis@google.com \
--cc=alex@shazbot.org \
--cc=dmatlack@google.com \
--cc=jgg@nvidia.com \
--cc=kvm@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.