From patchwork Mon Aug 31 15:37:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11746553 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20E3B109B for ; Mon, 31 Aug 2020 15:38:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9108207EA for ; Mon, 31 Aug 2020 15:38:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="eBTRGY6a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9108207EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCltV-0000Qs-Tm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Aug 2020 11:38:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClss-0007NN-Pn for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:14 -0400 Received: from mail-dm6nam08on2070.outbound.protection.outlook.com ([40.107.102.70]:41056 helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsq-0001yB-NP for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CA9ituaPySmYdpBCZWQHc719C9VrmO2NG9+6+e6vyFU90F01BXhTuYobsU3RN+6ut7xONhe+jOppQgRYoVtKfsye17t6cX+SJxu4H+3sCD/HrmJNzTPzziHBSxhLVnv///OrPy/O/Edsi92+EqS8HGVb3I+vxUM3BF+0AFm/lyo3KZE+YPje7XHDOujBbsD9fW/KVvfPHtt7W6iWRCJ3K5uFz1KXgSiEyinYkejbqDK0aRdBiMK2vTVWKLmbTIkAF0ANgHWk/ehquC1JAMQL/SFWzTh8aMxZj5IC/ukBbu8NhJ560M/PGuah9Kr6Gu5qfdCLjZF/M7DwUhQPRoB4VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MJ+BpJng5csN/LA+I/qcPQkYM/tISIORmRx+LOYMnks=; b=hORM3Vy8hyK6xLsYFFSIq/y5Tp6Pg2z/sJ60tyYU1JZyT2yeXLN0JIwCuzigEd90XFO6iCzy/7VCTbvNkYmv3I2yEx66mY7GYHl7KcTWxLvGruA7o89b+SmXOhIQACCdqeJUGDt4zl5J8g5c0NMcTUmJBuYpl0a5bI7ctwF7zxOPH+OVpwJHCH692Ie+5sYpc1qp6RShWQUqGr7CE08rIpEr9KHl+GGSWV1Y1Vc/AL+HCTi/6019BUZCInTm+2kMFx2NHqY37W6J4aVlZAccV2ScuvS9KmtFSyOYRf0c9e9mCvZx5A9ODE4XCPvZjAYFtpeAS4YDOtHNlZhZVqPCPw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MJ+BpJng5csN/LA+I/qcPQkYM/tISIORmRx+LOYMnks=; b=eBTRGY6a+GyfUq51LlvjAUZ2fHcsw2xp2QzSuQ9LF+DjVDHDA6KTX5D79vYYHN03TrwuzczBCPhSxTy6dX2I07/wkMbvuWSBMD5hgTnXyJSuGyEMLCZlXFdIi1L7b7uqN47qHv6xhfdvAT3tAL58zzTvUyvQk5k5HLgEHHwNfOg= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4484.namprd12.prod.outlook.com (2603:10b6:5:28f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Mon, 31 Aug 2020 15:37:36 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346%3]) with mapi id 15.20.3326.025; Mon, 31 Aug 2020 15:37:36 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v2 1/4] sev/i386: Add initial support for SEV-ES Date: Mon, 31 Aug 2020 10:37:10 -0500 Message-Id: <6222b0024f7af99fe7de5eede633d00e42162e2f.1598888232.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0061.namprd12.prod.outlook.com (2603:10b6:802:20::32) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by SN1PR12CA0061.namprd12.prod.outlook.com (2603:10b6:802:20::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Mon, 31 Aug 2020 15:37:35 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9569550a-4ca3-4eab-65e0-08d84dc3c93d X-MS-TrafficTypeDiagnostic: DM6PR12MB4484: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sEp+kjbfBef11bfZgkVrkg5IV8ofbX8OSiVzyVbxJsRsel2y/a7COTjh4OjyPDfh8ro02/ASUQiMVfsdmaGngLCbrs3N9jzKB2k5CD6DAH0rrf+g0fVIFgSjcptViR7RCmrHb3PGgjqDJ8/OvrddosHJNa+Bj39dBHPsdfNYgOQNpHnNnLxq9/DRxLwMynjPyeUKjSVe8sLM3hXK7KwgvCXaNpEtlr4MeEtuzd4SxdkDwD9ffcHWbiSooVjtTAdVPGLsWyJQaVR+bRSupXcAOuToqhI5Yptf5cl0qNbuL8lBkpEY3Av4FQqXVc9Mrm7ZNMh4l3ANg3JS4EgKoPpjUX7OMwltedn74PYKTSgWsOwIXxup9ZzxZxvjyQWuv3yx X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB1355.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(366004)(346002)(376002)(136003)(54906003)(956004)(16576012)(7416002)(2906002)(6666004)(4326008)(2616005)(6486002)(316002)(66556008)(8676002)(66946007)(478600001)(186003)(5660300002)(8936002)(86362001)(83380400001)(66476007)(36756003)(52116002)(26005)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BC9uk/Y5kE+Kl2S0IU3FJD8eG/XG8+D3Hl7bC1jXS8CpO66hDLSNRueM1NW1hFMk0Q2YE4CHLfjoMIel0mpPTNuBcYTuZwP7nZ5tw0NJFChW1dREVmhrCbEaTNSp6o/x3JE8LROIvncmO7nO1ebOpXoRz46v0IJy+nnGZqx1r9qnBQ5yGr3QQbSn03z33i4TTc6QkkZ2ZL8QEKg3o0APvje7HW5uMBBKKld8bk6qXA+Z9mIr/t/V4PDsYIEke/vEMBCRgUBt0GO8a0+jMi0uMh9/lhwM5pwkdW8oZBDvs7lSg0lbijDdYAaHDV5v45E80HJxN0bp2u6MxQJSfz1bGgiBPw2A1GbDfcOLGbSBDMZQsEn7cinXrOubP20lkTVfgJRlBORvmwz7prs+Ohwp9ERFv71V7RHe7g1pWRr4MuXFZ7xLbp2qivmkxFatPYz1qXbyB5A2Vrk7i0ppgRyTr06Qjduka2RPk4HX6SvCgLkPJqPzLJHzG6yqgKRg12M5psouQNcCBZBaoPrXTCEHQ+jzu+ORK4ZRXMcfpEsX3I5wSY6aOSTsjyWRf9BwaxL527pKJW19QFGOtgpMChZwf/OwvuTkyXeTTMtwb6yBd85AeVMT6dckM0lifOAPIZi2mRhvKLl0gAA4Xv+tFM5QRA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9569550a-4ca3-4eab-65e0-08d84dc3c93d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2020 15:37:36.6519 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xHBZq1bZzH2IaITt/kKzRcSjaqYZRPvFht2nuA55LtkDYM9viUkbWMz171Ow4jQanmY4UKW7hbe7tXfhSoORGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4484 Received-SPF: none client-ip=40.107.102.70; envelope-from=Thomas.Lendacky@amd.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 11:38:11 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_ILLEGAL_IP=1.3, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky Provide initial support for SEV-ES. This includes creating a function to indicate the guest is an SEV-ES guest (which will return false until all support is in place), performing the proper SEV initialization and ensuring that the guest CPU state is measured as part of the launch. Co-developed-by: Jiri Slaby Signed-off-by: Jiri Slaby Signed-off-by: Tom Lendacky --- target/i386/cpu.c | 1 + target/i386/sev-stub.c | 5 +++++ target/i386/sev.c | 46 ++++++++++++++++++++++++++++++++++++++++-- target/i386/sev_i386.h | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 588f32e136..bbbe581d35 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5969,6 +5969,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 0x8000001F: *eax = sev_enabled() ? 0x2 : 0; + *eax |= sev_es_enabled() ? 0x8 : 0; *ebx = sev_get_cbit_position(); *ebx |= sev_get_reduced_phys_bits() << 6; *ecx = 0; diff --git a/target/i386/sev-stub.c b/target/i386/sev-stub.c index 88e3f39a1e..040ac90563 100644 --- a/target/i386/sev-stub.c +++ b/target/i386/sev-stub.c @@ -49,3 +49,8 @@ SevCapability *sev_get_capabilities(Error **errp) error_setg(errp, "SEV is not available in this QEMU"); return NULL; } + +bool sev_es_enabled(void) +{ + return false; +} diff --git a/target/i386/sev.c b/target/i386/sev.c index c3ecf86704..6c9cd0854b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -359,6 +359,12 @@ sev_enabled(void) return !!sev_guest; } +bool +sev_es_enabled(void) +{ + return false; +} + uint64_t sev_get_me_mask(void) { @@ -578,6 +584,22 @@ sev_launch_update_data(SevGuestState *sev, uint8_t *addr, uint64_t len) return ret; } +static int +sev_launch_update_vmsa(SevGuestState *sev) +{ + int ret, fw_error; + + ret = sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_UPDATE_VMSA, NULL, &fw_error); + if (ret) { + error_report("%s: LAUNCH_UPDATE_VMSA ret=%d fw_error=%d '%s'", + __func__, ret, fw_error, fw_error_to_str(fw_error)); + goto err; + } + +err: + return ret; +} + static void sev_launch_get_measure(Notifier *notifier, void *unused) { @@ -590,6 +612,14 @@ sev_launch_get_measure(Notifier *notifier, void *unused) return; } + if (sev_es_enabled()) { + /* measure all the VM save areas before getting launch_measure */ + ret = sev_launch_update_vmsa(sev); + if (ret) { + exit(1); + } + } + measurement = g_new0(struct kvm_sev_launch_measure, 1); /* query the measurement blob length */ @@ -684,7 +714,7 @@ sev_guest_init(const char *id) { SevGuestState *sev; char *devname; - int ret, fw_error; + int ret, fw_error, cmd; uint32_t ebx; uint32_t host_cbitpos; struct sev_user_data_status status = {}; @@ -745,8 +775,20 @@ sev_guest_init(const char *id) sev->api_major = status.api_major; sev->api_minor = status.api_minor; + if (sev_es_enabled()) { + if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) { + error_report("%s: guest policy requires SEV-ES, but " + "host SEV-ES support unavailable", + __func__); + goto err; + } + cmd = KVM_SEV_ES_INIT; + } else { + cmd = KVM_SEV_INIT; + } + trace_kvm_sev_init(); - ret = sev_ioctl(sev->sev_fd, KVM_SEV_INIT, NULL, &fw_error); + ret = sev_ioctl(sev->sev_fd, cmd, NULL, &fw_error); if (ret) { error_report("%s: failed to initialize ret=%d fw_error=%d '%s'", __func__, ret, fw_error, fw_error_to_str(fw_error)); diff --git a/target/i386/sev_i386.h b/target/i386/sev_i386.h index 4db6960f60..4f9a5e9b21 100644 --- a/target/i386/sev_i386.h +++ b/target/i386/sev_i386.h @@ -29,6 +29,7 @@ #define SEV_POLICY_SEV 0x20 extern bool sev_enabled(void); +extern bool sev_es_enabled(void); extern uint64_t sev_get_me_mask(void); extern SevInfo *sev_get_info(void); extern uint32_t sev_get_cbit_position(void); From patchwork Mon Aug 31 15:37:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11746555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C3E109B for ; Mon, 31 Aug 2020 15:38:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B3FF1207EA for ; Mon, 31 Aug 2020 15:38:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="EgFXawrw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3FF1207EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCltY-0000Ya-SF for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Aug 2020 11:38:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsu-0007OG-Os for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:16 -0400 Received: from mail-dm6nam08on2070.outbound.protection.outlook.com ([40.107.102.70]:41056 helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClss-0001yB-Ut for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dBoo/l1dyGKjfi5t9E9FCEZ0WElaJ8h9Rp7NmnfabhiO9pKeVtxJwym5QwqJLfRIirsBLAs9muHj+/cIlrBDPnFtO3VpIuSfN3MLr8slWZx2OjsG7XfNoaKSyj/HiOYYRBx7FGFHBU+TXeSx2+YkqRV8YQU8UxG3KejLMYYuPj4OSH1r9i0GyCsD+LBe1mE78I/iphfNsZq3oZt3TMom40tcfBuNltaV/srMQ1j3AMtq1VChfJEDBQwzuiWsrz7MV36Vj/fskGpM6vP61ZBVgqBeQNE6EzPfHvhL42l0PfM6WcEeaFaynLVOo95rgCJL1zdGO3LgpV1HaBb611asLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RAFqVcWGNrVBCumzMwanuzQxEErwN32x9/5HVxnaLUM=; b=kT5fV3ATLvMB8m3z9+Aq78BX2u1Pnhk4QvEgmAihP8CjAJ1jrdy82XG1uI7s/Ii3hshNKELKV+tCh/wcVKNW5e/EAVI/Pv0IjWBvbHWyAg0/WJzVnkRHWtRXNTTiQ7Qs/nUtxQidklJ+Yh6iR69ASFeE/rKMzDq8i0HwQsTfotY77mOMRiV5FOK5hP35rOQ3Bo1ybCpwv3I2jL2MBMwSTUap9SFvqHV4FHJtjMZo4hJ8GmF5TrOGqk5Sb/oSMpiSDAfYZBZLf33n0jJodeupRq6ZqQHWhlb54do/n9M/kFTXrYHQGFiqokqDmLWx+QFWKjNC08fYDEukuAAaKS4YbA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RAFqVcWGNrVBCumzMwanuzQxEErwN32x9/5HVxnaLUM=; b=EgFXawrwixoAAtnCepVrbnHGF/CaaF4V9rcUIj1LfxBOcKaURHgPYEOurLfy9zv9/VH9glXruiRwJWZ7Bs4PTBmOVR6UbhzmmDfDFyFlwTQGTCsAYklP00e4rBT6wnXA+3o8edwTVRH28fbGTVpiOiopeg7GUkBOkdRhCfTUB/E= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4484.namprd12.prod.outlook.com (2603:10b6:5:28f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Mon, 31 Aug 2020 15:37:45 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346%3]) with mapi id 15.20.3326.025; Mon, 31 Aug 2020 15:37:45 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v2 2/4] sev/i386: Allow AP booting under SEV-ES Date: Mon, 31 Aug 2020 10:37:11 -0500 Message-Id: <3f4edde053460c94a6611ce2dde35851f93c9cb7.1598888232.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0048.namprd04.prod.outlook.com (2603:10b6:803:2a::34) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by SN4PR0401CA0048.namprd04.prod.outlook.com (2603:10b6:803:2a::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Mon, 31 Aug 2020 15:37:44 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3da89453-4fd1-4a9a-26c1-08d84dc3ce4c X-MS-TrafficTypeDiagnostic: DM6PR12MB4484: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:568; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g06XzJdZa0oTIi2EELwfVs6aNwVQ98+Qmrn2drr+vntErFltRQ71mMt6gyaM+SbxukSBPKSledrQAw7u7A3U7M5D4gPNO/Lzc43q0ifjWLMBiAG1CN1wce8p19CPbfj2Ub5psJ7Wvt3+eFatiwHyZBsTH0Lk7V0GNa81fYGVOpR0gAe4seIcAXrZlLujEufUjgNRunTRIOL/OQ4xBrNi7u4qqinMJPc1AJ1Cth9bDdWQpmOs2dkKmLGnhpE+LLtyQdnQkx0JUbPxzoUAJqDcecp/xSVIlKdoDvDUHbMj7nHgqIdRNOmHbCSv2zybCN9kEe2JuUJ+9DDzEJevYxYQOA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB1355.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(366004)(346002)(376002)(136003)(54906003)(956004)(16576012)(7416002)(2906002)(6666004)(4326008)(2616005)(6486002)(316002)(66556008)(8676002)(66946007)(478600001)(186003)(5660300002)(8936002)(86362001)(83380400001)(66476007)(36756003)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kmwy0CsI3sVrcbh4SlfMBBWImml/ZhEiA7guqDsgrtY78kqR8BMZWWBXf5I+/Xq66bk5XVXiW4ZL0gyl7An4uYApYUeGi1eOCA83+/1B/VjAzDcy4RShD7b9udstuJMPHLj9nECm4H+79VrNMmYwd737JdxCp68fffzPXDYx0WExZSxiii2NfQrEpTJrrXQQG87affapcNSW0XFdBD2JnCp75dTGwa56rrAO2ve5XnMgMM7XJJyYPsiZEtp6Ph2qSJV+q+uevZEUbsul5ejNLOrKQJhFnNFJ+mx18YyhSJb9gncwNr/R5CB8F8vf9TTYP1mmmnKVBHYKxhX4/vNoFRQ7ncDcB1hdQCttRxcT2xKRYylOjQRVIT+ys+yPxF3ZeAq2PrfhnJx833wDNca/KU8ZjECnrDhKfkLac9Q6YR711svcZpMRlme+Uy5tJySXvtNd9Fk9tHnNtd3LPDKfZPVPfEYxUUsESVqdXcbLbJ85goGSo4jSi4rGumXAMchjnTPFYvAekIz2Dsrxb4VHILXgaCFwec4qKtBFbwwpgvvFRld53FPWS/IQhaqo2q6e/FSavfswbmID92zr8QJddbAHoZBkrJQaKyEav7QS8XvERvbHyXxbT4WvO1WxWvRJW0rqK62L5sHyy7KcVpUHgw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3da89453-4fd1-4a9a-26c1-08d84dc3ce4c X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2020 15:37:45.2351 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rurh7oXpfA59WqVLUvjEAPqdgVFJEBk63qERRu1ov/W9dvxAKV2JyeSsmWnR9DjRgjxs0+WFCkj0FOOEgNQV1w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4484 Received-SPF: none client-ip=40.107.102.70; envelope-from=Thomas.Lendacky@amd.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 11:38:11 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_ILLEGAL_IP=1.3, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky When SEV-ES is enabled, it is not possible modify the guests register state after it has been initially created, encrypted and measured. Normally, an INIT-SIPI-SIPI request is used to boot the AP. However, the hypervisor cannot emulate this because it cannot update the AP register state. For the very first boot by an AP, the reset vector CS segment value and the EIP value must be programmed before the register has been encrypted and measured. Signed-off-by: Tom Lendacky --- accel/kvm/kvm-all.c | 64 ++++++++++++++++++++++++++++++++++++++++++ accel/stubs/kvm-stub.c | 5 ++++ hw/i386/pc_sysfw.c | 10 ++++++- include/sysemu/kvm.h | 16 +++++++++++ include/sysemu/sev.h | 3 ++ target/i386/kvm.c | 2 ++ target/i386/sev.c | 51 +++++++++++++++++++++++++++++++++ 7 files changed, 150 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 63ef6af9a1..20725b0368 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -39,6 +39,7 @@ #include "qemu/main-loop.h" #include "trace.h" #include "hw/irq.h" +#include "sysemu/kvm.h" #include "sysemu/sev.h" #include "qapi/visitor.h" #include "qapi/qapi-types-common.h" @@ -120,6 +121,12 @@ struct KVMState /* memory encryption */ void *memcrypt_handle; int (*memcrypt_encrypt_data)(void *handle, uint8_t *ptr, uint64_t len); + int (*memcrypt_save_reset_vector)(void *handle, void *flash_ptr, + uint64_t flash_size, uint32_t *addr); + + unsigned int reset_cs; + unsigned int reset_ip; + bool reset_valid; /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; @@ -239,6 +246,62 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) return 1; } +void kvm_memcrypt_set_reset_vector(CPUState *cpu) +{ + X86CPU *x86; + CPUX86State *env; + + /* Only update if we have valid reset information */ + if (!kvm_state->reset_valid) { + return; + } + + /* Do not update the BSP reset state */ + if (cpu->cpu_index == 0) { + return; + } + + x86 = X86_CPU(cpu); + env = &x86->env; + + cpu_x86_load_seg_cache(env, R_CS, 0xf000, kvm_state->reset_cs, 0xffff, + DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | + DESC_R_MASK | DESC_A_MASK); + + env->eip = kvm_state->reset_ip; +} + +int kvm_memcrypt_save_reset_vector(void *flash_ptr, uint64_t flash_size) +{ + CPUState *cpu; + uint32_t addr; + int ret; + + if (kvm_memcrypt_enabled() && + kvm_state->memcrypt_save_reset_vector) { + + addr = 0; + ret = kvm_state->memcrypt_save_reset_vector(kvm_state->memcrypt_handle, + flash_ptr, flash_size, + &addr); + if (ret) { + return ret; + } + + if (addr) { + kvm_state->reset_cs = addr & 0xffff0000; + kvm_state->reset_ip = addr & 0x0000ffff; + kvm_state->reset_valid = true; + + CPU_FOREACH(cpu) { + kvm_memcrypt_set_reset_vector(cpu); + } + } + } + + return 0; +} + /* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { @@ -2193,6 +2256,7 @@ static int kvm_init(MachineState *ms) } kvm_state->memcrypt_encrypt_data = sev_encrypt_data; + kvm_state->memcrypt_save_reset_vector = sev_es_save_reset_vector; } ret = kvm_arch_init(ms, s); diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 82f118d2df..3aece9b513 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -114,6 +114,11 @@ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len) return 1; } +int kvm_memcrypt_save_reset_vector(void *flash_ptr, uint64_t flash_size) +{ + return -ENOSYS; +} + #ifndef CONFIG_USER_ONLY int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev) { diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index b6c0822fe3..321ff94261 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -156,7 +156,8 @@ static void pc_system_flash_map(PCMachineState *pcms, PFlashCFI01 *system_flash; MemoryRegion *flash_mem; void *flash_ptr; - int ret, flash_size; + uint64_t flash_size; + int ret; assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled); @@ -204,6 +205,13 @@ static void pc_system_flash_map(PCMachineState *pcms, if (kvm_memcrypt_enabled()) { flash_ptr = memory_region_get_ram_ptr(flash_mem); flash_size = memory_region_size(flash_mem); + + ret = kvm_memcrypt_save_reset_vector(flash_ptr, flash_size); + if (ret) { + error_report("failed to locate and/or save reset vector"); + exit(1); + } + ret = kvm_memcrypt_encrypt_data(flash_ptr, flash_size); if (ret) { error_report("failed to encrypt pflash rom"); diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index b4174d941c..f74cfa85ab 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -247,6 +247,22 @@ bool kvm_memcrypt_enabled(void); */ int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len); +/** + * kvm_memcrypt_set_reset_vector - sets the CS/IP value for the AP if SEV-ES + * is active. + */ +void kvm_memcrypt_set_reset_vector(CPUState *cpu); + +/** + * kvm_memcrypt_save_reset_vector - locates and saves the reset vector to be + * used as the initial CS/IP value for APs + * if SEV-ES is active. + * + * Return: 1 SEV-ES is active and failed to locate a valid reset vector + * 0 SEV-ES is not active or successfully located and saved the + * reset vector address + */ +int kvm_memcrypt_save_reset_vector(void *flash_prt, uint64_t flash_size); #ifdef NEED_CPU_H #include "cpu.h" diff --git a/include/sysemu/sev.h b/include/sysemu/sev.h index 98c1ec8d38..5198e5a621 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -18,4 +18,7 @@ void *sev_guest_init(const char *id); int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len); +int sev_es_save_reset_vector(void *handle, void *flash_ptr, + uint64_t flash_size, uint32_t *addr); + #endif diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6f18d940a5..10eaba8943 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1912,6 +1912,8 @@ void kvm_arch_reset_vcpu(X86CPU *cpu) } /* enabled by default */ env->poll_control_msr = 1; + + kvm_memcrypt_set_reset_vector(CPU(cpu)); } void kvm_arch_do_init_vcpu(X86CPU *cpu) diff --git a/target/i386/sev.c b/target/i386/sev.c index 6c9cd0854b..0bc497379b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -70,6 +70,19 @@ struct SevGuestState { #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" +/* SEV Information Block GUID = 00f771de-1a7e-4fcb-890e-68c77e2fb44e */ +#define SEV_INFO_BLOCK_GUID \ + "\xde\x71\xf7\x00\x7e\x1a\xcb\x4f\x89\x0e\x68\xc7\x7e\x2f\xb4\x4e" + +typedef struct __attribute__((__packed__)) SevInfoBlock { + /* SEV-ES Reset Vector Address */ + uint32_t reset_addr; + + /* SEV Information Block size and GUID */ + uint16_t size; + char guid[16]; +} SevInfoBlock; + static SevGuestState *sev_guest; static Error *sev_mig_blocker; @@ -827,6 +840,44 @@ sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len) return 0; } +int +sev_es_save_reset_vector(void *handle, void *flash_ptr, uint64_t flash_size, + uint32_t *addr) +{ + SevInfoBlock *info; + + assert(handle); + + /* + * Initialize the address to zero. An address of zero with a successful + * return code indicates that SEV-ES is not active. + */ + *addr = 0; + if (!sev_es_enabled()) { + return 0; + } + + /* + * Extract the AP reset vector for SEV-ES guests by locating the SEV GUID. + * The SEV GUID is located 32 bytes from the end of the flash. Use this + * address to base the SEV information block. + */ + info = flash_ptr + flash_size - 0x20 - sizeof(*info); + if (memcmp(info->guid, SEV_INFO_BLOCK_GUID, 16)) { + error_report("SEV information block not found in pflash rom"); + return 1; + } + + if (!info->reset_addr) { + error_report("SEV-ES reset address is zero"); + return 1; + } + + *addr = info->reset_addr; + + return 0; +} + static void sev_register_types(void) { From patchwork Mon Aug 31 15:37:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11746557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26E5413B6 for ; Mon, 31 Aug 2020 15:38:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF82B20866 for ; Mon, 31 Aug 2020 15:38:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="yOO8cZc9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF82B20866 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCltZ-0000ZE-46 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Aug 2020 11:38:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsw-0007Px-GL for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:18 -0400 Received: from mail-dm6nam08on2070.outbound.protection.outlook.com ([40.107.102.70]:41056 helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsv-0001yB-0v for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lH9seH9Sf+TRE5Q4c5DPo0Y7mNH7xc0CNSmkZiqIWH6n5DAKB1Dn1+l+El1ePeQ1fhoHnJZ+afTI+8oQZOFX+BoQfO1Ot1Td0QvkdamLrp3B6lT89IVgnGtodoJrNhEcSb+f1hiBNTbPD6szbOCkT8FhYPXP5pxVc6GWUrJrU/iLTXuEzMCmtBJffABVwlBnITK7rPmB0XEe+v4QzP21zU0FRbG1qZn71gn9wP7d4Sxb2Ysb9QLwGso3QfkMXcoI+92K0xeMOrmMfVkCxSkeiHAceBtof/v3MySSl2C2MnM1s1j46DtpPCF1mXojlll+T6sMDlUMeJ0PlLe6BPczkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bXF8fTPJ/Y9pFcClOLMeQ5tenPBU4qylEmby8f9sbW8=; b=miim6xnQ0HxXovoXKDEnp8qKCeTQLweQStUxWSIWWEeIlNgI1HSjk2zHI06KMxOHGvMRsu/pOa6vWwApRGYHr8bsTxCQ8aEw9p3AXhNO9kpoU7zdfyoMmhejbl8TuZdMls+TyC+80LFBwxtwOvh9c3DiEajfDXx87tyn9SVXdWMy+dda8mhkiGEx1ZNSZUJmoFxQ90puTjPM+8VpJpa6DKgz3P/PH7mJWkD8MfRKb2wdbIqPD0olaoh7gYSbYvRw2T5YPaFd22nXyiDCGh6T9ZfDA1rkKAf0Li+m/nrYoQ4ZqRteFx7oXSvJNLsSRqvI18KLnMRTp6H6nPkykjwtCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bXF8fTPJ/Y9pFcClOLMeQ5tenPBU4qylEmby8f9sbW8=; b=yOO8cZc9TY6omObVz30baBinFtakqBehZ9mNtBR/ZHMClametkwj3sI9Q4kbJawIbofntS9VR37E6l7Gp9oELdMXYFKSfYK5GYb8cFsOqROacvqulY0HMMZgJwOmhR4zYgpaJVWtwzQZjp32k7eG4rw8frNYdCbLcNF2jenizAs= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4484.namprd12.prod.outlook.com (2603:10b6:5:28f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Mon, 31 Aug 2020 15:37:53 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346%3]) with mapi id 15.20.3326.025; Mon, 31 Aug 2020 15:37:53 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v2 3/4] sev/i386: Don't allow a system reset under an SEV-ES guest Date: Mon, 31 Aug 2020 10:37:12 -0500 Message-Id: <42e7c4c3b410731b191d5328a19a790255818a00.1598888232.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0029.namprd04.prod.outlook.com (2603:10b6:803:2a::15) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by SN4PR0401CA0029.namprd04.prod.outlook.com (2603:10b6:803:2a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Mon, 31 Aug 2020 15:37:52 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bda848df-9c59-4aad-9924-08d84dc3d363 X-MS-TrafficTypeDiagnostic: DM6PR12MB4484: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:418; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b3feol6n2Z8j7UvXAkSvWFCXemD1fBIk0VWZDLE7/srLZ3s/x4JzkwClM6fNsLf/VVhlXyDV3E+XbGn/PZjK5caCnSvGfFEAxvEB+lX1etkNvT5HMHvKTTZdMOhh4QO+12JgmheanKgcR9ki5sW9xrDVwtSq9WRlFNIuYE53iYjFRcOJ84zoHcLUP4HagaycN4FrEjQ1Fne6fPfkXXHgaaHu1W+1ArwHTG8YfP2Wc1mgYXG/7e6aEyFKuSiiBGEOIeQ1JkVX2/zA/qTIdYm7N1/y5j7EyroDvFM4gb68yiVNTYGJoHerE4GoMyCiXYx+ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB1355.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(366004)(346002)(376002)(136003)(54906003)(956004)(16576012)(7416002)(2906002)(6666004)(4326008)(2616005)(6486002)(316002)(66556008)(8676002)(66946007)(478600001)(186003)(5660300002)(8936002)(86362001)(83380400001)(66476007)(36756003)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: cnsTIa8m9YMXqbyF0uIw7Ao+nfksQqqZcgYkm8YI1/Sk8stejtIFEvjgkaCsZBEUsF/NnCXhGbYNgH7Bu4omvss/JgF6eGsXnUmuNNhJEO8k1KHmNOgDAl/hB3FIAIn4gPVvdY1pvqImylq2Kpk9JbJ24XdOWMlsXDM0ZWxn49V69qAfKYw4LQZSG6b06pfUpdbaOiBq8UIZH0BJB+4QbUjh0mMBuE6TN5SJy+Pp+BT3K+0reJ0Dfw0vIRaRYYRCfVF6mXJcCRFDz4D9yncCnxZqY/g8gR255oNqNR+x6mEUcED3krm8Ym5gaXht9wTvUW+AWW6lWhGHNv1dD67/hhn/YQIU1urWx2LPafPNk2wtYayENOAYNBrSUm87wuRBWqbMMKmD+FYnrNhZAvsywepgbCJaSkmTCTIaFgMcIe/yipiZJD6QsnUJHsKJAPYlZUtVaG5Vg64+0N63CqYPgDYpoCaM3fqi8oQKh6AdjkTviRRDWV73e9U5NVFKfrhRgirsLE+8HiMfMRrXuHr3g9k+AW6wb+JJMzQ0ljpSb4UgLMxHiL8tRI2uCEMZpvaUjyNilKi/FuhsxawzvmS1I2Bm7Xwp9quUXsh9/3k7YbZWTjHw81km56T8jKgJvXkIfIhgMlV823vJKx7R01IMBg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bda848df-9c59-4aad-9924-08d84dc3d363 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2020 15:37:53.6325 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: f2hrWQQNTRrT167uAXf0q1g15rF2IYLOv/BZiat0rvfI++hW4QA7UAJLRW7GxYW6Kw3EKH3jtTxH4rD1t58Adw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4484 Received-SPF: none client-ip=40.107.102.70; envelope-from=Thomas.Lendacky@amd.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 11:38:11 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_ILLEGAL_IP=1.3, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky An SEV-ES guest does not allow register state to be altered once it has been measured. When a SEV-ES guest issues a reboot command, Qemu will reset the vCPU state and resume the guest. This will cause failures under SEV-ES, so prevent that from occurring. Signed-off-by: Tom Lendacky --- accel/kvm/kvm-all.c | 9 +++++++++ include/sysemu/cpus.h | 2 ++ include/sysemu/hw_accel.h | 5 +++++ include/sysemu/kvm.h | 2 ++ softmmu/cpus.c | 5 +++++ softmmu/vl.c | 5 ++++- 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 20725b0368..63153b6e53 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2388,6 +2388,15 @@ void kvm_flush_coalesced_mmio_buffer(void) s->coalesced_flush_in_progress = false; } +bool kvm_cpu_check_resettable(void) +{ + /* + * If we have a valid reset vector override, then SEV-ES is active + * and the CPU can't be reset. + */ + return !kvm_state->reset_valid; +} + static void do_kvm_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg) { if (!cpu->vcpu_dirty) { diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 3c1da6a018..6d688c757f 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -24,6 +24,8 @@ void dump_drift_info(void); void qemu_cpu_kick_self(void); void qemu_timer_notify_cb(void *opaque, QEMUClockType type); +bool cpu_is_resettable(void); + void cpu_synchronize_all_states(void); void cpu_synchronize_all_post_reset(void); void cpu_synchronize_all_post_init(void); diff --git a/include/sysemu/hw_accel.h b/include/sysemu/hw_accel.h index e128f8b06b..8b4536e7ae 100644 --- a/include/sysemu/hw_accel.h +++ b/include/sysemu/hw_accel.h @@ -17,6 +17,11 @@ #include "sysemu/hvf.h" #include "sysemu/whpx.h" +static inline bool cpu_check_resettable(void) +{ + return kvm_enabled() ? kvm_cpu_check_resettable() : true; +} + static inline void cpu_synchronize_state(CPUState *cpu) { if (kvm_enabled()) { diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index f74cfa85ab..eb94bbbff9 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -494,6 +494,8 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr, #endif /* NEED_CPU_H */ +bool kvm_cpu_check_resettable(void); + void kvm_cpu_synchronize_state(CPUState *cpu); void kvm_cpu_synchronize_post_reset(CPUState *cpu); void kvm_cpu_synchronize_post_init(CPUState *cpu); diff --git a/softmmu/cpus.c b/softmmu/cpus.c index a802e899ab..32f286643f 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -927,6 +927,11 @@ void hw_error(const char *fmt, ...) abort(); } +bool cpu_is_resettable(void) +{ + return cpu_check_resettable(); +} + void cpu_synchronize_all_states(void) { CPUState *cpu; diff --git a/softmmu/vl.c b/softmmu/vl.c index 4eb9d1f7fd..422fbb1650 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1475,7 +1475,10 @@ void qemu_system_guest_crashloaded(GuestPanicInformation *info) void qemu_system_reset_request(ShutdownCause reason) { - if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { + if (!cpu_is_resettable()) { + error_report("cpus are not resettable, terminating"); + shutdown_requested = reason; + } else if (no_reboot && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { shutdown_requested = reason; } else { reset_requested = reason; From patchwork Mon Aug 31 15:37:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 11746559 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E78B13B6 for ; Mon, 31 Aug 2020 15:39:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E72F207EA for ; Mon, 31 Aug 2020 15:39:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amdcloud.onmicrosoft.com header.i=@amdcloud.onmicrosoft.com header.b="CchfDdmO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E72F207EA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCltb-0000g7-H0 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 31 Aug 2020 11:38:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsx-0007ST-Vc for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:20 -0400 Received: from mail-dm6nam08on2070.outbound.protection.outlook.com ([40.107.102.70]:41056 helo=NAM04-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kClsw-0001yB-Jo for qemu-devel@nongnu.org; Mon, 31 Aug 2020 11:38:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MwixvjLXwdWBYKHm25nGt56zo6QGp3LuS/owzHjj8HIPZNp7M9+MCVeBk151xU11KYpOW+TuX7pLDQhZBg/T82e3Ec3AEiHRGkl6ibIYPCm3G3YxJ6/BOlAXYQCUTnJXcLbZ9ETQ1YHc5EYZNzuxWTODmkhLGunTeDeWcEx/YGpoP/aKtizQgRwk7rD/ZidmzuYfzIr+uf2sHBfjGWyQqg8C8wE7ZWaSDLvETUPmOTrK55l6yykhOT45prck28YC8phCipV13IbJqNQM7rAT3GdST7slPej+5iCOI2+6y9iiLx42LQm9kXU48PItqMxVwJCcBAUYfwk3GLc+PZD4RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5v8tLZ5EMykDQReg1Sn6uVLFLb85eKqfhkZ7LCH/KsE=; b=K4uf90xg+AAuMpxNRBBMMWU8aBkXlAe+rjykQkNYhaw0vJb9le9GAhHSp2my4wO7iLMNQV3GR3s+Gx0rscBnnriDcy9LBDdpaIT+6hIKrSJtH6ocDAiNF8i/xBQRbDmKC8lgdzsCew6lQs2S+R2C0XVJ830j7jDKCpqhOHN4RPIphKvL6mj2CP4+5wFmG/vC4b5nJEviWHMso3hsn4KjwyL6FtQl06SqOOjiCSlmpedPHjbMjrJY4PBixPU5VgUlPIHGWmVt+WycRwyVd+qCc/fzmlJohgMpo+9yIULD2MhGr8PcFw8ljWYTnkgWBoa1qbVkF3mdEqwZjtAV2OF5rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5v8tLZ5EMykDQReg1Sn6uVLFLb85eKqfhkZ7LCH/KsE=; b=CchfDdmOVKAfhEjDZjZzB4y1EY5MkylBwS4R1cgUF4UXUMWO+rJDGJsiBcco3XP1ErpF5XM+xzalh3NQQgsH0jgCb9tl/9GvCJBGpAFfJTy4VbLkrfkL0e8iMEC4t9lsAYzbT5qcyKHniM9ZvFGMQpBP1OYbpgk/L7v4NLD7Arg= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4484.namprd12.prod.outlook.com (2603:10b6:5:28f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19; Mon, 31 Aug 2020 15:38:02 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::299a:8ed2:23fc:6346%3]) with mapi id 15.20.3326.025; Mon, 31 Aug 2020 15:38:02 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v2 4/4] sev/i386: Enable an SEV-ES guest based on SEV policy Date: Mon, 31 Aug 2020 10:37:13 -0500 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0105.namprd12.prod.outlook.com (2603:10b6:802:21::40) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by SN1PR12CA0105.namprd12.prod.outlook.com (2603:10b6:802:21::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Mon, 31 Aug 2020 15:38:00 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2d5244da-23d6-46b0-b62a-08d84dc3d851 X-MS-TrafficTypeDiagnostic: DM6PR12MB4484: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zCs2wjvIHkWROqgIbOKwu29BmOQtbQyTR3lx1O/pby1+XkUGpsuBjbTdm+kb8ltoHEqMj+aaDMdkXCTWo3Ry4FbCXPMGBzR2NApfbIJapFJolO+rlt32eVFgHwnbjs/4b3EIvYRPfE4WFerYpXl1xP9RGhqJ+6bRPgiqsn16C2UidPg9Yc+qAMO+NBhxmluIxVMMuJb/yxz9KzdIA5UrSxC9tcmetogeYMGOvMH58Ak7jeMhfZBdHBAora1O+gdtj7YUYz0CQVOHFGNtybPUkteoICx0SGd4OBeUX4xKl5Ix6AwI2u9ozXcqHS51dzRshLZSdqXY7Y+p02++RAyRnQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR12MB1355.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(366004)(346002)(376002)(136003)(54906003)(956004)(16576012)(7416002)(2906002)(6666004)(4326008)(2616005)(6486002)(316002)(66556008)(8676002)(66946007)(478600001)(186003)(5660300002)(8936002)(86362001)(83380400001)(66476007)(36756003)(52116002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2T/42Q1+pCntur19Loj8ATBlcarFpByAB/kZnyRZmf3E5sv9I1kmrWMM2BDOvhI2GVpcvyndcoKxXMVZ7uDXjs9MXtRKROKMJlH4c+O6s5NFeEvNVJ7ysTF/rBzqubxR+bhp/F/1VlmdS142go491cjZucMquWgiUblfCFXf0YhoBD2f6zzZZhIg7gr1vXUL2NUcWjwCEawKP6SnKJMUa0+yiM7dWOx/kdrCQBu0W+vvakxUwIQYUI34PbO35u8Zgighky/XNmiQoVnXjOBbRwZQPsQSJjMoGrvfFK1DUx+FyLAXv32Axz/AMmi8Fzs7Gw35CQa0gOJINCzl4AoGiUQ4TmhUnPuiamZjC99MhsTYe2S55tcFZVi1Zp+/bu48xh7CtsXNnu4m56LGmVtN9ApDyTmaOoojmk7Bcxk0cnb8D6UuhWZ2uxkJzPs5tWVO/ODjIVYvws7qL1o608w4y4b4ORrXQzpOVo+R6dyp7X3Xn1C+Wwo2eRlUT+SjReoIzhVSc4OovPk6593vptr6PZWvApKv90/iQV1IEXh8wHbiwMqlrfm/LXOi/NIRLFbV6eS2FiksSBnpPS6uYmGkU/0qQK6PyTy9efvKqgvJl2L9Xuqa7XCAYeuvijdzS2JNp8A7fFrpPbZyLX68KZBK4Q== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d5244da-23d6-46b0-b62a-08d84dc3d851 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2020 15:38:01.9638 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xtRUDrlZzqyOFf/lRPmZdcua+6jBfbeRVfGEPZOvtyKqUFfIFa46VDy/PJQZtDqY7vvlG3ghFWoGKdSiALqd+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4484 Received-SPF: none client-ip=40.107.102.70; envelope-from=Thomas.Lendacky@amd.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/31 11:38:11 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_ILLEGAL_IP=1.3, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Marcelo Tosatti , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky Update the sev_es_enabled() function return value to be based on the SEV policy that has been specified. SEV-ES is enabled if SEV is enabled and the SEV-ES policy bit is set in the policy object. Signed-off-by: Tom Lendacky --- target/i386/sev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 0bc497379b..0fd142abe9 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -70,6 +70,8 @@ struct SevGuestState { #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" +#define GUEST_POLICY_SEV_ES_BIT (1 << 2) + /* SEV Information Block GUID = 00f771de-1a7e-4fcb-890e-68c77e2fb44e */ #define SEV_INFO_BLOCK_GUID \ "\xde\x71\xf7\x00\x7e\x1a\xcb\x4f\x89\x0e\x68\xc7\x7e\x2f\xb4\x4e" @@ -375,7 +377,7 @@ sev_enabled(void) bool sev_es_enabled(void) { - return false; + return sev_enabled() && (sev_guest->policy & GUEST_POLICY_SEV_ES_BIT); } uint64_t