Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1232201ybl; Wed, 4 Dec 2019 20:20:45 -0800 (PST) X-Google-Smtp-Source: APXvYqy5a4SgyKezdBHQlqBArvhgWd6pu/takxLb/PAThNWxQElhFIBkeYu0Pxinj4I3hFwm6Xw9 X-Received: by 2002:aca:5b08:: with SMTP id p8mr5466693oib.178.1575519644902; Wed, 04 Dec 2019 20:20:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575519644; cv=none; d=google.com; s=arc-20160816; b=d837O8oYxE5f/KNnZyZEOhvN7Lwzia3R3UnFVZ3Yw4gWGtYNTrYCOnk4O4nmt7j4vr A3GhdvAv5gAdHM53wLo5e4y7kBiHovOfqGPS3bafcjQo6x3svOsWM/GznbdlzdFfcsTS kv3fVshsEkTQGm5tBlCRRlClvDkd8A1OUyvvAfPtWk4zfxdAtRV049sd+lcfyg/RYVsL TE8wS5C5EMYp33bziynb0XgwTbkqemRk5ouwQijzfIzvSlvBNkNXPlmvgiC8sbxQ4WNM 1PSC+Vqt0Hbrz956tOqhuiIUZBMYxxPR2wYXXeCLmU5WfdDmF/Rw1Ejdx+2f6MKkqOIX BITw== 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=BNh78S4fjwZyQQtddYByIWA7giwIsfzocwdcP3Y+uXs=; b=YrdO2GOtwqmTqXwsfHf2R/9gEprPo1INRyVWP+GL0MSxBhCjfxCit9e0gFAKB04YrF 28/DApRXGbjNLsXB+p9iNlw5px+2u+eCQnMrrm3rNL6ZpVU1w7wp4i+00npN/g8keFns FmBQ7o0eihR681thOUm9zeodMA/ssMoxB4h1xLH5+ba6Wotl61dHSOw1lCJ+HvPlEIcU OPsdFAAq2QMyoSoIiAvptyUQ5gqJRH8E9SLXLLvLpnJFqXHzUA5j9k6E0cBRlJf026G9 LG4PzPmuYlS+BOe2jLHHyfsDm2YYuD9xD1m3xQCRee6jV6xSg+yTVn9CMTylAda2efRD +7ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IFhU+OVd; 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 f4si4260241oto.169.2019.12.04.20.20.32; Wed, 04 Dec 2019 20:20:44 -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=IFhU+OVd; 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 S1728802AbfLEEUB (ORCPT + 99 others); Wed, 4 Dec 2019 23:20:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:48318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728132AbfLEEUB (ORCPT ); Wed, 4 Dec 2019 23:20:01 -0500 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 ED9842073B; Thu, 5 Dec 2019 04:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575519601; bh=i2PIqlRJ7sQMFV6ii943yJLdx+iIcnR8GRR57prfsxw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IFhU+OVdep6Oru3Q3sqJPA9ZGxPVPlzywpRQHl1c3Yaw19nIQf+CLtTTArePS9hvQ 1XxiSzS2m6BVTgy+5EiXZNjN1Cb+OV6v5W8AnLk33ztTiU2jawo8ihutjJmRvm3KGs 0vNnxWXcgjJ/1N6ov3GG2CIRhlS4SpFQ5Y8Mpb1o= Date: Thu, 5 Dec 2019 13:19:56 +0900 From: Masami Hiramatsu To: paulmck@kernel.org Cc: Ingo Molnar , 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: <20191205131956.5465722a947ff41ea22cbdf1@kernel.org> In-Reply-To: <20191204161239.GL2889@paulmck-ThinkPad-P72> References: <157527193358.11113.14859628506665612104.stgit@devnote2> <20191202210854.GD17234@google.com> <20191203071329.GC115767@gmail.com> <20191203175712.GI2889@paulmck-ThinkPad-P72> <20191204100549.GB114697@gmail.com> <20191204161239.GL2889@paulmck-ThinkPad-P72> 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 Hi Ingo, On Wed, 4 Dec 2019 08:12:39 -0800 "Paul E. McKenney" wrote: > On Wed, Dec 04, 2019 at 11:05:50AM +0100, Ingo Molnar wrote: > > > > * Paul E. McKenney wrote: > > > > > > * 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? > > > > Yeah, so basically in the write-locked path hlist_for_each_entry() > > generates (slightly) more efficient code than hlist_for_each_entry_rcu(), > > correct? > > Potentially yes, if the READ_ONCE() constrains the compiler. Or not, > depending of course on the compiler and the surrounding code. For this kprobes case, I can introduce get_kprobe_locked() which uses hlist_for_each_entry() instead of hlist_for_each_entry_rcu(). However, this sounds like a bit strange choice, because get_kprobe (RCU version) should be used on "hot" paths (because it is lock-free), and get_kprobe_locked() is used on slow paths. If hlist_for_each_entry() can be more efficient, we will keep unefficient API for hot paths, but use the efficient one for slow paths. Thank you, -- Masami Hiramatsu