From patchwork Fri Jul 9 21:55:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12368081 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=-19.0 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,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 2EE43C07E99 for ; Fri, 9 Jul 2021 21:58:52 +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 B3455613C7 for ; Fri, 9 Jul 2021 21:58:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3455613C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine 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]:43230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1yWI-0004qD-Ra for qemu-devel@archiver.kernel.org; Fri, 09 Jul 2021 17:58:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1yU2-00024y-L3 for qemu-devel@nongnu.org; Fri, 09 Jul 2021 17:56:30 -0400 Received: from mail-dm6nam12on2067.outbound.protection.outlook.com ([40.107.243.67]:33505 helo=NAM12-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1yU1-0005q1-2b for qemu-devel@nongnu.org; Fri, 09 Jul 2021 17:56:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KLzOgYxx7taE2CgcCkknkMtMYLk7ai98DpagkcBfjati4cdQdAj0B8OW1mZVJ4VgxzA6QUbFtmb18D+X2vsnGovyu6z2rxoDLmWSPCHgzDHhKPCYXGcZtqpQtvS9yRH3W+JI8bkPKXPCPclzOzgjO9fitRBWnXGI4lyyvo6sD7P1UnWRaC0MjnYAIlPiSgcKUFaRaF9a1iS1AmEmXZMjfUVZ3P934ehA5ADSr7Ed/rPuamL5HbF2V+zlfcchMJwbzmFWwflhhxn+RPC4fldLYLtJfzDKbfd9spACHvvXXBXgSGRtY/HTCeK1l940BNRsObmWxCfExLg0RsDIsA26vw== 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=SS5kgrI8gBb97Fva2W60j49RkiZfbbvK9wWxZ2hB5N0=; b=OF9U7b9puLHkndPFtK95iClFALNOmwIMEnaGp59irEkuLUQq3avIvp+JYN1Qa8HEfVdt+KjKYHuPluO9g5h2oLunZSJVUghinWmecQr+N/95/b1txrvFSKzh18c7JmfK6FsQOQGlxyAp8PXmWhFu6Emkvi9rvNU0Ep7Ex0pnTLQkXTIub0z+YHDHdU13PZglviWuliYyaHZdoRfglWjw8FTLIViI3fGEqH9DP1IVg+/Q60wX7/qrfAxe+KKXLYNcoKVUl4VNHNjWPirtMrkMcMdZzRgWHVIekttS7a85rYXNqagKEi2grJ/A0UPRm+uBQaWdaVffzutAQ4dwJepLgA== 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=SS5kgrI8gBb97Fva2W60j49RkiZfbbvK9wWxZ2hB5N0=; b=wswZhP2yiAvKrDzLHFTokWyT4iLA47Wu2aTjaT3hFsIVhm54faJ1fN8dW3+kwEEJfCDqiI0qE3yK4T9SzWuJV6iAIfZRmBpXQWbiBU11VeHqgsGYxY8och4hXZ/ruq2bNjCt+k0R7pYmQ/DOPdczEDptRN9Sf8qxgWd/qnmWhaM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4575.namprd12.prod.outlook.com (2603:10b6:806:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.21; Fri, 9 Jul 2021 21:56:12 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::a8a9:2aac:4fd1:88fa]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::a8a9:2aac:4fd1:88fa%3]) with mapi id 15.20.4308.022; Fri, 9 Jul 2021 21:56:12 +0000 From: Brijesh Singh To: qemu-devel@nongnu.org Cc: Connor Kuehl , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" , James Bottomley , "Dr . David Alan Gilbert" , Tom Lendacky , Paolo Bonzini , Dov Murik , David Gibson , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , kvm@vger.kernel.org, Michael Roth , Eduardo Habkost , Brijesh Singh Subject: [RFC PATCH 4/6] i386/sev: add the SNP launch start context Date: Fri, 9 Jul 2021 16:55:48 -0500 Message-Id: <20210709215550.32496-5-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210709215550.32496-1-brijesh.singh@amd.com> References: <20210709215550.32496-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0601CA0007.namprd06.prod.outlook.com (2603:10b6:803:2f::17) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0601CA0007.namprd06.prod.outlook.com (2603:10b6:803:2f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Fri, 9 Jul 2021 21:56:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 35fd1136-dac2-4def-46ad-08d943245dc9 X-MS-TrafficTypeDiagnostic: SA0PR12MB4575: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:208; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vLaFPJHqVWkt3xmLfYF3MpIVv+631upqSd7iuh0CvShhP/lJ7rqHUYlxFCWOgzF53/YfiDyzEAuPGj4seG45LKwUfxBnDMrDXlTCNblcaZVhsyM38Xnj7QoDIBhWtLYpyDgVNvMlb/xM8glcOd4ugIElRMlHz+QDupdeei+9wz0aku5KeZz8ezok4yCedfOXdFItXjmgLIh5JiIWaC4D7dXUREv+ljgtRMTes8kMi4ThobY2d3OoCRPekIjGV2myRsbOlpQwJmg6DW7WMlKUjsa6cXQiLCoeNwC4xHMHT79sUm0eBST962rMPw+770rtryJjWRu6zRu//jZ0q4wrEElltrcr46fb1gcdhG6ySUgShmh0gCfDf0KPf2HqwL5zac3rfKRg5+ciozwOXpOV6TWkXLnaOfEkhHSiLbsFYnqdJe8u8Nql6JQ0ZhWyDAA8oxUd4iB32b3pbvRs+Ysm91WzqjeSyByk8JAPqNJxAkYJKP7MOQLduMgyNtHZthDSdSQVx1RoTTwR2LvDyKoDCIR68neK1N/Zdybh+tDOXQNbrbs9nc6KWj/ZhHZ24jJX43TmaRdVtd6Dg2bmJ23Cd88NRqxkGzuQbxZfdsec5XTudemMMcB7XbBhwiie0kPNjuzAESwF6BBkcOGaAeFoKecCJf5DYzw+qu220tL9zkTsMFW8NdnMyiVidSAHJSWnzQfl1fViqytJCm65fSXjRg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB2718.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(136003)(39860400002)(376002)(396003)(346002)(6916009)(2616005)(66556008)(36756003)(6666004)(6486002)(83380400001)(7696005)(52116002)(2906002)(66476007)(316002)(4326008)(186003)(38100700002)(66946007)(38350700002)(8676002)(8936002)(956004)(86362001)(5660300002)(44832011)(54906003)(478600001)(1076003)(26005)(7416002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: omKuYw+JW2UfJRIKm2fzRKq2C/kdiMcPaQBekhgAIDwgm9iobJxrWv0iGj3cjBgGs1TqZFp8BFzpE5sb6uHDtD3194K4BNUbVmJ24lSAWHPSJzA0eWGKq0S0Hfc1fs9PAa5uxAQOyBEQBwdw0cHXBc9ceYPn2dwnBmkmMIfvzx7YVzCZvZGs65hlyiamExEc0FsxUNlkg8HMvnWTdQSt+hO4FX+yZ14E5ouE7dIabiKepjEguzrK/GCmKrbbMt/wM95KqepJQ3eWVr4LF0/aekCaAm3NjyKx7WMjKSs3q/HKx4fpk3U007yTy2yUyLljVTAIpwyJ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dac2-4def-46ad-08d943245dc9 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2021 21:56:12.2610 (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: LP3G8LG2TyVHnSqA9mdHCDi3/SyXvpiXbXI7fZ5EnV6Oo0BRlPlM5UjMZrdGwe1YqI9XaLvmsx1aXeo00Aa+0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4575 Received-SPF: softfail client-ip=40.107.243.67; envelope-from=brijesh.singh@amd.com; helo=NAM12-DM6-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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The SNP_LAUNCH_START is called first to create a cryptographic launch context within the firmware. Signed-off-by: Brijesh Singh --- target/i386/sev.c | 30 +++++++++++++++++++++++++++++- target/i386/trace-events | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index 84ae244af0..259408a8f1 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -812,6 +812,29 @@ sev_read_file_base64(const char *filename, guchar **data, gsize *len) return 0; } +static int +sev_snp_launch_start(SevGuestState *sev) +{ + int ret = 1; + int fw_error, rc; + struct kvm_sev_snp_launch_start *start = &sev->snp_config.start; + + trace_kvm_sev_snp_launch_start(start->policy); + + rc = sev_ioctl(sev->sev_fd, KVM_SEV_SNP_LAUNCH_START, start, &fw_error); + if (rc < 0) { + error_report("%s: SNP_LAUNCH_START ret=%d fw_error=%d '%s'", + __func__, ret, fw_error, fw_error_to_str(fw_error)); + goto out; + } + + sev_set_guest_state(sev, SEV_STATE_LAUNCH_UPDATE); + ret = 0; + +out: + return ret; +} + static int sev_launch_start(SevGuestState *sev) { @@ -1105,7 +1128,12 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) goto err; } - ret = sev_launch_start(sev); + if (sev_snp_enabled()) { + ret = sev_snp_launch_start(sev); + } else { + ret = sev_launch_start(sev); + } + if (ret) { error_setg(errp, "%s: failed to create encryption context", __func__); goto err; diff --git a/target/i386/trace-events b/target/i386/trace-events index 2cd8726eeb..18cc14b956 100644 --- a/target/i386/trace-events +++ b/target/i386/trace-events @@ -11,3 +11,4 @@ kvm_sev_launch_measurement(const char *value) "data %s" kvm_sev_launch_finish(void) "" kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d" kvm_sev_attestation_report(const char *mnonce, const char *data) "mnonce %s data %s" +kvm_sev_snp_launch_start(uint64_t policy) "policy 0x%" PRIx64