Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758487AbeAIXBS (ORCPT + 1 other); Tue, 9 Jan 2018 18:01:18 -0500 Received: from mail-by2nam03on0041.outbound.protection.outlook.com ([104.47.42.41]:42478 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753638AbeAIXBQ (ORCPT ); Tue, 9 Jan 2018 18:01:16 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [PATCH v1 1/2] x86/retpoline: Add a function to clear the RETPOLINE_AMD feature To: Thomas Gleixner Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Rik van Riel , Andi Kleen , Peter Zijlstra , Linus Torvalds , Jiri Kosina , Dan Williams , Dave Hansen , Borislav Petkov , Andy Lutomirski , Kees Cook , Tim Chen , Greg Kroah-Hartman , David Woodhouse , Paul Turner References: <20180109223723.29322.59126.stgit@tlendack-t1.amdoffice.net> <20180109223736.29322.5436.stgit@tlendack-t1.amdoffice.net> From: Tom Lendacky Message-ID: <12147db9-e975-268f-55ee-247868e0e0d8@amd.com> Date: Tue, 9 Jan 2018 17:01:10 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: DM5PR21CA0062.namprd21.prod.outlook.com (10.175.112.152) To DM5PR12MB1147.namprd12.prod.outlook.com (10.168.236.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 432fcdf0-a80a-40e8-b9d6-08d557b4e1e1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DM5PR12MB1147; X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;3:Ct3izL1ruqCB1nOfQ14pYVYrRLUXKqU76H6/7k9BXIDvklwlLRjRFAxbvreN21l1TU4931kqWX7PNeJR5RkjXEdjPWPRevThS4+S3onaTdUVCw44rL0L9vSMgyOkIbR0ZVCxMOK/0UMZsTmf7b6gmf1XIayBZVN8B3FpTzo0PdiiWzcxFpFGkszF++d0Y9xIhUyGmC0kov2niP20iPLpQbCZRmOukTBlwqBBFnqxO6ptmn2MnCx+4skmJBW3YRh6;25:bSbbB9HYUfgiUcfQMwcy86qo3IvxcLaW6jE7rlgYbL0wOO3xtdsOigijbAdYjAw0vCa/3b6akEv5toIjPm/YlTsC1q2mFLhurqKhA9v+jAlEhe59xngSS1lD3KQkVDmy//ynAyk0AJTCuNpnqfap/IkhUDrQbR2Yj/EgL9EF/HgJskszQSPCFcMJhnpWfI5XzIb61fn7ZZmlZf81X8Oxq6vwpWdWeMfaJ/tNZfQCTJ1T56MrKXW6ZmXQtmLyOa+VcnYlNFQJpOrupTYmgaZyNNyjXD+Law0udNTsyGwg2bC+Advh8NxbwaLtd8PBNjycs0uZSvwnoN2b47s9uBZ/qQ==;31:Ehq4kEuNmewR8kW6TaQddet6exSYJohBa9FvU+tAT9lNxzJhqZJ7TBB34iUObgyrVMN4os3pn6sotHIg1vm0m6YP6ZuqgxG5WRNYuGgiSUMGbdDPCYlvLol4MX3LKgMPv372xYlVRuE8Ot4y/eHLGQiK+9404V9IxeteglN91vzPWN256puSDgxJwmKRwjwhv3TMq5hdxmh+XzWORUAyWeToSEpOJ9KsTlIY7eUsIfY= X-MS-TrafficTypeDiagnostic: DM5PR12MB1147: X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:GcR9Qj3sAi4Nbqh4CrQyytUBWr/zB5U7MqPFGqzH98IA1sKNiKPx7mOzVuHkjt0tZRwDF6pMoqJ9igbaVxe6angnjMNlRmx366m25D94BZixLVHh5O05zs9GoXdPDCsed5ZghwxX8XiHkW9IcSef4r9+6mJpIQdbTdRlkZfEP9YbCTiX3hrCMAgftqZAmkeb5oiV8JudgNuS4L4f902FyBXU2bQ9e07GoEFXT9pw4/pzyncdqKv3H1R65NDn7J0wqv8ulxsvoyGxAamOjq3Oi9hcxM2GgDJVV0p4kdTiZ8PILLN64fZv4empfkmLCOWU/mzn5THMvBUre8MGHCiSTXOv2l58a5IR6UfKxkBqrZU6fBKxiJ/ebJNR50W5VlRv5WnI9fxsOQ64/nyCsZ7zx34WJE9WSeD+z1tB77sOP+15elZjuaYegLnUPowbO7AIRGasWxZf3VvxxPj2CmMPoEJLJe1QC2WxG4I/vdkme3X20AdPNn5rOJSKyA8Gi8wu;4:pb558HKaPi+F+ahH0edVwXe25b+BGH3pGoDZGSYtEKuFkts5u+gApgw6LjKLuSc8ROQc7ySx8TuZQp+BbKHNHwxYESy0gWBGDA7xig1vUOu7xGPwqf6Po3Q6TeoxUfwy6qWG1aGqp9R6580Tu8Yb/XKMQceM7uWBI7WkdWdK4ZHP2CCqN+KQkN/+ums+xZyVlCo5RGZfAXffSS/IkBNxVhjI/o2LduTqgFDCHrNGxrYsGa0cFYuTzGiq69BZ7rnIqyKg0Dx15KNGKDvKb14neAIJ6TPQfb7jIHLi6yvwXU59CIxhaeKrgIaWXKWmNgAf X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(3231023)(944501075)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR12MB1147;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:DM5PR12MB1147; X-Forefront-PRVS: 0547116B72 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(366004)(346002)(376002)(39860400002)(396003)(39380400002)(24454002)(189003)(199004)(25786009)(54906003)(6486002)(36756003)(3260700006)(83506002)(72206003)(229853002)(8936002)(65956001)(81166006)(6246003)(68736007)(2906002)(478600001)(8676002)(65806001)(4326008)(58126008)(105586002)(16576012)(66066001)(47776003)(106356001)(16526018)(7416002)(77096006)(81156014)(97736004)(31696002)(59450400001)(386003)(90366009)(65826007)(53546011)(2950100002)(6916009)(50466002)(3846002)(6116002)(316002)(7736002)(31686004)(5660300001)(305945005)(23676004)(2486003)(230700001)(53936002)(52146003)(52116002)(76176011)(64126003)(86362001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR12MB1147;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtETTVQUjEyTUIxMTQ3OzIzOmNGTms3U0c2VHQrNjNMUkd4TjNJMVdGYmt3?= =?utf-8?B?OWIvUytHeWQ0K1F6QVhuQjI1djVPVzlicm1sWHhuTjNyQmxuNnAvNnkvSTFl?= =?utf-8?B?L1Ivalh6NkNSakxZc3drU05kZ2RtM09HYllUUytpTlBjeXBFV2VmZmdNWGFK?= =?utf-8?B?TW8yQ3VwdWwxVlB1Tnd1V2xlQUM4cmkyR3hPZFJSbHI3d2crV0pzQXNuSFcv?= =?utf-8?B?ODJ4eVBtYkFZd3M3ekNvbnVrS1AvUjRBeXVXNE1CRndGTVROU1p6Z2RFdjk1?= =?utf-8?B?Q1lsdGlEMmxPeVVNeUx2QWxJM1RRdDZjK01pdkM5bmZUTlVyNWthREQydDcw?= =?utf-8?B?WE5FQlJYZ1NWR3VEdXhsMnZvV2FYRGZDb2NmTnZwblE1ZW9qUS9VWk9lay9M?= =?utf-8?B?Y0NGUUJrNmlwc2l0Z09pemRTbkN2T0dpMHI2a2VYc0x5UXVJZWd0dXIybW5E?= =?utf-8?B?cUxTVk9pNU5BYnBuUC9EU3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Zuxpb0Dz8NcoG84NDj1GCpjt7qYHbtnwo+52eogdy0uZP4qU=;5:W1FfC4Th/KlNF+0+1Ckixz+kGk36Azcms9Jah8Ez9FGHcUj6GL53qHGE1QALQGqn7I0ruuwvaZu9pGixkiqNvr+iT4Rl94Dumk9SKlo6Ne/ufp8c9jIUkOTWkx7tQ3SGIjL7Lc1hV6PljFCte8vakscvyjGnaY7bYla4sDoPk94=;24:nST7MOJM/UsoPSAhcYNExl/yv9Y/IJ0yjfxmfYFJF28mlGMoS27Dg5OdBOTPXI/Yu+fVjpJw5vdYaHpk9xqRn82bnuKuycchXGC8Xe2yox8=;7:fcutngZIKpWydLiv1/lfEPvJNPz6kX+v4+Gddq/+/Eksm15PKWf+hVv271bjbnOBlIlVu6qXoX3wXRGawbmiZuhDYrAy04r0EyjvWv6Wt394JcSujjBNJEQq8fpRoHBGmzihxh0Rrl5aoHHb5vYrnujB3PXMcFfrK0sFEomkyS46e2DVY1rlswGvOvTsYmkqTZc8ztU3kQrcVnXuHgZ476WZHab9KmcyTI92tIeVrPC6ya3ctpUkqdPrfGyJMJO+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR12MB1147;20:4tcY/fe0ai77a0Dd7BJBC787psiWtLnfJ46LATA3stNs72Kx3hPHaSdz1AKt77onn5O7u7ranT7XwwwnjDYgA0b7mbIOpxa1N7H6s7y2K0zF9QgVhWZIDsrFQXM2/2Sf8vKtx8Aq7yRBfi+hYTc4e5vcnFJ/qz7igCD6slnGYdooWs5JUxhJyYybT7cAaiVQ9thwL4NDz5wfaML6UGGtHah+SLYc68GNldbiDCFlpqETn7Xcemp+YolKlkovFHx1 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2018 23:01:13.1783 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 432fcdf0-a80a-40e8-b9d6-08d557b4e1e1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1147 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 1/9/2018 4:46 PM, Thomas Gleixner wrote: > On Tue, 9 Jan 2018, Tom Lendacky wrote: >> For AMD hardware, the RETPOLINE_AMD feature is dependent on LFENCE being >> a serializing instruction. Create a function to allow RETPOLINE_AMD to >> be cleared if it cannot be determined that LFENCE is serializing. In >> addition, update the spectre_v2_enabled variable so that sysfs output is >> correct. >> >> Signed-off-by: Tom Lendacky >> --- >> arch/x86/include/asm/nospec-branch.h | 1 + >> arch/x86/kernel/cpu/bugs.c | 10 ++++++++++ >> 2 files changed, 11 insertions(+) >> >> diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h >> index 8ddf851..5785684 100644 >> --- a/arch/x86/include/asm/nospec-branch.h >> +++ b/arch/x86/include/asm/nospec-branch.h >> @@ -153,6 +153,7 @@ >> #endif >> >> void spectre_v2_check_boottime_disable(void); >> +void retpoline_amd_disable(void); >> >> #endif /* __ASSEMBLY__ */ >> #endif /* __NOSPEC_BRANCH_H__ */ >> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c >> index b957f77..a4c594c 100644 >> --- a/arch/x86/kernel/cpu/bugs.c >> +++ b/arch/x86/kernel/cpu/bugs.c >> @@ -170,6 +170,16 @@ void __init spectre_v2_check_boottime_disable(void) >> return; >> } >> >> +void retpoline_amd_disable(void) >> +{ >> + if (!boot_cpu_has(X86_FEATURE_RETPOLINE_AMD)) >> + return; >> + >> + setup_clear_cpu_cap(X86_FEATURE_RETPOLINE_AMD); >> + spectre_v2_enabled = retp_compiler() ? >> + SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL; >> +} > > Urgh. That's an awful hack. why not do the obvious? My first attempt was very similar to your change below, but testing showed that spectre_v2_check_boottime_disable() is called before the X86_FEATURE_LFENCE_RDTSC can be set. I can look at moving where the X86_FEATURE_LFENCE_RDTSC is set, maybe into early_init_amd() or such if you think that would be best. Thanks, Tom > > Thanks, > > tglx > > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -148,14 +148,21 @@ void __init spectre_v2_check_boottime_di > retpoline: > if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { > retpoline_amd: > + if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD || > + !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) { > + pr_info("AMD retpoline not supported, fall back to generic\n"); > + goto retpoline_generic; > + } > + > spectre_v2_enabled = retp_compiler() ? > SPECTRE_V2_RETPOLINE_AMD : SPECTRE_V2_RETPOLINE_MINIMAL_AMD; > setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD); > - } else { > - retpoline_generic: > - spectre_v2_enabled = retp_compiler() ? > - SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL; > + setup_force_cpu_cap(X86_FEATURE_RETPOLINE); > + return; > } > +retpoline_generic: > + spectre_v2_enabled = retp_compiler() ? > + SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL; > setup_force_cpu_cap(X86_FEATURE_RETPOLINE); > return; > #else > >