From nobody Wed Dec 31 03:34:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBEC3C04A95 for ; Wed, 8 Nov 2023 17:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232622AbjKHRMm (ORCPT ); Wed, 8 Nov 2023 12:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbjKHRMj (ORCPT ); Wed, 8 Nov 2023 12:12:39 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F39961BC3; Wed, 8 Nov 2023 09:12:36 -0800 (PST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8G0XXp009876; Wed, 8 Nov 2023 17:12:36 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=sb1jNJWcf0Des609yZa4DqHxbtt1v4z3KOzytpH2Uz0=; b=prgYej4twDcO3WWowB6p9F0CFpXX4WRTL3QjoNMC6/OHCP2aPwd48Qx79WsIdDPfjtCY tgQGRSSOpy04gPLKYt8LqihhS0KoU9vLcsYIrDBfNrXvIe5nSW5uECnSH/n052w0Ft3G r4hBQjZ/zpMySsHnIDj1W4wISIXRaDLCGtMXhnI0JVb2ykihroYtzDJyfxXnMKF6lACy 4pNivLxhq92njiFfXK72GoW9sM6A4dfsxj1MkSCLFZWWjJeMsEut40Cv9SOgYZlrJCb7 Nu78sjAS40QfljKGT08+nz1SLNdaG+zGLice89k/r8Hj6IvOAE6speaigkOs+qBgL1Uj wQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8dfk2vpq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A8H9F0k032043; Wed, 8 Nov 2023 17:12:35 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8dfk2vpb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8GNBX7014309; Wed, 8 Nov 2023 17:12:34 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3u7w21xa13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:34 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A8HCVkU24511102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Nov 2023 17:12:31 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87CBF20043; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C0C92004B; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) From: Nina Schoetterl-Glausch To: Heiko Carstens , Alexander Gordeev , Christian Borntraeger , Vasily Gorbik , Claudio Imbrenda , Janosch Frank Cc: Nina Schoetterl-Glausch , David Hildenbrand , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Sven Schnelle , kvm@vger.kernel.org Subject: [PATCH v3 1/4] KVM: s390: vsie: Fix STFLE interpretive execution identification Date: Wed, 8 Nov 2023 18:12:26 +0100 Message-Id: <20231108171229.3404476-2-nsg@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231108171229.3404476-1-nsg@linux.ibm.com> References: <20231108171229.3404476-1-nsg@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: MXXzvTPP4V2uH69Ao2XZX2xy8oF102eZ X-Proofpoint-GUID: r91Tib7Gwe_f691GO5TFSPnbSmh93gx0 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-08_05,2023-11-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311080141 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" STFLE can be interpretively executed. This occurs when the facility list designation is unequal to zero. Perform the check before applying the address mask instead of after. Fixes: 66b630d5b7f2 ("KVM: s390: vsie: support STFLE interpretation") Reviewed-by: Claudio Imbrenda Acked-by: David Hildenbrand Signed-off-by: Nina Schoetterl-Glausch --- arch/s390/kvm/vsie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/s390/kvm/vsie.c b/arch/s390/kvm/vsie.c index 61499293c2ac..d989772fe211 100644 --- a/arch/s390/kvm/vsie.c +++ b/arch/s390/kvm/vsie.c @@ -988,9 +988,10 @@ static void retry_vsie_icpt(struct vsie_page *vsie_pag= e) static int handle_stfle(struct kvm_vcpu *vcpu, struct vsie_page *vsie_page) { struct kvm_s390_sie_block *scb_s =3D &vsie_page->scb_s; - __u32 fac =3D READ_ONCE(vsie_page->scb_o->fac) & 0x7ffffff8U; + __u32 fac =3D READ_ONCE(vsie_page->scb_o->fac); =20 if (fac && test_kvm_facility(vcpu->kvm, 7)) { + fac =3D fac & 0x7ffffff8U; retry_vsie_icpt(vsie_page); if (read_guest_real(vcpu, fac, &vsie_page->fac, sizeof(vsie_page->fac))) --=20 2.39.2 From nobody Wed Dec 31 03:34:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82F38C4167D for ; Wed, 8 Nov 2023 17:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232691AbjKHRMr (ORCPT ); Wed, 8 Nov 2023 12:12:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232498AbjKHRMj (ORCPT ); Wed, 8 Nov 2023 12:12:39 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8762D1FF9; Wed, 8 Nov 2023 09:12:37 -0800 (PST) Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8GjWrR000313; Wed, 8 Nov 2023 17:12:36 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=cIMLIDofioo0tHlvYKDWa9BjvHXwFewVdPCLtnkS2XU=; b=U4X5zg2up9rTZ1Woh18kSWreX05mU+CZdxnWJgqx/22ElCPedODuftTC39650/FWArvo f4L1owjL8JUVxj90U6OZHj18qzfvm/ZxVKXFPBWP49cwG9dzYMuOpy139TjoChoIaGrc lTab4epwrqIz08Lbs/mcRV+9GnhaLQq1QiEpzhzLKRoHZAaxR4syADzXTmUpCGgrCn17 A7u4kzuQfKiftEuRCLg1enYX4spMK/023ArTMq0o8nn+GImQVl+cs8t50OvF71F2gKKB lVA8T1XVarBtTB5YXWmL5ljPyu1LYz1gH6hcofR4BccOOcEd9NOQ5NP2lOtZV84nor3g ag== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8e4s99jn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:36 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A8Gjwxn003814; Wed, 8 Nov 2023 17:12:35 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8e4s99ja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +0000 Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8GeMXX000644; Wed, 8 Nov 2023 17:12:35 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3u7w22x9su-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:34 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A8HCVhg24511104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Nov 2023 17:12:31 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CAAD720043; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 996162004B; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) From: Nina Schoetterl-Glausch To: Claudio Imbrenda , Janosch Frank , Alexander Gordeev , Vasily Gorbik , Christian Borntraeger , Heiko Carstens , David Hildenbrand , Nina Schoetterl-Glausch Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sven Schnelle , linux-s390@vger.kernel.org Subject: [PATCH v3 2/4] KVM: s390: vsie: Fix length of facility list shadowed Date: Wed, 8 Nov 2023 18:12:27 +0100 Message-Id: <20231108171229.3404476-3-nsg@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231108171229.3404476-1-nsg@linux.ibm.com> References: <20231108171229.3404476-1-nsg@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: WRBtNgB7f-9UQvuUAa8GCm5qXBcSwoJr X-Proofpoint-GUID: dF0mDbG4DGHD92aJew2LYFExO9ut7FTF 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-08_05,2023-11-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 clxscore=1015 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311080141 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Acked-by: David Hildenbrand Reviewed-by: Claudio Imbrenda Signed-off-by: Nina Schoetterl-Glausch Acked-by: Heiko Carstens --- arch/s390/include/asm/facility.h | 6 ++++++ arch/s390/kernel/Makefile | 2 +- arch/s390/kernel/facility.c | 21 +++++++++++++++++++++ arch/s390/kvm/vsie.c | 12 +++++++++++- 4 files changed, 39 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/facil= ity.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(); } =20 +/** + * 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 +=3D sysinfo.o lgr.o os_info.o obj-y +=3D runtime_instr.o cache.o fpu.o dumpstack.o guarded_storage.o sth= yi.o obj-y +=3D entry.o reipl.o kdebugfs.o alternative.o obj-y +=3D nospec-branch.o ipl_vmparm.o machine_kexec_reloc.o unwind_bc.o -obj-y +=3D smp.o text_amode31.o stacktrace.o abs_lowcore.o +obj-y +=3D smp.o text_amode31.o stacktrace.o abs_lowcore.o facility.o =20 extra-y +=3D vmlinux.lds =20 diff --git a/arch/s390/kernel/facility.c b/arch/s390/kernel/facility.c new file mode 100644 index 000000000000..f02127219a27 --- /dev/null +++ b/arch/s390/kernel/facility.c @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright IBM Corp. 2023 + */ + +#include + +unsigned int stfle_size(void) +{ + static unsigned int size; + unsigned int r; + u64 dummy; + + r =3D READ_ONCE(size); + if (!r) { + r =3D __stfle_asm(&dummy, 1) + 1; + WRITE_ONCE(size, r); + } + return r; +} +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" =20 @@ -990,11 +991,20 @@ static int handle_stfle(struct kvm_vcpu *vcpu, struct= vsie_page *vsie_page) struct kvm_s390_sie_block *scb_s =3D &vsie_page->scb_s; __u32 fac =3D READ_ONCE(vsie_page->scb_o->fac); =20 + /* + * Alternate-STFLE-Interpretive-Execution facilities are not supported + * -> format-0 flcb + */ if (fac && test_kvm_facility(vcpu->kvm, 7)) { fac =3D fac & 0x7ffffff8U; retry_vsie_icpt(vsie_page); + /* + * format-0 -> size of nested guest's facility list =3D=3D guest's size + * guest's size =3D=3D host's size, since STFLE is interpretatively exec= uted + * 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 =3D (__u32)(__u64) &vsie_page->fac; } --=20 2.39.2 From nobody Wed Dec 31 03:34:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A982C4332F for ; Wed, 8 Nov 2023 17:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232744AbjKHRMu (ORCPT ); Wed, 8 Nov 2023 12:12:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232621AbjKHRMm (ORCPT ); Wed, 8 Nov 2023 12:12:42 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D0751BC3; Wed, 8 Nov 2023 09:12:40 -0800 (PST) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8Gf8Y6019032; Wed, 8 Nov 2023 17:12:40 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=lA65AQ6LI0srspR/dH2FZve8z9ibKrJ4DcDXXG64Vis=; b=G4jPMALesj4Xq+nx/BWojIMH8kpzK4LlifVhLiOUgFrvIGFnrsaxCWgwTqBgZA5PkBvk CfC63lCNplxW5G5wB3OIJBB2s/zTS1/W58hIt0oSVZ3wlUOM9Zbf4rfQV9MiL5R3/CZn 1MrDM5joGVvXfoWRXg2x4uT6u6n0ookb4tEG8GUFvfAIDysq4f3X9Vspuvl72OojmOvV NbSm6XiTdvjFQHklsHOUHZk/yso3nTXIfs7NWsO6omgHZ7oj7HCNOiAL20biBCFaRE+M M67xWn6VKBfz7B/DdKnLkwoUcumJtVSKssAGc/lq/NN+x7p3aT6X5IlHJfhhRqPinYuL TA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8dxh1kwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:37 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A8GfKaY019812; Wed, 8 Nov 2023 17:12:36 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8dxh1kuc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:36 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8GNBX8014309; Wed, 8 Nov 2023 17:12:35 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3u7w21xa16-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A8HCWLn44434134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Nov 2023 17:12:32 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 197F520043; Wed, 8 Nov 2023 17:12:32 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC59A2005A; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Nov 2023 17:12:31 +0000 (GMT) From: Nina Schoetterl-Glausch To: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Vasily Gorbik , Heiko Carstens , Alexander Gordeev Cc: Nina Schoetterl-Glausch , David Hildenbrand , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Sven Schnelle , kvm@vger.kernel.org Subject: [PATCH v3 3/4] KVM: s390: cpu model: Use proper define for facility mask size Date: Wed, 8 Nov 2023 18:12:28 +0100 Message-Id: <20231108171229.3404476-4-nsg@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231108171229.3404476-1-nsg@linux.ibm.com> References: <20231108171229.3404476-1-nsg@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: OrdsHv5LkEAgzEgcHnjY4Cq4SKu9YdR2 X-Proofpoint-ORIG-GUID: FD4OhWDO5H_Cirz52WWXPdO2uesol7ei 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-08_05,2023-11-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 spamscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxlogscore=882 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311080142 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the previously unused S390_ARCH_FAC_MASK_SIZE_U64 instead of S390_ARCH_FAC_LIST_SIZE_U64 for defining the fac_mask array. Note that both values are the same, there is no functional change. Reviewed-by: Claudio Imbrenda Signed-off-by: Nina Schoetterl-Glausch Reviewed-by: David Hildenbrand Reviewed-by: Janosch Frank --- arch/s390/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_h= ost.h index 427f9528a7b6..46fcd2f9dff8 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -811,7 +811,7 @@ struct s390_io_adapter { =20 struct kvm_s390_cpu_model { /* facility mask supported by kvm & hosting machine */ - __u64 fac_mask[S390_ARCH_FAC_LIST_SIZE_U64]; + __u64 fac_mask[S390_ARCH_FAC_MASK_SIZE_U64]; struct kvm_s390_vm_cpu_subfunc subfuncs; /* facility list requested by guest (in dma page) */ __u64 *fac_list; --=20 2.39.2 From nobody Wed Dec 31 03:34:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B941FC4332F for ; Wed, 8 Nov 2023 17:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232678AbjKHRMp (ORCPT ); Wed, 8 Nov 2023 12:12:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232495AbjKHRMj (ORCPT ); Wed, 8 Nov 2023 12:12:39 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DFFF1FF6; Wed, 8 Nov 2023 09:12:37 -0800 (PST) Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A8GtRL0012939; Wed, 8 Nov 2023 17:12:36 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=2NGVr2b1yHvGxHjOrPSZFgQarUSjlXt1y6/20minRPs=; b=DwcQx0U4+LEdpZ2JVIX3Yj4aFnoviNfcNSscGoCpJ0/S7UKiNdgF/oDW7Y6IGkvPtSoJ XK+W7SdAwVVJsZXsPX6j4dMHrN8GW+oQ/s3JVCS48fWTJC2h2pChYKz9BPP7433LTchw 9+4U35ORnVG8duQ+IReiceTQsCLOMMjVmyJYIonxh5/DLl/o35ex6sZwcqHO7NvJ0vz2 eqdZSnIBaPX9P8X+HprUFTO3xJFpP6iHq8knxnl985ZpQ1+cXpyHor0TIuBeBrVj5G1u uWWuIEVHLFVaEICcefDTO4LV98BDYTeaBEZF2ImxJ/8gA1H2n3e7aozUzM8p8/Z/47Km iA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u8dfk2vq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:36 +0000 Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3A8G12mF011120; Wed, 8 Nov 2023 17:12:36 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 3u8dfk2vpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +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 3A8GWpcG019231; Wed, 8 Nov 2023 17:12:35 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3u7w23x91a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Nov 2023 17:12:35 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A8HCW8x45220304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Nov 2023 17:12:32 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6610F20040; Wed, 8 Nov 2023 17:12:32 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 34DF72004B; Wed, 8 Nov 2023 17:12:32 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 8 Nov 2023 17:12:32 +0000 (GMT) From: Nina Schoetterl-Glausch To: Heiko Carstens , Alexander Gordeev , Claudio Imbrenda , Janosch Frank , Vasily Gorbik , Christian Borntraeger Cc: Nina Schoetterl-Glausch , kvm@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, David Hildenbrand , Sven Schnelle Subject: [PATCH v3 4/4] KVM: s390: Minor refactor of base/ext facility lists Date: Wed, 8 Nov 2023 18:12:29 +0100 Message-Id: <20231108171229.3404476-5-nsg@linux.ibm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231108171229.3404476-1-nsg@linux.ibm.com> References: <20231108171229.3404476-1-nsg@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PADLjdPIClBS5g3GrhcOmD4qIq2jc9zj X-Proofpoint-GUID: vHKWNxNPDOEgZCke-rGp2NJQVbLzgLfd 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-08_05,2023-11-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 adultscore=0 suspectscore=0 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 phishscore=0 spamscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311080141 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Directly use the size of the arrays instead of going through the indirection of kvm_s390_fac_size(). Don't use magic number for the number of entries in the non hypervisor managed facility bit mask list. Make the constraint of that number on kvm_s390_fac_base obvious. Get rid of implicit double anding of stfle_fac_list. Reviewed-by: Claudio Imbrenda Signed-off-by: Nina Schoetterl-Glausch --- Notes: I think it's nicer this way but it might be needless churn. arch/s390/kvm/kvm-s390.c | 44 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index b3f17e014cab..e00ab2f38c89 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -217,33 +217,25 @@ static int async_destroy =3D 1; module_param(async_destroy, int, 0444); MODULE_PARM_DESC(async_destroy, "Asynchronous destroy for protected guests= "); =20 -/* - * For now we handle at most 16 double words as this is what the s390 base - * kernel handles and stores in the prefix page. If we ever need to go bey= ond - * this, this requires changes to code, but the external uapi can stay. - */ -#define SIZE_INTERNAL 16 - +#define HMFAI_DWORDS 16 /* * Base feature mask that defines default mask for facilities. Consists of= the * defines in FACILITIES_KVM and the non-hypervisor managed bits. */ -static unsigned long kvm_s390_fac_base[SIZE_INTERNAL] =3D { FACILITIES_KVM= }; +static unsigned long kvm_s390_fac_base[HMFAI_DWORDS] =3D { FACILITIES_KVM = }; +static_assert(ARRAY_SIZE(((long[]){ FACILITIES_KVM })) <=3D HMFAI_DWORDS); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <=3D S390_ARCH_FAC_MASK_SIZE_U= 64); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <=3D S390_ARCH_FAC_LIST_SIZE_U= 64); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <=3D ARRAY_SIZE(stfle_fac_list= )); + /* * Extended feature mask. Consists of the defines in FACILITIES_KVM_CPUMOD= EL * and defines the facilities that can be enabled via a cpu model. */ -static unsigned long kvm_s390_fac_ext[SIZE_INTERNAL] =3D { FACILITIES_KVM_= CPUMODEL }; - -static unsigned long kvm_s390_fac_size(void) -{ - BUILD_BUG_ON(SIZE_INTERNAL > S390_ARCH_FAC_MASK_SIZE_U64); - BUILD_BUG_ON(SIZE_INTERNAL > S390_ARCH_FAC_LIST_SIZE_U64); - BUILD_BUG_ON(SIZE_INTERNAL * sizeof(unsigned long) > - sizeof(stfle_fac_list)); - - return SIZE_INTERNAL; -} +static const unsigned long kvm_s390_fac_ext[] =3D { FACILITIES_KVM_CPUMODE= L }; +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <=3D S390_ARCH_FAC_MASK_SIZE_U6= 4); +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <=3D S390_ARCH_FAC_LIST_SIZE_U6= 4); +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <=3D ARRAY_SIZE(stfle_fac_list)= ); =20 /* available cpu features supported by kvm */ static DECLARE_BITMAP(kvm_s390_available_cpu_feat, KVM_S390_VM_CPU_FEAT_NR= _BITS); @@ -3341,13 +3333,16 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long= type) kvm->arch.sie_page2->kvm =3D kvm; kvm->arch.model.fac_list =3D kvm->arch.sie_page2->fac_list; =20 - for (i =3D 0; i < kvm_s390_fac_size(); i++) { + for (i =3D 0; i < ARRAY_SIZE(kvm_s390_fac_base); i++) { kvm->arch.model.fac_mask[i] =3D stfle_fac_list[i] & - (kvm_s390_fac_base[i] | - kvm_s390_fac_ext[i]); + kvm_s390_fac_base[i]; kvm->arch.model.fac_list[i] =3D stfle_fac_list[i] & kvm_s390_fac_base[i]; } + for (i =3D 0; i < ARRAY_SIZE(kvm_s390_fac_ext); i++) { + kvm->arch.model.fac_mask[i] |=3D stfle_fac_list[i] & + kvm_s390_fac_ext[i]; + } kvm->arch.model.subfuncs =3D kvm_s390_available_subfunc; =20 /* we are always in czam mode - even on pre z14 machines */ @@ -5859,9 +5854,8 @@ static int __init kvm_s390_init(void) return -EINVAL; } =20 - for (i =3D 0; i < 16; i++) - kvm_s390_fac_base[i] |=3D - stfle_fac_list[i] & nonhyp_mask(i); + for (i =3D 0; i < HMFAI_DWORDS; i++) + kvm_s390_fac_base[i] |=3D nonhyp_mask(i); =20 r =3D __kvm_s390_init(); if (r) --=20 2.39.2