Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796168562; b=GknzTOMFlIffP1FEz7bVaak2h0uqKsVISJ/lZZJyfTfF9p8k1cYdqHssWMvcxEIgUhl/ wT9/8MBcvsc1k+qMuyuTW+BeK6BZdAUmK9L7S2pe0qXv60wNXhV/UOn+kqex0w0WmiaVG BiLvM08vi36pdyWDc+A+rn0xtMjeFZF8U11ZhDUMmrqcL4b01eJqPLfa283xhTK4fWKRS 6wzU6n+nYMORKXXNL7NcFYOcCWzLUm5GCRhjkCLeElnXbgwrpiPRx5GXlGtdfHssA0GI9 i2bwUU3nL5ChSkcfRyYjFdpUW1FXNQ9ieR/V7TkjZqv0a9T+yl+uRLl5EsK+y2iNzzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796168562; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=/fZWOQhQBtKcWtyHhRs72b9rovQm7Jw2y/j2MSRFxTw=; b=QbvJnLO+H+a3P0K6J4trTiP0YEijJ4Tc09qJoVAyqkEMGJHnfpXPWj8Bs3bwrkTBgoyq VCEw8wjHLXO2VV1KOxQ2iAQZl/y8LEKvtDqt48/Wi6wQYC6f3rhtID54KbiWNHYoZMXtY T7fbvpdiI7b7kodRIBAUKhmxeFBEDqgYGpYz+tNYrzGc4DvkUs5uiqoEywyjgCpmwkSAG ZF4qiqqzJPu0oZgZ+DeJqVsjdvcFdw2jDoBsEzBBSUqT/ssB0uIjZJdWvAQlZtLaQfTc4 HUahFRKN1+29fAJfwzTt1iN8gd3PzicsqEQ7rMrZHB0qYvi/OOE0oM3/iRPcvvHDQxg== 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=NPGJd3Ao; arc=none smtp.remote-ip=209.85.214.178 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 99F30606A31A for ; Tue, 1 Dec 2026 23:42:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99F30606A31A 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=NPGJd3Ao Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2f0e8bbc7a4so2345ad.1 for ; Tue, 01 Dec 2026 15:42:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796168561; x=1796773361; 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=/fZWOQhQBtKcWtyHhRs72b9rovQm7Jw2y/j2MSRFxTw=; b=NPGJd3Ao+3SHCas1MefLvBEEGlpqyoxaNUt2q1Nu1AGzfo/J1Jz6EgmRCez/+hlZYA HYVTbABjK2VRRKeAEXVa0putBwja8w2kKBH5lX0cErhtrCxX29guh5Cab67sNJ9wBfjN ID3rGS5EtgrcJw09rQgHQUlVA5GO8Isvzy85SjjNINsn4aghJnX/jA9VtKoaGXeHtPbU iT9v232JKBLobbxv0VvzvDnB5IdwgL58Rl3cpd3CCBI9FM/yOuuHjVHre+XyQmYpfJCR jLTBvHgK9OCTz5Af/r3ForaZp4UZzTCEo5Mmzuti9UpPLi3AvAJodbXK3WwdPPAGDIUF urcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796168561; x=1796773361; 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=/fZWOQhQBtKcWtyHhRs72b9rovQm7Jw2y/j2MSRFxTw=; b=XJgEQi2lyKAikHQopoNXu0NmjiFsfi6T8odo4PDk82T8iDAJOPKB/bxpLCn4EzT+gg PcaLAiN67f7pOtIJ59PzRw5Sqq+pdy79Ns7XWnmXrdCYGb1CmR55d9C9VibtCxdWLCFM 6wvwrz1+gMtPB9RdL4OAITQqXOt9bB8TOZmQRo4LdzmQo0kd0deHGWBjwUkbcaqBqVZ/ gRBu58n+ExtMySx40WxWV8IGz2HwcoXW7s1Loc4BPVh2+MfmXGU1N7ew3i0B8Y/q30Yp ThZruomKzxzp1YosdV4GnUiUWGDYELdsgfifkCrTK+JEgJOrLO7ZJ2oh8x/akSzEwapi CMDg== X-Gm-Message-State: APuU4Z/kaMhxy71PBivS9DC/0NJqwtAEYR2H34keyeabnyTaDpcIUpB7 B3saTkGnBMWawiqYukKHCmb1vxSe2pXSkOh7nvEtyWCbY2y01O/oOOKiRejCRiAVMDL6hkWUpCi 18JacbA== X-Gm-Gg: AZFdTZdwP0H/+IRt+R10v9UkGnnC3SSLPzR+FxIGG1cIQPt5lpjRSaNuE+hrmTymS33 aG3CQD58xEnc9Vvt7peuWHWR0ncHmNzNRe78Qqq5hr4R4pAIFmTeLLCQhuDBqAcePFwoFAIUoz0 LWRUv3A5o2/bttzbYLf8mZpO3KwbDGr82r7u7IXGeVEJ06cHLc4F+Bkop6qExRfnIc9kP1mvIVq hJbHu3DrMozl2/H7Bb+jBYEod4SR0uaWIjrX79r5kHLIM8bgILpi3yWjqSTcQwoeRiynS/hRWjB magsXmWe5KAHzy2+jyzfZ3UfBPP7dMVyp65b8ThdOPgCjdsx5Z+bGn4syLj8nauKLNieCOtNba4 RSHydVl5IzZmwHM5XI+XJOzAuEoEWCxG7MP0UV8GCxkXBwVixIEfK9EXLHT3te63bmDV/gpl5UV C5oWdqjOmxSNJ726NSjVBSUj5yMYCI1IqFRqPIoDJi9HSRAdumO5L2/w3aEOa5Ahr1nY+i0ZzOQ 4Dq8qQ77HdwIzUsCamy+E8PuqsVTkX6Exs8NayCEIyhABUTF5e4XD33GQx/hYy8roWLOYrpkHve 16jPFt2zM3sn0uMtlEqFl89RYaV+zOn3C0Lu/3J/lNmbgR3rFaNGcqos/Xs/Nmw= X-Received: by 2002:a17:903:3d0d:b0:2e9:73e0:2a6e with SMTP id d9443c01a7336-2f17a11b714mr193345ad.17.1796168560276; Tue, 01 Dec 2026 15:42:40 -0800 (PST) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad0a34asm59539610a91.3.2026.12.01.15.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 15:42:39 -0800 (PST) Date: Tue, 1 Dec 2026 15:42:35 -0800 From: Vipin Sharma To: Aaron Lewis Cc: kvm@vger.kernel.org, alex@shazbot.org, dmatlack@google.com, jgg@nvidia.com Subject: Re: [PATCH 1/3] vfio/type1: Skip reserved PFNs in vpfn_pages() Message-ID: <20261130214104.GA2554154.vipinsh@google.com> References: <20261119185659.889654-1-aaronlewis@google.com> <20261119185659.889654-2-aaronlewis@google.com> 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: <20261119185659.889654-2-aaronlewis@google.com> On Thu, Nov 19, 2026 at 06:56:57PM +0000, Aaron Lewis wrote: > vpfn_pages() is used by vfio_pin_pages_remote() and > vfio_unpin_pages_remote() to count how many pages in an IOVA range are > already accounted in dma->locked_vm via external page pinning. > > However, while vfio_pin_page_external() and > vfio_iommu_unmap_unpin_reaccount() skip invalid and reserved PFNs when > accounting dma->locked_vm, vpfn_pages() counts every entry in > dma->pfn_list indiscriminately. If a reserved PFN is externally pinned, > vpfn_pages() reports it as accounted in dma->locked_vm even though it > never was. > > As a result, vfio_unpin_pages_remote() inflates locked_vm when it > unwinds a failed vfio_iommu_replay(). vfio_pin_pages_remote() would > under-account for the same reason, but today it only consults > vpfn_pages() for runs that start with a non-reserved PFN. A subsequent > patch removes that restriction and relies on vpfn_pages() being exact. > > Check is_invalid_reserved_pfn() in vpfn_pages() so it only counts > externally pinned PFNs that were actually accounted. > > Fixes: f6c84a52cc41 ("vfio/type1: optimize vfio_pin_pages_remote()") > Fixes: d10872050ffe ("vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote()") > Signed-off-by: Aaron Lewis Reviewed-by: Vipin Sharma