From patchwork Thu Feb 24 16:56:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12758976 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C235C4332F for ; Thu, 24 Feb 2022 16:59:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C62AB8D0003; Thu, 24 Feb 2022 11:59:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BEA7D8D0002; Thu, 24 Feb 2022 11:59:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A16198D0003; Thu, 24 Feb 2022 11:59:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 8DC4C8D0002 for ; Thu, 24 Feb 2022 11:59:05 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4E0069AC96 for ; Thu, 24 Feb 2022 16:59:05 +0000 (UTC) X-FDA: 79178283450.21.6306154 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2079.outbound.protection.outlook.com [40.107.236.79]) by imf26.hostedemail.com (Postfix) with ESMTP id 828D3140005 for ; Thu, 24 Feb 2022 16:59:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cY/4s2ydXEF4nRm9gRHP60WQsesMZrdh8jd90/yMXKEnaFjuCi/bOmLkYF4Cbi6eZb14zwJC8EbEMTs19XS8ZPUW/kYb2FWwMpcHPNu/XaEk2XrIHrLBVDUatdHoDnhjeLYVU3HmbT5pX2We7HlfE1SKjlo3CDw8ro6E8SUYZNjMsGGJkcgcqed58D+TxvBK5irzXs+BtbgSQeEHbFhLhBEObWjpYXlZgL3+lt8lNUdKzxoX+LQBOAw/VaD6+9IqPS51rRp4F+Bd6IHukfSvSpxA7REmIRd7Rl7RtAsdgzJvPLtF5c6b7IudENOIjZhR7lOA+z8qj6mppoSWACSygw== 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=fbYtPu/R4hZSC0fOc8BmZk5t0+Odd/LLecFlmc4pxCo=; b=auwJXb7q6hJwwsA/Qefwg/IoPn9WRijXfF1U5Uff5ll034x7TJutHJyAJs8DV3szayD7LcSNSCM344tMOFSKg3V2WeDTCB9Oj0v2glV9nPN6RHDI8qr3LcTzY1wYJmCgSeHUzFYiHKRe14OF+1CtQDYfjJROkpDu9rWaZg2taBTzLNrtl5KjL61qj7Enu/5sijHpDne65XPc86cUG0qzEMC5kC2qayfX5awn5bKXU6E+giqyN4RNdi1UaHlZnyWJYavk4yGqZ1g+rFn7dV11QCotXz4qWx5sn3hZW6QNVSxZF8F8b/i7vyTrhZ6dEM8qvH7xL4L0unXZ+jrkV3J7uQ== 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=fbYtPu/R4hZSC0fOc8BmZk5t0+Odd/LLecFlmc4pxCo=; b=3B2BT046rIha32ZE3T+YYCOQawr449k8I3hC73cccftavUPdIL7WBeHfCX0TpG6rmbmyVK0WPzY7nD76EMGcqaeAyL5Oe+vmEDoS93C0M2U7OrhQz63ogtMeQU3xP552HaSHV6785S1nyEkcQJc+eK+cPxEs/GcIXA/0MVITDFU= Received: from DS7PR03CA0155.namprd03.prod.outlook.com (2603:10b6:5:3b2::10) by BN6PR12MB1218.namprd12.prod.outlook.com (2603:10b6:404:1b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 16:59:02 +0000 Received: from DM6NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b2:cafe::ad) by DS7PR03CA0155.outlook.office365.com (2603:10b6:5:3b2::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21 via Frontend Transport; Thu, 24 Feb 2022 16:59:02 +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 DM6NAM11FT060.mail.protection.outlook.com (10.13.173.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 16:59:01 +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; Thu, 24 Feb 2022 10:58:54 -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 v11 35/45] x86/compressed: Use firmware-validated CPUID leaves for SEV-SNP guests Date: Thu, 24 Feb 2022 10:56:15 -0600 Message-ID: <20220224165625.2175020-36-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224165625.2175020-1-brijesh.singh@amd.com> References: <20220224165625.2175020-1-brijesh.singh@amd.com> MIME-Version: 1.0 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: 2c5e0356-7090-4094-958e-08d9f7b6f547 X-MS-TrafficTypeDiagnostic: BN6PR12MB1218: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: 7mkt/aL4bq8e04T1zLVd7Rr9TkymZXpOu771+TBIhvuLMwhhyQetUK84pZ1uJJUHJE77yILQ4Ur5VRvZitBDnH8XKzJ5+JWqqLL2cSav1dX32/wSPoTUBrmaeijhoQSuOeG7mqPwhrIhnw69OxGIIgNuc9kbOdzrT5LkxLhf1dUqxkUjCF0T5gtEP0RtGMfuyMOP+f2U3c5ZneVjqVnDF83Ul7+wPEds0vI0nTcrPJHAu8xxKaSGOYubhIWW+N8eGaS8s5IHnwBmWUAAGrncy5qMIfHILE1vbNsMFXoqUKpN8D2Hv7fGoGS+PLxG/aE+AkW3El/eOvqrCjKbryVkrWyLWSulRRXVoRbDNeOdvHRbLE3c1qkwrecuSAp6zVfaAVrPy/YQWyiOlJw5aljbdySL3F/niLNsZOMUYLuuydbNBQEi7rZpl15dfo3e583fnqsLI0tq200WszupUIsliPSbipsaZSu13etJ6F5WHnQl36Q32us9Qt2KGKThxi3Bnp6yaGqc1M09O6BWVSQN/ynT/bwVhmpqw4U2qNHR8wc8c3oE64VeJi+XllGmE7aXLR3frvzKWhyL9+v2WmwBC1KkxcAxwhfOIzV/MzElrwvzayVXnR+2G65VFXwzmDCai695LeLUsY/qV9iNhMZgQC14Am9Dxg6e3sZPX33FsYk7R+Fu3nCthsBkjc68D98RbpFHXDKrQKHaesNyZ1ToHJr8AF1WdK+mzD35IPNjNkA= 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)(36840700001)(40470700004)(46966006)(70206006)(7696005)(82310400004)(7406005)(7416002)(86362001)(4326008)(6666004)(70586007)(8676002)(15650500001)(44832011)(508600001)(83380400001)(16526019)(5660300002)(8936002)(36756003)(26005)(336012)(40460700003)(1076003)(36860700001)(47076005)(316002)(54906003)(2906002)(81166007)(186003)(110136005)(356005)(2616005)(426003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 16:59:01.9759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5e0356-7090-4094-958e-08d9f7b6f547 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: DM6NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1218 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 828D3140005 X-Stat-Signature: y33p3qt4ixaz6ygux68rsiq4ptggcju1 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=3B2BT046; spf=pass (imf26.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.236.79 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com X-Rspam-User: X-HE-Tag: 1645721944-781460 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Michael Roth SEV-SNP guests will be provided the location of special 'secrets' 'CPUID' pages via the Confidential Computing blob. This blob is provided to the boot kernel either through an EFI config table entry, or via a setup_data structure as defined by the Linux Boot Protocol. Locate the Confidential Computing from these sources and, if found, use the provided CPUID page/table address to create a copy that the boot kernel will use when servicing cpuid instructions via a #VC CPUID handler. Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- arch/x86/boot/compressed/sev.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 9e281e89037a..42cc41c9cd86 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -408,6 +408,43 @@ static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) return cc_info; } +/* + * Initialize the kernel's copy of the SNP CPUID table, and set up the + * pointer that will be used to access it. + * + * Maintaining a direct mapping of the SNP CPUID table used by firmware would + * be possible as an alternative, but the approach is brittle since the + * mapping needs to be updated in sync with all the changes to virtual memory + * layout and related mapping facilities throughout the boot process. + */ +static void setup_cpuid_table(const struct cc_blob_sev_info *cc_info) +{ + const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table; + int i; + + if (!cc_info || !cc_info->cpuid_phys || cc_info->cpuid_len < PAGE_SIZE) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID); + + cpuid_table_fw = (const struct snp_cpuid_table *)cc_info->cpuid_phys; + if (!cpuid_table_fw->count || cpuid_table_fw->count > SNP_CPUID_COUNT_MAX) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID); + + cpuid_table = snp_cpuid_get_table(); + memcpy((void *)cpuid_table, cpuid_table_fw, sizeof(*cpuid_table)); + + /* Initialize CPUID ranges for range-checking. */ + for (i = 0; i < cpuid_table->count; i++) { + const struct snp_cpuid_fn *fn = &cpuid_table->fn[i]; + + if (fn->eax_in == 0x0) + cpuid_std_range_max = fn->eax; + else if (fn->eax_in == 0x40000000) + cpuid_hyp_range_max = fn->eax; + else if (fn->eax_in == 0x80000000) + cpuid_ext_range_max = fn->eax; + } +} + /* * Indicate SNP based on presence of SNP-specific CC blob. Subsequent checks * will verify the SNP CPUID/MSR bits. @@ -423,6 +460,15 @@ bool snp_init(struct boot_params *bp) if (!cc_info) return false; + /* + * If a SNP-specific Confidential Computing blob is present, then + * firmware/bootloader have indicated SNP support. Verifying this + * involves CPUID checks which will be more reliable if the SNP + * CPUID table is used. See comments over snp_setup_cpuid_table() for + * more details. + */ + setup_cpuid_table(cc_info); + /* * Pass run-time kernel a pointer to CC info via boot_params so EFI * config table doesn't need to be searched again during early startup