Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757196AbeAHWJe (ORCPT + 1 other); Mon, 8 Jan 2018 17:09:34 -0500 Received: from mail-bl2nam02on0041.outbound.protection.outlook.com ([104.47.38.41]:35648 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756461AbeAHWJb (ORCPT ); Mon, 8 Jan 2018 17:09:31 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; From: Tom Lendacky Subject: [PATCH v2 1/2] x86/cpu/AMD: Make LFENCE a serializing instruction To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Linus Torvalds , Dan Williams , Dave Hansen , Borislav Petkov , Thomas Gleixner , Tim Chen , Greg Kroah-Hartman , David Woodhouse , Paul Turner Date: Mon, 08 Jan 2018 16:09:21 -0600 Message-ID: <20180108220921.12580.71694.stgit@tlendack-t1.amdoffice.net> In-Reply-To: <20180108220912.12580.82330.stgit@tlendack-t1.amdoffice.net> References: <20180108220912.12580.82330.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: BN6PR08CA0084.namprd08.prod.outlook.com (10.172.143.150) To BN6PR12MB1137.namprd12.prod.outlook.com (10.168.226.139) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9b3e20eb-dbe4-4078-ee95-08d556e47bdd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:BN6PR12MB1137; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1137;3:LMMUHrxy30lAtCD7neGWUdgNpejQoR8mzf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v0BKpbJhnxlJSFPnPJ5m3H6bNwx7Og/o4WY3v5pp46aC12Q54ggkDGB3DQZbdpDw6iM0PHtCHzL77PGNwWzA5GeWJL6WrP6gvWNLeF9Yr6vp6Rn55/QfhIQwq0AELo2bVotz544VSQbzMhCUz75M4vejctffc4kmSU2/IZpsvobIG0BZOlA6XKs2Q/VStAo4Ggy1j9pWrFUY2EG6rjW9ffZyL1KrsjTo+ZMB1cPfxMS7Pp3lRzQzquJhPLhT0Lj0G8WMk5YWMbiZUxdULtWjbp9JLOm2Vw9sT6UMk9j1SvBXrhfrxeKyjdB+II;4:a3ceZlWTd/+XMqdudDBlLu5C5nERwInnaE/7qlGzKX4PM+90K7Z+LlZebHlr8sGoaUbtk/76S+Tmuq0Iw3RXzWz/LroRSZok6rQFTuYHwdq7HN5UPmGvJmYLrtccD8ysyjGeQ1elhT0hoc9mPwcVjCLnLg1lg6xQ9UldZqiOXwtBb0tRDaBnX5MuSPrFQX73Zx62xZeNHW3ZaESsoOm42OGVvJiUz7H72h1cPMf5sximrgjOxVeFvY+Lj4/x46CLTPQoByvNgPuAzxeDNy/0XjtdUxOnH/xCTzLs+RBdiWxbsgZpbDW8HGSu0GQs/UZk 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)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:BN6PR12MB1137;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:BN6PR12MB1137; X-Forefront-PRVS: 054642504A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(39380400002)(366004)(376002)(396003)(39860400002)(346002)(189003)(199004)(97736004)(1076002)(66066001)(6116002)(5660300001)(6666003)(53936002)(69596002)(86362001)(9686003)(47776003)(2950100002)(316002)(103116003)(6506007)(386003)(3846002)(2906002)(55016002)(4326008)(76176011)(2486003)(52116002)(23676004)(230700001)(25786009)(72206003)(16526018)(106356001)(305945005)(7696005)(7736002)(54906003)(105586002)(478600001)(8676002)(50466002)(58126008)(83506002)(8936002)(7416002)(81156014)(97746001)(68736007)(81166006)(53416004);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1137;H:tlendack-t1.amdoffice.net;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjEyTUIxMTM3OzIzOjVWU0U2Q1B2bjNGSWtZbElZVWtJREplRFFC?= =?utf-8?B?WUtWd2hNbTFudGpvVHo0RHVUUDlDWmhUZVVSb2cralR0UEplZHFKay9Uc1JZ?= =?utf-8?B?VlBEeWpITkFKUkM2WWtIVEREc0lRQXk2MTBzMk1ZbmdhNHBIc2NOc0d2bVRw?= =?utf-8?B?U2thanBPNGZ6dEJOL1RDc2ltM1BXcHo3L2t3YVVkQXExZVNJazJLNDM4eE1k?= =?utf-8?B?Qy8wc2VGL3laenFTeXUxc3BlZUdOcjVJLzFKTDFSc2VCMmpsV1Vpemh5UjZG?= =?utf-8?B?am1KU1p0WXV2V3B5NVRETFYzcmNxTDJzNFA5SHBpMkpaMklKRkZhY2U4N1Ev?= =?utf-8?B?MjJKeWdQM2FPMFpLUmtUM2V6MEREdEU5TUk5T25BMFluU1pFcVV6eC9tUmRN?= =?utf-8?B?YXo2YXZjbjQzTyttYmlvOFJYcWpEci9pREs3Y0dDbXFNZ1FTZXNEMVc0QnVh?= =?utf-8?B?NlVXNUEydXdYbHdJOWF2Q2k4cU5Id0F0WHluTWdzUVRWSXFCeEI5cHZPY2Fk?= =?utf-8?B?UlFyZitQQm1rMS9pNXQ0YUdrWWtIQjBqelZMQlBkUUdlN0UxNzBhREN2cFA0?= =?utf-8?B?QXBleFFjU0k2TTFqT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rVqE02drX8QJQoxnyyznhpaxwiPlow5iltdjOahbcyXUvYl4RjG770VO3HVZt7VWfjjBvfZ4F1rpuJjnjkDBpkNpFpvl SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1137;20:/F9UaRugyCqNQ9kWCYEfPLqnbSRe0mBCM6gx3mrpGUXc7qRa/95XqHPT/djJrHE3heWWUgbZ0NwF9RA82nggH8KyC+42P7BJ+6G9rWQE3aiG2xvH9QJDVLaDPvKPcAFx8HNkC3lYecodt5OnhQzNYXQ0T1p+YFh8j9AsGEnTiIaZKLZiErIti9gZspzL49Rz4ubrFeWsC5XmLXMtOn4+W91Fe7zJAK2AxLM03k/O+tFrhuC+aeq5HsX2GAe7RoNM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2018 22:09:26.7373 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b3e20eb-dbe4-4078-ee95-08d556e47bdd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1137 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: To aid in speculation control, make LFENCE a serializing instruction since it has less overhead than MFENCE. This is done by setting bit 1 of MSR 0xc0011029 (DE_CFG). Some families that support LFENCE do not have this MSR. For these families, the LFENCE instruction is already serializing. Signed-off-by: Tom Lendacky --- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/amd.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index ab02261..1e7d710 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -352,6 +352,8 @@ #define FAM10H_MMIO_CONF_BASE_MASK 0xfffffffULL #define FAM10H_MMIO_CONF_BASE_SHIFT 20 #define MSR_FAM10H_NODE_ID 0xc001100c +#define MSR_F10H_DECFG 0xc0011029 +#define MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT 1 /* K8 MSRs */ #define MSR_K8_TOP_MEM1 0xc001001a diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index bcb75dc..5b438d8 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -829,6 +829,16 @@ static void init_amd(struct cpuinfo_x86 *c) set_cpu_cap(c, X86_FEATURE_K8); if (cpu_has(c, X86_FEATURE_XMM2)) { + /* + * A serializing LFENCE has less overhead than MFENCE, so + * use it for execution serialization. On families which + * don't have that MSR, LFENCE is already serializing. + * msr_set_bit() uses the safe accessors, too, even if the MSR + * is not present. + */ + msr_set_bit(MSR_F10H_DECFG, + MSR_F10H_DECFG_LFENCE_SERIALIZE_BIT); + /* MFENCE stops RDTSC speculation */ set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC); }