Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1515340imm; Sun, 27 May 2018 08:49:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrutwBh197pCMQt500nmk8Oy8TtPnL5LT57EmnkR/LCt+CcZTJRiL1lJKrZqSKhj3r7MDu7 X-Received: by 2002:a65:4348:: with SMTP id k8-v6mr7657778pgq.395.1527436166118; Sun, 27 May 2018 08:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527436166; cv=none; d=google.com; s=arc-20160816; b=Tqq1mXJqRs5nfhr1kFzMC5Pz0rdPYHL5cScDiQM5h4Qg+EguG5iEbPYyXC6s03pJgY Fi5fFiffMcL+E4SGNNQG7t8hEcca5FRckkb1JA8ksEQjblflWNJiCIcK3zL/CPLW6EKy b2pcyi8JCzs7bl7BKjA7eAoDbrru1ZyQ809EcAvxblSOfGmyDfFJSftqnjtWcPDcUf0w mV3GpuYIWAMxe37Ayg/n8eVf7dhY1g85YkUzxqmasEnxISovUuA1XQZAVaN0WRaI12PL gZE+++YPG7DnomUmv20wmKAW5H94kZXZWFzDKM/LPB/iX+RQjAAinmk1shgn9ffH4aU1 t/qQ== 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:arc-authentication-results; bh=UObw895n2jQlVsc9rUhP9S6bgv94ptIsu1eyWkq4hg4=; b=Das2OiM58wgs16v/wWNW394XPRXf/zlZ28LkrnMVQXLdx3ApqjAVNvWJbWzfUsCxcO n+zWsQRK4oZucOeMHHvoQUmeDLnywVzziebjLkmFwVZJjfwSEvUjzjJ7OgBpDsNTCIuB 4diwjWQELAKf306L0gceXd4y/5JT9Jhyl5x3zBYQko/dkSCHoK6375+j9NZXSGG164zg Sssj99LeXCm1HdUbRUln/biXLVTSn+PZ4bwLgNUgFcvGxr/QdnJwY2WXFlKo+cOYnvd4 uNR3s0QkH2XPIlpMND40yt2jLLBRHWUz9QlXBqYNbPgFcgdpAoo9iIAz+8aPWTV6nDg+ 0ArQ== 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 5-v6si28914815pls.375.2018.05.27.08.49.11; Sun, 27 May 2018 08:49:26 -0700 (PDT) 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 S1033037AbeE0Pry (ORCPT + 99 others); Sun, 27 May 2018 11:47:54 -0400 Received: from mga02.intel.com ([134.134.136.20]:28381 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032825AbeE0PqW (ORCPT ); Sun, 27 May 2018 11:46:22 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2018 08:46:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,448,1520924400"; d="scan'208";a="227741112" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by orsmga005.jf.intel.com with ESMTP; 27 May 2018 08:46:17 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "H. Peter Anvin" Cc: "Ashok Raj" , "Dave Hansen" , "Rafael Wysocki" , "Tony Luck" , "Alan Cox" , "Ravi V Shankar" , "Arjan van de Ven" , "linux-kernel" , "x86" , Fenghua Yu Subject: [RFC PATCH 15/16] x86/split_lock: Add CONFIG and debugfs interface for testing #AC for split lock in kernel mode Date: Sun, 27 May 2018 08:46:04 -0700 Message-Id: <1527435965-202085-16-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1527435965-202085-1-git-send-email-fenghua.yu@intel.com> References: <1527435965-202085-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 Sometimes user wants to test how split lock in kernel mode is process. debugfs interface /sys/kernel/debug/x86/split_lock/test_kernel is provided to do the test. The interface is enabled by CONFIG_SPLIT_LOCK_AC_TEST. Writing 1 to the interface file triggers a split locked access in kernel and procedure of handling the split lock. The file is not readable. Signed-off-by: Fenghua Yu --- arch/x86/Kconfig | 10 +++++++ arch/x86/kernel/cpu/test_ctl.c | 61 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d42d90abd644..5d44cc86aecf 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -488,6 +488,16 @@ config SPLIT_LOCK_AC_PANIC_ON_KERNEL Say N if unsure. +config SPLIT_LOCK_AC_TEST + bool "Test #AC exception for split locked accesses" + default n + depends on SPLIT_LOCK_AC + help + Select to enable testing #AC exception for split lock accesses. + This adds interface /sys/kernel/debug/x86/split_lock/test_kernel + to allow user to trigger split locked access in kernel and test + split lock handling. + if X86_32 config X86_BIGSMP bool "Support for big SMP systems with more than 8 CPUs" diff --git a/arch/x86/kernel/cpu/test_ctl.c b/arch/x86/kernel/cpu/test_ctl.c index 8bdc01067be9..910ff19c2a3e 100644 --- a/arch/x86/kernel/cpu/test_ctl.c +++ b/arch/x86/kernel/cpu/test_ctl.c @@ -541,6 +541,64 @@ static int firmware_store(void *data, u64 val) DEFINE_DEBUGFS_ATTRIBUTE(firmware_ops, firmware_show, firmware_store, "%llx\n"); +#ifdef CONFIG_SPLIT_LOCK_AC_TEST +/* Execute locked btsl instruction with split lock operand. */ +static void split_lock_test_kernel(void) +{ + char cptr[128] __aligned(64); + int *iptr; + + /* + * Change the pointer, making it 3-byte away from the next cache + * line. + */ + iptr = (int *)(cptr + 61); + + /* Initial value 0 in iptr */ + *iptr = 0; + + pr_info("split lock test: split lock address=0x%lx\n", + (unsigned long)iptr); + + /* + * The distance between iptr and next cache line is 3 bytes. + * Operand size in "btsl" is 4 bytes. So iptr will span two cache + * lines. "lock btsl" instruction will trigger #AC in hardware + * and kernel will either re-execute the instruction or go to panic + * depending on user configuration in + * /sys/kernel/debug/x86/split_lock/kernel_mode. + */ + asm volatile ("lock btsl $0, %0\n\t" + : "=m" (*iptr)); + + if (*iptr == 1) + pr_info("split lock kernel test passes\n"); + else + pr_info("split lock kernel test fails\n"); +} + +/* + * Writing 1 to /sys/kernel/debug/x86/split_lock/test_kernel triggers + * split locke daccess in kernel mode. + */ +static int test_kernel_store(void *data, u64 val) +{ + if (split_lock_ac_kernel == DISABLE_SPLIT_LOCK_AC) + return -ENODEV; + + if (val != 1) + return -EINVAL; + + mutex_lock(&split_lock_mutex); + split_lock_test_kernel(); + mutex_unlock(&split_lock_mutex); + + return 0; +} + +DEFINE_DEBUGFS_ATTRIBUTE(test_kernel_ops, NULL, test_kernel_store, "%llx\n"); +#endif /* CONFIG_SPLIT_LOCK_AC_TEST */ + static int __init debugfs_setup_split_lock(void) { struct debugfs_file debugfs_files[] = { @@ -548,6 +606,9 @@ static int __init debugfs_setup_split_lock(void) {"kernel_mode", 0600, &kernel_mode_ops }, {"user_mode", 0600, &user_mode_ops }, {"firmware", 0600, &firmware_ops }, +#ifdef CONFIG_SPLIT_LOCK_AC_TEST + {"test_kernel", 0200, &test_kernel_ops }, +#endif }; struct dentry *split_lock_dir, *fd; int i; -- 2.5.0