From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796214339; b=UzF2AEifMYsBtjD0/oGKxKajGrFN4Rzhu4Kqqsr+EYBm7ezlPPqsN5pPlwSpBOdl5XLJ nQUE5n3yRYXsIxoGP0xBJ+JaO3hJgQTQosQAf95n1Bp8KVGDoUIY3mpmtFtqKN21TR+HS EdS0Z8fEQHT8c0A1rJhZ2cihyDNLybiWVf9A0vO9A1YFUggry0VlNT6cEqvxHkEsUYEJ3 KBx27Y/06vaV7Fe/U1SbTyCoDtGxdg8Jf9xFlNpTYJJeCZaMkFLng29GEu1l54kQyt/mJ RKB2BDMgZ9hRhUCPws0UXTFcW/seDk67AeqnhjQpJiAV/7k1DqcbQPKAPeLpz0MtF0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796214339; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=gWFu8KEjjJDvs7QrureyFnca67UFr/J5qbg/rrmQRLo=; b=v+aj8uL7PPu7C+ymsBn+3s4T6RolIANjMBNnYHujbVXzLSPe4Tr971URzdQv5L8vWq+G nZGpVtItlPhRAHQx2F5kb4xQKScbQpGyPl8NBQQdl8calzaPgJV6eZeRVZ8b4y0jqAWeI 6Tx+53igbynluBHDTmTlZ3BF2NJ0fDu3UHQCvC7SOCvy/BHoykh4Fea0Fx0i34voxiRFr SZC9vA3SnDZEuquSFp0qFtklD28+p/cYL3MFKLerhsnIeIFnwZk6vDy8hAEgkeLRnRR0j JUT5yvc7JtsrBb5aqaF94Qy5tLS21FJ8u3sG5vWvRL60nghV+VK1yPr0QEV9FwnpZeA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=dYKUx2eK; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DC0F606A329; Wed, 2 Dec 2026 12:25:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3DC0F606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=dYKUx2eK Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2AMKkj2795343; Wed, 2 Dec 2026 12:25:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=gWFu8KEjjJDvs7Qru reyFnca67UFr/J5qbg/rrmQRLo=; b=dYKUx2eKVCxBwLusFUkVsXbke63Aq5WFf GOYD3oM37Jit+BDo3t7/hk//eCCIgv6lwt3GTo4nXesqbRy6Fl1qlNrDoY6uhCA7 qTWTvy+siQbwWwWc61WS+fk+57M27gYhH1yEC+CVEd3QKycGtusPkGCdsTVk45Ox 5aRHpfpkuP4ybok/6QlxHFuLg3vwUoVWZcRIi7EuNOkCxt7HrSMaZfnBbG91RJ71 c50t0ogLStaMQ2QS2EVrmhFZd79QQrGOQ867Si7AAu0bg+ERKNl3gF7u9dFL6xOC UyAqcjI5IlIRoV9kI/+d8lx3xl0cVb4oLYEPPRf0eSkOc9EWg6qhg== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pmt9pan-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 12:25:22 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2Bb27d1627082; Wed, 2 Dec 2026 12:25:21 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4ja0pq3y1f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 12:25:21 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B2CPKuk18612854 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 12:25:20 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 42FEF5803F; Wed, 2 Dec 2026 12:25:20 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7434658054; Wed, 2 Dec 2026 12:25:18 +0000 (GMT) Received: from li-7897874c-2179-11b2-a85c-c322b68a81ac.ibm.com.com (unknown [9.111.87.152]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 12:25:18 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@kernel.org, borntraeger@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, Gautam Gala Subject: [GIT PULL 2/4] KVM: s390: vsie: Do not overwrite guest 3 state on early validity icpt Date: Wed, 2 Dec 2026 13:14:08 +0100 Message-ID: <20261202122437.289764-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202122437.289764-1-frankja@linux.ibm.com> References: <20261202122437.289764-1-frankja@linux.ibm.com> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: IKb2kKHMa3iKFT7J7ppUCLpXCOWh6jWY X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDA0OCBTYWx0ZWRfX62VQGKatQfQj Tv1IFureh5TeS67AzCaNNKPG65U1ePRVuX3MSQ7ayJwGGDAAZWeKp34Z5LBPEBkoTjN1PV3h0iu yCaqq5VgVXOBmWUBSGoZznDIQOOLRp3Yua5BT3rFTC8nbOIDNRVSfpZI7su+xQ12n7YDq/gqTca VR8vhFg2qXmXSPkD4jpxg6ID9wpE2nH5MIUnfj9amqe+4hELwOTUM5k0Brrr82aVgXvlRB5epgB JdWn8aPVOzoEnzuIb2uVQV0QBm3Ccd8054HVvdq0EcGxMdRuDtp3Hyz/O9KVlRgfW2codjJhFjs 5XGCeHtvnIMWYtrfY4cn79LvfQKiPCw3M43thcJ9FqJv1EF2NNr2IOVY79lSY3RIXCNXqwi4Kdr EGfjo9VwVzEj8FOguB9GCs02c2Lap5LQd164vH1ZumJGK2OLxIC0V/+iGnPaS2LKq9snOGddXNQ IuaDMzkFQBS2Rpwu1+A== X-Proofpoint-GUID: IKb2kKHMa3iKFT7J7ppUCLpXCOWh6jWY X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDA0OCBTYWx0ZWRfXyButyVsErz+D 6h1RxfoPmnU3wsnR9u2JLD9H38F1kXC8WDi7NV3Z2w+qSTuQmY8L2xAf2djy8/1+vjxlrqwoq8f aCWqff2J1VzdLZrNQZd3eB/X7HzQJ/A= X-Authority-Analysis: v=2.4 cv=U9cHnuru c=1 sm=1 tr=0 ts=6b100e32 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=HnRTBInXDna0ns452sMA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 priorityscore=1501 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020048 From: Gautam Gala 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 Signed-off-by: Gautam Gala Reviewed-by: Christian Borntraeger Signed-off-by: Christian Borntraeger --- 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 3ce133f20fa2..e2cb9bd411fd 100644 --- a/arch/s390/kvm/s390/vsie.c +++ b/arch/s390/kvm/s390/vsie.c @@ -425,6 +425,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) { @@ -432,10 +441,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 */ @@ -491,6 +497,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; @@ -500,8 +509,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; @@ -615,7 +626,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.1