Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933715AbeAHOr0 (ORCPT + 1 other); Mon, 8 Jan 2018 09:47:26 -0500 Received: from mail-cys01nam02on0070.outbound.protection.outlook.com ([104.47.37.70]:21776 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751597AbeAHOrY (ORCPT ); Mon, 8 Jan 2018 09:47:24 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Subject: Re: [tip:x86/pti] x86/cpu/AMD: Use LFENCE_RDTSC instead of MFENCE_RDTSC To: Thomas Gleixner , Andrew Cooper Cc: bp@alien8.de, dwmw@amazon.co.uk, gregkh@linux-foundation.org, pjt@google.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, tim.c.chen@linux.intel.com, torvalds@linux-foundation.org, peterz@infradead.org, dave.hansen@intel.com, linux-tip-commits@vger.kernel.org References: <20180105160756.23786.4220.stgit@tlendack-t1.amdoffice.net> <1b179b8b-6cc8-d736-81dc-2445be4baf02@citrix.com> From: Tom Lendacky Message-ID: <4d9a1f0d-a401-3f0f-9ee2-dd42f4b4716a@amd.com> Date: Mon, 8 Jan 2018 08: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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.78.1] X-ClientProxiedBy: MWHPR1601CA0018.namprd16.prod.outlook.com (10.172.93.28) To MWHPR12MB1152.namprd12.prod.outlook.com (10.169.204.16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a087c8b9-f542-44ac-03cb-08d556a6b948 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:MWHPR12MB1152; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;3:MhFbtJt/inMdO9X1HsAqx8kUJpI1zYaJooMe87+2T5I85d79evDutomFK2gL3JWSwb2TRgn6kN9tIFqZgXh9faVK6xDIuRvpZUKQSXJHmLSkNKYDcbJS6cmVM5t6/l3a8w9RkwEoQ2G+tVqDkAeMFPdDXH5comvZ0wyL7g0YvAd0OtTuSmn16k/Yml4YzAiqR1cRylb8M8NGOFZxm6xAo6lS2MEDfBiQj8Sao/wP6Ou8C6NGcukdo52CgggLYYTp;25:7I7WnuZLk2bzGwOpdDTVTdBX1+UD9szHDptpybmXVJnYkzY7NHfCMjtP1CILcXyrQGu7KyGBKUGj8XjWZNviK0+bfnohdFY8fCA8FVBSwqKY0NY8NcyPn5b3bTz2pNckDLQmWLoyXG+USlzdIhS48SWeN2COkF5vPvjSw9rEjSepEkIPBqy0ixen5HxIWFMD3a+hHDJlFmG4VCJZeNK521PR6eVW0Juc/abR0owlkWuiQ3GoXy6+GUpYYfuw8j1U4AHKHL1WR85TgrFElghsSUixkXvXOIO3RR+pXu9KJnyljr12gpBeEJxz+KjDGkbeuGfIfLnVt82hs5MzCSwmNw==;31:1Ozx5V4FBoa6iYB+nDsSgXn0O1M87tlKVmAWZtpsiW0AJXd+7MVpJ7+hTbQGviEoT1ERfpyOwoWoYoNI6E60Z0Y0RttxOViVXAH+8qZsCUoqBJege7F7WKGgrAgby0SqPnRA8fjcD0bm9M2V6TLdwHjxwDXVKuB4lTt2QM9Y2CrjuAa9uhubUWgqMuYQ3Ce9L8/8P4P/f6+4m82SE2HP9hPHNJm/mubZA7JatkoPLVU= X-MS-TrafficTypeDiagnostic: MWHPR12MB1152: X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1152;20:2MzJRkUfJF5ZH1b0PyPsnWm6fFvmlzuYjdub50fFb78VtHgpEl/gjoHQhuToBKFNMcBtmCfVAdoJpWOGpBDFWavze3zBraP/kGcjg0rSnlIrpyw9zbHOrYMBPPWxnJ8RLGWUL28kfMrVq2isGK9jAbKhSdcCiZ0FUl1RUlO5QTVIJBGBmh0CCqddvPmyW8Swsv89jAs+nW2beB6+qRBmTj6Dx2GghRf7DhfoEzjv+2IeED06wegCXy7hGfl1JHt2ppSwhWpaK0B+T9IKR8uurFLOcH6aIrixiffltC1ISLu1JcJiGO8alnuGDYOVfuwohDhMj3q5G38Ko/KkB0KtLV74l0UD8tXbEJ2BEHBp9z2bj1QMT94pjw2CUbCgBMoEJatOThsU1YbFB3odk8b/7LI2X/eODwB2HvXjuzrNX+gDa1iH+8474nXtisA2YLBLYtSKB28h7KW9498jfZhqlRKZRITulbzm6IkB7xbIRBM+MZn/T51OMmbK5HOUQTkD;4:lMjN6A1UBUpcStHrI0dqaVYvo0KWVfJGCWT8+DOR0pmS0gSXMoC7BF48DQcuYvVsNHn7gqv6Pt3URG1jQs7qHd7GI0Wki9DZmA09z/hwwbJJq6jQr0WwOE+96lG4KweYV111AWAj7UQn9X6dMVC2Ktc6cULeEV2v6XmpwheYx/GQIO+DjnvBlliX9EBSR95DdFxuuLBElOfOEQCslwg3nK8tfyZRedCxzyk13Pg+bfocXFRl1z8UtokXawAmE1YUd1MG1jHAkOYd6w/tbepwCaGSYZ/cKUPGaktXirCJl1t/t2N4zIHE4uuEaMYbz2sDCWHvRwdpNPcFmDWSXah+RA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(84791874153150); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:MWHPR12MB1152;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:MWHPR12MB1152; X-Forefront-PRVS: 054642504A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(346002)(376002)(366004)(39380400002)(396003)(39860400002)(199004)(189003)(24454002)(229853002)(68736007)(76176011)(16526018)(59450400001)(53936002)(8936002)(31686004)(81166006)(8676002)(81156014)(2870700001)(52116002)(966005)(3260700006)(50466002)(4326008)(65956001)(23676004)(58126008)(3846002)(6116002)(25786009)(83506002)(65806001)(16576012)(52146003)(5660300001)(47776003)(65826007)(66066001)(2486003)(110136005)(316002)(2906002)(6306002)(2950100002)(386003)(64126003)(90366009)(53546011)(6666003)(36756003)(6246003)(478600001)(77096006)(105586002)(6486002)(575784001)(31696002)(97736004)(7416002)(305945005)(86362001)(7736002)(8666007)(72206003)(106356001)(93886005);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1152;H:[10.236.65.116];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMTUyOzIzOklSMHhaQzF1eWY1Ny9LZnhFcnlYS0RjZ3FL?= =?utf-8?B?UStxcjZBWDkyTHZuN2tPaVFBUkx5RStJZk1vU3ovNnNINDNhamR1eXhzYllE?= =?utf-8?B?YmNON1BWUlZQaVpXUFpZbWdjL2lZMjA5dENyUjllc3J0amNENFJlTTYxeUtN?= =?utf-8?B?YmVCM2NpaWVyUzN0Nlh2YTJSVkdZOXprb1JVT1NUNzl4VTl2TzU3dVA3R2Ja?= =?utf-8?B?L2M4bjdkcVVIU1Z6VmlxNXFZYTFXUmk1anlacXRnWWlqajNDMXFRem85akZQ?= =?utf-8?B?VEtVSXVoYWdDZFdua2tBNythQ3dlc2VYaGpnUUhzbUpJRTkyTCs5cFEzaklZ?= =?utf-8?B?NjF4amVNYkJ6UmhIcy9PSTBBc29meGM0QkF6RldOMmdrcFhnbmtXY0kyMjNs?= =?utf-8?B?WDNRdGJDK1RwMWd4L0cvUTg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QLQNV63SerdbFPguNpI8J3FjHi99dgoeOOX9uAMl4B8yE439cSbHJJJLB5mgUHktGf6vLIAiefx/5Alio5XOm1kvqnli4f3Nr7tWBNbtwcyXoojIl X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2018 14:47:20.3045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a087c8b9-f542-44ac-03cb-08d556a6b948 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1152 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On 1/8/2018 5:10 AM, Thomas Gleixner wrote: > On Mon, 8 Jan 2018, Andrew Cooper wrote: > >> On 08/01/18 10:08, Thomas Gleixner wrote: >>> On Sat, 6 Jan 2018, tip-bot for Tom Lendacky wrote: >>> >>>> Commit-ID: 0bf17c102177d5da9363bf8b1e4704b9996d5079 >>>> Gitweb: https://git.kernel.org/tip/0bf17c102177d5da9363bf8b1e4704b9996d5079 >>>> Author: Tom Lendacky >>>> AuthorDate: Fri, 5 Jan 2018 10:07:56 -0600 >>>> Committer: Thomas Gleixner >>>> CommitDate: Sat, 6 Jan 2018 21:57:40 +0100 >>>> >>>> x86/cpu/AMD: Use LFENCE_RDTSC instead of MFENCE_RDTSC >>>> >>>> With LFENCE now a serializing instruction, set the LFENCE_RDTSC >>>> feature since the LFENCE instruction has less overhead than the >>>> MFENCE instruction. >>> Second thoughts on that. As pointed out by someone in one of the insane >>> long threads: >>> >>> What happens if the kernel runs as a guest and >>> >>> - the hypervisor did not set the LFENCE to serializing on the host >>> >>> - the hypervisor does not allow writing MSR_AMD64_DE_CFG >>> >>> That would bring the guest into a pretty bad state or am I missing >>> something essential here? >> >> What I did in Xen was to attempt to set it, then read it back and see.  >> If LFENCE still isn't serialising, using repoline is the only available >> mitigation. >> >> My understanding from the folk at AMD is that retpoline is safe to use, >> but has higher overhead than the LFENCE approach. Correct, the retpoline will work, it just takes more cycles. > > That still does not help vs. rdtsc_ordered() and LFENCE_RDTSC ... Ok, I can add the read-back check before setting the feature flag(s). But... what about the case where the guest is a different family than hypervisor? If we're on, say, a Fam15h hypervisor but the guest is started as a Fam0fh guest where the MSR doesn't exist and LFENCE is supposed to be serialized? I'll have to do a rdmsr_safe() and only set the flag(s) if I can successfully read the MSR back and validate the bit. Thanks, Tom > > Thanks, > > tglx >