Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3082655ybt; Mon, 29 Jun 2020 14:54:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDj6GjFhZBnpVpffGuhVI+sLNL9uytLQM0LdaBDZNW1+Mb1s5nc+3hEj4qu9UA98aV06PB X-Received: by 2002:a50:f149:: with SMTP id z9mr20167509edl.167.1593467648954; Mon, 29 Jun 2020 14:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593467648; cv=none; d=google.com; s=arc-20160816; b=U3KFwfOwidOVD8LCnC+PVqYMY171bsJLhW/FzeV67YYUWP1HZYhukTGNjmL0jJ34ew 9Lv7pifKyrujv+HA/9glApUc6svV4n0MAJboci93wCa3sJylICC5MgaPdp+B0DlDYrjq /qOxTiFxG9tDshOGohQLdK1aVeJuzfu9qpwWJz1S7WPkFOQ39WboI1HZlcWQKAjNz++a L5vLt0i8hZ1ruLaeFnHRYIiIRln+jkveQf8Q01+wNQLS5KeCsMFftBcP/HyPSU7eESPJ biy3dSE5EZCs0rYuVBN9lwAoQ47y0lxSadYYliluoCH59IZdSoeV4oxkHboQ8wPES3zq MUAw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8YZVzn/q9UqJxvY4pT8iQDQYZAKMuv6mllSPXhm7qxs=; b=BGZ8MQcWSqWAUj3iJffvwPg9VQyd07572nEPeXPlS7QCD1au25T7OjOY2Lo1LBLjaJ Rh5bTYSCyipQxCOEhP48X5+lUx35O3OH3V1M286g6FWBulr62QTQxzPWXsIdWtPMAD1i u3qdG9MbZUzDjZiyRryfhvvthZWJEtXQ/MT42iuUJr66jSrg9m5A5CG8Ki4BI4TcEEHe VFflWIJcNSEyfcH7vpQ8sCUiLO1ICKlEcSC9U7zmGgsVv/POzQlwSIhjcLWYiFE6xiRV zBOE1rzVNJy8v6Yx3DrrfIzpL9R/Owfw0dxW05dR2wm7EfoNS4GfzyJzo2DEqfgeQtuM bZmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zXSs+Qkc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h4si500833eje.121.2020.06.29.14.53.46; Mon, 29 Jun 2020 14:54:08 -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; dkim=pass header.i=@kernel.org header.s=default header.b=zXSs+Qkc; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732906AbgF2Vuo (ORCPT + 99 others); Mon, 29 Jun 2020 17:50:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:56764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbgF2Sfk (ORCPT ); Mon, 29 Jun 2020 14:35:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 854FD24787; Mon, 29 Jun 2020 15:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444093; bh=FhmwB88O57CR0ErdjSaM/GnQ/TxWai5+2EiBJyy0BBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zXSs+QkcT5DpZnoC/988wM3j/N/gWXfYrsSYXI/7KUdJtixmMlnDEKBApaLWhnh3T DDEkC0BSGQIxro4eBSkZ6BsXg/6rtTDaGukqugsuc2zVPeuJwS2VCYRtUoDVuNT35r xvvSoYiB0korG8Ok1n2KuUi9yUWZFFXDem6YBuqo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Masami Hiramatsu , Anders Roxell , Joel Fernandes , Steven Rostedt , Sasha Levin Subject: [PATCH 5.7 203/265] kprobes: Suppress the suspicious RCU warning on kprobes Date: Mon, 29 Jun 2020 11:17:16 -0400 Message-Id: <20200629151818.2493727-204-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629151818.2493727-1-sashal@kernel.org> References: <20200629151818.2493727-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.7-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.7.7-rc1 X-KernelTest-Deadline: 2020-07-01T15:14+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masami Hiramatsu [ Upstream commit 6743ad432ec92e680cd0d9db86cb17b949cf5a43 ] 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. Link: http://lkml.kernel.org/r/158927055350.27680.10261450713467997503.stgit@devnote2 Reported-by: Anders Roxell Suggested-by: Joel Fernandes Reviewed-by: Joel Fernandes (Google) Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- kernel/kprobes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 195ecb955fcc5..950a5cfd262ce 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; } -- 2.25.1