Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp961586pxp; Wed, 16 Mar 2022 22:44:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5iXGDMHHN5xn+DcW7RRX+/bjn5YNuMm/DUK7bArhd8+KzARH16SpwOoITGnk/+raOu2Zb X-Received: by 2002:a17:902:da91:b0:153:cc84:f13f with SMTP id j17-20020a170902da9100b00153cc84f13fmr3381635plx.38.1647495867078; Wed, 16 Mar 2022 22:44:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647495867; cv=none; d=google.com; s=arc-20160816; b=tnhCJ19Q0VYeeOJduxbYwO+U5Dx/H7J6rpFhQKxJfxd0b5QgOmKdKrd7W5+nnRzWJZ uLjEYEL+3nLxHC3E4fXsALCUluiW3by8Dl3OMvuD9m/mBL+3sNObeaWrp16Waber0tRw kyKoogvivn7C/EWana+a/zdtGv+w1q9pW90/HugXfBNJi4rTcWBDlMMT7rktNAo7kqlh oUZMcoWBkK3TDEiWFyvkobR2gDBPdTwFlRI2JUmEs8VAwfm2nHq0yISia20RvTaff4Sf vtVLU8lfVgauI+k9v2QSqyWPZ4drb5lPvCZDz72Bi7TFHPmtj0m3KHzPw3Pc0xs1c96G iaZw== 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=qLUS2zARls4/eGqBXbr08Qf4l3tdqMxvywRg1Oh8EPg=; b=ralKSazlfF5NxjuL5w3ereOQMVeno4ACc+vHlIWbjf0JGGc9QxHB9oCYlu5SHi5TJ1 AMhahEmJUsYfWIi7JHzbPBaicAjRC1rMzZPcJ/cU4C8w60TK4AqGxtDLwj1JNSzwlfUg c/NQGxOrM6YDZnwqYuSBWfOYpPtrljiOP5ZiH/xbp71z0LtbQrdEH5cR+Hoov0QchF6P 9/U0ZqBnGsFhQrMiDFBJd2MinjO2qcTL2/TzulScOg1UGL9LLE2LL4+d4TMvkN3HXk8a XSCfUOIwFHuWSIsbvADIi5YpgZLzmHxIcSI+qGA0UDPc2qcMdVgELA4qXa1Qxi9ASpPZ k2pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=THUmzvwT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l5-20020a17090aec0500b001bfc324fc16si3400053pjy.99.2022.03.16.22.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 22:44:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=THUmzvwT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7358F105057; Wed, 16 Mar 2022 21:38:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244596AbiCNTup (ORCPT + 99 others); Mon, 14 Mar 2022 15:50:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244544AbiCNTu0 (ORCPT ); Mon, 14 Mar 2022 15:50:26 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EA9113EA8; Mon, 14 Mar 2022 12:48:56 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 22EJlZXE025722; Mon, 14 Mar 2022 19:48:43 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=qLUS2zARls4/eGqBXbr08Qf4l3tdqMxvywRg1Oh8EPg=; b=THUmzvwToDDcbbIaxPbX1ZxtJD/tRO6r4RK7NUeedsQN7q8JWlHewVNdzXQ+TU3bxVmM i/uRGzR3N2GKJCK5bbdcGCIKxRk9aQhX/nuG57Qc4jD0FMw939MuJqKdWXn5Ze4PO3pq N4A95RDPaY+CHAOfADKcQhRYLhDrgtyorHKP3943C+f/+j4z9LGtdGFtA5Cr6Eis+sdS vDCpNjmFai2ShppA4DsTqMTD4BvClehwZMUxwjzLBGfcBnf7usjtymlawpp+urDJr2G9 XgpSQRGgB4n8hADwQBgJ0+vHS2nW7eyo/dt62zsL/121TZaJgtDhg7lPTR5msQDlEZJg tg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3et6ag0y40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Mar 2022 19:48:42 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 22EJmgcb032260; Mon, 14 Mar 2022 19:48:42 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 3et6ag0y3m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Mar 2022 19:48:42 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 22EJlB1S005387; Mon, 14 Mar 2022 19:48:40 GMT Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by ppma01wdc.us.ibm.com with ESMTP id 3erk5989br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Mar 2022 19:48:40 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 22EJmdVj34996614 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Mar 2022 19:48:39 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43117112062; Mon, 14 Mar 2022 19:48:39 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CD0711206E; Mon, 14 Mar 2022 19:48:30 +0000 (GMT) Received: from li-c92d2ccc-254b-11b2-a85c-a700b5bfb098.ibm.com.com (unknown [9.211.32.184]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 14 Mar 2022 19:48:29 +0000 (GMT) From: Matthew Rosato To: linux-s390@vger.kernel.org Cc: alex.williamson@redhat.com, cohuck@redhat.com, schnelle@linux.ibm.com, farman@linux.ibm.com, pmorel@linux.ibm.com, borntraeger@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, gerald.schaefer@linux.ibm.com, agordeev@linux.ibm.com, svens@linux.ibm.com, frankja@linux.ibm.com, david@redhat.com, imbrenda@linux.ibm.com, vneethv@linux.ibm.com, oberpar@linux.ibm.com, freude@linux.ibm.com, thuth@redhat.com, pasic@linux.ibm.com, joro@8bytes.org, will@kernel.org, pbonzini@redhat.com, corbet@lwn.net, jgg@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-doc@vger.kernel.org Subject: [PATCH v4 21/32] KVM: s390: mechanism to enable guest zPCI Interpretation Date: Mon, 14 Mar 2022 15:44:40 -0400 Message-Id: <20220314194451.58266-22-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220314194451.58266-1-mjrosato@linux.ibm.com> References: <20220314194451.58266-1-mjrosato@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6Qj65mQKEXfsEP4ZuwPaKSmMwIZK4i8T X-Proofpoint-GUID: tFdt_d0RisMYzEQOMjKNgDtCVCIIFVpQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.850,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-03-14_13,2022-03-14_02,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 bulkscore=0 malwarescore=0 adultscore=0 phishscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2203140116 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 The guest must have access to certain facilities in order to allow interpretive execution of zPCI instructions and adapter event notifications. However, there are some cases where a guest might disable interpretation -- provide a mechanism via which we can defer enabling the associated zPCI interpretation facilities until the guest indicates it wishes to use them. Acked-by: Pierre Morel Signed-off-by: Matthew Rosato --- arch/s390/include/asm/kvm_host.h | 4 ++++ arch/s390/kvm/kvm-s390.c | 41 ++++++++++++++++++++++++++++++++ arch/s390/kvm/kvm-s390.h | 10 ++++++++ 3 files changed, 55 insertions(+) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index b468d3a2215e..bf61ab05f98c 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -252,7 +252,10 @@ struct kvm_s390_sie_block { #define ECB2_IEP 0x20 #define ECB2_PFMFI 0x08 #define ECB2_ESCA 0x04 +#define ECB2_ZPCI_LSI 0x02 __u8 ecb2; /* 0x0062 */ +#define ECB3_AISI 0x20 +#define ECB3_AISII 0x10 #define ECB3_DEA 0x08 #define ECB3_AES 0x04 #define ECB3_RI 0x01 @@ -938,6 +941,7 @@ struct kvm_arch{ int use_cmma; int use_pfmfi; int use_skf; + int use_zpci_interp; int user_cpu_state_ctrl; int user_sigp; int user_stsi; diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 32e75f6f4e4d..d91b2547f0bf 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1029,6 +1029,45 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr) return 0; } +static void kvm_s390_vcpu_pci_setup(struct kvm_vcpu *vcpu) +{ + /* Only set the ECB bits after guest requests zPCI interpretation */ + if (!vcpu->kvm->arch.use_zpci_interp) + return; + + vcpu->arch.sie_block->ecb2 |= ECB2_ZPCI_LSI; + vcpu->arch.sie_block->ecb3 |= ECB3_AISII + ECB3_AISI; +} + +void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm) +{ + struct kvm_vcpu *vcpu; + unsigned long i; + + /* + * If host is configured for PCI and the necessary facilities are + * available, turn on interpretation for the life of this guest + */ + if (!sclp.has_zpci_lsi || !sclp.has_aisii || !sclp.has_aeni || + !sclp.has_aisi || !IS_ENABLED(CONFIG_VFIO_PCI) || + !IS_ENABLED(CONFIG_S390_KVM_IOMMU)) + return; + + mutex_lock(&kvm->lock); + + kvm->arch.use_zpci_interp = 1; + + kvm_s390_vcpu_block_all(kvm); + + kvm_for_each_vcpu(i, vcpu, kvm) { + kvm_s390_vcpu_pci_setup(vcpu); + kvm_s390_sync_request(KVM_REQ_VSIE_RESTART, vcpu); + } + + kvm_s390_vcpu_unblock_all(kvm); + mutex_unlock(&kvm->lock); +} + static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req) { unsigned long cx; @@ -3236,6 +3275,8 @@ static int kvm_s390_vcpu_setup(struct kvm_vcpu *vcpu) kvm_s390_vcpu_crypto_setup(vcpu); + kvm_s390_vcpu_pci_setup(vcpu); + mutex_lock(&vcpu->kvm->lock); if (kvm_s390_pv_is_protected(vcpu->kvm)) { rc = kvm_s390_pv_create_cpu(vcpu, &uvrc, &uvrrc); diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index 098831e815e6..14bb2539f837 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -496,6 +496,16 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu, */ void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm); +/** + * kvm_s390_vcpu_pci_enable_interp + * + * Set the associated PCI attributes for each vcpu to allow for zPCI Load/Store + * interpretation as well as adapter interruption forwarding. + * + * @kvm: the KVM guest + */ +void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm); + /** * diag9c_forwarding_hz * -- 2.27.0