Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp644048rdf; Fri, 3 Nov 2023 10:31:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErZoxmWU9G6PlcpMyjClF0fTOJpJBcl/7irVHtGsLfua5gO82jkAnVDtEjOR8aJ0j2J63B X-Received: by 2002:a17:903:244b:b0:1cc:4596:841f with SMTP id l11-20020a170903244b00b001cc4596841fmr3978480pls.31.1699032704457; Fri, 03 Nov 2023 10:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699032704; cv=none; d=google.com; s=arc-20160816; b=KdYGN9pohcelOhJMDuOZaPhFKIvk0VeT/TxP6XoZxrQx6RLjI93Dvon33g43WjZzBa ir/WM6d1nOR9NEsk21foIFHs4rP60VxhqOvC7F1O1z5adBk552AiuDRQ3d+rh5yXajzP 9kDuvXhgoauRUNTPKUzaVfeQG5hiDr/DLotfXwiReKGAFgvy2cAVMLAql2kTY6t1t9Qm chZ8rRDWg9dHuAKXcykabP1Wf+5SfdHn0ElaqJs9fVx5sgCRSMEwqa+XNLY91U73ID+/ lYIX1rSxs83Ls/6kHl/CqbNZwyfSexdStDZkU51p+SSnwCOmfW8BY3vNBhhXaMiSj+cp Urtw== 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=UsNIhSuDbtYP3OaMXs+2agd2J5yFl9Vo8sEz+w3vziQ=; fh=q/j4/sO+pmtd8FRUVekzmK1gDQa/xddlkkkwkukasfM=; b=05BqVDAeWr7qB7ZfzrfZYI4/wB4ZIOVOd6OvAGhrB6MRYQcagqwVJvb4kHvClWBqUo GqkZivO9Bq8eEUlKfHi2TCa1hSWquODifa+BfyGMhsRGuMKzlde+tvfTSRfQNaatFRj+ /yirkKo46wF+mUWR1jWo68sZUvrsB+buG6gu3j2VLSlcdTBqH+bOIGrMathQl5UfSxHr eV/mvo7q3hj5lVbEmQbmZtt0ziNvz7tIGBRtn5xqgJmO/H4F7MYtZav7COq0xprf9PfI wTrVWiXja1sZzEn/zSanRKKVjxpJbNeST8mr7678w6AXhL4vmNo2kyKjdGf9ZnIlr4yM QgOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SrVzf+ok; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id by13-20020a056a02058d00b005bd2b19dfc4si2074453pgb.493.2023.11.03.10.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 10:31:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=SrVzf+ok; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id B74C180D8FEB; Fri, 3 Nov 2023 10:31:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345845AbjKCRbh (ORCPT + 99 others); Fri, 3 Nov 2023 13:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbjKCRbf (ORCPT ); Fri, 3 Nov 2023 13:31:35 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C899013E; Fri, 3 Nov 2023 10:31:32 -0700 (PDT) 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 3A3H9OC2002669; Fri, 3 Nov 2023 17:31:32 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=UsNIhSuDbtYP3OaMXs+2agd2J5yFl9Vo8sEz+w3vziQ=; b=SrVzf+ok+1PamAioLd/0etN4xnUuW1ewG7aPQF5paIDUwv2EMc+eMfBvwMeXuC8Q5y/c KGVoz2edANb4Gf4+6VA3lzR208P35ssHZsuSZZFsi7mNgiZiPu+GbVSUJXtJflXDPEuQ Y4Zu2OcShLugkD80eXG0fi2Q3uzK21eXgyzQnt1oYyIF8dTHcRRMgkmsvsPceZCPorJb 5w0keDFdDVYmHWjUBJ8nsWkCvtJjfCffWxfSPQ7fqv0uOJqyhPnWdw+QZSdN6oKTX/QT gNGll7kfzD034KpknHXSrVjgPjHtaHc73gsi53OdLmjcA4uvSYFgnVHqj397tq8DbmEX +w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3u550x0mby-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:31:31 +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 3A3H9lHV004743; Fri, 3 Nov 2023 17:31:31 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 3u550x0mbn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:31:31 +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 3A3HLu1K007685; Fri, 3 Nov 2023 17:31:30 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3u1dmp7gs1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 03 Nov 2023 17:31:30 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3A3HUBe138338974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 3 Nov 2023 17:30:11 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 172C920040; Fri, 3 Nov 2023 17:30:11 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D00962005A; 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: Christian Borntraeger , Janosch Frank , Heiko Carstens , Claudio Imbrenda , Alexander Gordeev , Vasily Gorbik Cc: Nina Schoetterl-Glausch , David Hildenbrand , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, Cornelia Huck , Sven Schnelle , Michael Mueller , David Hildenbrand Subject: [PATCH 4/4] KVM: s390: Minor refactor of base/ext facility lists Date: Fri, 3 Nov 2023 18:30:08 +0100 Message-Id: <20231103173008.630217-5-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-ORIG-GUID: YfRqRlpFGu1Yz6e7jED8TE4eMlxY3ZgT X-Proofpoint-GUID: T7TI_AAbL0-9oREfMC48cUjLy_6NNNn8 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 mlxlogscore=999 bulkscore=0 clxscore=1015 phishscore=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 suspectscore=0 impostorscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311030146 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 10:31:41 -0700 (PDT) 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. Signed-off-by: Nina Schoetterl-Glausch --- I found it confusing before and 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 = 1; module_param(async_destroy, int, 0444); MODULE_PARM_DESC(async_destroy, "Asynchronous destroy for protected guests"); -/* - * 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 beyond - * 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] = { FACILITIES_KVM }; +static unsigned long kvm_s390_fac_base[HMFAI_DWORDS] = { FACILITIES_KVM }; +static_assert(ARRAY_SIZE(((long[]){ FACILITIES_KVM })) <= HMFAI_DWORDS); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <= S390_ARCH_FAC_MASK_SIZE_U64); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <= S390_ARCH_FAC_LIST_SIZE_U64); +static_assert(ARRAY_SIZE(kvm_s390_fac_base) <= ARRAY_SIZE(stfle_fac_list)); + /* * Extended feature mask. Consists of the defines in FACILITIES_KVM_CPUMODEL * and defines the facilities that can be enabled via a cpu model. */ -static unsigned long kvm_s390_fac_ext[SIZE_INTERNAL] = { 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[] = { FACILITIES_KVM_CPUMODEL }; +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <= S390_ARCH_FAC_MASK_SIZE_U64); +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <= S390_ARCH_FAC_LIST_SIZE_U64); +static_assert(ARRAY_SIZE(kvm_s390_fac_ext) <= ARRAY_SIZE(stfle_fac_list)); /* 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 = kvm; kvm->arch.model.fac_list = kvm->arch.sie_page2->fac_list; - for (i = 0; i < kvm_s390_fac_size(); i++) { + for (i = 0; i < ARRAY_SIZE(kvm_s390_fac_base); i++) { kvm->arch.model.fac_mask[i] = 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] = stfle_fac_list[i] & kvm_s390_fac_base[i]; } + for (i = 0; i < ARRAY_SIZE(kvm_s390_fac_ext); i++) { + kvm->arch.model.fac_mask[i] |= stfle_fac_list[i] & + kvm_s390_fac_ext[i]; + } kvm->arch.model.subfuncs = kvm_s390_available_subfunc; /* we are always in czam mode - even on pre z14 machines */ @@ -5859,9 +5854,8 @@ static int __init kvm_s390_init(void) return -EINVAL; } - for (i = 0; i < 16; i++) - kvm_s390_fac_base[i] |= - stfle_fac_list[i] & nonhyp_mask(i); + for (i = 0; i < HMFAI_DWORDS; i++) + kvm_s390_fac_base[i] |= nonhyp_mask(i); r = __kvm_s390_init(); if (r) -- 2.39.2