Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1622311ybl; Tue, 3 Dec 2019 10:00:23 -0800 (PST) X-Google-Smtp-Source: APXvYqwyH4eDRcreAwTuE3Xc5qVCP0H+R6rXSz13B409nt7qtJd31b1KK9/4m/VUbQhubYESQ4Ci X-Received: by 2002:a54:4583:: with SMTP id z3mr4514320oib.164.1575396023593; Tue, 03 Dec 2019 10:00:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575396023; cv=none; d=google.com; s=arc-20160816; b=UxF1VvsbCVlgt9NFpvu0UtyzlCaqQ9+oakgMgegjFHuq/JB2XdVfO4dg8qFau3vvpR nkopbhqSm8s0jTtrWETb5D2g49A+UP6Mz1xyOga7RUwzWVIIMbqaMFAEqthW/quFWj2g NE6cH4xNJdYnQZdJNBO5rT/kRgJx8ptXJmXoqyDC1lDI6x5DXtxR3qLKDhdMXViI2SYX 4XSd9LcShtVsNbPrI1R6dmy5uGUoLG/yAm8MWbugn5MslUsGl5DWKxDIh22EMkcPm/x0 bVZByfEaRPUJZIkAv0y3z0+yg1WWSVaG/senpjHrdx6HSlYDfAh7hHP3P5v4FFh8LWY4 n6JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=agSLuXrgUwG4D9i3UvllNHnVwmxuDg98BDyfXsAcv2I=; b=OkbrmQr7N6GElZ1amScx4+e3OML7PFJDauE7rQ3UlI5v4odcB0ice/8qfhMPxipUlu 6ek+p0d7sMOimO6BRJx7nAR0gVfm6GykMtnZcGq5IFy2/0+WCZ0wCcjFrOAuLsKJkcUm TKXxrutuLbdN5bNlHtlesbe7a42hGGBSH9Psj2L6b/ndiJK80l8yiW0IHpFzb83Kkmlq uy3FOTMSg3V+794j0gknr8Aj9ve/yK4aRzh+GkTxjhV0yWMZN5HH62h1E8Ue40Cx9Z/g HDqI4K31qf77SNqoIrrslXLNm9e3Ymix2NkSAfMEpq5wAvaVFovVgW3iSbIxQJPj24A2 vxXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hI3NOZiC; 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 j24si1633425oij.157.2019.12.03.10.00.10; Tue, 03 Dec 2019 10:00:23 -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=hI3NOZiC; 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 S1727059AbfLCR5N (ORCPT + 99 others); Tue, 3 Dec 2019 12:57:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:40596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbfLCR5N (ORCPT ); Tue, 3 Dec 2019 12:57:13 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (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 53F3D20674; Tue, 3 Dec 2019 17:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575395832; bh=2kktFZXD9CwoMbSmBlBwAhAuQvCLLNSXzvolzrrYLkA=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=hI3NOZiCUI9g1G+djYFq5JeGstQs+WuqJrQiddfYqVVLV8zruMzt2OiVa5zCkvhCE ev5xBCJDwjvEkzFj/5YzjU9g5wHgWbwfq3Vvg1rePHNZEjwjAcUd5Zf/b2s8xfHD+g Kfw2bOkvzI40czmGQR9IQNZqH3V5tfp+Qx1LIctg= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 2D8D33522780; Tue, 3 Dec 2019 09:57:12 -0800 (PST) Date: Tue, 3 Dec 2019 09:57:12 -0800 From: "Paul E. McKenney" To: Ingo Molnar Cc: Joel Fernandes , Peter Zijlstra , Masami Hiramatsu , Anders Roxell , "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: <20191203175712.GI2889@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <157527193358.11113.14859628506665612104.stgit@devnote2> <20191202210854.GD17234@google.com> <20191203071329.GC115767@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191203071329.GC115767@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 03, 2019 at 08:13:29AM +0100, Ingo Molnar wrote: > > * 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. > > Come on, we do not silence warnings! > > If it's safely inside the lock then why not change it from > hlist_for_each_entry_rcu() to hlist_for_each_entry()? > > I do think that 'lockdep flag' inside hlist_for_each_entry_rcu(): > > /** > * hlist_for_each_entry_rcu - iterate over rcu list of given type > * @pos: the type * to use as a loop cursor. > * @head: the head for your list. > * @member: the name of the hlist_node within the struct. > * @cond: optional lockdep expression if called from non-RCU protection. > * > * This list-traversal primitive may safely run concurrently with > * the _rcu list-mutation primitives such as hlist_add_head_rcu() > * as long as the traversal is guarded by rcu_read_lock(). > */ > #define hlist_for_each_entry_rcu(pos, head, member, cond...) \ > > is actively harmful. Why is it there? For cases where common code might be invoked both from the reader (with RCU protection) and from the updater (protected by some lock). This common code can then use the optional argument to hlist_for_each_entry_rcu() to truthfully tell lockdep that it might be called with either form of protection in place. This also combines with the __rcu tag used to mark RCU-protected pointers, in which case sparse complains when a non-RCU API is applied to these pointers, to get back to your earlier question about use of hlist_for_each_entry_rcu() within the update-side lock. But what are you seeing as actively harmful about all of this? What should we be doing instead? If you are suggesting that KCSAN might replace sparse's use of __rcu, I have been attempting to think along those lines, but thus far without any success. In contrast, I am starting to think that lockdep has made the sparse __acquires() and __releases() tags obsolete. Or am I missing your point? Thanx, Paul