From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEF33C43461 for ; Mon, 14 Sep 2020 17:21:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D8DC20715 for ; Mon, 14 Sep 2020 17:21:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gwcvtriq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="K/1mLFYl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725961AbgINRVi (ORCPT ); Mon, 14 Sep 2020 13:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbgINRQY (ORCPT ); Mon, 14 Sep 2020 13:16:24 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAABEC061788; Mon, 14 Sep 2020 10:16:16 -0700 (PDT) Date: Mon, 14 Sep 2020 17:16:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1600103775; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQVrCZ4mcp7SJ0BjmotzJ2aqXd6Tqdnv8aQgvLzbuvs=; b=gwcvtriqYr8xPQbrZU+6o2uVP6AK10LlT8B61idwDDF6DD4hJTPnv6UtXQdX/4hlJqK6kZ WOtLcfZPASN/tg5glZ84q0S8mucSL4E4C9kdD4EOISsYpuuCsjomAnKtZvTelmW3YdL5O0 /5HPG+8aPXhtjaAwPLCbJjN4kQtyQY5MeFPeeVbvAauPVMzwQGOvMIg+ACNenJ+ArOHTLO L1/0PbUNZLpRxcY9Y6tOUuYJM8+FCJbOMxAmxmqVcjMNuBrk9FKg+xAVLm1b309E0bM0vE TwjQQtFoLaZa7B+YE6onvaYnZBJ3/NfHvX/WqZuydYyIXJUVm516TKJV5Yq3GA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1600103775; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EQVrCZ4mcp7SJ0BjmotzJ2aqXd6Tqdnv8aQgvLzbuvs=; b=K/1mLFYlku21Q/jxzcYffAvZTnQ5NMYQVeGhPkmk14NfccNPc+KH9FPPzqZ8hx63ZP1UhA 6AyTdp6VFLTGVFBA== From: "tip-bot2 for Masami Hiramatsu" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/kprobes] kprobes: Remove NMI context check Cc: Masami Hiramatsu , "Peter Zijlstra (Intel)" , Ingo Molnar , x86 , LKML In-Reply-To: <159870615628.1229682.6087311596892125907.stgit@devnote2> References: <159870615628.1229682.6087311596892125907.stgit@devnote2> MIME-Version: 1.0 Message-ID: <160010377449.15536.10398989560902081648.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 perf/kprobes branch of tip: Commit-ID: e03b4a084ea6b0a18b0e874baec439e69090c168 Gitweb: https://git.kernel.org/tip/e03b4a084ea6b0a18b0e874baec439e69090c168 Author: Masami Hiramatsu AuthorDate: Sat, 29 Aug 2020 22:02:36 +09:00 Committer: Ingo Molnar CommitterDate: Tue, 08 Sep 2020 11:52:35 +02:00 kprobes: Remove NMI context check The in_nmi() check in pre_handler_kretprobe() is meant to avoid recursion, and blindly assumes that anything NMI is recursive. However, since commit: 9b38cc704e84 ("kretprobe: Prevent triggering kretprobe from within kprobe_flush_task") there is a better way to detect and avoid actual recursion. By setting a dummy kprobe, any actual exceptions will terminate early (by trying to handle the dummy kprobe), and recursion will not happen. Employ this to avoid the kretprobe_table_lock() recursion, replacing the over-eager in_nmi() check. Signed-off-by: Masami Hiramatsu Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Link: https://lkml.kernel.org/r/159870615628.1229682.6087311596892125907.stgit@devnote2 --- kernel/kprobes.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index a0afaa7..2111382 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1359,7 +1359,8 @@ static void cleanup_rp_inst(struct kretprobe *rp) struct hlist_node *next; struct hlist_head *head; - /* No race here */ + /* To avoid recursive kretprobe by NMI, set kprobe busy here */ + kprobe_busy_begin(); for (hash = 0; hash < KPROBE_TABLE_SIZE; hash++) { kretprobe_table_lock(hash, &flags); head = &kretprobe_inst_table[hash]; @@ -1369,6 +1370,8 @@ static void cleanup_rp_inst(struct kretprobe *rp) } kretprobe_table_unlock(hash, &flags); } + kprobe_busy_end(); + free_rp_inst(rp); } NOKPROBE_SYMBOL(cleanup_rp_inst); @@ -2035,17 +2038,6 @@ static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) unsigned long hash, flags = 0; struct kretprobe_instance *ri; - /* - * To avoid deadlocks, prohibit return probing in NMI contexts, - * just skip the probe and increase the (inexact) 'nmissed' - * statistical counter, so that the user is informed that - * something happened: - */ - if (unlikely(in_nmi())) { - rp->nmissed++; - return 0; - } - /* TODO: consider to only swap the RA after the last pre_handler fired */ hash = hash_ptr(current, KPROBE_HASH_BITS); raw_spin_lock_irqsave(&rp->lock, flags);