Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751368AbeADXr2 (ORCPT + 1 other); Thu, 4 Jan 2018 18:47:28 -0500 Received: from mail-sn1nam01on0054.outbound.protection.outlook.com ([104.47.32.54]:11950 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751243AbeADXrW (ORCPT ); Thu, 4 Jan 2018 18:47:22 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: Avoid speculative indirect calls in kernel To: David Woodhouse , Andrew Cooper , Paolo Bonzini , "pavel@ucw.cz" Cc: "tim.c.chen@linux.intel.com" , "linux-kernel@vger.kernel.org" , "torvalds@linux-foundation.org" , "tglx@linutronix.de" , "andi@firstfloor.org" , "gnomes@lxorguk.ukuu.org.uk" , "dave.hansen@intel.com" , "gregkh@linux-foundation.org" , Andrea Arcangeli References: <20180103230934.15788-1-andi@firstfloor.org> <20180104114231.GB1702@amd> <1515066469.12987.112.camel@amazon.co.uk> <94b12025-b27c-04d2-8726-c07a3af6b265@redhat.com> <7a3584c6-0c00-d807-5130-13d1f4b34102@citrix.com> <1515079777.12987.149.camel@amazon.co.uk> <1515082507.12987.159.camel@infradead.org> <1515096331.29312.35.camel@infradead.org> From: Tom Lendacky Message-ID: Date: Thu, 4 Jan 2018 17:47:15 -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: <1515096331.29312.35.camel@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR22CA0056.namprd22.prod.outlook.com (10.171.142.18) To CY4PR12MB1143.namprd12.prod.outlook.com (10.168.164.135) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 470580dc-e144-4db4-506b-08d553cd7efd X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(48565401081)(2017052603307)(7153060);SRVR:CY4PR12MB1143; X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1143;3:Y+fSOgS2P+drvkFH+id8125c5NePOZAivHHTq06PNyH3iK4n1eM70vsnMyEggZwPFIlpOryg57KRYVYGxGxOoRPzsCcTlNd4PhtWtUP0aIw7v7FAYMjQNvTbe1tZ5PyW6Sy5BrfiGjH1NslzaFc/a+fjwVI5slyspj3oG1hfA0OGF6hx9YjmnSZ6hwG8T3IPzJyUKkvQN3X83ta/H5blOF34ukbAUX1SjSEMKAP1DySeWywwgqkRYjM9rfdM+Isn;25:rJZZbJHOSlkdl81FN5ZQ6pBZxPrSKvS8k51cipzV3hNELRfMSIbSaE8NHFRGZq3m9n5Rh6UaeRZLcvnPtuxJtCSUILjQc1D3HEF7zvmjLPU9mwohdlDmUEFVyU0i9Y7PNlEy2Sh7LOqlmpOuMKCWKTqv/BMlKXnQUv5JNajDbFYUDaOlnVXWWCuMRIS6TlPASFqYmfw4DXLkRiPBWhKHaroaGsxAf3ire3RgSeLyVysWcdw3RS2YSKXlquW6lQIbz/O4pP2brlZzrCl0e8J+aMQdvCkX535GoT2UumJbWPOPxqVsC6xYMFFS1fAFVdBk2QYcXE1tkEEHSFRimYOGoA==;31:9Iyjk4YTUY7Pkr9RplY2Iy/Uu/dyQIMpq3e7uUdu2QfdqwJ2skilRvd3kOTu4uv0nEnPNQdL0VDvZpqUwlMBAhH4JQY04cvPAbiWaZ36ub3qbm8UXW8nutuZzMZg3cfeNOJXgkE0OTD0dg5hGkSi6h6s/LmSRdjc9wFUFK5wOD+eP8AsBPNcinFPq4HZN3aUZ7wchr4+CJ4ujxBdcAdWjgNikuki/nrUQZziFb0+NkM= X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1143;20:ErlyRcjeWl4INU5gXxqekDh//Wgrkw+4qF26MLQW3DfKr4A4M14bMNl3nD4QlNNzPlzYkIRr7Bx6+85gT8/u4zL+9CgysJ/j8cgJEFi5CX5fK6S5eFZ2l+Z1xO0jkYcOcskMXbVAUnktduWgKPPuTZ+iy1BKOMh4ob5/rU7NLkPonBLJTOyIvWaj0wyCNGb8+4YhJ2NQzUM2qHV0tH5EFn46hzHUiYVMvA8hkS2Qbayg2sZ4B/099DTIA6Tg+vVrhsOTKvxV7PbUUBmIVQaafCn8ZhtV3OZafHwpsOV0sQdrEtAwGAnHP8h/9UlZUbwQSrX4xFKRDbTTESE7mDrJ7KK1xShn0+9m/O33Npao2O9UiNkVDXMzwbrhGNE90/3JU4cjCA8VnUVK6Kh4XIcSmiJBk8Ad15MarG5NAuk6Ulthwsy6uD1P9pju88hoIJfbjT8wcIFHNsEnnmike6twT7hYwzr4LHn6HuU5IueYoH66TBi+49c7k6GXws7NQwBM;4:uRKNxeCCuwTZh+SIr3NzxU47okqYd466XfmRENaO1sYid3yYcVjMkmG3QYVw4Tdaxs7CakFvmVFT/PFQeZ4EI5Ngem6TNF12tZ2fLO+w4Hs2HtzVpgrdqDZ1t/fhrSl09kHzQk+iyanbvuAn/pD4npj+7ix3b8IeTOjOLYH/2t8ymNVlMX203OTsWLUIZiQFdwKiD1ce8f4YX/rDIyWuFwHu3unnsTCRiykk4DE6akJNmS6sVBUvJI2trg8CSr03xtZSA4oLMTu2zkNQ22VaL+/vJbtjdaR84i2wLDdnrrf059bE117sfiNQ+STSKNw+zLN4dUoXuPmnKvIHluTkgQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(146755900322472); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3231023)(944501075)(3002001)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(6072148)(201708071742011);SRVR:CY4PR12MB1143;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CY4PR12MB1143; X-Forefront-PRVS: 054231DC40 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(346002)(376002)(39860400002)(396003)(366004)(39380400002)(24454002)(377424004)(199004)(189003)(2870700001)(77096006)(31686004)(6486002)(5660300001)(2906002)(4326008)(229853002)(90366009)(6246003)(6306002)(65826007)(81166006)(31696002)(6666003)(53936002)(86362001)(2950100002)(25786009)(386003)(53546011)(3260700006)(305945005)(65956001)(65806001)(7416002)(6116002)(8666007)(66066001)(3846002)(81156014)(7736002)(110136005)(8936002)(50466002)(58126008)(54906003)(47776003)(97736004)(68736007)(16576012)(16526018)(316002)(76176011)(8676002)(478600001)(966005)(2501003)(72206003)(93886005)(105586002)(52146003)(52116002)(83506002)(106356001)(2486003)(59450400001)(36756003)(23676004)(64126003);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR12MB1143;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTRQUjEyTUIxMTQzOzIzOmVWYUt5NWg5RjVFNHI2SWJ3NTM5bkFtUklz?= =?utf-8?B?VjNmRTFrNkQvR0d0NVRCYklRVUZ1a0l0TGtCajdDOWJ2U1lRdUxBMHpzVXRW?= =?utf-8?B?ZUVjMGdCWUtZVi9VQ01Ua0RHM0MzQWVDTjczMUsxNTJxVE1ZSHl1K0oyd21M?= =?utf-8?B?NkFEMDVTOW9GL1pkbUJ4V3FodlJiZDRGMEJWbjdabzhjb3dRdXhBdnZ4a2RC?= =?utf-8?B?OGpJMXc5VzhQbndoWm5SKzM3QitaSHBEMWZ1K0piMjVteDVRSS9SL25FdXBz?= =?utf-8?B?U3dlSEN4SWFWc3VBaE1JR1pzSmtxRFZscTEzS1FGZ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NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR12MB1143;20:+93E4tP9FXj4vq9DJalXE8k07+Wr1wk1U5ew4ml9LPXHsEzj/7by2sxkr6aESKU22OebHRUkA5xA1L/zjSqe59Q/KhEbBpOQKaiALmimFzCHlYVwpGgORrLHaU7QgmrMB3bxyC4sqmeT35MMeKJKx2Ua5gaMbt9YQ7gLIltm0g6XYffFTjxeaT2qAcnGGIKnnO63xqrUXR2ZEQ4y5WB0LBCIJeATGs76hkjPXosJMSsS6OBTRHHcGgv4nwnG2z9r X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2018 23:47:19.2349 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 470580dc-e144-4db4-506b-08d553cd7efd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 1/4/2018 2:05 PM, David Woodhouse wrote: > On Thu, 2018-01-04 at 14:00 -0600, Tom Lendacky wrote: >> Yes, lfence is sufficient.  As long as the target is in the register >> before the lfence and we jump through the register all is good, i.e.: > > Thanks. Can I have a Reviewed-by: for this then please: Reviewed-by: Tom Lendacky While this works, a more efficient way to do the lfence support would be to not use the retpoline in this case. Changing the indirect jumps to do the "mov [rax], rax; lfence; jmp *rax" sequence would be quicker. I'm not sure if this is feasible given the need to do a retpoline if you can't use lfence, though. Thanks, Tom > > http://git.infradead.org/users/dwmw2/linux-retpoline.git/commitdiff/08d9eda03 > > From: David Woodhouse > Date: Thu, 4 Jan 2018 20:01:53 +0000 > Subject: [PATCH] x86/retpoline: Simplify AMD variant of retpoline thunk > > On AMD (which is X86_FEATURE_K8), just the lfence is sufficient. > > Signed-off-by: David Woodhouse > --- >  arch/x86/lib/retpoline.S | 2 +- >  1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S > index bbdda5cc136e..26070976bff0 100644 > --- a/arch/x86/lib/retpoline.S > +++ b/arch/x86/lib/retpoline.S > @@ -11,7 +11,7 @@ >   >  ENTRY(__x86.indirect_thunk.\reg) >   CFI_STARTPROC > - ALTERNATIVE "call 2f", __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE > + ALTERNATIVE_2 "call 2f", __stringify(lfence;jmp *%\reg), X86_FEATURE_K8, __stringify(jmp *%\reg), X86_BUG_NO_RETPOLINE >  1: >   lfence >   jmp 1b > --  > 2.14.3 >