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 4071FC001DC for ; Thu, 20 Jul 2023 19:11:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A682280153; Thu, 20 Jul 2023 15:11:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8565D28004C; Thu, 20 Jul 2023 15:11:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71F00280153; Thu, 20 Jul 2023 15:11:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6461428004C for ; Thu, 20 Jul 2023 15:11:38 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2A241A0296 for ; Thu, 20 Jul 2023 19:11:38 +0000 (UTC) X-FDA: 81032934276.16.EE7D6A7 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2043.outbound.protection.outlook.com [40.107.223.43]) by imf15.hostedemail.com (Postfix) with ESMTP id ED4CAA001E for ; Thu, 20 Jul 2023 19:11:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=LRGW3Jqj; spf=pass (imf15.hostedemail.com: domain of kim.phillips@amd.com designates 40.107.223.43 as permitted sender) smtp.mailfrom=kim.phillips@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1689880295; a=rsa-sha256; cv=pass; b=ePLtmncNFf6B8/iy1GequkiKh5Xl4xwcBpafLQSfE2dMnUYgLZHFNVZ6EJJuDKNlhJ0RwD 0716GEF38IsZQTbYM+R2UaBHnrD1z0XDrupccLJinkMmD3YRedp8uxgJyuzZ1nDVJSiDn9 tLTFQaxg6JwmdB9I+miRQxGoVzGMAyc= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=LRGW3Jqj; spf=pass (imf15.hostedemail.com: domain of kim.phillips@amd.com designates 40.107.223.43 as permitted sender) smtp.mailfrom=kim.phillips@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689880295; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HF08v0YjbDlgUIEEG9sIEHxgjF+Irmaa20Jud8VnW14=; b=M0osQW6m7PwNthkCCq1BJdfjVIuSDdBTVwOmiXkhz9o310e2oaYzDarOY7qRNYT49to6zz bjOlp32Lrf+ITV7+Ic8S13ydq4x+xMjILYkk3jnnhOCbCJNr6oAWSH6svm+5Nw8WG1n1b3 5nnuOV9RhFHFYYTg2DK/s3NHeD1146U= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CKZ7LZO9LXE344xUzv2b7FmbfMnpwRGn65uolrxV3JuDc2gNiE/XFCBmjmlVLlGHpX0GjHVMgI3wwHJSz1mFwPeu+Wt0X4U+3fUqWp+g+lvSZ0lGTqcR9u2tKrKH/pJFOW73e9O1AxrM5+PKZNci+onkT2n6BYJAlU3Ut5qhcl74bm7k8kEuOoDPBMq/QiGnzXYJ/LisjPhObse5G7fUSF4yc0qdrhguQ0lDyL4vJdcPsW94AfcYMKimfNOQb1/UeEjcqMENnnhNWh58/+vANhMDLB2h3GRR6f3hyF8zahxLt/eIEzHRhEW1Pksbk08gFoSk3hC8vS/m+aSVWnNnwQ== 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=HF08v0YjbDlgUIEEG9sIEHxgjF+Irmaa20Jud8VnW14=; b=oJAuj5QO1/+x9sQSW8+z9nRxDpisJkbFCjc+EmIKtxTjE85iHNsFfqurT3TAGXUmjfy8UN8APg5OEyK7HSZEX5mA/b1kgh/057SRetN6RrOzcCVbuq26wPlzWzz4xOhZC4w2km4R0he2xr5mK0a/nc28u78nJYLqpkZNdOjSTzrRolI71TLN0YCRuVxt+EqqejKPr9enouRDY49XefTd0A+uM2wUOISQZJaCGFgUghsHxKymZ0N9gjvHBVDgV9uRKxgha1JQB0FmuRdgu9J3+bL4bEpF9ZHXg1VvSrG2xOCy40i4nxF8tEINkpL6s8ce0eThtr2Y5NXCXE48V3CHWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=intel.com 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=HF08v0YjbDlgUIEEG9sIEHxgjF+Irmaa20Jud8VnW14=; b=LRGW3JqjXTFjPOFpjBEI5e535vteKisPXyNjG/1H6eaz4riGNzBWXXdaMt9fmd6LyFWNqFcuoe3FmXIhAns68FxkIaiPVK/UprkCKDWrklR6/84A21cudDUIrjKz22Y+qOJAWKBwOpS0INLm+Oiv5KAe+0Xgsj2kDO1JbFIFBds= Received: from BN0PR04CA0194.namprd04.prod.outlook.com (2603:10b6:408:e9::19) by MN2PR12MB4304.namprd12.prod.outlook.com (2603:10b6:208:1d0::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.26; Thu, 20 Jul 2023 19:11:32 +0000 Received: from BN8NAM11FT087.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::c2) by BN0PR04CA0194.outlook.office365.com (2603:10b6:408:e9::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Thu, 20 Jul 2023 19:11:32 +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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT087.mail.protection.outlook.com (10.13.177.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6609.28 via Frontend Transport; Thu, 20 Jul 2023 19:11:32 +0000 Received: from [10.236.30.70] (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.2507.23; Thu, 20 Jul 2023 14:11:29 -0500 Message-ID: Date: Thu, 20 Jul 2023 14:11:16 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Dave Hansen , Michael Roth , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20230612042559.375660-1-michael.roth@amd.com> <20230612042559.375660-9-michael.roth@amd.com> <696ea7fe-3294-f21b-3bc0-3f8cc0a718e9@intel.com> <396d0e29-defc-e207-2cbd-fe7137e798ad@intel.com> Content-Language: en-US From: Kim Phillips Subject: Re: [PATCH RFC v9 08/51] x86/speculation: Do not enable Automatic IBRS if SEV SNP is enabled In-Reply-To: <396d0e29-defc-e207-2cbd-fe7137e798ad@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed 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-TrafficTypeDiagnostic: BN8NAM11FT087:EE_|MN2PR12MB4304:EE_ X-MS-Office365-Filtering-Correlation-Id: bff98c7a-843f-4386-8ead-08db895520f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p0wQy22Jpw+LxeV1rQEgtQSNHnzR7TfU41AT+LCg0ljqd45B5vf0EWrshMVWfLxzN8eeR/GnNrEIupyWQ1CndzklHM91SR6ViBX0tn9ou+Kk3ik5lpRiO9U6pIXRQXmoEpSyFQYFMRbIsUQhfySeAA9E1jLTdwc7L9Fs92cM7SJixYqx8pUkho52NnBlLLeqxxXYgOcopEY3ksjh8uKy8VX67dMxdT0dl17RsvBiDMFADisLCfQwuzXXKjDJBtICiKzDkrAEUrgO67K+x5ToAvsuRjPbRr1hrP1wUrZJ46xmsILmEbOqc9MOE91A0XAGhuxw7W5MNBMs7+XD14eL6H91T8oXHqnDV0x2ytM4+4UX4kJbXN18KBUJrgZjAHma7SUOGhJO6UJwmUbbeTLRI4Sm1vhAms0TRE9vx5jph4DAmcTOBkz4yR9IxyzcTPrL5ULXBOaZPXGxoLCTP7oWdrBTwwYyxFh4n+GtrVXxhtHaV0iNKXZnvfjGJ/nix7oWX6sRrWifAngHnq/GwjoZBevf/aSj80dWPnT1kuEr/q+bdCgHI+UCz+cssAkiA+rFUgELWHlttCHzAGZ2HxlKij5Usl1HuzHuxk4SgjX1l/sL2BxcMER/sRTbuyY5tbI9NFRjVsF3KLaxFz23QRz5cAa910Yy7hrpfI0rB6nB+FC+Hjah29OkZQKGl0c+rG518EFNYIIzi+tinQTGsXxWVwyLIhx8julwstXq8cbNYAybLwI9vAPfjk3MwTrhYMXhGeQLzuarTdc0bJulLBEJ0xr1AxUaafJ97GBz8fraHLQ= 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:(13230028)(4636009)(376002)(136003)(346002)(39860400002)(396003)(82310400008)(451199021)(40470700004)(36840700001)(46966006)(336012)(186003)(26005)(6666004)(16576012)(316002)(70206006)(70586007)(4326008)(16526019)(40480700001)(966005)(53546011)(41300700001)(5660300002)(54906003)(44832011)(110136005)(31686004)(478600001)(7416002)(7406005)(8936002)(8676002)(2616005)(356005)(47076005)(426003)(36860700001)(40460700003)(83380400001)(2906002)(81166007)(82740400003)(31696002)(36756003)(86362001)(43740500002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jul 2023 19:11:32.0621 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bff98c7a-843f-4386-8ead-08db895520f5 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: BN8NAM11FT087.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4304 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: ED4CAA001E X-Stat-Signature: jdmp1bsdn5h431e1m98aduy6uyaktnmf X-Rspam-User: X-HE-Tag: 1689880294-503930 X-HE-Meta: U2FsdGVkX1++UYCG1Rz6dWEr1qfsZ9b1b7XRH9+KFztVMFivUpJizBCBWUjJr5nzMyEBAoFCSlVZflMpRkaS7wxrgOWcZXpdoNp06cAAOckDU5LN9DnD6TdmpER30y7nTOya22Ge8yErxRkRCnJOuecGI8umqPTXAFoHnYsfx3TBzr6FKBL/e+TtKa9AuV8CsLSukgnY9NG+B8UeG6sxVsobutFWHrp2/ZKywR5bM/psSgOv352nzSX0xBVNiAf9prYNb4xOqNRBgUpzx0bs+4zglXnjKmnlTJjQ/+OIGVFIiXHMyLckp3aeqr6oH2WD8pEj8pBKpBA77f/9O1lZ3is8tG0xXAlwnwOoviAVlDPkrofm+7pBtux0m9rFTHJafb6JYpVGMSIxl1RrEHFJNqM6v3a1V2Yw9p5HJ7oeKLsWU7r2NV0bdM+TZLKnmAAdNC/XHQKognjFsXo0KeuPKtB1Y1AS1l5MXd85sDieJFVH6S/va4TXr+ywyBr7jgp2iHjvh9+1QwEfiGH9wv1n8zHCugFO8QwErhChwYkv3YMVp5uSEMjNWeWkp97I47r/w0J+I2ho2fYLyL9b6j65QgD9LCTsWduwfyCMCh6yT4U7bKCvWn+nazohqe+daOXs0YaDwh8HCRjZzBzZgrIiAfSgLeDdF5ebg3Jf1nxVGrffvcX3XjpG3GLHb5umACrbn+60zirhVulFEjr5ZbsGuxB98NVfsTzroRWXrb4OSDJqX8g/GrXslhAH5g0w0GQQURATxjAvQFXlIQOZo+BnCtVAc1Jduq3+CEQQ9meHFN02lj3CkkduYqa69PQ8wr+PEcdiQ+raEE0etRNt+J14IDiFiK5YFF0pmNQOied91BjYO4WVoRMb/d/juL61neCVN88wt1MKjMBBHHL+Hl2ktKy1g43OTW9tdVw0CjUw439NZBS3mMMUoTXLJ1AHeeaV/gMKCSq+hMBI1KJVrur Dk3/vuQd DmVNxdpkmT72fDhlLqrWDnzq/6+vlumeHJF9+nhxzgulkRjGkKEIaxRW7MRTnVeuLBsdb9+iiHD9KEGT7cOkANqddljo+DDmuNN7PwEmSSbWBUgkIXAYtNTuiNCYNbSX2jRDulqYJ5xsCQ0bCpGiqQCdJCv6kvsKnv8otX2Cklu5w+KggSCEKKVZdNrdWCNbqXJOmkMmekZLXDKwCC6fTZbC8aS+nBMF/kbv3lctQPbT01Fe1TvOquivfq9kncN6gsRywVi0dxYzWk3Hr/xVYfDqouRjIyG5xyaro4oshSw+eBFzJiesNzq25uWphrKYzrskV2p8+Vd5VPNiLI6UBG+DsrZf90RL2/DX4OzJnW/COEtl4sf32bMIZ2oafEC8wPGlK 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: On 7/18/23 6:17 PM, Dave Hansen wrote: > On 7/18/23 15:34, Kim Phillips wrote: > ... >> Automatic IBRS provides protection to [1]: >> >>  - Processes running at CPL=0 >>  - Processes running as host when Secure Nested Paging (SEV-SNP) is enabled >> >> i.e., >> >>     (CPL < 3) || ((ASID == 0) && SNP) >> >> Because of this limitation, do not enable Automatic IBRS when SNP is >> enabled. > > Gah, I found that hard to parse. I think it's because you're talking > about an SEV-SNP host in one part and "SNP" in the other but _meaning_ > SNP host and SNP guest. > > Could I maybe suggest that you folks follow the TDX convention and > actually add _GUEST and _HOST to the feature name be explicit about > which side is which? > >> Instead, fall back to retpolines. > > Now I'm totally lost. > > This is talking about falling back to retpolines ... in the kernel. But > "Automatic IBRS provides protection to ... CPL < 3", aka. the kernel. > >> Note that the AutoIBRS feature may continue to be used within the >> guest. > > What is this trying to say? > > "AutoIBRS can still be used in a guest since it protects CPL < 3" > > or > > "The AutoIBRS bits can still be twiddled within the guest even though it > doesn't do any good" > > ? Hopefully the commit text in this version will help answer all your questions?: From 96dbd72d018287bc5b72f6083884e2125c9d09bc Mon Sep 17 00:00:00 2001 From: Kim Phillips Date: Mon, 17 Jul 2023 14:08:15 -0500 Subject: [PATCH] x86/speculation: Do not enable Automatic IBRS if SEV SNP is enabled Automatic IBRS provides protection to [1]: - Processes running at CPL=0 - Processes running as host when Secure Nested Paging (SEV-SNP) is enabled I.e., from the host side (ASID=0, based on host EFER.AutoIBRS) If SYSCFG[SNPEn]=0 then: IBRS is enabled for supervisor mode (CPL < 3) only If SYSCFG[SNPEn]=1 then: IBRS is enabled at all CPLs From the guest side (ASID!=0, based on guest EFER.AutoIBRS) IBRS is enabled for supervisor mode (CPL < 3) Therefore, don't enable Automatic IBRS in host mode if SNP is enabled, because it will penalize user-mode indirect branch performance. Have the kernel fall back to retpolines instead. Note that the AutoIBRS feature may continue to be used within guests, where ASID != 0. [1] "AMD64 Architecture Programmer's Manual Volume 2: System Programming", Pub. 24593, rev. 3.41, June 2023, Part 1, Section 3.1.7 "Extended Feature Enable Register (EFER)" - accessible via Link. Link: https://bugzilla.kernel.org/attachment.cgi?id=304652 Signed-off-by: Kim Phillips --- arch/x86/kernel/cpu/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8cd4126d8253..311c0a6422b5 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1348,7 +1348,8 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) * AMD's AutoIBRS is equivalent to Intel's eIBRS - use the Intel feature * flag and protect from vendor-specific bugs via the whitelist. */ - if ((ia32_cap & ARCH_CAP_IBRS_ALL) || cpu_has(c, X86_FEATURE_AUTOIBRS)) { + if ((ia32_cap & ARCH_CAP_IBRS_ALL) || (cpu_has(c, X86_FEATURE_AUTOIBRS) && + !cpu_feature_enabled(X86_FEATURE_SEV_SNP))) { setup_force_cpu_cap(X86_FEATURE_IBRS_ENHANCED); if (!cpu_matches(cpu_vuln_whitelist, NO_EIBRS_PBRSB) && !(ia32_cap & ARCH_CAP_PBRSB_NO)) -- 2.34.1