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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 1A412C4BA10 for ; Wed, 26 Feb 2020 08:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DBD0F24656 for ; Wed, 26 Feb 2020 08:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582707598; bh=PfXVwen4hTVjQMRYwec2sWG+kkHoy5njpKLA4uQB6ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Wha+cjD9x8kCdOWwL0q147OspLt6EvdaTgFIq3tYkvf4RH0EIj9w/cnepta4T4xA0 YhyoPmNhf0TctenmgfrX6aBkW9hmwx92EF+ehgXRxDZYuPnXg2srhp8OKDZ3HTQtFO OwStOXnWsmlVwt8CLVTHHT/kF1qnlHC5YpZM2Aj0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727259AbgBZI7g (ORCPT ); Wed, 26 Feb 2020 03:59:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:49388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725872AbgBZI7g (ORCPT ); Wed, 26 Feb 2020 03:59:36 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F37621556; Wed, 26 Feb 2020 08:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582707575; bh=PfXVwen4hTVjQMRYwec2sWG+kkHoy5njpKLA4uQB6ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XJEBXZiEf8Bj7BbW64kR8UZI0Q8iDU8EBiA3xtETf0mJoVYXUknvpTPMaPsgvEnhE VWHU++7YVKTXaWR5isL/r8/Ohsvp1YlRkg7YZGGQt8oGiJLQI2j+F2iAiU9N9nwhwf OjdW3L22men/kF7HAkNXMTY0W0DUava/GGCwbYTw= From: Masami Hiramatsu To: Ingo Molnar Cc: Anders Roxell , paulmck@kernel.org, joel@joelfernandes.org, "Naveen N . Rao" , Anil S Keshavamurthy , David Miller , Masami Hiramatsu , Linux Kernel Mailing List , Steven Rostedt Subject: [PATCH -tip V4 1/4] kprobes: Suppress the suspicious RCU warning on kprobes Date: Wed, 26 Feb 2020 17:59:30 +0900 Message-Id: <158270757059.18966.14260537198561848568.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <158270755997.18966.3544449431956918068.stgit@devnote2> References: <158270755997.18966.3544449431956918068.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Anders reported that the lockdep warns that suspicious RCU list usage in register_kprobe() (detected by CONFIG_PROVE_RCU_LIST.) This is because get_kprobe() access kprobe_table[] by hlist_for_each_entry_rcu() without rcu_read_lock. If we call get_kprobe() from the breakpoint handler context, it is run with preempt disabled, so this is not a problem. But in other cases, instead of rcu_read_lock(), we locks kprobe_mutex so that the kprobe_table[] is not updated. So, current code is safe, but still not good from the view point of RCU. Joel suggested that we can silent that warning by passing lockdep_is_held() to the last argument of hlist_for_each_entry_rcu(). Add lockdep_is_held(&kprobe_mutex) at the end of the hlist_for_each_entry_rcu() to suppress the warning. Reported-by: Anders Roxell Suggested-by: Joel Fernandes Signed-off-by: Masami Hiramatsu Reviewed-by: Joel Fernandes (Google) --- kernel/kprobes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 2625c241ac00..bd484392d789 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -326,7 +326,8 @@ struct kprobe *get_kprobe(void *addr) struct kprobe *p; head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)]; - hlist_for_each_entry_rcu(p, head, hlist) { + hlist_for_each_entry_rcu(p, head, hlist, + lockdep_is_held(&kprobe_mutex)) { if (p->addr == addr) return p; }