Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754760AbeAMX1m (ORCPT + 1 other); Sat, 13 Jan 2018 18:27:42 -0500 Received: from mail-bl2nam02on0052.outbound.protection.outlook.com ([104.47.38.52]:28832 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752543AbeAMX1k (ORCPT ); Sat, 13 Jan 2018 18:27:40 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [PATCH v2] x86/retpoline: Add LFENCE to the retpoline/RSB filling RSB macros To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Rik van Riel , Andi Kleen , Josh Poimboeuf , Peter Zijlstra , Linus Torvalds , Jiri Kosina , Dan Williams , Dave Hansen , Borislav Petkov , Andy Lutomirski , Kees Cook , Thomas Gleixner , Tim Chen , Greg Kroah-Hartman , David Woodhouse , Paul Turner Date: Sat, 13 Jan 2018 17:27:30 -0600 Message-ID: <20180113232730.31060.36287.stgit@tlendack-t1.amdoffice.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (10.161.151.159) To BN6PR12MB1140.namprd12.prod.outlook.com (10.168.226.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0feb7bc5-2fcc-4e7d-4cfb-08d55add3a1e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:BN6PR12MB1140; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1140;3:466d54d0eeJU5jCOWn9R2RsWiYBxWKGBjdvwW2wk4CoW6RV5NoO7A/Fy1r2h9Z16S0QfU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3wVQdGjoxi/Zlja71X+YRNbzOoIlUPBZg8xVymceR4F2+B3/MYerugg69byx/c4pfK7dlCWuvD+NY6sy0vwBXj6Lv9m7QrVEGHOmSF/0nBhz0aBMurjztePA4uUXzWuhIQfYXylCeZWULojCNJOZ4mUiotMypanTKTM7vo4dVdKN+w4/V3qjpAyjHiAMqu/qzv9YlPmyYOs8HtKVDUS147A1TatTTxWHdRXsUJyajePmU7hdg6iR1Bkhs58JozyhzHoRcyCaeZjHt8;4:UnqYan1uavA/lnJV2zk1N4quAWF9arrEyFonNkCrIXKjhcp7ehX+6K1A41CXPjbYf8NHP4jJ8cXIB2r8h2tVG7/6SevzNkUZ0MOeGkO1YXRxLkaKBtk5rwgvmanQjg+BAi1HZFQNPv0gzSq8kr/shTVefqJ691Y9Rfo8md+RheVNWjupzXOUKN7H6h9m4m/NNxyKqmS3eG9Zo4aZw9J2WgaUB7V35QAztf98JPsr54+ej/4DEaj0LWfj/FAyeof/fWyJC8OmuwD3Eb1CekKvVXMFwEgKVWBEfmLzchBOUhvxWxZqhWm26hcokvOyaiBA X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231023)(944501160)(10201501046)(6055026)(6041268)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(6072148)(201708071742011);SRVR:BN6PR12MB1140;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN6PR12MB1140; X-Forefront-PRVS: 05514B7026 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(396003)(39860400002)(346002)(39380400002)(376002)(189003)(199004)(305945005)(52116002)(7696005)(7416002)(55016002)(103116003)(58126008)(5660300001)(2486003)(23676004)(59450400001)(8676002)(386003)(8936002)(6506007)(81166006)(81156014)(68736007)(54906003)(9686003)(47776003)(66066001)(53936002)(97736004)(316002)(25786009)(53416004)(3846002)(86362001)(478600001)(230700001)(2906002)(6116002)(97746001)(7736002)(83506002)(4326008)(69596002)(16526018)(105586002)(106356001)(72206003)(1076002)(50466002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1140;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxMTQwOzIzOmFSdmRCNWNmQlJXRzVLYzZvNzZ0VEV5RFZP?= =?utf-8?B?aHJzL3RlTFA4M2EybmZvMjBPWnp3NEo0L1dpanIxa2hpdUVLa0s1NUJHeER4?= =?utf-8?B?Y3A0ZUdEd0kzeTh4WGpZRlVrYlF4Q0lGOTBEZlRqSi9aMWhDY0Y3NG50WTNl?= =?utf-8?B?RFpBQzVMVFQrYTIyQWwyaHBLK080QnA5ZFNuMzRSMHF4ZVhKc0ZWN0I1SE5I?= =?utf-8?B?cG4yK1pCMlorYXlQTDZBM0lkd09HK2JVNGJlUkxCN01HZFJUU3duZzhVYmE0?= =?utf-8?B?UlcxWWhyNmdXSC9sOTlWam9vS1QwSThEZXNpZm1YNkVJdEw3Uks4RlBid1k1?= =?utf-8?B?QWJwZ3NJRmhmdDlRM05SSzRKL2szQ3FidGlxWU83MDhNS0psSHFUZEFhQjV6?= =?utf-8?B?MktUMjJORXBLQlpoUmhzSko5SUdKNys0aHAvYlBUZytPOSs3Ymw4OGtjZU1z?= =?utf-8?B?dzlSdFp0Q1ZWeHUwbTU1eXo5WVhkM3NRaGF0c3NTU0w4TVo1ZE44K09WRjJI?= =?utf-8?B?eTV2aWtYNmNlVzdaemNBSkE3dDdkdU9kZHl3RkJWZnF4ZEx6V01IbnZyOFlL?= =?utf-8?B?V3hHVEtEcTNmOHZTREdXajZ1VDZqVWEzUHpOaHcxWGhvRGczejR2eTUvNXll?= =?utf-8?B?YW5tak82QXpjQU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pamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1140;20:PBu1X3pYGH523t2eYQCbIN6aeHU2emtNJGDeN07VvBAW3Nak0rcz4QmvTax3o2bNM1aXx87JWoTxYKXdingOwe46aOTMNi824T31EcA2plvZ0jU7+L5RLOU92K8O3vq25RhKV8I7y6vboqom5PxknrfWw+zm7/NnJI2rYLwGC7sFOpLm3b+FutG91lBc39NfFqlPQmpWiiQ4Xi07xaMm51Fsbu4JFo6jM9KxR7V9fDfuyIm3LCjhv+qY6Vpyt1Z6 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2018 23:27:33.8379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0feb7bc5-2fcc-4e7d-4cfb-08d55add3a1e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1140 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: The PAUSE instruction is currently used in the retpoline and RSB filling macros as a speculation trap. The use of PAUSE was originally suggested because it showed a very, very small difference in the amount of cycles/time used to execute the retpoline as compared to LFENCE. On AMD, the PAUSE instruction is not a serializing instruction, so the pause/jmp loop will use excess power as it is speculated over waiting for return to mispredict to the correct target. The RSB filling macro is applicable to AMD, and, if software is unable to verify that LFENCE is serializing on AMD (possible when running under a hypervisor), the generic retpoline support will be used and, so, is also applicable to AMD. Keep the current usage of PAUSE for Intel, but add an LFENCE instruction to the speculation trap for AMD. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/nospec-branch.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 402a11c..7b45d84 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -11,7 +11,7 @@ * Fill the CPU return stack buffer. * * Each entry in the RSB, if used for a speculative 'ret', contains an - * infinite 'pause; jmp' loop to capture speculative execution. + * infinite 'pause; lfence; jmp' loop to capture speculative execution. * * This is required in various cases for retpoline and IBRS-based * mitigations for the Spectre variant 2 vulnerability. Sometimes to @@ -38,11 +38,13 @@ call 772f; \ 773: /* speculation trap */ \ pause; \ + lfence; \ jmp 773b; \ 772: \ call 774f; \ 775: /* speculation trap */ \ pause; \ + lfence; \ jmp 775b; \ 774: \ dec reg; \ @@ -73,6 +75,7 @@ call .Ldo_rop_\@ .Lspec_trap_\@: pause + lfence jmp .Lspec_trap_\@ .Ldo_rop_\@: mov \reg, (%_ASM_SP) @@ -165,6 +168,7 @@ " .align 16\n" \ "901: call 903f;\n" \ "902: pause;\n" \ + " lfence;\n" \ " jmp 902b;\n" \ " .align 16\n" \ "903: addl $4, %%esp;\n" \