Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp950526ybl; Mon, 2 Dec 2019 22:03:21 -0800 (PST) X-Google-Smtp-Source: APXvYqySc0ccm/NNO8CVKcD4xp0XuHjZz/Ua1WXCc8NG0Dk6Bu9IENH4OJTACkRgRZdUCXif0sd6 X-Received: by 2002:a05:6830:170b:: with SMTP id 11mr2141881otk.75.1575353001058; Mon, 02 Dec 2019 22:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575353001; cv=none; d=google.com; s=arc-20160816; b=uerJxSPLDzllvNlSu5X7HgS5A1eJXWcMHEOH2CU79WIv67C+PX2kGyBKJwn+QlKCaY 2xmQNw/6q2O3Z9Muvi6aAfHI3ACDu+F/nzu8+ugHHiL/gBr4vFfFYKm/JJJb+kMFSqic 3VO5pkEKVIO78sHu+gTHCdfFhYbQzfkoc7NY3SoS5txuMMs5gV/J73LAIXCeX6+LlvW8 rWX9OdR1AiHrPNLBlO2l/VhoqVRZOQJRTYAT/8R1IWfUkyx+kGgfSxCW57pL0IvvzysG i1xy1RhWJOm1Bykjl6ZYy5OWKN+Mjb/Ru4ZA2HOHxg15cWsx2nYWA7gyM/eFc0XuGVg/ KLtw== 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:subject:cc:to:from:date :dkim-signature; bh=7az34TFZXTgMHRKIXf0UN0SO+QgsM6gRJ5WVIhjJmD8=; b=lXMESekBhmmNDT6XuSEoMQ5pmGCTULaMvzmn4qzMjen++ltV75H0khFJD7JhTXzvy1 puoIe/pqeRwNIy1l88XF2fX304EQ5DBubE2WqfSM48JnBBmAaI/4JlV2fnlG+z9jQHL2 NP528VzNztJLVIYjxPNFZdZp7xdbcbhThdX5hItCtX9cQbAQQ5LvyB8qvWtE5DnITXfu 2QdHfHlOu32Xp/tOyOXE82qiDELBqIBFWsjbM3C8E/UeRUWsOqITy8z3WxX+lxNweER8 +fbFT5Q+I9RxaggpJDIf1jdSZtJvPCyxunDq/Uiuc/ls70lrp7wP41oJC3cgD4YpQwy4 Oj4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y6VwYbwS; 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 j6si795115oie.222.2019.12.02.22.02.56; Mon, 02 Dec 2019 22:03:21 -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=Y6VwYbwS; 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 S1727059AbfLCGCQ (ORCPT + 99 others); Tue, 3 Dec 2019 01:02:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:42882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfLCGCQ (ORCPT ); Tue, 3 Dec 2019 01:02:16 -0500 Received: from devnote2 (unknown [180.22.253.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 776F220684; Tue, 3 Dec 2019 06:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575352935; bh=U3312gghEjD+4yD8J4laQQ5wqu89YhGM/9fXJ/iYSrI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Y6VwYbwS2TBnVxRp3WwQ4lohL3RGNRE4yYMEL8L/8Ei4NFKyg60CVfzAR5vTPlWOc dkwH12N44ttRYA4SnqCCmxiCUtGvTWN2vMc5JJ+C08j5RCfl7cKqmyaHkNk0qFAoub STmJDnoNkHkp4PVt93w5Xuk2zOs1AY+y6D5s0MI0= Date: Tue, 3 Dec 2019 15:02:10 +0900 From: Masami Hiramatsu To: Joel Fernandes Cc: Ingo Molnar , Anders Roxell , paulmck@kernel.org, "Naveen N . Rao" , Anil S Keshavamurthy , David Miller , Linux Kernel Mailing List Subject: Re: [PATCH -tip] kprobes: Lock rcu_read_lock() while searching kprobe Message-Id: <20191203150210.7210c6e29c537c8954889c5b@kernel.org> In-Reply-To: <20191202233531.GO17234@google.com> References: <157527193358.11113.14859628506665612104.stgit@devnote2> <20191202210854.GD17234@google.com> <20191203073453.057c1bed6931457b011dd8cc@kernel.org> <20191202233531.GO17234@google.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2 Dec 2019 18:35:31 -0500 Joel Fernandes wrote: > On Tue, Dec 03, 2019 at 07:34:53AM +0900, Masami Hiramatsu wrote: > > Hi Joel, > > > > On Mon, 2 Dec 2019 16:08:54 -0500 > > Joel Fernandes wrote: > > > > > On Mon, Dec 02, 2019 at 04:32:13PM +0900, Masami Hiramatsu wrote: > > > > 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. > > > > > > > > Let's lock the rcu_read_lock() around get_kprobe() and > > > > ensure kprobe_mutex is locked at those points. > > > > > > > > Note that we can safely unlock rcu_read_lock() soon after > > > > accessing the list, because we are sure the found kprobe has > > > > never gone before unlocking kprobe_mutex. Unless locking > > > > kprobe_mutex, caller must hold rcu_read_lock() until it > > > > finished operations on that kprobe. > > > > > > > > Reported-by: Anders Roxell > > > > Signed-off-by: Masami Hiramatsu > > > > > > Instead of this, can you not just pass the lockdep_is_held() expression as > > > the last argument to list_for_each_entry_rcu() to silence the warning? Then > > > it will be a simpler patch. > > > > Ah, I see. That is more natural to silence the warning. > > Np, and on such fix, my: > > Reviewed-by: Joel Fernandes (Google) > Thanks! I found another similar issue while testing, I'll fix it too. -- Masami Hiramatsu