Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2311223rwb; Thu, 27 Jul 2023 05:35:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlG+U0XED9HuULkxJVYvVxwZitiLKZiMyxctce0MXdJiuRbFFPM3T4ehU6MjQSeMIAZV/7aE X-Received: by 2002:a17:907:b10:b0:98e:933:28fe with SMTP id h16-20020a1709070b1000b0098e093328femr1642868ejl.66.1690461309199; Thu, 27 Jul 2023 05:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690461309; cv=none; d=google.com; s=arc-20160816; b=S6MYz8e40gP4VTEGLvtNnfVjXFKBc2NLUXuLdfl33BZIQv+hWYha8W5nebqttye2Sw IWjariAYFlJgyKO7Gt0ggMCLyIgiTHg6O/bwFlmjaG6CyTojcP3aV3QcZK7/D4679ldc G88lOU5e+P8xX2uothxP/FoYI1DCez53t664GenLpfo3v40ee3WTzVpPbhOXEWqUuFCD T5F5GMt4CJg49n7z+10pKPItNf80IIbWdA73bUFeQNQ8XISGCL+B9I0IRQKkFM3+W3rk QESWRHIM2zTNDbSzU6Cn6nwFhKf+//uRTxbxIUjBaHPsBwqH3EnvpN/dhnR4iDmNsmje 8qnA== 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=Kb45gmG62YcJdhYbQumntF3jwUQ/CdCBL8RR1Aj1AQg=; fh=P4AoDd1q3SXDW+MbbYvFsez57D2nr/B/XNHsJiBn6AU=; b=KfTPFrzOrXqhJgHnv7E4hiSD9KmXxfH2f+gKibHqjCSsaj+rIyhwl0ya0atHq4hWto vUsPkvmAAOf6KoGdbdWOj/XUwVpybd+ySXtA59Cv9zix2rUau6bucar8SDckCtei99Fw 3EwrL91pZAbNebE2hnUwtzWCW3mnCv8Q/BQGaPiAkMR5wLOIUyA7vAmQ2/JOzkPUsqxu CG0xTV/Ug30rTJ8tTnOMjgy9rN5ekF+cg0szU9G2CKFELBpfO7MtLqiVnOd7Wo+1iLPY naOp8jYslYYJxukJ2VeVSYSqt6C3fH0UystD33FEh0v2/X6fg25N1i7JD/+y9xXNNAl5 T3bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=BpwOfpZ6; 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=REJECT 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 o26-20020a1709062e9a00b0099454cbf77csi925969eji.750.2023.07.27.05.34.44; Thu, 27 Jul 2023 05:35:09 -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=BpwOfpZ6; 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=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233899AbjG0MVM (ORCPT + 99 others); Thu, 27 Jul 2023 08:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232856AbjG0MVC (ORCPT ); Thu, 27 Jul 2023 08:21:02 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2842D51; Thu, 27 Jul 2023 05:21:00 -0700 (PDT) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36RC9a89031355; Thu, 27 Jul 2023 12:21:00 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=Kb45gmG62YcJdhYbQumntF3jwUQ/CdCBL8RR1Aj1AQg=; b=BpwOfpZ6tEUYcm9w3MjNpGJIyC7I5fpAR3LrwA8YWj+o2LxqGK5cPUq16sfAyd9O4M6P XmW03mUB2TpXTsI4ymBffwOGwKLITqyeagVolEo6TwDeGFfzJNCoIQjU0HPBMzZ/d+iS F3WqP4avYPDZV1/Y3dxljRiqc24u8XMj0nfeMSaMtTRM7m+FtYF4AccWpgZOAUNN1p/4 Yhcn11BncrmHj0KWHOhpuiKk8Miescto1CCc8FZh43UVn0JTha9WkIqzMidbeKocR3tq +MH+Fuu6q8936DRzazslFjCobNwYExb3K3GVVZA404MxferkboEeq9mi/J4aO41cVq85 ow== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3s3qmn1jpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 12:20:59 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36RCGKG8005156; Thu, 27 Jul 2023 12:20:59 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 3s3qmn1jpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 12:20:59 +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 36RAaZbG001973; Thu, 27 Jul 2023 12:20:58 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3s0tenddgb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jul 2023 12:20:57 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 36RCKsll25297528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 27 Jul 2023 12:20:54 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AB18F20040; Thu, 27 Jul 2023 12:20:54 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73FF520043; Thu, 27 Jul 2023 12:20:54 +0000 (GMT) Received: from a46lp73.lnxne.boe (unknown [9.152.108.100]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 27 Jul 2023 12:20:54 +0000 (GMT) From: Steffen Eiden To: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org Cc: Janosch Frank , Claudio Imbrenda , David Hildenbrand , Michael Mueller , Marc Hartmayer Subject: [PATCH 2/3] KVM: s390: Add UV feature negotiation Date: Thu, 27 Jul 2023 14:20:52 +0200 Message-Id: <20230727122053.774473-3-seiden@linux.ibm.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230727122053.774473-1-seiden@linux.ibm.com> References: <20230727122053.774473-1-seiden@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Pq7M_QJsaM7rWr4fepkm5SCoco_09SBv X-Proofpoint-ORIG-GUID: R1EnF9oHqEq8mRhdp0ks3TeTX-EBNCe_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-27_06,2023-07-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 phishscore=0 clxscore=1015 impostorscore=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307270108 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,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 Add a uv_feature list for pv-guests to the kvm cpu-model. The feature bits 'AP-interpretation for secure guests' and 'AP-interrupt for secure guests' are available. Signed-off-by: Steffen Eiden --- arch/s390/include/asm/kvm_host.h | 2 + arch/s390/include/uapi/asm/kvm.h | 24 +++++++++++ arch/s390/kvm/kvm-s390.c | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index 2bbc3d54959d..7ae57ac352b2 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -817,6 +817,8 @@ struct kvm_s390_cpu_model { __u64 *fac_list; u64 cpuid; unsigned short ibc; + /* subset of available uv features for pv-guests enabled by user space */ + struct kvm_s390_vm_cpu_uv_feat uv_feat_guest; }; typedef int (*crypto_hook)(struct kvm_vcpu *vcpu); diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h index a73cf01a1606..7ea7e4fbd37e 100644 --- a/arch/s390/include/uapi/asm/kvm.h +++ b/arch/s390/include/uapi/asm/kvm.h @@ -159,6 +159,30 @@ struct kvm_s390_vm_cpu_subfunc { __u8 reserved[1728]; }; +#define KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST 6 +#define KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST 7 + +#define KVM_S390_VM_CPU_UV_FEAT_NR_BITS 64 +struct kvm_s390_vm_cpu_uv_feat { + union { + struct { + __u64 res0 : 4; + __u64 ap : 1; /* bit 4 */ + __u64 ap_intr : 1; /* bit 5 */ + }; + __u64 feat; + }; +}; + +#define KVM_S390_VM_CPU_UV_FEAT_GUEST_MASK \ +(((struct kvm_s390_vm_cpu_uv_feat) { \ + .ap = 1, \ + .ap_intr = 1, \ +}).feat) + +#define KVM_S390_VM_CPU_UV_FEAT_GUEST_DEFAULT \ +((struct kvm_s390_vm_cpu_uv_feat) { }) + /* kvm attributes for crypto */ #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW 0 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW 1 diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c index 339e3190f6dc..50c8b85b89ac 100644 --- a/arch/s390/kvm/kvm-s390.c +++ b/arch/s390/kvm/kvm-s390.c @@ -1531,6 +1531,32 @@ static int kvm_s390_set_processor_subfunc(struct kvm *kvm, return 0; } +static int kvm_s390_set_uv_feat(struct kvm *kvm, struct kvm_device_attr *attr) +{ + struct kvm_s390_vm_cpu_uv_feat data = {}; + unsigned long filter = + uv_info.uv_feature_indications & + (unsigned long)KVM_S390_VM_CPU_UV_FEAT_GUEST_MASK; + + if (copy_from_user(&data, (void __user *)attr->addr, sizeof(data))) + return -EFAULT; + if (!bitmap_subset((unsigned long *)&data, &filter, + KVM_S390_VM_CPU_UV_FEAT_NR_BITS)) + return -EINVAL; + + mutex_lock(&kvm->lock); + if (kvm->created_vcpus) { + mutex_unlock(&kvm->lock); + return -EBUSY; + } + kvm->arch.model.uv_feat_guest = data; + mutex_unlock(&kvm->lock); + + VM_EVENT(kvm, 3, "SET: guest uv feat: 0x%16.16llx", data.feat); + + return 0; +} + static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) { int ret = -ENXIO; @@ -1545,6 +1571,9 @@ static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) case KVM_S390_VM_CPU_PROCESSOR_SUBFUNC: ret = kvm_s390_set_processor_subfunc(kvm, attr); break; + case KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST: + ret = kvm_s390_set_uv_feat(kvm, attr); + break; } return ret; } @@ -1777,6 +1806,37 @@ static int kvm_s390_get_machine_subfunc(struct kvm *kvm, return 0; } +static int kvm_s390_get_processor_uv_feat(struct kvm *kvm, + struct kvm_device_attr *attr) +{ + struct kvm_s390_vm_cpu_uv_feat *src = &kvm->arch.model.uv_feat_guest; + + if (copy_to_user((void __user *)attr->addr, src, sizeof(*src))) + return -EFAULT; + VM_EVENT(kvm, 3, "GET: guest uv feat: 0x%16.16llx", + kvm->arch.model.uv_feat_guest.feat); + + return 0; +} + +static int kvm_s390_get_machine_uv_feat(struct kvm *kvm, + struct kvm_device_attr *attr) +{ + struct kvm_s390_vm_cpu_uv_feat data = { + .feat = uv_info.uv_feature_indications & + KVM_S390_VM_CPU_UV_FEAT_GUEST_MASK + }; + + BUILD_BUG_ON(sizeof(struct kvm_s390_vm_cpu_uv_feat) != + sizeof(uv_info.uv_feature_indications)); + if (copy_to_user((void __user *)attr->addr, &data, + sizeof(struct kvm_s390_vm_cpu_uv_feat))) + return -EFAULT; + VM_EVENT(kvm, 3, "GET: guest uv feat: 0x%16.16llx", data.feat); + + return 0; +} + static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) { int ret = -ENXIO; @@ -1800,6 +1860,12 @@ static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) case KVM_S390_VM_CPU_MACHINE_SUBFUNC: ret = kvm_s390_get_machine_subfunc(kvm, attr); break; + case KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST: + ret = kvm_s390_get_processor_uv_feat(kvm, attr); + break; + case KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST: + ret = kvm_s390_get_machine_uv_feat(kvm, attr); + break; } return ret; } @@ -1952,6 +2018,8 @@ static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr) case KVM_S390_VM_CPU_MACHINE_FEAT: case KVM_S390_VM_CPU_MACHINE_SUBFUNC: case KVM_S390_VM_CPU_PROCESSOR_SUBFUNC: + case KVM_S390_VM_CPU_MACHINE_UV_FEAT_GUEST: + case KVM_S390_VM_CPU_PROCESSOR_UV_FEAT_GUEST: ret = 0; break; default: @@ -3292,6 +3360,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm->arch.model.cpuid = kvm_s390_get_initial_cpuid(); kvm->arch.model.ibc = sclp.ibc & 0x0fff; + kvm->arch.model.uv_feat_guest = KVM_S390_VM_CPU_UV_FEAT_GUEST_DEFAULT; + kvm_s390_crypto_init(kvm); if (IS_ENABLED(CONFIG_VFIO_PCI_ZDEV_KVM)) { -- 2.40.1