Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2627575ybc; Wed, 20 Nov 2019 17:48:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzfMOvOfFJLIx6a311zPGFZg1vpKXXKHFyoJW6swFcUWMtnMNnBD0b2rKJk6aZ35VJfEyQ+ X-Received: by 2002:a17:906:394c:: with SMTP id g12mr9619964eje.233.1574300890701; Wed, 20 Nov 2019 17:48:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574300890; cv=none; d=google.com; s=arc-20160816; b=ssZXB0Pav0kcxGutjjxESVZcul7YBQOcblWNp51APHmI0RnTF7zOn8Cz2DT6vZ9Ss5 XRMBFOeQAEloRr3L2Frxx7++/szOVFOlxM6e9RndOLTzBoQNmZ+VO5g9Kb7XWJAPWdST aTe6P+2I0CDna7VV2a2gg5gTvQuzhM5RZBGuTYeMbZebYqlymfQlY6y+uo7Amt0Q9D2I 2/m05900LzBmE/PadHhJ6n8JQVY4bsCaoqK4g9LDBbiXUASq6KQzEFiXuadTzGa9Jgtf ID8xSTAsCQI4ZDnFUtrLC6aQ1St9QUHbNoA4DBT/pYqitWXgRojvMDGtSsL45othVnlB A3nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=BQwQ3sxaaor4eYT6xjuOePM7X2GtkSNPeTYo+lun68c=; b=Ffhuz1p3TIl6kJ23zGXrjg1wMqlpwSKaRLuf92AHbWgvl/Gv0pEoy5VZ2ytf8kTzn/ OsecjKvv/7/XEada46jpBYLHmI89nuKfCyOEp6J8N4FQZ7qnMRKkQjMxtpA+AIjybF3+ kk77c2dZE59Ew5YLh3wYwekCDs/VQiWqeCNcJrY/ATEKCEFOtE2xUqr6YN66I2ilq8io wPYefACVMSQEvobeN3sWxlXJ8cbnVxLugqAbhZ//hgCgsg+4P7QSjMLrAdPx9z5rMICc 0npE+S8YCyL4p2Uo0KKcxfpDxA6ylsfS/UIS/5b4QjBOTD4Z6nOx5MQ1A/u9drzjCwDY 6SVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f25si638807eje.225.2019.11.20.17.47.47; Wed, 20 Nov 2019 17:48:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726927AbfKUBqD (ORCPT + 99 others); Wed, 20 Nov 2019 20:46:03 -0500 Received: from mga05.intel.com ([192.55.52.43]:49101 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726695AbfKUBpw (ORCPT ); Wed, 20 Nov 2019 20:45:52 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2019 17:45:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,224,1571727600"; d="scan'208";a="407025914" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga005.fm.intel.com with ESMTP; 20 Nov 2019 17:45:50 -0800 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H Peter Anvin" , "Peter Zijlstra" , "Tony Luck" , "Ashok Raj" , "Ravi V Shankar" Cc: "linux-kernel" , "x86" , Fenghua Yu Subject: [PATCH v10 6/6] x86/split_lock: Enable split lock detection by kernel parameter Date: Wed, 20 Nov 2019 16:53:23 -0800 Message-Id: <1574297603-198156-7-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1574297603-198156-1-git-send-email-fenghua.yu@intel.com> References: <1574297603-198156-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split lock detection is disabled by default. Enable the feature by kernel parameter "split_lock_detect". Usually it is enabled in real time when expensive split lock issues cannot be tolerated so should be fatal errors, or for debugging and fixing the split lock issues to improve performance. Please note: enabling this feature will cause kernel panic or SIGBUS to user application when a split lock issue is detected. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- .../admin-guide/kernel-parameters.txt | 10 ++++++ arch/x86/kernel/cpu/intel.c | 34 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 8dee8f68fe15..1ed313891f44 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3166,6 +3166,16 @@ nosoftlockup [KNL] Disable the soft-lockup detector. + split_lock_detect + [X86] Enable split lock detection + This is a real time or debugging feature. When enabled + (and if hardware support is present), atomic + instructions that access data across cache line + boundaries will result in an alignment check exception. + When triggered in applications the kernel will send + SIGBUS. The kernel will panic for a split lock in + OS code. + nosync [HW,M68K] Disables sync negotiation for all devices. nowatchdog [KNL] Disable both lockup detectors, i.e. diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index bc0c2f288509..9bf6daf185b9 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef CONFIG_X86_64 #include @@ -655,6 +656,26 @@ static void init_intel_misc_features(struct cpuinfo_x86 *c) wrmsrl(MSR_MISC_FEATURES_ENABLES, msr); } +static void split_lock_init(void) +{ + if (split_lock_detect_enabled) { + u64 test_ctrl_val; + + /* + * The TEST_CTRL MSR is per core. So multiple threads can + * read/write the MSR in parallel. But it's possible to + * simplify the read/write without locking and without + * worry about overwriting the MSR because only bit 29 + * is implemented in the MSR and the bit is set as 1 by all + * threads. Locking may be needed in the future if situation + * is changed e.g. other bits are implemented. + */ + rdmsrl(MSR_TEST_CTRL, test_ctrl_val); + test_ctrl_val |= MSR_TEST_CTRL_SPLIT_LOCK_DETECT; + wrmsrl(MSR_TEST_CTRL, test_ctrl_val); + } +} + static void init_intel(struct cpuinfo_x86 *c) { early_init_intel(c); @@ -770,6 +791,8 @@ static void init_intel(struct cpuinfo_x86 *c) tsx_enable(); if (tsx_ctrl_state == TSX_CTRL_DISABLE) tsx_disable(); + + split_lock_init(); } #ifdef CONFIG_X86_32 @@ -1032,9 +1055,20 @@ static const struct cpu_dev intel_cpu_dev = { cpu_dev_register(intel_cpu_dev); +#undef pr_fmt +#define pr_fmt(fmt) "x86/split lock detection: " fmt + static void __init split_lock_setup(void) { setup_force_cpu_cap(X86_FEATURE_SPLIT_LOCK_DETECT); + + if (cmdline_find_option_bool(boot_command_line, + "split_lock_detect")) { + split_lock_detect_enabled = true; + pr_info("enabled\n"); + } else { + pr_info("disabled\n"); + } } #define SPLIT_LOCK_CPU(model) {X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY} -- 2.19.1