Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Naveed Khan" <naveed@digiscrypt.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: s390: gmap: protect entire guest top-level table when shadowing
Date: Tue, 23 Jun 2026 17:06:58 +0000	[thread overview]
Message-ID: <20260623170659.0CFC91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <178223359030.58041.119573473883113694@digiscrypt.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Pre-existing AB-BA deadlock between the gmap `children_lock` and the `kvm->mmu_lock`.
--

commit adfa2afc574e2132990a75c0f57245c13f93a6d8
Author: Naveed Khan <naveed@digiscrypt.com>

KVM: s390: gmap: protect entire guest top-level table when shadowing

This commit updates the top-level guest table protection to use the table
length rather than the designation type. This ensures that the entire table
is write-protected, preventing nested guests from modifying writable
trailing pages and retaining stale translations.

> diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c
> --- a/arch/s390/kvm/gmap.c
> +++ b/arch/s390/kvm/gmap.c
> @@ -1263,7 +1263,7 @@ static int gmap_protect_asce_top_level(struct kvm_s390_mmu_cache *mc, struct gma
>  	/* Pairs with the smp_wmb() in kvm_mmu_invalidate_end(). */
>  	smp_rmb();
>  
> -	rc = kvm_s390_get_guest_pages(sg->kvm, context.f, asce.rsto, asce.dt + 1, false);
> +	rc = kvm_s390_get_guest_pages(sg->kvm, context.f, asce.rsto, asce.tl + 1, false);
>  	if (rc > 0)
>  		rc = -EFAULT;
>  	if (!rc)
>  		rc = _gmap_protect_asce_top_level(mc, sg, &context);

[Severity: Critical]
This isn't a bug introduced by this patch, but is there a pre-existing AB-BA
deadlock between the gmap children_lock and kvm->mmu_lock here?

When unshadowing an existing real-space mapping, gmap_create_shadow() takes
the locks in this order:

arch/s390/kvm/gmap.c:gmap_create_shadow() {
	scoped_guard(spinlock, &parent->children_lock) {
		...
		scoped_guard(write_lock, &parent->kvm->mmu_lock) {
		...
}

Concurrently, when creating a virtual-space shadow, gmap_create_shadow()
releases children_lock and calls gmap_protect_asce_top_level(), which
eventually calls __gmap_protect_asce_top_level() where the locks are
taken in the reverse order:

arch/s390/kvm/gmap.c:__gmap_protect_asce_top_level() {
	guard(write_lock)(&sg->kvm->mmu_lock);
	...
	scoped_guard(spinlock, &parent->children_lock) {
	...
}

Since sg->kvm is identically parent->kvm, could this cause a deadlock
if one VCPU creates a real-space shadow while another concurrently creates a
virtual-space shadow for the same parent gmap?

>  	if (rc)
>  		kvm_s390_release_faultin_array(sg->kvm, context.f, true);
>  	return rc;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/178223359030.58041.119573473883113694@digiscrypt.com?part=1

  reply	other threads:[~2026-06-23 17:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 16:53 [PATCH] KVM: s390: gmap: protect entire guest top-level table when shadowing Naveed Khan
2026-06-23 17:06 ` sashiko-bot [this message]
2026-06-23 17:34 ` Christian Borntraeger

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=20260623170659.0CFC91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=naveed@digiscrypt.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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