From patchwork Tue Jan 26 17:36:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047627 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.7 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 84A04C433DB for ; Tue, 26 Jan 2021 17:40:24 +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 1D6402228A for ; Tue, 26 Jan 2021 17:40:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1D6402228A 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]:36490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SKE-0003h6-Oo for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:40:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SHG-00028K-EA for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:19 -0500 Received: from mail-co1nam11on2057.outbound.protection.outlook.com ([40.107.220.57]:48352 helo=NAM11-CO1-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 1l4SHD-0006st-Iy for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D7snSCtG3JTUFvjw4zxp4EfRPQ2/9goph9Qw3UUnLX5TjQaXkiori7WnCOHuZ6BKb8hwzNksw8L8aECb2H+8ekz+7+HC5cQAi7kL61yiOVG+WZMMAMJpGR5GJ21MwKhQq37GgR4IgyytrFF2sC//tMKW+wv3XXNcTov7y6xz+luvx3Z7Ij0DJ2DujSYI3/lfYEvNAn9ACI4kKfkUrwtoxcggKrhsB/gb4Iqh1ymy/pgQyQomL0xNQyUslLDUGmdaPCn/ZyQvrzb4LEbCV9hO6ris9/2Yb8hIxrUiUbItLMshwfv8gxR4tp7ZFqgcIS/JXKPtWIkuDR5wr5Fdyp8yMQ== 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=EMT6c48pr51dMYrBD0z3r9sMxcFpJUFNtsoZoqe32nY=; b=CDg4uVat/wjqTqjmqmqbGrbvJV1Vahvu4o4W96JSfUJl6gYrY5MGYMF8eZ/cU2Obz9mHo/gqkk9eoOdFE8D4VCNbXYpz8eMexHL6aGsS1BU0AXfHIYPamcK5EmGNFsI6kBXF1TdrJztx2WLRJHt1pe+vGBNa+5F2zpmA4YSbE5cz9hFGvEJGVIHVLvZyoxxfq0SpIoPJup+0kZI08FKPCEV9F5KMrA7KeYJdoF+CPhPA5gD4nfcmOdlI3Kl+4KxTkbbNrJIdVvAXS1f+/8o3ZyfO++IZc+StujnzYfn5zDDvts8NbyZ+WuARgNqitIx2G6iKMMXMMcmz7FoVChDUdQ== 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=EMT6c48pr51dMYrBD0z3r9sMxcFpJUFNtsoZoqe32nY=; b=O5CbGWstHBbkkg2Ayfi8CBa73EL7HczDpv6AYDs0mCVOJrli8Fjhi++0r76RTaR0ZwV+7P2qICyoVCcEb2+zGlqGp3e4CVvzA6QHkG6oAgCPzsLWztb4aS085mi9o+9WUUzqTbqJPTcWXxPmgCj8rpi5XIBLAPJwNqX/wupGsJY= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:37:13 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:37:13 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 1/6] sev/i386: Add initial support for SEV-ES Date: Tue, 26 Jan 2021 11:36:44 -0600 Message-Id: <2e6386cbc1ddeaf701547dd5677adf5ddab2b6bd.1611682609.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: SA9PR13CA0167.namprd13.prod.outlook.com (2603:10b6:806:28::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 SA9PR13CA0167.namprd13.prod.outlook.com (2603:10b6:806:28::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.7 via Frontend Transport; Tue, 26 Jan 2021 17:37:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cd680423-a6c0-4743-6b61-08d8c22103ff X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: ID8oZ8HyKDiVBP3sKufLlvnUcIYfOzoLtvxXHy3J4eOiUbnmqvAJr9P6tGjdSXIlsrIKXSqKKtS/0cFs2gneCd4r3FUZVZANcz5ycr9jgXQd5wnXaS0nMAZQS/xaNzXrzcTQhalbwikrbRJjzUPvqH5fdtfbWsBhD1eBYgeYab2vli1lM4hEVkteM/EQIIn89oMx43CO0ZTe+kCiGDgg8xM4piMG5dq+rrwOc/vu7uc4H7+tpGWypql2EwihFZe+l8fCe4T5lkMBt8qnNd16Th9mV7vgOxn+Z0k6ss3FwYQx50Oxn26M1CgueajvcdGeYSzKs0WPFZLD4gOKUBS6ls1V34RBD3fDlABL8HZvi62CoRZXphyAdPWHMW79wOCbBWCGT5qPHlFMqd9dqtkDtDGRefG6gv5CqldHHBzJpPhQc0jzkQnkKfpreNZM4Nob 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(83380400001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008)(309714004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Shmyu85v4bEKCyD55c3P6XPk4Mhcvrv0RK06BMtQlUY4kB8h7SofV78dJBMl32g5s0/sq3xQZrTNX+FRu4BTRosv/v1+BMQep10Pvp1avDhUhSdwnnMNmqIBSiDq2gkfUkcRZZK2XMynScVrpTod84AUPdiPUhRdxZzjiqgOnD7pwoQztvpHgi5/md69G+guzlpaX0MWAVFiCQWwoslyD8waq/85l5QXa3U/lzyEVCdR8SpTMGX/uhDkyAqg3Kc/SorvNUwRAT74mZrpSgrODM2YUvsBxTr//6A6wqm//CWXKg43JdaMFPg82CdEaf+7KiWxKfcEonrn/I1GyXsSeH0okmRKdX1+MTUdP69Gg4ofs0ojmUcTWrefbK6HF8q+d7cQskNzd9WNH5HWhoVzLD603j9MHGQA0L8/OlHP6STvR4qSrxIZLKSs3yYeGP/VEkvmqbRdNrLsJP4BAoRbCfa9eOGrBXtDorTmL96exy50UhxcaNb3JbFnVnboHDa5n/PQIBx3/FGe5Txld7tJDxqLhbACPSFDDM6rFCAiOJpwNRLCaU/rYDseATay5LeP2QLhvRzqM8rh6sbVTpBEqQrtUCvIAkYEtgnUpyjKfDcpwV6V87ZcgwHonaOkoHfwLRpa2d9u/ZftXdDoy0pJp0W9sxFg+jNpaKa8pkBMUpJ0qFBpdiv9pWLZgU8Z5HKhjjJX0JXX9p0LwPl7/GUBq25CUDl48RBiH5ykxGO3WQdREPwhiaR3hDhbcXKepC/SUIL2o3z352WX7xhfcsK/CeyNjv01RBau+NYYCYTWL2HEkQMMYL9Gds7YbRa1xWQW0QCmXtemkSJ0hmnnpzSIOUhKaxFWNP7HX4kblhR7DkqpeRwcF17ho3LVJrAgwIgpOkcw+lt5ZmNQJWOzPSb+fbNvRaWV3fWH9d6tgzImldu+GGrE1AuKbl7bqXM9hA2bCj/EkAC1hw1W7rhYi87WQlbavpfNoK0qefmi3kfOAd8e+pjf8AHlvM9ozifWgvrTX8RXz5pSRm6WtONgq2SedJlq5Fv5d7myzEKo8+o3NSAuoZvLRQtZ8f2a2n4ITbdL X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd680423-a6c0-4743-6b61-08d8c22103ff X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:37:13.1024 (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: v36q3jn3MSHn2Zm2A0qAG0xXWK4DYtb3RylNbtBh74J3V8Qfs0ztEhL2H0PXUfLdn6ScXUPN2GF2HcS3Y+0qSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.57; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Reviewed-by: Dr. David Alan Gilbert Co-developed-by: Jiri Slaby Signed-off-by: Jiri Slaby Signed-off-by: Tom Lendacky Reviewed-by: Venu Busireddy --- 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 72a79e6019..0415d8a99c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5987,6 +5987,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 Tue Jan 26 17:36:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047629 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.7 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 CE0CCC433E9 for ; Tue, 26 Jan 2021 17:40:35 +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 6FE6522A84 for ; Tue, 26 Jan 2021 17:40:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FE6522A84 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]:37040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SKQ-0003vd-Hy for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:40:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SHR-0002EN-Fr for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:29 -0500 Received: from mail-co1nam11on2049.outbound.protection.outlook.com ([40.107.220.49]:64609 helo=NAM11-CO1-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 1l4SHM-0006yT-BN for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:29 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jmJOQlcjcAYJbTkGHvBCeeYD4JUF1uR4JCMsUetjz3r1NqkVgWtmXW9/iFCOsrf2rodIP7D/i8Wb6B3ctawSQSoPGCTe8mlsmDgFZ90MAM7MPCBwxvaWaShdztoNKIVsYWkoEwb5CEkuOGE5SvnUp0ENjIwUKBxgXCa73HCeF9+vDJ0xoAgJb6YlOTCW1EXC6IX+8UrZpjgynRGirnL9SSj27aAzwjsGPaqqCVlki39F3teU9H9lgx9nPUv31BJyymk9xD7rjr4XxthX/rntfhZSykePBbkwW8RJu15Qzta4PcK0Zolj7qpYFuDCwbU4JfmyZWk+cpQjjpJ3DujyCw== 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=8WjCjqNwQxZDZUw3moMX0D0fUfH7UK2ltKPE5+az78M=; b=P2iTDyC1hB2DGVhsHArgE/Szr+AT2JHHzvYokqB8tuTaLiYZxhYvsYdmGcoAdJiF3EvcwjwelaZxxwFIpbboE+4e0Qv7HlYFZWloagfkWlno1+BpB070mYq48GWrCPc5SR6KvP7wBfJu0B/zOU7Qb/JPC2hRKQATXEVSEq4hqb2XpDNOu6We3raS9Ew1MoyJz+CfVknMRNHqqv2khiImsTvHiqqtbFwTC/oJBn48HqlUw7kuFnyDB6tkKYhZb4UaW1TEd4cAy2mgtlE60bAjWjdWfv8s8UFVKIhPz39WyhdM425vCK2Ktwrp1VdKFSuwVHfJBDvGjYsgVZqSZ0097Q== 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=8WjCjqNwQxZDZUw3moMX0D0fUfH7UK2ltKPE5+az78M=; b=rrxLVoOrlJOvHungGonvso6PeUVFEHlWY4TP3OaUPPdY1jdx5ABwZugF3wKhdb8lDOUWJo4fO4Iw5WHO0rItC+X8F1oE6LAGJ8fmt8L4O4hPDclZDDN1097X8dfP7W/4hurF8C34dU5UkrZlYw3y+PcF5GUETm2zoQupvcOvrdM= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:37:21 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:37:21 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 2/6] sev/i386: Require in-kernel irqchip support for SEV-ES guests Date: Tue, 26 Jan 2021 11:36:45 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN7PR04CA0220.namprd04.prod.outlook.com (2603:10b6:806:127::15) 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 SN7PR04CA0220.namprd04.prod.outlook.com (2603:10b6:806:127::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.12 via Frontend Transport; Tue, 26 Jan 2021 17:37:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a1aff093-a15c-4b33-6458-08d8c22108eb X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: Z4vwzT5MnsnRGPnwAlXM32A5MhJ+oQ+tx2huGnt3MhB1jK9B4IoDEQlQBVBbjgLb9PaF73I7OWxGsl48d8jscSveertwa3RuZdi8NSvT3Xp4hBbotg6fHE5koCpcXCwVaT27grva8nnT9WCBiMKSmlKXOzbA20C4u8ggnjXLWg0+MaUsgRttykGb+9wxV04KNQ45wlJXgn7HN7sP8NLTTqolnAoWqQNalJ3sfXEwYFvObXoXs2Gx+ZVlGkoY9sT3LczLmvw2KSpaS29vUXwsrSYpRpf0npJgNgm2dj4/pnPpqajqoUEmTodvbkvMTR1X4Zf+acrqEyPdKy6tPOBl4GOLfU8d2y62/olH0jMirRZNYxBnCAivdT2PhRoqHxhrcXc4ul6d8w7RqFlO/64+Bg== 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rpnfQcbS9IUw046Y/QXgUGeERf5Uf7rOeSX3KZPoWcNj0hLWvM2OpFPBTFpbHIAa1qDdvOqebDaz+GmrOrfs9hUBmQrzENtS7qfXeND6t3I8mTUWdPIe1fqTaCSYQ87OgBhGsuYzRztziwAzGGyQzY6TvfDqE4eXpXz4iKC8yH+/a31jlPneQEmmN7kOcbuUps5A4y2PVMdttAIL/d4TKwCjWNTjWe+L2KrNcJxh5Cs5jcK5tlTS3izJlyMYSVnX7dvNdItqzK8Y/qgnh2yfJZJZ0fFtPQriKcpSbH+Sqgsz5DoONepu3ax1Cix+WLIb+wJ1aIyg4MwGuDt6WIXbd0vX4Jk0003pnLNPpZSwlVy2SgggMWLyeNEvc6J69/wcUvabs/cVh0Fb77TK18m1x3/18wm4gFJOV2FHD2z+3D/7TUHpW+NVINrYli0+8/yVHqqWy+NKrdCtRu4vhfylMx3at2BYNz+nqKzCID2B3bmZDuF1XPuPEYnRD3NV2+CuP/lDDzJzzyTQ/knp00bAV2HAiw+l8HzH/Bgw2Vn0AlwKGKeThxmH9kxY26PvIO8kLuzk0xnkqDEO5FyBx2Chf+1NBPBTPpymp6eP6IsUkjTv3p+PtM8xQkKX95LYILwEnHQla7WGK3kA+Un8ykECpKqFB9uc5NjJFKlrdLo/1JU1y1WNfoP119Mxz0I8CDnlPnlkOkH2+7ubUfiN8X0WCJKt4HwWPeeCZznqaKd2cMFSTcXeFRc4GV0kNpKfngk8xS9AADdC7QCi2QA3Rly9lbFM6QpTSCEzcP8ocYdcbt6D7HYA0GZKFLvJxZVSDbOru9Dav9pOLMP2cholFd6gXquqFpKHbpO/md/rK+Hcg9ouwATqYo4nrooufA/pJdSB/pyxj1XitLKkGvpTbosv5eTj9iC4gX+AImbWBu76n5sAEsSEciTjyE2h4YLR/lBX6lIPp+YaGrfjHc3MNu5M0xlnZpUM2c213NVrk0waLz4MHoqJQo55nnT3duCm5zcd4xwUTb7OQP9dF6/6ENXG3U46ngTAEIl5qaqAO5djmUxFar1fSypBnRKrjdlBdvGs X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1aff093-a15c-4b33-6458-08d8c22108eb X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:37:21.3968 (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: ChVEYz/Svh/X/msvDkfd92a2AJyma/f7jxB3BGvMau2zFElGKlWTYeDrkjdqIAiLVPM9Curg6F8lpXR3dfDMbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.49; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Tom Lendacky Reviewed-by: Venu Busireddy --- 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 Tue Jan 26 17:36:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047631 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.7 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 676ACC433DB for ; Tue, 26 Jan 2021 17:40:51 +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 D3DA322472 for ; Tue, 26 Jan 2021 17:40:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3DA322472 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]:37514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SKf-0004AN-Vr for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:40:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SHW-0002M1-Ax for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:34 -0500 Received: from mail-co1nam11on2078.outbound.protection.outlook.com ([40.107.220.78]:62912 helo=NAM11-CO1-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 1l4SHU-0006zl-5B for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:34 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ozp5cCdfzw9gZ2Z6zLeSbhJ10EtIJPdd1KffSFi4/aMzAplMcGJcWWZZc8mPUfbpsgc7Zc4y4YYIPzewGMRSzkQeFUkGzplDiAyVK2hltp29py83ueQLjbtYxA/GGaw8Ypdea5vSQvWnaCISsQCx7AH28MrNMKMu/OHzOTARPcftaCgjp95U817Pl3+rK3XQ8c2Y/H/YgRgUsHbuZWaVBu9Y5Rs2ImyrNQqbqwvsH99Q/sXtuwEusRcZMCoPi/Ju60P/oWtBuW3EXblqYwhCw6bFHKLh5PJowbh9z2JFElycgKBOlpXnHKu1zfG/u3kq/SENnXca0jPwzK3SQGRWsw== 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=Qn6uXkYsgPpBufxkwzzkYaYmmLis3W0DaS30xUlTKeg=; b=nFI2Gs7imtRUdE2QPsHz4UmA7Xobli51Z7rzlegts58/Y4uriTaQoTB74jxGxjHXH23kt0Y3psnC1QiWSQxVJoXBmdIlkL8ZBHpH7Wk4+xyLZkth0dcXlHJMv7lu/Q2Oo7B5wIWeRNTN1iB2+rAH7Rx6EEUyP2m8F8I+xXP4re8eUJhZq805VZOMqMQdkv/Nj658rv75ywBBn4+PdpIpnssXOTF7pSiMPSFhhygKvOp1mzMPUklG9sAFwqM+N2WnYKFZpOV/Q9QovmD+4H2P93oheLf2eV6e9onW847on/rW5rdB7HbB8Y4f+tuiuBKaLQFrPJEIUJmsaBpqEJ8tug== 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=Qn6uXkYsgPpBufxkwzzkYaYmmLis3W0DaS30xUlTKeg=; b=YM1pjoEmEW52QWTASSsus+5zIixS5F/FnlzJS1y01W4GvApygh/oAjb72NMPA2H5vTpJXZ2qOzF+kt12Kr1nKA/VArzsusgNe/wuVgLCfhIKEbM0iLo8dCGCz9EMDAJmpfe2pfPlwGkmSMK5Cs9qUupczb0dB5ha0MH/KVXqDSg= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:37:29 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:37:29 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 3/6] sev/i386: Allow AP booting under SEV-ES Date: Tue, 26 Jan 2021 11:36:46 -0600 Message-Id: <22db2bfb4d6551aed661a9ae95b4fdbef613ca21.1611682609.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: SN6PR2101CA0009.namprd21.prod.outlook.com (2603:10b6:805:106::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 SN6PR2101CA0009.namprd21.prod.outlook.com (2603:10b6:805:106::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.2 via Frontend Transport; Tue, 26 Jan 2021 17:37:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9f9004f9-2721-40f8-9aca-08d8c2210dc4 X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: 4XOQCJx93cCHqL3Iz2nOaHEs6mENhZyct066DqwfzhyLCjoQy+1fr+JtMyFfs9AcBzxjf/g0Itmgi30/UQavW3VmF4KRZD/+GmYg+W2N2E0OIjEBv3hxxoR5KLXQVR62jdjZjWLESMJHVq32AQyq+shDsXgD/7wpI8ojqQIt9A9Ok2e6gSLO/o11U5KtRUx6RXpxm6E8NXb0z8yXozJc1plcHyCgdC5vmOqIoEOJ04grTb9fPMszbxUl6XZ1GCaD9UiQTo4BT8gEreElZmrFFRra40xyUILpJdDyeQVA+rlwiiWlX25cUvUPIAlLxRgvSMolqIToi8gosYvyr0IeGrOYCrnVY5GdrtynVNFO9WlKG042gExFR78OupbrLSxU1vVwpPBELgRh5v9ZDXt5wQ== 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(83380400001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: O+Y8xzGb/RtB4aEwz3MoKuhAIiZ7nADqJ5Hkbab2tR9V5C7d103VTd9BfdlPGLbsWs82DgMNWc78HegjPEOYVb7if4z94BD5z4m8H6hprbIkMkHtlqJQar3WrGUa0j5wh3KumVGUJVLZGx0/wi1tiUtG0fKJI20p8cLMVbYIWb3l3d4E8+N8diKWLNmAmjDB/D4VE3DXYYGTkrt8cyuj2z5oWXhZj9Q3U2pttYWEarPyRV7e/hTMu0wYbegzAwwp9Z1E237Ggrx4IBtnpvDGiLAM2W0cgICxV/MbW/uq6KM5VT9kVVG7gBHImtd8BRvkWHkY8R71IE5tgkAW60TdHxCcyQ/eJOF12pxXcf0HRROCGWf1TQBR5sCbeng0kfVMGXYSotbbxwj9ZRVQbhGMVZ0kMbC9HNnRGNjD7Bo4lBZwQI9IaJb/RVhlKkg5aqwHHr+9ANYV3UumC1bzfrMoa9VBfySgp7rCo8kkSI74SXyajMVP1seZmjEiDDAkhrjjJnL7pd05hTC5DO6IabtBbRtqOhPnz6p1hmBflz094RdNXs2+0Ags3xShz1WkO2FsdwCwXWkQFNYPoDomQMrbNC3ARXys6Fa04tmlh9i9a/W9gShi4o+l/glrdk8vytd8qNezM3/30FAXjhfMMw4pgw0NAuK/Fzu6FSStOx30lcyAphej8jYQxagj1B2Lp6uG/e8wxQEDJS99LgrM+gvrLysu/ZVbUGgI/asR2JirojSDppnxCEzThHW+LwHq3Js8CzXBPonmMDK28VWpjUJitQOgDzCL0gjwo8gcvMUjTPBaELwj3cxOdYGtPFEBEoeC1Avc/VEJXnIdj1RYwdcOh+1WA7c8d1S2KEwugqBIIJClMfKXT+F9jtxZDUA2xxWtytxvU70yQi5iElOtioJ/g/gE50PXqRlQAfh4c+STK3dp3EexI3gZ3DeGLUrIj36TExcMddja7eq0UjmrcsK2USlI4yRJR9GQTa9DeWCyZLTKnkEA+BPCiFOLKLBMyfa9nIs94BRTCdPlCeAy9VT7GaPiDCF6Vd9M4B9FFc4gD/R5VLE1RXt5dKAjbmcIwM0K X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f9004f9-2721-40f8-9aca-08d8c2210dc4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:37:29.5172 (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: jrSFNohBX3e1gsD0R+Hz+KH4Y/c8O/3zCRyqSvsdAsPI+o9W9MuL+G+aXxYDrPA+Z2DyNjxjoCOUr8hBLBc+vA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.78; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 3feb17d965..410879cf94 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" @@ -126,6 +127,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; @@ -245,6 +252,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) { @@ -2216,6 +2279,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 Tue Jan 26 17:36:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047633 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.7 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 5D7C2C433E0 for ; Tue, 26 Jan 2021 17:43:29 +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 D938F21919 for ; Tue, 26 Jan 2021 17:43:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D938F21919 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]:45126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SNE-0007Sm-08 for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:43:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SHu-0002ev-Vg for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:59 -0500 Received: from mail-co1nam11on2072.outbound.protection.outlook.com ([40.107.220.72]:53056 helo=NAM11-CO1-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 1l4SHr-00077Y-Pt for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:37:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dz57kt7HvC0/Xee9FSbVd+h+RgVOvzPF2dkIT4Q+59GKPeLaQhK5RlRI4LZ38HCSv1MI6O1IFWqbMy/+JnTZIPF3MAUS4xn3l9NIxuJpt4ac2ul1AqKdfzyTfEEDkBLIjC6HY6+AaQ8W/+7q8bJGZEZdTm2xpdyNh5rwoaiYpOsuKoU3k5L6hrPHQaWG5S68PbYIJken+UCvHIn36a9hBDU65C6hqWmcwFdr0aFcYI/JHwBJRmu8ocQ3zkRSXigYt6b21YTEXW+cCSmz0VbSvEvU+oWL6PTZi/gj25ugFPgM9+xHnhKjstM+PCxXkPligKbIoWu9lb4eV2gTbIj1yA== 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=LNEcWZlWlcJqfGW8c3IYrcWONHME3Ra1aEww8H3njTI=; b=ISeqHNw1qrBSSJ1Ab/PS8XHbiWrkG8Q0iOpIGsYrYTDTyKWktK2F3C9Z6LVV4lKxYHHzKy6psV8v377ScWlhRLxYZouQw0/iWBgxX1SH26BG8FZ3fynrLDaHDe2fm45oC3yFvIj1K3awu62gG7U06iAaWZ6AWWkr6FIrML8LAGRsSjqG4A7NLY/TkkocqaRBinMcNJgeEtqIdzPNj+VlL/pSGU7mNgnup4fhHQEGn7tYMoNLjnqECEhK2Pk73i84jldpLfiSUHwCXxxfPBEnnDWEc9gvomQJmPMx1B1x15Qlu5FmOKJ5y7f3T0Y0v8lfWhuAxBkfsxVOX2SiOh0NGw== 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=LNEcWZlWlcJqfGW8c3IYrcWONHME3Ra1aEww8H3njTI=; b=me61X51CpIiGp25+otD9M4a8UullB9EDIB1Ggas/eYDzqmPjiJUXPAV6Ji4Q6tLxh7Eztxwgd5ig9FWb5Xau3JamF9qRmcxxCFRDVI1VZ4+SzWuUUK9ij0I6B5LTMk0cOZVc0rG0mZ3aQT/hxYRF/9oXUOi7rLIFlEkBxH816Hk= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:37:53 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:37:53 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 4/6] sev/i386: Don't allow a system reset under an SEV-ES guest Date: Tue, 26 Jan 2021 11:36:47 -0600 Message-Id: <1ac39c441b9a3e970e9556e1cc29d0a0814de6fd.1611682609.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: SN4PR0401CA0001.namprd04.prod.outlook.com (2603:10b6:803:21::11) 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 SN4PR0401CA0001.namprd04.prod.outlook.com (2603:10b6:803:21::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Tue, 26 Jan 2021 17:37:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9fd6630f-5cb9-43c9-09fe-08d8c2211bda X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: 8R5flbpe0h2CYp0FMV4h1nxLugCvl/BxGHX79xRewLdYnjuHTO/jynHolfHiVCHL3GE79/PBa8tB2PpsdeMBw1nES9/Gy0I71KM2qmKzAjIxbmVg30W0fFkIrGMmciAE2vbThDqsRWPfqCISrlNXE36TpGXmHf2MmdB438x4Py7Hudk5/+Cu/HFMkwsqsGJvOJ1COyBaS/WlbM8f34H12RSRFUJgQ8mOqy4dv1QKh5PC3GBKhWmn9g3r9LZas3g0fFiK4r7nRk3NmnFtJdH4fqQvxNiZro6Xif0MuXiIemqdUUGc3j3OJZ/scEM8fzSO32rF5ZLWh2Z52siI/vPLxEHqk5svkpZXXloxkantuyCul9U7aCmue6o7B54+Khtgvp+oSoruFlAZXRu+BiRQuw== 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(83380400001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: TM+aGvOM22WA9gAa25tqFKSTpmMCFOrCuqncMKfV7J9pHstQEI3NschchKAGoamRh5/uL6NaMkXoW3xt6bNnd93bdeMj2ACmf9sE9ZV89wa/u/nX37UK1nVH2qH35/QPv1S9/mwYhYMJCI7IbEMMLBLHZhjDRam7fe93KqLLk/ErHDrJnE1U12tXEhYGJ4i42zdbLWEysKWc2BCHBbEXyd9IeLPk0hXWXdwglt8hSJw2MK8HTwawxxH2gVjo4k3+hbyTjKWdEgkpFEHpehQus0HAEeZ9s9IRR5oecQsotRV7LCaOOhSsv0RbMjfaPBIvp6ZLgtRaP3scsOG409tr1LfjN8HlRK9n0hmd0cEFGYNdfhkGw5KhE75t+z7JQSoxfk9nkA5ifq5+keerN39lztVea6CiZZvMcSc8KdYNUFcx20Is30CJIhuRNIuMp8bmsk5XEErPu74wHDqDAPq9YO0lM9J2ct9lBTdmma2r9JkWQX19AWbhrlIIbXKave8InQuyxo8cU+BBzXL/pJX4s6oOUcOeafW6FBjBKVWEzliNjDmU6BCJ25FdYKcXEoK5WHZ0GyzjTBhb+LOLZtUYLrATQ3PLLtrqt860P7UQYYhJ49uuz8YSJHdb4LnyMhwexdNRpz5uj+19WitEAtButV+54gOc0YLkimfo1aHoOlCtluKEFEpWkL2929BL3O48SzK/gBLG7n5JsiWbSWZ1Jlt3hFr0pK5QloA+GUNNn2d1yK8+NGiQOD5BDsjvUfiJBpb8yQ4gg14+ATxndJZjWU/mYaKFdmwS+jPJA8Rwr36WhBtnbA1k1M2NGUA80n5EttG6Q0sRGHA0OXNhoQjflLY40+UryDvhmxVZvhPFyVMvqnJKf++0LUr1/2woMjVJs2uanPwuFjbhyo3QxI6T12+qDZhmbAxpujffLEai8ecTYhBupbc47yILLL1reHo0eKEnAPP560aPvY5kpA4YVlabqNyasJqIpyM3xuszwSnXzOTV3naFln/Trpl3eC+T9cBirF1kv61MPVwcNpU+7xrmhyR+0z2+BkaYCj196knVFe72vuqvdlwF94ho2fyS X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fd6630f-5cb9-43c9-09fe-08d8c2211bda X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:37:53.1398 (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: zOlvDZfdFACCg9TVPhsFmllXih+RMEDV34exjUNLO4dB9HVZm8RP4X0XCCN0By3ET9Uzqe73eph968ho4S/yQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.72; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Tom Lendacky Reviewed-by: Venu Busireddy --- 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 | 3 +++ 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, 56 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 410879cf94..6c099a3869 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2414,6 +2414,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 beee050815..1813691898 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -527,6 +527,9 @@ void qemu_system_reset_request(ShutdownCause reason) if (reboot_action == REBOOT_ACTION_SHUTDOWN && reason != SHUTDOWN_CAUSE_SUBSYSTEM_RESET) { shutdown_requested = reason; + } else if (!cpus_are_resettable()) { + error_report("cpus are not resettable, terminating"); + 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 84fb10ea35..123ec1be7e 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -1290,3 +1290,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 dc27fa36c9..7a892d663d 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -2599,3 +2599,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 Tue Jan 26 17:36:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047635 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.7 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 1B64DC433E0 for ; Tue, 26 Jan 2021 17:43:39 +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 C202722210 for ; Tue, 26 Jan 2021 17:43:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C202722210 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]:45890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SNN-0007p0-Lu for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:43:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SJ4-0003mB-NS for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:39:11 -0500 Received: from mail-co1nam11on2056.outbound.protection.outlook.com ([40.107.220.56]:47575 helo=NAM11-CO1-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 1l4SJ3-0007TT-52 for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:39:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NyO7g6AuOfzx60F4myI/dNpPsx58eSAoJdUvEUNE06xBKa1tD2MAz6IFxi9JAv7w32aftRkTrItPmjvFzNarKknj/GPV+8WXa7xHb2bdKlbyVUp9/KfaurkTBWDcKn5+ku0gh5Y3+22DyyeX1xLKrnVk3/j7hrd+N0ch6Fr80/AnYw13WIWke6hCS1zp5H5bgoOlzUwlOanOKCpTBNrkPYgRq+Dsp594CQth7UmihJr04uIZ2BcjIEK4NF59gS3ATYTo4D/fudzfDAbN6kV+4RBCfmWdPlMXUg8T8vOEUugdzkSqwsUY/WPgM7q3/bsdAYvhMn9NhaNutFbP2GKhNw== 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=SnqQ/3+vt27xJWQC+Mvf+WdNlMs1n1ittorc1+cYsd/tXGqCBPTWFN3jNsVY23OqKbeKiU6sdeaBp63uYlILZkQ8zhQsW8RQi3uThgKwY6VFzDQUs07lJOv4sZohR0zG6CqT9CV1m2nE88NSqp4uCWxboVmqpqeG9yhA68pdXjZoM5uyL+yP9YkERkdli96JaPQOOcmeYaDvebl2+/4/F2Rq9HzkrQlgZ5hCGuAU8KBOD5w6AUp+1EDM7YVsv8BB+5xvcSyIeIBsSVPE64pfWWhvgERexIoDenBo5FnlXA2T/y6vAL+J+kqZMdIyOE78yopSd8uQLXgLZuSWlzlHfA== 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=VfvVpS9m9K108GYu0E9fEgszASr2gaoGQ7cyzKDiSTz6z/gJ5Lp6m3aIYemuFZQ5ABxZC0qFSwwBpXDUSffjiGAroQcLzMGIiH+1VM9ibchERp1zzLEly9AEBieUET6KrMO0cmzyspRVAmVDAWB4rCDrPnALiFDyOzD82kt6jyc= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:39:06 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:39:06 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 5/6] kvm/i386: Use a per-VM check for SMM capability Date: Tue, 26 Jan 2021 11:36:48 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0014.namprd13.prod.outlook.com (2603:10b6:806:21::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 SA9PR13CA0014.namprd13.prod.outlook.com (2603:10b6:806:21::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.5 via Frontend Transport; Tue, 26 Jan 2021 17:39:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 825499ae-2a78-47f9-5e60-08d8c2214756 X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: iZd3QygK4iXsLpxrUm9u0mOWbk2s38gHNtuSMIEzou/bLnnIri0KNEFm991ZJK0dH9aVmkbvLSZYIWCDU2/vZ6+aG2n0l+97lZdHHovq9JSgibbEqd8QCwZ2PUgq+im5p1UK5M16EYdQuZ4p5pa1l9mFCMJRBrLamAg71e1rHhuE4j9xdz9jEB4ZpXgNg94qkZHomJuMLrhfHUEifvohW2NBG/uldFWxeRLoA7ZyJ/8F/+9MLPf92LohV1Y7t7FFFCnFZ6kJlDBU0oCvH6XW8wAsjWNgld4ur/1mqZyG8CTedIwzhi/XmDQcvt41TF21dI1vZ5cSyBV4ClGIlq9jzwYTSFtsdZqsOitWDZm2N81p0pxKwP0NyCE6yjznZ2Jn 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(4744005)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(83380400001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wZk2ilCrcRTKsOA4/XjJvTLN51eDfeS7XDIa+lsWC7Xszq3sei+Y+UthpOk+jicOStTpF3BNwWUxlfWVY50SHzYNusaPAqaRLmgro4BkB4/tj8bW5T+DZBRSDdojrnIHs5NC3b3h57zZ7om3vcTqzX20V2WeEr/TuKaGTCBJ4D/G/20+/e8M/s64IsQupBUukye4GxLxpTS27qjwebtIb2xWb0KAxuwS9WtvNCTuBjKxsVQxSO0XaAEfWxJBNEeYSYNsNqWFlRPjDn1ypHof5ANknn4eiFbBG6RUOpIR1eYAYibYhf3NS7od9NyIHgUohOS1DpEmFg+bDxFPey5als72bOOdIQJRMCn2VmX3Y7DiMCg7xVZUT+jzBGYf3QV4lTTlpH3xwXvaKwThpfO0RdqmZDLTw1LmbY5/EAKpfikWisFcdmIxda/hu/o62aa/JCK4KXba3RlcdMdz7JpZFuF/yoDC0s8tCVDKZ3YthfowUjrRBP6nCPqUKMzQ4aDixc0rxtae8Rym4jpOF6ri4Q1e/BGUVv0hra8/D12xDfR6RMnF3aMohFVp1J86ZWGjo+WE0+GKvoPDrXJef9jC5iVHiCMpTWrIWw9vjzmYO/FQFGru370b8BaxO9LXDgFY76kQlw+ryEMPFK1sSw86X3Ljzsf63NhIZWxMnsvAnYTesOEUpPckkOroc9Ke/aP6b0OTxw8rL3D4pZBrJBfFciMtDeLaG6gO7jtrq7jedjEEfyQdCF/yIAVe1aDF5KlAcaAhTkef7GB6y4+qb/SYbkFQFhr5T6nr/nIuZtww8FaVdaZcD9avaskq5wf/lBLi86PUD9xnqkSmeCagvtPlOzm0NZCDF7Xv7gFAJu5q7SF4WrcOMPd+fF8qxvrquHGG/H9G1sWBXSDVGGml1da0c2yBq5AxyJNl25/u1PEai9oEY1NLmkUVNx8emZRgPl9GK3wQ2t+P7sm0oh29GmF9ZSwoIRG4dcaYec6MEiS4xY4jf1wRZA7q+5CFYjmq08qn0TnwsYzAfS3+Xq6YnuU546OhbJd3+IodDYs5v2tNvVJ+e10xvscj9mEDB0wTecqf X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 825499ae-2a78-47f9-5e60-08d8c2214756 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:39:06.1356 (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: 2iMu9RsTyVbaZRAgCitJ5kHELpxkfXO/xGdwuZPVqLm+mEBq4b0ahkVeUeRzT8fQ6v+XlI8VLoSD0z2aj6CpaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.56; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Reviewed-by: Venu Busireddy --- 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 Tue Jan 26 17:36:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Lendacky X-Patchwork-Id: 12047637 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.7 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 53541C433DB for ; Tue, 26 Jan 2021 17:44:01 +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 EB18321919 for ; Tue, 26 Jan 2021 17:44:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB18321919 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]:47006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4SNk-0008IA-1g for qemu-devel@archiver.kernel.org; Tue, 26 Jan 2021 12:44:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4SJE-0003tg-3H for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:39:20 -0500 Received: from mail-co1nam11on2049.outbound.protection.outlook.com ([40.107.220.49]:30816 helo=NAM11-CO1-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 1l4SJC-0007VU-8N for qemu-devel@nongnu.org; Tue, 26 Jan 2021 12:39:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BhdQGfKWwjShXtY/eHYRQqevGJlNn4e74kK+y7E6z2YImauvIfkCY5FTrG2KifQIFB8wx4picobM+HY4QhNjU3Y6D56HnngNW/8US48ACoTfe9sdUc57BcqyYJtID3jP2afzaTaxIrO5q9hOxVNw22OOzVmTPnRqHdvUO5CHozN6tpTGaShrz9oeFDge33SjkHsQziw3EaM3AuXL5zwNiSJBz31EwXkhDxLVssLn+HIy9ctabxHyU0mVCNVNdDAzcVHsYWwZ8/wh/G4L3wO+fbGo8gq4+q0tRT/xI6L+pATxlcJWhvisL2pabFKUQAxdMLyGr0VVG11/1vqH0c/YGw== 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=bIfuL6SaYz9K83EQGRHG3BeFNg3MYsKIVGAse8b2ROYA67wqjg2RnBOIezGxypnsqsETvYl/fyxsfiVDK7iDKr9EpvkV96447DudzzUf6W6e7d17nI2XqI+9Qvo2ICxfrXL12FQKOtCVEOKMaVdPGoy0hi2XwakIXkjgQR2gJGTLoPRRaErsH7H334QNG5CA7MYFuFZ/NgVcAXBDK9cc7owGWDb4TgZ+LxaU3jNvPfe9Db/LnfocDn6vYOpPtL2EX46X9QyidGXnXytu+Pklab6ser+ourhlOrDbaB2hvMsne7G8BDhqvSzp3W7NUeEWQjJDojUsmNKDJId+l+ajhA== 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=KAAUsqf9G0MAw+MV/9y4tVA3tGLRpZiMVQjJKDRQ/uCbb0g0VT5p9Lvsm0FPA7RF0bVlqqTEzynhCCBV1Gwnlr4GKBS4Ut6yH/9dUGtn4M0MiP90dHZ4xy29FdidFsIy8VcRXer7j8tLytfMqvoXtTQ+sZ59gMk0u5/I15tWU3w= 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 DM6PR12MB4153.namprd12.prod.outlook.com (2603:10b6:5:212::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.13; Tue, 26 Jan 2021 17:39:14 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::cc15:4b1f:9f84:6914%4]) with mapi id 15.20.3784.019; Tue, 26 Jan 2021 17:39:14 +0000 From: Tom Lendacky To: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [PATCH v6 6/6] sev/i386: Enable an SEV-ES guest based on SEV policy Date: Tue, 26 Jan 2021 11:36:49 -0600 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CH2PR10CA0002.namprd10.prod.outlook.com (2603:10b6:610:4c::12) 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 CH2PR10CA0002.namprd10.prod.outlook.com (2603:10b6:610:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Tue, 26 Jan 2021 17:39:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a33a47c9-4a22-4be1-b574-08d8c2214c67 X-MS-TrafficTypeDiagnostic: DM6PR12MB4153: 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: XqXp4gUmnUzwedlbxkHFNbBe2t0wyXcpMBZ2paB0R+5EK1Kuq5oqiN1+gCDV4ujfA+NwYYSvtsnZVSL33SJfixZtXFpKLhjnqkfciZjzHJZKsXxq9261Wyf0y36TfEdu/LU8UE5f2KlPEupgTpdQXjjeGkQb7MEmkPtrZGoe8q0tCCv2o2kqNicRqdYUrWoVz+e3e38ZsbHhufZXo6A9WqLsmBp69gGHTUTEWCmTWLjHjj+4+9YDKCnc8KHqWUHdcKxtiKy137OGHQd9/FuEM52fFkmTExW3p+4YCMLFogthpXtMMS8d7SPXHXEtDCyfxCrtQEgT13ip0OyTAhGSyIhxgKS9D5hTvUm8OBlrZpEQWGo4pW6gsSiN7f9lFTbh/9UDDap6NlkQDEbGGhbnCg== 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)(366004)(39860400002)(376002)(396003)(346002)(136003)(8676002)(7696005)(52116002)(478600001)(6666004)(7416002)(4326008)(2906002)(4744005)(66476007)(316002)(54906003)(5660300002)(26005)(2616005)(956004)(86362001)(83380400001)(36756003)(186003)(16526019)(6486002)(66946007)(8936002)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: NIKoCjFgZMV397EHj9Y9vTC88ncpV2QTR8Z633axwBCzJ7VGQCFKZSC0X6bKJiyVKv91MxnNDXP1flHJbNksFxfC1cG3cxefV44mXr4TqxH0lyq6/ZnsuspeXVsHbW9ToEXKtDzsiwCPosDOGeeFp+E2zAMqxu5CXvSc+etpffUG/8wAGzR/BzYV7XGI1I+jaVZmu5UKRG6gY9Vr2iQd1UbD+VrAD+xdvrkRgbd9zQTUtb2ibmg0gYa12e1ud/r/HNgHAnY4bm+r+2h6CAPk+p1OPMfOjPGaE6kfV4GE2o1j2kTy2XHXYgg5fiJ5/vfovi5hgqltPlwq0dUIV4RAua580Dd4nRRQx9P1aszATDzDVIyKArPMfuMIqrseIQiIa3DP3a9hltRuq22E4NAcxQCVS9sOVlOgDVOSF2B98Eqa6VryMQvhJkAVmuKZwinCGUR5dYA5jRMRTBI/MCBYskX2IhxK2/NrnWPAzFYTL0y6tsgpDJVu+4odVtIEXi/EhCBSDRHR/ILmKLm/oXu+3In5wSWx+weVCDNRAJ4r6jzEjKyNNuvTXC8wQenLJEKR6dJNARq/k0A7Z0XyK/skdyNrhpdd0sbSmAKduYMpsmvM68C1iGVdT6IRibVZNtbvWWRnDbmnlLq453+p38N3o5Pr2tEdDtoUwqdbYAPN2czT84+H2otWHEoAaItOF/esjSJCkIUvN7OYf+EPnXcP/URb2TY7e+3+2eyJ74m1oEKORfmHtbw5TQz6PB5oHYIsjd4XlBkFL6i2Uohcr3hf8u9NgU07grOICLxPbWRXrof4XhnlEfjtZS+ZHwStEiKT+1w4TZzrVKS7jN2zVFXPv1Opmhm0NEWrWss+tTFl2y+laF74dDoolepVDPSOR8MluZHxN2sDfH94ok7//HITKXnsSdVhRrfWOtsP57Ju7H+2GxqbTe4svS2gWml96EZMmRUsJyWDJoY9PIwz5Fx43G88nhW5JZAG3sG6yPBnHtv6L/1qxwGEgAqa/iUeDmitMbovLEMuG/KPEvSgoTVNfE4oGhEmTXgzE6KAEqEGQ2gjGrKktpfNXOhkgO8ozqV8 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a33a47c9-4a22-4be1-b574-08d8c2214c67 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2021 17:39:14.5998 (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: NINDInyFVg1sSbriq2EKCGMNxsNirkD+U1vPovIL8i5JsfnVAfOr7HOfA5PgfTwJCYuvYaKWU4kQb2yEUqlHOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4153 Received-SPF: softfail client-ip=40.107.220.49; envelope-from=Thomas.Lendacky@amd.com; helo=NAM11-CO1-obe.outbound.protection.outlook.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 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 Reviewed-by: Venu Busireddy --- 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