mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gautam Gala <ggala@linux.ibm.com>
To: kvm@vger.kernel.org, linux-s390@vger.kernel.org
Cc: borntraeger@linux.ibm.com, frankja@linux.ibm.com,
	imbrenda@linux.ibm.com, david@kernel.org, hca@linux.ibm.com,
	gor@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com,
	pbonzini@redhat.com, seanjc@google.com, shuah@kernel.org,
	ggala@linux.ibm.com, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 1/2] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt
Date: Thu, 19 Nov 2026 13:49:35 +0100	[thread overview]
Message-ID: <20261119124936.33396-2-ggala@linux.ibm.com> (raw)
In-Reply-To: <20261119124936.33396-1-ggala@linux.ibm.com>

shadow_scb() calls prepare_cpuflags() first, which can reject the SCB
provided by guest 2 with a validity interception. This happens before
the guest state (gpsw, gg14, gg15, gcr, cputm, ckc, todpr, pp) and the
control fields (gbea, fpf) are copied from the original SCB into the
shadow SCB.

The error path still calls unshadow_scb(), which copies that state from
the shadow SCB back into the original one. The shadow SCB does not hold
guest 3 state at this point:

 - For a new or recycled vsie page, get_vsie_page() has cleared the
   shadow SCB, so the guest 3 state in the guest 2 SCB is overwritten
   with zeroes.
 - For a cached vsie page that is looked up again by SCB address, the
   shadow SCB still holds the state from the end of the previous run,
   so the current guest 3 state is replaced by the old one.

No guest 3 instruction ran, yet guest 2 sees its guest 3 state (PSW,
GRs, CRs, timers) modified. unshadow_scb() also clears FPF_BPBC if
facility 82 is available, because fpf was cleared in the shadow SCB
just before, and copies back a stale ihcpu.

The SCB and the validity condition are controlled by guest 2, so this
is a correctness problem for guest 2 only and does not cross a guest or
host boundary.

Only the interception data needs to be passed on in this case. Add
unshadow_icpt() for that and use it from unshadow_scb() and from the
prepare_cpuflags() failure path, which now returns directly. The other
failure paths of shadow_scb() are reached after the guest state has
been copied and keep using unshadow_scb().

On a cached vsie page, the interception data in the shadow SCB still
holds the values of the previous run. set_validity_icpt() writes ipa,
ipb and icptcode, but not icptstatus, so a stale icptstatus would be
passed on together with the new validity interception. Also, it is not
defined what SIE stores in icptstatus, ipa and ipb when it exits without
an interception, so they must not be relied upon to be zero or unchanged.
Clear them together with icptcode when the shadow SCB is reused,
so that no stale interception data is passed on to guest 2.

Fixes: a3508fbe9dc6 ("KVM: s390: vsie: initial support for nested virtualization")
Reported-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Gautam Gala <ggala@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
---
 arch/s390/kvm/s390/vsie.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kvm/s390/vsie.c b/arch/s390/kvm/s390/vsie.c
index 5926689fa226..1f618bb274a8 100644
--- a/arch/s390/kvm/s390/vsie.c
+++ b/arch/s390/kvm/s390/vsie.c
@@ -424,6 +424,15 @@ static void prepare_ibc(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	}
 }
 
+static void unshadow_icpt(struct kvm_s390_sie_block *scb_o,
+			  struct kvm_s390_sie_block *scb_s)
+{
+	scb_o->icptcode = scb_s->icptcode;
+	scb_o->icptstatus = scb_s->icptstatus;
+	scb_o->ipa = scb_s->ipa;
+	scb_o->ipb = scb_s->ipb;
+}
+
 /* unshadow the scb, copying parameters back to the real scb */
 static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 {
@@ -431,10 +440,7 @@ static void unshadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	struct kvm_s390_sie_block *scb_o = vsie_page->scb_o;
 
 	/* interception */
-	scb_o->icptcode = scb_s->icptcode;
-	scb_o->icptstatus = scb_s->icptstatus;
-	scb_o->ipa = scb_s->ipa;
-	scb_o->ipb = scb_s->ipb;
+	unshadow_icpt(scb_o, scb_s);
 	scb_o->gbea = scb_s->gbea;
 
 	/* timer */
@@ -490,6 +496,9 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	/* make sure we don't have any leftovers when reusing the scb */
 	scb_s->icptcode = 0;
+	scb_s->icptstatus = 0;
+	scb_s->ipa = 0;
+	scb_s->ipb = 0;
 	scb_s->eca = 0;
 	scb_s->ecb = 0;
 	scb_s->ecb2 = 0;
@@ -499,8 +508,10 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 	scb_s->fpf = 0;
 
 	rc = prepare_cpuflags(vcpu, vsie_page);
-	if (rc)
-		goto out;
+	if (rc) {
+		unshadow_icpt(scb_o, scb_s);
+		return rc;
+	}
 
 	/* timer */
 	scb_s->cputm = scb_o->cputm;
@@ -614,7 +625,6 @@ static int shadow_scb(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page)
 
 	prepare_ibc(vcpu, vsie_page);
 	rc = shadow_crycb(vcpu, vsie_page);
-out:
 	if (rc)
 		unshadow_scb(vcpu, vsie_page);
 	return rc;
-- 
2.56.0


  reply	other threads:[~2026-11-19 12:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:49 [PATCH v1 0/2] " Gautam Gala
2026-11-19 12:49 ` Gautam Gala [this message]
2026-11-19 12:49 ` [PATCH v1 2/2] KVM: s390: selftests: Add vsie validity interception tests Gautam Gala

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=20261119124936.33396-2-ggala@linux.ibm.com \
    --to=ggala@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@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-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=svens@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

all inboxes | Powered by JetHome®