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);