Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3502960pxp; Tue, 8 Mar 2022 16:06:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrraziXUTv2koShXrTZJG3+ac2/N10VDuhTqS18tiZqNpuKlpKiNFogrEjU6oQtiTah+5I X-Received: by 2002:a65:4845:0:b0:325:c147:146d with SMTP id i5-20020a654845000000b00325c147146dmr16439626pgs.140.1646784412832; Tue, 08 Mar 2022 16:06:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1646784412; cv=pass; d=google.com; s=arc-20160816; b=OIWJlC22d//+ELbP/TLWfvU0XDvY7GWXqGsfBMKkBM8FGoToDRJnqgi1UtyWiLjb67 UCwlnLLhPhyeca15IydR83fqKHvp4ibWqm1siAdFP0xZ+acus3Rirc3PT07xnJR3WB67 cCcyMsWnzl6oY06MrF9m4R5b9goA+Tsti3Gmy/yHENhrT33/3+TQEkgUvc1dRfRaNH4p Fm5BlQ86BleZ5k6Hq5LbJMLjU1UJlDkCNjaPTuIahuWvJnIsD7fP5sD+0TIR2d605Tgj OnKP7rTD2zXESSTlRhjKadp0+8ZLArQci0+pH1thNmRn7Acorcf3sU3Q2PSZ0CUXGOuQ Pr1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G66NGRXdXKgohObFhMOU5M+y0JCo9aTJaomphlm0EdI=; b=c0XBYqoWvzBH3v9n+MYVjCI4hfgYsLJjc+ThO+emYlLGdvRIa2oIhDuZa1zGKoOitC hl8bvC4ztelABN3dhbHT+n2KOL8qcDnwWC/yamQfH+7sx5aKBQq9mjot1xVT4ugFadYF yO6Mv2qldwv0oE7HZLpXadd4VTjHf/TU0/bwgIX1nfRJulP14qqtAdLRCuZI26dhVp/R TKyhIDB3JIFIXsyiSux6D66VzRCZLl5NXDmI1fQh2L0HOcaMXUbszuqywAIvJw2nYu/k 24tlkKyEvj3BBfqRre57LSAUYceKy6Cre/utxDncRTYL0vVTd5ff1r7st7Un7sXecwTN BjUA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=WoIcqZ5E; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g9-20020a636b09000000b00380ab39bf72si316332pgc.8.2022.03.08.16.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:06:52 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=WoIcqZ5E; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5258CE5421; Tue, 8 Mar 2022 15:38:05 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238389AbiCGVlF (ORCPT + 99 others); Mon, 7 Mar 2022 16:41:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343735AbiCGVh5 (ORCPT ); Mon, 7 Mar 2022 16:37:57 -0500 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B180188B2D; Mon, 7 Mar 2022 13:35:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OXOMFh845GLlGBol1pqImER+AnXAfFZ+XGDd5cw59z95e+7FYJzThBa8jxlK9FU+ciB+boZswH/Ul/0GMfGXFy1bd0dsaXK2WaEd9bxhn+sv1h4uFd2VZOViVDXxKGPidxpXQJcIUrNfA//U+/M9iQ1qy1JYInKkSSKSeEW3G4Fan9LUyinfV803n3qpMQ0MdYUJWmbi24qxdFMBYClDVRvukz/OVpfdN9ypwZBz5xSj+uUeF/qhWwf4BThUAGK2zeVVSHc6ha3AborvtAMDQdEBcNXNLQm0V/+R2QbNgxA9zYXMcs2eUhIWspoIoRIp3QDVXLEZVqqZb1JXQCYhMQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G66NGRXdXKgohObFhMOU5M+y0JCo9aTJaomphlm0EdI=; b=h3uo3cF47pOXENil8L0pupnEdcTr9hYsue6WdIRCYHhaIr8QIpDHEjH1C7M+cuZL9D2S5BpUvpQ4obeS/B0XddJgUW/VEqwtCmQGqTgVsmXkdx0bFXrtyyYGEkKA4d67hG+n8Kdnr5gK/c4uCLXxj/wRdxEiL76ugqsFpgGy/cW1LjXIJewUm7R9dQXy+S4z7gRwPQrVSHYar2d1QsYh50v89JX6N/4ZjK1CSJ7tcAvuMylMv+zSiC82MHUjL/ZpRoxKqBWTouFekgRju5dcOaHHNz5zf7bWYO1o4Z77E+pua5F3Ec6n8DWzKoAnD3PUBvR+j5IPwRg9GFhKc2ImGw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=G66NGRXdXKgohObFhMOU5M+y0JCo9aTJaomphlm0EdI=; b=WoIcqZ5EhY+SVQ2f+dkQDhq8mHnkz6Uwohjnzh24IAZco/IM8spnyb0dX5me4tmfta+Vatps/wzFNGQEZ1hgK9qw/e+ZHDR9s+CMNAuynrXlKA/rUjCD54e3/0fuL0ldWM3T5rNEzTrifty7I9FwhoDANUPEwmsh5We5SqDb1U4= Received: from BN9PR03CA0146.namprd03.prod.outlook.com (2603:10b6:408:fe::31) by MN0PR12MB5931.namprd12.prod.outlook.com (2603:10b6:208:37e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.16; Mon, 7 Mar 2022 21:35:35 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::15) by BN9PR03CA0146.outlook.office365.com (2603:10b6:408:fe::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Mon, 7 Mar 2022 21:35:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Mon, 7 Mar 2022 21:35:35 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Mon, 7 Mar 2022 15:35:30 -0600 From: Brijesh Singh To: , , , , , , CC: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , "Vitaly Kuznetsov" , Jim Mattson , "Andy Lutomirski" , Dave Hansen , Sergio Lopez , Peter Gonda , "Peter Zijlstra" , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , , , , , Brijesh Singh Subject: [PATCH v12 42/46] x86/sev: Register SEV-SNP guest request platform device Date: Mon, 7 Mar 2022 15:33:52 -0600 Message-ID: <20220307213356.2797205-43-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307213356.2797205-1-brijesh.singh@amd.com> References: <20220307213356.2797205-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 16d3f324-e561-4d6b-da8b-08da00826a50 X-MS-TrafficTypeDiagnostic: MN0PR12MB5931:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Nagy763NCHgLyKtgtmGd4x7bpsf66/pK40UcTLjj3RMa/d3WsUFnWGMfP//+7CsEDZanhBYgiq5RyfHJULV5P7CLZ6LBjjPxh+oOPzLeOuNAmcNOIGYlhDLW7E0NJ5WPqUVUzHqoVPp6Wvxq5zr0zmuDTyxqLm6VvMjHrlGCADI84+rcoR1Tcdaka2BguRQYAL4kQniCYYKLkBTuKhRBXPHrqsiqM/Ya509D6NJagrv7JGC/QNiqm+Kt4hk8p+k82kjCA8e+gp0mCXi1nHiAIY5g/JPujmBAPZzjP0q/9+m6XXuhaSf9ukfvvcQbKL01kCBfqQNRKaWy0+K9bV24TSt9gZqjf7A0sfyS46oStTra2DOTEpd/ZGBpiLqjA5ooKhJBHHInHtxHZuqP9+Nm9jjOTW/xGz6cQOymm4bbfYNrCit2dToUNigu/cX74cXrEiJn9IMg+VtO00qAXxUbdNVy3fgaeLwaGObcjHbvoD1GqPah0OT14rCqOo0EzB950GeRnikY7vgwuTZWxayEzXvOrpXAtZWa1wvmVrgV7Uf0Ga6n4is6Mv/XZuJtVdkRfEOwT07a+2EkRi96A3SikahuGyzL4uegFYC5dF4hE09PQodNCG8cfIWiL3rX+wLJQb1R5hkBvc9EdJah7xXkeLEvyXni0r/QmyN0Uu5mi4nxxLLud8nCWT90yiwa14rgF7B5tO+CjxyqNdDug0hjzhC0YEAd/RBagsvJgDHthg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(4326008)(83380400001)(8676002)(36756003)(81166007)(54906003)(70206006)(70586007)(508600001)(86362001)(36860700001)(6666004)(7696005)(110136005)(316002)(16526019)(336012)(186003)(2616005)(1076003)(426003)(26005)(82310400004)(2906002)(356005)(40460700003)(44832011)(7416002)(8936002)(7406005)(47076005)(5660300002)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 21:35:35.5153 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16d3f324-e561-4d6b-da8b-08da00826a50 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5931 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Version 2 of the GHCB specification providesa Non Automatic Exit (NAE) event type that can be used by the SEV-SNP guest to communicate with the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent. SNP_LAUNCH_UPDATE can insert two special pages into the guest’s memory: the secrets page and the CPUID page. The PSP firmware populates the contents of the secrets page. The secrets page contains encryption keys used by the guest to interact with the firmware. Because the secrets page is encrypted with the guest’s memory encryption key, the hypervisor cannot read the keys. See SEV-SNP firmware spec for further details on the secrets page format. Create a platform device that the SEV-SNP guest driver can bind to get the platform resources such as encryption key and message id to use to communicate with the PSP. The SEV-SNP guest driver provides a userspace interface to get the attestation report, key derivation, extended attestation report etc. Signed-off-by: Brijesh Singh --- arch/x86/include/asm/sev.h | 4 +++ arch/x86/kernel/sev.c | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 9830ee1d6ef0..ca977493eb72 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -95,6 +95,10 @@ struct snp_req_data { unsigned int data_npages; }; +struct snp_guest_platform_data { + u64 secrets_gpa; +}; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern struct static_key_false sev_es_enable_key; extern void __sev_es_ist_enter(struct pt_regs *regs); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 97c86541b9c6..5f48263bff8a 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include #include #include @@ -2180,3 +2183,56 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned return ret; } EXPORT_SYMBOL_GPL(snp_issue_guest_request); + +static struct platform_device guest_req_device = { + .name = "snp-guest", + .id = -1, +}; + +static u64 get_secrets_page(void) +{ + u64 pa_data = boot_params.cc_blob_address; + struct cc_blob_sev_info info; + void *map; + + /* + * The CC blob contains the address of the secrets page, check if the + * blob is present. + */ + if (!pa_data) + return 0; + + map = early_memremap(pa_data, sizeof(info)); + memcpy(&info, map, sizeof(info)); + early_memunmap(map, sizeof(info)); + + /* smoke-test the secrets page passed */ + if (!info.secrets_phys || info.secrets_len != PAGE_SIZE) + return 0; + + return info.secrets_phys; +} + +static int __init snp_init_platform_device(void) +{ + struct snp_guest_platform_data data; + u64 gpa; + + if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) + return -ENODEV; + + gpa = get_secrets_page(); + if (!gpa) + return -ENODEV; + + data.secrets_gpa = gpa; + if (platform_device_add_data(&guest_req_device, &data, sizeof(data))) + return -ENODEV; + + if (platform_device_register(&guest_req_device)) + return -ENODEV; + + pr_info("SNP guest platform device initialized.\n"); + return 0; +} +device_initcall(snp_init_platform_device); -- 2.25.1