Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2629870ybc; Wed, 20 Nov 2019 17:51:19 -0800 (PST) X-Received: by 2002:a17:906:b246:: with SMTP id ce6mr9416081ejb.298.1574300839739; Wed, 20 Nov 2019 17:47:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwcozOeE54nYEZYMxyvtH9qaA4wYI/haMxzKlwR1qxqRB/eBsgirFwIKhcPQwFXsCC6C4eM X-Received: by 2002:a17:906:b246:: with SMTP id ce6mr9415916ejb.298.1574300838027; Wed, 20 Nov 2019 17:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574300838; cv=none; d=google.com; s=arc-20160816; b=Ji2reRUv/JNcMgomPXTiVyq4yo/TE7kwTnF7cf1UDGsltwpRCWbiCvQC+fUtQhvAor EYjB1PD+4IUYDKyt6ZLcBf82E6qXXgZ4C43gJew4XQGqYtEbdcS3a3kdPJVXzuMltjIm tIW9gCltgVeQwaZyklDmHApjayaxt4VLZBxFv4NzUUEwbGLNiUR0C6PYD5NCq4qyD5r1 Qm4Gw5ht8THPzmMD9qKYhp7vCdanuKcHD0A4efhesvAUeJx8b0XztF0okqjHWtDEeOJy KVNBM2yZGQOHTiGXv3aquQvj/Y2DEEZ9Zt2guUyuiGFkTPleQaBdqojP+jz6PjMGqQZ9 XInQ== 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=GtH0FqzjodNa7Svb08JDOYw0JwZVxQN5+AAnUdwKvKY=; b=ASPspDmKQUH/YZkv6NoSKsHEv43VTlxmCeqcbeGjUHwZWFTdV/l4BuSJM1eqMWcE0I OtVg+sz9H3cZGkEQGKn2iY21qs8n7ivtECBQs4NtnP+uLfgz0rJpziI1eSd0y0tHpZYC Jl7UFo4DZVbttAtp3VcFdH5LyAdxK5H9HD5MQokJPEdZOeZoxjPMmdn5vqv8txBzASoR rv5erUopVSRI0t0RVpPKTVExbcd1sS6eFcua4RVsEb9jpWFeL/+iXNPgSApLreq0Fzkd SIUO66MjFVL3mt9OKfZvhCq+/d/r5wFjA5NpZY7V/kunt5yxjgg/5/vd0yLWTBzcxIht nWdw== 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 a24si972860eda.446.2019.11.20.17.46.53; Wed, 20 Nov 2019 17:47:18 -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 S1726792AbfKUBpy (ORCPT + 99 others); Wed, 20 Nov 2019 20:45:54 -0500 Received: from mga05.intel.com ([192.55.52.43]:49098 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726614AbfKUBpv (ORCPT ); Wed, 20 Nov 2019 20:45:51 -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="407025911" 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 5/6] x86/split_lock: Handle #AC exception for split lock Date: Wed, 20 Nov 2019 16:53:22 -0800 Message-Id: <1574297603-198156-6-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 Currently Linux does not expect to see an alignment check exception in kernel mode (since it does not set CR4.AC). The existing #AC handlers will just return from exception to the faulting instruction which will trigger another exception. Add a new handler for #AC exceptions that will force a panic on split lock for kernel mode. Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- arch/x86/include/asm/traps.h | 3 +++ arch/x86/kernel/cpu/intel.c | 2 ++ arch/x86/kernel/traps.c | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h index b25e633033c3..0fa4eef83057 100644 --- a/arch/x86/include/asm/traps.h +++ b/arch/x86/include/asm/traps.h @@ -172,4 +172,7 @@ enum x86_pf_error_code { X86_PF_INSTR = 1 << 4, X86_PF_PK = 1 << 5, }; + +extern bool split_lock_detect_enabled; + #endif /* _ASM_X86_TRAPS_H */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 2614616fb6d3..bc0c2f288509 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -32,6 +32,8 @@ #include #endif +bool split_lock_detect_enabled; + /* * Just in case our CPU detection goes bad, or you have a weird system, * allow a way to override the automatic disabling of MPX. diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 4bb0f8447112..044033ff4326 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -293,9 +293,29 @@ DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, 0, NULL, "coprocessor segment overru DO_ERROR(X86_TRAP_TS, SIGSEGV, 0, NULL, "invalid TSS", invalid_TSS) DO_ERROR(X86_TRAP_NP, SIGBUS, 0, NULL, "segment not present", segment_not_present) DO_ERROR(X86_TRAP_SS, SIGBUS, 0, NULL, "stack segment", stack_segment) -DO_ERROR(X86_TRAP_AC, SIGBUS, BUS_ADRALN, NULL, "alignment check", alignment_check) #undef IP +dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code) +{ + unsigned int trapnr = X86_TRAP_AC; + char str[] = "alignment check"; + int signr = SIGBUS; + + RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); + + if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) == NOTIFY_STOP) + return; + + if (!user_mode(regs) && split_lock_detect_enabled) + panic("Split lock detected\n"); + + cond_local_irq_enable(regs); + + /* Handle #AC generated in any other cases. */ + do_trap(X86_TRAP_AC, SIGBUS, "alignment check", regs, + error_code, BUS_ADRALN, NULL); +} + #ifdef CONFIG_VMAP_STACK __visible void __noreturn handle_stack_overflow(const char *message, struct pt_regs *regs, -- 2.19.1