From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582652; cv=none; d=zohomail.com; s=zohoarc; b=RqmWGUJzBGPNfQasNBRVD8KefQ0G5XerdCPSYH8IbdJ0rlL1bdNMNrN/hZl0BMjX0JCRKAXT2Cd4HajEuBLv2m4pMBFt72Xvc4S8fAxNxdHPJwV1aPfFVwVZ4bWzY+2+dNGBiut5NfXlX86mX8/gLfstJHrd6Pt8nRX0nV4nR+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582652; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GRbDh45YYLhKhbeoY1uMw6ZYOhP8a8klGK+ZuUo2u+s=; b=mvDMot3cQqONiGChL03d5XpZai0TD2QcgrDlHR78VGPzOBZwrAXuDfWm/Kh7ReLE2FtgpTb0R1+pEwOcMPF9mqDok5f244zbdkVQf8NBrJD0bd/hctHTg/AoL0CkAoHeVtm2paDeRXbM4p1cdVQgB8bzJVGREYqv19nkxfyR8dg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582652973690.7350138626779; Wed, 13 Jan 2021 16:04:12 -0800 (PST) Received: from localhost ([::1]:38054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq7X-0003qo-F3 for importer@patchew.org; Wed, 13 Jan 2021 19:04:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1x-0006sB-Qt; Wed, 13 Jan 2021 18:58:25 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:38365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1v-0006ZX-In; Wed, 13 Jan 2021 18:58:25 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ0Kttz9sVy; Thu, 14 Jan 2021 10:58:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=PMr7j5j8OSe0AP5kUuFMOJLePX4fph0iQtNNjr88kFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WOU/Nolj6jlStIr4NRM6WXyowwAzxfu41mUBsAt2hjacUVyKfMzCuBeg3nnoRXdhH hz2tPK9t7Dy95n4vvy1Ul/4WMa/beNDURAUo0XociRRNmbNIiWM7vgaXJPhjxnXS8J E1NNnb87UwZo6RN48TQLEmCj5ir03CdkKQRyk5r4= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 01/13] qom: Allow optional sugar props Date: Thu, 14 Jan 2021 10:57:59 +1100 Message-Id: <20210113235811.1909610-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cohuck@redhat.com, kvm@vger.kernel.org, David Hildenbrand , frankja@linux.ibm.com, pragyansri.pathi@intel.com, mst@redhat.com, mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, andi.kleen@intel.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , thuth@redhat.com, Eduardo Habkost , Richard Henderson , Greg Kurz , qemu-s390x@nongnu.org, jun.nakajima@intel.com, David Gibson , berrange@redhat.com, Marcelo Tosatti , qemu-ppc@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Greg Kurz Global properties have an @optional field, which allows to apply a given property to a given type even if one of its subclasses doesn't support it. This is especially used in the compat code when dealing with the "disable-modern" and "disable-legacy" properties and the "virtio-pci" type. Allow object_register_sugar_prop() to set this field as well. Signed-off-by: Greg Kurz Message-Id: <159738953558.377274.16617742952571083440.stgit@bahia.lan> Signed-off-by: David Gibson Reviewed-by: Eduardo Habkost Reviewed-by: Cornelia Huck Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qom/object.h | 3 ++- qom/object.c | 4 +++- softmmu/rtc.c | 3 ++- softmmu/vl.c | 17 +++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index d378f13a11..6721cd312e 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -638,7 +638,8 @@ bool object_apply_global_props(Object *obj, const GPtrA= rray *props, Error **errp); void object_set_machine_compat_props(GPtrArray *compat_props); void object_set_accelerator_compat_props(GPtrArray *compat_props); -void object_register_sugar_prop(const char *driver, const char *prop, cons= t char *value); +void object_register_sugar_prop(const char *driver, const char *prop, + const char *value, bool optional); void object_apply_compat_props(Object *obj); =20 /** diff --git a/qom/object.c b/qom/object.c index 2fa0119647..491823db4a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -442,7 +442,8 @@ static GPtrArray *object_compat_props[3]; * other than "-global". These are generally used for syntactic * sugar and legacy command line options. */ -void object_register_sugar_prop(const char *driver, const char *prop, cons= t char *value) +void object_register_sugar_prop(const char *driver, const char *prop, + const char *value, bool optional) { GlobalProperty *g; if (!object_compat_props[2]) { @@ -452,6 +453,7 @@ void object_register_sugar_prop(const char *driver, con= st char *prop, const char g->driver =3D g_strdup(driver); g->property =3D g_strdup(prop); g->value =3D g_strdup(value); + g->optional =3D optional; g_ptr_array_add(object_compat_props[2], g); } =20 diff --git a/softmmu/rtc.c b/softmmu/rtc.c index e1e15ef613..5632684fc9 100644 --- a/softmmu/rtc.c +++ b/softmmu/rtc.c @@ -179,7 +179,8 @@ void configure_rtc(QemuOpts *opts) if (!strcmp(value, "slew")) { object_register_sugar_prop("mc146818rtc", "lost_tick_policy", - "slew"); + "slew", + false); } else if (!strcmp(value, "none")) { /* discard is default */ } else { diff --git a/softmmu/vl.c b/softmmu/vl.c index 7ddf405d76..3f7721b83e 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1663,16 +1663,20 @@ static int machine_set_property(void *opaque, return 0; } if (g_str_equal(qom_name, "igd-passthru")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, valu= e); + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, valu= e, + false); return 0; } if (g_str_equal(qom_name, "kvm-shadow-mem")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e); + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + false); return 0; } if (g_str_equal(qom_name, "kernel-irqchip")) { - object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e); - object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, val= ue); + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, valu= e, + false); + object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, val= ue, + false); return 0; } =20 @@ -2297,9 +2301,10 @@ static void qemu_process_sugar_options(void) =20 val =3D g_strdup_printf("%d", (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("= smp-opts"), "cpus", 1)); - object_register_sugar_prop("memory-backend", "prealloc-threads", v= al); + object_register_sugar_prop("memory-backend", "prealloc-threads", v= al, + false); g_free(val); - object_register_sugar_prop("memory-backend", "prealloc", "on"); + object_register_sugar_prop("memory-backend", "prealloc", "on", fal= se); } =20 if (watchdog) { --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582417; cv=none; d=zohomail.com; s=zohoarc; b=bQ6zjJdukpxv0NSlIAtMzetenm1KUDmjUlVyt15DToxlTvvsXwWBoVULg7xT4ywLnTBBNmKIqP3etTZD0jxIgwksfAkrjIv2F6A6IJoMZ6HmQ6jEAtYsHx/DVXUfDJcaenP/B9DaEBIwW2/T0oU2vgtkiJdKiDOfl614mXCDuRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582417; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zCegGZ7HU86kliFrbAk/1ajIR0sLxcojOJrqnkydioo=; b=crcyzt+6Ax2zo9zVUrE1JlTkXQsRyKEthyTPb8CVGCIxGvqrDuHfAgKUxZpkd8O7x6n5cTVSNoqttzN4QVc4QZW+1OcukI/m+op/lejNbSZwE0Rex0SIn0P0TAFFfn22svAAPxKbTm7ymACUicSh5WWeng4IiPdig2RWdHN10Sk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582417377499.01299016042265; Wed, 13 Jan 2021 16:00:17 -0800 (PST) Received: from localhost ([::1]:57762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq3k-0000Ft-6N for importer@patchew.org; Wed, 13 Jan 2021 19:00:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1x-0006s2-LG; Wed, 13 Jan 2021 18:58:25 -0500 Received: from ozlabs.org ([203.11.71.1]:59793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1v-0006Za-2L; Wed, 13 Jan 2021 18:58:25 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ3Lt5z9sWS; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=mHVxcrGGzYrCfA9rYxmOKa3RCA68YZNhZxMoJegXBdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TsT92BTdo138QHl6Cg7+TQApgSL/NEvo6wqGTTgwn6YEuc83GqzBEXmPEIT7jWkSP aC2xhsT4+q5YDYfL3aecES7WC/DdqqDsJmJeYo+1IdePO+RIaPY/L/QxJXFKO2tAGm HnEbNdKjeTrsr7PZn/6HwzWPWde8vSVrMLJReynk= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 02/13] confidential guest support: Introduce new confidential guest support class Date: Thu, 14 Jan 2021 10:58:00 +1100 Message-Id: <20210113235811.1909610-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Several architectures have mechanisms which are designed to protect guest memory from interference or eavesdropping by a compromised hypervisor. AMD SEV does this with in-chip memory encryption and Intel's MKTME can do similar things. POWER's Protected Execution Framework (PEF) accomplishes a similar goal using an ultravisor and new memory protection features, instead of encryption. To (partially) unify handling for these, this introduces a new ConfidentialGuestSupport QOM base class. "Confidential" is kind of vague, but "confidential computing" seems to be the buzzword about these schemes, and "secure" or "protected" are often used in connection to unrelated things (such as hypervisor-from-guest or guest-from-guest security). The "support" in the name is significant because in at least some of the cases it requires the guest to take specific actions in order to protect itself from hypervisor eavesdropping. Signed-off-by: David Gibson --- backends/confidential-guest-support.c | 33 ++++++++++++++++++++ backends/meson.build | 1 + include/exec/confidential-guest-support.h | 38 +++++++++++++++++++++++ include/qemu/typedefs.h | 1 + target/i386/sev.c | 3 +- 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 backends/confidential-guest-support.c create mode 100644 include/exec/confidential-guest-support.h diff --git a/backends/confidential-guest-support.c b/backends/confidential-= guest-support.c new file mode 100644 index 0000000000..9b0ded0db4 --- /dev/null +++ b/backends/confidential-guest-support.c @@ -0,0 +1,33 @@ +/* + * QEMU Confidential Guest support + * + * Copyright: David Gibson, Red Hat Inc. 2020 + * + * Authors: + * David Gibson + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "exec/confidential-guest-support.h" + +OBJECT_DEFINE_ABSTRACT_TYPE(ConfidentialGuestSupport, + confidential_guest_support, + CONFIDENTIAL_GUEST_SUPPORT, + OBJECT) + +static void confidential_guest_support_class_init(ObjectClass *oc, void *d= ata) +{ +} + +static void confidential_guest_support_init(Object *obj) +{ +} + +static void confidential_guest_support_finalize(Object *obj) +{ +} diff --git a/backends/meson.build b/backends/meson.build index 484456ece7..d4221831fc 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -6,6 +6,7 @@ softmmu_ss.add([files( 'rng-builtin.c', 'rng-egd.c', 'rng.c', + 'confidential-guest-support.c', ), numa]) =20 softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files('rng-random.c')) diff --git a/include/exec/confidential-guest-support.h b/include/exec/confi= dential-guest-support.h new file mode 100644 index 0000000000..5f131023ba --- /dev/null +++ b/include/exec/confidential-guest-support.h @@ -0,0 +1,38 @@ +/* + * QEMU Confidential Guest support + * This interface describes the common pieces between various + * schemes for protecting guest memory or other state against a + * compromised hypervisor. This includes memory encryption (AMD's + * SEV and Intel's MKTME) or special protection modes (PEF on POWER, + * or PV on s390x). + * + * Copyright: David Gibson, Red Hat Inc. 2020 + * + * Authors: + * David Gibson + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + */ +#ifndef QEMU_CONFIDENTIAL_GUEST_SUPPORT_H +#define QEMU_CONFIDENTIAL_GUEST_SUPPORT_H + +#ifndef CONFIG_USER_ONLY + +#include "qom/object.h" + +#define TYPE_CONFIDENTIAL_GUEST_SUPPORT "confidential-guest-support" +OBJECT_DECLARE_SIMPLE_TYPE(ConfidentialGuestSupport, CONFIDENTIAL_GUEST_SU= PPORT) + +struct ConfidentialGuestSupport { + Object parent; +}; + +typedef struct ConfidentialGuestSupportClass { + ObjectClass parent; +} ConfidentialGuestSupportClass; + +#endif /* !CONFIG_USER_ONLY */ + +#endif /* QEMU_CONFIDENTIAL_GUEST_SUPPORT_H */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 976b529dfb..33685c79ed 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -36,6 +36,7 @@ typedef struct BusState BusState; typedef struct Chardev Chardev; typedef struct CompatProperty CompatProperty; typedef struct CoMutex CoMutex; +typedef struct ConfidentialGuestSupport ConfidentialGuestSupport; typedef struct CPUAddressSpace CPUAddressSpace; typedef struct CPUState CPUState; typedef struct DeviceListener DeviceListener; diff --git a/target/i386/sev.c b/target/i386/sev.c index 1546606811..6b49925f51 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -31,6 +31,7 @@ #include "qom/object.h" #include "exec/address-spaces.h" #include "monitor/monitor.h" +#include "exec/confidential-guest-support.h" =20 #define TYPE_SEV_GUEST "sev-guest" OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST) @@ -322,7 +323,7 @@ sev_guest_instance_init(Object *obj) =20 /* sev guest info */ static const TypeInfo sev_guest_info =3D { - .parent =3D TYPE_OBJECT, + .parent =3D TYPE_CONFIDENTIAL_GUEST_SUPPORT, .name =3D TYPE_SEV_GUEST, .instance_size =3D sizeof(SevGuestState), .instance_finalize =3D sev_guest_finalize, --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582421; cv=none; d=zohomail.com; s=zohoarc; b=lEGbA6Ih7BYLARzZIMlVYc8bouzocCzqwi1Re2D3tAeV7gDUajwuMihYvWmxU9NVb+SrQvnx2hA6uWi5qTxplkMFtfLv/4HxNeXOFjSESqhLu09rKPzTFxDb/QwBLfdLNOglRofDBUNAVj+e1YxNNtv7moMdSPvRCL6KdN9Y+1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582421; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wd+QWv20mZ7SyrCYQBfz+fWUdKqzOSdh2O4zIit2R3Y=; b=FvUGBOfmojVZjq0Xb7lKBHXRvdmyJ4Uszq3pUYxpzipn5WKIE59cWxuXQaVlrTgYeXM2WqPbWJRL9fJtHwT/w5o1dCWGZnNhazx3K+Fvv9vThdK4IiFmKPlB9uqajrjeo0a9aWGCufCNOpZ67E/v2PRyAOQkT5aY/auFVA2Eboc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582421223558.9127272730123; Wed, 13 Jan 2021 16:00:21 -0800 (PST) Received: from localhost ([::1]:57996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq3n-0000M3-VY for importer@patchew.org; Wed, 13 Jan 2021 19:00:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1z-0006ub-7D; Wed, 13 Jan 2021 18:58:27 -0500 Received: from ozlabs.org ([203.11.71.1]:55637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq1v-0006ZZ-Fi; Wed, 13 Jan 2021 18:58:26 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ2cc7z9sWK; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=thJIxYImNDEGyMXfz3IxBysZDEAVYAA8TpCNd/GoFv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LUZSZpzHhIh+aQUgZMNAMYDGFjl7hsS01f0a3uX7lhdjtvXrisZHo1rOogRdbuRiW BtbO570Xc5xpifpHqCzpxxOhK2p/O/7Gd+6APuxF3O0Ld+eC75Je+/+Ue+y4xSQg6Y ZgSuWtdbUYUrsLal9vikkfBewsMyn7xkHfIb0oao= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 03/13] sev: Remove false abstraction of flash encryption Date: Thu, 14 Jan 2021 10:58:01 +1100 Message-Id: <20210113235811.1909610-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When AMD's SEV memory encryption is in use, flash memory banks (which are initialed by pc_system_flash_map()) need to be encrypted with the guest's key, so that the guest can read them. That's abstracted via the kvm_memcrypt_encrypt_data() callback in the KVM state.. except, that it doesn't really abstract much at all. For starters, the only called is in code specific to the 'pc' family of machine types, so it's obviously specific to those and to x86 to begin with. But it makes a bunch of further assumptions that need not be true about an arbitrary confidential guest system based on memory encryption, let alone one based on other mechanisms: * it assumes that the flash memory is defined to be encrypted with the guest key, rather than being shared with hypervisor * it assumes that that hypervisor has some mechanism to encrypt data into the guest, even though it can't decrypt it out, since that's the whole point * the interface assumes that this encrypt can be done in place, which implies that the hypervisor can write into a confidential guests's memory, even if what it writes isn't meaningful So really, this "abstraction" is actually pretty specific to the way SEV works. So, this patch removes it and instead has the PC flash initialization code call into a SEV specific callback. Signed-off-by: David Gibson Reviewed-by: Cornelia Huck --- accel/kvm/kvm-all.c | 31 ++----------------------------- accel/kvm/sev-stub.c | 9 ++------- accel/stubs/kvm-stub.c | 10 ---------- hw/i386/pc_sysfw.c | 17 ++++++----------- include/sysemu/kvm.h | 16 ---------------- include/sysemu/sev.h | 4 ++-- target/i386/sev-stub.c | 5 +++++ target/i386/sev.c | 24 ++++++++++++++---------- 8 files changed, 31 insertions(+), 85 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 389eaace72..260ed73ffe 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -120,10 +120,6 @@ struct KVMState KVMMemoryListener memory_listener; QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus; =20 - /* memory encryption */ - void *memcrypt_handle; - int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len); - /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; struct KVMAs { @@ -222,26 +218,6 @@ int kvm_get_max_memslots(void) return s->nr_slots; } =20 -bool kvm_memcrypt_enabled(void) -{ - if (kvm_state && kvm_state->memcrypt_handle) { - return true; - } - - return false; -} - -int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) -{ - if (kvm_state->memcrypt_handle && - kvm_state->memcrypt_encrypt_data) { - return kvm_state->memcrypt_encrypt_data(kvm_state->memcrypt_handle, - ptr, len); - } - - return 1; -} - /* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { @@ -2206,13 +2182,10 @@ static int kvm_init(MachineState *ms) * encryption context. */ if (ms->memory_encryption) { - kvm_state->memcrypt_handle =3D sev_guest_init(ms->memory_encryptio= n); - if (!kvm_state->memcrypt_handle) { - ret =3D -1; + ret =3D sev_guest_init(ms->memory_encryption); + if (ret < 0) { goto err; } - - kvm_state->memcrypt_encrypt_data =3D sev_encrypt_data; } =20 ret =3D kvm_arch_init(ms, s); diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c index 4f97452585..5db9ab8f00 100644 --- a/accel/kvm/sev-stub.c +++ b/accel/kvm/sev-stub.c @@ -15,12 +15,7 @@ #include "qemu-common.h" #include "sysemu/sev.h" =20 -int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) +int sev_guest_init(const char *id) { - abort(); -} - -void *sev_guest_init(const char *id) -{ - return NULL; + return -1; } diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 680e099463..0f17acfac0 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -81,16 +81,6 @@ int kvm_on_sigbus(int code, void *addr) return 1; } =20 -bool kvm_memcrypt_enabled(void) -{ - return false; -} - -int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) -{ - return 1; -} - #ifndef CONFIG_USER_ONLY int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) { diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 92e90ff013..11172214f1 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -38,6 +38,7 @@ #include "sysemu/sysemu.h" #include "hw/block/flash.h" #include "sysemu/kvm.h" +#include "sysemu/sev.h" =20 #define FLASH_SECTOR_SIZE 4096 =20 @@ -147,7 +148,7 @@ static void pc_system_flash_map(PCMachineState *pcms, PFlashCFI01 *system_flash; MemoryRegion *flash_mem; void *flash_ptr; - int ret, flash_size; + int flash_size; =20 assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled); =20 @@ -191,16 +192,10 @@ static void pc_system_flash_map(PCMachineState *pcms, flash_mem =3D pflash_cfi01_get_memory(system_flash); pc_isa_bios_init(rom_memory, flash_mem, size); =20 - /* Encrypt the pflash boot ROM */ - if (kvm_memcrypt_enabled()) { - flash_ptr =3D memory_region_get_ram_ptr(flash_mem); - flash_size =3D memory_region_size(flash_mem); - ret =3D kvm_memcrypt_encrypt_data(flash_ptr, flash_size); - if (ret) { - error_report("failed to encrypt pflash rom"); - exit(1); - } - } + /* Encrypt the pflash boot ROM, if necessary */ + flash_ptr =3D memory_region_get_ram_ptr(flash_mem); + flash_size =3D memory_region_size(flash_mem); + sev_encrypt_flash(flash_ptr, flash_size, &error_fatal); } } } diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index bb5d5cf497..11cf0b875d 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -233,22 +233,6 @@ int kvm_has_intx_set_mask(void); */ bool kvm_arm_supports_user_irq(void); =20 -/** - * kvm_memcrypt_enabled - return boolean indicating whether memory encrypt= ion - * is enabled - * Returns: 1 memory encryption is enabled - * 0 memory encryption is disabled - */ -bool kvm_memcrypt_enabled(void); - -/** - * kvm_memcrypt_encrypt_data: encrypt the memory range - * - * Return: 1 failed to encrypt the range - * 0 succesfully encrypted memory region - */ -int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len); - =20 #ifdef NEED_CPU_H #include "cpu.h" diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 7ab6e3e31d..7335e59867 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,8 +16,8 @@ =20 #include "sysemu/kvm.h" =20 -void *sev_guest_init(const char *id); -int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len); +int sev_guest_init(const char *id); +int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp); int sev_inject_launch_secret(const char *hdr, const char *secret, uint64_t gpa, Error **errp); #endif diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c index c1fecc2101..1ac1fd5b94 100644 --- a/target/i386/sev-stub.c +++ b/target/i386/sev-stub.c @@ -54,3 +54,8 @@ int sev_inject_launch_secret(const char *hdr, const char = *secret, { return 1; } + +int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp) +{ + return 0; +} diff --git a/target/i386/sev.c b/target/i386/sev.c index 6b49925f51..2a4b2187d6 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -682,7 +682,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -void * +int sev_guest_init(const char *id) { SevGuestState *sev; @@ -695,7 +695,7 @@ sev_guest_init(const char *id) ret =3D ram_block_discard_disable(true); if (ret) { error_report("%s: cannot disable RAM discard", __func__); - return NULL; + return -1; } =20 sev =3D lookup_sev_guest_info(id); @@ -766,23 +766,27 @@ sev_guest_init(const char *id) qemu_add_machine_init_done_notifier(&sev_machine_done_notify); qemu_add_vm_change_state_handler(sev_vm_state_change, sev); =20 - return sev; + return 0; err: sev_guest =3D NULL; ram_block_discard_disable(false); - return NULL; + return -1; } =20 int -sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) +sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp) { - SevGuestState *sev =3D handle; - - assert(sev); + if (!sev_guest) { + return 0; + } =20 /* if SEV is in update state then encrypt the data else do nothing */ - if (sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { - return sev_launch_update_data(sev, ptr, len); + if (sev_check_state(sev_guest, SEV_STATE_LAUNCH_UPDATE)) { + int ret =3D sev_launch_update_data(sev_guest, ptr, len); + if (ret < 0) { + error_setg(errp, "failed to encrypt pflash rom"); + return ret; + } } =20 return 0; --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582714; cv=none; d=zohomail.com; s=zohoarc; b=YFADX+tfS+hiSqUduDElG4z3VEwj2Ka2f60eaad/uO7tPlaB2xJdXe1c+3v9dgjqYuBvwoOp5KBME3gHX64GWC4LRxeDJpg+IyLkz+bl/yO34CbXMmYWl8lA0LhKEiV2jOYyeWWF77PpHaM+rRr5BPNM76Rz7EKZSYz9OXvQCT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582714; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l9viuTCeD0AJLbbea69EbQZPMzDH6EtBN/y1n2KXhaI=; b=EGnyQZuzdQ7TnDwCOF6UeSbLcFDpMXKMnTA4jWd+n+3paZHQNJ9QA9pvUu0RutbJJV7eu24878XwIDMMlVbdIt2sq0Cbpq4ScMOXSJo1N7dCJA+y+89xGldHeA0kCdH//FGTpwFN/hZoOSjCRJg/y1Nd/I6RVXLHvEwztB1jV/M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582714364587.791413765293; Wed, 13 Jan 2021 16:05:14 -0800 (PST) Received: from localhost ([::1]:42552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq8X-0005ej-5D for importer@patchew.org; Wed, 13 Jan 2021 19:05:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq26-0007FH-Nv; Wed, 13 Jan 2021 18:58:34 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:35153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq23-0006eT-Sn; Wed, 13 Jan 2021 18:58:34 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ5D5fz9sWd; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=lmXvmEt0/qEDekwjJo+m9ott2kpnTrEBhRR6dc7AzfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyuLBFF+Gf344EZ7cUI8JJbiLd5ucniv8+ujDAn3fsU0H6dphtdEuQpQfvn+8ZuZA XDq3UJxuOLCCxVHnDNUac45PV4jI4dJgQ+yDO2kIirI7gqurwfpsBX1yLaKa9TOvfF 6OFEBhX/vjhqLISBbUN8BBoj127pgFwsdpnqjH2s= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 04/13] confidential guest support: Move side effect out of machine_set_memory_encryption() Date: Thu, 14 Jan 2021 10:58:02 +1100 Message-Id: <20210113235811.1909610-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When the "memory-encryption" property is set, we also disable KSM merging for the guest, since it won't accomplish anything. We want that, but doing it in the property set function itself is thereoretically incorrect, in the unlikely event of some configuration environment that set the property then cleared it again before constructing the guest. More importantly, it makes some other cleanups we want more difficult. So, instead move this logic to machine_run_board_init() conditional on the final value of the property. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Reviewed-by: Greg Kurz Reviewed-by: Cornelia Huck --- hw/core/machine.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index de3b8f1b31..8909117d80 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -437,14 +437,6 @@ static void machine_set_memory_encryption(Object *obj,= const char *value, =20 g_free(ms->memory_encryption); ms->memory_encryption =3D g_strdup(value); - - /* - * With memory encryption, the host can't see the real contents of RAM, - * so there's no point in it trying to merge areas. - */ - if (value) { - machine_set_mem_merge(obj, false, errp); - } } =20 static bool machine_get_nvdimm(Object *obj, Error **errp) @@ -1166,6 +1158,15 @@ void machine_run_board_init(MachineState *machine) cc->deprecation_note); } =20 + if (machine->memory_encryption) { + /* + * With memory encryption, the host can't see the real + * contents of RAM, so there's no point in it trying to merge + * areas. + */ + machine_set_mem_merge(OBJECT(machine), false, &error_abort); + } + machine_class->init(machine); phase_advance(PHASE_MACHINE_INITIALIZED); } --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582524; cv=none; d=zohomail.com; s=zohoarc; b=l9k/3prvlRQZRSyH6JRE7hGf3vChu/pVjkGUUVWHof9oTAx8WHXJjDP6nji4rqdZVxPiv9ToTBkCMk4C0zN8PL17SIml7A+jrpvSajsUfjC5RXGGmbUgPv4KUBsdfa974nkAGtlHUrtkAP65tL0kgl3n3FFhKf+/lHxIzB5cFu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582524; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7YrnKFGjo4BRH9gAhzcAhM/h8JTbcv+OMn4sgd6ImNQ=; b=CmiV81bm6bYZS7e9wBnM+xfEfJqhy6m+kP/mGc01gCh4LvxfL8xuBX1lmtLmhNQoeWduCYeHBAN+mv6Y+D+qyJVZwMozsCB0hz/kalX7+Jo8gyWXns/lXQinAFKShn5dTmKIfeTFbBCuJhmRw80VOdCLkVFxYyNSh9Z2HwmDp74= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582524833656.91105232181; Wed, 13 Jan 2021 16:02:04 -0800 (PST) Received: from localhost ([::1]:59902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq5T-00019K-Lk for importer@patchew.org; Wed, 13 Jan 2021 19:02:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq27-0007GY-69; Wed, 13 Jan 2021 18:58:35 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:46171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq24-0006eV-48; Wed, 13 Jan 2021 18:58:34 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ4TQBz9sWP; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=/3Q4sEeOR4X9dZi9ZTw3f3cnX096S2u0KkWUMX2X/VM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I4F2+9SCDPHP/lj6U2abnDcLOFwrhDDaPAp4o6MoPh3C59YMMjrz4C9y2L/c8NLh5 e0r/4kUKRT0hSN5v0X6laDc48kdrVzAHUbrzcPzB+x2AiPG09h+y/p8CvrXGiETISL VaEGB6D5YM8GL47ZBYFCGW9aB+2IuNL6F4XRmF9g= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 05/13] confidential guest support: Rework the "memory-encryption" property Date: Thu, 14 Jan 2021 10:58:03 +1100 Message-Id: <20210113235811.1909610-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently the "memory-encryption" property is only looked at once we get to kvm_init(). Although protection of guest memory from the hypervisor isn't something that could really ever work with TCG, it's not conceptually tied to the KVM accelerator. In addition, the way the string property is resolved to an object is almost identical to how a QOM link property is handled. So, create a new "confidential-guest-support" link property which sets this QOM interface link directly in the machine. For compatibility we keep the "memory-encryption" property, but now implemented in terms of the new property. Signed-off-by: David Gibson Reviewed-by: Greg Kurz Reviewed-by: Cornelia Huck --- accel/kvm/kvm-all.c | 5 +++-- accel/kvm/sev-stub.c | 5 +++-- hw/core/machine.c | 43 +++++++++++++++++++++++++++++++++++++------ include/hw/boards.h | 2 +- include/sysemu/sev.h | 2 +- target/i386/sev.c | 32 ++------------------------------ 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 260ed73ffe..28ab126f70 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2181,8 +2181,9 @@ static int kvm_init(MachineState *ms) * if memory encryption object is specified then initialize the memory * encryption context. */ - if (ms->memory_encryption) { - ret =3D sev_guest_init(ms->memory_encryption); + if (ms->cgs) { + /* FIXME handle mechanisms other than SEV */ + ret =3D sev_kvm_init(ms->cgs); if (ret < 0) { goto err; } diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c index 5db9ab8f00..3d4787ae4a 100644 --- a/accel/kvm/sev-stub.c +++ b/accel/kvm/sev-stub.c @@ -15,7 +15,8 @@ #include "qemu-common.h" #include "sysemu/sev.h" =20 -int sev_guest_init(const char *id) +int sev_kvm_init(ConfidentialGuestSupport *cgs) { - return -1; + /* SEV can't be selected if it's not compiled */ + g_assert_not_reached(); } diff --git a/hw/core/machine.c b/hw/core/machine.c index 8909117d80..94194ab82d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -32,6 +32,7 @@ #include "hw/mem/nvdimm.h" #include "migration/global_state.h" #include "migration/vmstate.h" +#include "exec/confidential-guest-support.h" =20 GlobalProperty hw_compat_5_2[] =3D {}; const size_t hw_compat_5_2_len =3D G_N_ELEMENTS(hw_compat_5_2); @@ -427,16 +428,37 @@ static char *machine_get_memory_encryption(Object *ob= j, Error **errp) { MachineState *ms =3D MACHINE(obj); =20 - return g_strdup(ms->memory_encryption); + if (ms->cgs) { + return g_strdup(object_get_canonical_path_component(OBJECT(ms->cgs= ))); + } + + return NULL; } =20 static void machine_set_memory_encryption(Object *obj, const char *value, Error **errp) { - MachineState *ms =3D MACHINE(obj); + Object *cgs =3D + object_resolve_path_component(object_get_objects_root(), value); + + if (!cgs) { + error_setg(errp, "No such memory encryption object '%s'", value); + return; + } =20 - g_free(ms->memory_encryption); - ms->memory_encryption =3D g_strdup(value); + object_property_set_link(obj, "confidential-guest-support", cgs, errp); +} + +static void machine_check_confidential_guest_support(const Object *obj, + const char *name, + 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 + */ } =20 static bool machine_get_nvdimm(Object *obj, Error **errp) @@ -836,6 +858,15 @@ static void machine_class_init(ObjectClass *oc, void *= data) object_class_property_set_description(oc, "suppress-vmdesc", "Set on to disable self-describing migration"); =20 + object_class_property_add_link(oc, "confidential-guest-support", + TYPE_CONFIDENTIAL_GUEST_SUPPORT, + offsetof(MachineState, cgs), + machine_check_confidential_guest_suppor= t, + OBJ_PROP_LINK_STRONG); + object_class_property_set_description(oc, "confidential-guest-support", + "Set confidential guest scheme t= o support"); + + /* For compatibility */ object_class_property_add_str(oc, "memory-encryption", machine_get_memory_encryption, machine_set_memory_encryption); object_class_property_set_description(oc, "memory-encryption", @@ -1158,9 +1189,9 @@ void machine_run_board_init(MachineState *machine) cc->deprecation_note); } =20 - if (machine->memory_encryption) { + if (machine->cgs) { /* - * With memory encryption, the host can't see the real + * With confidential guests, the host can't see the real * contents of RAM, so there's no point in it trying to merge * areas. */ diff --git a/include/hw/boards.h b/include/hw/boards.h index 17b1f3f0b9..1acd662fa5 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -270,7 +270,7 @@ struct MachineState { bool iommu; bool suppress_vmdesc; bool enable_graphics; - char *memory_encryption; + ConfidentialGuestSupport *cgs; char *ram_memdev_id; /* * convenience alias to ram_memdev_id backend memory region diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 7335e59867..3b5b1aacf1 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,7 +16,7 @@ =20 #include "sysemu/kvm.h" =20 -int sev_guest_init(const char *id); +int sev_kvm_init(ConfidentialGuestSupport *cgs); int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp); int sev_inject_launch_secret(const char *hdr, const char *secret, uint64_t gpa, Error **errp); diff --git a/target/i386/sev.c b/target/i386/sev.c index 2a4b2187d6..5399a136ad 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -335,26 +335,6 @@ static const TypeInfo sev_guest_info =3D { } }; =20 -static SevGuestState * -lookup_sev_guest_info(const char *id) -{ - Object *obj; - SevGuestState *info; - - obj =3D object_resolve_path_component(object_get_objects_root(), id); - if (!obj) { - return NULL; - } - - info =3D (SevGuestState *) - object_dynamic_cast(obj, TYPE_SEV_GUEST); - if (!info) { - return NULL; - } - - return info; -} - bool sev_enabled(void) { @@ -682,10 +662,9 @@ sev_vm_state_change(void *opaque, int running, RunStat= e state) } } =20 -int -sev_guest_init(const char *id) +int sev_kvm_init(ConfidentialGuestSupport *cgs) { - SevGuestState *sev; + SevGuestState *sev =3D SEV_GUEST(cgs); char *devname; int ret, fw_error; uint32_t ebx; @@ -698,13 +677,6 @@ sev_guest_init(const char *id) return -1; } =20 - sev =3D lookup_sev_guest_info(id); - if (!sev) { - error_report("%s: '%s' is not a valid '%s' object", - __func__, id, TYPE_SEV_GUEST); - goto err; - } - sev_guest =3D sev; sev->state =3D SEV_STATE_UNINIT; =20 --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582680; cv=none; d=zohomail.com; s=zohoarc; b=N2DWsymftLig6Sn/LzM2EGUcg3JsHCWCi0T6cywv8vUoA/Fnk7Av47dGy4s7Y3yFYnN3ML+zlQy+ofWelNYlrp6sX7ZCGbNGY6dYOQUo+K8vXgUzd+QjwVJyKnZr8zxDX1HO4ZGizXRJcuCArzuDfJvtIwftkCxRzTwwjQPK/8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582680; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KSiqV3TqiIwucR3mzn07gmxLDc167B4vMFvYLPxGOU4=; b=UZChdsyrBtIfoSEEhR1LVD00HZqgdpfuEEDNugCpf/n9qsF0O2H+Vu/b8dSDfOgPOs6JgxlJkd+jTH+EwGdOUw96AerVTcQjqRgXFsdpuz5F7smhDIOvse5TadcqSTSD6EcxfOJhE7n7zZj5/Me8vMTKaPYLri1HL1NCkXZQX0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582680916838.0024653358071; Wed, 13 Jan 2021 16:04:40 -0800 (PST) Received: from localhost ([::1]:39332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq7z-0004Lt-R8 for importer@patchew.org; Wed, 13 Jan 2021 19:04:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq27-0007GS-54; Wed, 13 Jan 2021 18:58:35 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:57655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq24-0006ep-Ba; Wed, 13 Jan 2021 18:58:34 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ66Hrz9sWX; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=Dv66XL0Xu5XiFw4ZQdSY1TGdKn45Up+V2jY+iQE5wYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JdKn1pyUgh8JG5peE6mRyJ64v8KTjhz72BvdOgs5QU/LfMlPjPuWaw8GqxGDlCXqq 3SWntlvSbE+ZZfh0iqWAKIyw0C0KCBeYMTMAuY5p2+wLto1rqq5NSs4Nt/JYMwaXuf k0ewiEFCG4zhlVaFaS/0U7y7gmboRPSLhFpjQyJs= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 06/13] sev: Add Error ** to sev_kvm_init() Date: Thu, 14 Jan 2021 10:58:04 +1100 Message-Id: <20210113235811.1909610-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cohuck@redhat.com, kvm@vger.kernel.org, David Hildenbrand , frankja@linux.ibm.com, pragyansri.pathi@intel.com, mst@redhat.com, mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, andi.kleen@intel.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , thuth@redhat.com, Eduardo Habkost , Richard Henderson , Greg Kurz , qemu-s390x@nongnu.org, jun.nakajima@intel.com, David Gibson , berrange@redhat.com, Marcelo Tosatti , qemu-ppc@nongnu.org, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This allows failures to be reported richly and idiomatically. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Cornelia Huck --- accel/kvm/kvm-all.c | 4 +++- accel/kvm/sev-stub.c | 2 +- include/sysemu/sev.h | 2 +- target/i386/sev.c | 31 +++++++++++++++---------------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 28ab126f70..c5b0750fd0 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2182,9 +2182,11 @@ static int kvm_init(MachineState *ms) * encryption context. */ if (ms->cgs) { + Error *local_err =3D NULL; /* FIXME handle mechanisms other than SEV */ - ret =3D sev_kvm_init(ms->cgs); + ret =3D sev_kvm_init(ms->cgs, &local_err); if (ret < 0) { + error_report_err(local_err); goto err; } } diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c index 3d4787ae4a..512e205f7f 100644 --- a/accel/kvm/sev-stub.c +++ b/accel/kvm/sev-stub.c @@ -15,7 +15,7 @@ #include "qemu-common.h" #include "sysemu/sev.h" =20 -int sev_kvm_init(ConfidentialGuestSupport *cgs) +int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { /* SEV can't be selected if it's not compiled */ g_assert_not_reached(); diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 3b5b1aacf1..5c5a13c6ca 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,7 +16,7 @@ =20 #include "sysemu/kvm.h" =20 -int sev_kvm_init(ConfidentialGuestSupport *cgs); +int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp); int sev_inject_launch_secret(const char *hdr, const char *secret, uint64_t gpa, Error **errp); diff --git a/target/i386/sev.c b/target/i386/sev.c index 5399a136ad..e2b41ef342 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -662,7 +662,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -int sev_kvm_init(ConfidentialGuestSupport *cgs) +int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { SevGuestState *sev =3D SEV_GUEST(cgs); char *devname; @@ -684,14 +684,14 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs) host_cbitpos =3D ebx & 0x3f; =20 if (host_cbitpos !=3D sev->cbitpos) { - error_report("%s: cbitpos check failed, host '%d' requested '%d'", - __func__, host_cbitpos, sev->cbitpos); + error_setg(errp, "%s: cbitpos check failed, host '%d' requested '%= d'", + __func__, host_cbitpos, sev->cbitpos); goto err; } =20 if (sev->reduced_phys_bits < 1) { - error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," - " requested '%d'", __func__, sev->reduced_phys_bits); + error_setg(errp, "%s: reduced_phys_bits check failed, it should be= >=3D1," + " requested '%d'", __func__, sev->reduced_phys_bits); goto err; } =20 @@ -700,20 +700,19 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs) devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); sev->sev_fd =3D open(devname, O_RDWR); if (sev->sev_fd < 0) { - error_report("%s: Failed to open %s '%s'", __func__, - devname, strerror(errno)); - } - g_free(devname); - if (sev->sev_fd < 0) { + error_setg(errp, "%s: Failed to open %s '%s'", __func__, + devname, strerror(errno)); + g_free(devname); goto err; } + g_free(devname); =20 ret =3D sev_platform_ioctl(sev->sev_fd, SEV_PLATFORM_STATUS, &status, &fw_error); if (ret) { - error_report("%s: failed to get platform status ret=3D%d " - "fw_error=3D'%d: %s'", __func__, ret, fw_error, - fw_error_to_str(fw_error)); + error_setg(errp, "%s: failed to get platform status ret=3D%d " + "fw_error=3D'%d: %s'", __func__, ret, fw_error, + fw_error_to_str(fw_error)); goto err; } sev->build_id =3D status.build; @@ -723,14 +722,14 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs) trace_kvm_sev_init(); ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error); if (ret) { - error_report("%s: failed to initialize ret=3D%d fw_error=3D%d '%s'= ", - __func__, ret, fw_error, fw_error_to_str(fw_error)); + error_setg(errp, "%s: failed to initialize ret=3D%d fw_error=3D%d = '%s'", + __func__, ret, fw_error, fw_error_to_str(fw_error)); goto err; } =20 ret =3D sev_launch_start(sev); if (ret) { - error_report("%s: failed to create encryption context", __func__); + error_setg(errp, "%s: failed to create encryption context", __func= __); goto err; } =20 --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582998; cv=none; d=zohomail.com; s=zohoarc; b=T0FzBpeM2y6C/73mq8PvPxuNOZxuJRuPzRUz7J9YofWuX5l0Y61kSqszx/o4+JPNqYiENn1imzwBXpPhJ9U/JqX5yU7sDVyCo5HVUSvVBdDKm82Gt1oqyQGNHdv72r3ng6iHkHP+H/IyAnv96JB85iaulICMCCbxNQfY8ZCbk6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582998; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C+I8e2Qn7MqVZDP9MlIFEfMZbghKHo6iB16iRIy6DoE=; b=dooHEm+p1oi/hXh67R+wxKdy6QeI/e/YjPW+hYn7a8yXmsghDBzyboZqBrx4Ev4/gxyRMdEdTpYuPtP8HbUUKjI3xMtl41NK50Ho0r7uV498jpQXBypJnuxkdw6SW/KF4WImli8U+VDKUmMbweQ8GujHUo31GB5NUGDaaK82UoA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582998249655.0060671781794; Wed, 13 Jan 2021 16:09:58 -0800 (PST) Received: from localhost ([::1]:56794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqD6-0003B3-R2 for importer@patchew.org; Wed, 13 Jan 2021 19:09:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq25-0007CO-IY; Wed, 13 Jan 2021 18:58:33 -0500 Received: from ozlabs.org ([203.11.71.1]:58647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq23-0006en-Lz; Wed, 13 Jan 2021 18:58:33 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXQ6v7Cz9sWk; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582294; bh=idJr0chYvjooRoA3aqKnU601BZd17+94MhdcU47V62A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZL+y3MKlNgB5V+HRIddau2xZRc6ivsKrn3t/xFPR8WxiViIiH2Xk6XkGU+p50nzp3 9PiQflWHy4l7o9AMlYI6cuxI6Ra0IMEMQUAlves2Zjz6icBTX85QlI1njCPu4/yEZ+ 0oS6eZN8sQ8K+HEg3dVIKHxSHipa8jKx9IAI+y9E= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 07/13] confidential guest support: Introduce cgs "ready" flag Date: Thu, 14 Jan 2021 10:58:05 +1100 Message-Id: <20210113235811.1909610-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The platform specific details of mechanisms for implementing confidential guest support may require setup at various points during initialization. Thus, it's not really feasible to have a single cgs initialization hook, but instead each mechanism needs its own initialization calls in arch or machine specific code. However, to make it harder to have a bug where a mechanism isn't properly initialized under some circumstances, we want to have a common place, relatively late in boot, where we verify that cgs has been initialized if it was requested. This patch introduces a ready flag to the ConfidentialGuestSupport base type to accomplish this, which we verify just before the machine specific initialization function. Signed-off-by: David Gibson Reviewed-by: Cornelia Huck Reviewed-by: Greg Kurz --- hw/core/machine.c | 8 ++++++++ include/exec/confidential-guest-support.h | 2 ++ target/i386/sev.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 94194ab82d..5a7433332b 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1190,6 +1190,14 @@ void machine_run_board_init(MachineState *machine) } =20 if (machine->cgs) { + /* + * Where confidential guest support is initialized depends on + * the specific mechanism in use. But, we need to make sure + * it's ready by now. If it isn't, that's a bug in the + * implementation of that cgs mechanism. + */ + assert(machine->cgs->ready); + /* * With confidential guests, the host can't see the real * contents of RAM, so there's no point in it trying to merge diff --git a/include/exec/confidential-guest-support.h b/include/exec/confi= dential-guest-support.h index 5f131023ba..bcaf6c9f49 100644 --- a/include/exec/confidential-guest-support.h +++ b/include/exec/confidential-guest-support.h @@ -27,6 +27,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(ConfidentialGuestSupport, CONF= IDENTIAL_GUEST_SUPPORT) =20 struct ConfidentialGuestSupport { Object parent; + + bool ready; }; =20 typedef struct ConfidentialGuestSupportClass { diff --git a/target/i386/sev.c b/target/i386/sev.c index e2b41ef342..3d94635397 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -737,6 +737,8 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error *= *errp) qemu_add_machine_init_done_notifier(&sev_machine_done_notify); qemu_add_vm_change_state_handler(sev_vm_state_change, sev); =20 + cgs->ready =3D true; + return 0; err: sev_guest =3D NULL; --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610583294; cv=none; d=zohomail.com; s=zohoarc; b=H89nEwO620y8SS2Vc5DvQOL1TiMocfEefIfxYjGV53P3YDgDeGLV0fRhJTBR0cTAGa6JJS2c24VBoUSjQadiz1ywFiQBjMwzjg50C223j5wo0eIF/aD9mFa/M+JiN6PQ7a7kUZLqF/xEwab5Kq0Sq/8WbxiZ+bYh7dKEYahwUqY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610583294; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VKBPXikfjJRgF9dYwV1YBrdcgV453MzvP71jv5oc6Eo=; b=RR3ko41ya6BZluqR+zfJ5mUK3nnegS3hTb6GXcEprKek75qCcYhvvt5fnnEFRB+MxBVTwAoLrKQluk4+bju+trmQY9KOBSTXCtGCeV2DD29Yvb+oNYV0hW/hzrX8+Yv9+fETLWlojb84gEbGlOKfihqWVGx6g5MK21sLH2BF+ug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610583294792778.5850360448641; Wed, 13 Jan 2021 16:14:54 -0800 (PST) Received: from localhost ([::1]:40010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqHt-00088H-Fp for importer@patchew.org; Wed, 13 Jan 2021 19:14:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq28-0007Kd-M5; Wed, 13 Jan 2021 18:58:36 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:34313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq25-0006fG-Tv; Wed, 13 Jan 2021 18:58:36 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR1Tr1z9sXb; Thu, 14 Jan 2021 10:58:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=DVHvwIFYF5zIwyyGLWDcCato2JVKksJgBlh9j+VQqL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jTlVEvch3zry53tRmBDlCkK4cf+QcvmCRDcfLu/b5oIXVVQY5077CPMkSyEjN3U8s g5PBBzdxOqRo3z+l7T9m+S4pqmIV3le8DKxYkdbteZXEytSD9p7MbM1Evo3zsytRN8 jrfQK8ZJtUmeLoUSk8ZvXAY/Jr6RG6t2NX0tH6lg= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 08/13] confidential guest support: Move SEV initialization into arch specific code Date: Thu, 14 Jan 2021 10:58:06 +1100 Message-Id: <20210113235811.1909610-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" While we've abstracted some (potential) differences between mechanisms for securing guest memory, the initialization is still specific to SEV. Given that, move it into x86's kvm_arch_init() code, rather than the generic kvm_init() code. Signed-off-by: David Gibson Reviewed-by: Cornelia Huck --- accel/kvm/kvm-all.c | 14 -------------- accel/kvm/sev-stub.c | 4 ++-- target/i386/kvm/kvm.c | 12 ++++++++++++ target/i386/sev.c | 7 ++++++- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c5b0750fd0..adf27c1864 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2177,20 +2177,6 @@ static int kvm_init(MachineState *ms) =20 kvm_state =3D s; =20 - /* - * if memory encryption object is specified then initialize the memory - * encryption context. - */ - if (ms->cgs) { - Error *local_err =3D NULL; - /* FIXME handle mechanisms other than SEV */ - ret =3D sev_kvm_init(ms->cgs, &local_err); - if (ret < 0) { - error_report_err(local_err); - goto err; - } - } - ret =3D kvm_arch_init(ms, s); if (ret < 0) { goto err; diff --git a/accel/kvm/sev-stub.c b/accel/kvm/sev-stub.c index 512e205f7f..9587d1b2a3 100644 --- a/accel/kvm/sev-stub.c +++ b/accel/kvm/sev-stub.c @@ -17,6 +17,6 @@ =20 int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { - /* SEV can't be selected if it's not compiled */ - g_assert_not_reached(); + /* If we get here, cgs must be some non-SEV thing */ + return 0; } diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 6dc1ee052d..e8b9dc48a2 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -42,6 +42,7 @@ #include "hw/i386/intel_iommu.h" #include "hw/i386/x86-iommu.h" #include "hw/i386/e820_memory_layout.h" +#include "sysemu/sev.h" =20 #include "hw/pci/pci.h" #include "hw/pci/msi.h" @@ -2135,6 +2136,17 @@ int kvm_arch_init(MachineState *ms, KVMState *s) uint64_t shadow_mem; int ret; struct utsname utsname; + Error *local_err =3D NULL; + + /* + * if memory encryption object is specified then initialize the + * memory encryption context (no-op otherwise) + */ + ret =3D sev_kvm_init(ms->cgs, &local_err); + if (ret < 0) { + error_report_err(local_err); + return ret; + } =20 if (!kvm_check_extension(s, KVM_CAP_IRQ_ROUTING)) { error_report("kvm: KVM_CAP_IRQ_ROUTING not supported by KVM"); diff --git a/target/i386/sev.c b/target/i386/sev.c index 3d94635397..aa79cacabe 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -664,13 +664,18 @@ sev_vm_state_change(void *opaque, int running, RunSta= te state) =20 int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) { - SevGuestState *sev =3D SEV_GUEST(cgs); + SevGuestState *sev + =3D (SevGuestState *)object_dynamic_cast(OBJECT(cgs), TYPE_SEV_GUE= ST); char *devname; int ret, fw_error; uint32_t ebx; uint32_t host_cbitpos; struct sev_user_data_status status =3D {}; =20 + if (!sev) { + return 0; + } + ret =3D ram_block_discard_disable(true); if (ret) { error_report("%s: cannot disable RAM discard", __func__); --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582698; cv=none; d=zohomail.com; s=zohoarc; b=NhXIQR9loqU9mP2B/8MEOprjNXveMz/7k9xpb9lsEMC7CdeyuucO661PfVxsAU8J4MsGltHcrm+X1poMuKP0USueDQodzw6zmnsKilReDZgEQ6jCxqo5AfsHcABykZQralCxS/AM0GgA3WmAZTJZULdzrgg+gCoBWmEkLSK9wRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582698; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mb69v1PZ9dWjdM9+DrYmfZqLz/fYTIyH1SaCTINwAbU=; b=FC6SjN5PbuzxY7RFRcpifk2v1IuNNywPw6OWd51rcQhgDOc0tJdqI4NvNt1XgDU58D7LVo/D6AI60V7BhU/9oxRVFLTVbTnl5xMPA1DLPDnnr7T/zydlbKvH4RZC5v5+XuPzzx9Cli3a1HzwO1G3H2yZEKZq3xh4BlpgLZzv5P0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 16105826987621003.7803863563687; Wed, 13 Jan 2021 16:04:58 -0800 (PST) Received: from localhost ([::1]:41114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzq8H-00055T-L2 for importer@patchew.org; Wed, 13 Jan 2021 19:04:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq28-0007J8-2m; Wed, 13 Jan 2021 18:58:36 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:42003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq25-0006fH-Ts; Wed, 13 Jan 2021 18:58:35 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR0hDnz9sX1; Thu, 14 Jan 2021 10:58:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=XAe7Xx+YpNUPHcyhxW/cHKgMuEbgQoNbc1c/1ol/ah8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHrQo0CpGmuAyajbdwUMx7qgn9Kr7iTclU8Uk3Goi3mgJfMWU9Nzex3+mn0SUfPIy xecXjdlhCJ1+mTEjl5fbqWu0n2T0lKHXdsVYiVX+tGC9y732Yulz2rRkTGA0sx0BfA V3fI8nw9ocNIb/PNhEsP0m0vgGwV8LbBBaXzbDoM= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 09/13] confidential guest support: Update documentation Date: Thu, 14 Jan 2021 10:58:07 +1100 Message-Id: <20210113235811.1909610-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that we've implemented a generic machine option for configuring various confidential guest support mechanisms: 1. Update docs/amd-memory-encryption.txt to reference this rather than the earlier SEV specific option 2. Add a docs/confidential-guest-support.txt to cover the generalities of the confidential guest support scheme Signed-off-by: David Gibson Reviewed-by: Greg Kurz --- docs/amd-memory-encryption.txt | 2 +- docs/confidential-guest-support.txt | 43 +++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 docs/confidential-guest-support.txt diff --git a/docs/amd-memory-encryption.txt b/docs/amd-memory-encryption.txt index 80b8eb00e9..145896aec7 100644 --- a/docs/amd-memory-encryption.txt +++ b/docs/amd-memory-encryption.txt @@ -73,7 +73,7 @@ complete flow chart. To launch a SEV guest =20 # ${QEMU} \ - -machine ...,memory-encryption=3Dsev0 \ + -machine ...,confidential-guest-support=3Dsev0 \ -object sev-guest,id=3Dsev0,cbitpos=3D47,reduced-phys-bits=3D1 =20 Debugging diff --git a/docs/confidential-guest-support.txt b/docs/confidential-guest-= support.txt new file mode 100644 index 0000000000..2790425b38 --- /dev/null +++ b/docs/confidential-guest-support.txt @@ -0,0 +1,43 @@ +Confidential Guest Support +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +Traditionally, hypervisors such as qemu have complete access to a +guest's memory and other state, meaning that a compromised hypervisor +can compromise any of its guests. A number of platforms have added +mechanisms in hardware and/or firmware which give guests at least some +protection from a compromised hypervisor. This is obviously +especially desirable for public cloud environments. + +These mechanisms have different names and different modes of +operation, but are often referred to as Secure Guests or Confidential +Guests. We use the term "Confidential Guest Support" to distinguish +this from other aspects of guest security (such as security against +attacks from other guests, or from network sources). + +Running a Confidential Guest +---------------------------- + +To run a confidential guest you need to add two command line parameters: + +1. Use "-object" to create a "confidential guest support" object. The + type and parameters will vary with the specific mechanism to be + used +2. Set the "confidential-guest-support" machine parameter to the ID of + the object from (1). + +Example (for AMD SEV):: + + qemu-system-x86_64 \ + \ + -machine ...,confidential-guest-support=3Dsev0 \ + -object sev-guest,id=3Dsev0,cbitpos=3D47,reduced-phys-bits=3D1 + +Supported mechanisms +-------------------- + +Currently supported confidential guest mechanisms are: + +AMD Secure Encrypted Virtualization (SEV) + docs/amd-memory-encryption.txt + +Other mechanisms may be supported in future. --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582869; cv=none; d=zohomail.com; s=zohoarc; b=F8KPLZuoKMRJsCNwu6HJnu4bjYWMiTfoMqKBp6/2Vo537QhEQ51aHQPsKfT9KI1qJagCPXZI65TPLS2DGIeM0yAG7w5Fqw4VmZK5vft/dx+aHuyBLw5hTxsgl3ZeRAxQy6WQPnuWH+w0yew6tDrn3wb4VPtt8bmnESfQ0nEQoOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582869; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XslGXxdWQ+Flt4A+9iOCF3ka4BX9qhwBxZWA2SSQeQU=; b=BWsyXm21gp1yVgMlFF0D0Pa9xEYChmN/w2gQ3Id2MzMtSmFQvzT3ZwZI+7EQSDJAjBHkiZkxgKvCM00LZQPjm+KqcVE5wuPI2N0mKFckDIrwVJ1iHC/g0Y3OVGbQsUpqB71Lm7qmC/AwXwoYXhz5rCutgHJDa8hobj55GqVarMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582869943257.37745466704564; Wed, 13 Jan 2021 16:07:49 -0800 (PST) Received: from localhost ([::1]:49804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqB2-0000Fi-Rr for importer@patchew.org; Wed, 13 Jan 2021 19:07:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq28-0007JQ-6B; Wed, 13 Jan 2021 18:58:36 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:52495) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq25-0006fL-T8; Wed, 13 Jan 2021 18:58:35 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR2NGfz9sXH; Thu, 14 Jan 2021 10:58:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=RYQUxxrIJnb6U4ZslRMJnpr5hI4pN7/28Mmn1jMp/TQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZYtAx3Tsn2Zv63D3+yKoYKjXkQFC96WF3p1PfEJgfcsY9rATNj4Yf3bo3UbhkIw8 Vgtgj8pzC/JjAcoJkedkDlX25UlFtWLQiIDiTZ1MZ9X6Q1Ac7v5o1TZyGdo9UP6X4P JSms9Sb4i68oSTj4UuC/pLFi0k/wH/D3t49HhAhg= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 10/13] spapr: Add PEF based confidential guest support Date: Thu, 14 Jan 2021 10:58:08 +1100 Message-Id: <20210113235811.1909610-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Some upcoming POWER machines have a system called PEF (Protected Execution Facility) which uses a small ultravisor to allow guests to run in a way that they can't be eavesdropped by the hypervisor. The effect is roughly similar to AMD SEV, although the mechanisms are quite different. Most of the work of this is done between the guest, KVM and the ultravisor, with little need for involvement by qemu. However qemu does need to tell KVM to allow secure VMs. Because the availability of secure mode is a guest visible difference which depends on having the right hardware and firmware, we don't enable this by default. In order to run a secure guest you need to create a "pef-guest" object and set the confidential-guest-support property to point to it. Note that this just *allows* secure guests, the architecture of PEF is such that the guest still needs to talk to the ultravisor to enter secure mode. Qemu has no directl way of knowing if the guest is in secure mode, and certainly can't know until well after machine creation time. To start a PEF-capable guest, use the command line options: -object pef-guest,id=3Dpef0 -machine confidential-guest-support=3Dpef0 Signed-off-by: David Gibson --- docs/confidential-guest-support.txt | 3 + docs/papr-pef.txt | 30 +++++++ hw/ppc/meson.build | 1 + hw/ppc/pef.c | 119 ++++++++++++++++++++++++++++ hw/ppc/spapr.c | 6 ++ include/hw/ppc/pef.h | 25 ++++++ target/ppc/kvm.c | 18 ----- target/ppc/kvm_ppc.h | 6 -- 8 files changed, 184 insertions(+), 24 deletions(-) create mode 100644 docs/papr-pef.txt create mode 100644 hw/ppc/pef.c create mode 100644 include/hw/ppc/pef.h diff --git a/docs/confidential-guest-support.txt b/docs/confidential-guest-= support.txt index 2790425b38..f0801814ff 100644 --- a/docs/confidential-guest-support.txt +++ b/docs/confidential-guest-support.txt @@ -40,4 +40,7 @@ Currently supported confidential guest mechanisms are: AMD Secure Encrypted Virtualization (SEV) docs/amd-memory-encryption.txt =20 +POWER Protected Execution Facility (PEF) + docs/papr-pef.txt + Other mechanisms may be supported in future. diff --git a/docs/papr-pef.txt b/docs/papr-pef.txt new file mode 100644 index 0000000000..6419e995cf --- /dev/null +++ b/docs/papr-pef.txt @@ -0,0 +1,30 @@ +POWER (PAPR) Protected Execution Facility (PEF) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Protected Execution Facility (PEF), also known as Secure Guest support +is a feature found on IBM POWER9 and POWER10 processors. + +If a suitable firmware including an Ultravisor is installed, it adds +an extra memory protection mode to the CPU. The ultravisor manages a +pool of secure memory which cannot be accessed by the hypervisor. + +When this feature is enabled in qemu, a guest can use ultracalls to +enter "secure mode". This transfers most of its memory to secure +memory, where it cannot be eavesdropped by a compromised hypervisor. + +Launching +--------- + +To launch a guest which will be permitted to enter PEF secure mode: + +# ${QEMU} \ + -object pef-guest,id=3Dpef0 \ + -machine confidential-guest-support=3Dpef0 \ + ... + +Live Migration +---------------- + +Live migration is not yet implemented for PEF guests. For +consistency, we currently prevent migration if the PEF feature is +enabled, whether or not the guest has actually entered secure mode. diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build index ffa2ec37fa..218631c883 100644 --- a/hw/ppc/meson.build +++ b/hw/ppc/meson.build @@ -27,6 +27,7 @@ ppc_ss.add(when: 'CONFIG_PSERIES', if_true: files( 'spapr_nvdimm.c', 'spapr_rtas_ddw.c', 'spapr_numa.c', + 'pef.c', )) ppc_ss.add(when: 'CONFIG_SPAPR_RNG', if_true: files('spapr_rng.c')) ppc_ss.add(when: ['CONFIG_PSERIES', 'CONFIG_LINUX'], if_true: files( diff --git a/hw/ppc/pef.c b/hw/ppc/pef.c new file mode 100644 index 0000000000..02b9b3b460 --- /dev/null +++ b/hw/ppc/pef.c @@ -0,0 +1,119 @@ +/* + * PEF (Protected Execution Facility) for POWER support + * + * Copyright David Gibson, Redhat Inc. 2020 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "sysemu/kvm.h" +#include "migration/blocker.h" +#include "exec/confidential-guest-support.h" +#include "hw/ppc/pef.h" + +#define TYPE_PEF_GUEST "pef-guest" +OBJECT_DECLARE_SIMPLE_TYPE(PefGuest, PEF_GUEST) + +typedef struct PefGuest PefGuest; +typedef struct PefGuestClass PefGuestClass; + +struct PefGuestClass { + ConfidentialGuestSupportClass parent_class; +}; + +/** + * PefGuest: + * + * The PefGuest object is used for creating and managing a PEF + * guest. + * + * # $QEMU \ + * -object pef-guest,id=3Dpef0 \ + * -machine ...,confidential-guest-support=3Dpef0 + */ +struct PefGuest { + ConfidentialGuestSupport parent_obj; +}; + +#ifdef CONFIG_KVM +static int kvmppc_svm_init(Error **errp) +{ + if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_SECURE_GUEST)) { + error_setg(errp, + "KVM implementation does not support Secure VMs (is an = ultravisor running?)"); + return -1; + } else { + int ret =3D kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SECURE_GUEST,= 0, 1); + + if (ret < 0) { + error_setg(errp, + "Error enabling PEF with KVM"); + return -1; + } + } + + return 0; +} + +/* + * Don't set error if KVM_PPC_SVM_OFF ioctl is invoked on kernels + * that don't support this ioctl. + */ +void kvmppc_svm_off(Error **errp) +{ + int rc; + + if (!kvm_enabled()) { + return; + } + + rc =3D kvm_vm_ioctl(KVM_STATE(current_accel()), KVM_PPC_SVM_OFF); + if (rc && rc !=3D -ENOTTY) { + error_setg_errno(errp, -rc, "KVM_PPC_SVM_OFF ioctl failed"); + } +} +#else +static int kvmppc_svm_init(Error **errp) +{ + g_assert_not_reached(); +} +#endif + +int pef_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) +{ + if (!object_dynamic_cast(OBJECT(cgs), TYPE_PEF_GUEST)) { + return 0; + } + + if (!kvm_enabled()) { + error_setg(errp, "PEF requires KVM"); + return -1; + } + + return kvmppc_svm_init(errp); +} + +OBJECT_DEFINE_TYPE_WITH_INTERFACES(PefGuest, + pef_guest, + PEF_GUEST, + CONFIDENTIAL_GUEST_SUPPORT, + { TYPE_USER_CREATABLE }, + { NULL }) + +static void pef_guest_class_init(ObjectClass *oc, void *data) +{ +} + +static void pef_guest_init(Object *obj) +{ +} + +static void pef_guest_finalize(Object *obj) +{ +} diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 2c403b574e..accf7a834b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -83,6 +83,7 @@ #include "hw/ppc/spapr_tpm_proxy.h" #include "hw/ppc/spapr_nvdimm.h" #include "hw/ppc/spapr_numa.h" +#include "hw/ppc/pef.h" =20 #include "monitor/monitor.h" =20 @@ -2658,6 +2659,11 @@ static void spapr_machine_init(MachineState *machine) char *filename; Error *resize_hpt_err =3D NULL; =20 + /* + * if Secure VM (PEF) support is configured, then initialize it + */ + pef_kvm_init(machine->cgs, &error_fatal); + msi_nonbroken =3D true; =20 QLIST_INIT(&spapr->phbs); diff --git a/include/hw/ppc/pef.h b/include/hw/ppc/pef.h new file mode 100644 index 0000000000..57d4ec9fe6 --- /dev/null +++ b/include/hw/ppc/pef.h @@ -0,0 +1,25 @@ +/* + * PEF (Protected Execution Facility) for POWER support + * + * Copyright David Gibson, Redhat Inc. 2020 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef HW_PPC_PEF_H +#define HW_PPC_PEF_H + +int pef_kvm_init(ConfidentialGuestSupport *cgs, Error **errp); + +#ifdef CONFIG_KVM +void kvmppc_svm_off(Error **errp); +#else +static inline void kvmppc_svm_off(Error **errp) +{ +} +#endif + + +#endif /* HW_PPC_PEF_H */ diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index daf690a678..0c5056dd5b 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2929,21 +2929,3 @@ void kvmppc_set_reg_tb_offset(PowerPCCPU *cpu, int64= _t tb_offset) kvm_set_one_reg(cs, KVM_REG_PPC_TB_OFFSET, &tb_offset); } } - -/* - * Don't set error if KVM_PPC_SVM_OFF ioctl is invoked on kernels - * that don't support this ioctl. - */ -void kvmppc_svm_off(Error **errp) -{ - int rc; - - if (!kvm_enabled()) { - return; - } - - rc =3D kvm_vm_ioctl(KVM_STATE(current_accel()), KVM_PPC_SVM_OFF); - if (rc && rc !=3D -ENOTTY) { - error_setg_errno(errp, -rc, "KVM_PPC_SVM_OFF ioctl failed"); - } -} diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 73ce2bc951..989f61ace0 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -39,7 +39,6 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu); target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl); -void kvmppc_svm_off(Error **errp); #ifndef CONFIG_USER_ONLY bool kvmppc_spapr_use_multitce(void); int kvmppc_spapr_enable_inkernel_multitce(void); @@ -216,11 +215,6 @@ static inline target_ulong kvmppc_configure_v3_mmu(Pow= erPCCPU *cpu, return 0; } =20 -static inline void kvmppc_svm_off(Error **errp) -{ - return; -} - static inline void kvmppc_set_reg_ppc_online(PowerPCCPU *cpu, unsigned int online) { --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610583182; cv=none; d=zohomail.com; s=zohoarc; b=Cft1DC/gTt2Krp5zqFoQTtknIb0Cd+Yb3q6L6mxznYELirwRhlFYefuIZEcDYD4ixEC/eBI12aHV5QfyxXIt7Ft48nnRVJfQCcECO213+pzBs+nXYm3kZcnIvbJqzc74KNcQ/v6wKfulWKHBlUDtGUoo3CUwl6Cm8/7fCz8+RbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610583182; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=51eIULAE4M4ytnQxSIgt6zOWEF1wk/nxVpND178/ZTc=; b=TnQj/b/lbUNzXlGKl9O+4tY/m1yWQr6z15pEWWbpdPap8qDsR34SejDoNkoj2hO680QuqbZ2ubWzdda1AnCimRcBqBs6I6Ewq9mPtknhCPn7jms41qimlXYK3rCwmAb0IZqCLSDNasqu0Ugd0MmhHSexp/AK/SB5dh0WjO7qbMg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610583182327412.2120508831373; Wed, 13 Jan 2021 16:13:02 -0800 (PST) Received: from localhost ([::1]:34890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqG5-0005wY-4I for importer@patchew.org; Wed, 13 Jan 2021 19:13:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq28-0007J0-3T; Wed, 13 Jan 2021 18:58:36 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:50169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq26-0006fO-03; Wed, 13 Jan 2021 18:58:35 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR3Gm0z9sj5; Thu, 14 Jan 2021 10:58:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=NmD42X0WsHRqDVYpVVbDz7PiUpDumAPsjTSKm/2tvCs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eHnrJQZ9Z4likHKrb5Kig2JSXFW0K06BO15ZxTUk6xEr/KwURm9e9/XjyUT8EI6lB iY3L/J4gGwpnSp8p8o/6ndTeJ+yr82C+aujC7PsR2jVMwSVeh/t5Y3M4BvxM29ePok 8hzRL5a/WrMh32T/jRpiEVR+JaU30Vjhv16FKmP4= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 11/13] spapr: PEF: prevent migration Date: Thu, 14 Jan 2021 10:58:09 +1100 Message-Id: <20210113235811.1909610-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We haven't yet implemented the fairly involved handshaking that will be needed to migrate PEF protected guests. For now, just use a migration blocker so we get a meaningful error if someone attempts this (this is the same approach used by AMD SEV). Signed-off-by: David Gibson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Greg Kurz --- hw/ppc/pef.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/ppc/pef.c b/hw/ppc/pef.c index 02b9b3b460..d7a49ef337 100644 --- a/hw/ppc/pef.c +++ b/hw/ppc/pef.c @@ -42,6 +42,8 @@ struct PefGuest { }; =20 #ifdef CONFIG_KVM +static Error *pef_mig_blocker; + static int kvmppc_svm_init(Error **errp) { if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_SECURE_GUEST)) { @@ -58,6 +60,11 @@ static int kvmppc_svm_init(Error **errp) } } =20 + /* add migration blocker */ + error_setg(&pef_mig_blocker, "PEF: Migration is not implemented"); + /* NB: This can fail if --only-migratable is used */ + migrate_add_blocker(pef_mig_blocker, &error_fatal); + return 0; } =20 --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610582866; cv=none; d=zohomail.com; s=zohoarc; b=G7wO11Rl8wOepkMDXBV6B4mgBma5cz9GY5w2zm5+kY5tetnkOhb2vywqpwh2yBtkbTLWnOoeMhDhz4SKsXE7erWZ1BTNZ3AdaMk3uq+UtEzmRNR8suh2LcsPHeby9iNBWW2PG9ORYeCVQ69sqtSeU8u8J6Xer/yuFJAVkvGeTlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610582866; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NYbwxpJ4pyIbWAHg+3LV1OJkKdaYvyv5/nsP3grZh2U=; b=FCNbnvbaeWxjptrrbR0xRTXV66A/BMOXd92zzIzXSEetjtPu75H5g+kwLfwj34MTE8xwPqV+k5qI0irrhVpVcZVYLdNTrLIaKxaSNID73Le3x3KPsCA8oAdvAF31KUeH2xUisrxn8s+/3fE/5Uyb3cRuhQzRzPEtvNZtf9epFMo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610582866045167.8194641333754; Wed, 13 Jan 2021 16:07:46 -0800 (PST) Received: from localhost ([::1]:49344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqAy-0008VE-Rg for importer@patchew.org; Wed, 13 Jan 2021 19:07:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq2A-0007QE-JG; Wed, 13 Jan 2021 18:58:38 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:36387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq28-0006iO-Ou; Wed, 13 Jan 2021 18:58:38 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR4BBWz9sjB; Thu, 14 Jan 2021 10:58:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=cJPi6/8rIQ8cwCcDD17pu1Q0OOK2AVCJGI2N7uMc4L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=js6IfPg2vCEVsr0cG7Nxp8qFRit3WOJkeDIsZ8aQeKhwDiqQPOb3AGyScr2AmcdAp KWqhmn1YJ74MYBKVi7g7d1CbNZE1gWPrhThn8PocuUl2refDqTV35XG5Rlhqzr6CWg FVRgbPz7EsmIRCa/VafgxuLxHw4yvB53y/TSD/dc= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 12/13] confidential guest support: Alter virtio default properties for protected guests Date: Thu, 14 Jan 2021 10:58:10 +1100 Message-Id: <20210113235811.1909610-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The default behaviour for virtio devices is not to use the platforms normal DMA paths, but instead to use the fact that it's running in a hypervisor to directly access guest memory. That doesn't work if the guest's memory is protected from hypervisor access, such as with AMD's SEV or POWER's PEF. So, if a confidential guest mechanism is enabled, then apply the iommu_platform=3Don option so it will go through normal DMA mechanisms. Those will presumably have some way of marking memory as shared with the hypervisor or hardware so that DMA will work. Signed-off-by: David Gibson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Cornelia Huck Reviewed-by: Greg Kurz --- hw/core/machine.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 5a7433332b..61ae363559 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -33,6 +33,8 @@ #include "migration/global_state.h" #include "migration/vmstate.h" #include "exec/confidential-guest-support.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-pci.h" =20 GlobalProperty hw_compat_5_2[] =3D {}; const size_t hw_compat_5_2_len =3D G_N_ELEMENTS(hw_compat_5_2); @@ -1204,6 +1206,17 @@ void machine_run_board_init(MachineState *machine) * areas. */ machine_set_mem_merge(OBJECT(machine), false, &error_abort); + + /* + * Virtio devices can't count on directly accessing guest + * memory, so they need iommu_platform=3Don to use normal DMA + * mechanisms. That requires also disabling legacy virtio + * support for those virtio pci devices which allow it. + */ + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", + "on", true); + object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform", + "on", false); } =20 machine_class->init(machine); --=20 2.29.2 From nobody Fri Apr 19 17:23:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1610583378; cv=none; d=zohomail.com; s=zohoarc; b=Qy9kifED40F6F7IgNgOr4I/Xc7Y2yWwhiRNJvF1Pg/nLayKHjpiZ8pENyg7PLKY8G//NAjeTwf9wvVdX2YeClITJfph5no9SSNiiU71cg3J4dtCtJ/VPm/5LVw9hAq6ZmK/RBywdOfFoN4wdo5x0OGXWmNyGkMAwjIstINcFQKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610583378; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o9qj5pUhF6U4+An8/Ffc3kibLKDtWisS2W9fguU1VRU=; b=iYYyGRlfE1G66EXXjDT902ZO7S6EHLIqdHhL8on5lWiuvJNzZMvQ1TwHc0Ljm/Keto6byNpLOw89j1f8t9crm5615s/WbY08Otn0IlhUbErZMTuvVqcBO8HQBPKmzoJ6BEyZfWawe96piy/tPAImKrVUO/wwnCvuG0uAq9Gubtw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1610583377907243.2419833172347; Wed, 13 Jan 2021 16:16:17 -0800 (PST) Received: from localhost ([::1]:42138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzqJE-0000cm-Qx for importer@patchew.org; Wed, 13 Jan 2021 19:16:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq2f-0008IS-Ta; Wed, 13 Jan 2021 18:59:09 -0500 Received: from ozlabs.org ([2401:3900:2:1::2]:43993) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzq2d-0006ie-TI; Wed, 13 Jan 2021 18:59:09 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4DGPXR55cYz9sjD; Thu, 14 Jan 2021 10:58:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1610582295; bh=Vj1RSGtq3tXPDmBRhrrfnvI3/OQqRk1glYDp8Wuofx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EMcifB8rGQ7bJ4C/bNq90cgIoKZ4gnlKZL7TKYI7fAWaQ17H9yHCBVqnnWlprnO2d 6q4Dnm7Is7OKZRL0lWjza6ZGKJbWnwJ5v0rxsQCU3T4U1QjX/MbUnCJSmllDyKwxp0 XJpp9zIfXm0eMZmBrSu8zjHCPwk6BEtyvZyHntdw= From: David Gibson To: brijesh.singh@amd.com, pair@us.ibm.com, dgilbert@redhat.com, pasic@linux.ibm.com, qemu-devel@nongnu.org Subject: [PATCH v7 13/13] s390: Recognize confidential-guest-support option Date: Thu, 14 Jan 2021 10:58:11 +1100 Message-Id: <20210113235811.1909610-14-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210113235811.1909610-1-david@gibson.dropbear.id.au> References: <20210113235811.1909610-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 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=2401:3900:2:1::2; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, thuth@redhat.com, Marcelo Tosatti , berrange@redhat.com, jun.nakajima@intel.com, kvm@vger.kernel.org, David Hildenbrand , cohuck@redhat.com, Richard Henderson , Greg Kurz , mdroth@linux.vnet.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, frankja@linux.ibm.com, mst@redhat.com, pragyansri.pathi@intel.com, andi.kleen@intel.com, Paolo Bonzini , David Gibson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" At least some s390 cpu models support "Protected Virtualization" (PV), a mechanism to protect guests from eavesdropping by a compromised hypervisor. This is similar in function to other mechanisms like AMD's SEV and POWER's PEF, which are controlled by the "confidential-guest-support" machine option. s390 is a slightly special case, because we already supported PV, simply by using a CPU model with the required feature (S390_FEAT_UNPACK). To integrate this with the option used by other platforms, we implement the following compromise: - When the confidential-guest-support option is set, s390 will recognize it, verify that the CPU can support PV (failing if not) and set virtio default options necessary for encrypted or protected guests, as on other platforms. i.e. if confidential-guest-support is set, we will either create a guest capable of entering PV mode, or fail outright. - If confidential-guest-support is not set, guests might still be able to enter PV mode, if the CPU has the right model. This may be a little surprising, but shouldn't actually be harmful. To start a guest supporting Protected Virtualization using the new option use the command line arguments: -object s390-pv-guest,id=3Dpv0 -machine confidential-guest-support=3Dpv0 Signed-off-by: David Gibson --- docs/confidential-guest-support.txt | 3 ++ docs/system/s390x/protvirt.rst | 19 ++++++--- hw/s390x/pv.c | 62 +++++++++++++++++++++++++++++ include/hw/s390x/pv.h | 1 + target/s390x/kvm.c | 3 ++ 5 files changed, 82 insertions(+), 6 deletions(-) diff --git a/docs/confidential-guest-support.txt b/docs/confidential-guest-= support.txt index f0801814ff..50b976a082 100644 --- a/docs/confidential-guest-support.txt +++ b/docs/confidential-guest-support.txt @@ -43,4 +43,7 @@ AMD Secure Encrypted Virtualization (SEV) POWER Protected Execution Facility (PEF) docs/papr-pef.txt =20 +s390x Protected Virtualization (PV) + docs/system/s390x/protvirt.rst + Other mechanisms may be supported in future. diff --git a/docs/system/s390x/protvirt.rst b/docs/system/s390x/protvirt.rst index 712974ad87..0f481043d9 100644 --- a/docs/system/s390x/protvirt.rst +++ b/docs/system/s390x/protvirt.rst @@ -22,15 +22,22 @@ If those requirements are met, the capability `KVM_CAP_= S390_PROTECTED` will indicate that KVM can support PVMs on that LPAR. =20 =20 -QEMU Settings -------------- +Running a Protected Virtual Machine +----------------------------------- =20 -To indicate to the VM that it can transition into protected mode, the +To run a PVM you will need to select a CPU model which includes the `Unpack facility` (stfle bit 161 represented by the feature -`unpack`/`S390_FEAT_UNPACK`) needs to be part of the cpu model of -the VM. +`unpack`/`S390_FEAT_UNPACK`), and add these options to the command line:: + + -object s390-pv-guest,id=3Dpv0 \ + -machine confidential-guest-support=3Dpv0 + +Adding these options will: + +* Ensure the `unpack` facility is available +* Enable the IOMMU by default for all I/O devices +* Initialize the PV mechanism =20 -All I/O devices need to use the IOMMU. Passthrough (vfio) devices are currently not supported. =20 Host huge page backings are not supported. However guests can use huge diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index ab3a2482aa..319d74dfcf 100644 --- a/hw/s390x/pv.c +++ b/hw/s390x/pv.c @@ -14,8 +14,11 @@ #include =20 #include "cpu.h" +#include "qapi/error.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "qom/object_interfaces.h" +#include "exec/confidential-guest-support.h" #include "hw/s390x/ipl.h" #include "hw/s390x/pv.h" =20 @@ -111,3 +114,62 @@ void s390_pv_inject_reset_error(CPUState *cs) /* Report that we are unable to enter protected mode */ env->regs[r1 + 1] =3D DIAG_308_RC_INVAL_FOR_PV; } + +#define TYPE_S390_PV_GUEST "s390-pv-guest" +OBJECT_DECLARE_SIMPLE_TYPE(S390PVGuest, S390_PV_GUEST) + +/** + * S390PVGuest: + * + * The S390PVGuest object is basically a dummy used to tell the + * confidential guest support system to use s390's PV mechanism. + * + * # $QEMU \ + * -object s390-pv-guest,id=3Dpv0 \ + * -machine ...,confidential-guest-support=3Dpv0 + */ +struct S390PVGuest { + ConfidentialGuestSupport parent_obj; +}; + +typedef struct S390PVGuestClass S390PVGuestClass; + +struct S390PVGuestClass { + ConfidentialGuestSupportClass parent_class; +}; + +int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp) +{ + if (!object_dynamic_cast(OBJECT(cgs), TYPE_S390_PV_GUEST)) { + return 0; + } + + if (!s390_has_feat(S390_FEAT_UNPACK)) { + error_setg(errp, + "CPU model does not support Protected Virtualization"); + return -1; + } + + cgs->ready =3D true; + + return 0; +} + +OBJECT_DEFINE_TYPE_WITH_INTERFACES(S390PVGuest, + s390_pv_guest, + S390_PV_GUEST, + CONFIDENTIAL_GUEST_SUPPORT, + { TYPE_USER_CREATABLE }, + { NULL }) + +static void s390_pv_guest_class_init(ObjectClass *oc, void *data) +{ +} + +static void s390_pv_guest_init(Object *obj) +{ +} + +static void s390_pv_guest_finalize(Object *obj) +{ +} diff --git a/include/hw/s390x/pv.h b/include/hw/s390x/pv.h index aee758bc2d..9bbf66f356 100644 --- a/include/hw/s390x/pv.h +++ b/include/hw/s390x/pv.h @@ -43,6 +43,7 @@ void s390_pv_prep_reset(void); int s390_pv_verify(void); void s390_pv_unshare(void); void s390_pv_inject_reset_error(CPUState *cs); +int s390_pv_init(ConfidentialGuestSupport *cgs, Error **errp); #else /* CONFIG_KVM */ static inline bool s390_is_pv(void) { return false; } static inline int s390_pv_vm_enable(void) { return 0; } diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index b8385e6b95..d2435664dc 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -387,6 +387,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } =20 kvm_set_max_memslot_size(KVM_SLOT_MAX_BYTES); + + s390_pv_init(ms->cgs, &error_fatal); + return 0; } =20 --=20 2.29.2