Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1462004pxy; Thu, 29 Apr 2021 07:36:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIaODYTbn8Wn7hh3xLpsDPbUAPWS9bFqyAhz7aaKoWifI0h+ebVVmlgnpjJd7Z+372E2pW X-Received: by 2002:a17:902:bf44:b029:ec:c083:7377 with SMTP id u4-20020a170902bf44b02900ecc0837377mr35003367pls.27.1619706961424; Thu, 29 Apr 2021 07:36:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1619706961; cv=pass; d=google.com; s=arc-20160816; b=XNaBSPu5s6+gIM14B7l8yNvPhzO1iwGn76GQaFNVVxhh1KKeJx7/Z7V1sLkXL8/+wd FnLNSVKb5ZWghz3h60e8EwHBv0uE9B5Bj0sGEyIdMJAKfJQhXErWcqhdayJ/8blBYpFA YBjlDjkx69W0Fb87cr7CusKziFi+Oh3X5KP4mHGSotjROj2cxEDwyZxZ313NgygrDfvj 88a0msfMnCP78WDsXHMybv4A82X7pK4pOdji69gbChNpJ0uxRfTeXI3RgUTAfqfCKHEi 4VusVD2AVUuqt44J7k92eqenm/1R+sw2Lu0yVFL8HQilJtKwVAQzti2xNCGAr8beQBCn rEmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=jToExw5jUBUAUkUDUttH+6n8m49NtZfR4QxnbculwTU=; b=FBDMwRiMFS9G8bzNcNYF98QkK5SHx5IjyuYmBvQoNQunV5Rs+z86ydnoeLUf0wODgk YF49Giwz6rWhJQvF8CsZYyGZTlLGnry0FT0er4qtBDQijba4iPm/Ml4nFeVESZHVSciA 3KTwK/vJPiuIGBnKoSJB484z6Eq2lCdRcEKABoYUPyS64Vl/oibeNO47CqWjzut7fSCQ yK33J1E4j4kcS8yeXGNja8xX6J13IRD10VOeyCjCHVv70GINM058FzYRz9nF72hNtSQ1 Jp6T2fZIN9lOpXdKe65VVH1/8FfMF42lmzHXYXKLQL47DyVKAMsB3C2ptQOEtVnFjR9c E1Og== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=TmfIufNq; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m21si85307pgj.213.2021.04.29.07.35.47; Thu, 29 Apr 2021 07:36:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=TmfIufNq; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240552AbhD2Od1 (ORCPT + 99 others); Thu, 29 Apr 2021 10:33:27 -0400 Received: from mail-dm6nam08on2080.outbound.protection.outlook.com ([40.107.102.80]:12257 "EHLO NAM04-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240564AbhD2Od0 (ORCPT ); Thu, 29 Apr 2021 10:33:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KYombHQEmxv4nrTmma7TUlx78v4cChmX4oAVw50kK4Q2ticzZavtYhIa3E4Y/bX/gRtLkLF84odc70Gb+K78hfR3j/ofh7yE8T1mjaFIE1SllBgKDtL/ErVyh/3x+WtDmJVgslKIlyoGWbwbn3RpEEID0Fb8VOAgUGPESRNbynjWpgXJX9AJX19P5VI2ruKeAoH1/O8iRVVkSsQYBnBv5/6Ukicv3IDGdmvIDyrpj6mhNBToAP7rfVTHfpZBm0K2IKIMFyy4EuYJOBOsCiJxetXFN5hkHmn+PV6pLvW9f2BRw3e5l4BOOLeWw8JMeQnQSGKoOGg4BkpY/B+OmJIIBA== 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=jToExw5jUBUAUkUDUttH+6n8m49NtZfR4QxnbculwTU=; b=HSojX0ydDILAdTRxm15rf//siKF0ApKkghuM9Tfxlux13V4mSH2Sg+d53D/hR8np8HiEPwFhvcH4SlpAXEEa+L/Mr7fBrGbd2aFBk1GjDuy4tSh45ihd4qT5vL0NBnrmWgOWIj8ZZ/0Z61pw61MG1U7PDG74/eSqIo8RrkUCx7LjrnpqSNd/n8jP6J2z1QXSV28fVRiek8iPg3jrVRJ3UOavzz6JmOlUNmDcXPrXnooh8I8llnvv6KrOB5/q/iQ1khmbl4yCpSuXjY082oUtjpqgGXTFZGGFHO5mgWpBv2XjTmp7TmIIenGzc4l44QhH+V+m1zrqc/0nMH1nrrx5fw== 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=jToExw5jUBUAUkUDUttH+6n8m49NtZfR4QxnbculwTU=; b=TmfIufNqTJAL949YGCTlsGqt8QpiPJ7xUyIC8nw1EaFIIlN8WulK9gKg8HvZUopUNUdaEmfz8u30SPyG8zd2se6VAv+5lGJqTFNow1G2PBI8yl5TufYcpTxqL3cHBiEuaQdIGRKFzk/QwS38sdUuoHv4ZLQlPXLfshqHFHtVmho= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB3435.namprd12.prod.outlook.com (2603:10b6:5:39::26) by DM5PR12MB1195.namprd12.prod.outlook.com (2603:10b6:3:7a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 29 Apr 2021 14:32:38 +0000 Received: from DM6PR12MB3435.namprd12.prod.outlook.com ([fe80::69b0:5e8d:c318:3f3b]) by DM6PR12MB3435.namprd12.prod.outlook.com ([fe80::69b0:5e8d:c318:3f3b%7]) with mapi id 15.20.4087.025; Thu, 29 Apr 2021 14:32:38 +0000 Subject: Re: [v3 1/1] x86/cpufeatures: Implement Predictive Store Forwarding control. To: Tom Lendacky , Reiji Watanabe Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, Jonathan Corbet , bsd@redhat.com References: <20210428160349.158774-1-rsaripal@amd.com> <20210428160349.158774-2-rsaripal@amd.com> <84eddb82-7626-c1e0-78b3-a92b5039e011@amd.com> <238f41fd-2f7b-cfa0-b538-2a659c38c7e3@amd.com> From: "Saripalli, RK" Message-ID: <75258a4d-131d-766a-b20c-b3cc5ee65817@amd.com> Date: Thu, 29 Apr 2021 09:32:35 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 In-Reply-To: <238f41fd-2f7b-cfa0-b538-2a659c38c7e3@amd.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.11] X-ClientProxiedBy: SN7PR04CA0010.namprd04.prod.outlook.com (2603:10b6:806:f2::15) To DM6PR12MB3435.namprd12.prod.outlook.com (2603:10b6:5:39::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [172.31.9.26] (165.204.77.11) by SN7PR04CA0010.namprd04.prod.outlook.com (2603:10b6:806:f2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Thu, 29 Apr 2021 14:32:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e307f9cb-714c-4100-9022-08d90b1ba34c X-MS-TrafficTypeDiagnostic: DM5PR12MB1195: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HRN8kQ1I7JjLQmj2KylpNoE4eIhjA10Ig4M1oHv3F9LYm/JsMcaLR+9EhwGPJbelEmdqWe/7n74mOyeM47HPhMSiFVhzHkCjO59FOt3qo8Lvk96ziORkY11JwgHZzsKJJMhw5s1X+87A/EDI6rv4ozhPOi9Wdh1/9BOqGyJ9O/0shpZ5ShNFsqap2dMGMa4GaEincx4bpmxvrIA4VmnmgMXGVqSaF6slAhX+8pEpLoBLs5jMYwltdlmm5GcWDrEbnisPIBKCX2zKJ4P1TgWQdTg18mKUMtF2KAQwob+DaJUUXPfevKAAi1qLavX4fQ9g0QR3owoFIm2W0ciIMSRXTARxLIaAxwTb+kYPO8OtDzBknHrB9M8Mc+IrpTfs4axTJFzJTz9IGEaJK7EK/x7ghU5YD4qkQ6sYCHk6DXPRuZwapU9/lEb3MU660fMjhUqJJDZORlVx7wHuqxXlesC3Jj6dZ4HoqkoAoAvcvqETgnbZhROw8OGaLyttXhSGyOdc6kopkg58s0EwuA8ybJALYmBAtb1m8wjAF9vorsdgZ+UeePy8s2w8T/oHmfqx4M+wLWM18OeXNfG5zD8YU4NFBNTxiwnEGvDOn68aPsT3RFw9eUoNCliU++7vQyhtU5f8cMCHVI/e8NqeNEJzuHcChvPvh3571/8xZBdF+dyabZiQQ85+jzCz1u2tHCwGsc+y X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3435.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(366004)(396003)(346002)(39860400002)(31696002)(956004)(5660300002)(53546011)(66476007)(31686004)(16526019)(66556008)(478600001)(186003)(36756003)(8936002)(316002)(2906002)(38100700002)(6486002)(2616005)(8676002)(83380400001)(4326008)(66946007)(26005)(16576012)(110136005)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?a09tUmYwYXQ4N2tpOFgyY3hZb3J3Vlp6cXNtTVY3SnI4eEorangxaHhCSFhr?= =?utf-8?B?RFNyak9YMGNXYWZPaEFKQVRzOGtCdmhOUGVBc3pLaDBJMWpDUEQxeE5kaUp6?= =?utf-8?B?RXZTRDQ4RktpMmcvQWpyeE9TUnV0REpjS3dQbUhhZkh5T0xtblhQd0Z6WnRD?= =?utf-8?B?U2t1cmZPM25OZ2l4czVmMEdrZGdNSytTUVVEMVliUUY4SlB6akVGK2g4UExa?= =?utf-8?B?MTZaT1ZRa3FNdkxWSlZqeHZzWDl1SW5qU3VGdHAwTFI3KzRFLzU1dXpBZURl?= =?utf-8?B?M1BuZUdIZ3pPUzdIUzZzOUh4dXhIQ1pCZllVMVdLQWtGaUNhTXl2R29BUW54?= =?utf-8?B?SXVkM21uL0g3MGRVQ3BOOEI1WDBucDM4dlZodi9tZmlTU0diQXFrOTBpclJj?= =?utf-8?B?ZFEvL3lONEhmZmdIS2xHdVJJbFhRUmQ5QlBZWHU3aHpGNFpDN3MrWUdMNDRi?= =?utf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?= =?utf-8?B?WXAwdnhRWEs0UFVEbVNpdWxNdDAwQXBKNkRCTUhmT1JsQ0llbVlYNDBHUEdi?= =?utf-8?B?NTlPTVorNnI3Vk5rbkFDbUdJaEREY1hVOHJ1VmMxckJkbE5CalgwL3ZCYTFM?= =?utf-8?B?Um1weTg2bHFRbU8yVEpuTmM2eE1mWFFuNTNoTDgvSFVEQkxPd25kajNIWldu?= =?utf-8?B?SFN1TTFMa2Z3ZW41SWovTGRpNXZsdGpNRXdIclV1ZXdYL0U4cGxuVzQ5akli?= =?utf-8?B?THlEaHlSUWx5Znp4RzFmSmR2K2dGNm5mZy9lR0UyN1NVSzJrQ1pMaHdUTjNG?= =?utf-8?B?UnhGdVRNU1V3OHRkVHB2ZE9qMnE3dWFJQkdNMC9qTEVSeUZlOGtRZFNjT3h1?= =?utf-8?Q?6vd2tAw7xmJ+UInMbMoqeeBWeLHlfm7auZMWEdy?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e307f9cb-714c-4100-9022-08d90b1ba34c X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3435.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2021 14:32:38.2521 (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: ZBumoG/ooUfyvhsUeGrGCkktFYuEu2e/kMw76NekXBy8fMXFH0tpVPNdxPlq7N0Bdk7I+sTPHp/AaxF+512b5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1195 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/29/2021 9:25 AM, Tom Lendacky wrote: > On 4/29/21 9:01 AM, Saripalli, RK wrote: >> >> >> On 4/29/2021 12:38 AM, Reiji Watanabe wrote: >>>> + if (!strcmp(str, "off")) { >>>> + set_cpu_cap(&boot_cpu_data, X86_FEATURE_MSR_SPEC_CTRL); >>>> + x86_spec_ctrl_base |= SPEC_CTRL_PSFD; >>>> + wrmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); >>> >>> My previous suggestion about updating MSR_IA32_SPEC_CTRL meant >>> something like: >>> >>> rdmsrl(MSR_IA32_SPEC_CTRL, current); >>> wrmsrl(MSR_IA32_SPEC_CTRL, current | SPEC_CTRL_PSFD); >>> >>> And this is to keep the behavior of code below check_bugs(). >>> (Or do you intentionally change it due to some reason ?) >>> BTW, x86_spec_ctrl_base, which is updated in psf_cmdline(), >>> would be overwritten by check_bugs() anyway as follows. >>> --- >> >> Since psf_cmdline() directly writes to the MSR itself (and it only does this) >> if the feature is available (per CPUID), check_bugs() should be ok. >> >> My patch for now does not depend on the value of x86_spec_ctrl_base after psf_cmdline() >> finishes execution. > > Reiji is correct. What if BIOS has set some other bits in SPEC_CTRL (now > or in the future) as part of setup. You will effectively be zeroing them > out. The correct method is as he has documented, by reading the MSR, > or'ing in the PSFD bit and writing the MSR. Yes, I agree with his analysis and fixing it. > > Thanks, > Tom > >> >>> void __init check_bugs(void) >>> { >>> <...> >>> /* >>> * Read the SPEC_CTRL MSR to account for reserved bits which may >>> * have unknown values. AMD64_LS_CFG MSR is cached in the early AMD >>> * init code as it is not enumerated and depends on the family. >>> */ >>> if (boot_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) >>> rdmsrl(MSR_IA32_SPEC_CTRL, x86_spec_ctrl_base); >>> <...> >>> --- >>> >>>> + setup_clear_cpu_cap(X86_FEATURE_PSFD); >>> >>> Does X86_FEATURE_PSFD need to be cleared for the 'off' case ? >>> Do you want to remove "psfd" from /proc/cpuinfo >>> when PSFD is enabled ? (not when PSFD is disabled ?) >>> >>> >> No, it should not be cleared, I agree. >> But I did test with KVM (with my patch that is not here) and I do not see >> issues (meaning user space guest in QEMU is seeing PSF CPUID guest capability) >> >> I see no reason to clear this feature and I will submit a new patch with this and other changes. >> >>> Thanks, >>> Reiji >>>