From mboxrd@z Thu Jan 1 00:00:00 1970 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 CE6B4C433F5 for ; Wed, 9 Feb 2022 18:12:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 676F08D001C; Wed, 9 Feb 2022 13:12:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BB358D0021; Wed, 9 Feb 2022 13:12:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1271A8D001C; Wed, 9 Feb 2022 13:12:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id EE08D8D0020 for ; Wed, 9 Feb 2022 13:12:34 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B58899790F for ; Wed, 9 Feb 2022 18:12:34 +0000 (UTC) X-FDA: 79124036628.18.1097FC7 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2087.outbound.protection.outlook.com [40.107.244.87]) by imf25.hostedemail.com (Postfix) with ESMTP id 2B1AAA0004 for ; Wed, 9 Feb 2022 18:12:34 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RlaBkdwdcC5/n+OyQ07XPjpbLZJ7mbVW2ukz1MSypykjNLK4yrVnEXcOMfMdRi2gSBaS4TcMIyxR5Ulv7/rxDt5fzBsUNYuVbc1qy7+/BeNQTCmMDiI6Wf8LVKRKb+hwXk54wZdqAI8XF410Ey4vQoHbO141KwYMvR62264h11cDL90ek9h3mwUeU1YUCIm1xRr/MdpbwM2Ht9pPt+PjYQNNwWqCmGEO7uUgglMR0xtDKakslipcvqcHsdD/8iWs6qDRyvqUnvWhHXh4i2QVqHY7i06qjuqVtPs+jknyTc/SdW1TcSWbs2dZLe6w34QSfgVO6NxbZX3Eu2a9X9ueWQ== 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=Ru0Ow8P8Y56s5ktioTvnArAhG9CFR+1Uno56elzvA4k=; b=JZl61xRgS8bpQqkBIY6L/gMhfM1qABJlhp/xDtyx5FU6eqQsO2dg0egpCwdY+qWBgC6m5I5tXjU4I143zvw5TSI2AqfkdzoRm71CoqzzwstCfcie8KjTzPfIBed+df+iswvqwcAsowsQAzGgJSE1te2pzxfpHxWxViMAPEN/6Z/ZLvfAK+RQ/QC67GQ7AbixGb1EDrPofK8q6WBoV8sQNaqRhZDiT7SpLGGK+9GehRsiSbc5h6udy4o0C1LVrp53fcznUNeZ3NHI1QeMffdB/OmrN7tJ3SaJVULQk59DFEcDRZy2tW7+R6Ok6neJtEXI5DrrUceFlVb7/XnyJ3D3MA== 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=Ru0Ow8P8Y56s5ktioTvnArAhG9CFR+1Uno56elzvA4k=; b=rhcs1ZFhQlWSEsh5oWSG1DOWgGPEkTO3rmyAf2MhzxEHjsJntLwv5hht2ku+O3JT4cEo+Gpvcgc6b3WZEkBkhrnLhgZMonYts7EHiXhntrqm9pIGG/TmjWtCXfnBke8WhKakgjp2fHuHCIXkwHd3GCzHgUu7zW6T2p4T7B4x5ZY= Received: from BN9P221CA0013.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::6) by BN8PR12MB2979.namprd12.prod.outlook.com (2603:10b6:408:66::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 18:12:31 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::5a) by BN9P221CA0013.outlook.office365.com (2603:10b6:408:10a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 18:12:31 +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 BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 18:12:31 +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; Wed, 9 Feb 2022 12:12:24 -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 v10 34/45] x86/compressed: Add SEV-SNP feature detection/setup Date: Wed, 9 Feb 2022 12:10:28 -0600 Message-ID: <20220209181039.1262882-35-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220209181039.1262882-1-brijesh.singh@amd.com> References: <20220209181039.1262882-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain 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: b5ca1dba-fb71-40b9-a2ac-08d9ebf7bd13 X-MS-TrafficTypeDiagnostic: BN8PR12MB2979:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Aa1Cv2A4H3pclwFivnwju0aBjX2f4BPOnC//euEtAC69gpngCHZq/9Q3WT2rBf9zVecsCqdEniCtiJv/wjERL2wSN3JMtgFT24S8npITKyPRHLpMVy24AMKmpWYIEPZwnRw3+9/QLMaIG5ZGMmrTeYKdzGyyd5fpYR7GuxU5j8hunNQaHbc+ogN4U15qSvBrnWY9d4ID0aiQb7KSDoIqfLFz0NUg45J5o8UTtaqg1OAJDSfpHXrlNCC0ZLUoP59Sp5xPxwPROdCKDA26XO3X6hlrs9QBzq95EmzNDi6yg414Szy11SKPphmS8j5vYjjhBu/zIDC8CggKlBdJwJWr5EQPbtbysP7xo+zgYdsZSJjwoe8rZ/6JsQNFqn9YpfSyXqAs7Xv/p6TR5qWCIYtPZiroHPX9ASR6FMWad6FTmrgycuRxNd6DfdHRxukQvJGIPVY5hHeMgMkyct9ax9mpQdfg9LVC1tYR8a00nkQgL+jiq0Zo0MMuw7Cjz5ivAdS8ERuCywAGfXNVu2nfWJkbmzn36BSNW/OL12GsKNmRe6XS1kfthIISetHBXvQeMisnO93Bq1aJCViC5i8UeaudH7/fSPrEMIWDN9O/BJkdBWhoBWx7jm46ckKIbIpT3ogyRBFVDUqHoP0PG3LmJuBarnR+/hAwPipJZxz/OiLJe0cGWwa96rwGtHsjfMx9bXfDW5wH4OqlpS3eynFpMsKRarmx6Elm/xqgE1CtulMOsik= 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)(508600001)(36756003)(26005)(2906002)(7696005)(54906003)(110136005)(81166007)(82310400004)(316002)(356005)(186003)(336012)(16526019)(7406005)(7416002)(5660300002)(47076005)(86362001)(44832011)(36860700001)(83380400001)(4326008)(70586007)(70206006)(8676002)(8936002)(1076003)(2616005)(426003)(40460700003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 18:12:31.0484 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5ca1dba-fb71-40b9-a2ac-08d9ebf7bd13 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: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2979 X-Stat-Signature: owdax5sfdcqjitdmo6yizabgzjqxxabc X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=rhcs1ZFh; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf25.hostedemail.com: domain of brijesh.singh@amd.com designates 40.107.244.87 as permitted sender) smtp.mailfrom=brijesh.singh@amd.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2B1AAA0004 X-HE-Tag: 1644430354-75284 Content-Transfer-Encoding: quoted-printable 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 Initial/preliminary detection of SEV-SNP is done via the Confidential Computing blob. Check for it prior to the normal SEV/SME feature initialization, and add some sanity checks to confirm it agrees with SEV-SNP CPUID/MSR bits. Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh --- arch/x86/boot/compressed/sev.c | 112 ++++++++++++++++++++++++++++++++- arch/x86/include/asm/sev.h | 3 + 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/se= v.c index ed717b6dd246..9e281e89037a 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -274,6 +274,13 @@ void sev_enable(struct boot_params *bp) { unsigned int eax, ebx, ecx, edx; struct msr m; + bool snp; + + /* + * Setup/preliminary detection of SNP. This will be sanity-checked + * against CPUID/MSR values later. + */ + snp =3D snp_init(bp); =20 /* Check for the SME/SEV support leaf */ eax =3D 0x80000000; @@ -294,8 +301,11 @@ void sev_enable(struct boot_params *bp) ecx =3D 0; native_cpuid(&eax, &ebx, &ecx, &edx); /* Check whether SEV is supported */ - if (!(eax & BIT(1))) + if (!(eax & BIT(1))) { + if (snp) + error("SEV-SNP support indicated by CC blob, but not CPUID."); return; + } =20 /* Set the SME mask if this is an SEV guest. */ boot_rdmsr(MSR_AMD64_SEV, &m); @@ -320,5 +330,105 @@ void sev_enable(struct boot_params *bp) enforce_vmpl0(); } =20 + if (snp && !(sev_status & MSR_AMD64_SEV_SNP_ENABLED)) + error("SEV-SNP supported indicated by CC blob, but not SEV status MSR.= "); + sme_me_mask =3D BIT_ULL(ebx & 0x3f); } + +/* Search for Confidential Computing blob in the EFI config table. */ +static struct cc_blob_sev_info *find_cc_blob_efi(struct boot_params *bp) +{ + unsigned long cfg_table_pa; + unsigned int cfg_table_len; + int ret; + + ret =3D efi_get_conf_table(bp, &cfg_table_pa, &cfg_table_len); + if (ret) + return NULL; + + return (struct cc_blob_sev_info *)efi_find_vendor_table(bp, cfg_table_p= a, + cfg_table_len, + EFI_CC_BLOB_GUID); +} + +struct cc_setup_data { + struct setup_data header; + u32 cc_blob_address; +}; + +/* + * Search for a Confidential Computing blob passed in as a setup_data en= try + * via the Linux Boot Protocol. + */ +static struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_para= ms *bp) +{ + struct cc_setup_data *sd =3D NULL; + struct setup_data *hdr; + + hdr =3D (struct setup_data *)bp->hdr.setup_data; + + while (hdr) { + if (hdr->type =3D=3D SETUP_CC_BLOB) { + sd =3D (struct cc_setup_data *)hdr; + return (struct cc_blob_sev_info *)(unsigned long)sd->cc_blob_address; + } + hdr =3D (struct setup_data *)hdr->next; + } + + return NULL; +} + +/* + * Initial set up of SNP relies on information provided by the + * Confidential Computing blob, which can be passed to the boot kernel + * by firmware/bootloader in the following ways: + * + * - via an entry in the EFI config table + * - via a setup_data structure, as defined by the Linux Boot Protocol + * + * Scan for the blob in that order. + */ +static struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + cc_info =3D find_cc_blob_efi(bp); + if (cc_info) + goto found_cc_info; + + cc_info =3D find_cc_blob_setup_data(bp); + if (!cc_info) + return NULL; + +found_cc_info: + if (cc_info->magic !=3D CC_BLOB_SEV_HDR_MAGIC) + sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); + + return cc_info; +} + +/* + * Indicate SNP based on presence of SNP-specific CC blob. Subsequent ch= ecks + * will verify the SNP CPUID/MSR bits. + */ +bool snp_init(struct boot_params *bp) +{ + struct cc_blob_sev_info *cc_info; + + if (!bp) + return false; + + cc_info =3D find_cc_blob(bp); + if (!cc_info) + return false; + + /* + * 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 + * phase. + */ + bp->cc_blob_address =3D (u32)(unsigned long)cc_info; + + return true; +} diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 1a7e21bb6eea..4e3909042001 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -11,6 +11,7 @@ #include #include #include +#include =20 #define GHCB_PROTOCOL_MIN 1ULL #define GHCB_PROTOCOL_MAX 2ULL @@ -151,6 +152,7 @@ void __init snp_prep_memory(unsigned long paddr, unsi= gned int sz, enum psc_op op void snp_set_memory_shared(unsigned long vaddr, unsigned int npages); void snp_set_memory_private(unsigned long vaddr, unsigned int npages); void snp_set_wakeup_secondary_cpu(void); +bool snp_init(struct boot_params *bp); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -168,6 +170,7 @@ static inline void __init snp_prep_memory(unsigned lo= ng paddr, unsigned int sz, static inline void snp_set_memory_shared(unsigned long vaddr, unsigned i= nt npages) { } static inline void snp_set_memory_private(unsigned long vaddr, unsigned = int npages) { } static inline void snp_set_wakeup_secondary_cpu(void) { } +static inline bool snp_init(struct boot_params *bp) { return false; } #endif =20 #endif --=20 2.25.1