Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1035962iof; Mon, 6 Jun 2022 18:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWZotgFetx/Yr8gW0Hr/qU21cLvsJqb+rPlBbNi/qL0x7tU3DDs+DKcLaxFG4KH2u+mB40 X-Received: by 2002:a17:907:9612:b0:705:5ed9:ece4 with SMTP id gb18-20020a170907961200b007055ed9ece4mr24208027ejc.113.1654566407414; Mon, 06 Jun 2022 18:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654566407; cv=none; d=google.com; s=arc-20160816; b=XS5Dlbqm/rE0W083XYFiTA4ysgygGSDqUFaY+MDszbF12yEfCLb8awcmN/mRum/G1+ yH9e9IdTA9QkBQ7vMMAKA2qsSrmTIGhasT8sIcAFJGiW/MXHNK81AvA4gzBAO+0cjKL0 rw+vJyXNSGHD+lmrIdmg/Ci4s/R4aluUd8OgFZ3uwlmASz9Egpk+ZJyP3RzUd3BmBAPh WXX7sOXC8mQ22y7miQ+3pLRgJJeUVHcUBdaP+YrI/wLlh1NF9CMHKHtoRy681o9TvvKp fg35Z30CiItGFqMllsjKnuVBXqWGDYzRgTAwYEv2rcPaOpvDellJxIkANlzNHuWUSnBG RgZg== 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=2hqTfkWRCNXoG6EJfq+z3z2Rc0hH7NHiHHHph71pG6g=; b=FFYkccmfCj1N1r6yzLI8eK4GQYAcQsK5ZNs7yg66CZ1C2Fr1Bc4BmkXd/c0SX9JWxM SFdfiXHYZWwnkr2eCb62OKwoAdH2C170w7b07ss6Re4BySfpV3+8//0EaX4avpcb9KZ0 C3Ui73GZSD8dgBwBI6rYpdOJzq5zWM5jon3/+kU+H6LSPecirdd0+HhDDiYiMbUQJ6l/ dXzgbDRDAEoO65xxN9EZSV93PRwXygkypD+XXwovr72Mk4Xhr4Xxn09syhf/65dSh4DK Sk+T6hxt3VvtcjzBC9a5iGr4KAyTsPKCsiQYLvGhU4jzF32hnAth97DYpynsZDRPVHuK R+vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=eDhJMsJ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oq21-20020a170906cc9500b006e88cc5c374si16369169ejb.179.2022.06.06.18.46.22; Mon, 06 Jun 2022 18:46:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=eDhJMsJ0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234165AbiFFUhW (ORCPT + 99 others); Mon, 6 Jun 2022 16:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234139AbiFFUhG (ORCPT ); Mon, 6 Jun 2022 16:37:06 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F292C9D4C0; Mon, 6 Jun 2022 13:35:10 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 256KV1Qx029073; Mon, 6 Jun 2022 20:35:07 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=2hqTfkWRCNXoG6EJfq+z3z2Rc0hH7NHiHHHph71pG6g=; b=eDhJMsJ0u5/tpMQKm7iLsoMIUaXb/lNxvP2udxPYrT55eWjoQ9RiyxeILx3h/zgqjL3p a7e3CJujRYIvxqNPtfN3Uax+dFtLl6k/7WYlvf5vcUWpUI2t1nmcOd1+mh4FcSSD0pMQ Mimd+NUXKSjUR6ugiHmiqUhY+BLz7ULRKG3rD7gVt8N5KveaVxI76Lrp+ROoYN7hbAah IRdb4fIpkejcrZwBNuuuYKdnJ5V7VblvRCOM7CXbjWq5VhCH/stxJI3wSrBbpedjzHPs 7Ttyv8xV07yNYOeVfGvxqCgNQYADX3+xvWLxRrPM/UvFkVa98ATMok8EUDpEqGze8d1A 5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ghpqfj8je-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Jun 2022 20:35:06 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 256KVRGa031251; Mon, 6 Jun 2022 20:35:06 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ghpqfj8hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Jun 2022 20:35:06 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 256KLQVA007318; Mon, 6 Jun 2022 20:35:05 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma02dal.us.ibm.com with ESMTP id 3gfy1abrdy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Jun 2022 20:35:05 +0000 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 256KZ4oq42598806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 6 Jun 2022 20:35:04 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7310D28059; Mon, 6 Jun 2022 20:35:04 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DFFCA2805A; Mon, 6 Jun 2022 20:34:58 +0000 (GMT) Received: from li-c92d2ccc-254b-11b2-a85c-a700b5bfb098.ibm.com.com (unknown [9.163.20.188]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 6 Jun 2022 20:34:58 +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, pbonzini@redhat.com, corbet@lwn.net, jgg@nvidia.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [PATCH v9 14/21] KVM: s390: mechanism to enable guest zPCI Interpretation Date: Mon, 6 Jun 2022 16:33:18 -0400 Message-Id: <20220606203325.110625-15-mjrosato@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220606203325.110625-1-mjrosato@linux.ibm.com> References: <20220606203325.110625-1-mjrosato@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: UU_ChKh6AB72XBRcmgKZNS16SFTiRGJu X-Proofpoint-GUID: T6bkhjvEG7PbRqkp9E6pwig3iRfPhk9Q X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-06_06,2022-06-03_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206060081 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,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 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. Reviewed-by: Christian Borntraeger Reviewed-by: Pierre Morel Signed-off-by: Matthew Rosato --- arch/s390/include/asm/kvm_host.h | 4 ++++ arch/s390/kvm/kvm-s390.c | 38 ++++++++++++++++++++++++++++++++ arch/s390/kvm/kvm-s390.h | 10 +++++++++ 3 files changed, 52 insertions(+) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index c1518a505060..8e381603b6a7 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -254,7 +254,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 @@ -940,6 +943,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 d96c9be0480b..a66da3f66114 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1031,6 +1031,42 @@ 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; + + lockdep_assert_held(&kvm->lock); + + if (!kvm_s390_pci_interp_allowed()) + return; + + /* + * If host is configured for PCI and the necessary facilities are + * available, turn on interpretation for the life of this guest + */ + 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); +} + static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req) { unsigned long cx; @@ -3336,6 +3372,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 497d52a83c78..975cffaf13de 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h @@ -507,6 +507,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