Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp953553ybl; Mon, 2 Dec 2019 22:07:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxNXNpLAlDlPrUi9e9495pQojXf5raqNsu5TbH8VHDdofJu8b5QT78Ev2SoQ//Ua6qtpc0h X-Received: by 2002:a05:6830:154c:: with SMTP id l12mr2059788otp.275.1575353238191; Mon, 02 Dec 2019 22:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575353238; cv=none; d=google.com; s=arc-20160816; b=hnUHXNt+sI0c7uGAH5FpHngBDqoD8+JYsH8MHwWdzblk2uTRivU4VNd/xFwnYoAdtT fL9xWu+rBBqy+/Y4l9DxjJ04c7UThFDjFKC1iEohA2BckqBwFbIavVWtVPizLxhi3Ius HMvGNn0oL+DYOpYrjSyxGkJlrPiokmGd+4sVW/NlurIpey+998oQBl/urHFprvl6Vva5 q/8J7ekNU6LpkzgU+h+Fidm/Qise3Yk5RkWin36pbnJnI1KmLM1u06CtUj8V0wyAXMmv +Ek1GZFI8QR88JAGCOzP9uOdWkkBCTBY1eTzgCf9hhvJM8QmJyTU8+xoiuJ/CNAYRo1+ +xOg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9xpcAIVxzDPh1dIlx6bgn2PZr5gjb+OrWtNRlgQDXKk=; b=hPtOakAitUdHMkwk/dhG5c0zVvXAngLh+VYbJSYp5O/XlWK9vdJ7Vdexh488QMQjqP MfyxZZ+Uze36x0tEFNxCjqBcvRv+BqGFGoJu+WNPyItj0dK17e3vz+7WQ57h5W+6v7QW hZKnzXBo0kgPmEwXX+9OmHBts6swDloB71wMt6iByDBgkmgwANudv/BR3RhnUdDNoS/i MyEHDebDfasXSJa1PpehkrPaVBHnM0wPyz8aZHii6JReM+28Pnu0QaaJe0nYuaRtJ9+g 7o6sdHRpgRaM8r1m1DYTgX9LYy1NMkdrH+rQwsESGENIRpKQXtDKroxpUJktjAZz7h/i JH+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pqXdZgTn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d3si705518oti.56.2019.12.02.22.07.06; Mon, 02 Dec 2019 22:07: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; dkim=pass header.i=@kernel.org header.s=default header.b=pqXdZgTn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbfLCGGY (ORCPT + 99 others); Tue, 3 Dec 2019 01:06:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:44042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfLCGGY (ORCPT ); Tue, 3 Dec 2019 01:06:24 -0500 Received: from localhost.localdomain (unknown [180.22.253.92]) (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 4619020684; Tue, 3 Dec 2019 06:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575353183; bh=0IdTj408H9VDhD7k+XOPYN9S53vMdUcDRsF6ueMx+Y4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pqXdZgTne+g2oh1LFnjyQNSUtwe3ShS3lxPFjYD5xVIh2ut9c800/dx9nDRWL6GHz bE5xucSlFhrsqLs7+cV19BHSqqy2ZYeA0BzUI/TZ9lCxzBsPmsd1qyStS4OJOGOzDq ZcfAQvAUR3dahQ5OJEzqkkou0zVQw9wvFNV7GEWE= 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 Subject: [PATCH -tip V2 1/2] kprobes: Suppress the suspicious RCU warning on kprobes Date: Tue, 3 Dec 2019 15:06:17 +0900 Message-Id: <157535317763.16485.12112495601308191775.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157535316659.16485.11817291759382261088.stgit@devnote2> References: <157535316659.16485.11817291759382261088.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 53534aa258a6..f9ecb6d532fb 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; }