Thread (186 messages) 186 messages, 12 authors, 2h ago

Re: [PATCH v8 19/46] KVM: guest_memfd: Use actual size for invalidation in kvm_gmem_release()

From: Fuad Tabba <hidden>
Date: 2026-06-19 10:46:45
Also in: kvm, linux-coco, linux-doc, linux-kselftest, linux-mm, lkml

On Fri, 19 Jun 2026 at 01:31, Ackerley Tng via B4 Relay
[off-list ref] wrote:
From: Ackerley Tng <redacted>

__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 <redacted>
---
Reviewed-by: Fuad Tabba <redacted>

Cheers,
/fuad
quoted hunk ↗ jump to hunk
 virt/kvm/guest_memfd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index d163559da0235..d72ecbfcc3144 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -366,6 +366,7 @@ static long kvm_gmem_fallocate(struct file *file, int mode, loff_t offset,

 static int kvm_gmem_release(struct inode *inode, struct file *file)
 {
+       pgoff_t end = i_size_read(inode) >> PAGE_SHIFT;
        struct gmem_file *f = file->private_data;
        struct kvm_memory_slot *slot;
        struct kvm *kvm = f->kvm;
@@ -396,9 +397,9 @@ 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_start(f, 0, -1ul,
+       __kvm_gmem_invalidate_start(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.55.0.rc0.738.g0c8ab3ebcc-goog
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help