From nobody Sun May 19 05:00:04 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=1595559679; cv=none; d=zohomail.com; s=zohoarc; b=IDOoj7lre2/iEpezFv3GcdOmrHOhfnad8uf9N1FNuWtWCYUoAC7oAOZGqaztXYrF3+emU5VhAjHTjQ0RyRJTI5PQ4u2oBDh+4rQPvk17+o2JiM6NQgfZ8hhAGWehQuJNAOYSSvcoMhsip+YshjVTMKSh1CiulQKFgvi23cYnO00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559679; 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=S6Yl9QH7c+xo/zsr+3D95uxo2lSniK2I20iGdUfbaOA=; b=KMD70HEYM6cmqceL/sV4qv4Zz3xtlyGubIUttxlKdEOFSjY6jCk5lDxaqoEJIGD+upEYae2UUUyRrzqnbWfkU2NhYy02a/KzEkBqT8s4PGDYmESZ/Z7mj163U04tvF9vWl5Rai7eKYhvh127OTlGpGXPuvofxeJOI/Clank8ML8= 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 1595559679414392.97199777722903; Thu, 23 Jul 2020 20:01:19 -0700 (PDT) Received: from localhost ([::1]:55816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynxW-0003wS-7e for importer@patchew.org; Thu, 23 Jul 2020 23:01:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuL-0007El-9L; Thu, 23 Jul 2020 22:58:01 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:59865 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuJ-00060G-BL; Thu, 23 Jul 2020 22:58:00 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlv33w0z9sSt; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559467; bh=aXMwhPSEkPHTpzErQPz4f4zNkJ2AVJxzRI0h3KgdOaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I8R/r6K0P/IZg9wSKSjVg8EjaXlXMJmGktM9HhxalYdYd1gB7LXXgFxkcmHIyQHqn yxPqtlhIW670eVcVZpL3C3m1uB0rstBiBaYembN8TPTdsKUsNqvjo+wNjHOe5V8GXt lrZfMdVdBphNf6F/mciBlXPWMn31lLx5pZr4iUis= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 01/10] host trust limitation: Introduce new host trust limitation interface Date: Fri, 24 Jul 2020 12:57:35 +1000 Message-Id: <20200724025744.69644-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 has a similar mechanism. 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 HostTrustLimitation QOM interface. Signed-off-by: David Gibson Acked-by: Dr. David Alan Gilbert Reviewed-by: Richard Henderson --- backends/Makefile.objs | 2 ++ backends/host-trust-limitation.c | 29 ++++++++++++++++++++++++ include/exec/host-trust-limitation.h | 33 ++++++++++++++++++++++++++++ include/qemu/typedefs.h | 1 + 4 files changed, 65 insertions(+) create mode 100644 backends/host-trust-limitation.c create mode 100644 include/exec/host-trust-limitation.h diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 22d204cb48..dcb8f58d31 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -21,3 +21,5 @@ common-obj-$(CONFIG_LINUX) +=3D hostmem-memfd.o common-obj-$(CONFIG_GIO) +=3D dbus-vmstate.o dbus-vmstate.o-cflags =3D $(GIO_CFLAGS) dbus-vmstate.o-libs =3D $(GIO_LIBS) + +common-obj-y +=3D host-trust-limitation.o diff --git a/backends/host-trust-limitation.c b/backends/host-trust-limitat= ion.c new file mode 100644 index 0000000000..96a381cd8a --- /dev/null +++ b/backends/host-trust-limitation.c @@ -0,0 +1,29 @@ +/* + * QEMU Host Trust Limitation interface + * + * 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/host-trust-limitation.h" + +static const TypeInfo host_trust_limitation_info =3D { + .name =3D TYPE_HOST_TRUST_LIMITATION, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(HostTrustLimitationClass), +}; + +static void host_trust_limitation_register_types(void) +{ + type_register_static(&host_trust_limitation_info); +} + +type_init(host_trust_limitation_register_types) diff --git a/include/exec/host-trust-limitation.h b/include/exec/host-trust= -limitation.h new file mode 100644 index 0000000000..03887b1be1 --- /dev/null +++ b/include/exec/host-trust-limitation.h @@ -0,0 +1,33 @@ +/* + * QEMU Host Trust Limitation interface + * + * 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_HOST_TRUST_LIMITATION_H +#define QEMU_HOST_TRUST_LIMITATION_H + +#include "qom/object.h" + +#define TYPE_HOST_TRUST_LIMITATION "host-trust-limitation" +#define HOST_TRUST_LIMITATION(obj) \ + INTERFACE_CHECK(HostTrustLimitation, (obj), \ + TYPE_HOST_TRUST_LIMITATION) +#define HOST_TRUST_LIMITATION_CLASS(klass) \ + OBJECT_CLASS_CHECK(HostTrustLimitationClass, (klass), \ + TYPE_HOST_TRUST_LIMITATION) +#define HOST_TRUST_LIMITATION_GET_CLASS(obj) \ + OBJECT_GET_CLASS(HostTrustLimitationClass, (obj), \ + TYPE_HOST_TRUST_LIMITATION) + +typedef struct HostTrustLimitationClass { + InterfaceClass parent; +} HostTrustLimitationClass; + +#endif /* QEMU_HOST_TRUST_LIMITATION_H */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 427027a970..624d59c037 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -51,6 +51,7 @@ typedef struct FWCfgIoState FWCfgIoState; typedef struct FWCfgMemState FWCfgMemState; typedef struct FWCfgState FWCfgState; typedef struct HostMemoryBackend HostMemoryBackend; +typedef struct HostTrustLimitation HostTrustLimitation; typedef struct I2CBus I2CBus; typedef struct I2SCodec I2SCodec; typedef struct IOMMUMemoryRegion IOMMUMemoryRegion; --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559589; cv=none; d=zohomail.com; s=zohoarc; b=k1csYSDridsNnNn13yP0wwxinKTGF5p69W6mxPqSZULqK6etuc8O3v4h9fKdHvkYk8+Q8xAIkkjzAnjs22zgLlKNJlxKVDSsGWjs6KwZT2P20nvVIgm/zcR+f7DBuMKqMA+62eCRMRxKTxf6TxwvAhWRC2yZkHDk5H99vpM77CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559589; 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=K9yxvlBYc9ljdUHrLhZAabPBMBHnw/LsGdyjbRyCG2w=; b=k3iqRssXmKpXYfJZHuC6DzCAEK4UdxYfbof3ZGJy+KJj4he2t0NJhwiXGaBC/OksM+HXtuOXK/m1xjAaLgv3Vo3hkN/c5ZW4nYyEAnitdQmVqvX4+z3YKgSm/eVAqgPV1p27jALCk9t6WO9WWv0FU/2IMKlnQbOYAn1EqYN71y8= 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 1595559589916127.24314206340034; Thu, 23 Jul 2020 19:59:49 -0700 (PDT) Received: from localhost ([::1]:49330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynw4-0001H5-KP for importer@patchew.org; Thu, 23 Jul 2020 22:59:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuL-0007Ep-9y; Thu, 23 Jul 2020 22:58:01 -0400 Received: from ozlabs.org ([203.11.71.1]:45897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuH-00060C-OY; Thu, 23 Jul 2020 22:58:00 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlv27sJz9sPB; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559467; bh=jOh302ICMvqv+PqzmEYZM/FeEcTqLZlPD0brgAjYmLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ax3uyoL3DMEDQU+kVdFw8ajofr1GheaEnjnjIqAGJGYNMleUsjmoLbYhZzERr9Hrz 5vN4FtGUUHrslBUodzGTv7vDUKks96VKaM81LyhwdgpZc+qSNrWeS07B+dm529q23H fvQW8SXUEyh7QkdbgnqXIqNv+HRpNpP4GYum0vgQ= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 02/10] host trust limitation: Handle memory encryption via interface Date: Fri, 24 Jul 2020 12:57:36 +1000 Message-Id: <20200724025744.69644-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 the moment AMD SEV sets a special function pointer, plus an opaque handle in KVMState to let things know how to encrypt guest memory. Now that we have a QOM interface for handling things related to host trust limitation, use a QOM method on that interface, rather than a bare function pointer for this. Signed-off-by: David Gibson Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 38 ++++++--- accel/kvm/sev-stub.c | 7 +- include/exec/host-trust-limitation.h | 3 + include/sysemu/sev.h | 4 +- target/i386/sev.c | 119 +++++++++++---------------- 5 files changed, 80 insertions(+), 91 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 63ef6af9a1..d7d95eacc7 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -39,11 +39,11 @@ #include "qemu/main-loop.h" #include "trace.h" #include "hw/irq.h" -#include "sysemu/sev.h" #include "qapi/visitor.h" #include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "sysemu/reset.h" +#include "exec/host-trust-limitation.h" =20 #include "hw/boards.h" =20 @@ -117,9 +117,8 @@ 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); + /* host trust limitation (e.g. by guest memory encryption) */ + HostTrustLimitation *htl; =20 /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; @@ -221,7 +220,7 @@ int kvm_get_max_memslots(void) =20 bool kvm_memcrypt_enabled(void) { - if (kvm_state && kvm_state->memcrypt_handle) { + if (kvm_state && kvm_state->htl) { return true; } =20 @@ -230,10 +229,12 @@ bool kvm_memcrypt_enabled(void) =20 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); + HostTrustLimitation *htl =3D kvm_state->htl; + + if (htl) { + HostTrustLimitationClass *htlc =3D HOST_TRUST_LIMITATION_GET_CLASS= (htl); + + return htlc->encrypt_data(htl, ptr, len); } =20 return 1; @@ -2186,13 +2187,24 @@ 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) { + Object *obj =3D object_resolve_path_component(object_get_objects_r= oot(), + ms->memory_encryption); + + if (object_dynamic_cast(obj, TYPE_HOST_TRUST_LIMITATION)) { + HostTrustLimitation *htl =3D HOST_TRUST_LIMITATION(obj); + HostTrustLimitationClass *htlc + =3D HOST_TRUST_LIMITATION_GET_CLASS(htl); + + ret =3D htlc->kvm_init(htl); + if (ret < 0) { + goto err; + } + + kvm_state->htl =3D htl; + } else { ret =3D -1; 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..9c7c897593 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) -{ - abort(); -} - -void *sev_guest_init(const char *id) +HostTrustLimitation *sev_guest_init(const char *id) { return NULL; } diff --git a/include/exec/host-trust-limitation.h b/include/exec/host-trust= -limitation.h index 03887b1be1..a19f12ae14 100644 --- a/include/exec/host-trust-limitation.h +++ b/include/exec/host-trust-limitation.h @@ -28,6 +28,9 @@ =20 typedef struct HostTrustLimitationClass { InterfaceClass parent; + + int (*kvm_init)(HostTrustLimitation *); + int (*encrypt_data)(HostTrustLimitation *, uint8_t *, uint64_t); } HostTrustLimitationClass; =20 #endif /* QEMU_HOST_TRUST_LIMITATION_H */ diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 98c1ec8d38..a4aee6a87d 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,6 +16,6 @@ =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); +HostTrustLimitation *sev_guest_init(const char *id); + #endif diff --git a/target/i386/sev.c b/target/i386/sev.c index c3ecf86704..8e3c9dcc2c 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -28,6 +28,7 @@ #include "sysemu/runstate.h" #include "trace.h" #include "migration/blocker.h" +#include "exec/host-trust-limitation.h" =20 #define TYPE_SEV_GUEST "sev-guest" #define SEV_GUEST(obj) \ @@ -281,26 +282,6 @@ sev_guest_set_sev_device(Object *obj, const char *valu= e, Error **errp) sev->sev_device =3D g_strdup(value); } =20 -static void -sev_guest_class_init(ObjectClass *oc, void *data) -{ - object_class_property_add_str(oc, "sev-device", - sev_guest_get_sev_device, - sev_guest_set_sev_device); - object_class_property_set_description(oc, "sev-device", - "SEV device to use"); - object_class_property_add_str(oc, "dh-cert-file", - sev_guest_get_dh_cert_file, - sev_guest_set_dh_cert_file); - object_class_property_set_description(oc, "dh-cert-file", - "guest owners DH certificate (encoded with base64)"); - object_class_property_add_str(oc, "session-file", - sev_guest_get_session_file, - sev_guest_set_session_file); - object_class_property_set_description(oc, "session-file", - "guest owners session parameters (encoded with base64)"); -} - static void sev_guest_instance_init(Object *obj) { @@ -319,40 +300,6 @@ sev_guest_instance_init(Object *obj) OBJ_PROP_FLAG_READWRITE); } =20 -/* sev guest info */ -static const TypeInfo sev_guest_info =3D { - .parent =3D TYPE_OBJECT, - .name =3D TYPE_SEV_GUEST, - .instance_size =3D sizeof(SevGuestState), - .instance_finalize =3D sev_guest_finalize, - .class_init =3D sev_guest_class_init, - .instance_init =3D sev_guest_instance_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_USER_CREATABLE }, - { } - } -}; - -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) { @@ -679,10 +626,9 @@ sev_vm_state_change(void *opaque, int running, RunStat= e state) } } =20 -void * -sev_guest_init(const char *id) +static int sev_kvm_init(HostTrustLimitation *htl) { - SevGuestState *sev; + SevGuestState *sev =3D SEV_GUEST(htl); char *devname; int ret, fw_error; uint32_t ebx; @@ -692,14 +638,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; - } - - 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; + return -1; } =20 sev_guest =3D sev; @@ -763,17 +702,17 @@ 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) +static int +sev_encrypt_data(HostTrustLimitation *opaque, uint8_t *ptr, uint64_t len) { - SevGuestState *sev =3D handle; + SevGuestState *sev =3D SEV_GUEST(opaque); =20 assert(sev); =20 @@ -785,6 +724,46 @@ sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t = len) return 0; } =20 +static void +sev_guest_class_init(ObjectClass *oc, void *data) +{ + HostTrustLimitationClass *htlc =3D HOST_TRUST_LIMITATION_CLASS(oc); + + object_class_property_add_str(oc, "sev-device", + sev_guest_get_sev_device, + sev_guest_set_sev_device); + object_class_property_set_description(oc, "sev-device", + "SEV device to use"); + object_class_property_add_str(oc, "dh-cert-file", + sev_guest_get_dh_cert_file, + sev_guest_set_dh_cert_file); + object_class_property_set_description(oc, "dh-cert-file", + "guest owners DH certificate (encoded with base64)"); + object_class_property_add_str(oc, "session-file", + sev_guest_get_session_file, + sev_guest_set_session_file); + object_class_property_set_description(oc, "session-file", + "guest owners session parameters (encoded with base64)"); + + htlc->kvm_init =3D sev_kvm_init; + htlc->encrypt_data =3D sev_encrypt_data; +} + +/* sev guest info */ +static const TypeInfo sev_guest_info =3D { + .parent =3D TYPE_OBJECT, + .name =3D TYPE_SEV_GUEST, + .instance_size =3D sizeof(SevGuestState), + .instance_finalize =3D sev_guest_finalize, + .class_init =3D sev_guest_class_init, + .instance_init =3D sev_guest_instance_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOST_TRUST_LIMITATION }, + { TYPE_USER_CREATABLE }, + { } + } +}; + static void sev_register_types(void) { --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559574; cv=none; d=zohomail.com; s=zohoarc; b=b7Mg1AK0g9R10qTTJ6OZ11k7G9JOkRcd6kRa0xezA8XLqjETIKJ9b6XdbVFbmy09Hh5d3t5GP0Cn8oOIa0o1xRWppICwihidGNHxh2sGKQgpO91WnQFG6zN31mxBPQSdHv1iut5L2Y8gmZ5qV59uc3uQahKeMees4XMhBDffd9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559574; 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=dyMqMPt9qQlUqisie6HqnuxztZrUo8iiPDr66hMzMM0=; b=QXISF7CP7JmhSx6Wk9bkrEsnEUGb7X0c5A53vomevAOG3O7IcW+uyIW2cwLwDx7Gja5oac4tDvmYRFn4bQ1grOtZ5FrHKFoJJxn5TfqxYyDjqLWRzRFqHR8sJei2ABDrGOmJqs9BeCKV+Wj9O0VUj+xHyGukGSv/RUjJ08ixV6k= 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 1595559574735967.2648345508347; Thu, 23 Jul 2020 19:59:34 -0700 (PDT) Received: from localhost ([::1]:47698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynvp-0000dI-2x for importer@patchew.org; Thu, 23 Jul 2020 22:59:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuL-0007Eg-3B; Thu, 23 Jul 2020 22:58:01 -0400 Received: from ozlabs.org ([203.11.71.1]:33841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuH-00060F-OP; Thu, 23 Jul 2020 22:58:00 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlv5VC5z9sTC; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559467; bh=HmcdQhqv6u0WvbSTqY3hEVc0yzPwYsuoT3bUsWyJi1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n+0JQilQDIIAqWIav0HdtD8GraIx0bzBq46AppmC0VpVi9JpX1ocIHF453u/sZEj+ KZm03zv0/a5pF6t4mrGFmXShx35yH7G+SO1peo8tUOVUlc0AzoFSC6IgJi18fgSyp1 X4ejxuJxqNWUobrouQrOCxr/nMMaiaqWZ+ITBYz8= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 03/10] host trust limitation: Move side effect out of machine_set_memory_encryption() Date: Fri, 24 Jul 2020 12:57:37 +1000 Message-Id: <20200724025744.69644-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 --- 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 2f881d6d75..035a1fc631 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -432,14 +432,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) @@ -1131,6 +1123,15 @@ void machine_run_board_init(MachineState *machine) } } =20 + if (machine->memory_encryption) { + /* + * With host trust limitation, 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); } =20 --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559573; cv=none; d=zohomail.com; s=zohoarc; b=NfzwRRf42kMfahp1er2MlW/iI9q7eHwLg3jpEnbmOmgL1KxnuskCnYvduHlXvLHaj/390wrGPzN5buZMY/BUeAaYzZBmyBE0SaGTwJcGvCTJ3v5xPUta3KzC6kG3vdxIV3cD1MaTcJGHCq6BlG4oWo4gD/7NIIUWhOD8L5V/Sd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559573; 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=spDp/MGTkbqqgf/sz4voEwQrT0b11jl4QzC/p1ZD0js=; b=Ou7If06dAmoGCB5YWLIKyITWAETWDGd6K054N517ye8KgKs2naNW7Mng8cHWeC9I/t5VEGQwBt8b5PF2kyqyMAV61xhS4qAw7r1Npw05IqiHKtE61u/Ax3ZWRvZCUN567gRzAC3IWwlbQUIS/hODKVBK4HBhBNURplhnBoTfeKc= 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 159555957383313.33865386163427; Thu, 23 Jul 2020 19:59:33 -0700 (PDT) Received: from localhost ([::1]:47540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynvn-0000ZK-PU for importer@patchew.org; Thu, 23 Jul 2020 22:59:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuL-0007Ef-1M; Thu, 23 Jul 2020 22:58:01 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:51663 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuH-00060B-OC; Thu, 23 Jul 2020 22:58:00 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlv4Z8Sz9sSn; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559467; bh=R0fgLYiXYKzsBYFKyppNWeAvNHP70nX+ch1lmvuKdkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nfyg+H1j2J84kBQamTgGTxcM7EJvrRZ+dLtwvoISyZJ9FIF3BwuTfOeq7x76/C0/W U4DTmGjwwPKE+0UwUR5DhjQcFxzLuHbN3JuJLtbWPvhqdT8k9qOKkbDOFpBjyR9HvI TRE7xA2fFVoIgxJ5fW2b5jvI2Y9BuFFLrtcEkyIc= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 04/10] host trust limitation: Rework the "memory-encryption" property Date: Fri, 24 Jul 2020 12:57:38 +1000 Message-Id: <20200724025744.69644-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 "host-trust-limitation" 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: Richard Henderson --- accel/kvm/kvm-all.c | 23 +++++++---------------- hw/core/machine.c | 41 ++++++++++++++++++++++++++++++++++++----- include/hw/boards.h | 2 +- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d7d95eacc7..e2d8f47f93 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2186,25 +2186,16 @@ static int kvm_init(MachineState *ms) * if memory encryption object is specified then initialize the memory * encryption context. */ - if (ms->memory_encryption) { - Object *obj =3D object_resolve_path_component(object_get_objects_r= oot(), - ms->memory_encryption); - - if (object_dynamic_cast(obj, TYPE_HOST_TRUST_LIMITATION)) { - HostTrustLimitation *htl =3D HOST_TRUST_LIMITATION(obj); - HostTrustLimitationClass *htlc - =3D HOST_TRUST_LIMITATION_GET_CLASS(htl); - - ret =3D htlc->kvm_init(htl); - if (ret < 0) { - goto err; - } + if (ms->htl) { + HostTrustLimitationClass *htlc =3D + HOST_TRUST_LIMITATION_GET_CLASS(ms->htl); =20 - kvm_state->htl =3D htl; - } else { - ret =3D -1; + ret =3D htlc->kvm_init(ms->htl); + if (ret < 0) { goto err; } + + kvm_state->htl =3D ms->htl; } =20 ret =3D kvm_arch_init(ms, s); diff --git a/hw/core/machine.c b/hw/core/machine.c index 035a1fc631..b599b0ba65 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -27,6 +27,7 @@ #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" #include "migration/vmstate.h" +#include "exec/host-trust-limitation.h" =20 GlobalProperty hw_compat_5_0[] =3D { { "virtio-balloon-device", "page-poison", "false" }, @@ -422,16 +423,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->htl) { + return g_strdup(object_get_canonical_path_component(OBJECT(ms->htl= ))); + } + + return NULL; } =20 static void machine_set_memory_encryption(Object *obj, const char *value, Error **errp) { - MachineState *ms =3D MACHINE(obj); + Object *htl =3D + object_resolve_path_component(object_get_objects_root(), value); + + if (!htl) { + 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, "host-trust-limitation", htl, errp); +} + +static void machine_check_host_trust_limitation(const Object *obj, + const char *name, + Object *new_target, + Error **errp) +{ + /* + * So far the only constraint is that the target has the + * TYPE_HOST_TRUST_LIMITATION interface, and that's checked by the + * QOM core + */ } =20 static bool machine_get_nvdimm(Object *obj, Error **errp) @@ -852,6 +874,15 @@ static void machine_class_init(ObjectClass *oc, void *= data) object_class_property_set_description(oc, "enforce-config-section", "Set on to enforce configuration section migration"); =20 + object_class_property_add_link(oc, "host-trust-limitation", + TYPE_HOST_TRUST_LIMITATION, + offsetof(MachineState, htl), + machine_check_host_trust_limitation, + OBJ_PROP_LINK_STRONG); + object_class_property_set_description(oc, "host-trust-limitation", + "Set host trust limitation object to use"); + + /* 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", @@ -1123,7 +1154,7 @@ void machine_run_board_init(MachineState *machine) } } =20 - if (machine->memory_encryption) { + if (machine->htl) { /* * With host trust limitation, the host can't see the real * contents of RAM, so there's no point in it trying to merge diff --git a/include/hw/boards.h b/include/hw/boards.h index 426ce5f625..c70fb8bd9f 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -278,7 +278,7 @@ struct MachineState { bool suppress_vmdesc; bool enforce_config_section; bool enable_graphics; - char *memory_encryption; + HostTrustLimitation *htl; char *ram_memdev_id; /* * convenience alias to ram_memdev_id backend memory region --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559596; cv=none; d=zohomail.com; s=zohoarc; b=mjfFHCxXNxmg4o9thodiPYiwjwB7MSA2mKZk4WSmnsqu8njv8sFwTjRdZD8PCOO0nDaxcEdDThxTdStc+7MTYsX5d01SelS4SeLRIsaK4tIfLPGz9dU4ZNoShj0lfu3tAFSBdGNf9UsOaUxKoFWbP4NKpu2unsQ2omBVMN8LUe4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559596; 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=VxNEi1szjL2YCTfqxil3eYhp6oPgFEmQfaaJB4MYOPQ=; b=VsdTv3fKZdHKmlAs4toJjdd/G4+qEhQD5/wiKv8b4bAzMr9jF8DMKZBVsKgSlnYotqnTrMKQEQgoB3CNcZc1iFA5vw7CJ9bUJCAgj0ktZ4aB1hA31LXrRJVY5AEaWS5bPICki803I4rM21HpRmv78X+2uliIZZjSZA/A234HLKA= 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 1595559596068943.9729252565037; Thu, 23 Jul 2020 19:59:56 -0700 (PDT) Received: from localhost ([::1]:49966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynwA-0001Wl-QA for importer@patchew.org; Thu, 23 Jul 2020 22:59:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuV-0007aW-Bh; Thu, 23 Jul 2020 22:58:11 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:54029 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuO-00061k-Es; Thu, 23 Jul 2020 22:58:10 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlv6Cjvz9sSy; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559467; bh=JRbdSSqaG0liT/aslzU3m1hnjce6fptMd9RZ6TZwddU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DC+6Qtnf39Aai/D6H6P+axBMx2XtA8CqUBXghtuGqnWLCxlAl8ULsWtB8yeiWgOTr BgzzWGWvgW7tYg6H4e7aTsYsTVgI6T2WFB0Qh+TozWdOKmI00eLAPxHPt2RIRw0H4Z 9kOu41/eZJKnbw5YFCo7cYkulVBqhQCoMdYj5/ms= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 05/10] host trust limitation: Decouple kvm_memcrypt_*() helpers from KVM Date: Fri, 24 Jul 2020 12:57:39 +1000 Message-Id: <20200724025744.69644-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 kvm_memcrypt_enabled() and kvm_memcrypt_encrypt_data() helper functions don't conceptually have any connection to KVM (although it's not possible in practice to use them without it). They also rely on looking at the global KVMState. But the same information is available from the machine, and the only existing callers have natural access to the machine state. Therefore, move and rename them to helpers in host-trust-limitation.h, taking an explicit machine parameter. Signed-off-by: David Gibson Reviewed-by: Richard Henderson --- accel/kvm/kvm-all.c | 27 --------------------- accel/stubs/kvm-stub.c | 10 -------- hw/i386/pc_sysfw.c | 6 +++-- include/exec/host-trust-limitation.h | 36 ++++++++++++++++++++++++++++ include/sysemu/kvm.h | 17 ------------- 5 files changed, 40 insertions(+), 56 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index e2d8f47f93..4b6402c12c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -117,9 +117,6 @@ struct KVMState KVMMemoryListener memory_listener; QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus; =20 - /* host trust limitation (e.g. by guest memory encryption) */ - HostTrustLimitation *htl; - /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; struct KVMAs { @@ -218,28 +215,6 @@ int kvm_get_max_memslots(void) return s->nr_slots; } =20 -bool kvm_memcrypt_enabled(void) -{ - if (kvm_state && kvm_state->htl) { - return true; - } - - return false; -} - -int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) -{ - HostTrustLimitation *htl =3D kvm_state->htl; - - if (htl) { - HostTrustLimitationClass *htlc =3D HOST_TRUST_LIMITATION_GET_CLASS= (htl); - - return htlc->encrypt_data(htl, ptr, len); - } - - return 1; -} - /* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { @@ -2194,8 +2169,6 @@ static int kvm_init(MachineState *ms) if (ret < 0) { goto err; } - - kvm_state->htl =3D ms->htl; } =20 ret =3D kvm_arch_init(ms, s); diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 82f118d2df..78b3eef117 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -104,16 +104,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 b6c0822fe3..e8d3b795a1 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 "exec/host-trust-limitation.h" =20 /* * We don't have a theoretically justifiable exact lower bound on the base @@ -201,10 +202,11 @@ static void pc_system_flash_map(PCMachineState *pcms, pc_isa_bios_init(rom_memory, flash_mem, size); =20 /* Encrypt the pflash boot ROM */ - if (kvm_memcrypt_enabled()) { + if (host_trust_limitation_enabled(MACHINE(pcms))) { 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); + ret =3D host_trust_limitation_encrypt(MACHINE(pcms), + flash_ptr, flash_size); if (ret) { error_report("failed to encrypt pflash rom"); exit(1); diff --git a/include/exec/host-trust-limitation.h b/include/exec/host-trust= -limitation.h index a19f12ae14..fc30ea3f78 100644 --- a/include/exec/host-trust-limitation.h +++ b/include/exec/host-trust-limitation.h @@ -14,6 +14,7 @@ #define QEMU_HOST_TRUST_LIMITATION_H =20 #include "qom/object.h" +#include "hw/boards.h" =20 #define TYPE_HOST_TRUST_LIMITATION "host-trust-limitation" #define HOST_TRUST_LIMITATION(obj) \ @@ -33,4 +34,39 @@ typedef struct HostTrustLimitationClass { int (*encrypt_data)(HostTrustLimitation *, uint8_t *, uint64_t); } HostTrustLimitationClass; =20 +/** + * host_trust_limitation_enabled - return whether guest memory is protected + * from hypervisor access (with memory + * encryption or otherwise) + * Returns: true guest memory is not directly accessible to qemu + * false guest memory is directly accessible to qemu + */ +static inline bool host_trust_limitation_enabled(MachineState *machine) +{ + return !!machine->htl; +} + +/** + * host_trust_limitation_encrypt: encrypt the memory range to make + * it guest accessible + * + * Return: 1 failed to encrypt the range + * 0 succesfully encrypted memory region + */ +static inline int host_trust_limitation_encrypt(MachineState *machine, + uint8_t *ptr, uint64_t len) +{ + HostTrustLimitation *htl =3D machine->htl; + + if (htl) { + HostTrustLimitationClass *htlc =3D HOST_TRUST_LIMITATION_GET_CLASS= (htl); + + if (htlc->encrypt_data) { + return htlc->encrypt_data(htl, ptr, len); + } + } + + return 1; +} + #endif /* QEMU_HOST_TRUST_LIMITATION_H */ diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index b4174d941c..c7b9739609 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -231,23 +231,6 @@ int kvm_destroy_vcpu(CPUState *cpu); */ 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); - - #ifdef NEED_CPU_H #include "cpu.h" =20 --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559811; cv=none; d=zohomail.com; s=zohoarc; b=MDsuYwrgRy3D3WWvnR9VPB7zycEECuQr/pXOuQ6XoqZ1nUiCk4vgoRthS8KqN7Y5Lw0Fm91n7Uecr0sczILpD/Gd43RpXBwdok9Zh01mhRX9jvNQIuV6yuyKI9lV17SHR8l5uEKjMwNJ1e6C1fKMr398/ptOFHZcuBUC1++emGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559811; 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=Q7tyPDaK6PiVWLcgX0UOh1Rg5N2hwO7b/83Sa+1yG1c=; b=NaGgpXWX1xhnAQVZgzLpR74p6bFeU5To6aN0+kI44m7TfeqxpqIIxbtGrbmTD6/HiwVxXU0w9VN/203ehp+MwbrVzcXY7c6ixc2YhnfzUVYl1hnNeWgzuqO6s3usspOqii06Y78e2VlKhoB5sJd+cD60/37ukGUtBn3BhwfjnNE= 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 1595559811143197.50664003632937; Thu, 23 Jul 2020 20:03:31 -0700 (PDT) Received: from localhost ([::1]:34442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynzd-0006m3-TS for importer@patchew.org; Thu, 23 Jul 2020 23:03:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuP-0007Mm-UH; Thu, 23 Jul 2020 22:58:05 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:41959 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuN-00061f-W3; Thu, 23 Jul 2020 22:58:05 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlw00Rzz9sTF; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559468; bh=xgmDQa3udk5W0XmmFTnrKQDvJ/BjSvIb0v09eBORE70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OGBTdOPiL8Nuu2cNvQr4R0hIaMZJWJVN7ZYOOU1+Jy0huQdGQy/w2e1zDJi8inGMI sfXsFRM+wueL5uASQSTxss6FU3dO287ugy3GwG20FzTIJmZBhmgeHhy9l/aCGLs3To iO87zT9VzxIzMNoBplOdxlcOc+iAP26IC9fuwfF0= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 06/10] host trust limitation: Add Error ** to HostTrustLimitation::kvm_init Date: Fri, 24 Jul 2020 12:57:40 +1000 Message-Id: <20200724025744.69644-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Richard Henderson , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , David Gibson 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 --- accel/kvm/kvm-all.c | 4 +++- include/exec/host-trust-limitation.h | 2 +- target/i386/sev.c | 31 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 4b6402c12c..3f98c6be7c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2164,9 +2164,11 @@ static int kvm_init(MachineState *ms) if (ms->htl) { HostTrustLimitationClass *htlc =3D HOST_TRUST_LIMITATION_GET_CLASS(ms->htl); + Error *local_err =3D NULL; =20 - ret =3D htlc->kvm_init(ms->htl); + ret =3D htlc->kvm_init(ms->htl, &local_err); if (ret < 0) { + error_report_err(local_err); goto err; } } diff --git a/include/exec/host-trust-limitation.h b/include/exec/host-trust= -limitation.h index fc30ea3f78..d93b537280 100644 --- a/include/exec/host-trust-limitation.h +++ b/include/exec/host-trust-limitation.h @@ -30,7 +30,7 @@ typedef struct HostTrustLimitationClass { InterfaceClass parent; =20 - int (*kvm_init)(HostTrustLimitation *); + int (*kvm_init)(HostTrustLimitation *, Error **); int (*encrypt_data)(HostTrustLimitation *, uint8_t *, uint64_t); } HostTrustLimitationClass; =20 diff --git a/target/i386/sev.c b/target/i386/sev.c index 8e3c9dcc2c..0d06976da5 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -626,7 +626,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -static int sev_kvm_init(HostTrustLimitation *htl) +static int sev_kvm_init(HostTrustLimitation *htl, Error **errp) { SevGuestState *sev =3D SEV_GUEST(htl); char *devname; @@ -648,14 +648,14 @@ static int sev_kvm_init(HostTrustLimitation *htl) 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 @@ -664,20 +664,19 @@ static int sev_kvm_init(HostTrustLimitation *htl) 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; @@ -687,14 +686,14 @@ static int sev_kvm_init(HostTrustLimitation *htl) 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.26.2 From nobody Sun May 19 05:00:04 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=1595559838; cv=none; d=zohomail.com; s=zohoarc; b=DS/fwnFhoGceRIDs7vSp6AQ1f8om5DFPEL+JacwtXoX4EJPs8+4Ic+81IhFkzEYQ18093Kusz46Q12VRqcV4on3ImTibahiPBBh/35UE4OETg6haoZGUzd42wPwws0/M43+iR5zNAXDDa2rVaHKMgF5zkwbtMWDedBZQjkLQ6UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559838; 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=KzSRrvsURYAWCdOvnpcxSvbHoM0R+ZxPkvxR/vTSrSY=; b=mrs6PnLMRsapcbfWlcyK+wXOIK7y/ntNCp/hpgCMFxQWGbDTXQaYiPKDcsjtmb7PNjWY6y9NuyMWTjhX8/td3td0WpQncMmPviT70mbXzBC7LfeLId0QGKOKd7mM1dh8vOd8CryEJ0yTjdAbCzC3sumxRXenA9WyI0zOu18ecg8= 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 1595559838626407.47564761294507; Thu, 23 Jul 2020 20:03:58 -0700 (PDT) Received: from localhost ([::1]:35690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyo05-0007GR-FT for importer@patchew.org; Thu, 23 Jul 2020 23:03:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuQ-0007NB-5i; Thu, 23 Jul 2020 22:58:06 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:55205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuO-00061i-6F; Thu, 23 Jul 2020 22:58:05 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlw0lN1z9sTH; Fri, 24 Jul 2020 12:57:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559468; bh=Oy4RlJb/Bjycm/HhrLyUbyYuUJPIz3gMN+mQh6H8/u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n0zBs27t5hcUyQFkH4E/1ktWWBZ+c3ZmHt0tdrUktlpOzPYjZvwh6q2aO3c0+v1tK ur1QYvSNzrnjuElvIEy3qTA68pRjKgy7lEzRHqYhl1AHevAdpjaopdo5cs7FxslqeL At78BKwQczW28ygQEUul8Bsr9hU4sTErkSIFmxX0= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 07/10] spapr: Add PEF based host trust limitation Date: Fri, 24 Jul 2020 12:57:41 +1000 Message-Id: <20200724025744.69644-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , Ram Pai , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 host-trust-limitation machine 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 directly 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 host-trust-limitation=3Dpef0 Signed-off-by: David Gibson Acked-by: Ram Pai --- target/ppc/Makefile.objs | 2 +- target/ppc/pef.c | 83 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 target/ppc/pef.c diff --git a/target/ppc/Makefile.objs b/target/ppc/Makefile.objs index e8fa18ce13..ac93b9700e 100644 --- a/target/ppc/Makefile.objs +++ b/target/ppc/Makefile.objs @@ -6,7 +6,7 @@ obj-y +=3D machine.o mmu_helper.o mmu-hash32.o monitor.o ar= ch_dump.o obj-$(TARGET_PPC64) +=3D mmu-hash64.o mmu-book3s-v3.o compat.o obj-$(TARGET_PPC64) +=3D mmu-radix64.o endif -obj-$(CONFIG_KVM) +=3D kvm.o +obj-$(CONFIG_KVM) +=3D kvm.o pef.o obj-$(call lnot,$(CONFIG_KVM)) +=3D kvm-stub.o obj-y +=3D dfp_helper.o obj-y +=3D excp_helper.o diff --git a/target/ppc/pef.c b/target/ppc/pef.c new file mode 100644 index 0000000000..53a6af0347 --- /dev/null +++ b/target/ppc/pef.c @@ -0,0 +1,83 @@ +/* + * 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/host-trust-limitation.h" + +#define TYPE_PEF_GUEST "pef-guest" +#define PEF_GUEST(obj) \ + OBJECT_CHECK(PefGuestState, (obj), TYPE_PEF_GUEST) + +typedef struct PefGuestState PefGuestState; + +/** + * PefGuestState: + * + * The PefGuestState object is used for creating and managing a PEF + * guest. + * + * # $QEMU \ + * -object pef-guest,id=3Dpef0 \ + * -machine ...,host-trust-limitation=3Dpef0 + */ +struct PefGuestState { + Object parent_obj; +}; + +static int pef_kvm_init(HostTrustLimitation *gmpo, 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; +} + +static void pef_guest_class_init(ObjectClass *oc, void *data) +{ + HostTrustLimitationClass *gmpc =3D HOST_TRUST_LIMITATION_CLASS(oc); + + gmpc->kvm_init =3D pef_kvm_init; +} + +static const TypeInfo pef_guest_info =3D { + .parent =3D TYPE_OBJECT, + .name =3D TYPE_PEF_GUEST, + .instance_size =3D sizeof(PefGuestState), + .class_init =3D pef_guest_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOST_TRUST_LIMITATION }, + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void +pef_register_types(void) +{ + type_register_static(&pef_guest_info); +} + +type_init(pef_register_types); --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559880; cv=none; d=zohomail.com; s=zohoarc; b=lUNwQJVd8BgyerLBlgJy68p5V2OSDgA4ogWxXJHHvF+XWUR5hstdGPIkvVQ1DVCUtYpjlqgj6mQOaJvhy3BgtaJd7XwPpHsU/DpyfnNcGn8UW2R2MdKYATvz9KXOnshluEx9urH1NaDd937UC5YBpqHkmrry0XRtyduL0Q0v9sM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559880; 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=t8VVPNBwco2BQSwyriDFS8TzgIOSn8dreKbv/4DScAM=; b=KfSBbtDkFdOn034jyBkMc5wyiTxJ5apZpdrZEexGOBwDWJGyJXnUwzrRPqFgadtv0WkNKYXiMm+ARNPQ1d/2mTtU13y7fobR5Wfu6LocHm0GHJHZfBmk/gJg7/TTF8/DiEqHbCblrvgrlMj+FOTFD/tpryRFxj6OT+QuIINAqUU= 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 1595559880476269.1282552314992; Thu, 23 Jul 2020 20:04:40 -0700 (PDT) Received: from localhost ([::1]:38586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyo0j-0008QM-V5 for importer@patchew.org; Thu, 23 Jul 2020 23:04:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuR-0007Ra-Pp; Thu, 23 Jul 2020 22:58:07 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:42179 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuO-00061m-FB; Thu, 23 Jul 2020 22:58:07 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlw1T28z9sTK; Fri, 24 Jul 2020 12:57:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559468; bh=oUlu8u5TiukpYL5YY0i+HjSckV5d3NnHfXBN6cEFoNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YAM+uwL/E+M/lqPo6JwEV3OirVdPwoH0YUjmphFtXRnwwwmqxPNOtpZXt6UKp+3y2 kVvh0eEmXx8oPDzXuZjXDRfW1jIUhPJ/GeNmPPagmkoRSudKOBfc+1SUViCmyhbYOT k/e5svfcGURMKHpEqITtS1JU8RUB0oQRn4sjEifo= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 08/10] spapr: PEF: block migration Date: Fri, 24 Jul 2020 12:57:42 +1000 Message-Id: <20200724025744.69644-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 --- target/ppc/pef.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/ppc/pef.c b/target/ppc/pef.c index 53a6af0347..6a50efd580 100644 --- a/target/ppc/pef.c +++ b/target/ppc/pef.c @@ -36,6 +36,8 @@ struct PefGuestState { Object parent_obj; }; =20 +static Error *pef_mig_blocker; + static int pef_kvm_init(HostTrustLimitation *gmpo, Error **errp) { if (!kvm_check_extension(kvm_state, KVM_CAP_PPC_SECURE_GUEST)) { @@ -52,6 +54,10 @@ static int pef_kvm_init(HostTrustLimitation *gmpo, Error= **errp) } } =20 + /* add migration blocker */ + error_setg(&pef_mig_blocker, "PEF: Migration is not implemented"); + migrate_add_blocker(pef_mig_blocker, &error_abort); + return 0; } =20 --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559784; cv=none; d=zohomail.com; s=zohoarc; b=TTxEBKGi7LKA7HdCBMqVwCkMzOJU0sXQxFu3kMPcban57Wt7Zkiu448bO0NgfGE/YGX+xIdn7P23hM84ZfIMClAfOKFh5Cqm3kdOdECg0iNHAhr9gSpWq2771X8oxBnY+9PCUK1jkkXHb/hLPbqcd6Fx14EwhbF7LyzMBTFuK4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559784; 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=bp9Euu30mFCCaQrhI6QQEMcmFjfYukOaH+MQ3N04XkI=; b=UkvYEYr3+uWwkIWAFRu4s6ILFw0mhPu/cfkmsJ8lCF1lO8Zl2HuBM9TFnSpbWQRar+bfsA3Ox0Am13PjJCSsfIxQXeYezsdHEQKoW9kIZZaLUePr7zlGRH1uq/8WXIvlZEGIGg+MjRsMEXt+BHvwBr2KCd2OFIfpALxiaw6mhzc= 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 1595559784980170.91292380113634; Thu, 23 Jul 2020 20:03:04 -0700 (PDT) Received: from localhost ([::1]:60328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jynzD-0005os-RL for importer@patchew.org; Thu, 23 Jul 2020 23:03:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuR-0007R5-Hg; Thu, 23 Jul 2020 22:58:07 -0400 Received: from ozlabs.org ([203.11.71.1]:35611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuO-00061q-RK; Thu, 23 Jul 2020 22:58:07 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlw2CWGz9sTR; Fri, 24 Jul 2020 12:57:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559468; bh=S0SoxbGMoHrm4nxccN2FECIGesfK+qvLP0XWEh7c1/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fsw/pl4ETCgZRnUMnWoMvWLxPNqj0W0aX0j5oGnZxcSxibV0Nu6T7QHmXii5ZyiXd gwcHi8Gw1/rAeCHONaMwMfFat3Kj/nmQxVEVXbnIC3hWgbdO8VZRrKsxwbkkzFOO7K fD6aaWybXL1omHTDqn5vbbG9IPhzpY7SOwrln0IM= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 09/10] host trust limitation: Alter virtio default properties for protected guests Date: Fri, 24 Jul 2020 12:57:43 +1000 Message-Id: <20200724025744.69644-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/23 22:57:48 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 host trust limitation 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: Halil Pasic --- hw/core/machine.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index b599b0ba65..2a723bf07b 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -28,6 +28,8 @@ #include "hw/mem/nvdimm.h" #include "migration/vmstate.h" #include "exec/host-trust-limitation.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-pci.h" =20 GlobalProperty hw_compat_5_0[] =3D { { "virtio-balloon-device", "page-poison", "false" }, @@ -1161,6 +1163,15 @@ 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 disabling legacy virtio support + * for virtio pci devices + */ + object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", "on"= ); + object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform", "= on"); } =20 machine_class->init(machine); --=20 2.26.2 From nobody Sun May 19 05:00:04 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=1595559906; cv=none; d=zohomail.com; s=zohoarc; b=Sj9MgLrrvKZXs6zVT06iIZO52nNYRpgj0x1X624Kz9upIRUgXJVLlYnRb+2kt76E411YyvETaPsRBp6ZO/73Y4gCVeRO5geIheUgL8FWP/uTSwDSdiTcrywAwCQc1VhYZUGAGMU8eA03ZTDvQ2r/uzT6wZW2XvlKaXxjnpw2lrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595559906; 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=t0wLHZZ7jj5Shv5jwV7jtcbjzid5Y14bszfRpcAMFVE=; b=fRM37OK6Chw5L6cB/Y+FLqIYYz0CV9CjS6IwojxTQbnqNlo9yVKcRPxqR0QYnEbmIWTQOindkXCGOyEOdCEbgasnrgrvpJGoSGx3EUjfKnyRpKO7oZksFo6CXrdVppqU0O8kA2VRB8NLXRXGGO4sf+lgXboosCC3zJmNbh/5UPY= 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 159555990671677.1607910052054; Thu, 23 Jul 2020 20:05:06 -0700 (PDT) Received: from localhost ([::1]:40704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jyo1B-0000qw-IP for importer@patchew.org; Thu, 23 Jul 2020 23:05:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuR-0007QF-9y; Thu, 23 Jul 2020 22:58:07 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:36865 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jynuO-00061o-BI; Thu, 23 Jul 2020 22:58:06 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4BCYlw2nzSz9sTT; Fri, 24 Jul 2020 12:57:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1595559468; bh=/o46AHd29VbcsNq9WcZf6nE94CsdYc+R5nZVL/Rr/HI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pSuzO9oG4N0zQaZIvbeJU7FN70QP4ZKEEpvcOr/jb4KRvrGtL4GgERFkyKACeAnXN C3V2s+HwQakiko3lp4TBXkrCi7CoBZhihn8CuBdR0/9T1ELAjFSeGV7tcu2j5wPuxC 6hX7tzTwsR/GqgVUfC1xdRMGLpbwYxSnB6k/qEEE= From: David Gibson To: dgilbert@redhat.com, frankja@linux.ibm.com, pair@us.ibm.com, qemu-devel@nongnu.org, pbonzini@redhat.com, brijesh.singh@amd.com Subject: [for-5.2 v4 10/10] s390: Recognize host-trust-limitation option Date: Fri, 24 Jul 2020 12:57:44 +1000 Message-Id: <20200724025744.69644-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724025744.69644-1-david@gibson.dropbear.id.au> References: <20200724025744.69644-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-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -9 X-Spam_score: -1.0 X-Spam_bar: - X-Spam_report: (-1.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: Thomas Huth , Cornelia Huck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , ehabkost@redhat.com, kvm@vger.kernel.org, "Michael S. Tsirkin" , David Hildenbrand , mdroth@linux.vnet.ibm.com, pasic@linux.ibm.com, Christian Borntraeger , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , David Gibson 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 bythe "host-trust-limitation" 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 host-trust-limitation 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 host-trust-limitation is set, we will either create a guest capable of entering PV mode, or fail outright - If host-trust-limitation is not set, guest's 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 host-trust-limitation=3Dpv0 Signed-off-by: David Gibson --- hw/s390x/pv.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c index ab3a2482aa..4bf3b345b6 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/host-trust-limitation.h" #include "hw/s390x/ipl.h" #include "hw/s390x/pv.h" =20 @@ -111,3 +114,61 @@ 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" +#define S390_PV_GUEST(obj) \ + OBJECT_CHECK(S390PVGuestState, (obj), TYPE_S390_PV_GUEST) + +typedef struct S390PVGuestState S390PVGuestState; + +/** + * S390PVGuestState: + * + * The S390PVGuestState object is basically a dummy used to tell the + * host trust limitation system to use s390's PV mechanism. guest. + * + * # $QEMU \ + * -object s390-pv-guest,id=3Dpv0 \ + * -machine ...,host-trust-limitation=3Dpv0 + */ +struct S390PVGuestState { + Object parent_obj; +}; + +static int s390_pv_kvm_init(HostTrustLimitation *gmpo, Error **errp) +{ + if (!s390_has_feat(S390_FEAT_UNPACK)) { + error_setg(errp, + "CPU model does not support Protected Virtualization"); + return -1; + } + + return 0; +} + +static void s390_pv_guest_class_init(ObjectClass *oc, void *data) +{ + HostTrustLimitationClass *gmpc =3D HOST_TRUST_LIMITATION_CLASS(oc); + + gmpc->kvm_init =3D s390_pv_kvm_init; +} + +static const TypeInfo s390_pv_guest_info =3D { + .parent =3D TYPE_OBJECT, + .name =3D TYPE_S390_PV_GUEST, + .instance_size =3D sizeof(S390PVGuestState), + .class_init =3D s390_pv_guest_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOST_TRUST_LIMITATION }, + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void +s390_pv_register_types(void) +{ + type_register_static(&s390_pv_guest_info); +} + +type_init(s390_pv_register_types); --=20 2.26.2