Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp643988rdf; Fri, 3 Nov 2023 10:31:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8+p4cXYSxk9c45ZtsNbyn6wta+urqqRU4W/ugx5rbeThDjtGY0ECPs1iqmcMLNb6Lcu55 X-Received: by 2002:a05:6a00:23c6:b0:68f:c7c5:a73a with SMTP id g6-20020a056a0023c600b0068fc7c5a73amr26772793pfc.16.1699032698553; Fri, 03 Nov 2023 10:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699032698; cv=none; d=google.com; s=arc-20160816; b=bJY69dgYCRldHMKyL7D9T4owJ7EOKU8SdfHIKYEcdHmqjnAKWbJ0/dH/aRCjkQLlHD Ul6c+6N073acpDhjfoDgCkepUi+gdkodUpAFl01UWHhP5aJA1RBluf2eCZUOmpsRZqe7 bwVkFQkgv6FEvCQTyUjMNZkOqmn/6Ou6eQUGHd92zfGuS6mwGrapmkoyGmciQxFqGhWx +KPLzG/cWUV+P2UlEo5zj6IDGyuPdnlUyRLxA/ucKABbK9iutBMce2Tfh4+rEMy4yBSX 7jbmo9nYNbMkuFY0oJaNicqem+mk/RT9e9HbXfbsJif6mWTM/tLBrxfPMSK6q64vfz62 33Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rW1R49MZgm4F0aHWaNHbGSUo7bf0vAKQc//SxLmUw9Y=; fh=tZmRnbXoc0e6J6WcsImiHciFlY3BOH28+UuJXoMzvDs=; b=vk++B63Weo2BGaabCp1e6VPqGZhV4b+H8zBmcACIOPb+a4ic6DFc6c14t3LS+Wmd1f KrKfVCkGyoe6l5L6nWd4onunXP5JFjj4WH9C1yDbN5F9mUB5Fy5MhoNnGPP60glYH1p6 zVhNbc/VFKbqqsYjiBw+cRNPnJ4PKywocGY78DkwxbOQeqDNZVhQmmYqCGS1eW5qBunc ESmnKi/8BfZ3a7xmvVhtX7FK/l2TJAvlAhNFBFQ+zmaIj7HYxP7wJR/yN4a0V0YkzLsH YH4iE3ztUBLVBipvnXBV9wxijzWgPyifh5p3Au1hLpUepV99cV9wYt6+vpcUQorST5lP UKoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=g1C2WPVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e7-20020a6558c7000000b005b96dd10899si1792787pgu.852.2023.11.03.10.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=g1C2WPVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0DA7480658FF; Fri, 3 Nov 2023 10:30:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377675AbjKCRa2 (ORCPT + 99 others); Fri, 3 Nov 2023 13:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376525AbjKCRaW (ORCPT ); Fri, 3 Nov 2023 13:30:22 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FD3313E; Fri, 3 Nov 2023 10:30:17 -0700 (PDT) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3H7GSB002202; Fri, 3 Nov 2023 17:30:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=rW1R49MZgm4F0aHWaNHbGSUo7bf0vAKQc//SxLmUw9Y=; b=g1C2WPVLZcVRnijp6gRdSMaWr5FPsbti5qUV2aGF11x4NNsUQq7Ysn88Axg0rFVGH/qW hcUk8lW06i8a4sdq0U+KU+xzpfmcxZ+a4YyPUc2v7W0ojcvAYrSxR/ADHx0p9kJD2f1n 1kQe0Q//o5PX3a1QaZk3WXu/IkuxTcFZGTEqGTwF4/eEIpHOegz40fIlcba0t+hmIVPR Q9deYgig4P7lRzOKfk9WB3NoMwx8gV45+j3R0MayL2cxROfd+JgvQcUmWN6UEreDm8IZ KQv1ey4Qs4VdgS/PGswz1iHTqqViIb17OqO4mXLh88BeuH1m4agDDgyaBEDsiowcr+Cv og== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u54yws4sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:30:16 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A3H7iok003895; Fri, 3 Nov 2023 17:30:16 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u54yws4s4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:30:16 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A3GUneB000588; Fri, 3 Nov 2023 17:30:15 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3u1cmtqt1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:30:15 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A3HUAfv18612758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Nov 2023 17:30:10 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D1BA2004E; Fri, 3 Nov 2023 17:30:10 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 206822004B; Fri, 3 Nov 2023 17:30:10 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 3 Nov 2023 17:30:10 +0000 (GMT) From: Nina Schoetterl-Glausch To: Alexander Gordeev , Claudio Imbrenda , Christian Borntraeger , Vasily Gorbik , Heiko Carstens , Nina Schoetterl-Glausch , Janosch Frank , David Hildenbrand Cc: Cornelia Huck , linux-s390@vger.kernel.org, Sven Schnelle , kvm@vger.kernel.org, David Hildenbrand , linux-kernel@vger.kernel.org, Michael Mueller Subject: [PATCH 2/4] KVM: s390: vsie: Fix length of facility list shadowed Date: Fri, 3 Nov 2023 18:30:06 +0100 Message-Id: <20231103173008.630217-3-nsg@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103173008.630217-1-nsg@linux.ibm.com> References: <20231103173008.630217-1-nsg@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 48ytNKaUiGovYjAqXkgiQLFaTULcgg8q X-Proofpoint-ORIG-GUID: -z2QJDfpKsCF1d-9C8oeRphP6EqHBFSR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-03_16,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311030146 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 10:30:34 -0700 (PDT) The length of the facility list accessed when interpretively executing STFLE is the same as the hosts facility list (in case of format-0) When shadowing, copy only those bytes. The memory following the facility list need not be accessible, in which case we'd wrongly inject a validity intercept. Fixes: 66b630d5b7f2 ("KVM: s390: vsie: support STFLE interpretation") Signed-off-by: Nina Schoetterl-Glausch --- arch/s390/include/asm/facility.h | 6 ++++++ arch/s390/kernel/Makefile | 2 +- arch/s390/kernel/facility.c | 18 ++++++++++++++++++ arch/s390/kvm/vsie.c | 12 +++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 arch/s390/kernel/facility.c diff --git a/arch/s390/include/asm/facility.h b/arch/s390/include/asm/facility.h index 94b6919026df..796007125dff 100644 --- a/arch/s390/include/asm/facility.h +++ b/arch/s390/include/asm/facility.h @@ -111,4 +111,10 @@ static inline void stfle(u64 *stfle_fac_list, int size) preempt_enable(); } +/** + * stfle_size - Actual size of the facility list as specified by stfle + * (number of double words) + */ +unsigned int stfle_size(void); + #endif /* __ASM_FACILITY_H */ diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile index 0df2b88cc0da..0daa81439478 100644 --- a/arch/s390/kernel/Makefile +++ b/arch/s390/kernel/Makefile @@ -41,7 +41,7 @@ obj-y += sysinfo.o lgr.o os_info.o obj-y += runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sthyi.o obj-y += entry.o reipl.o kdebugfs.o alternative.o obj-y += nospec-branch.o ipl_vmparm.o machine_kexec_reloc.o unwind_bc.o -obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o +obj-y += smp.o text_amode31.o stacktrace.o abs_lowcore.o facility.o extra-y += vmlinux.lds diff --git a/arch/s390/kernel/facility.c b/arch/s390/kernel/facility.c new file mode 100644 index 000000000000..c33a95a562da --- /dev/null +++ b/arch/s390/kernel/facility.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright IBM Corp. 2023 + */ + +#include + +unsigned int stfle_size(void) +{ + static unsigned int size = 0; + u64 dummy; + + if (!size) { + size = __stfle_asm(&dummy, 1) + 1; + } + return size; +} +EXPORT_SYMBOL(stfle_size); diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index d989772fe211..c168e88c64da 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "kvm-s390.h" #include "gaccess.h" @@ -990,11 +991,20 @@ static int handle_stfle(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) struct kvm_s390_sie_block *scb_s = &vsie_page->scb_s; __u32 fac = READ_ONCE(vsie_page->scb_o->fac); + /* + * Alternate-STFLE-Interpretive-Execution facilities are not supported + * -> format-0 flcb + */ if (fac && test_kvm_facility(vcpu->kvm, 7)) { fac = fac & 0x7ffffff8U; retry_vsie_icpt(vsie_page); + /* + * format-0 -> size of nested guest's facility list == guest's size + * guest's size == host's size, since STFLE is interpretatively executed + * using a format-0 for the guest, too. + */ if (read_guest_real(vcpu, fac, &vsie_page->fac, - sizeof(vsie_page->fac))) + stfle_size() * sizeof(u64))) return set_validity_icpt(scb_s, 0x1090U); scb_s->fac = (__u32)(__u64) &vsie_page->fac; } -- 2.39.2