From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F9F948C8C5; Thu, 7 May 2026 20:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778185370; cv=none; b=Ibit52LNaI9GLHEvLkhF4NCI7/yDGyKqrpOeTE/YNqW1pnMq7FJAvuDfBnUcqL2O7ofVDoVk9q/90dpcwalT6mzPLsYspme4NvKJDF/AT4XZIaOW4yGl8nM3tFTq3xp46NPmFmI0Y+tQ0wXG4+62ljdLVDHTy+tEbyiR91RCNxo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778185370; c=relaxed/simple; bh=fFtmWEB2rVwOQInVf+/O+AAAmMZe98X9Uk/1RyXVqxs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XBfAMX6Vzy6OxKpXIUaHjEIThoJvldHYYVHCR9WsNwHB6G/xXHMln4bZSiQX83dKs7FMq5eyxtIlAa6RcOKwUIokKToZXdPDcTHZLkZdFchDh2G0EDCQ/TsDfgIduCep/D8SlhHU/EEaUTSSqXqG9WxhfIOwyXcraAC38krK+sk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mvaP+oVt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mvaP+oVt" Received: by smtp.kernel.org (Postfix) with ESMTPS id 81C1BC2BCB8; Thu, 7 May 2026 20:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778185370; bh=fFtmWEB2rVwOQInVf+/O+AAAmMZe98X9Uk/1RyXVqxs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mvaP+oVtXNE1T3F7BFnHbkR0Do5+V2YtbUZCI/B0LSJ2RoHZfunSBYn/JQRQSA276 u7KLzCm9oYvABACug7hPzVufNH+iIOPLpjsYxO7ytwcfU/u4L3H1KXwGZ6JTPA5UiE v/NkmacUD+HyBiyP+/neQWt5EO5fm91bxwPYWFm404KVJwyolzAIgsv07DJS3J5Pkm DAndgl+NjPQ6GclpKe9HAvyP9pnRJ+AAaDm3j5YC+FNyUj/yvDQDtv3zknIVkWefn+ pLqC8Iu1mqXAsOizt5TA2nHfpLr51doOQrkf2tiKqZuPo7yAZOkWYSj3X8slp/QdiA BV7v8RDD8Z1gg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7347FCD343F; Thu, 7 May 2026 20:22:50 +0000 (UTC) From: Ackerley Tng via B4 Relay Date: Thu, 07 May 2026 13:22:35 -0700 Subject: [PATCH v6 16/43] KVM: guest_memfd: Use actual size for invalidation in kvm_gmem_release() Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260507-gmem-inplace-conversion-v6-16-91ab5a8b19a4@google.com> References: <20260507-gmem-inplace-conversion-v6-0-91ab5a8b19a4@google.com> In-Reply-To: <20260507-gmem-inplace-conversion-v6-0-91ab5a8b19a4@google.com> To: aik@amd.com, andrew.jones@linux.dev, binbin.wu@linux.intel.com, brauner@kernel.org, chao.p.peng@linux.intel.com, david@kernel.org, ira.weiny@intel.com, jmattson@google.com, jthoughton@google.com, michael.roth@amd.com, oupton@kernel.org, pankaj.gupta@amd.com, qperret@google.com, rick.p.edgecombe@intel.com, rientjes@google.com, shivankg@amd.com, steven.price@arm.com, tabba@google.com, willy@infradead.org, wyihan@google.com, yan.y.zhao@intel.com, forkloop@google.com, pratyush@kernel.org, suzuki.poulose@arm.com, aneesh.kumar@kernel.org, liam@infradead.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Shuah Khan , Shuah Khan , Vishal Annapurve , Andrew Morton , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Youngjun Park , Qi Zheng , Shakeel Butt , Kiryl Shutsemau , Jason Gunthorpe , Vlastimil Babka Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, Ackerley Tng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1778185365; l=1535; i=ackerleytng@google.com; s=20260225; h=from:subject:message-id; bh=LSFEUZnHaOopcxqUEi0sDjR1Doime7tSJ4O6yqxwRt0=; b=/vOP4AdpdOPvG0vm/pWq6fbnDjc3tTn7sEYOQboWhIq67Ao5ApttT2OLD+kQoR9LNtnsKf+tf 6p0lDRmkhG6BqVgy195ik79HDXsZwZRhvx0PXefOX24yR8AcenlQKt0 X-Developer-Key: i=ackerleytng@google.com; a=ed25519; pk=sAZDYXdm6Iz8FHitpHeFlCMXwabodTm7p8/3/8xUxuU= X-Endpoint-Received: by B4 Relay for ackerleytng@google.com/20260225 with auth_id=649 X-Original-From: Ackerley Tng Reply-To: ackerleytng@google.com From: Ackerley Tng __kvm_gmem_invalidate_begin() and __kvm_gmem_invalidate_end() actually do not specially handle -1ul. -1ul is used as a huge number, which legal indices do not exceed, and hence the invalidation works as expected. Since a later patch is going to make use of the exact range, calculate the size of the guest_memfd inode and use it as the end range for invalidating SPTEs. Signed-off-by: Ackerley Tng --- virt/kvm/guest_memfd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 050a8c092b1a3..9f6eebfb68f6b 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -370,6 +370,7 @@ static int kvm_gmem_release(struct inode *inode, struct file *file) struct kvm_memory_slot *slot; struct kvm *kvm = f->kvm; unsigned long index; + pgoff_t end; /* * Prevent concurrent attempts to *unbind* a memslot. This is the last @@ -396,9 +397,10 @@ static int kvm_gmem_release(struct inode *inode, struct file *file) * Zap all SPTEs pointed at by this file. Do not free the backing * memory, as its lifetime is associated with the inode, not the file. */ - __kvm_gmem_invalidate_begin(f, 0, -1ul, + end = i_size_read(inode) >> PAGE_SHIFT; + __kvm_gmem_invalidate_begin(f, 0, end, kvm_gmem_get_invalidate_filter(inode)); - __kvm_gmem_invalidate_end(f, 0, -1ul); + __kvm_gmem_invalidate_end(f, 0, end); list_del(&f->entry); -- 2.54.0.563.g4f69b47b94-goog