From: sashiko-bot@kernel.org
To: "Shivank Garg" <shivankg@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/9] KVM: guest_memfd: implement folio migration for non-confidential VMs
Date: Wed, 05 Aug 2026 07:09:07 +0000 [thread overview]
Message-ID: <20260805070908.0B6351F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805-shivank-gmem-migrate-v3-3-00d8bdec4e1d@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Pre-existing ABBA deadlock between folio lock and filemap_invalidate_lock in kvm_gmem_error_folio
--
--- Patch [3]: [PATCH v3 3/9] KVM: guest_memfd: implement folio migration for non-confidential VMs ---
commit 7a6778b9d1b7f5633978063ee1c7ee906f8f31c4
Author: Shivank Garg <shivankg@amd.com>
KVM: guest_memfd: implement folio migration for non-confidential VMs
This commit implements the folio migration callback for guest_memfd using
filemap_migrate_folio(). It explicitly uses a trylock for the invalidate lock
to avoid an ABBA deadlock with the truncation path.
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 169f75f954337..583341d593c93 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
[ ... ]
> @@ -488,13 +488,45 @@ static struct file_operations kvm_gmem_fops = {
[ ... ]
> + /*
> + * Migration invokes ->migrate_folio() while holding the folio lock.
> + * Use a non-blocking trylock to avoid inverting the lock order with
> + * truncation, which takes the invalidate lock before locking the
> + * folios.
> + */
> + if (!filemap_invalidate_trylock_shared(mapping))
> + return -EAGAIN;
[ ... ]
> static int kvm_gmem_error_folio(struct address_space *mapping, struct folio *folio)
> {
> pgoff_t start, end;
>
> filemap_invalidate_lock_shared(mapping);
[Severity: High]
This is a pre-existing issue, but does kvm_gmem_error_folio() suffer from the
same ABBA deadlock that you correctly avoided in the new migration path?
The truncation path in kvm_gmem_punch_hole() acquires the invalidate_lock for
write, and then acquires folio locks during truncate_inode_pages_range().
Concurrently, if a hardware memory error occurs, memory_failure() acquires the
folio lock before calling the error_remove_folio callback (which is routed to
kvm_gmem_error_folio()). This callback then unconditionally calls
filemap_invalidate_lock_shared(), resulting in an inversion:
Thread 1 (Truncation):
kvm_gmem_punch_hole()
filemap_invalidate_lock(inode->i_mapping);
truncate_inode_pages_range(...)
folio_lock(folio);
Thread 2 (Memory Failure):
memory_failure()
folio_lock(folio);
kvm_gmem_error_folio(...)
filemap_invalidate_lock_shared(mapping);
Should this error path also use filemap_invalidate_trylock_shared() or another
mechanism to avoid the deadlock?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-shivank-gmem-migrate-v3-0-00d8bdec4e1d@amd.com?part=3
next prev parent reply other threads:[~2026-08-05 7:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 6:40 [PATCH v3 0/9] KVM: guest_memfd: folio migration for non-confidential VMs Shivank Garg
2026-08-05 6:40 ` [PATCH v3 1/9] KVM: guest_memfd: take the invalidate lock when unbinding a dying file Shivank Garg
2026-08-05 7:06 ` sashiko-bot
2026-08-05 6:40 ` [PATCH v3 2/9] mm: split AS_UNMOVABLE back out of AS_INACCESSIBLE Shivank Garg
2026-08-05 6:40 ` [PATCH v3 3/9] KVM: guest_memfd: implement folio migration for non-confidential VMs Shivank Garg
2026-08-05 7:09 ` sashiko-bot [this message]
2026-08-05 6:40 ` [PATCH v3 4/9] KVM: guest_memfd: add GUEST_MEMFD_FLAG_MIGRATABLE Shivank Garg
2026-08-05 7:08 ` sashiko-bot
2026-08-05 6:40 ` [PATCH v3 5/9] KVM: selftests: fix maxnode arguments in xapic_ipi_test Shivank Garg
2026-08-05 6:40 ` [PATCH v3 6/9] KVM: selftests: use BITS_PER_TYPE() for NUMA masks Shivank Garg
2026-08-05 6:40 ` [PATCH v3 7/9] KVM: selftests: add get_numa_mem_nodes() Shivank Garg
2026-08-05 6:40 ` [PATCH v3 8/9] KVM: selftests: use allowed NUMA nodes in guest_memfd_test Shivank Garg
2026-08-05 6:40 ` [PATCH v3 9/9] KVM: selftests: exercise guest_memfd folio migration Shivank Garg
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=20260805070908.0B6351F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shivankg@amd.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox