From nobody Fri Apr 26 14:02:45 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=1590032696; cv=none; d=zohomail.com; s=zohoarc; b=V8zbJjIc0D7TNpfIOpy3hjrTVWS/pmb+n+9VE7BafQxpBVyp08APz1wSVPzha+5SnajgXj+OnKeCp/4fxFcnTTiAX7Vdt/5PzpRLzbZ0PAnKBNpBY7Vvs5Ldpp5/3LdjQjtTDmwyKzTyMoe5CIedXiu3Igcy8vYjM/sTUlB/7aQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032696; 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=nvct60rJX8Bxtf6oJcGpAdgUf4/yU7ZKWW4d0IdGdSU=; b=i/hr3CjRtSynFg9SJa2UeLinU99oWievasZFFyKOP/yj+SB9PVZTrNlXXh2Wu1vFTYqaX8kSugBCnmkW3f4AZuH0WhXhwQ4CYKNhF6DOm/1i3bfMhblAxmhjrboSpgW/z4xPMmZcA4+6DoYqtQtKvtCV9CHPk/S++sp9kaC3+wI= 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 1590032696704360.6870624676154; Wed, 20 May 2020 20:44:56 -0700 (PDT) Received: from localhost ([::1]:53052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbc8d-0005DY-E5 for importer@patchew.org; Wed, 20 May 2020 23:44:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7E-0002sp-O8; Wed, 20 May 2020 23:43:28 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:52953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7C-0003Tq-B2; Wed, 20 May 2020 23:43:28 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr3J0lz9sTK; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=b/ySedG6EPtDyWOrvJGyJDxoH9+NiT2I5+DDWgavmns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ItLRJ9KpIT0rlyJMStLLstOF0HYYFlpyWulI3c0dxJ8nha6BFpr+2qSz30UlBK9J3 O/S6/P0+q3njZeUxbKrDpW0b+h6cgXyUgbx4NAMpji/gA/ACJr0h4bEKlPFSf+YWDD ESlGHcW8/1tsLgO7w1bsHou7vzvq/Pg/TOcY9IJY= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 01/18] target/i386: sev: Remove unused QSevGuestInfoClass Date: Thu, 21 May 2020 13:42:47 +1000 Message-Id: <20200521034304.340040-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" This structure is nothing but an empty wrapper around the parent class, which by QOM conventions means we don't need it at all. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 1 - target/i386/sev_i386.h | 5 ----- 2 files changed, 6 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 51cdbe5496..2312510cf2 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -287,7 +287,6 @@ static const TypeInfo qsev_guest_info =3D { .name =3D TYPE_QSEV_GUEST_INFO, .instance_size =3D sizeof(QSevGuestInfo), .instance_finalize =3D qsev_guest_finalize, - .class_size =3D sizeof(QSevGuestInfoClass), .class_init =3D qsev_guest_class_init, .instance_init =3D qsev_guest_init, .interfaces =3D (InterfaceInfo[]) { diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index 8ada9d385d..4f193642ac 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -41,7 +41,6 @@ extern char *sev_get_launch_measurement(void); extern SevCapability *sev_get_capabilities(void); =20 typedef struct QSevGuestInfo QSevGuestInfo; -typedef struct QSevGuestInfoClass QSevGuestInfoClass; =20 /** * QSevGuestInfo: @@ -64,10 +63,6 @@ struct QSevGuestInfo { uint32_t reduced_phys_bits; }; =20 -struct QSevGuestInfoClass { - ObjectClass parent_class; -}; - struct SEVState { QSevGuestInfo *sev_info; uint8_t api_major; --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032944; cv=none; d=zohomail.com; s=zohoarc; b=A46gO403NaPOvGaBDezGSpnvINaZbGAtBaXrW76Dh2ZbsUo/uelJOH+D5xnNKd5ohP7wPxIBZ11BMeaBwoHzrSBEUjvLBH6+4UpehmAArWJzc7HWLwLbtqTjlYb/WanhZeB4oLMgv0780exS5fBomgPJAYNWAVDWgN1caYbAnJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032944; 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=zvlDay1fknUV5iuZ6MKGW+7vca/AIEbrFOTfpZfHslU=; b=h78VBJYPrMvworK1UXzuYpZotUmIrqwQ8Pjzafegt/aCb1Gclb+xpby8PduhZTVg9/oytBSdB0n+LzefPZunu+uYot7PM2bRz6kjdeI8TtcM4Ixagh6gNX1KNJJ76mChzl1vJHVH8wh6hK0cd+pq5IKf51oKifG492BS22cpiSc= 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 1590032944274423.16063120044885; Wed, 20 May 2020 20:49:04 -0700 (PDT) Received: from localhost ([::1]:39368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcCc-0003gC-Bk for importer@patchew.org; Wed, 20 May 2020 23:49:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7E-0002tH-T7; Wed, 20 May 2020 23:43:28 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:43713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7C-0003Tr-Bj; Wed, 20 May 2020 23:43:28 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr46D4z9sTM; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=qt1SRH9INoxyxgglr9QeYCX23oCC/+kJcGSaqPbv7SA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCodzQxQJSyz8Wn7Jsmit/eQ8OxfEseFlAV2jSTI7S+W2WGOXRr36p+AxAiQEHlwu X5x27w/rGSj0qLr4UbVu6tdvRNzBuzwVa1H0gsJ22ighBFfo5WY2K2d0RggbA4iDEC lBOJ6UsmnxWplajoHGFuNG/j0WOR+bEWYdrbJwUM= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 02/18] target/i386: sev: Move local structure definitions into .c file Date: Thu, 21 May 2020 13:42:48 +1000 Message-Id: <20200521034304.340040-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" Neither QSevGuestInfo nor SEVState (not to be confused with SevState) is used anywhere outside target/i386/sev.c, so they might as well live in there rather than in a (somewhat) exposed header. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 44 ++++++++++++++++++++++++++++++++++++++++++ target/i386/sev_i386.h | 44 ------------------------------------------ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 2312510cf2..53def5f41a 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -29,6 +29,50 @@ #include "trace.h" #include "migration/blocker.h" =20 +#define TYPE_QSEV_GUEST_INFO "sev-guest" +#define QSEV_GUEST_INFO(obj) \ + OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) + +typedef struct QSevGuestInfo QSevGuestInfo; + +/** + * QSevGuestInfo: + * + * The QSevGuestInfo object is used for creating a SEV guest. + * + * # $QEMU \ + * -object sev-guest,id=3Dsev0 \ + * -machine ...,memory-encryption=3Dsev0 + */ +struct QSevGuestInfo { + Object parent_obj; + + char *sev_device; + uint32_t policy; + uint32_t handle; + char *dh_cert_file; + char *session_file; + uint32_t cbitpos; + uint32_t reduced_phys_bits; +}; + +struct SEVState { + QSevGuestInfo *sev_info; + uint8_t api_major; + uint8_t api_minor; + uint8_t build_id; + uint32_t policy; + uint64_t me_mask; + uint32_t cbitpos; + uint32_t reduced_phys_bits; + uint32_t handle; + int sev_fd; + SevState state; + gchar *measurement; +}; + +typedef struct SEVState SEVState; + #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index 4f193642ac..8eb7de1bef 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -28,10 +28,6 @@ #define SEV_POLICY_DOMAIN 0x10 #define SEV_POLICY_SEV 0x20 =20 -#define TYPE_QSEV_GUEST_INFO "sev-guest" -#define QSEV_GUEST_INFO(obj) \ - OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) - extern bool sev_enabled(void); extern uint64_t sev_get_me_mask(void); extern SevInfo *sev_get_info(void); @@ -40,44 +36,4 @@ extern uint32_t sev_get_reduced_phys_bits(void); extern char *sev_get_launch_measurement(void); extern SevCapability *sev_get_capabilities(void); =20 -typedef struct QSevGuestInfo QSevGuestInfo; - -/** - * QSevGuestInfo: - * - * The QSevGuestInfo object is used for creating a SEV guest. - * - * # $QEMU \ - * -object sev-guest,id=3Dsev0 \ - * -machine ...,memory-encryption=3Dsev0 - */ -struct QSevGuestInfo { - Object parent_obj; - - char *sev_device; - uint32_t policy; - uint32_t handle; - char *dh_cert_file; - char *session_file; - uint32_t cbitpos; - uint32_t reduced_phys_bits; -}; - -struct SEVState { - QSevGuestInfo *sev_info; - uint8_t api_major; - uint8_t api_minor; - uint8_t build_id; - uint32_t policy; - uint64_t me_mask; - uint32_t cbitpos; - uint32_t reduced_phys_bits; - uint32_t handle; - int sev_fd; - SevState state; - gchar *measurement; -}; - -typedef struct SEVState SEVState; - #endif --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032812; cv=none; d=zohomail.com; s=zohoarc; b=lSNacljcu9Vg9hICk8JkeC6NwdvgWDmT72zHf6SPmvdOPTG23uK99MoZU6o+2xltnzK8uijujFnKpvR/2COs9c8tP4dEddPsUH51sS1NFsPhn8kPZUpYHTd8tCKTM58byq7+yS2teLYmEgT+geoMEaEvsXb6GiGOtWSwzwtFCfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032812; 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=0RxqLfoXjiyn0JvOPjV8pWh9gWzSYdHU/1Nq8okGMA8=; b=LhMVi5u0kKOzto3zF690zz6cpmWLkSPvN/F0vxATGJlytL0WDnTz5D3V0lK7Lh5/3QLWKp9QmfIxKHGem1pMbOTZ0FcGJc7FqiUsvlypT8fpHOCzkNKTNbcVH5GUwlw3JGf/K9nKKAVf2fhgiEWOQ0Z/3sUrmHpd+lLo0bkDHC8= 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 1590032812780151.76712845784357; Wed, 20 May 2020 20:46:52 -0700 (PDT) Received: from localhost ([::1]:60588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcAV-0008Q1-Fb for importer@patchew.org; Wed, 20 May 2020 23:46:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7E-0002ry-D6; Wed, 20 May 2020 23:43:28 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:55165 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 1jbc7C-0003Ts-FF; Wed, 20 May 2020 23:43:27 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr52Ckz9sTN; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=x4cTpeERhufcej3SjqDJ1ML9cL1niX2LXo7xACc0qi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eIWFqhrta5l5bLqtDrBdfgvlDjka8MFRqDAsW5kekdT0Lc9sAwvViTrNX0B48cvRP n+48jvSD9YMVSHoIkDJRIbI6oBx29HZZefsP0NZx6NC5qhD+Jbi9SslSttHmujDpSg O0bB+nFiCZi0/9C5iXKNk2OK+QmtZIi+tCqjX8WI= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 03/18] target/i386: sev: Rename QSevGuestInfo Date: Thu, 21 May 2020 13:42:49 +1000 Message-Id: <20200521034304.340040-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 this is a purely passive object which is just a container for information used elsewhere, hence the name. I'm going to change that though, so as a preliminary rename it to SevGuestState. That name risks confusion with both SEVState and SevState, but I'll be working on that in following patches. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 87 ++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 53def5f41a..b6ed719fb5 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -29,22 +29,23 @@ #include "trace.h" #include "migration/blocker.h" =20 -#define TYPE_QSEV_GUEST_INFO "sev-guest" -#define QSEV_GUEST_INFO(obj) \ - OBJECT_CHECK(QSevGuestInfo, (obj), TYPE_QSEV_GUEST_INFO) +#define TYPE_SEV_GUEST "sev-guest" +#define SEV_GUEST(obj) \ + OBJECT_CHECK(SevGuestState, (obj), TYPE_SEV_GUEST) =20 -typedef struct QSevGuestInfo QSevGuestInfo; +typedef struct SevGuestState SevGuestState; =20 /** - * QSevGuestInfo: + * SevGuestState: * - * The QSevGuestInfo object is used for creating a SEV guest. + * The SevGuestState object is used for creating and managing a SEV + * guest. * * # $QEMU \ * -object sev-guest,id=3Dsev0 \ * -machine ...,memory-encryption=3Dsev0 */ -struct QSevGuestInfo { +struct SevGuestState { Object parent_obj; =20 char *sev_device; @@ -57,7 +58,7 @@ struct QSevGuestInfo { }; =20 struct SEVState { - QSevGuestInfo *sev_info; + SevGuestState *sev_info; uint8_t api_major; uint8_t api_minor; uint8_t build_id; @@ -235,82 +236,82 @@ static struct RAMBlockNotifier sev_ram_notifier =3D { }; =20 static void -qsev_guest_finalize(Object *obj) +sev_guest_finalize(Object *obj) { } =20 static char * -qsev_guest_get_session_file(Object *obj, Error **errp) +sev_guest_get_session_file(Object *obj, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 return s->session_file ? g_strdup(s->session_file) : NULL; } =20 static void -qsev_guest_set_session_file(Object *obj, const char *value, Error **errp) +sev_guest_set_session_file(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 s->session_file =3D g_strdup(value); } =20 static char * -qsev_guest_get_dh_cert_file(Object *obj, Error **errp) +sev_guest_get_dh_cert_file(Object *obj, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 return g_strdup(s->dh_cert_file); } =20 static void -qsev_guest_set_dh_cert_file(Object *obj, const char *value, Error **errp) +sev_guest_set_dh_cert_file(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *s =3D QSEV_GUEST_INFO(obj); + SevGuestState *s =3D SEV_GUEST(obj); =20 s->dh_cert_file =3D g_strdup(value); } =20 static char * -qsev_guest_get_sev_device(Object *obj, Error **errp) +sev_guest_get_sev_device(Object *obj, Error **errp) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 return g_strdup(sev->sev_device); } =20 static void -qsev_guest_set_sev_device(Object *obj, const char *value, Error **errp) +sev_guest_set_sev_device(Object *obj, const char *value, Error **errp) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 sev->sev_device =3D g_strdup(value); } =20 static void -qsev_guest_class_init(ObjectClass *oc, void *data) +sev_guest_class_init(ObjectClass *oc, void *data) { object_class_property_add_str(oc, "sev-device", - qsev_guest_get_sev_device, - qsev_guest_set_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", - qsev_guest_get_dh_cert_file, - qsev_guest_set_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", - qsev_guest_get_session_file, - qsev_guest_set_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)"); } =20 static void -qsev_guest_init(Object *obj) +sev_guest_instance_init(Object *obj) { - QSevGuestInfo *sev =3D QSEV_GUEST_INFO(obj); + SevGuestState *sev =3D SEV_GUEST(obj); =20 sev->sev_device =3D g_strdup(DEFAULT_SEV_DEVICE); sev->policy =3D DEFAULT_GUEST_POLICY; @@ -326,32 +327,32 @@ qsev_guest_init(Object *obj) } =20 /* sev guest info */ -static const TypeInfo qsev_guest_info =3D { +static const TypeInfo sev_guest_info =3D { .parent =3D TYPE_OBJECT, - .name =3D TYPE_QSEV_GUEST_INFO, - .instance_size =3D sizeof(QSevGuestInfo), - .instance_finalize =3D qsev_guest_finalize, - .class_init =3D qsev_guest_class_init, - .instance_init =3D qsev_guest_init, + .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 }, { } } }; =20 -static QSevGuestInfo * +static SevGuestState * lookup_sev_guest_info(const char *id) { Object *obj; - QSevGuestInfo *info; + SevGuestState *info; =20 obj =3D object_resolve_path_component(object_get_objects_root(), id); if (!obj) { return NULL; } =20 - info =3D (QSevGuestInfo *) - object_dynamic_cast(obj, TYPE_QSEV_GUEST_INFO); + info =3D (SevGuestState *) + object_dynamic_cast(obj, TYPE_SEV_GUEST); if (!info) { return NULL; } @@ -510,7 +511,7 @@ sev_launch_start(SEVState *s) gsize sz; int ret =3D 1; int fw_error, rc; - QSevGuestInfo *sev =3D s->sev_info; + SevGuestState *sev =3D s->sev_info; struct kvm_sev_launch_start *start; guchar *session =3D NULL, *dh_cert =3D NULL; =20 @@ -696,7 +697,7 @@ sev_guest_init(const char *id) s->sev_info =3D lookup_sev_guest_info(id); if (!s->sev_info) { error_report("%s: '%s' is not a valid '%s' object", - __func__, id, TYPE_QSEV_GUEST_INFO); + __func__, id, TYPE_SEV_GUEST); goto err; } =20 @@ -786,7 +787,7 @@ sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t l= en) static void sev_register_types(void) { - type_register_static(&qsev_guest_info); + type_register_static(&sev_guest_info); } =20 type_init(sev_register_types); --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032810; cv=none; d=zohomail.com; s=zohoarc; b=isn4BKNbvhO1av6HVE38ytZhpMg0aEzRg78hpIxdxUKSzCIo/F3aGHuB9/d2ojFydUsGtRsyo8xYbV52sP4IoPpBd9khV8VEogjSPewYOq4P1Jx7WtZZceZmxtuWeWtEJI8KiX/aXI0DGU+cOqDvISFLAc08B7IT9qhep19KM7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032810; 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=i2CWgZVd9NV/3OEV+1jPG2aM5lL/SThr7+8QPptMm28=; b=jh5iiofNzi0B4SfTAUVfhun3jlx7Wv/M0kcnM5bd9RMPFqomKOWehUdkLiAEjbXgjnW0pUBm8Ry4QgdHbj8lOK0LFTAsZqrMUbxKsRzGJsgBNENIV28hPO2EVHjMiNSngKjgOjhMynjPLviO5oYwce5+P+o6/jp5glZga77k7G0= 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 1590032810117582.5889458148404; Wed, 20 May 2020 20:46:50 -0700 (PDT) Received: from localhost ([::1]:60408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcAS-0008Lg-R7 for importer@patchew.org; Wed, 20 May 2020 23:46:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7E-0002rw-C7; Wed, 20 May 2020 23:43:28 -0400 Received: from ozlabs.org ([203.11.71.1]:52143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7C-0003Tt-8k; Wed, 20 May 2020 23:43:27 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr5r2Xz9sTR; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=ScMyXOHqlJVI3Y1EURo7w0uOiUqN2ce3gWfMmvqVEj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knDP1MsAdW5AS+OF9SvJzk38ZzvnXZIHwzpMsGnn8Mrgpb6ONJSXQfLIS64r1ZVfa QvFYVtVJGCVB9dMtxu5MO26mlnrNnEFfWVbJcr/uKzQ63eOjnl1kjP39kERMJwnx+Z Ekprw22f8M9nnt/GzDOBfRKYi0e5tJU89B6rP4is= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 04/18] target/i386: sev: Embed SEVState in SevGuestState Date: Thu, 21 May 2020 13:42:50 +1000 Message-Id: <20200521034304.340040-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 SevGuestState contains only configuration information. For runtime state another non-QOM struct SEVState is allocated separately. Simplify things by instead embedding the SEVState structure in SevGuestState. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 54 +++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b6ed719fb5..b4ab9720d6 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -35,6 +35,22 @@ =20 typedef struct SevGuestState SevGuestState; =20 +struct SEVState { + uint8_t api_major; + uint8_t api_minor; + uint8_t build_id; + uint32_t policy; + uint64_t me_mask; + uint32_t cbitpos; + uint32_t reduced_phys_bits; + uint32_t handle; + int sev_fd; + SevState state; + gchar *measurement; +}; + +typedef struct SEVState SEVState; + /** * SevGuestState: * @@ -48,6 +64,7 @@ typedef struct SevGuestState SevGuestState; struct SevGuestState { Object parent_obj; =20 + /* configuration parameters */ char *sev_device; uint32_t policy; uint32_t handle; @@ -55,25 +72,11 @@ struct SevGuestState { char *session_file; uint32_t cbitpos; uint32_t reduced_phys_bits; -}; =20 -struct SEVState { - SevGuestState *sev_info; - uint8_t api_major; - uint8_t api_minor; - uint8_t build_id; - uint32_t policy; - uint64_t me_mask; - uint32_t cbitpos; - uint32_t reduced_phys_bits; - uint32_t handle; - int sev_fd; - SevState state; - gchar *measurement; + /* runtime state */ + SEVState state; }; =20 -typedef struct SEVState SEVState; - #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 @@ -506,12 +509,12 @@ sev_read_file_base64(const char *filename, guchar **d= ata, gsize *len) } =20 static int -sev_launch_start(SEVState *s) +sev_launch_start(SevGuestState *sev) { + SEVState *s =3D &sev->state; gsize sz; int ret =3D 1; int fw_error, rc; - SevGuestState *sev =3D s->sev_info; struct kvm_sev_launch_start *start; guchar *session =3D NULL, *dh_cert =3D NULL; =20 @@ -686,6 +689,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) void * sev_guest_init(const char *id) { + SevGuestState *sev; SEVState *s; char *devname; int ret, fw_error; @@ -693,27 +697,27 @@ sev_guest_init(const char *id) uint32_t host_cbitpos; struct sev_user_data_status status =3D {}; =20 - sev_state =3D s =3D g_new0(SEVState, 1); - s->sev_info =3D lookup_sev_guest_info(id); - if (!s->sev_info) { + 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; } =20 + sev_state =3D s =3D &sev->state; s->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; =20 - s->cbitpos =3D object_property_get_int(OBJECT(s->sev_info), "cbitpos",= NULL); + s->cbitpos =3D object_property_get_int(OBJECT(sev), "cbitpos", NULL); if (host_cbitpos !=3D s->cbitpos) { error_report("%s: cbitpos check failed, host '%d' requested '%d'", __func__, host_cbitpos, s->cbitpos); goto err; } =20 - s->reduced_phys_bits =3D object_property_get_int(OBJECT(s->sev_info), + s->reduced_phys_bits =3D object_property_get_int(OBJECT(sev), "reduced-phys-bits", NULL); if (s->reduced_phys_bits < 1) { error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," @@ -723,7 +727,7 @@ sev_guest_init(const char *id) =20 s->me_mask =3D ~(1UL << s->cbitpos); =20 - devname =3D object_property_get_str(OBJECT(s->sev_info), "sev-device",= NULL); + devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); s->sev_fd =3D open(devname, O_RDWR); if (s->sev_fd < 0) { error_report("%s: Failed to open %s '%s'", __func__, @@ -754,7 +758,7 @@ sev_guest_init(const char *id) goto err; } =20 - ret =3D sev_launch_start(s); + ret =3D sev_launch_start(sev); if (ret) { error_report("%s: failed to create encryption context", __func__); goto err; --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032946; cv=none; d=zohomail.com; s=zohoarc; b=GB3qP5V+aTXeLqt3DynaUNN+3alLbdpmCxLXUIFPKJOefIWadcteWLfQv5uvJho0A/uTccAYiGP7sGna+7xhji61xPMigrLCIkwmpxWjPy3CvvFCuxtyN8eRIT/bVwrxPrPdW/DOXdXilSLUs+UyLqpq6jsMTn1ZwdChFsjHE4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032946; 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=SF0P2AMJ2SqOC4cEH00cHPa/eWXWKnstXn3vNywAHqI=; b=ECBBqxo+VCS8YRjdvAEk/Wacyz81sq9WgGWiY62JFxVFeMid66yX02q0LFyaIHlGmudGAWVnVFTsF6CBjcUbVV7xP5bMT4xhTkkzAQsLMxWrM2npBqVHUXg1aTF371YzjNTEGYaTa+vYqCLgqXADkSz5tHViOHxufRWGrq4eoM8= 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 1590032946088607.2994981331833; Wed, 20 May 2020 20:49:06 -0700 (PDT) Received: from localhost ([::1]:39382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcCe-0003gq-Uc for importer@patchew.org; Wed, 20 May 2020 23:49:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7I-00035F-Vd; Wed, 20 May 2020 23:43:32 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:39117 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 1jbc7H-0003Wm-LT; Wed, 20 May 2020 23:43:32 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns0cvwz9sTX; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=C43QFCKoZDphxvW0PDFBBWurI4a1MCtoUEnKjEOco+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5iP8+NoLBxGZ111BnCGl/P3nljGiKcZUTK4v6IFw6MSwgT5WLtdwAXFOohDuXXxi 0EL+Uk+8mKXytTPPFfuFcOr4aGNsQMbjZCQr9evUhrBc/IWEE5K39bIAmy4o0/+B6m kUyDEvTDIO/flfEClgnL7u1kO+WeK9CkaRr5q38Y= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 05/18] target/i386: sev: Partial cleanup to sev_state global Date: Thu, 21 May 2020 13:42:51 +1000 Message-Id: <20200521034304.340040-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 SEV code uses a pretty ugly global to access its internal state. Now that SEVState is embedded in SevGuestState, we can avoid accessing it via the global in some cases. In the remaining cases use a new global referencing the containing SevGuestState which will simplify some future transformations. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 92 ++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index b4ab9720d6..9e8ab7b056 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -80,7 +80,7 @@ struct SevGuestState { #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" =20 -static SEVState *sev_state; +static SevGuestState *sev_guest; static Error *sev_mig_blocker; =20 static const char *const sev_fw_errlist[] =3D { @@ -159,21 +159,21 @@ fw_error_to_str(int code) } =20 static bool -sev_check_state(SevState state) +sev_check_state(const SevGuestState *sev, SevState state) { - assert(sev_state); - return sev_state->state =3D=3D state ? true : false; + assert(sev); + return sev->state.state =3D=3D state ? true : false; } =20 static void -sev_set_guest_state(SevState new_state) +sev_set_guest_state(SevGuestState *sev, SevState new_state) { assert(new_state < SEV_STATE__MAX); - assert(sev_state); + assert(sev); =20 - trace_kvm_sev_change_state(SevState_str(sev_state->state), + trace_kvm_sev_change_state(SevState_str(sev->state.state), SevState_str(new_state)); - sev_state->state =3D new_state; + sev->state.state =3D new_state; } =20 static void @@ -366,25 +366,25 @@ lookup_sev_guest_info(const char *id) bool sev_enabled(void) { - return sev_state ? true : false; + return !!sev_guest; } =20 uint64_t sev_get_me_mask(void) { - return sev_state ? sev_state->me_mask : ~0; + return sev_guest ? sev_guest->state.me_mask : ~0; } =20 uint32_t sev_get_cbit_position(void) { - return sev_state ? sev_state->cbitpos : 0; + return sev_guest ? sev_guest->state.cbitpos : 0; } =20 uint32_t sev_get_reduced_phys_bits(void) { - return sev_state ? sev_state->reduced_phys_bits : 0; + return sev_guest ? sev_guest->state.reduced_phys_bits : 0; } =20 SevInfo * @@ -393,15 +393,15 @@ sev_get_info(void) SevInfo *info; =20 info =3D g_new0(SevInfo, 1); - info->enabled =3D sev_state ? true : false; + info->enabled =3D sev_enabled(); =20 if (info->enabled) { - info->api_major =3D sev_state->api_major; - info->api_minor =3D sev_state->api_minor; - info->build_id =3D sev_state->build_id; - info->policy =3D sev_state->policy; - info->state =3D sev_state->state; - info->handle =3D sev_state->handle; + info->api_major =3D sev_guest->state.api_major; + info->api_minor =3D sev_guest->state.api_minor; + info->build_id =3D sev_guest->state.build_id; + info->policy =3D sev_guest->state.policy; + info->state =3D sev_guest->state.state; + info->handle =3D sev_guest->state.handle; } =20 return info; @@ -550,7 +550,7 @@ sev_launch_start(SevGuestState *sev) =20 object_property_set_int(OBJECT(sev), start->handle, "handle", &error_abort); - sev_set_guest_state(SEV_STATE_LAUNCH_UPDATE); + sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); s->handle =3D start->handle; s->policy =3D start->policy; ret =3D 0; @@ -563,7 +563,7 @@ out: } =20 static int -sev_launch_update_data(uint8_t *addr, uint64_t len) +sev_launch_update_data(SevGuestState *sev, uint8_t *addr, uint64_t len) { int ret, fw_error; struct kvm_sev_launch_update_data update; @@ -575,7 +575,7 @@ sev_launch_update_data(uint8_t *addr, uint64_t len) update.uaddr =3D (__u64)(unsigned long)addr; update.len =3D len; trace_kvm_sev_launch_update_data(addr, len); - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, &update, &fw_error); if (ret) { error_report("%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", @@ -588,19 +588,20 @@ sev_launch_update_data(uint8_t *addr, uint64_t len) static void sev_launch_get_measure(Notifier *notifier, void *unused) { + SevGuestState *sev =3D sev_guest; int ret, error; guchar *data; - SEVState *s =3D sev_state; + SEVState *s =3D &sev->state; struct kvm_sev_launch_measure *measurement; =20 - if (!sev_check_state(SEV_STATE_LAUNCH_UPDATE)) { + if (!sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { return; } =20 measurement =3D g_new0(struct kvm_sev_launch_measure, 1); =20 /* query the measurement blob length */ - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (!measurement->len) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -612,7 +613,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement->uaddr =3D (unsigned long)data; =20 /* get the measurement blob */ - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (ret) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -620,7 +621,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) goto free_data; } =20 - sev_set_guest_state(SEV_STATE_LAUNCH_SECRET); + sev_set_guest_state(sev, SEV_STATE_LAUNCH_SECRET); =20 /* encode the measurement value and emit the event */ s->measurement =3D g_base64_encode(data, measurement->len); @@ -635,9 +636,9 @@ free_measurement: char * sev_get_launch_measurement(void) { - if (sev_state && - sev_state->state >=3D SEV_STATE_LAUNCH_SECRET) { - return g_strdup(sev_state->measurement); + if (sev_guest && + sev_guest->state.state >=3D SEV_STATE_LAUNCH_SECRET) { + return g_strdup(sev_guest->state.measurement); } =20 return NULL; @@ -648,20 +649,21 @@ static Notifier sev_machine_done_notify =3D { }; =20 static void -sev_launch_finish(SEVState *s) +sev_launch_finish(SevGuestState *sev) { + SEVState *s =3D &sev->state; int ret, error; Error *local_err =3D NULL; =20 trace_kvm_sev_launch_finish(); - ret =3D sev_ioctl(sev_state->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); + ret =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); if (ret) { error_report("%s: LAUNCH_FINISH ret=3D%d fw_error=3D%d '%s'", __func__, ret, error, fw_error_to_str(error)); exit(1); } =20 - sev_set_guest_state(SEV_STATE_RUNNING); + sev_set_guest_state(sev, SEV_STATE_RUNNING); =20 /* add migration blocker */ error_setg(&sev_mig_blocker, @@ -677,11 +679,11 @@ sev_launch_finish(SEVState *s) static void sev_vm_state_change(void *opaque, int running, RunState state) { - SEVState *s =3D opaque; + SevGuestState *sev =3D opaque; =20 if (running) { - if (!sev_check_state(SEV_STATE_RUNNING)) { - sev_launch_finish(s); + if (!sev_check_state(sev, SEV_STATE_RUNNING)) { + sev_launch_finish(sev); } } } @@ -704,7 +706,8 @@ sev_guest_init(const char *id) goto err; } =20 - sev_state =3D s =3D &sev->state; + sev_guest =3D sev; + s =3D &sev->state; s->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); @@ -766,23 +769,24 @@ sev_guest_init(const char *id) =20 ram_block_notifier_add(&sev_ram_notifier); qemu_add_machine_init_done_notifier(&sev_machine_done_notify); - qemu_add_vm_change_state_handler(sev_vm_state_change, s); + qemu_add_vm_change_state_handler(sev_vm_state_change, sev); =20 - return s; + return sev; err: - g_free(sev_state); - sev_state =3D NULL; + sev_guest =3D NULL; return NULL; } =20 int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) { - assert(handle); + SevGuestState *sev =3D handle; + + assert(sev); =20 /* if SEV is in update state then encrypt the data else do nothing */ - if (sev_check_state(SEV_STATE_LAUNCH_UPDATE)) { - return sev_launch_update_data(ptr, len); + if (sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { + return sev_launch_update_data(sev, ptr, len); } =20 return 0; --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033059; cv=none; d=zohomail.com; s=zohoarc; b=UYSiDXRil/oF1sBj7HvpgcZzeBMyT4LHOYBWOThtlRJ4ap4YKwlZRaLU3jYS61coqrkiS9n/sNaJU1lPHOu7/VUwzD3W53JQdbFhT8uglesQ/JPDpd3LmLMOtgq7h1D2/OhZEx8ItB7ca3f9vuK4FQX+1zsT1ij9lSd8V/M+1Xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033059; 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=WZJJa0StrUdpVnhjwMmfZeoD5z2fGM18jLKQMp3FIc4=; b=LvOCK/QlwlAPGyuIBfF+nDzjZUvhkQgT4wxlj91jQY0xbis7Rolqcx/uUGRn4ejBjVMjcHyol4df7Z4JO312Hhg+L6a5M12z7m4fPj9Ft3dZc10mgUZ+OKYJGr75QZMw1MJxTBcZTT/c1f4iQRxfcNz6bqzsELRL6g0AwMaO61s= 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 1590033059056587.7947939948824; Wed, 20 May 2020 20:50:59 -0700 (PDT) Received: from localhost ([::1]:46488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcES-0007QV-Sn for importer@patchew.org; Wed, 20 May 2020 23:50:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-00036r-L3; Wed, 20 May 2020 23:43:33 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:59379 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 1jbc7I-0003Wl-7q; Wed, 20 May 2020 23:43:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnr6g2mz9sTS; Thu, 21 May 2020 13:43:12 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032592; bh=M+eXnJW1btziN4G5uNLQz37je7bEajAkkFSb+aa7K24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AENwXPgM3o2mrp3sS7zPYmSBF/8anerUXVNQPs5uVXFDn8EyJJhXEqi4VkHd0KqOv 6m/sMcCkNAFxRrKBOxheict5WSLXJh58UG4TXmTVRMmenMr3W73InyJ07jwtHgT0rR Sgt/OYUwSTN4V/5UmjcoBEudbhL31PQrN1kahEdM= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 06/18] target/i386: sev: Remove redundant cbitpos and reduced_phys_bits fields Date: Thu, 21 May 2020 13:42:52 +1000 Message-Id: <20200521034304.340040-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 SEVState structure has cbitpos and reduced_phys_bits fields which are simply copied from the SevGuestState structure and never changed. Now that SEVState is embedded in SevGuestState we can just access the original copy directly. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 9e8ab7b056..d25af37136 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -41,8 +41,6 @@ struct SEVState { uint8_t build_id; uint32_t policy; uint64_t me_mask; - uint32_t cbitpos; - uint32_t reduced_phys_bits; uint32_t handle; int sev_fd; SevState state; @@ -378,13 +376,13 @@ sev_get_me_mask(void) uint32_t sev_get_cbit_position(void) { - return sev_guest ? sev_guest->state.cbitpos : 0; + return sev_guest ? sev_guest->cbitpos : 0; } =20 uint32_t sev_get_reduced_phys_bits(void) { - return sev_guest ? sev_guest->state.reduced_phys_bits : 0; + return sev_guest ? sev_guest->reduced_phys_bits : 0; } =20 SevInfo * @@ -713,22 +711,19 @@ sev_guest_init(const char *id) host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; =20 - s->cbitpos =3D object_property_get_int(OBJECT(sev), "cbitpos", NULL); - if (host_cbitpos !=3D s->cbitpos) { + if (host_cbitpos !=3D sev->cbitpos) { error_report("%s: cbitpos check failed, host '%d' requested '%d'", - __func__, host_cbitpos, s->cbitpos); + __func__, host_cbitpos, sev->cbitpos); goto err; } =20 - s->reduced_phys_bits =3D object_property_get_int(OBJECT(sev), - "reduced-phys-bits", NULL); - if (s->reduced_phys_bits < 1) { + if (sev->reduced_phys_bits < 1) { error_report("%s: reduced_phys_bits check failed, it should be >= =3D1," - " requested '%d'", __func__, s->reduced_phys_bits); + " requested '%d'", __func__, sev->reduced_phys_bits); goto err; } =20 - s->me_mask =3D ~(1UL << s->cbitpos); + s->me_mask =3D ~(1UL << sev->cbitpos); =20 devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); s->sev_fd =3D open(devname, O_RDWR); --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032781; cv=none; d=zohomail.com; s=zohoarc; b=VCJeO1FZphOoLR6nrgPQFYCDlfKV6/g3aiVHuvMT/MZy4VnA9sDLQ1PstJj7WpbQySeQAmRVqq+0FdL1hOjwqewCZq97GqIYiSwdUUH0YIY2NASkdXB6e4jGy37BDIsBpfh0fG27c329F/czgij0kcnru1bt2Rp+4zndmGdcaMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032781; 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=pLbdiVVcrdEkLt3X5wCBzkYiI1jJvRx/Y3olPH7WB0g=; b=cSXzieW+3TPCwcaDm4cPHRtBh/j3a85yNdM1nhh9LUbMRrTRJVRQsWkXNIRNh093gJHFInUuRrJmL27gAQ1PtV+ZHGWIMCKPrMhjt8b6lLefbu/KZJuc0imS1U9dJ7s81gqOfK+inUB6O4WN6U3+CqK3crlSmeX4s4NVEMqRNm8= 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 1590032781136125.46759470183065; Wed, 20 May 2020 20:46:21 -0700 (PDT) Received: from localhost ([::1]:59366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbc9z-0007w0-VD for importer@patchew.org; Wed, 20 May 2020 23:46:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7I-000341-Ii; Wed, 20 May 2020 23:43:32 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:36107) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7H-0003Wg-Gb; Wed, 20 May 2020 23:43:32 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns27szz9sTg; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=bf5Cd9xw2ZTvT2sR3eQKUWyajZbzGCNDJL88uOSTsxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FSbn203Rcy19lTP/Uh82Cy4AGqsnatY7iLqO1Uu8XUf+L14nn+MXwj7IzuNAJs8GW i3uJUx/g84fqSywOCIEW/9jbHGEcBeg8ccTaDTqgmW8US17FJnd6H0XVtsN3Zf5t6z HxpqCsnypeqML8EXHQMmBW/KfTN4Ivk8ZV66ZFVU= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 07/18] target/i386: sev: Remove redundant policy field Date: Thu, 21 May 2020 13:42:53 +1000 Message-Id: <20200521034304.340040-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" SEVState::policy is set from the final value of the policy field in the parameter structure for the KVM_SEV_LAUNCH_START ioctl(). But, AFAICT that ioctl() won't ever change it from the original supplied value which comes from SevGuestState::policy. So, remove this field and just use SevGuestState::policy directly. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index d25af37136..4b261beaa7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -39,7 +39,6 @@ struct SEVState { uint8_t api_major; uint8_t api_minor; uint8_t build_id; - uint32_t policy; uint64_t me_mask; uint32_t handle; int sev_fd; @@ -397,7 +396,7 @@ sev_get_info(void) info->api_major =3D sev_guest->state.api_major; info->api_minor =3D sev_guest->state.api_minor; info->build_id =3D sev_guest->state.build_id; - info->policy =3D sev_guest->state.policy; + info->policy =3D sev_guest->policy; info->state =3D sev_guest->state.state; info->handle =3D sev_guest->state.handle; } @@ -520,8 +519,7 @@ sev_launch_start(SevGuestState *sev) =20 start->handle =3D object_property_get_int(OBJECT(sev), "handle", &error_abort); - start->policy =3D object_property_get_int(OBJECT(sev), "policy", - &error_abort); + start->policy =3D sev->policy; if (sev->session_file) { if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) { goto out; @@ -550,7 +548,6 @@ sev_launch_start(SevGuestState *sev) &error_abort); sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); s->handle =3D start->handle; - s->policy =3D start->policy; ret =3D 0; =20 out: --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033163; cv=none; d=zohomail.com; s=zohoarc; b=VZb5ikD7L1DSINe0g5C1FOzrKhg+yKz1Dg+PM8ks0NdPVoMBvWzzlidDIx6E1bTE6c3iCizNtHx+Ves1Ond4RWFujme4/wb191DG5DCuSO8/E3ob/NyZeiEhyhQCRGWlvsHLHzbA90YpYkMZdvNdS4JVYbPTma9NR7JASDq8NI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033163; 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=+QgPlPT/Jsud11pV37c4IdJ8a1iHwti6nFKVFZ6DIZI=; b=TSRJJa4mla9/vHhWKy2HbUQ30nCB7x2xaA2oWx2TVW55BpcXBfsaw91jk6uwDkoBF/KTtwJTeAcX2NgcUrU3CzUg2Xdk09ROHXMRV7mfMf6E/2LVit4ZAcptOCet4947aZ+kHPuE550SVeCLryG/7IVYrQd4ZuaisB8KIJu8/Kc= 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 1590033163796491.24011145026884; Wed, 20 May 2020 20:52:43 -0700 (PDT) Received: from localhost ([::1]:54402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcGA-0002Co-Jp for importer@patchew.org; Wed, 20 May 2020 23:52:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-000362-AA; Wed, 20 May 2020 23:43:33 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:48147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7H-0003Wh-PI; Wed, 20 May 2020 23:43:32 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns1NXdz9sTT; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=d27Ffc+UM25I6jMKKixH/o4N+rS/wECOugs7Ml/AULE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NyyiKIgRv8Sa41xtepCYVJluBW+AhLBvINnbN87OdeeyM3yp4/39vXYbVeNhQymmh w9h5HFnBxqtFma/Dgw4COf4HOWHWO0y7kNHNCWwxUKEF0NL/sue/3Cjot/cnJ24R8g 0hCZAyi+kNc4RRVPYdd1yxxpob8XWUeWxID41pRw= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 08/18] target/i386: sev: Remove redundant handle field Date: Thu, 21 May 2020 13:42:54 +1000 Message-Id: <20200521034304.340040-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 user can explicitly specify a handle via the "handle" property wired to SevGuestState::handle. That gets passed to the KVM_SEV_LAUNCH_START ioctl() which may update it, the final value being copied back to both SevGuestState::handle and SEVState::handle. AFAICT, nothing will be looking SEVState::handle before it and SevGuestState::handle have been updated from the ioctl(). So, remove the field and just use SevGuestState::handle directly. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 4b261beaa7..24e2dea9b8 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -40,7 +40,6 @@ struct SEVState { uint8_t api_minor; uint8_t build_id; uint64_t me_mask; - uint32_t handle; int sev_fd; SevState state; gchar *measurement; @@ -64,13 +63,13 @@ struct SevGuestState { /* configuration parameters */ char *sev_device; uint32_t policy; - uint32_t handle; char *dh_cert_file; char *session_file; uint32_t cbitpos; uint32_t reduced_phys_bits; =20 /* runtime state */ + uint32_t handle; SEVState state; }; =20 @@ -398,7 +397,7 @@ sev_get_info(void) info->build_id =3D sev_guest->state.build_id; info->policy =3D sev_guest->policy; info->state =3D sev_guest->state.state; - info->handle =3D sev_guest->state.handle; + info->handle =3D sev_guest->handle; } =20 return info; @@ -517,8 +516,7 @@ sev_launch_start(SevGuestState *sev) =20 start =3D g_new0(struct kvm_sev_launch_start, 1); =20 - start->handle =3D object_property_get_int(OBJECT(sev), "handle", - &error_abort); + start->handle =3D sev->handle; start->policy =3D sev->policy; if (sev->session_file) { if (sev_read_file_base64(sev->session_file, &session, &sz) < 0) { @@ -544,10 +542,8 @@ sev_launch_start(SevGuestState *sev) goto out; } =20 - object_property_set_int(OBJECT(sev), start->handle, "handle", - &error_abort); sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); - s->handle =3D start->handle; + sev->handle =3D start->handle; ret =3D 0; =20 out: --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033223; cv=none; d=zohomail.com; s=zohoarc; b=SJomikEKWfDXS+vxQ7FprqcVku7YIQixTQC1HIsSyv+aOzinElZCaT4/IjnfhUSJtfarZ+GJYs95MWkStVSLICafaezR/NIQ6Dk5px0dWBhoKQqMCRY+lOal29cZFz6mna+nq2b960Im8olCJBcaboWUBCi65Lm6Wy0N7vbYXP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033223; 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=Duy06dbBYgWvwGx5oAf1h+7NVwOB8oGSVnx0l3WJVbw=; b=NfkCxcrIqBrP42OoBDvy5RNAtjjqmU0CfxYXh/w2ygWKqzrA5Z9rVA9sAGJxZ1vWJjde18fzDFHm78G16e/eYbV4g7GRU7HgtNnMyx+oJHGKyWEU3DZF760F4KoAkeiUW7ihwtrZdzQz1KLlKQZ5iGAF59lu+Rx8FxfX70Fxoz8= 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 1590033223456443.05527901554706; Wed, 20 May 2020 20:53:43 -0700 (PDT) Received: from localhost ([::1]:57812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcH8-00040i-89 for importer@patchew.org; Wed, 20 May 2020 23:53:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-000374-MY; Wed, 20 May 2020 23:43:33 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:39693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7I-0003Wv-5P; Wed, 20 May 2020 23:43:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns2x39z9sTd; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=+6wORPXba/FHMuWdDdlY8yg4w9EvwoE0aoktBT1heY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XTpAIsFI7q+M5+ao82y+YJsAqkvYesCjXshW160mqdR1noSQAf7IMLGYDSZQPBD6Z xT7K8payzDPaDc0Auz7il9JClDi1XZPZyCegrjY980TiN9CUjCLZTOm4Dl9fvwemF8 vgVTxAohZs8Ftss9pVJon67zZUybVuFXaz4tAIs0= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 09/18] target/i386: sev: Unify SEVState and SevGuestState Date: Thu, 21 May 2020 13:42:55 +1000 Message-Id: <20200521034304.340040-10-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" SEVState is contained with SevGuestState. We've now fixed redundancies and name conflicts, so there's no real point to the nested structure. Just move all the fields of SEVState into SevGuestState. This eliminates the SEVState structure, which as a bonus removes the confusion with the SevState enum. Signed-off-by: David Gibson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- target/i386/sev.c | 79 ++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 24e2dea9b8..d273174ad3 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -35,18 +35,6 @@ =20 typedef struct SevGuestState SevGuestState; =20 -struct SEVState { - uint8_t api_major; - uint8_t api_minor; - uint8_t build_id; - uint64_t me_mask; - int sev_fd; - SevState state; - gchar *measurement; -}; - -typedef struct SEVState SEVState; - /** * SevGuestState: * @@ -70,7 +58,13 @@ struct SevGuestState { =20 /* runtime state */ uint32_t handle; - SEVState state; + uint8_t api_major; + uint8_t api_minor; + uint8_t build_id; + uint64_t me_mask; + int sev_fd; + SevState state; + gchar *measurement; }; =20 #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ @@ -158,7 +152,7 @@ static bool sev_check_state(const SevGuestState *sev, SevState state) { assert(sev); - return sev->state.state =3D=3D state ? true : false; + return sev->state =3D=3D state ? true : false; } =20 static void @@ -167,9 +161,9 @@ sev_set_guest_state(SevGuestState *sev, SevState new_st= ate) assert(new_state < SEV_STATE__MAX); assert(sev); =20 - trace_kvm_sev_change_state(SevState_str(sev->state.state), + trace_kvm_sev_change_state(SevState_str(sev->state), SevState_str(new_state)); - sev->state.state =3D new_state; + sev->state =3D new_state; } =20 static void @@ -368,7 +362,7 @@ sev_enabled(void) uint64_t sev_get_me_mask(void) { - return sev_guest ? sev_guest->state.me_mask : ~0; + return sev_guest ? sev_guest->me_mask : ~0; } =20 uint32_t @@ -392,11 +386,11 @@ sev_get_info(void) info->enabled =3D sev_enabled(); =20 if (info->enabled) { - info->api_major =3D sev_guest->state.api_major; - info->api_minor =3D sev_guest->state.api_minor; - info->build_id =3D sev_guest->state.build_id; + info->api_major =3D sev_guest->api_major; + info->api_minor =3D sev_guest->api_minor; + info->build_id =3D sev_guest->build_id; info->policy =3D sev_guest->policy; - info->state =3D sev_guest->state.state; + info->state =3D sev_guest->state; info->handle =3D sev_guest->handle; } =20 @@ -507,7 +501,6 @@ sev_read_file_base64(const char *filename, guchar **dat= a, gsize *len) static int sev_launch_start(SevGuestState *sev) { - SEVState *s =3D &sev->state; gsize sz; int ret =3D 1; int fw_error, rc; @@ -535,7 +528,7 @@ sev_launch_start(SevGuestState *sev) } =20 trace_kvm_sev_launch_start(start->policy, session, dh_cert); - rc =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error); + rc =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_START, start, &fw_error); if (rc < 0) { error_report("%s: LAUNCH_START ret=3D%d fw_error=3D%d '%s'", __func__, ret, fw_error, fw_error_to_str(fw_error)); @@ -566,7 +559,7 @@ sev_launch_update_data(SevGuestState *sev, uint8_t *add= r, uint64_t len) update.uaddr =3D (__u64)(unsigned long)addr; update.len =3D len; trace_kvm_sev_launch_update_data(addr, len); - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, &update, &fw_error); if (ret) { error_report("%s: LAUNCH_UPDATE ret=3D%d fw_error=3D%d '%s'", @@ -582,7 +575,6 @@ sev_launch_get_measure(Notifier *notifier, void *unused) SevGuestState *sev =3D sev_guest; int ret, error; guchar *data; - SEVState *s =3D &sev->state; struct kvm_sev_launch_measure *measurement; =20 if (!sev_check_state(sev, SEV_STATE_LAUNCH_UPDATE)) { @@ -592,7 +584,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement =3D g_new0(struct kvm_sev_launch_measure, 1); =20 /* query the measurement blob length */ - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (!measurement->len) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -604,7 +596,7 @@ sev_launch_get_measure(Notifier *notifier, void *unused) measurement->uaddr =3D (unsigned long)data; =20 /* get the measurement blob */ - ret =3D sev_ioctl(sev->state.sev_fd, KVM_SEV_LAUNCH_MEASURE, + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_MEASURE, measurement, &error); if (ret) { error_report("%s: LAUNCH_MEASURE ret=3D%d fw_error=3D%d '%s'", @@ -615,8 +607,8 @@ sev_launch_get_measure(Notifier *notifier, void *unused) sev_set_guest_state(sev, SEV_STATE_LAUNCH_SECRET); =20 /* encode the measurement value and emit the event */ - s->measurement =3D g_base64_encode(data, measurement->len); - trace_kvm_sev_launch_measurement(s->measurement); + sev->measurement =3D g_base64_encode(data, measurement->len); + trace_kvm_sev_launch_measurement(sev->measurement); =20 free_data: g_free(data); @@ -628,8 +620,8 @@ char * sev_get_launch_measurement(void) { if (sev_guest && - sev_guest->state.state >=3D SEV_STATE_LAUNCH_SECRET) { - return g_strdup(sev_guest->state.measurement); + sev_guest->state >=3D SEV_STATE_LAUNCH_SECRET) { + return g_strdup(sev_guest->measurement); } =20 return NULL; @@ -642,12 +634,11 @@ static Notifier sev_machine_done_notify =3D { static void sev_launch_finish(SevGuestState *sev) { - SEVState *s =3D &sev->state; int ret, error; Error *local_err =3D NULL; =20 trace_kvm_sev_launch_finish(); - ret =3D sev_ioctl(s->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); + ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_FINISH, 0, &error); if (ret) { error_report("%s: LAUNCH_FINISH ret=3D%d fw_error=3D%d '%s'", __func__, ret, error, fw_error_to_str(error)); @@ -683,7 +674,6 @@ void * sev_guest_init(const char *id) { SevGuestState *sev; - SEVState *s; char *devname; int ret, fw_error; uint32_t ebx; @@ -698,8 +688,7 @@ sev_guest_init(const char *id) } =20 sev_guest =3D sev; - s =3D &sev->state; - s->state =3D SEV_STATE_UNINIT; + sev->state =3D SEV_STATE_UNINIT; =20 host_cpuid(0x8000001F, 0, NULL, &ebx, NULL, NULL); host_cbitpos =3D ebx & 0x3f; @@ -716,20 +705,20 @@ sev_guest_init(const char *id) goto err; } =20 - s->me_mask =3D ~(1UL << sev->cbitpos); + sev->me_mask =3D ~(1UL << sev->cbitpos); =20 devname =3D object_property_get_str(OBJECT(sev), "sev-device", NULL); - s->sev_fd =3D open(devname, O_RDWR); - if (s->sev_fd < 0) { + 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 (s->sev_fd < 0) { + if (sev->sev_fd < 0) { goto err; } =20 - ret =3D sev_platform_ioctl(s->sev_fd, SEV_PLATFORM_STATUS, &status, + 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 " @@ -737,12 +726,12 @@ sev_guest_init(const char *id) fw_error_to_str(fw_error)); goto err; } - s->build_id =3D status.build; - s->api_major =3D status.api_major; - s->api_minor =3D status.api_minor; + sev->build_id =3D status.build; + sev->api_major =3D status.api_major; + sev->api_minor =3D status.api_minor; =20 trace_kvm_sev_init(); - ret =3D sev_ioctl(s->sev_fd, KVM_SEV_INIT, NULL, &fw_error); + 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)); --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033149; cv=none; d=zohomail.com; s=zohoarc; b=Pkeh75vkf6DVHoq5JFp4KMRy9yG0NaV2uUv2Tw00qt+U7NHzqm6ckTN/EmojjtlgTgL/RrcvSJV8ifz+Ugdxzo1M11tKortoZq+pvKSodQfTDHTA+sZ2CoBsXHTtNt8KGAcByVDz0GM8tzI/CkLaU53U1YtKWmC931L/lcgYqSA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033149; 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=/F0C5qoty3ImGGJpPoQ4K8WzOgg98jS2rfc0nfmKTP0=; b=ctEBESVLSivi22Y7s7t80zVCCxj3j5LPI8VNe+koB8XBGjAS7DlGRIH5IC3dMBBU8FkyiuhaGjJgO5denluKVOM1lqdcnQ6ToVkG43QQEUH0w76TH6wsUgONMCLzc94ueZMFxCb7YWMcYjwDPWOMluYVnxeEhmBtUlV60mTDMAI= 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 159003314963443.545290981172684; Wed, 20 May 2020 20:52:29 -0700 (PDT) Received: from localhost ([::1]:53136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcFw-0001fq-H0 for importer@patchew.org; Wed, 20 May 2020 23:52:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-00037J-RE; Wed, 20 May 2020 23:43:33 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:60887 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 1jbc7I-0003Wy-B1; Wed, 20 May 2020 23:43:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns3n23z9sTq; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=5KLDWlcKYyTYo3NQYirtMT0jjuuJjP++orsplm2jw/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GPSqg05BjZwbm6erLBBKafVtKtXNxUDW5hP+sPLfb1kphPhopYmRy2Gqgw3KSXVHu 4PAshUTPvB228yu4FvEzJy1BXcoAw2appFcR2QEIunhprXziTsV6ilJqLAjQHaXXNN Am+4HY9hn40sP0efS/rBIyJhmF7TRy+ZgfZ5Syfo= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 10/18] guest memory protection: Add guest memory protection interface Date: Thu, 21 May 2020 13:42:56 +1000 Message-Id: <20200521034304.340040-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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. This introduces a new GuestMemoryProtection QOM interface which we'll use to (partially) unify handling of these various mechanisms. Signed-off-by: David Gibson Tested-by: Thiago Jung Bauermann --- backends/Makefile.objs | 2 ++ backends/guest-memory-protection.c | 29 +++++++++++++++++++++ include/exec/guest-memory-protection.h | 36 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 backends/guest-memory-protection.c create mode 100644 include/exec/guest-memory-protection.h diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 28a847cd57..e4fb4f5280 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 guest-memory-protection.o diff --git a/backends/guest-memory-protection.c b/backends/guest-memory-pro= tection.c new file mode 100644 index 0000000000..7e538214f7 --- /dev/null +++ b/backends/guest-memory-protection.c @@ -0,0 +1,29 @@ +#/* + * QEMU Guest Memory Protection 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/guest-memory-protection.h" + +static const TypeInfo guest_memory_protection_info =3D { + .name =3D TYPE_GUEST_MEMORY_PROTECTION, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(GuestMemoryProtectionClass), +}; + +static void guest_memory_protection_register_types(void) +{ + type_register_static(&guest_memory_protection_info); +} + +type_init(guest_memory_protection_register_types) diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h new file mode 100644 index 0000000000..38e9b01667 --- /dev/null +++ b/include/exec/guest-memory-protection.h @@ -0,0 +1,36 @@ +#/* + * QEMU Guest Memory Protection 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_GUEST_MEMORY_PROTECTION_H +#define QEMU_GUEST_MEMORY_PROTECTION_H + +#include "qom/object.h" + +typedef struct GuestMemoryProtection GuestMemoryProtection; + +#define TYPE_GUEST_MEMORY_PROTECTION "guest-memory-protection" +#define GUEST_MEMORY_PROTECTION(obj) \ + INTERFACE_CHECK(GuestMemoryProtection, (obj), \ + TYPE_GUEST_MEMORY_PROTECTION) +#define GUEST_MEMORY_PROTECTION_CLASS(klass) \ + OBJECT_CLASS_CHECK(GuestMemoryProtectionClass, (klass), \ + TYPE_GUEST_MEMORY_PROTECTION) +#define GUEST_MEMORY_PROTECTION_GET_CLASS(obj) \ + OBJECT_GET_CLASS(GuestMemoryProtectionClass, (obj), \ + TYPE_GUEST_MEMORY_PROTECTION) + +typedef struct GuestMemoryProtectionClass { + InterfaceClass parent; +} GuestMemoryProtectionClass; + +#endif /* QEMU_GUEST_MEMORY_PROTECTION_H */ + --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590032929; cv=none; d=zohomail.com; s=zohoarc; b=Lyqk7YrmguB9eX2E+Oxq1ufRxNSuQh/LvIKVo9vjne4miaTqJJGCiBiA49Kld7ydTY90g7vMyByx7RIoWkS5M3JkVM3y0QIp/PWwO/4WZLpmE20gn3nqnCQ0+b4nJwgspYbT7f0+uCKESwErSgMp+T2i7XJIx2GB0FHt2ihDHaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590032929; 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=z5zvFBTl8GWGbHSCvPWpQ0wLZEUc9TLPERVbZU/UOpA=; b=e+O7sjqAYoYEcIkB68uzcnfeT28ydeZEzN388dHA/ClNm4Yix6LMXn9OO2RHtuuZhZd3kuBZP2pgkOAz0Uyg6VnbTleQ+Tw7UgH3R7LJsvT6kpzkstwXRcVTUhDT4DM/26qOywXAoY/rP3w+xHFmXYE5zqqWBfXUSmzZfMWudzo= 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 1590032929296265.8141709566818; Wed, 20 May 2020 20:48:49 -0700 (PDT) Received: from localhost ([::1]:38922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcCN-0003Py-OD for importer@patchew.org; Wed, 20 May 2020 23:48:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-00036l-KH; Wed, 20 May 2020 23:43:33 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:57969) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7I-0003X1-4U; Wed, 20 May 2020 23:43:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns4mdTz9sV0; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=U1JW5BDbXm0zdTvvoJUG5+cAZw/o4R4aBteoujOcyYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LH0pkriZQttTukg4x4P39LZVM9wx+SFxVNcmLoSgpTodbLbDl8797SJBYknTwwNQI 0LE1G2YvPXtlcGpCivrhkl/nRzxDs4FSvTPfZ0adx3s8pJQlSmaUifLRPCHQIF6tbA zMZclgtndQdlAXTNpTDXzhy0iW+qe5ue4uqBNw9M= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 11/18] guest memory protection: Handle memory encrption via interface Date: Thu, 21 May 2020 13:42:57 +1000 Message-Id: <20200521034304.340040-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 guest memory protection, use a QOM method on that interface, rather than a bare function pointer for this. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- accel/kvm/kvm-all.c | 23 +++---- accel/kvm/sev-stub.c | 5 -- include/exec/guest-memory-protection.h | 2 + include/sysemu/sev.h | 6 +- target/i386/sev.c | 84 ++++++++++++++------------ 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d06cc04079..40997de38c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -45,6 +45,7 @@ #include "qapi/qapi-types-common.h" #include "qapi/qapi-visit-common.h" #include "sysemu/reset.h" +#include "exec/guest-memory-protection.h" =20 #include "hw/boards.h" =20 @@ -119,8 +120,7 @@ struct KVMState QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus; =20 /* memory encryption */ - void *memcrypt_handle; - int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len); + GuestMemoryProtection *guest_memory_protection; =20 /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; @@ -172,7 +172,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->guest_memory_protection) { return true; } =20 @@ -181,10 +181,13 @@ 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); + GuestMemoryProtection *gmpo =3D kvm_state->guest_memory_protection; + + if (gmpo) { + GuestMemoryProtectionClass *gmpc =3D + GUEST_MEMORY_PROTECTION_GET_CLASS(gmpo); + + return gmpc->encrypt_data(gmpo, ptr, len); } =20 return 1; @@ -2101,13 +2104,11 @@ 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) { + kvm_state->guest_memory_protection =3D sev_guest_init(ms->memory_e= ncryption); + if (!kvm_state->guest_memory_protection) { 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..4a5cc5569e 100644 --- a/accel/kvm/sev-stub.c +++ b/accel/kvm/sev-stub.c @@ -15,11 +15,6 @@ #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) { return NULL; diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h index 38e9b01667..eb712a5804 100644 --- a/include/exec/guest-memory-protection.h +++ b/include/exec/guest-memory-protection.h @@ -30,6 +30,8 @@ typedef struct GuestMemoryProtection GuestMemoryProtectio= n; =20 typedef struct GuestMemoryProtectionClass { InterfaceClass parent; + + int (*encrypt_data)(GuestMemoryProtection *, uint8_t *, uint64_t); } GuestMemoryProtectionClass; =20 #endif /* QEMU_GUEST_MEMORY_PROTECTION_H */ diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 98c1ec8d38..7735a7942e 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -16,6 +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); +typedef struct GuestMemoryProtection GuestMemoryProtection; + +GuestMemoryProtection *sev_guest_init(const char *id); + #endif diff --git a/target/i386/sev.c b/target/i386/sev.c index d273174ad3..986c2fee51 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/guest-memory-protection.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,20 +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) { @@ -670,7 +637,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -void * +GuestMemoryProtection * sev_guest_init(const char *id) { SevGuestState *sev; @@ -748,16 +715,16 @@ 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 GUEST_MEMORY_PROTECTION(sev); err: sev_guest =3D NULL; return NULL; } =20 -int -sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) +static int +sev_encrypt_data(GuestMemoryProtection *opaque, uint8_t *ptr, uint64_t len) { - SevGuestState *sev =3D handle; + SevGuestState *sev =3D SEV_GUEST(opaque); =20 assert(sev); =20 @@ -769,6 +736,45 @@ sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t = len) return 0; } =20 +static void +sev_guest_class_init(ObjectClass *oc, void *data) +{ + GuestMemoryProtectionClass *gmpc =3D GUEST_MEMORY_PROTECTION_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)"); + + gmpc->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_GUEST_MEMORY_PROTECTION }, + { TYPE_USER_CREATABLE }, + { } + } +}; + static void sev_register_types(void) { --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033052; cv=none; d=zohomail.com; s=zohoarc; b=KikLMqr1sOpavolrJI9PkEza1SdlEql3v82m2ZS5XY9Ru4N3jNFhpT7yut0SDYb+kwSevsPibrKRQC2U827pDSp5Q7ktYj2FhNyfziu3ZvxBq+UJ1zj9UhOAr1POwckC4vYozxzuBEFcbEIAqWAE+4X5p+8WDCQnYN3QZdQFCUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033052; 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=xYdEOMEy+7qDxZszomsqcpWi1CUEwmqlyg7x8QX0j/0=; b=C7Kdh96VU7eCmwQtenU8PhtOIeapSVeoGPfVMb8lCqIeo8wcGbWPB872jXfDLkA6TDtBMzR7pX7SutbURVZN9rZY9AUjWbqp4RnCsijmFwHt0hfKGrXoLTVGPalbBsW/OyAumiuI3ECeD+gfomHcf3pqIoP3ydgjEH8+8yZ1s5o= 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 1590033052362108.01739137850814; Wed, 20 May 2020 20:50:52 -0700 (PDT) Received: from localhost ([::1]:45996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcEN-0007DE-56 for importer@patchew.org; Wed, 20 May 2020 23:50:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7J-00037e-SK; Wed, 20 May 2020 23:43:33 -0400 Received: from ozlabs.org ([203.11.71.1]:47609) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7I-0003X6-D6; Wed, 20 May 2020 23:43:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns5ftgz9sV2; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=gQ7WBzFCWsSO8Y6ZBoDXD7CE89Jjg6PXDsNnEC8gJ/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n0ZFujptmNQqtbScYQR4NUz+GHU4Vsgmyl8ih2NxLksU8mYVfT4boyRqjAwNl3Xmi awB/JgMXVbR+xvGfa/QWWx0we5QVVFToVhV6hotfIpLip9UKr6WoROxF7EVDs4/+3N 09EIlfDem8HP41lnmEC3dVhyeuDNQAREPYoJITC8= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 12/18] guest memory protection: Perform KVM init via interface Date: Thu, 21 May 2020 13:42:58 +1000 Message-Id: <20200521034304.340040-13-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" machine option is notionally generic, but in fact is only used for AMD SEV setups. Make another step towards it being actually generic, but having using the GuestMemoryProtection QOM interface to dispatch the initial setup, rather than directly calling sev_guest_init() from kvm_init(). Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- accel/kvm/kvm-all.c | 18 ++++++++++--- include/exec/guest-memory-protection.h | 1 + target/i386/sev.c | 37 ++++---------------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 40997de38c..5cf1a397e3 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -39,7 +39,6 @@ #include "qemu/main-loop.h" #include "trace.h" #include "hw/irq.h" -#include "sysemu/sev.h" #include "sysemu/balloon.h" #include "qapi/visitor.h" #include "qapi/qapi-types-common.h" @@ -2104,8 +2103,21 @@ static int kvm_init(MachineState *ms) * encryption context. */ if (ms->memory_encryption) { - kvm_state->guest_memory_protection =3D sev_guest_init(ms->memory_e= ncryption); - if (!kvm_state->guest_memory_protection) { + Object *obj =3D object_resolve_path_component(object_get_objects_r= oot(), + ms->memory_encryption); + + if (object_dynamic_cast(obj, TYPE_GUEST_MEMORY_PROTECTION)) { + GuestMemoryProtection *gmpo =3D GUEST_MEMORY_PROTECTION(obj); + GuestMemoryProtectionClass *gmpc =3D + GUEST_MEMORY_PROTECTION_GET_CLASS(gmpo); + + ret =3D gmpc->kvm_init(gmpo); + if (ret < 0) { + goto err; + } + + kvm_state->guest_memory_protection =3D gmpo; + } else { ret =3D -1; goto err; } diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h index eb712a5804..3707b96515 100644 --- a/include/exec/guest-memory-protection.h +++ b/include/exec/guest-memory-protection.h @@ -31,6 +31,7 @@ typedef struct GuestMemoryProtection GuestMemoryProtectio= n; typedef struct GuestMemoryProtectionClass { InterfaceClass parent; =20 + int (*kvm_init)(GuestMemoryProtection *); int (*encrypt_data)(GuestMemoryProtection *, uint8_t *, uint64_t); } GuestMemoryProtectionClass; =20 diff --git a/target/i386/sev.c b/target/i386/sev.c index 986c2fee51..60e9d8c735 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -300,26 +300,6 @@ sev_guest_instance_init(Object *obj) OBJ_PROP_FLAG_READWRITE); } =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) { @@ -637,23 +617,15 @@ sev_vm_state_change(void *opaque, int running, RunSta= te state) } } =20 -GuestMemoryProtection * -sev_guest_init(const char *id) +static int sev_kvm_init(GuestMemoryProtection *gmpo) { - SevGuestState *sev; + SevGuestState *sev =3D SEV_GUEST(gmpo); char *devname; int ret, fw_error; uint32_t ebx; uint32_t host_cbitpos; struct sev_user_data_status status =3D {}; =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 @@ -715,10 +687,10 @@ 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 GUEST_MEMORY_PROTECTION(sev); + return 0; err: sev_guest =3D NULL; - return NULL; + return -1; } =20 static int @@ -757,6 +729,7 @@ sev_guest_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "session-file", "guest owners session parameters (encoded with base64)"); =20 + gmpc->kvm_init =3D sev_kvm_init; gmpc->encrypt_data =3D sev_encrypt_data; } =20 --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033314; cv=none; d=zohomail.com; s=zohoarc; b=WgwzPUuibFzvmpVAoKLoPyEy3MfGij8K3zytnI3cjOxZkHjgf0N0PFLqa7zbsDNwBVJ1vDecCGr4gFyEpA0rv1xSfKE8b71IzjZxEFdeyBMT4WJm+7P5hVBaibVep2t7tEOP5qYR/8dIiIQVVwLur2lcLeMPTw7HXVj+3FahPus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033314; 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=45EvpQnSeudyc8leVOSTrrizTSIosc9UY3jC6AWNyAw=; b=Gbuy3Al0jm65thmesH1OQ/CjMIcLZXgwqjpzEKPp8fkC6jQZAAy9/IXW9j4RqBR9Byf5iqXjvDH8CC0+BjNlVm/vMeTH6j+5sIsF/w8EeHnhDtgWdBBAuHyPo2dpkuDe/mHnDG09IqbrKIJf+BiFdjnspKSeAuykCOnDSK3zXGA= 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 159003331451029.60789629372755; Wed, 20 May 2020 20:55:14 -0700 (PDT) Received: from localhost ([::1]:34378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcIa-0005wk-V9 for importer@patchew.org; Wed, 20 May 2020 23:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7M-0003Ep-BL; Wed, 20 May 2020 23:43:36 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:36719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7L-0003Y3-9k; Wed, 20 May 2020 23:43:35 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnt1Htpz9sVD; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032594; bh=xjUzdFv7PO3XoJd/FFXhNb/LuH61Tpp8Hb6PMqjq6AU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V12T8RrQNZRt1llpfwcvPHSPZKsvhbSvojMbSVrwspCyAcr3xF47JqQxghRvMtC2k DuycoeilI8yuvVdl0uSRz1AknrYYfEl27+9bNUY6SplBoKgZRM5DG93oS1pVpZIXDy 3jpasCwXyhZ51bNgL1Cw3lwkPAWCBPSWFFhWH3rc= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 13/18] guest memory protection: Move side effect out of machine_set_memory_encryption() Date: Thu, 21 May 2020 13:42:59 +1000 Message-Id: <20200521034304.340040-14-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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. But more important, 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 Tested-by: Thiago Jung Bauermann --- 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 bb3a7b18b1..e75f0b73d0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -429,14 +429,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) @@ -1129,6 +1121,15 @@ void machine_run_board_init(MachineState *machine) } } =20 + if (machine->memory_encryption) { + /* + * With guest memory protection, 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 Fri Apr 26 14:02:45 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=1590033247; cv=none; d=zohomail.com; s=zohoarc; b=kqAhIkR6MGBqh7rIv7JoU9k/aAaoFOgqBHh6kkWqPe4GXHfVe7SAnQXegK2YTVy3toLRXL2kwa/WidT+7tsC1x3OEULGFTdXEuJeEHzB7rVBcTJNXwk5FkmuaTebESA9w1oRDlAV+fR5NM2BGfhymQRwag/FGJRlyKCmuR/IDEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033247; 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=IiEFDWPzs1aiWuuQX+n4sqE/Lg3F6gbU4OtjkkVzzVg=; b=oHvvO2TsMzXkG4JG3a1BXruDkqFOIOHFv92xcxZp74IdhzZz5sdWlk6EhV15KGBBuRPwmEdEdvk5VL3YNj/oFXTqiOaxnmnRBZz0zdIAlAjM2NxqcPkVWczyuBVEENjgRkGZe4bvCTeZWsGCma2C1kCaeXLG0LB8Y/YCs8c3glA= 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 1590033247531904.3517649466518; Wed, 20 May 2020 20:54:07 -0700 (PDT) Received: from localhost ([::1]:59512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcHW-0004gl-8X for importer@patchew.org; Wed, 20 May 2020 23:54:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7L-0003Dj-UE; Wed, 20 May 2020 23:43:35 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:39577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7K-0003Xs-Pw; Wed, 20 May 2020 23:43:35 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFns6cHlz9sV6; Thu, 21 May 2020 13:43:13 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032593; bh=nm9xB2V5R/0lVmUDvJmT+YhtEegXvU4xCUn008zu1Y0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J76UE+l8Q9zlvDFZqaaUtPjqUeTJjmI3FTmuPrNug7bZHMqfkVrajRLwYSd2DBlOf ZP9UcfOGw4fCrdb/qBjBAR1yx6znI7e5nkptHh1km7squAu7TjCboLDJUA+0hlt3B8 +0IL111yZzXR9CWIWwNqwxJ+jZ/9kphyDwN3JQqw= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 14/18] guest memory protection: Rework the "memory-encryption" property Date: Thu, 21 May 2020 13:43:00 +1000 Message-Id: <20200521034304.340040-15-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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: -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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 "guest-memory-protection" 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 Tested-by: Thiago Jung Bauermann --- accel/kvm/kvm-all.c | 23 +++++++---------------- hw/core/machine.c | 41 ++++++++++++++++++++++++++++++++++++----- include/hw/boards.h | 4 +++- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 5cf1a397e3..3588adf1e1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2102,25 +2102,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_GUEST_MEMORY_PROTECTION)) { - GuestMemoryProtection *gmpo =3D GUEST_MEMORY_PROTECTION(obj); - GuestMemoryProtectionClass *gmpc =3D - GUEST_MEMORY_PROTECTION_GET_CLASS(gmpo); - - ret =3D gmpc->kvm_init(gmpo); - if (ret < 0) { - goto err; - } + if (ms->gmpo) { + GuestMemoryProtectionClass *gmpc =3D + GUEST_MEMORY_PROTECTION_GET_CLASS(ms->gmpo); =20 - kvm_state->guest_memory_protection =3D gmpo; - } else { - ret =3D -1; + ret =3D gmpc->kvm_init(ms->gmpo); + if (ret < 0) { goto err; } + + kvm_state->guest_memory_protection =3D ms->gmpo; } =20 ret =3D kvm_arch_init(ms, s); diff --git a/hw/core/machine.c b/hw/core/machine.c index e75f0b73d0..88d699bceb 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/guest-memory-protection.h" =20 GlobalProperty hw_compat_5_0[] =3D {}; const size_t hw_compat_5_0_len =3D G_N_ELEMENTS(hw_compat_5_0); @@ -419,16 +420,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->gmpo) { + return object_get_canonical_path_component(OBJECT(ms->gmpo)); + } + + return NULL; } =20 static void machine_set_memory_encryption(Object *obj, const char *value, Error **errp) { - MachineState *ms =3D MACHINE(obj); + Object *gmpo =3D + object_resolve_path_component(object_get_objects_root(), value); + + if (!gmpo) { + 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, gmpo, "guest-memory-protection", errp); +} + +static void machine_check_guest_memory_protection(const Object *obj, + const char *name, + Object *new_target, + Error **errp) +{ + /* + * So far the only constraint is that the target has the + * TYPE_GUEST_MEMORY_PROTECTION interface, and that's checked by + * the QOM core + */ } =20 static bool machine_get_nvdimm(Object *obj, Error **errp) @@ -849,6 +871,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, "guest-memory-protection", + TYPE_GUEST_MEMORY_PROTECTION, + offsetof(MachineState, gmpo), + machine_check_guest_memory_protection, + OBJ_PROP_LINK_STRONG); + object_class_property_set_description(oc, "guest-memory-protection", + "Set guest memory protection 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", @@ -1121,7 +1152,7 @@ void machine_run_board_init(MachineState *machine) } } =20 - if (machine->memory_encryption) { + if (machine->gmpo) { /* * With guest memory protection, 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 18815d9be2..19bf2c38fc 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -12,6 +12,8 @@ #include "qom/object.h" #include "hw/core/cpu.h" =20 +typedef struct GuestMemoryProtection GuestMemoryProtection; + #define TYPE_MACHINE_SUFFIX "-machine" =20 /* Machine class name that needs to be used for class-name-based machine @@ -277,7 +279,7 @@ struct MachineState { bool suppress_vmdesc; bool enforce_config_section; bool enable_graphics; - char *memory_encryption; + GuestMemoryProtection *gmpo; char *ram_memdev_id; /* * convenience alias to ram_memdev_id backend memory region --=20 2.26.2 From nobody Fri Apr 26 14:02:45 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=1590033380; cv=none; d=zohomail.com; s=zohoarc; b=dqJN+VJGxrUazL730LOSZTivkcVwUo5XzSaItW3FB1np0ehinJmilZbFETJFVJu6ebrG0n8+2ZIitH59kUZCNPr2dqbStcLR1UnFGytN0pEL/t0oaZBy+Hzy9kx8ko/driYb+4DiyccyEGxkSYXAxnP94UxmgCUvJkgFH8JdJog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033380; 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=CIGQdUzOEnitvRBv3uvdn2OmEol8cDGEubRopqc8IlE=; b=cO54xSVEgiP7HJRWs+MkHIQ4IQy+VMGAXoC5vIHW0+zOcPmoNIQl5f0arzPryJONiULW+vLuyR4fAfkf9OKvzsbuzlz1WEDF3sHEI1C1jx5LM9t/BEQvcMZrvRH1zZPI5baBoS1d07VWT8+CzlUV9KVlmI9cV5ch7MuPnmsZehk= 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 1590033380762728.42842564693; Wed, 20 May 2020 20:56:20 -0700 (PDT) Received: from localhost ([::1]:38662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcJf-0008Eh-GN for importer@patchew.org; Wed, 20 May 2020 23:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7N-0003Hd-9M; Wed, 20 May 2020 23:43:37 -0400 Received: from ozlabs.org ([203.11.71.1]:55805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7L-0003YF-UT; Wed, 20 May 2020 23:43:36 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnt32ghz9sV9; Thu, 21 May 2020 13:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032594; bh=RoNYjMOb+doFdnm8Dtz4iYwT7R/uzrYzxbbPkPOmRbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ft9gHqWiKKadAQA4Gb8zk/3KXA1XgTZaseI7ixaLwykCUNZpN3RPTnkJdqfvGCiXW xnTkR+pJMA+Dj81tRKBsuqZwBjWVeOmIeKsZ+Ibon0cnpHJkxhoyXj3ZFLBr12ez2u ll7AiGHm5wDAbOeyHTOEsMAw5thcTIsfcls9bqZ4= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 15/18] guest memory protection: Decouple kvm_memcrypt_*() helpers from KVM Date: Thu, 21 May 2020 13:43:01 +1000 Message-Id: <20200521034304.340040-16-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 guest-memory-protection.h, taking an explicit machine parameter. Signed-off-by: David Gibson Reviewed-by: Richard Henderson Tested-by: Thiago Jung Bauermann --- accel/kvm/kvm-all.c | 28 ------------------- accel/stubs/kvm-stub.c | 10 ------- hw/i386/pc_sysfw.c | 6 ++-- include/exec/guest-memory-protection.h | 38 ++++++++++++++++++++++++++ include/sysemu/kvm.h | 17 ------------ 5 files changed, 42 insertions(+), 57 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 3588adf1e1..1b10e94222 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -118,9 +118,6 @@ struct KVMState KVMMemoryListener memory_listener; QLIST_HEAD(, KVMParkedVcpu) kvm_parked_vcpus; =20 - /* memory encryption */ - GuestMemoryProtection *guest_memory_protection; - /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; struct KVMAs { @@ -169,29 +166,6 @@ int kvm_get_max_memslots(void) return s->nr_slots; } =20 -bool kvm_memcrypt_enabled(void) -{ - if (kvm_state && kvm_state->guest_memory_protection) { - return true; - } - - return false; -} - -int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) -{ - GuestMemoryProtection *gmpo =3D kvm_state->guest_memory_protection; - - if (gmpo) { - GuestMemoryProtectionClass *gmpc =3D - GUEST_MEMORY_PROTECTION_GET_CLASS(gmpo); - - return gmpc->encrypt_data(gmpo, ptr, len); - } - - return 1; -} - /* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { @@ -2110,8 +2084,6 @@ static int kvm_init(MachineState *ms) if (ret < 0) { goto err; } - - kvm_state->guest_memory_protection =3D ms->gmpo; } =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 b8d8ef59eb..9cef5f7780 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/guest-memory-protection.h" =20 /* * We don't have a theoretically justifiable exact lower bound on the base @@ -196,10 +197,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 (guest_memory_protection_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 guest_memory_protection_encrypt(MACHINE(pcms), + flash_ptr, flash_siz= e); if (ret) { error_report("failed to encrypt pflash rom"); exit(1); diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h index 3707b96515..7d959b4910 100644 --- a/include/exec/guest-memory-protection.h +++ b/include/exec/guest-memory-protection.h @@ -14,6 +14,7 @@ #define QEMU_GUEST_MEMORY_PROTECTION_H =20 #include "qom/object.h" +#include "hw/boards.h" =20 typedef struct GuestMemoryProtection GuestMemoryProtection; =20 @@ -35,5 +36,42 @@ typedef struct GuestMemoryProtectionClass { int (*encrypt_data)(GuestMemoryProtection *, uint8_t *, uint64_t); } GuestMemoryProtectionClass; =20 +/** + * guest_memory_protection_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 guest_memory_protection_enabled(MachineState *machine) +{ + return !!machine->gmpo; +} + +/** + * guest_memory_protection_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 guest_memory_protection_encrypt(MachineState *machine, + uint8_t *ptr, uint64_t l= en) +{ + GuestMemoryProtection *gmpo =3D machine->gmpo; + + if (gmpo) { + GuestMemoryProtectionClass *gmpc =3D + GUEST_MEMORY_PROTECTION_GET_CLASS(gmpo); + + if (gmpc->encrypt_data) { + return gmpc->encrypt_data(gmpo, ptr, len); + } + } + + return 1; +} + #endif /* QEMU_GUEST_MEMORY_PROTECTION_H */ =20 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 3b2250471c..cfc4cee995 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 Fri Apr 26 14:02:45 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=1590033341; cv=none; d=zohomail.com; s=zohoarc; b=ToGKhedxg/ZymBQ99/4hd/TdHlrQGFuvRmenj1RBZV3uuwvFlAzpXxHL37mpUvCzlHAe8/imeI3jhjbnKPW6GqBZPuujHK4eyITs7M7lZafESffeZhtzYn2y723vCZ+iUXqY3JseLUVqZVP2pbrnu/ECi/zA/4f5ZiYyc0fLJWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033341; 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=psSoeBtEmh44VJzComDreoO6bGBw00d5uh8OFOA+USU=; b=ZttlBfnjgm9rolsKQ8//fOTyGqXkiFD0qQIHf8xilomeItq3Uo1PmZX75yM7Ch0GdzKOXGTwh3OpZImT2cWLVjyyENiPuLaSrNmRBz8koAOQCcMn2EDAJUhJhtW6ZjMnv4UQR40g1Y0q9BDFaVrq0ZKn7BJACReVqp57DpCCEqY= 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 1590033341134860.4086547454907; Wed, 20 May 2020 20:55:41 -0700 (PDT) Received: from localhost ([::1]:36078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcJ1-0006nF-TZ for importer@patchew.org; Wed, 20 May 2020 23:55:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7N-0003Hz-FT; Wed, 20 May 2020 23:43:37 -0400 Received: from ozlabs.org ([203.11.71.1]:41131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7M-0003YT-8D; Wed, 20 May 2020 23:43:37 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnt57zsz9sVF; Thu, 21 May 2020 13:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032594; bh=eup3iyYUWnuqB9PIhUENkDwPcTYFDbBI7Pm2SOCB26g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LNlximYBa0hlzRkqewPUvqQcL4/R29JENQCQDo/w2gabH//RHCoafExY6olBai97u dBQwRafjSrUt1N7sGl4TCztWSHVjBRgZF3YIvdHrb5leAvrL2fd0eMZZRQFV5J5kPj /BTpeFjCzuO4WBH9PcgTwAQYVEQ4Kou+DlBjYV8c= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 16/18] guest memory protection: Add Error ** to GuestMemoryProtection::kvm_init Date: Thu, 21 May 2020 13:43:02 +1000 Message-Id: <20200521034304.340040-17-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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" 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 Tested-by: Thiago Jung Bauermann --- accel/kvm/kvm-all.c | 4 +++- include/exec/guest-memory-protection.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 1b10e94222..4011699736 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2079,9 +2079,11 @@ static int kvm_init(MachineState *ms) if (ms->gmpo) { GuestMemoryProtectionClass *gmpc =3D GUEST_MEMORY_PROTECTION_GET_CLASS(ms->gmpo); + Error *local_err =3D NULL; =20 - ret =3D gmpc->kvm_init(ms->gmpo); + ret =3D gmpc->kvm_init(ms->gmpo, &local_err); if (ret < 0) { + error_report_err(local_err); goto err; } } diff --git a/include/exec/guest-memory-protection.h b/include/exec/guest-me= mory-protection.h index 7d959b4910..2a88475136 100644 --- a/include/exec/guest-memory-protection.h +++ b/include/exec/guest-memory-protection.h @@ -32,7 +32,7 @@ typedef struct GuestMemoryProtection GuestMemoryProtectio= n; typedef struct GuestMemoryProtectionClass { InterfaceClass parent; =20 - int (*kvm_init)(GuestMemoryProtection *); + int (*kvm_init)(GuestMemoryProtection *, Error **); int (*encrypt_data)(GuestMemoryProtection *, uint8_t *, uint64_t); } GuestMemoryProtectionClass; =20 diff --git a/target/i386/sev.c b/target/i386/sev.c index 60e9d8c735..6a56ec203b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -617,7 +617,7 @@ sev_vm_state_change(void *opaque, int running, RunState= state) } } =20 -static int sev_kvm_init(GuestMemoryProtection *gmpo) +static int sev_kvm_init(GuestMemoryProtection *gmpo, Error **errp) { SevGuestState *sev =3D SEV_GUEST(gmpo); char *devname; @@ -633,14 +633,14 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) 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 @@ -649,20 +649,19 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) 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; @@ -672,14 +671,14 @@ static int sev_kvm_init(GuestMemoryProtection *gmpo) 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 Fri Apr 26 14:02:45 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=1590033418; cv=none; d=zohomail.com; s=zohoarc; b=Ld9caa97UpjkCJ1GmmfxS3Dbejzn7B746Lyd2FmDGzFk+nyQ8mdJ/8WcSoD/FnFtcWivVkSodxc51AKMRZ/B78X2PyaCxxXmnHKqSL2iFEXmwxh0WaILtp91W53OMHVLa3Y092AxpWYUKPidfc93K6mhsWQZUMGhQ5jowDkcJ8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033418; 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=a3zjQIB+h5qdxrA5IcPz2Wt/3D/m+DROGto7TcyuBWc=; b=TT7+5o6QOj9FpCMeTrfM+oUyeYpQwS8xIBhlAOWrgotR9uSMhIqtjhtss+R0LP2RBUwwCRBJ58ayPu8Z+TJfvDYv8lRshD4UiCf7zlekJ1Hc398HlIoIsCj5D415OsooxZV+6Siq7NvrvbzyLnKKn4nfsD3in3MmgCwkSdnbXuk= 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 1590033418234694.6620900319446; Wed, 20 May 2020 20:56:58 -0700 (PDT) Received: from localhost ([::1]:41250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcKG-0001Cp-Uz for importer@patchew.org; Wed, 20 May 2020 23:56:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7O-0003Jg-21; Wed, 20 May 2020 23:43:38 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:45131 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 1jbc7M-0003YY-BQ; Wed, 20 May 2020 23:43:37 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnv0Y7Hz9sVV; Thu, 21 May 2020 13:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032595; bh=W558T0y4xrxfOwPQYmYtDO1muLcuKoHvSX6UyLLotaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fu5vGs+iKEOzGWF/cnWDp+sxjuKBr2gNFHYge8LcUfqI1/VHBY7bTWyO+UPfmC8GH feY/nu1w0t+nvrOmuDOl5kkcnSR0XDO7JCHgVkvDeQQOLZqPmvtuISABpwOiKeHcBu x2KRYwntQ3xZXweSyYjweUmqLFIgZC0aoCThEeks= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 17/18] spapr: Added PEF based guest memory protection Date: Thu, 21 May 2020 13:43:03 +1000 Message-Id: <20200521034304.340040-18-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 Framework) 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 havint 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 guest-memory-protection machine pro= perty 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, so we can't know if the guest actually is secure until well after machine creation time. Signed-off-by: David Gibson Acked-by: Ram Pai Tested-by: Thiago Jung Bauermann --- target/ppc/Makefile.objs | 2 +- target/ppc/pef.c | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 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..823daf3e9c --- /dev/null +++ b/target/ppc/pef.c @@ -0,0 +1,81 @@ +/* + * PEF (Protected Execution Framework) 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" + +#define TYPE_PEF_GUEST "pef-guest" +#define PEF_GUEST(obj) \ + OBJECT_CHECK(PefGuestState, (obj), TYPE_SEV_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 ...,guest-memory-protection=3Dpef0 + */ +struct PefGuestState { + Object parent_obj; +}; + +static Error *pef_mig_blocker; + +static int pef_kvm_init(GuestMemoryProtection *gmpo, Error **errp) +{ + PefGuestState *pef =3D PEF_GUEST(gmpo); + + 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) +{ + GuestMemoryProtectionClass *gmpc =3D GUEST_MEMORY_PROTECTION_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_GUEST_MEMORY_PROTECTION }, + { 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 Fri Apr 26 14:02:45 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=1590033442; cv=none; d=zohomail.com; s=zohoarc; b=CfiLNRbipobKWo7D8NmCZjcZjUxHK8fAIpTTvffdlnnLTiE9ZB8ziFLjGF43T1HVY3ObvxqjjQhW/PcVgtb6fikwC0ULMkK3iKHaOAuexh1FV8isTTywnW4odFpZOi72PHV2X0e5pIUTSX1x0mfk4naCEVGQ6kMQ64XIhukrrtM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590033442; 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=D56rKgoStK7LULrg22cBTvSszNiyI9r6Lehjgxr1f1E=; b=EuJDVKO26FVOLkDwZSSWTYPCSMBCU7Flp/yr5H/q2IK1aqVUGlM24lME0UrMwJLERlj9CvE+PH8m+PQTNyuZBN9/2PwWjL3O5V71FiL9aK8ajluRKrPLEwdNt/ur6rs0Uwch6BvSWEm7l7gjli/zUMnKwi04FITqMQcGzc/1ZXg= 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 1590033442787821.2285601911204; Wed, 20 May 2020 20:57:22 -0700 (PDT) Received: from localhost ([::1]:42964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbcKf-0002SV-ES for importer@patchew.org; Wed, 20 May 2020 23:57:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbc7N-0003Ie-LX; Wed, 20 May 2020 23:43:37 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:47881 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 1jbc7M-0003YU-8c; Wed, 20 May 2020 23:43:37 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 49SFnt6QqDz9sVG; Thu, 21 May 2020 13:43:14 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1590032594; bh=FeXJqAbqicMbULwoyafKv73wne8M05KzRx96/hIBYS8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKD3NL+MimoyWtFhDKs3K9p+VZwC6KMyzmpIeq1qoV1LFv5JdiDY1wejmyv0RUKjk ONF9bpuW5w2G8jCr8Hb7sCO79YxbenlKa4w6Cfmz8+F2wEdgzdDCl7Dh1Ft2cdt6z9 mNxWLF8UT0kuEbn9hhCJ+pZsYJMSpsqAJM855Xjs= From: David Gibson To: qemu-devel@nongnu.org, brijesh.singh@amd.com, frankja@linux.ibm.com, dgilbert@redhat.com, pair@us.ibm.com Subject: [RFC v2 18/18] guest memory protection: Alter virtio default properties for protected guests Date: Thu, 21 May 2020 13:43:04 +1000 Message-Id: <20200521034304.340040-19-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200521034304.340040-1-david@gibson.dropbear.id.au> References: <20200521034304.340040-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/05/20 23:43:13 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Eduardo Habkost , kvm@vger.kernel.org, "Michael S. Tsirkin" , cohuck@redhat.com, mdroth@linux.vnet.ibm.com, qemu-ppc@nongnu.org, Paolo Bonzini , 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 guest memory protection 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 Tested-by: Thiago Jung Bauermann --- hw/core/machine.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/core/machine.c b/hw/core/machine.c index 88d699bceb..cb6580954e 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/guest-memory-protection.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-pci.h" =20 GlobalProperty hw_compat_5_0[] =3D {}; const size_t hw_compat_5_0_len =3D G_N_ELEMENTS(hw_compat_5_0); @@ -1159,6 +1161,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