From nobody Sat Apr 11 15:29:14 2026 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 69F7BC28B2B for ; Wed, 10 Aug 2022 12:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbiHJM5D (ORCPT ); Wed, 10 Aug 2022 08:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232347AbiHJM4i (ORCPT ); Wed, 10 Aug 2022 08:56:38 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 816BD5B052; Wed, 10 Aug 2022 05:56:37 -0700 (PDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27ACobru003244; Wed, 10 Aug 2022 12:56:37 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=v3mI9pBXv3/3EDB31sjcbJrExOo43e9SJBGEzzM6aoY=; b=VKv0u51GqiotyTocik9nXEAbn4rf8EIcFM0uD0yif55nEAm9/3Sfa9Pp5J2dT/c3Dx+0 9bPDQSMZNw35aNeu6b0SXwQS/mT05bc8f8onBrw4YsG/AGFRhjEMiAj34hnwIgd4XhmL QV0zOI1mTiW24yz8Xw6biusazvMQ69kGf61CjkMCSTZWvgjGpdRKPgncDeyFX5XCcw9D 5iINyEWnSL5sZzgdaaR29Z/r7CbloldBR6ww0Kp1iFwEBaanztWY/n3Gguy5Eh0XE4+a VXYjfZlHNgYtRqY/iG/nhpoPlXbqo8wd7PqDb+I9pZf9czK5Lu4XFTFV8ejJuLcgnZpi UQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hv65w61rr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Aug 2022 12:56:37 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27ACphrq008714; Wed, 10 Aug 2022 12:56:36 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hv65w61qf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Aug 2022 12:56:36 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27ACuSp2012812; Wed, 10 Aug 2022 12:56:34 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma02fra.de.ibm.com with ESMTP id 3huww0ru73-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Aug 2022 12:56:33 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27ACuUTk36176156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Aug 2022 12:56:30 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6550F4C044; Wed, 10 Aug 2022 12:56:30 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFA094C040; Wed, 10 Aug 2022 12:56:29 +0000 (GMT) Received: from p-imbrenda.bredband2.com (unknown [9.145.0.105]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 10 Aug 2022 12:56:29 +0000 (GMT) From: Claudio Imbrenda To: kvm@vger.kernel.org Cc: borntraeger@de.ibm.com, frankja@linux.ibm.com, thuth@redhat.com, pasic@linux.ibm.com, david@redhat.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, scgl@linux.ibm.com, seiden@linux.ibm.com, nrb@linux.ibm.com Subject: [PATCH v13 5/6] KVM: s390: pv: support for Destroy fast UVC Date: Wed, 10 Aug 2022 14:56:24 +0200 Message-Id: <20220810125625.45295-6-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810125625.45295-1-imbrenda@linux.ibm.com> References: <20220810125625.45295-1-imbrenda@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3QomBZ9wUqO9A9fV37DLo3O_WznEyn9e X-Proofpoint-GUID: IXafiDRlK-u9tz6baDTWsCUPuoLDcp-A X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-10_07,2022-08-10_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxlogscore=999 impostorscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 suspectscore=0 priorityscore=1501 phishscore=0 mlxscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208100037 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for the Destroy Secure Configuration Fast Ultravisor call, and take advantage of it for asynchronous destroy. When supported, the protected guest is destroyed immediately using the new UVC, leaving only the memory to be cleaned up asynchronously. Signed-off-by: Claudio Imbrenda Reviewed-by: Janosch Frank Reviewed-by: Nico Boehr --- arch/s390/include/asm/uv.h | 10 +++++++ arch/s390/kvm/pv.c | 57 ++++++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h index be3ef9dd6972..28a9ad57b6f1 100644 --- a/arch/s390/include/asm/uv.h +++ b/arch/s390/include/asm/uv.h @@ -34,6 +34,7 @@ #define UVC_CMD_INIT_UV 0x000f #define UVC_CMD_CREATE_SEC_CONF 0x0100 #define UVC_CMD_DESTROY_SEC_CONF 0x0101 +#define UVC_CMD_DESTROY_SEC_CONF_FAST 0x0102 #define UVC_CMD_CREATE_SEC_CPU 0x0120 #define UVC_CMD_DESTROY_SEC_CPU 0x0121 #define UVC_CMD_CONV_TO_SEC_STOR 0x0200 @@ -81,6 +82,7 @@ enum uv_cmds_inst { BIT_UVC_CMD_UNSHARE_ALL =3D 20, BIT_UVC_CMD_PIN_PAGE_SHARED =3D 21, BIT_UVC_CMD_UNPIN_PAGE_SHARED =3D 22, + BIT_UVC_CMD_DESTROY_SEC_CONF_FAST =3D 23, BIT_UVC_CMD_DUMP_INIT =3D 24, BIT_UVC_CMD_DUMP_CONFIG_STOR_STATE =3D 25, BIT_UVC_CMD_DUMP_CPU =3D 26, @@ -230,6 +232,14 @@ struct uv_cb_nodata { u64 reserved20[4]; } __packed __aligned(8); =20 +/* Destroy Configuration Fast */ +struct uv_cb_destroy_fast { + struct uv_cb_header header; + u64 reserved08[2]; + u64 handle; + u64 reserved20[5]; +} __packed __aligned(8); + /* Set Shared Access */ struct uv_cb_share { struct uv_cb_header header; diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c index eba4f3fc2138..160ef95cea68 100644 --- a/arch/s390/kvm/pv.c +++ b/arch/s390/kvm/pv.c @@ -201,6 +201,9 @@ static int kvm_s390_pv_dispose_one_leftover(struct kvm = *kvm, { int cc; =20 + /* It used the destroy-fast UVC, nothing left to do here */ + if (!leftover->handle) + goto done_fast; cc =3D uv_cmd_nodata(leftover->handle, UVC_CMD_DESTROY_SEC_CONF, rc, rrc); KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY LEFTOVER VM: rc %x rrc %x", *rc, *= rrc); WARN_ONCE(cc, "protvirt destroy leftover vm failed rc %x rrc %x", *rc, *r= rc); @@ -215,6 +218,7 @@ static int kvm_s390_pv_dispose_one_leftover(struct kvm = *kvm, free_pages(leftover->stor_base, get_order(uv_info.guest_base_stor_len)); free_pages(leftover->old_gmap_table, CRST_ALLOC_ORDER); vfree(leftover->stor_var); +done_fast: atomic_dec(&kvm->mm->context.protected_count); return 0; } @@ -248,6 +252,32 @@ static void kvm_s390_destroy_lower_2g(struct kvm *kvm) srcu_read_unlock(&kvm->srcu, srcu_idx); } =20 +static int kvm_s390_pv_deinit_vm_fast(struct kvm *kvm, u16 *rc, u16 *rrc) +{ + struct uv_cb_destroy_fast uvcb =3D { + .header.cmd =3D UVC_CMD_DESTROY_SEC_CONF_FAST, + .header.len =3D sizeof(uvcb), + .handle =3D kvm_s390_pv_get_handle(kvm), + }; + int cc; + + cc =3D uv_call_sched(0, (u64)&uvcb); + *rc =3D uvcb.header.rc; + *rrc =3D uvcb.header.rrc; + WRITE_ONCE(kvm->arch.gmap->guest_handle, 0); + KVM_UV_EVENT(kvm, 3, "PROTVIRT DESTROY VM FAST: rc %x rrc %x", *rc, *rrc); + WARN_ONCE(cc, "protvirt destroy vm fast failed rc %x rrc %x", *rc, *rrc); + /* Inteded memory leak on "impossible" error */ + if (!cc) + kvm_s390_pv_dealloc_vm(kvm); + return cc ? -EIO : 0; +} + +static inline bool is_destroy_fast_available(void) +{ + return test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CONF_FAST, uv_info.inst_calls= _list); +} + /** * kvm_s390_pv_set_aside - Set aside a protected VM for later teardown. * @kvm: the VM @@ -269,6 +299,7 @@ static void kvm_s390_destroy_lower_2g(struct kvm *kvm) int kvm_s390_pv_set_aside(struct kvm *kvm, u16 *rc, u16 *rrc) { struct pv_vm_to_be_destroyed *priv; + int res =3D 0; =20 /* * If another protected VM was already prepared, refuse. @@ -280,14 +311,21 @@ int kvm_s390_pv_set_aside(struct kvm *kvm, u16 *rc, u= 16 *rrc) if (!priv) return -ENOMEM; =20 - priv->stor_var =3D kvm->arch.pv.stor_var; - priv->stor_base =3D kvm->arch.pv.stor_base; - priv->handle =3D kvm_s390_pv_get_handle(kvm); - priv->old_gmap_table =3D (unsigned long)kvm->arch.gmap->table; - WRITE_ONCE(kvm->arch.gmap->guest_handle, 0); - if (s390_replace_asce(kvm->arch.gmap)) { + if (is_destroy_fast_available()) { + res =3D kvm_s390_pv_deinit_vm_fast(kvm, rc, rrc); + } else { + priv->stor_var =3D kvm->arch.pv.stor_var; + priv->stor_base =3D kvm->arch.pv.stor_base; + priv->handle =3D kvm_s390_pv_get_handle(kvm); + priv->old_gmap_table =3D (unsigned long)kvm->arch.gmap->table; + WRITE_ONCE(kvm->arch.gmap->guest_handle, 0); + if (s390_replace_asce(kvm->arch.gmap)) + res =3D -ENOMEM; + } + + if (res) { kfree(priv); - return -ENOMEM; + return res; } =20 kvm_s390_destroy_lower_2g(kvm); @@ -464,6 +502,7 @@ static void kvm_s390_pv_mmu_notifier_release(struct mmu= _notifier *subscription, { struct kvm *kvm =3D container_of(subscription, struct kvm, arch.pv.mmu_no= tifier); u16 dummy; + int r; =20 /* * No locking is needed since this is the last thread of the last user of= this @@ -472,7 +511,9 @@ static void kvm_s390_pv_mmu_notifier_release(struct mmu= _notifier *subscription, * unregistered. This means that if this notifier runs, then the * struct kvm is still valid. */ - kvm_s390_cpus_from_pv(kvm, &dummy, &dummy); + r =3D kvm_s390_cpus_from_pv(kvm, &dummy, &dummy); + if (!r && is_destroy_fast_available()) + kvm_s390_pv_deinit_vm_fast(kvm, &dummy, &dummy); } =20 static const struct mmu_notifier_ops kvm_s390_pv_mmu_notifier_ops =3D { --=20 2.37.1