Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1383626ybt; Thu, 25 Jun 2020 04:56:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymC+EW0csyvJOx0Geyx/RkwXmGzTd7N6uvPBPcYEKb0ShW6I4Au00YH/gvGpPQx+b90urc X-Received: by 2002:a17:906:c9d6:: with SMTP id hk22mr28464665ejb.101.1593086165497; Thu, 25 Jun 2020 04:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593086165; cv=none; d=google.com; s=arc-20160816; b=cxXU4oWUlxGvq7/+ZJhmbo6qaR3FM7Rh8phVnjg8zKacrxeDHxmZV6AuWwXb5N/NLJ OLWmgU+k4Midg4FasSXhUaNKD4tOLVuuBmntXaC+lpkeT/8T1KCUbzBAQOzfVxEGaE9A DxTYbqw6oC2XhVVfnWJa58Sogbwx7v6RL+6pJAxF4V98aprFQbIIAz5p4gN6UuBu7i7/ X67rLLDwWcLJoIOwi3EKCfElJ7TK434Np8ftATe192xUCsz5oeC2HwzPS8r84n8p81Hl gRn8nYvdLTuGecS+NoDZckt0E3If5hwib1fuYIbe41D2NBIMh/vmpdZFC5s0YtLkb8uy uj2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=EJpO6sxFWmxt5OhKGZnWJ/6R1AKRqxXIGbKnQrXdsNU=; b=Mchku36XaNHJfUcPSBSRAwwn/zA57JsMRXApTyKzwDZEAYVyzcIUIc4IZIwm8tQZ0/ 6mK3KAzcYKDqc8eGG7oOD1Inn9b3aC96e4vIhGHdnYYIp30tGMNCR6Ty25ERVYGP98l7 t7SjfN7dkK8RRp+mWtslMxvlmw08oLTxPDBqsHReKhEr++KIoJzOYTfmq1FHUKSW8iAk FZZ+m+UH4yvrNmjNg9CiOwkvIK37wgCOkRNqcTXzvTNPcpfe2Gtbk2mg8xxHaK8hxgs+ TktIiYpkdu84m0CBi/KV/vZsgaf8HtIqVO7a1HvUVlDz9BaoDFhB53rwBE4bHfLAApa7 KhSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds15si20893689ejc.14.2020.06.25.04.55.41; Thu, 25 Jun 2020 04:56:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404592AbgFYLyg (ORCPT + 99 others); Thu, 25 Jun 2020 07:54:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728063AbgFYLxg (ORCPT ); Thu, 25 Jun 2020 07:53:36 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CA04C061573; Thu, 25 Jun 2020 04:53:36 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1joQRg-0005sB-UR; Thu, 25 Jun 2020 13:53:33 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 7C5551C0092; Thu, 25 Jun 2020 13:53:32 +0200 (CEST) Date: Thu, 25 Jun 2020 11:53:32 -0000 From: "tip-bot2 for Peter Zijlstra" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/entry] x86/entry: Fix #UD vs WARN more Cc: "Peter Zijlstra (Intel)" , Andy Lutomirski , x86 , LKML In-Reply-To: <20200622114713.GE577403@hirez.programming.kicks-ass.net> References: <20200622114713.GE577403@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Message-ID: <159308601215.16989.11684885436197238827.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/entry branch of tip: Commit-ID: 145a773aef83181d47ebab21bb33c89233aadb1e Gitweb: https://git.kernel.org/tip/145a773aef83181d47ebab21bb33c89233aadb1e Author: Peter Zijlstra AuthorDate: Tue, 16 Jun 2020 13:28:36 +02:00 Committer: Peter Zijlstra CommitterDate: Thu, 25 Jun 2020 13:45:40 +02:00 x86/entry: Fix #UD vs WARN more vmlinux.o: warning: objtool: exc_invalid_op()+0x47: call to probe_kernel_read() leaves .noinstr.text section Since we use UD2 as a short-cut for 'CALL __WARN', treat it as such. Have the bare exception handler do the report_bug() thing. Fixes: 15a416e8aaa7 ("x86/entry: Treat BUG/WARN as NMI-like entries") Signed-off-by: Peter Zijlstra (Intel) Acked-by: Andy Lutomirski Link: https://lkml.kernel.org/r/20200622114713.GE577403@hirez.programming.kicks-ass.net --- arch/x86/kernel/traps.c | 72 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index a7d1570..1d9ea21 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -84,17 +84,16 @@ static inline void cond_local_irq_disable(struct pt_regs *regs) local_irq_disable(); } -int is_valid_bugaddr(unsigned long addr) +__always_inline int is_valid_bugaddr(unsigned long addr) { - unsigned short ud; - if (addr < TASK_SIZE_MAX) return 0; - if (probe_kernel_address((unsigned short *)addr, ud)) - return 0; - - return ud == INSN_UD0 || ud == INSN_UD2; + /* + * We got #UD, if the text isn't readable we'd have gotten + * a different exception. + */ + return *(unsigned short *)addr == INSN_UD2; } static nokprobe_inline int @@ -216,40 +215,45 @@ static inline void handle_invalid_op(struct pt_regs *regs) ILL_ILLOPN, error_get_trap_addr(regs)); } -DEFINE_IDTENTRY_RAW(exc_invalid_op) +static noinstr bool handle_bug(struct pt_regs *regs) { - bool rcu_exit; + bool handled = false; + + if (!is_valid_bugaddr(regs->ip)) + return handled; /* - * Handle BUG/WARN like NMIs instead of like normal idtentries: - * if we bugged/warned in a bad RCU context, for example, the last - * thing we want is to BUG/WARN again in the idtentry code, ad - * infinitum. + * All lies, just get the WARN/BUG out. */ - if (!user_mode(regs) && is_valid_bugaddr(regs->ip)) { - enum bug_trap_type type; + instrumentation_begin(); + /* + * Since we're emulating a CALL with exceptions, restore the interrupt + * state to what it was at the exception site. + */ + if (regs->flags & X86_EFLAGS_IF) + raw_local_irq_enable(); + if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) { + regs->ip += LEN_UD2; + handled = true; + } + if (regs->flags & X86_EFLAGS_IF) + raw_local_irq_disable(); + instrumentation_end(); - nmi_enter(); - instrumentation_begin(); - trace_hardirqs_off_finish(); - type = report_bug(regs->ip, regs); - if (regs->flags & X86_EFLAGS_IF) - trace_hardirqs_on_prepare(); - instrumentation_end(); - nmi_exit(); + return handled; +} - if (type == BUG_TRAP_TYPE_WARN) { - /* Skip the ud2. */ - regs->ip += LEN_UD2; - return; - } +DEFINE_IDTENTRY_RAW(exc_invalid_op) +{ + bool rcu_exit; - /* - * Else, if this was a BUG and report_bug returns or if this - * was just a normal #UD, we want to continue onward and - * crash. - */ - } + /* + * We use UD2 as a short encoding for 'CALL __WARN', as such + * handle it before exception entry to avoid recursive WARN + * in case exception entry is the one triggering WARNs. + */ + if (!user_mode(regs) && handle_bug(regs)) + return; rcu_exit = idtentry_enter_cond_rcu(regs); instrumentation_begin();