From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796171151; b=Vif2kkuBSy46BX+GDNZAUU9ArpuFgmhYMqMa5dhpKy1lTArmUl84OJuLGTBObSFRYihl sVNa/XB5Xj/xPqaf80ChMVsOayooHOXtTDtWdpLsUmvbptBgVzznwUCaT+cc1TkrI2AG6 zOGmVTScg4vbCqENpu1SHpNY3dMbWspH4SWQE7qZ9igo6szK2dUQCfZ6dul335SZVWmCR E0p+ovdq1WOLbhshQJKQLlYOE6lLBMKFiO0tpHuk9PYasiNmHPghvaCxi5KhAZ9zpOCAm 49JOclf/CPQKS+kAfIFG4T/IFm7SWsl1fXVlIOSieJ5Dh0ff3iil+WKZRhoYKgrarXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796171151; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=9lzJKn/qVKDA4Xsyyi25sUQXtXLh8tlZAhahrQu+2NY=; b=R6xnGa4AWBX7QiHFdH3tqbNn1vC9EEkhQzyOdUA3G1DJhGE40Sk431OYRTtxs6trS1Hc UfHdDIKr1JYG286qPObeJZJTtP8/KETxJvVMJwCpQ3zK/OsNRIdDobWSvjKdyQvT2USOx BAr/imPfsAM1N2s2HnNXoJ8KuUcHnDc2B1yJDBb3OXnv1/KV6bkKtYpYgVa9vGfw30vo2 WQAbPNIaWL0VaSJC3hT8JhU8K0+4d8mYFHg/ys5lru+y8Dmnu55yQCBYeC8WOp6XqUbh2 AaX6TB2Lk7gnAaf6lqXdrgc2XW92tLcCgW2uP4PzTHcFqk4PxZH0JVPMroD7xEXYuIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IKMC7QZG; arc=none smtp.remote-ip=209.85.214.173 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0010D606A31A for ; Wed, 2 Dec 2026 00:25:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0010D606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IKMC7QZG Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2f0e8bbc7a4so4085ad.1 for ; Tue, 01 Dec 2026 16:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796171150; x=1796775950; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9lzJKn/qVKDA4Xsyyi25sUQXtXLh8tlZAhahrQu+2NY=; b=IKMC7QZG+lR8J71ImFXrNSbgaYV1UAtTO9GFdwRNBNHQAlM4VCrUb65ui0Ku0TN8VK iss+IoOHlrI1fowoJjrL2rU6bC3A4kxE6DK6YtAbJgpEaIPhLzVGS10xTIgFw9OqfIPs N/JmRcHc+61kIjoKJ9cOyz/h2pdmc1CNanyp83704XnIaDuiuO3GcdDQPvrt27AtH73j nIMVqGQwRVWzf93HbAMq8I5KHjdnmm6g1tJwADLtF8wNerY6yB+894chxDumFFjil+NV 8Xh/a52dC+znrNqiBh7SzW6s2eVK3LYFb/eLNelDdwL05FgUYyir+ZtcAWEWMD5Z2hwS OQ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796171150; x=1796775950; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9lzJKn/qVKDA4Xsyyi25sUQXtXLh8tlZAhahrQu+2NY=; b=rdI9onAzRxm+WgexfgZYHPoQMomRcugyA7v43K4/SbIvGfFSedXpAsVZ0oVxkdKyEI p5Gv6ArDM+I5m5urVU1vNpcbes0T0uWV8EIk+semp5qZIRNwDBshbkJiCNdFhChtplXo nHcA0UVQg7h7i1nwJjFhdsbYRCnkuvSQmBXQf88e6ctnsaUmU3/8KfQNXuQIjpAx1931 VjWQD5iuTDruIKFvT/UkHy1XwLcACHcvN0weRRRCHcO6BlgPFDvE+EgCI6xjXaIZNHf/ YfsSYviZIJTcvI0jwjcGfJ9zOkdArQJA+oes+oSSqrB2YM3wHjmTZXB6gWPmTIFbPzJ7 hgxQ== X-Forwarded-Encrypted: i=1; AL+hErFJEofleCHuKUfFnqxVOC0HL2q3yoMAhHRuywuAb3Vu5Fwb+H3A8tD5793AtCe65cGcAus=@vger.kernel.org X-Gm-Message-State: APuU4Z+61k5gycVSXBq+HvPy6b40+lTwPYpUW9ZUrJlsCl/jpGwUOJA3 m5xqNY7b8N6R/GcQlu6bh1NOcnh09WaqXHvrWhB1hbAh3a+Nf91UIZK1/Fuw1XJgLg== X-Gm-Gg: AZFdTZddzBat1nSj7py+k7n6tER81sLD09616DSUq9Wli0Ap8YpY41hv9ZDgSboYMbJ zC2si0YxnwkirxMehc3ZAp1TiYzwbjeHnq9NNpPzJpQZsyjO77ILLCE+V6+vJ/nL3ZxrER9fSI4 FbiEzED3+z4TOr2cfE6SmLmhcWTfsacgdrUsIFORRRcWKItjydTdS9uHacAX9IYBsaSOYtBbtlJ HOWi3GM8+liHatf0oec80Y6YO/got7/gC1j5OzPNu3hFWOr+Njp0YQb075DvludTG7fWWTm8tXn n30O8MDykVqu5Wd8yFkJMI0Xn6ffBjnKgEpKvpDa24gkUmSmDIHTfGkRkO2D0tmh/Ru5L/mwwzX Y+qz3ZmCNHRedGxR1cS4OXKUJ/y4Hx2ZsXCFo4X/uYRg+/Url3u5tMIzZwP4UfMyq5EuhydHWlu frJbHwJHdk7KSMa1D6MSYsmEPeMq3Zm0L/sEl9EuNMvurmyPakhpZOZPEIMUyBI6phgFZhiFIy9 JTXNO6fUxqUl42du37VOGlYSNwERqB07j4i9rsNNfJ+1+RG8gqn4ICTWOLMwx+HOos1ERNxdRG8 aIIZsFrJ+6HqmMoT7o7oCLMsHD95AciOWJmlp23tX4lKGxukoYpXBS10UwP4ycJLBQ== X-Received: by 2002:a17:902:d98f:b0:2ec:f228:764d with SMTP id d9443c01a7336-2f17a11c6b6mr431665ad.18.1796171149663; Tue, 01 Dec 2026 16:25:49 -0800 (PST) Received: from google.com (176.13.105.34.bc.googleusercontent.com. [34.105.13.176]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b405ecb486sm62508937a91.16.2026.12.01.16.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 16:25:48 -0800 (PST) Date: Tue, 1 Dec 2026 16:25:45 -0800 From: Vipin Sharma To: Alex Williamson Cc: Aaron Lewis , Jason Gunthorpe , kvm@vger.kernel.org, dmatlack@google.com Subject: Re: [PATCH 0/3] vfio/type1: Fix pin leaks for reserved GUP-pinned pages Message-ID: <20261202002319.GD2554154.vipinsh@google.com> References: <20261119185659.889654-1-aaronlewis@google.com> <20261119202713.GU2245175@nvidia.com> <20261125123432.353f392d@shazbot.org> <20261130165227.5cdba5ad@shazbot.org> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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.)