From nobody Thu May 16 19:23:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1672833225273740.1750664413045; Wed, 4 Jan 2023 03:53:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pD2Ix-0007UF-Hi; Wed, 04 Jan 2023 06:51:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2Iw-0007S8-4X; Wed, 04 Jan 2023 06:51:34 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2Iu-0002PF-DV; Wed, 04 Jan 2023 06:51:33 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nn7H32JpWz4y0Q; Wed, 4 Jan 2023 22:51:27 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Nn7Gy6Zy1z4y0B; Wed, 4 Jan 2023 22:51:22 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Eric Farman , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang Subject: [PATCH 1/5] confidential guest support: Introduce a 'check' class handler Date: Wed, 4 Jan 2023 12:51:07 +0100 Message-Id: <20230104115111.3240594-2-clg@kaod.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104115111.3240594-1-clg@kaod.org> References: <20230104115111.3240594-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=6L6x=5B=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1672833226459100003 From: C=C3=A9dric Le Goater Some machines have specific requirements to activate confidential guest support. Add a class handler to the confidential guest support interface to let the arch implementation perform extra checks. Cc: Eduardo Habkost Cc: Marcel Apfelbaum Cc: "Philippe Mathieu-Daud=C3=A9" Cc: Yanan Wang Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Thomas Huth --- include/exec/confidential-guest-support.h | 4 +++- hw/core/machine.c | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/exec/confidential-guest-support.h b/include/exec/confi= dential-guest-support.h index ba2dd4b5df..9e6d362b26 100644 --- a/include/exec/confidential-guest-support.h +++ b/include/exec/confidential-guest-support.h @@ -23,7 +23,8 @@ #include "qom/object.h" =20 #define TYPE_CONFIDENTIAL_GUEST_SUPPORT "confidential-guest-support" -OBJECT_DECLARE_SIMPLE_TYPE(ConfidentialGuestSupport, CONFIDENTIAL_GUEST_SU= PPORT) +OBJECT_DECLARE_TYPE(ConfidentialGuestSupport, ConfidentialGuestSupportClas= s, + CONFIDENTIAL_GUEST_SUPPORT) =20 struct ConfidentialGuestSupport { Object parent; @@ -55,6 +56,7 @@ struct ConfidentialGuestSupport { =20 typedef struct ConfidentialGuestSupportClass { ObjectClass parent; + bool (*check)(const Object *obj, Error **errp); } ConfidentialGuestSupportClass; =20 #endif /* !CONFIG_USER_ONLY */ diff --git a/hw/core/machine.c b/hw/core/machine.c index f589b92909..bab43cd675 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -502,11 +502,12 @@ static void machine_check_confidential_guest_support(= const Object *obj, Object *new_target, Error **errp) { - /* - * So far the only constraint is that the target has the - * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked - * by the QOM core - */ + ConfidentialGuestSupportClass *cgsc =3D + CONFIDENTIAL_GUEST_SUPPORT_GET_CLASS(new_target); + + if (cgsc->check) { + cgsc->check(obj, errp); + } } =20 static bool machine_get_nvdimm(Object *obj, Error **errp) --=20 2.38.1 From nobody Thu May 16 19:23:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1672833139606786.5790446720118; Wed, 4 Jan 2023 03:52:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pD2Iy-0007VD-63; Wed, 04 Jan 2023 06:51:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2Ix-0007Tj-4b; Wed, 04 Jan 2023 06:51:35 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2Iv-0002Pm-Fl; Wed, 04 Jan 2023 06:51:34 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nn7H66HDyz4y0f; Wed, 4 Jan 2023 22:51:30 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Nn7H35vnfz4y0B; Wed, 4 Jan 2023 22:51:27 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Eric Farman , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH 2/5] s390x/pv: Implement CGS check handler Date: Wed, 4 Jan 2023 12:51:08 +0100 Message-Id: <20230104115111.3240594-3-clg@kaod.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104115111.3240594-1-clg@kaod.org> References: <20230104115111.3240594-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=6L6x=5B=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1672833140134100001 From: C=C3=A9dric Le Goater When a protected VM is started with the maximum number of CPUs (248), the service call providing information on the CPUs requires more buffer space than allocated and QEMU disgracefully aborts : LOADPARM=3D[........] Using virtio-blk. Using SCSI scheme. .......................................................................= ............ qemu-system-s390x: KVM_S390_MEM_OP failed: Argument list too long Implement a test for this limitation in the ConfidentialGuestSupportClass check handler and provide some valid information to the user before the machine starts. Signed-off-by: C=C3=A9dric Le Goater --- hw/s390x/pv.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 8dfe92d8df..3a7ec70634 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -266,6 +266,26 @@ int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Er= ror **errp) return 0; } =20 +static bool s390_pv_check_cpus(Error **errp) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + uint32_t pv_max_cpus =3D mc->max_cpus - 1; + + if (ms->smp.max_cpus > pv_max_cpus) { + error_setg(errp, "Protected VMs support a maximum of %d CPUs", + pv_max_cpus); + return false; + } + + return true; +} + +static bool s390_pv_guest_check(const Object *obj, Error **errp) +{ + return s390_pv_check_cpus(errp); +} + OBJECT_DEFINE_TYPE_WITH_INTERFACES(S390PVGuest, s390_pv_guest, S390_PV_GUEST, @@ -275,6 +295,9 @@ OBJECT_DEFINE_TYPE_WITH_INTERFACES(S390PVGuest, =20 static void s390_pv_guest_class_init(ObjectClass *oc, void *data) { + ConfidentialGuestSupportClass *cgsc =3D CONFIDENTIAL_GUEST_SUPPORT_CLA= SS(oc); + + cgsc->check =3D s390_pv_guest_check; } =20 static void s390_pv_guest_init(Object *obj) --=20 2.38.1 From nobody Thu May 16 19:23:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1672833119395919.7264469633882; Wed, 4 Jan 2023 03:51:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pD2J5-0007bN-Tx; Wed, 04 Jan 2023 06:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J4-0007b7-QC; Wed, 04 Jan 2023 06:51:42 -0500 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J3-0002QT-5Y; Wed, 04 Jan 2023 06:51:42 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nn7HB37l9z4y0g; Wed, 4 Jan 2023 22:51:34 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Nn7H72mzdz4y0B; Wed, 4 Jan 2023 22:51:31 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Eric Farman , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH 3/5] s390x/pv: Check for support on the host Date: Wed, 4 Jan 2023 12:51:09 +0100 Message-Id: <20230104115111.3240594-4-clg@kaod.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104115111.3240594-1-clg@kaod.org> References: <20230104115111.3240594-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=6L6x=5B=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1672833120286100001 From: C=C3=A9dric Le Goater Support for protected VMs should have been enabled on the host with the kernel parameter 'prot_virt=3D1'. If the hardware supports the feature, it is reflected under sysfs. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Thomas Huth --- hw/s390x/pv.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 3a7ec70634..8d0d3f4adc 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -14,6 +14,7 @@ #include =20 #include "qapi/error.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" #include "qom/object_interfaces.h" @@ -281,9 +282,29 @@ static bool s390_pv_check_cpus(Error **errp) return true; } =20 +#define S390_PV_HOST "/sys/firmware/uv/prot_virt_host" + +static bool s390_pv_check_host(Error **errp) +{ + gchar *s =3D NULL; + uint64_t pv_host =3D 0; + + if (g_file_get_contents(S390_PV_HOST, &s, NULL, NULL)) { + pv_host =3D g_ascii_strtoull(s, NULL, 10); + } + g_free(s); + + if (pv_host !=3D 1) { + error_setg(errp, "Host does not support protected VMs"); + return false; + } + + return true; +} + static bool s390_pv_guest_check(const Object *obj, Error **errp) { - return s390_pv_check_cpus(errp); + return s390_pv_check_cpus(errp) && s390_pv_check_host(errp); } =20 OBJECT_DEFINE_TYPE_WITH_INTERFACES(S390PVGuest, --=20 2.38.1 From nobody Thu May 16 19:23:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1672833154159154.66668358136042; Wed, 4 Jan 2023 03:52:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pD2J6-0007c1-RR; Wed, 04 Jan 2023 06:51:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J5-0007bJ-Nf; Wed, 04 Jan 2023 06:51:43 -0500 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J3-0002Ql-LC; Wed, 04 Jan 2023 06:51:43 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nn7HG00yWz4y0k; Wed, 4 Jan 2023 22:51:38 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Nn7HB6lK4z4y0B; Wed, 4 Jan 2023 22:51:34 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Eric Farman , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH 4/5] s390x/pv: Introduce a s390_pv_check() helper for runtime Date: Wed, 4 Jan 2023 12:51:10 +0100 Message-Id: <20230104115111.3240594-5-clg@kaod.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104115111.3240594-1-clg@kaod.org> References: <20230104115111.3240594-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=6L6x=5B=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1672833156177100003 From: C=C3=A9dric Le Goater If a secure kernel is started in a non-protected VM, the OS will hang during boot without giving a proper error message to the user. Perform the checks on Confidential Guest support at runtime with an helper called from the service call switching the guest to protected mode. Signed-off-by: C=C3=A9dric Le Goater --- include/hw/s390x/pv.h | 2 ++ hw/s390x/pv.c | 14 ++++++++++++++ target/s390x/diag.c | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h index 9360aa1091..ca7dac2e20 100644 --- a/include/hw/s390x/pv.h +++ b/include/hw/s390x/pv.h @@ -55,6 +55,7 @@ int kvm_s390_dump_init(void); int kvm_s390_dump_cpu(S390CPU *cpu, void *buff); int kvm_s390_dump_mem_state(uint64_t addr, size_t len, void *dest); int kvm_s390_dump_completion_data(void *buff); +bool s390_pv_check(Error **errp); #else /* CONFIG_KVM */ static inline bool s390_is_pv(void) { return false; } static inline int s390_pv_query_info(void) { return 0; } @@ -75,6 +76,7 @@ static inline int kvm_s390_dump_cpu(S390CPU *cpu, void *b= uff) { return 0; } static inline int kvm_s390_dump_mem_state(uint64_t addr, size_t len, void *dest) { return 0; } static inline int kvm_s390_dump_completion_data(void *buff) { return 0; } +static inline bool s390_pv_check(Error **errp) { return false; } #endif /* CONFIG_KVM */ =20 int s390_pv_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 8d0d3f4adc..96c0728ec9 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -307,6 +307,20 @@ static bool s390_pv_guest_check(const Object *obj, Err= or **errp) return s390_pv_check_cpus(errp) && s390_pv_check_host(errp); } =20 +bool s390_pv_check(Error **errp) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + Object *obj =3D OBJECT(ms->cgs); + + if (!obj) { + error_setg(errp, "Protected VM started without a Confidential" + " Guest support interface"); + return false; + } + + return s390_pv_guest_check(obj, errp); +} + OBJECT_DEFINE_TYPE_WITH_INTERFACES(S390PVGuest, s390_pv_guest, S390_PV_GUEST, diff --git a/target/s390x/diag.c b/target/s390x/diag.c index 76b01dcd68..9b16e25930 100644 --- a/target/s390x/diag.c +++ b/target/s390x/diag.c @@ -79,6 +79,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uin= t64_t r3, uintptr_t ra) uint64_t addr =3D env->regs[r1]; uint64_t subcode =3D env->regs[r3]; IplParameterBlock *iplb; + Error *local_err =3D NULL; =20 if (env->psw.mask & PSW_MASK_PSTATE) { s390_program_interrupt(env, PGM_PRIVILEGED, ra); @@ -176,6 +177,12 @@ out: return; } =20 + if (!s390_pv_check(&local_err)) { + error_report_err(local_err); + env->regs[r1 + 1] =3D DIAG_308_RC_INVAL_FOR_PV; + return; + } + s390_ipl_reset_request(cs, S390_RESET_PV); break; default: --=20 2.38.1 From nobody Thu May 16 19:23:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1672833230590879.943698457258; Wed, 4 Jan 2023 03:53:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pD2J8-0007d7-KF; Wed, 04 Jan 2023 06:51:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J7-0007ce-Pq; Wed, 04 Jan 2023 06:51:45 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pD2J5-0002Sr-Tj; Wed, 04 Jan 2023 06:51:45 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Nn7HK41F6z4y0W; Wed, 4 Jan 2023 22:51:41 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Nn7HG3cwQz4y0B; Wed, 4 Jan 2023 22:51:38 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-s390x@nongnu.org Cc: qemu-devel@nongnu.org, Thomas Huth , Halil Pasic , Christian Borntraeger , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Eric Farman , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH 5/5] s390x/pv: Move check on hugepage under s390_pv_guest_check() Date: Wed, 4 Jan 2023 12:51:11 +0100 Message-Id: <20230104115111.3240594-6-clg@kaod.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230104115111.3240594-1-clg@kaod.org> References: <20230104115111.3240594-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=6L6x=5B=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1672833232470100003 From: C=C3=A9dric Le Goater Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Thomas Huth --- hw/s390x/pv.c | 14 +++++++++++++- target/s390x/diag.c | 7 ------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index 96c0728ec9..4e1f991d98 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -302,9 +302,21 @@ static bool s390_pv_check_host(Error **errp) return true; } =20 +static bool s390_pv_check_hpage(Error **errp) +{ + if (kvm_s390_get_hpage_1m()) { + error_setg(errp, "Protected VMs can currently not be backed with " + "huge pages"); + return false; + } + + return true; +} + static bool s390_pv_guest_check(const Object *obj, Error **errp) { - return s390_pv_check_cpus(errp) && s390_pv_check_host(errp); + return s390_pv_check_cpus(errp) && s390_pv_check_host(errp) && + s390_pv_check_hpage(errp); } =20 bool s390_pv_check(Error **errp) diff --git a/target/s390x/diag.c b/target/s390x/diag.c index 9b16e25930..28f4350aed 100644 --- a/target/s390x/diag.c +++ b/target/s390x/diag.c @@ -170,13 +170,6 @@ out: return; } =20 - if (kvm_enabled() && kvm_s390_get_hpage_1m()) { - error_report("Protected VMs can currently not be backed with " - "huge pages"); - env->regs[r1 + 1] =3D DIAG_308_RC_INVAL_FOR_PV; - return; - } - if (!s390_pv_check(&local_err)) { error_report_err(local_err); env->regs[r1 + 1] =3D DIAG_308_RC_INVAL_FOR_PV; --=20 2.38.1