Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759239AbeAIXi3 (ORCPT + 1 other); Tue, 9 Jan 2018 18:38:29 -0500 Received: from mail-dm3nam03on0085.outbound.protection.outlook.com ([104.47.41.85]:29447 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759206AbeAIXi1 (ORCPT ); Tue, 9 Jan 2018 18:38:27 -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> <12147db9-e975-268f-55ee-247868e0e0d8@amd.com> From: Tom Lendacky Message-ID: Date: Tue, 9 Jan 2018 17:38:19 -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: DM5PR21CA0047.namprd21.prod.outlook.com (10.172.92.161) To BN6PR12MB1139.namprd12.prod.outlook.com (10.168.226.141) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 72fbcbeb-84ef-4339-84c8-08d557ba13a9 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7153060)(7193020);SRVR:BN6PR12MB1139; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1139;3:Y/mRllaooytGYQiSmftcqJA0aBBg7NoqLwi5CzCqCX7lyL4XRaGGCsPfuALr6+WVjO0R5lvGY0iP3og78Ncsy8rvL/TGb9Otpj55Tdi2Db+vRA/OMcb/X21QuzuZ8GKIL0qZJl9bdIsNdUuBlmT7CfxERiiCnE/TBThdHqhkjeRXB8M7M0YQpeRNPOOHvzC9u7sF6HXs1r4FLHaHq5g94wlesle0++I7fIp7C472K5PlMYOBm1qJILfZqiRWcDGk;25:CcxQeqZO3XS4wsZ82QSgnLfmq/ysadDU6KjtX6ZKH0SHSTsEqqAOP7YKzD9ddg2zqFRZoRmWFcAscgciURqXeIPuBFz8nyPQf7Mb63BbVn60BR+zi2fzYjt1YzAk3EdTv3UWjsu6avzSZxmA+2QlgS1ZU88eVNXIHb8c8jaYw7/PMNc2elU/y0cdaM7xUbBVwc7FUYJQH1j8Em5LzbD9yzYGG4UGOBEI+z5i6acv++J9mo40OB7TYv/5adOepG4/WoDB7Y+kndtbgrOwe3f4gVe9xbB97lF3FX9Uplrte6Ja+HKia5TDFjDtBAPcajFOHOHXditzeF5wzcOeTFfmcw==;31:KQECmna23RTIHCAK251jYEwMOGeBM7LUHknU4SeLZnT87ZATb/wrew/t3BgHiSZXbgfBNuytd3G9NN4TMLGaib8yWL3De4VYm0yMEPgmuVSXBwmrEIr6ipuwINQ0nwY9w9PDqdCdKFy+EcOeaSg1YJcPurayuy3uK99HvfAmJBEWXrKkKif11O6YyRgxPs7aLFFlujHvQ4XCxBw3hjOObICYY76W/CAYixPJitsCW04= X-MS-TrafficTypeDiagnostic: BN6PR12MB1139: X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1139;20:w9wbxC11UtwBAlzIJzM/+nMI6wOxMTqDg/W/Cjb1+8wliZHg4OZAqRi/PH1qec60jXjjghmihdwM56jUSCO87XQ7ozI5Fl7QTgzSjIuojTg4aqRxWiRiKI+qMc9FBa4GXi58Bp/3ubFLJAnEDivJxvMMRt3QEEp8vQZdnuNlL3QjG9tZwmXp57YJ6kyaZ7/0nHUn/Qml4ooXhwCO5unt9Jb8P1xKrurnl92Pbz14EuXt+M2DV8lNQCnZzsUfmaZNbXjbOdbqfbJPj2+OFFT/dVoLNvUTb1zb1HBcR2vR2JkXZcHPEMnFbuzQRB1v3eYvIyxrfzaVvoAWF3Hhh6WnaNissEx5AshypyYMOjS96XpeCGsJm91aJ91nGv9TwPuosRtUJuIJB3yQyMnjMyc/Pus5cJoW2WIzV+vhFrBWGI0Ru/mYtLLXif2AAYiMAKorWYcHUYfzaQUnobHJcWwoLUaynOJOAOT9JR6Trt/aEeC4DPIZb6vHM0HrDZUBuelA;4:zjzF/2aCazd6kG593dYWoEE22y3A85JlCSnsmMiIMsEA5aPQQ++FYQyjfdPLNZrcPzMTS7HhIXHFFAK2VNTdnKFUAECfAvhw5e3kGbIgUky5L0EEfsI2e2DWHiHC/ZzW/JuwIR436R3BplGYSEjYYtMze8Ey1dTVXpfOhL9IH4xSgtAsQ2i7B+5RA3zPJKyjX7eLwO3yMSiiq5SbINXm2UvCSOArBXrvfSIXNptK5GSLb7jJn3RYdBnFDuk7ecK3lmMSw18E6FilLQ+N9n0+aQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(10201501046)(3231023)(944501075)(93006095)(93001095)(3002001)(6055026)(6041268)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:BN6PR12MB1139;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN6PR12MB1139; X-Forefront-PRVS: 0547116B72 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(346002)(39380400002)(39860400002)(366004)(376002)(396003)(199004)(189003)(24454002)(16576012)(90366009)(83506002)(72206003)(54906003)(2906002)(230700001)(36756003)(65826007)(6116002)(478600001)(64126003)(25786009)(3846002)(77096006)(6486002)(86362001)(229853002)(76176011)(23676004)(52146003)(2486003)(6666003)(52116002)(58126008)(68736007)(6916009)(16526018)(53936002)(59450400001)(316002)(97736004)(2950100002)(53546011)(50466002)(386003)(105586002)(5660300001)(6246003)(7736002)(81156014)(4326008)(8936002)(305945005)(3260700006)(81166006)(93886005)(106356001)(47776003)(66066001)(65806001)(65956001)(8676002)(31686004)(7416002)(31696002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1139;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxMTM5OzIzOnN2eHByN3NhTTlvNk9iZW1TcW5IWnNRbG5x?= =?utf-8?B?N1RKaW1MbWRSc2IxUjhVWS8vd3VLeDJZZnMvZWs0cndNU0ZCS04rVytEL1Yy?= =?utf-8?B?bTU3WDRzVDFpSFFwa1ZNaW5pSXFFUjBWa3puYzRYYUJ6YXI4TW1BQ3FuTmc4?= =?utf-8?B?YnJ1NitraXV5OFpWZnp4aVhKUEZzZVhRMzdPR0hyZjNwSnEzdVVndUd2MlYy?= =?utf-8?B?K0UzYktacHRvNFhXd08yZ25oM3hPMnlXTU5rNngrNnYwOS9ZT093MEVzaFVX?= =?utf-8?B?NFl2UWk2K2p2T2swYmRYTzBET1l5bmNtVVVjOWE0a3Zla0paUG44c0ljOTN2?= =?utf-8?B?aUlKR2h2UlBEaDJKR0tFKzRZY3Z4bGpBSFlWUUNiQnRoNlAwWUhieHdDdU9Y?= =?utf-8?B?WDVrUzZRMnk1WmZxVE1YeWg2anFYeC9BSXN5ZDhRRjRXaFJLSGVGWXFsOHpB?= =?utf-8?B?ODY3UXI3elNFU3pOMUhiL2kzUjVQYXdacU93Z3J2aVdSSUltcHppRDh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9ISRwwN62Ail4+EsJVyAI5UgS+7f05Z9yXQRxas3qSjg6gJGnj3rfEp5CGbtpRYsxu+Gp7XdPQ8=;5:WZ5EP6FzP5i8A8G581rSsbXNBVZq8V28+HRfP0zuORSKisVRFXvb2UwBed3L78axU1hbXWymYqVXfrKJs3yqUSU28jw1S9WqpilBPGhnDlmO/HL+/CTRyTNKX/l2YE354tSAA3CmHvJAfmrAnGOs635KEG/a8p5KNouLx4LI2kk=;24:KExAU86B4xFUyd5EIPLg09cpUODo87M+Wq/xvAHARCP1MNe1kmngNINaHMSnkgaV9YehnYU4nKoTFyZzQ65FrmaF+On8HHA+l9BU8Otk470=;7:5t8ybPfKrY7PPvKQ/HK83CQOPnKt/iPZEc7eROs2hLZgQXzI/TxvPCFucd/oEA14b2BtaG035KEmMLfccJG8cLK4O4zN7GxlPfmloRgOUKbS08GUdMvJqcdZNeIKTz2R+KDtdpD6grHqsUJ1sBujTSnBHPPk9nCwEbIzwjocjydsefP9k6cX0QwmCBWb/RjXPHrD/7fkIWXEAuXKbDn6wbCYI5iLaTrDpHWhxmcH8q1StdkglB3A5973GKIDOYhl SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1139;20:S1/1pavFIBne+1g6Ojt/ZF7yyfOQZgax7rvx7vdLG9UfvnF9FA9kE6N0knQl0sWC1p/WC+BEND8sNQX3tV9l386J6tFvh6YAWYslJIJbM2GD74pHzYpAYGwaH93sqojrz/agY/FZecDc+3Qi1zz1QTGRNL0qvB2vZn8FZ2dtTdJTe2CcJ2scdOfcCtFqUJcM6tqvYqS7dtwW+Gpt9kCN7Rpq2xc46Cv6CfaR9TBW8/zH713AYzi82UThluC3IsFO X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2018 23:38:23.3047 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 72fbcbeb-84ef-4339-84c8-08d557ba13a9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1139 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 1/9/2018 5:09 PM, Thomas Gleixner wrote: > On Tue, 9 Jan 2018, Tom Lendacky wrote: >> On 1/9/2018 4:46 PM, Thomas Gleixner wrote: >>> 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. > > Wait, we can move the selection _AFTER_ identify_boot_cpu(). Much cleaner. Since it's just a single patch now, do you want me to re-submit this after I test it or will you just pick this up as is? I did notice that the patch does change the behavior associated with the command line options, though. Not sure if that was intentional. Thanks, Tom > > Thanks, > > tglx > > 8<---------------- > > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -152,7 +152,5 @@ > # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) > #endif > > -void spectre_v2_check_boottime_disable(void); > - > #endif /* __ASSEMBLY__ */ > #endif /* __NOSPEC_BRANCH_H__ */ > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -24,6 +24,8 @@ > #include > #include > > +static void __init spectre_v2_check_boottime_disable(void); > + > void __init check_bugs(void) > { > identify_boot_cpu(); > @@ -33,6 +35,9 @@ void __init check_bugs(void) > print_cpu_info(&boot_cpu_data); > } > > + /* Select the proper spectre mitigation before patching alternatives */ > + spectre_v2_check_boottime_disable(); > + > #ifdef CONFIG_X86_32 > /* > * Check whether we are able to run this kernel safely on SMP. > @@ -106,7 +111,7 @@ static inline bool match_option(const ch > return len == arglen && !strncmp(arg, opt, len); > } > > -void __init spectre_v2_check_boottime_disable(void) > +static void __init spectre_v2_check_boottime_disable(void) > { > char arg[20]; > int ret; > @@ -148,14 +153,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 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -1322,8 +1322,6 @@ void __init setup_arch(char **cmdline_p) > > register_refined_jiffies(CLOCK_TICK_RATE); > > - spectre_v2_check_boottime_disable(); > - > #ifdef CONFIG_EFI > if (efi_enabled(EFI_BOOT)) > efi_apply_memmap_quirks(); >