Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 7/8] KVM: s390: Lock pte when making page secure
Date: Mon, 01 Jun 2026 17:10:30 +0000	[thread overview]
Message-ID: <20260601171030.C9FC21F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260601152951.196859-8-imbrenda@linux.ibm.com>

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

Pre-existing issues:
- [Critical] Unconditional conversion of a raw PFN to a folio using `pfn_folio()` in `_kvm_s390_pv_make_secure()` leads to a host kernel panic when applied to device memory.
--

commit e0fa339799f284890bdbcc3dd174cd7125deb24a
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>

KVM: s390: Lock pte when making page secure

This commit ensures that _kvm_s390_pv_make_secure() takes the pte lock
for the given address before freezing the folio during Secure Execution
transitions. This prevents concurrent GUP access while the page is mapped.

> diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
> index c2dafd812a3b2..4b865e75351c1 100644
> --- a/arch/s390/kvm/pv.c
> +++ b/arch/s390/kvm/pv.c
[ ... ]
> @@ -103,9 +105,21 @@ static void _kvm_s390_pv_make_secure(struct guest_fault *f)
>  {
>  	struct pv_make_secure *priv = f->priv;
>  	struct folio *folio;
> +	spinlock_t *ptl;	/* pte lock from try_get_locked_pte() */
> +	pte_t *ptep;
>  
>  	folio = pfn_folio(f->pfn);

[Severity: Critical]
This is a pre-existing issue, but can this unconditional conversion of a raw
PFN to a folio cause a host kernel panic when a guest maps device memory?

If a malicious or misconfigured guest maps device memory (e.g., via VFIO PCI)
into its address space and attempts to transition it to Secure Execution,
KVM's fault-in logic will return a valid PFN but set f->page = NULL for raw
device memory without a vmemmap.

If we unconditionally call pfn_folio(f->pfn) before checking f->page,
pfn_to_page() yields an invalid pointer. The page_folio() wrapper then
immediately dereferences this pointer to read the compound_head field.

Furthermore, even if the PFN is valid but points to a reserved page, the
fallback logic in __kvm_s390_pv_make_secure() could attempt to increment
the refcount of a reserved page:

__kvm_s390_pv_make_secure() {
    ...
    if (!f->page)
        folio_get(folio);
    ...
}

Could this crash the kernel via VM_BUG_ON_FOLIO() on systems with
CONFIG_DEBUG_VM enabled? Should the folio conversion be delayed until
after verifying we have a normal refcounted memory page?

>  	priv->rc = -EAGAIN;
> +
> +	if (!mmap_read_trylock(priv->kvm->mm))
> +		return;
> +
> +	ptep = try_get_locked_pte(priv->kvm->mm, gfn_to_hva(priv->kvm, f->gfn), &ptl);
> +	if (IS_ERR_VALUE(ptep)) {
> +		priv->rc = PTR_ERR(ptep);
> +		goto out;
> +	}
> +
>  	if (folio_trylock(folio)) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260601152951.196859-1-imbrenda@linux.ibm.com?part=7

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

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 15:29 [PATCH v2 0/8] KVM: s390: More gmap and vsie fixes Claudio Imbrenda
2026-06-01 15:29 ` [PATCH v2 1/8] KVM: s390: Fix _gmap_unmap_crste() Claudio Imbrenda
2026-06-01 15:29 ` [PATCH v2 2/8] KVM: s390: Fix _gmap_crstep_xchg_atomic() Claudio Imbrenda
2026-06-01 15:29 ` [PATCH v2 3/8] KVM: s390: Avoid potentially sleeping while atomic when zapping pages Claudio Imbrenda
2026-06-01 16:09   ` sashiko-bot
2026-06-01 15:29 ` [PATCH v2 4/8] KVM: s390: Fix guest / virtual address confusion in _essa_clear_cbrl() Claudio Imbrenda
2026-06-01 16:25   ` sashiko-bot
2026-06-01 15:29 ` [PATCH v2 5/8] KVM: s390: vsie: Fix rmap handling in _do_shadow_crste() Claudio Imbrenda
2026-06-01 16:41   ` sashiko-bot
2026-06-01 15:29 ` [PATCH v2 6/8] KVM: s390: Fix fault-in code Claudio Imbrenda
2026-06-01 16:52   ` sashiko-bot
2026-06-01 15:29 ` [PATCH v2 7/8] KVM: s390: Lock pte when making page secure Claudio Imbrenda
2026-06-01 17:10   ` sashiko-bot [this message]
2026-06-01 15:29 ` [PATCH v2 8/8] KVM: s390: Prevent memslots outside the ASCE range Claudio Imbrenda
2026-06-01 17:26   ` sashiko-bot

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=20260601171030.C9FC21F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --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