From patchwork Thu Jan 14 23:12:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B81B7C433DB for ; Thu, 14 Jan 2021 23:16:16 +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 0AD3023A59 for ; Thu, 14 Jan 2021 23:16:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AD3023A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Bqg-0006OE-SE for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:16:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0BoD-0004l8-2R for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:41 -0500 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:64385 helo=NAM10-BN7-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 1l0Bo9-0006I0-45 for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:40 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mrgUXWKkMj2dCYjklwoPCN3oRhl9HtLZd4RIfgtBWO50k5OLRsbcyF36AREFHVcTkLu/8lFWkkpHU5umHn8SA3jN2X6eYIA9vvo8aHP3CWdNVgOQRYkrwueG26uoIe7RNGjSiuTxhJhv9xHUOLrRt/Hw8FQ763s+TUef+mlqMkCi15JFeabP5dtkK7WxUcnTUwOQ/xxbHk1CK8TBPhbHLPPNVOEssdsLkhwq+5i+pnufDMJ0OzALOq8OZTWjE4gTLtd0dPq8C8teBaAZtGK25tHuVussdGCywRaaNNWRUQuoO90xDhMUyiJu7B0a4bV9uKsHIHY4hLvGBVlLFlv9nw== 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=DL/4RU8ga+O/ynjbp7ttMwZnaHB0wh1OA0hcnvMmlC0=; b=TNDhe4ft/AIYyQTWtEy9szBEza0PDV2GELqxDVM6t8yUy9Y47iY8+Lv2dk4RDXcm/S8OUxpUYQT34zsiYzlOyyYCKSFX1fEGAyzh99J1emqrkY8Ewoz+nVNcloh7R3RmUAltSxvSrq9vTowwNAi1rvj0+LvlbzlOd+pm73z+dDUmhWWfMezztzMcwGuAWL4VSDOlIeiAImUBitRSpctWMFqHuDv9OvLlyVNVKAesRfMo9ttFTEj/JXQdSAKMhEYjsQxdI6nh3DdgtaeqY0T/yS19C5Ozi9opjbKBSs4PB6wz5ehhbUyi3TmE/jqa3bPYr7LfViKHD/lkcucBW0XCGA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DL/4RU8ga+O/ynjbp7ttMwZnaHB0wh1OA0hcnvMmlC0=; b=yqqsPgrOChtcBjyDE222aM+0ajmmQZLS3Y3LPg6OnvWHDDc7ezsLwCwkE1M5Os2ICz0rWuZm5B+2yr2CfuplWYPLnKcHNqFcYXa8wOSu3+1dhOvvNoY9fxOccBqup8C98uzu1sxm5AANjLX4q8caacErBJqq1L+4sllLTYA16k8= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:12:58 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:12:57 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 1/6] sev/i386: Add initial support for SEV-ES Date: Thu, 14 Jan 2021 17:12:31 -0600 Message-Id: <6403cdc0040bc07355b35fe56e26fb9cd11eb172.1610665956.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0601CA0012.namprd06.prod.outlook.com (2603:10b6:803:2f::22) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0601CA0012.namprd06.prod.outlook.com (2603:10b6:803:2f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Thu, 14 Jan 2021 23:12:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e5947bc0-205f-44a6-6f79-08d8b8e1ee67 X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: 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: 9x8VQFwLp8Qgiu7OJC4v2Kz/yA+FiQ1YYkWsiZAaS1WAhwq9xoR5UYAbuGaPBZsw5egW8rDWO8NYwWN2m9JISYtf3ANQ27oz9vX3XD88xSKCHpJWiBy1rVsjwiQvAF1C+lg/TvKqitMgv/xohZEhhtimGdfbU4uBLsC1UpI4BU5emqXwWwXHAQr+v8vM+wOM1isw5ipbPcQ8l66Y5jm4GIfB0JCMkzWlYVd1C3uPnz4KB9SlMyWWr3n407STTmAOy2IC7aiv/hp9g/aqjxLwt1hpNgBzXaFa3u3hiOnyY9Skc6xKnnMZDGTRV3MKfSFHlAYqdfBcU00Sm2FjV9vj61LwbbeQQt1j9J808ctXjmE2LXZt8H8ZH1v5tkO35ziaI8G+bjqINiVbUaWPZyfv+ETMmnLbfyLb4Bp+NUpeTeby/i80Rt5LZApj+q7msykB 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6666004)(6486002)(16526019)(86362001)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(83380400001)(2906002)(66946007)(8676002)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: p0EVQdWvteJu7VknEvfarPlXwS4/vYY8mzEUyn3N07PSCS3PCklYW4ArT0AW+vNLG3nXquzpkrEmvOhTe+DNXzKGDtiGRWinA9E3YIKZcG1S3WXlZP+i+IDbrbWsRmZQgvUf0I2hBxalU2fg5SgY9mpTeMPRrSKVbvbj5H5q4N+djdy96tAh8FVpmyyuLaaSm78myx+NBrJyuJTmlVxm9qXQSyY/N56xutoOxmryuEzJF2JGYAQ+dDLNR1IjIR69yqx1AKHHY0yV4au5ulrWUHu1MNrOP31XbJxFtR3RLYRFm1NcryKPYh7A1GXZZyM04nDfLkSZu7R0rTH/KupMS2OKfH9AMLj9yarUbxuNaBdVEhTPOKR3dgkJpUL0s/dqc54Oj0SACopWAjdLRTm4XAwUVad6UfSa4NOtcHjqikTqv/AF60MemxhdqlVeoKIDzpM5IbXPxHQiZs18wG6TtzxE/4KagqH9z43p6yF/9wMs41AuxNWzWvCG1c7Q7E2OpozhA7uJeu6TqxLrEFHnNCxCydkVTYovvXIHpQ6pQzcA+K5mg6gwwd+mbWNR8qHtgRvREijRJ521G6uHSUOtw/t6W6EGfOfNpoV3P4/I/lLJsL2du5rw88DsceZWYq718C1bbJFCiavVNK1TqGE9ccPY9TjqpZzeXOTugh/kYP8NypzZMgWCu3Hd1xe/Y+ra8sfpzNvlDsHCbSDIKf8YMUlwWX4TqYixXdr38YBaTHqCDVMNGAdlI0Y9fC/WW8SdkNMy4obKtihsphNaxVThnrO4xfQfQ1F2qo9KVj4cceZcebh3q+Yv7U62WHvcSZWk6/jvLviO/80SDYaNNJaQJ4Wa4gZar/4xugdWHS7SaF6n/UYz+Wq+f0zVSwkjyXMm1XcieyKhzP0x2s7THnrRHzOmDYueSAV9kmDKTGJEFEDtAJ1LFvk5JPBI4AbzHHiFspVINJe9FFv7c4lwnuVhXKPle7i8Nbxbyfdz6Ownt6eSDIp7ebnYW1ha87B/cwUb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:12:57.9164 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: e5947bc0-205f-44a6-6f79-08d8b8e1ee67 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: L9vDIk4ocHWjB/hvaEMqgVwmHH4BNqRji+y2nllxhnulwOdk2GIeNIlnEm3wXG5tZYKpYuAZ7z1HrrXCjx6iwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 , Sean Christopherson , Marcelo Tosatti , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.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. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Co-developed-by: Jiri Slaby Signed-off-by: Jiri Slaby Signed-off-by: Tom Lendacky Reviewed-by: Dr. David Alan Gilbert --- target/i386/cpu.c | 1 + target/i386/sev-stub.c | 6 ++++++ target/i386/sev.c | 44 ++++++++++++++++++++++++++++++++++++++++-- target/i386/sev_i386.h | 1 + 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 35459a38bb..9adb34c091 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5986,6 +5986,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 c1fecc2101..229a2ee77b 100644 --- a/target/i386/sev-stub.c +++ b/target/i386/sev-stub.c @@ -49,8 +49,14 @@ SevCapability *sev_get_capabilities(Error **errp) error_setg(errp, "SEV is not available in this QEMU"); return NULL; } + int sev_inject_launch_secret(const char *hdr, const char *secret, uint64_t gpa, Error **errp) { return 1; } + +bool sev_es_enabled(void) +{ + return false; +} diff --git a/target/i386/sev.c b/target/i386/sev.c index 1546606811..fce2128c07 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -360,6 +360,12 @@ sev_enabled(void) return !!sev_guest; } +bool +sev_es_enabled(void) +{ + return false; +} + uint64_t sev_get_me_mask(void) { @@ -580,6 +586,20 @@ 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)); + } + + return ret; +} + static void sev_launch_get_measure(Notifier *notifier, void *unused) { @@ -592,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 */ @@ -686,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 = {}; @@ -747,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 Thu Jan 14 23:12:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA20DC433E0 for ; Thu, 14 Jan 2021 23:16:21 +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 29B3023A59 for ; Thu, 14 Jan 2021 23:16:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29B3023A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Bqm-0006Y8-89 for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:16:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0BoF-0004lv-1r for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:43 -0500 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:64385 helo=NAM10-BN7-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 1l0BoD-0006I0-5M for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NNX0azJHSWBExM+aU1CjBdlTQrDlU8kBtpn+q53UOxJdRKxwGm7dvqrGEuqw+e9fy+Ht+sEWrGU0lYTzyd+pBaFtIgJ+bXa0G7hoBIu+oB+Iganu2Ju8ZLWOoFwkgKakn5X2GP4AqP4G5jwIxOmmVHaem2BfzCifG1Duu/M7sHGBnjcyj5yaxn41UTdRx179lcBOX/z27Y9rPGxj3tk3xsHFdivAdD743jDgkGCSEn3QxRfoV0n3l5HIAx6pwELMjpVbZeNcaQetojGrX8zSSGggc2C/giykJu3e8pclSYr3QSBQHg4M40MTmz5Qkc3Qg0+vg2awE/69VPP9x92TXA== 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=RR4A/N+dHdf2kJUGloeATQgrbAqV+8e8m+BX5sC3A4A=; b=U/3OeRjstt6yQnqR/TyDQs7AJAvk8ZJQ/4w2kgWIxzLXryihVZ338VTY3lbTHKeAAdSlUfQjyXzqXkRw3bO8xRMFBSbc8MSeYgfi2dh01hVlTnxOiDeVwa8Kzl1mUKEF6MmVV8RFiNiMw+0uIB1ngJRpfNykACwK6SV0HrGZ5tbs/AjTUqRW4QCw+B914Kad7NVUTiRTIOOzjzNZAApn5RO/3gmMHGFD6wOOthe5VJoio7pURWw9DN1UBrGAGlib3e38J8S7l59gnjO0nphsohN1bnuX/eHKq6ciBtXonuuKIp//iwVflDtZc9pi1vSVWpyUP+G0bN8y230pivB8GQ== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RR4A/N+dHdf2kJUGloeATQgrbAqV+8e8m+BX5sC3A4A=; b=wNCtIH3O+yjaj0suAO8QCRpTOS7oLg41EUNHw74fDQX7Yx8a4zno6CTESWuNQPEC5v8Pwe57s0jgB7OhGKsrdN0IzV4dPEzMcjfCPDccd/5zrkRTg9+9F5rqPdwHHeFBr42TGybeIkqgJbsxsfukYBTNfatMPaKd3FxooOsD6A4= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:13:06 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:13:06 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 2/6] sev/i386: Require in-kernel irqchip support for SEV-ES guests Date: Thu, 14 Jan 2021 17:12:32 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0501CA0145.namprd05.prod.outlook.com (2603:10b6:803:2c::23) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0145.namprd05.prod.outlook.com (2603:10b6:803:2c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.7 via Frontend Transport; Thu, 14 Jan 2021 23:13:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 293b86f6-64ba-49b0-755e-08d8b8e1f34d X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:989; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w1NTPYAPG1WqH1FvWBuOoVuioeIl+9xPxzxjMTRkVXyJ9fV5PhxhLuH79rJCdmrH/Q+97li8rtNp7PZk94AyI778cBMn1gxAVMXz7r3mEXWHIIRQk4oJJ6ov/p2SQaYIh/eDHBvCqS+iaohm9gNgRNxuBt/WmLSrLDzv+3JRofCyiRN8JAPUfXXhmGRhL0r4RAqQmyXvQiXTY7ENxPpQnV2gn20PqVB/wo1vOazNHojrmuB5UNdxinV1Vj8r0sdNyY8ZBSLJNxUJ3zGQ/I2v+AiGMOcbPUxsvGjFFpuN0PtNhLj/ldYfIstGnIrvGncre0c2/0kHIBIXnOGfe22VZTeBLnJ8nJyWuguZnJ9+dxihBMjNuk92VBtmitRXnuMJAMS/qKYH29fzvNlHXVsBWg== 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6666004)(6486002)(16526019)(86362001)(4744005)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(2906002)(66946007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Q36mazhHSNpcvsnvVbFgVaFKJwF0xQUhFA3+EWZPv72+OVHw8bM0XjeAtFo0w42AOVVp2dK5HjtxxrrZhVwZDDfemHcCZ+9VZgC+8iXwGpSRPWCNrycU17Blp/UGQkh+92SeX3D+ghW10KS/Gyc+uyiYFNGJjV97MX2CrvFXSgqrJcNhzcK9EVQWvRm1kL/S/7q4sS9apgCjgBTcoH+Oqor86I37g2sOe3W0JfKdVQ48lLVPnZ8zKqsmcFQh9ARW+plk3qozgXw8ktyagiDguH/gBDFW1rMWNYDoG8wZ7bs8Uejpz7UTyra0z65esIK1Z5F6/9tHzjo7YjZkq9cGmOCasJq+9w+oLv9bOTToOkxhQ5w3Fiu5zzeJOaweGqEShh0rMSMpiU0yFWu+Rif+VQU+oee1V7GURCommb0utJ5Ym6JOxZKDQuRIV3nOxC6ePqSK3Re9FC87XDusW4aL9VbjNCiEA1toLnixujYYWEiN4rhF/0lT7OSkZrZFZB5Sfs44ctBMu8E9S/LHZPcDksKSrBapgVHhuhUgpASaA7YPV4+838dOBc6aWJnF/CNnPfAJ2hFc1lT0Jm9H2b6CVGAH4nkhxdhHSvbv96BVR5Ya4MEYXiaNFMzxV3HERkqTeDjThk0pwp54sNvd3VjSCPpe8xBZnC8HwqBNcKA06n4H0oBGL1zRiCu898h81GVKi2mhfjVr1CZqTlxunTxRK9I2uhpFNLA06+TJ7t4UTSUMAl3Q6dJ/nPVH/DscKOJXyFbglh+OieRMX/2PjGKvFC0L13be5q2cs9YE0IiwB+NX9lLZHJOVHLSU+d+p+8rAUi6v25qi24fahEYExf8FHuOB5ILsVS5F8pjeAHyFLoWToqBiyHLbC0zIcUHAIIJwJtKFBp+MJxrKLEQRVmEEPz5ZE/x4jNf8PtzAUc8TN509A354cBmG+KtjjGodTUWUvJIrh//qlIahzwL4JgGuSrB5dwDo7EKndRtn5E47oaWHsDQ6p4k21yEMTFqgRyiQ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:13:06.1237 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 293b86f6-64ba-49b0-755e-08d8b8e1f34d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u77riJCCjeIqsU9n3PiJ1WendN5pC7WmvWRZOfKZDX+hn8H1yb4LnxBV+UdWmgObJedRem30u9yd/JmQXtC0xA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 , Sean Christopherson , Marcelo Tosatti , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky In prep for AP booting, require the use of in-kernel irqchip support. This lessens the Qemu support burden required to boot APs. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Signed-off-by: Tom Lendacky Reviewed-by: Dr. David Alan Gilbert --- target/i386/sev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/target/i386/sev.c b/target/i386/sev.c index fce2128c07..ddec7ebaa7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -776,6 +776,12 @@ sev_guest_init(const char *id) sev->api_minor = status.api_minor; if (sev_es_enabled()) { + if (!kvm_kernel_irqchip_allowed()) { + error_report("%s: SEV-ES guests require in-kernel irqchip support", + __func__); + goto err; + } + if (!(status.flags & SEV_STATUS_FLAGS_CONFIG_ES)) { error_report("%s: guest policy requires SEV-ES, but " "host SEV-ES support unavailable", From patchwork Thu Jan 14 23:12:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94ADDC433DB for ; Thu, 14 Jan 2021 23:16:23 +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 37DEB23A59 for ; Thu, 14 Jan 2021 23:16:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37DEB23A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Bqo-0006dG-1G for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:16:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0BoJ-0004nS-4C for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:47 -0500 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:64385 helo=NAM10-BN7-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 1l0BoF-0006I0-8u for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:46 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NXDKiOqwTU2qh4NMxiUbM3CnhjI0jk3xq9y/6mzyFI1cRy7/Wn4ncKFE1E6ipjZv6B6jcFf4PmSBbQl/HtIOc0ojm7WRZxxy4cnoxkFKTSTZA+gO2hzftqdV1Vy7ZZE2ViOhj0kDi9dwsDPZ1nxFFlCJnFc74Bj6+X0nSeFvgWqWV7b5Cybb6hVDRmuIQrLNLC4piOZAu0/L3Wm3zlApR25FRqcG8stwq/anFjCOhrh1mtZxlhYMN+p+Q9pZbYV39ieGBIlXwpfbdzajZZU8PR9J+RPp14Y+ntz+/3oGPlLqWosH+bHsm4yerU5ke9gRsqC0WlxpLzsdW5keJM60gQ== 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=Bi/qRjxqO3eDHwVtQw0kC8+ET8WaZKTRPyDGmooVHfM=; b=DGizj93BfGQduL9O+hLDuIQ4dt56990QuaxEt6cNQAv/KIHsEDWehqf0os0GFr3TmTbPxYs0Id6cJ9fjpkriYATB6HYIn05/ddG0pdbJwebx0p0DREfYwoMOxfbVKYcxtpK00/vzJ3aD15T0wY602/7donRBJ6UvODroFSJOklNOqvs+TS1DVoutTGAiaA0osuzZ55yFbKdfcX32b2nxF9NBW0lJOxHYUlauo4K3xBUR3+Aow3RuN/4lS12Z7hmXgwba0FS+7o/InQSz44BQCN9s8wS8XEwn0EX4uAuXsWNuC447FXDClcCiqRScyl7kZDEQ79K3XCSeRpc41C13VQ== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Bi/qRjxqO3eDHwVtQw0kC8+ET8WaZKTRPyDGmooVHfM=; b=xM8dzoCiRCY4V1ALQs7HHSyHNC95lTObxUh0Hb3kcuONBvJL+uMYJDoKOU8pnil0Utsr5aGZUX4teAPidyzJcirulDQ8vvbiX/0oqRSOXAW0ymY624ugpw8gGHm3uxPnFwq7rJpkSBkmGIMqkhl/xmCzFdf78h7P2MX+IF7h//U= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:13:29 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:13:29 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 3/6] sev/i386: Allow AP booting under SEV-ES Date: Thu, 14 Jan 2021 17:12:33 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0201CA0033.namprd02.prod.outlook.com (2603:10b6:803:2e::19) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0033.namprd02.prod.outlook.com (2603:10b6:803:2e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Thu, 14 Jan 2021 23:13:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4490e5e2-60fd-4a04-597b-08d8b8e20151 X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oEzcX+N46s94k50QLNJ5vZaiyEj8Szxz/Y4vFBR4mXWN2mwMmtAADGTSsbygG3Ec/zIWZL2wbQ7MQsthDeHLNycbW6t385mUI4ILzLKTD9c8TpcPGl6Z8HULE94AhTwKirBAocjcGuZlK0/GWVED/oGHUvSGbVJ2HkfWQHqBhXZCqhLze0FcUT/pPURBQA+iLBesik4SmbIozyfzPjzHDIpeMPtCN9nQoYSBCuI9c/5PKTsb2QBvmj3GUtaVYSUzzOSpx5JJAzLtYGm2Y8T20IeRE08WXLAuTkg/yzrfjclgYSdsjkBCYXay+5vFQavUpQ9lJv9XuRGwWEeZWDm9TeryuSx6OTkOW50Z3LoOBdNdmlCJA8FaqslvDh9u0d2R0cNUImlYjSS+gS6+kNpzMg== 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6666004)(6486002)(16526019)(86362001)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(83380400001)(2906002)(66946007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Ui5Iw75OwaBHB65sVHYvBq0xNc2N5DpFlM69e6rt1OrEOPyPTXcf5TQxqpV1ewBjg1OhMIogeFvyXtbDrukQOupcrGKc08o1epUgX+2PQL1+XR665kYD7AREZlPRUyw6yHpji7R4TmmVsSRITvxzCBNDJpvKaJXgGMswcWS+Ae2A3F2eudN5osCJbjYz/z6WvhXY5Dag2pmv7YnvwZi4hlWvQqQopan5+6DLtRl9Lje+b1YgFn0wrEG6gHmDXi/oA1oZGhR7KfcTK7DHQ9lwvbpf7/450UoojiVAPxm8nyg/SNaxc/9J5sBUiku8uFna58wpySQUmTiv0G2iipRxxkFIEdlIaCcoYaoNyeuJ7NfYruO9wNJvPUjlUtGWSfKPMsuvqt0l4yceTZ+H3tP897eQs4He8jjcyjrVkQ5bET81SANXWNWk4VNszIgzg62tPrtPu8DujK0BJrli9tclpWJHhZixpADb9nE3jBq6BiczsbKd+qGxD3T+3pxD6BrDYMjFBwRrkivBcWAqmCeZP6B5U5cNN0S5Bg7FeqBPWzOIxkChDSBzZdNy6a8++8McbwvBrcyalQuL7Eebk9ExJ3d3DgQqBi6av59BTG3gTBYkmYrMTbHe0EHoaGaRDJKIo4ffk8smGVRdvF501pa6KwW/yYU7XalgOUeu4qO7ZWzO/PKFbdcGbc5uA6liEDd1MtjYsy7FwS4m32mzM+wu5lfjdDIUZxqGNnKhOm8P0lMJvKJjH8ZVtmW59miZRElHHypnxJ0UMZhcukho+JlcRTbvmJWTijvGmgwVfxMyvCmfRCaTHc8hI+j8ATCd5cg2rL+OyeMNCGh9QIYYNwu5dOS7sMgxHeuVQNoBe5me8R9loZ5BWeBUf4ECGsv7cUdVq/5xMMuU4IxAdeA+bCsWn14yNh2KaE4iBELWmvA4tL5QcpbuALKKyicRzf9l4DaAJQs5ozSXIScIF18AOhy0bFw1EEim0k9IZoaL3apchx7/D4wFculhajvipy0O0wQG X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:13:29.5853 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 4490e5e2-60fd-4a04-597b-08d8b8e20151 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YJ0RmLZzYkH9OkiCbZ5y9xkaQYMCDtzPP5ICVvJykqWH9QOIDPoAtMVNGE1hndG6ji5n265BfDzAeLwJh3N5lA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 , Sean Christopherson , Marcelo Tosatti , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.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. Search the guest firmware for the guest for a specific GUID that tells Qemu the value of the reset vector to use. Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Cc: Richard Henderson Cc: Eduardo Habkost Cc: Marcelo Tosatti 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/kvm.c | 2 ++ target/i386/sev.c | 74 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 173 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 389eaace72..9db74b465e 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" @@ -123,6 +124,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); + + uint32_t reset_cs; + uint32_t reset_ip; + bool reset_data_valid; /* For "info mtree -f" to tell if an MR is registered in KVM */ int nr_as; @@ -242,6 +249,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_data_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_data_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) { @@ -2213,6 +2276,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 680e099463..162c28429e 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -91,6 +91,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 436b78c587..edec28842d 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -248,7 +248,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); @@ -301,6 +302,13 @@ static void pc_system_flash_map(PCMachineState *pcms, * search for them */ pc_system_parse_ovmf_flash(flash_ptr, flash_size); + + 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 bb5d5cf497..875ca101e3 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -249,6 +249,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 7ab6e3e31d..6f5ad3fd03 100644 --- a/include/sysemu/sev.h +++ b/include/sysemu/sev.h @@ -20,4 +20,7 @@ void *sev_guest_init(const char *id); int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len); int sev_inject_launch_secret(const char *hdr, const char *secret, uint64_t gpa, Error **errp); +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/kvm.c b/target/i386/kvm/kvm.c index 6dc1ee052d..aaae79557d 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1920,6 +1920,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 ddec7ebaa7..badc141554 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -22,6 +22,7 @@ #include "qom/object_interfaces.h" #include "qemu/base64.h" #include "qemu/module.h" +#include "qemu/uuid.h" #include "sysemu/kvm.h" #include "sev_i386.h" #include "sysemu/sysemu.h" @@ -31,6 +32,7 @@ #include "qom/object.h" #include "exec/address-spaces.h" #include "monitor/monitor.h" +#include "hw/i386/pc.h" #define TYPE_SEV_GUEST "sev-guest" OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST) @@ -71,6 +73,12 @@ struct SevGuestState { #define DEFAULT_GUEST_POLICY 0x1 /* disable debug */ #define DEFAULT_SEV_DEVICE "/dev/sev" +#define SEV_INFO_BLOCK_GUID "00f771de-1a7e-4fcb-890e-68c77e2fb44e" +typedef struct __attribute__((__packed__)) SevInfoBlock { + /* SEV-ES Reset Vector Address */ + uint32_t reset_addr; +} SevInfoBlock; + static SevGuestState *sev_guest; static Error *sev_mig_blocker; @@ -896,6 +904,72 @@ int sev_inject_launch_secret(const char *packet_hdr, const char *secret, return 0; } +static int +sev_es_parse_reset_block(SevInfoBlock *info, uint32_t *addr) +{ + if (!info->reset_addr) { + error_report("SEV-ES reset address is zero"); + return 1; + } + + *addr = info->reset_addr; + + return 0; +} + +int +sev_es_save_reset_vector(void *handle, void *flash_ptr, uint64_t flash_size, + uint32_t *addr) +{ + QemuUUID info_guid, *guid; + SevInfoBlock *info; + uint8_t *data; + uint16_t *len; + + 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 on its own (original implementation) or within + * the Firmware GUID Table (new implementation), either of which are + * located 32 bytes from the end of the flash. + * + * Check the Firmware GUID Table first. + */ + if (pc_system_ovmf_table_find(SEV_INFO_BLOCK_GUID, &data, NULL)) { + return sev_es_parse_reset_block((SevInfoBlock *)data, addr); + } + + /* + * SEV info block not found in the Firmware GUID Table (or there isn't + * a Firmware GUID Table), fall back to the original implementation. + */ + data = flash_ptr + flash_size - 0x20; + + qemu_uuid_parse(SEV_INFO_BLOCK_GUID, &info_guid); + info_guid = qemu_uuid_bswap(info_guid); /* GUIDs are LE */ + + guid = (QemuUUID *)(data - sizeof(info_guid)); + if (!qemu_uuid_is_equal(guid, &info_guid)) { + error_report("SEV information block/Firmware GUID Table block not found in pflash rom"); + return 1; + } + + len = (uint16_t *)((uint8_t *)guid - sizeof(*len)); + info = (SevInfoBlock *)(data - le16_to_cpu(*len)); + + return sev_es_parse_reset_block(info, addr); +} + static void sev_register_types(void) { From patchwork Thu Jan 14 23:12:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BC5EC433E0 for ; Thu, 14 Jan 2021 23:18: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 BE54723A59 for ; Thu, 14 Jan 2021 23:18:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE54723A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0BtF-0000wP-VZ for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:18:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0BoN-0004qT-2s for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:51 -0500 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:64385 helo=NAM10-BN7-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 1l0BoJ-0006I0-An for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+E4mAwMlgoIDpMfAu9axNdDQ0aEF26c3BF5isPaYjyamrUipkqQlLUYfevLVf+rggJ+NkRzO6K0xWXM9uf0YwY7t2OSclPmjvFx7GJLNBiicosf3eJn9hNfsmUX1Cu5+/rjHsAifLawOym7UeqxoMGPEsD2Y+y8NRe8tDylCEmv9atmiPMdg7EGslV9tLC6+RjJmM9xoNM7Pr1nC3VdTywVYqKqWaOwoB+GUfeI5koScswdW+2qj966yFf6gX3D51qrMJlLE7gKGUu1wFkmw/xWwe+gCMQ4VTXQiyghKNH4VSyp/4LKAvEK/xiBgWj/9SXyJiYdXhJdoLXuTrIIUg== 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=8MJM3MwcQCi6+TtCwbqmYr7g5OpsCa+GYvXki6dgeA0=; b=gl3q/jItqs7gOPd+aTSx8cxusC4PwQ/1s9gdcT7Zj6XAaINZocQdRsTfT4G147iEjSaEB1wE8ytVksyTKm4JxKdz3T8GAHEqNdjFqWZbhbKhe4D77AT/hd9K/VI41VzRUO8cqXD6Qgq0qT5e3R4xvHCBIQw2sjWAIkM4WBGv+l/e0oNY8m2F8bmRwrXBVz9A0hbANtNCf+/meFK6bYbvbhKsktmUBjsyEdcJ/c/vDjickomlkgRC7nMLQb7qVTdiar5Yz5C8b8GMTS1Hxz38EJala/Q1FwpljTbM8i/CHldaurDwYVkNAgTjtWZe7GanhrGEx8PtrQLhgwfmMppF5w== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8MJM3MwcQCi6+TtCwbqmYr7g5OpsCa+GYvXki6dgeA0=; b=FL+I4nqCIadYCCTL2K8KHo8fdlaCTMPmiWXXeDJU1fRiUalfkW6s8tPFXU527LR7/J4lfTSU9cEYBBwKFvSdud+GMn0cZrJo4eC/LZQt4NvPO61itUMuWFJtJbNB5ikKeegF/UKrX1ZttS4SdRfKoLqnN1oGHE8ZmPIMso4/cOU= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:13:38 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:13:37 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 4/6] sev/i386: Don't allow a system reset under an SEV-ES guest Date: Thu, 14 Jan 2021 17:12:34 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR01CA0022.prod.exchangelabs.com (2603:10b6:805:b6::35) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR01CA0022.prod.exchangelabs.com (2603:10b6:805:b6::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Thu, 14 Jan 2021 23:13:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cae84028-a466-4b93-2f8b-08d8b8e2063b X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1002; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4e7lTdf+WITIgLcuNpWmY2pKPlgf3+GdiFiQT8BCl0QMb8nZoQKPjpy9cDTIfUM/ccRF+0yWpDbXNG+02yiGEqvUBXM/+3IymkUKfzcI9WoidNVC/8vORNhRAfjDlusMtA4oDb4lSqAMyMGOvTA+ZQXen71D+1jkmfVGD0lmuY87b/uXOaKZV+NkzprDXRvaOYkRNwqzPvm2rcsmzCpfYdvc/kuhg6gwS0ICn2aeorigSnvdAvEZFPPK5LBP4Vpv1SUhpgf4nj8WZxhv9KQa0iUkEiMeuKxYT1DlGSU4vwErDjRxrMpypT0v6s8q1OwWN4WAV7W5ThHmwIRH6xjr2h2prxY2UPoTTVL+zjf148T1zrPD7VcMMTkOAXF47hoyyZET8DNBLrnZAF9do0oApQ== 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6486002)(16526019)(86362001)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(83380400001)(2906002)(66946007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6KToolttX1keJDcG4TF5TU/gl1g316BF3OyLt0gDataIkVfDgxgCmNEZ4RxrbW0oPuA5JtYBb5TD4AXtBeNPf0DCABz+dQOVZFJHu9SwIVx4zV7Nfw7PbccrT65BFYnhX1Oif0J67MsQtnwFJTbOECLqoeqSkzx7+PidrQaEARliXq7akyDQMWCcil+NgMVgqLz7fdvuoDBobLsQA5lQ7eF2WVX9b0B2LdHyYheZmAmqxQ9+XvkU/QBlhJ3BlEHN6feNJIFsX+hN9Z5V0GIBTqAnnlv/84RoYLcyewbcT1BduVislIv9hrUBi9kldVAxnGuXMGFjdMsWlf8CTa7v/CNLamKVSEI8XwXIavIcXmZz4/dbxnHHxi5nw4RegGydQk961yjxpdwd/EHQJLOpBSsR9eJjsOJmPXOWtqNLronf9dEid5A+wGxnLwees9mbLDxkUu81UImnN+VfxxxM6nMni2CTSiX0JlvR76YMTR3cXarODglhFW4uzjFym9kbNMECw1xxuw4ROp5pUUfpRqE8BNO4ri9QVdjZj75oPs4aXM8UcdtVS2ttNjeMgIl04gBpvH6sJEGZcaXYVymuBBKaOXKmX9MGbLDVgp/RX1uGsDVidQJ2wIk8o5qh5K5j1RZo96uYIJ2PrGDYDXE24l842PJXrUNOVSrYzkFV+kJogaFuMIw7adqnq1kerP9mLooVq5+gzGVDUhLb/Gq241TIYeYB+kYb7r/D4dGesA4CmJ0HZCvB566tVAUWDxdk5uamA4qC3EmfXYui4/frDCV6kFALxnzTbqV/8mnqowR/NdSbrkxOJjo08SMPOZZvcf6tpsO0dYXrVM3XLWNZFisqUWQOeaN9Jgh96/iCpsNC85wV0fVbPeySIBElCQlbVEEfGypcKk85YR3q3yuUevsjxDZrk6aZO7v5jLzg+MzQO2+UxoARamy3nqopMRSlZQgFLoA2EnaYf3+tqEoyh6LnZFID79Xyat8PcS7xDqaC022Rit/ALITITZSLCzAA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:13:37.9087 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: cae84028-a466-4b93-2f8b-08d8b8e2063b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7mJgV5SXt2IiZwDF5QZb+HfiKC9od8VaY9Z76iKwYzqV7o94gKJwQMOxE1RmIdFhurkJwPB3wiAIKSNyhP5Htg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Rikalo , Brijesh Singh , Eduardo Habkost , "Michael S. Tsirkin" , Connor Kuehl , Sean Christopherson , Marcelo Tosatti , David Hildenbrand , "Dr. David Alan Gilbert" , Paolo Bonzini , David Gibson , Jiri Slaby , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.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 an SEV-ES guest issues a reboot command, Qemu will reset the vCPU state and resume the guest. This will cause failures under SEV-ES. Prevent that from occuring by introducing an arch-specific callback that returns a boolean indicating whether vCPUs are resettable. Cc: Peter Maydell Cc: Aurelien Jarno Cc: Jiaxun Yang Cc: Aleksandar Rikalo Cc: David Gibson Cc: David Hildenbrand Signed-off-by: Tom Lendacky Reviewed-by: Dr. David Alan Gilbert --- accel/kvm/kvm-all.c | 5 +++++ include/sysemu/cpus.h | 2 ++ include/sysemu/hw_accel.h | 5 +++++ include/sysemu/kvm.h | 10 ++++++++++ softmmu/cpus.c | 5 +++++ softmmu/runstate.c | 7 +++++-- target/arm/kvm.c | 5 +++++ target/i386/kvm/kvm.c | 6 ++++++ target/mips/kvm.c | 5 +++++ target/ppc/kvm.c | 5 +++++ target/s390x/kvm.c | 5 +++++ 11 files changed, 58 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 9db74b465e..9ac44ad018 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2411,6 +2411,11 @@ void kvm_flush_coalesced_mmio_buffer(void) s->coalesced_flush_in_progress = false; } +bool kvm_cpu_check_are_resettable(void) +{ + return kvm_arch_cpu_check_are_resettable(); +} + 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 e8156728c6..1cb4f9dbeb 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -57,6 +57,8 @@ extern int icount_align_option; /* Unblock cpu */ void qemu_cpu_kick_self(void); +bool cpus_are_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 ffed6192a3..61672f9b32 100644 --- a/include/sysemu/hw_accel.h +++ b/include/sysemu/hw_accel.h @@ -22,4 +22,9 @@ void cpu_synchronize_post_reset(CPUState *cpu); void cpu_synchronize_post_init(CPUState *cpu); void cpu_synchronize_pre_loadvm(CPUState *cpu); +static inline bool cpu_check_are_resettable(void) +{ + return kvm_enabled() ? kvm_cpu_check_are_resettable() : true; +} + #endif /* QEMU_HW_ACCEL_H */ diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 875ca101e3..3e265cea3d 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -573,4 +573,14 @@ int kvm_get_max_memslots(void); /* Notify resamplefd for EOI of specific interrupts. */ void kvm_resample_fd_notify(int gsi); +/** + * kvm_cpu_check_are_resettable - return whether CPUs can be reset + * + * Returns: true: CPUs are resettable + * false: CPUs are not resettable + */ +bool kvm_cpu_check_are_resettable(void); + +bool kvm_arch_cpu_check_are_resettable(void); + #endif diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 1dc20b9dc3..89de46eae0 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -194,6 +194,11 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu) } } +bool cpus_are_resettable(void) +{ + return cpu_check_are_resettable(); +} + int64_t cpus_get_virtual_clock(void) { /* diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 636aab0add..7b4f212d19 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -523,8 +523,11 @@ void qemu_system_guest_crashloaded(GuestPanicInformation *info) void qemu_system_reset_request(ShutdownCause reason) { - if (reboot_action == REBOOT_ACTION_SHUTDOWN && - reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { + if (!cpus_are_resettable()) { + error_report("cpus are not resettable, terminating"); + shutdown_requested = reason; + } else if (reboot_action == REBOOT_ACTION_SHUTDOWN && + reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { shutdown_requested = reason; } else { reset_requested = reason; diff --git a/target/arm/kvm.c b/target/arm/kvm.c index ffe186de8d..00e124c812 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -1045,3 +1045,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; } + +bool kvm_arch_cpu_check_are_resettable(void) +{ + return true; +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index aaae79557d..bb6bfc19de 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -27,6 +27,7 @@ #include "sysemu/kvm_int.h" #include "sysemu/runstate.h" #include "kvm_i386.h" +#include "sev_i386.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -4788,3 +4789,8 @@ bool kvm_has_waitpkg(void) { return has_msr_umwait; } + +bool kvm_arch_cpu_check_are_resettable(void) +{ + return !sev_es_enabled(); +} diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 477692566a..a907c59c5e 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -1289,3 +1289,8 @@ int mips_kvm_type(MachineState *machine, const char *vm_type) return -1; } + +bool kvm_arch_cpu_check_are_resettable(void) +{ + return true; +} diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index daf690a678..f45ed11058 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2947,3 +2947,8 @@ void kvmppc_svm_off(Error **errp) error_setg_errno(errp, -rc, "KVM_PPC_SVM_OFF ioctl failed"); } } + +bool kvm_arch_cpu_check_are_resettable(void) +{ + return true; +} diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index b8385e6b95..5c5ba801f1 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -2601,3 +2601,8 @@ void kvm_s390_stop_interrupt(S390CPU *cpu) kvm_s390_vcpu_interrupt(cpu, &irq); } + +bool kvm_arch_cpu_check_are_resettable(void) +{ + return true; +} From patchwork Thu Jan 14 23:12:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF763C433E0 for ; Thu, 14 Jan 2021 23:16:26 +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 9176823A59 for ; Thu, 14 Jan 2021 23:16:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9176823A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Bqr-0006kO-Ly for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:16:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0BoQ-0004tT-O7 for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:54 -0500 Received: from mail-bn7nam10on2056.outbound.protection.outlook.com ([40.107.92.56]:64385 helo=NAM10-BN7-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 1l0BoN-0006I0-AC for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:13:54 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SknHPJFSytA+pbAblFPvdHTItQjqNMvQ/FiyTgj+3AtbrYlTWMWBILTI4FrKaR4gbEwj/0DksxVyKW8Dn38exJ5yCWS3q0k1kLPsVXUA5OxBTNoTl+oishdSQDSivUoM9eSqW8FF9pU7fcFer86DqW8HtYy5VKCtBOMroQtDTDg+F7afJwcDs020HI7/AqLkSZF56N6xQZCCUAzn2wJteThzkrjnJwvDcTipDLaKQPKTaqLx7MErbwOyyhgjHPgiy+h25L1KEo1vjDNJZ95uEMRFcK+WLeWku8UOMCu4Lph6giUO/h7DQuqEjqokhs5gWFF85YM7Ooe6oufmNkQIog== 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=uR4/S7ATo2WmVto3ZLWqLM2d/h/9jnloCS7eA9/vH1Q=; b=CDZ1ipkqLk3MUnkRTXINv5FVkRH8H5KyBdQXEnEqgcDp3u2ZaJrVM/L5TKPa0c9rqIj0x+azrw82NgnUw9QN8Lv1qbEAJP7jlYmBhw5YHuWCXp+3eZFZO1+SggWKiO8YGfQfln0ya4N/Y1G9gNurYx5vIzZqkFUKgVRLUQaodguMgFoYMCKNjIYHyZeGKPTDVdK1RHiCrqBGMJZKkfxplrIIqBOLYEJY9Ovxv5BOwn6x9MMR020Uy0+GDoEFzO79/u6ZAqr/oLWJ3cCqheqbFkL67Q7QX6lvgugzW/g/055kTvwyhkUqlX0kWGbpizMZ8SCFJKdBwVWinJJqeD0uNQ== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uR4/S7ATo2WmVto3ZLWqLM2d/h/9jnloCS7eA9/vH1Q=; b=5l2SnoWAJb9kydjcnoyXAQf3KQGSn3IdRajWpCdpieNmamR6D6LLUKq/KaqLUUojbzSx1JUd5knfPkxLwis7qxwH2yV4CxV1GTOkjcVMTM1ZBJ9SR9BIXMjog2KcfxdoY42Q9YrmdnPAnDm2XVemDcPUJaFz4R6b2xAh82xliUc= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:13:46 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:13:46 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 5/6] kvm/i386: Use a per-VM check for SMM capability Date: Thu, 14 Jan 2021 17:12:35 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR2101CA0020.namprd21.prod.outlook.com (2603:10b6:805:106::30) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR2101CA0020.namprd21.prod.outlook.com (2603:10b6:805:106::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.1 via Frontend Transport; Thu, 14 Jan 2021 23:13:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d48aeb8f-2bcf-49be-362f-08d8b8e20b82 X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1oclUrQfFT73OTNkqcZYCwuKt2KqdvoTuBae/FBSr5pnyWHDqDrncs9fYhibh1NwAJ18zcMBmiNFfQ44as90u20ICq6WyXZeAx3XF1oy1rVOiQh6tX5aKSTLfjd1EaszbgvKEQj3Sexc2Wo2FCmG3FM88APWvqXRzoZ3KOdTUW8H5mw94Ig54LxM2PWMxcpIGHCCfOeoJn3lwSr+IMpVjVk6gZ6zpHD7oTDBrBf583myDf70ljqwEYGRHlphnQS3lFyYzxsQji3jQhHPROVVGiSOb8VJ77a9L4Vgz7WADLJD5k0lhuh1wKFDuDq0f92rw8Ukbybqzbzhwp9axy/sCHrRe4+hW+L++fjyOmg78Q1XdVLuTE12RoJ2qSNE1EJW 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6666004)(6486002)(16526019)(86362001)(4744005)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(83380400001)(2906002)(66946007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2S12Q9u5jRlGFckMPfpYNdIrMzrAf3visZtI73PvnShlY3arBKUkvZEaFRMTDUbdqJ70SJWFhahjdDwde6N69tSdXPCacG6vzANX+1gRLTkzf6E7dVTGg7UA6UiMa+4MLOzbSC0K/9FJ3z5sh6JZ/LeRZDg6gtpayVZN39XMxCohnIW8zQe3DM8srd0LuFr3wUiRyTSeVBk8j64b0086f4jLxPKYYe38e3ECMQYrMEvYpifxURCoFqDiE6tFCYDNWxtooEBbt/lvN6m66KMUj6veR44+QjP60Yv+oxhGbe0DtX0p0jTKVPVJKlgJ7kZ2RS7DeM+6wBTts3VvR/nUnCA5HM36uyEEZpV91A0Huzxi5V4+RB+R9AQCEMh+IKTcv3IlwvofAkcp1ZztL9BTdUVYIT2jHbm1kiqf/xJSG2v5xdCyqFyweY0tpFE+aW1inyAIOWQrd+essHw1hsrv+2Upg8oA16RTTslrQLvrNeTZCOx7TK9+Hrz/0sCXwn4RHW1OZ1cpSo3ySKRZ6gLn23KbC1zrLPn43QNxewi5/Th/dsrvbIdtey9ghj8JrK+zR6NKrc51NH+RtBBneC7JvoeLqnSDr00Ton/YQGeduuxJP9K1U2qs5J2/OkbIbl/h2ihVMqlh2dsnY+alph2+Fi7LcPfYOAv7oiol7lNHhuVB0h+YA15xCiFJSgx1goH0pk3cl4f5ruXmEakvZ0m1ifpv6tRciJQ9MOswY+c/i9vmHJRQ/FWqFirSz+6dZMXB72LjZmhBmHZGOvzvyJabJFCS/rreBUSx0lffZnMs1IhDwyeKdRVEXsknrrLd3KalVA2WWmP7f3VP/wkzM0f48pzqsPQfMo2+7ZTJ+Z9kNiIxmn7+XYzk2/aO8nOfWwN5S+FxFII4AWCPi5xoH/dRI/Kl5xPRPKb37fhVtyvj/SphbqjZ08CpsrWIyAV2OKjDjEIemIbfP5wEFrmV+rZJImDZAFSdqB7jE9VPp3O8XtbcstiKBR2/MGcvxOxsqJj3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:13:46.7218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: d48aeb8f-2bcf-49be-362f-08d8b8e20b82 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pS98DQ2L/k52nU8hmZGgcMBuaEmGO2BwqdcMcx+Ks7At7fMyRSfvBwE1sCzixW7/vQ6xojrhfk2nX6MTMpGE3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 , Sean Christopherson , Marcelo Tosatti , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Tom Lendacky SMM is not currently supported for an SEV-ES guest by KVM. Change the SMM capability check from a KVM-wide check to a per-VM check in order to have a finer-grained SMM capability check. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Suggested-by: Sean Christopherson Signed-off-by: Tom Lendacky --- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index bb6bfc19de..37fca43cd9 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -135,7 +135,7 @@ int kvm_has_pit_state2(void) bool kvm_has_smm(void) { - return kvm_check_extension(kvm_state, KVM_CAP_X86_SMM); + return kvm_vm_check_extension(kvm_state, KVM_CAP_X86_SMM); } bool kvm_has_adjust_clock_stable(void) From patchwork Thu Jan 14 23:12:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12021061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBD01C433E0 for ; Thu, 14 Jan 2021 23:18:37 +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 409D623A59 for ; Thu, 14 Jan 2021 23:18:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 409D623A59 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l0Bsx-0000t6-WC for qemu-devel@archiver.kernel.org; Thu, 14 Jan 2021 18:18:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l0Bp7-0005gn-DJ for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:14:39 -0500 Received: from mail-bn7nam10on2061.outbound.protection.outlook.com ([40.107.92.61]:29001 helo=NAM10-BN7-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 1l0Bp1-0006Y2-Kr for qemu-devel@nongnu.org; Thu, 14 Jan 2021 18:14:37 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l58y2zBBdQIQ6BDh2ccuigLQPxDXWZ05bqNFg2ljWfH0Tdq0vEauqBIhn63cTD60fWcmYngzKFGstoGXMOLHJ3mOpVIQY+3LlBG0rmdoWdQeWj6zVhKOgztaZTaqqu0rYDRLyUPmzs5Sh73N+WiaH9tNbLJuKKWb6oKk19T72APDd5NfMveuI9VXAGHJPLX2n/l6eJj9Gcfvoct2KdzjbWVh6ypfqpBrzgJDTl8KfuaXc5eqzEI+xuZqVsjoWteil0H4Fy6FGiy2GP7b+80ZhnBqql6Id/LCGQ9KDFGyePOa9csx41mBO9BbPR6uoIDyajWbPIoDBUSdnx/Tp9o3dQ== 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=a7yg6pbXOjy6pWpK7qw208nKUA0YEOXcTqQdNTJlFaU=; b=KKQ2AFj1Awh5vMga7xFbR5E6oW+S17lEDQCj0VgyeTKr/B5EZF3QzAa2QwTmudEefjHTbUd+AW+LXDV/qzg9ogXGyQO5q+XVSarZSZ3uFy1OgDy19SDKlSBg5fQaK4o0gLqcGePuDcW9CkmYyZrn8lfhoyE7gHpTr6Y984eYY/Vjm9kH07jYMVBR7NAwdzZik/ixKbwz7lLPm8rGMnBr9QkyFm0FgIc319ZWlM/ij35wYh2ML4Le/vpyoab+K1SsP6uGCC20HZSP4BughYKxsUq10RX1hpMcBcAKZBYkMeHoHkSLO+2XELzGRWQ8gE4p21YEViVe1MbfIt6cKfPaVg== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=a7yg6pbXOjy6pWpK7qw208nKUA0YEOXcTqQdNTJlFaU=; b=FOmdjW3a3iECjkBdxeO09AsGxMv6EcsKcyW9AXaroVMZKIPTZS10WX205/97k7RfIGZ+t9Cd0RyBvdk6yIpxbha6lrZhpSHcduZJi44tGyOn6aXoGRbK3FqE9vyx0iwjZNi3oeoVvyeAoD96HNICJ9Q4VzX7A47ZyeI5+cHU1kU= 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 DM5PR12MB2503.namprd12.prod.outlook.com (2603:10b6:4:b2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 23:13:55 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 23:13:55 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v5 6/6] sev/i386: Enable an SEV-ES guest based on SEV policy Date: Thu, 14 Jan 2021 17:12:36 -0600 Message-Id: <38989f30c7243296111352d769e4e184f3036cbb.1610665956.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0067.namprd02.prod.outlook.com (2603:10b6:803:20::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.10 via Frontend Transport; Thu, 14 Jan 2021 23:13:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4d511acf-fcc4-4521-a258-08d8b8e2109b X-MS-TrafficTypeDiagnostic: DM5PR12MB2503: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /aelx9WzHq/74XZiYITgIYqHGwdpkLuv0i6zQ7OYb2xK2iJJjfLZxHU5IA6XleIEJ0DUcw4n5gveDp65jMKGl1NAIWxYp6rE6/M9g3EGpRjxl2HgXb4z9fJhG4JOAOuKRv3A7BEpdxyeZI1US86jaL5S/ak5rUalw3SFtRXQBPrunx/COtFzsfqvtIotXAccuDZm/wSAZuZ6CEGWBsmkuNIEjvG5lD0PaM1/FAJ90OK87A9XINXuOO+erTEQc6MR73nEaQiTg0+mKiAQN9Y8J5js+d75/kljIioCiz9VWbQi1gINc4DwVPy6wtH0tk3BhBs0Oq/mKa89lTlMTY9vbUxp+/xLcIeqCWz8d2XroXBPmckKHB/gjoUxh3rEPpfqZ3MbEFZS1CawmRvkv5JdCw== 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)(136003)(366004)(346002)(376002)(396003)(39860400002)(8936002)(54906003)(186003)(6666004)(6486002)(16526019)(86362001)(4744005)(7696005)(956004)(66476007)(66556008)(52116002)(316002)(5660300002)(7416002)(2616005)(4326008)(36756003)(26005)(478600001)(83380400001)(2906002)(66946007)(8676002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: PHhcUXa+218O0hsX/8tK5ePsjgCOKMgF6VOXHpIEtUzarV6SCUR5jQ+4LWhhE/MpE52wCGpSbq0yX6mcXoeIIGXX7Mzu7ft5crg6MSgh4z95QJzfLE5NT/XPBExeGsyt66zAa+ZOCXT2cdHQo8m/Ji+LWaehZy+eEx3tdhHusBa38kjuR/qU5ZhGx+UsfA2gBx2TxGyRo3loxjoHLxvhbkXH602yI6JYkZVktYwXXG24uouwN5g4dt7HU02VPNkIxC23uwdtR7Sb3a5/cTReIpR4It3nDC843qIhxR8Pu4o9Q27TvkkXWCltPgy1480mckYWJDx4rkDaH87U2Faw/wamibOPhg/9KHVCi6clGQYLnh0y/F9/SqR+euTJw6rQPAxuZa1kUveWYbgrA1QEvySRbPcXU9Wi4apo+pRaSC2LoP5ltwoazeHP7+cJnMyfKzjTTDS6A2OjMS5ysX3ZcWyxibPkUJxT04srcox0OsWax9JMesH0ppgSHL+blhYiX3cOjyRDV8spsoARuoOxBaCurDBFnwlTwBwY/wCig3znAxFhdFXY2erOMO7gmih1KqCvc25tRuN1bgPzEGG/up7zYrIgPzPoM3PYdvdAbrXrrjW4z15Vl+tSBL73KqdWbX2CYCUvc5PuxBgGDC3GdlWftkKXivyt1JapghsoIafSyI4p0CC7YbT1ffpgMj92LuT5lxK+JGGojkUKY8g9U5kfGGGfuHNkzrYyc3N+OURg2Myr21Y713vL1VD2a2D1sDLqxEviBoz/GEYrhS9fCckDiCC9V+XR8okNSysiHM7vOFvmMTdb93yt5q7cyZ+lZiaLkAAeUmARXIdkEOl8JFxX1A175966ykPFTbQLjYmxyAP+6T/EmrxY6g/Isi6ISDkd2sZoaEoaab3C6TbE/KG2CsHyVhM5tBE4DOE/rb6oupNcQzwn93wYnM7WcDYjPsKp29Vd8RhGoX11FBxVahUePINYVyCVy1wbj1gMoMhYSMnqc5q5wEZmrcayGV7Y X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 23:13:55.2400 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 4d511acf-fcc4-4521-a258-08d8b8e2109b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9hI7DBP9zfZhWRuhXx1BomP1qT2Yuwv8TxfwLwZ7j2aPFTkC23ynZb4PbabMz+JmO7pTyEwQ5+OCSwoGBffRlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2503 Received-SPF: softfail client-ip=40.107.92.61; envelope-from=Thomas.Lendacky@amd.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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 , Sean Christopherson , Marcelo Tosatti , Richard Henderson , "Dr. David Alan Gilbert" , Paolo Bonzini , Jiri Slaby , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.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. Cc: Paolo Bonzini Cc: Richard Henderson Cc: Eduardo Habkost Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Tom Lendacky --- target/i386/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index badc141554..62ecc28cf6 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -371,7 +371,7 @@ sev_enabled(void) bool sev_es_enabled(void) { - return false; + return sev_enabled() && (sev_guest->policy & SEV_POLICY_ES); } uint64_t