From: sashiko-bot@kernel.org
To: "Christoph Schlameuss" <schlameuss@linux.ibm.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH 17/21] KVM: s390: vsie: Allow guest-3 cpu add and remove with vsie sigpif
Date: Thu, 09 Jul 2026 15:35:29 +0000 [thread overview]
Message-ID: <20260709153529.E856D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-vsie-sigpi-v1-17-ea9f12066408@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [High] If `_shadow_sca()` encounters a transient error, it prematurely updates the cached MCN but zeroes out the shadow SCA, permanently breaking VSIE SIGP handling.
- [High] Dynamic MCN updates fail to clear shadow SCA entries for removed vCPUs, leaving stale pointers that the hardware may access.
- [High] Mismatch between cached `vsie_sca->flags` and actual guest SCA format leads to copying garbage MCN data from wrong offsets.
- [Low] Incorrect pointer type `struct kvm_s390_sie_block *` is used for the guest SCA page.
Pre-existing issues:
- [Critical] get_sca_entry_addr() incorrectly calculates the host physical address (HPA) of SCA entries located past the first page, leading to arbitrary host physical memory access.
--
--- Patch [17]: [PATCH 17/21] KVM: s390: vsie: Allow guest-3 cpu add and remove with vsie sigpif ---
commit c4d503d35381889298738f17763bcbfdd845d493
Author: Christoph Schlameuss <schlameuss@linux.ibm.com>
KVM: s390: vsie: Allow guest-3 cpu add and remove with vsie sigpif
This commit enables dynamically adding and removing guest-3 CPUs in KVM
by shadowing the SCA and re-initializing the shadow SCA whenever the guest's
multi-cpu configuration (MCN) changes. It introduces caching and comparison
of the expected MCN to detect when the layout changes.
> diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c
> index 74455c689c51b..de8931e714ca2 100644
> --- a/arch/s390/kvm/vsie.c
> +++ b/arch/s390/kvm/vsie.c
[ ... ]
> +static void sca_mcn_copy(struct vsie_sca *vsie_sca, void *sca)
> +{
> + int offset = offsetof(struct bsca_block, mcn);
> + int size = BYTES_PER_LONG;
> +
> + if (test_bit(VSIE_SCA_ESCA, &vsie_sca->flags)) {
[Severity: High]
If a guest switches a control block from BSCA to ESCA (or vice versa) while
keeping the same physical sca_gpa, will the cached VSIE_SCA_ESCA flag in
vsie_sca->flags be stale?
Later in _shadow_sca(), the layout is determined dynamically using
sie_uses_esca(vsie_page->scb_o). If these disagree, could sca_mcn_copy() read
garbage memory from the wrong MCN offset?
> + offset = offsetof(struct esca_block, mcn);
> + size = BYTES_PER_LONG * 4;
> + }
> + memcpy(&vsie_sca->mcn, sca + offset, size);
> +}
[ ... ]
> static int _shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page,
> struct vsie_sca *vsie_sca)
> {
[ ... ]
> - if (is_esca)
> - mcn = phys_to_virt(sca_o_hpa) + offsetof(struct esca_block, mcn);
> - else
> - mcn = phys_to_virt(sca_o_hpa) + offsetof(struct bsca_block, mcn);
> + sca_mcn_copy(vsie_sca, phys_to_virt(sca_o_hpa));
[Severity: High]
If _shadow_sca() encounters an error later in this function, could this early
copy of the MCN cause permanent failures?
If _shadow_sca() returns an error, vsie_sca->mcn will already be updated to
the new value, while the error path zeroes out the shadow SCA but leaves
vsie_sca->ssca.osca unmodified.
On the next VSIE entry retry, shadow_sca() will see that sca_mcn_equals() is
true, and skip re-initializing the shadow SCA. Does this leave the guest
with a broken SIGP configuration permanently?
>
> /* pin and make shadow for ALL scb in the sca */
> cpu_slots = is_esca ? KVM_S390_MAX_VSIE_VCPUS : KVM_S390_BSCA_CPU_SLOTS;
> - for_each_set_bit_inv(cpu_nr, mcn, cpu_slots) {
> + for_each_set_bit_inv(cpu_nr, (unsigned long *)&vsie_sca->mcn, cpu_slots) {
[Severity: High]
Does this loop exclusively iterate over the bits set in the new MCN?
If a vCPU was removed by the guest (its MCN bit transitions from 1 to 0), the
loop skips that CPU index entirely. Does this mean the ssda and ossea
pointers for the removed CPU are never cleared, leaving stale pointers that
the hardware might still access?
> rc = get_sca_entry_addr(vcpu->kvm, vsie_sca, cpu_nr, NULL, &sca_o_entry_hpa);
[Severity: Critical]
This is a pre-existing issue, but looking at get_sca_entry_addr() called
here, is there a problem with how it calculates the host physical address
for SCA entries past the first page?
arch/s390/kvm/vsie.c:get_sca_entry_addr() {
...
if (hpa)
*hpa = vsie_sca->sca_o_pages[pn].hpa + offset;
...
}
Because offset is the total byte offset from the start of the SCA block, and
sca_o_pages[pn].hpa is already the physical address of the specific pn-th
page, does adding offset again push the resulting HPA massively out of
bounds?
> if (rc)
> goto err;
[ ... ]
> /* Shadow or reshadow the SCA on VSIE enter. */
> static int shadow_sca(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page, struct vsie_sca *vsie_sca)
> {
> - int rc = 0;
> + struct kvm_s390_sie_block *sca_o = phys_to_virt(vsie_sca->sca_o_pages[0].hpa);
[Severity: Low]
This isn't a bug, but sca_o is typed as a State Control Block
(struct kvm_s390_sie_block *) when the memory appears to actually be a System
Control Area (struct bsca_block or struct esca_block). Could this static
typing make the code confusing to read?
> + bool do_init_ssca;
>
> - guard(rwsem_write)(&vcpu->kvm->arch.vsie.vsie_sca_lock);
> - if (!vsie_sca->ssca.osca)
> - rc = _shadow_sca(vcpu, vsie_page, vsie_sca);
> + scoped_guard(rwsem_read, &vcpu->kvm->arch.vsie.vsie_sca_lock) {
> + do_init_ssca = !vsie_sca->ssca.osca;
> + do_init_ssca = do_init_ssca || !sca_mcn_equals(vsie_sca, sca_o);
> + if (!do_init_ssca)
> + return 0;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-vsie-sigpi-v1-0-ea9f12066408@linux.ibm.com?part=17
next prev parent reply other threads:[~2026-07-09 15:35 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 15:15 [PATCH 00/21] KVM: s390: vsie: Add VSIE SIGP Interpretation (vsie_sigpi) Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 01/21] KVM: s390: Remove double 64bscao feature check Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 02/21] KVM: s390: vsie: Remove duplicate assertion Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 03/21] KVM: s390: vsie: Convert shift to phys_to_pfn() Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 04/21] KVM: s390: vsie: Add SCAO read and write helpers Christoph Schlameuss
2026-07-09 15:24 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 05/21] KVM: s390: vsie: Move SCAO validation into a function Christoph Schlameuss
2026-07-09 15:26 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 06/21] KVM: s390: vsie: Add vsie_sigpif detection Christoph Schlameuss
2026-07-09 15:32 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 07/21] KVM: s390: vsie: Add ssca_block and ssca_entry structs for vsie_ie Christoph Schlameuss
2026-07-09 15:24 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 08/21] KVM: s390: vsie: Move pin/unpin_scb methods Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 09/21] KVM: s390: vsie: Move pin/unpin guest page Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 10/21] KVM: s390: vsie: Move release/acquire gmap shadow Christoph Schlameuss
2026-07-09 15:15 ` [PATCH 11/21] KVM: s390: vsie: Create helpers to alloc and free vsie_pages Christoph Schlameuss
2026-07-09 15:23 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 12/21] KVM: s390: vsie: Replace radix_tree with xarray addr_to_page Christoph Schlameuss
2026-07-09 15:25 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 13/21] KVM: s390: vsie: Add helper to pin multiple guest pages Christoph Schlameuss
2026-07-09 15:28 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 14/21] KVM: s390: vsie: Add helper to release gmap shadow Christoph Schlameuss
2026-07-09 15:30 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 15/21] KVM: s390: vsie: Add struct vsie_sca with pin and unpin Christoph Schlameuss
2026-07-09 15:31 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 16/21] KVM: s390: vsie: Shadow VSIE SCA in guest-1 Christoph Schlameuss
2026-07-09 15:37 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 17/21] KVM: s390: vsie: Allow guest-3 cpu add and remove with vsie sigpif Christoph Schlameuss
2026-07-09 15:35 ` sashiko-bot [this message]
2026-07-09 15:15 ` [PATCH 18/21] KVM: s390: vsie: Add VSIE max shadow configuration Christoph Schlameuss
2026-07-09 15:35 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 19/21] KVM: s390: vsie: Add VSIE shadow stat counters Christoph Schlameuss
2026-07-09 15:30 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 20/21] KVM: s390: vsie: Create minimal scb shadows for not running g3 blocks Christoph Schlameuss
2026-07-09 15:47 ` sashiko-bot
2026-07-09 15:15 ` [PATCH 21/21] KVM: s390: vsie: Enable VSIE SIGPI Christoph Schlameuss
2026-07-09 15:44 ` 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=20260709153529.E856D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=schlameuss@linux.ibm.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