From: sashiko-bot@kernel.org
To: "Claudio Imbrenda" <imbrenda@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org
Subject: Re: [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error
Date: Mon, 13 Jul 2026 15:31:13 +0000 [thread overview]
Message-ID: <20260713153114.46BB71F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260713150857.269954-7-imbrenda@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] The condition `!vcpu->arch.sie_block->scaol` incorrectly assumes `scaol` is always non-zero for a valid SCA physical address, which can lead to silently skipping ESCA cleanup for valid vCPUs.
Pre-existing issues:
- [Critical] In `sca_add_vcpu()`, the hardware-visible ESCA `mcn` validity bit is set before the `sda` (State Description Address) pointer is written, exposing an uninitialized (zero) `sda` to concurrent hardware SIGP operations.
- [High] The patch fixes the clearing of the ESCA entry in `sca_del_vcpu()` during duplicate vCPU destruction, but misses an identical issue in `sca_clear_ext_call()` which also corrupts the original vCPU's ESCA state.
- [High] Memory leak of `vcpu->arch.mc` on the error path of `kvm_arch_vcpu_create()`.
--
--- Patch [6]: [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error ---
commit 2c6e0529648df791186dd5602fe55245586d90d7
Author: Claudio Imbrenda <imbrenda@linux.ibm.com>
KVM: s390: Fix overclearing ESCA in case of error
If an attempt is made to create a vCPU with an already existing ID,
the duplicated vCPU will be destroyed. When destroying a vCPU, its
ESCA entry will be cleared. This patch fixes a regression where the
original vCPU ESCA entry was erroneously cleared by checking if the
pointer to the ESCA is set.
> diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
> index fc0a884d7f549..6339a327a7be2 100644
> --- a/arch/s390/kvm/kvm-s390.c
> +++ b/arch/s390/kvm/kvm-s390.c
> @@ -3458,7 +3458,7 @@ static void sca_del_vcpu(struct kvm_vcpu *vcpu)
> {
> struct esca_block *sca = vcpu->kvm->arch.sca;
>
> - if (!kvm_s390_use_sca_entries())
> + if (!kvm_s390_use_sca_entries() || !vcpu->arch.sie_block->scaol)
[Severity: High]
Is it possible for scaol to legitimately be zero here?
Since scaol stores the lower 32 bits of the ESCA block physical address, if
the block allocated via alloc_pages_exact() happens to be 4GB aligned
(e.g., 0x100000000), scaol would evaluate to zero.
Would this cause the cleanup to be skipped for a fully initialized vCPU,
leaving the mcn bit set and sda pointing to a freed sie_block? Can this
cause a use-after-free if hardware receives a SIGP for the freed vCPU ID?
> return;
>
> clear_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);
[Severity: High]
This is a pre-existing issue, but it looks like a similar regression exists
in sca_clear_ext_call().
When a duplicate vCPU is destroyed, kvm_arch_vcpu_destroy() calls
kvm_s390_clear_local_irqs(), which invokes sca_clear_ext_call(). Without a
similar initialization check, this unconditionally zeroes the sigp_ctrl:
arch/s390/kvm/interrupt.c:sca_clear_ext_call() {
...
WRITE_ONCE(sigp_ctrl->value, 0);
...
}
Will this silently drop pending external calls or emergency signals for the
original, legitimate vCPU?
[Severity: High]
This is a pre-existing issue, but I noticed a potential memory leak on the
error path of kvm_arch_vcpu_create().
If an initialization step fails after vcpu->arch.mc is allocated via
kvm_s390_new_mmu_cache(), the error path frees vcpu->arch.sie_block but
appears to omit freeing vcpu->arch.mc:
arch/s390/kvm/kvm-s390.c:kvm_arch_vcpu_create() {
...
out_free_sie_block:
free_page((unsigned long)(vcpu->arch.sie_block));
return rc;
}
Does this code leak the memory allocated for the mmu_cache?
[Severity: Critical]
This is a pre-existing issue, but the initialization order in sca_add_vcpu()
seems risky.
The mcn validity bitmask is set before the sda pointer is written:
arch/s390/kvm/kvm-s390.c:sca_add_vcpu() {
...
set_bit_inv(vcpu->vcpu_id, (unsigned long *)sca->mcn);
sca->cpu[vcpu->vcpu_id].sda = virt_to_phys(vcpu->arch.sie_block);
...
}
Can a concurrent hardware SIGP instruction from another vCPU observe the
valid mcn bit and read an uninitialized sda pointer before the host software
writes the SIE block address?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713150857.269954-1-imbrenda@linux.ibm.com?part=6
next prev parent reply other threads:[~2026-07-13 15:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 15:08 [PATCH v2 0/7] KVM: s390: Misc fixes Claudio Imbrenda
2026-07-13 15:08 ` [PATCH v2 1/7] KVM: s390: Fix unlikely NULL gmap dereference Claudio Imbrenda
2026-07-13 15:47 ` sashiko-bot
2026-07-14 8:32 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 2/7] KVM: s390: Return -EFAULT instead of PGM_ADDRESSING Claudio Imbrenda
2026-07-13 15:27 ` sashiko-bot
2026-07-14 8:44 ` Steffen Eiden
2026-07-13 15:08 ` [PATCH v2 3/7] KVM: s390: Fix race in __do_essa() Claudio Imbrenda
2026-07-13 15:31 ` sashiko-bot
2026-07-13 15:08 ` [PATCH v2 4/7] KVM: s390: cmma: Fix dirty tracking when removing memslot Claudio Imbrenda
2026-07-13 15:58 ` sashiko-bot
2026-07-13 15:08 ` [PATCH v2 5/7] KVM: s390: ucontrol: Add missing locking around gmap_remove_child() Claudio Imbrenda
2026-07-13 15:29 ` sashiko-bot
2026-07-13 15:08 ` [PATCH v2 6/7] KVM: s390: Fix overclearing ESCA in case of error Claudio Imbrenda
2026-07-13 15:31 ` sashiko-bot [this message]
2026-07-13 15:08 ` [PATCH v2 7/7] KVM: s390: Return -EINTR if a signal was pending while faulting-in Claudio Imbrenda
2026-07-13 15:33 ` 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=20260713153114.46BB71F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@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