From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A058BC4332F for ; Tue, 5 Oct 2021 16:29:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E84561381 for ; Tue, 5 Oct 2021 16:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236479AbhJEQbH (ORCPT ); Tue, 5 Oct 2021 12:31:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:35046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236088AbhJEQbG (ORCPT ); Tue, 5 Oct 2021 12:31:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2189D61373; Tue, 5 Oct 2021 16:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633451356; bh=iwigj6eqF85kwprTmioYxRpgk7wef6bzF9Dh2dvCPjw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=AlXg6bGLNt7mMzBF/flLI36K2EjnFNxsBWAu6yprqL0wtI8WnL9FR1JLjxK+2foPA jfdoChtdolfmJnadyhnhdglJpcA3NvDTReEmu41CYpBxcx4I09xz/9jBm0JIM+oUBG GwrGAm2OhG7s5lqdXitgyMHwK2MpXzzkaPaEAoai+NN6loKruu6mH5D1vkxk873n+9 ibhq+PXrqr9yCgkzlF01zxyvkwigyxbkPytXlmd9WIT93erDqC5KBKDcgFW/SWCM5c 285Qeaajs7HoZNhb2B9+5VREBGmTjJmid0ze2Zv3L1ML7+tXNgHsYqLX89RJ3Noi4F gIB761HlQ35Dg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id D979A5C098A; Tue, 5 Oct 2021 09:29:15 -0700 (PDT) Date: Tue, 5 Oct 2021 09:29:15 -0700 From: "Paul E. McKenney" To: Mathieu Desnoyers Cc: rostedt , linux-kernel , Linus Torvalds , Josh Triplett , Lai Jiangshan , "Joel Fernandes, Google" , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , rcu , netfilter-devel , coreteam , netdev Subject: Re: [RFC][PATCH] rcu: Use typeof(p) instead of typeof(*p) * Message-ID: <20211005162915.GT880162@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20211005094728.203ecef2@gandalf.local.home> <505004021.2637.1633446912223.JavaMail.zimbra@efficios.com> <20211005115817.2e1b57bd@gandalf.local.home> <155148572.2789.1633450504238.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155148572.2789.1633450504238.JavaMail.zimbra@efficios.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Oct 05, 2021 at 12:15:04PM -0400, Mathieu Desnoyers wrote: > ----- On Oct 5, 2021, at 11:58 AM, rostedt rostedt@goodmis.org wrote: > > > On Tue, 5 Oct 2021 11:15:12 -0400 (EDT) > > Mathieu Desnoyers wrote: > > > >> ----- On Oct 5, 2021, at 9:47 AM, rostedt rostedt@goodmis.org wrote: > >> [...] > >> > #define rcu_dereference_raw(p) \ > >> > ({ \ > >> > /* Dependency order vs. p above. */ \ > >> > typeof(p) ________p1 = READ_ONCE(p); \ > >> > - ((typeof(*p) __force __kernel *)(________p1)); \ > >> > + ((typeof(p) __force __kernel)(________p1)); \ > >> > }) > >> > >> AFAIU doing so removes validation that @p is indeed a pointer, so a user might > >> mistakenly > >> try to use rcu_dereference() on an integer, and get away with it. I'm not sure > >> we want to > >> loosen this check. I wonder if there might be another way to achieve the same > >> check without > >> requiring the structure to be declared, e.g. with __builtin_types_compatible_p ? > > > > Is that really an issue? Because you would be assigning it to an integer. > > > > > > x = rcu_dereference_raw(y); > > > > And that just makes 'x' a copy of 'y' and not really a reference to it, thus > > if you don't have a pointer, it's just a fancy READ_ONCE(y). > > See Documentation/RCU/arrayRCU.rst: > > "It might be tempting to consider use > of RCU to instead protect the index into an array, however, this use > case is **not** supported. The problem with RCU-protected indexes into > arrays is that compilers can play way too many optimization games with > integers, which means that the rules governing handling of these indexes > are far more trouble than they are worth. If RCU-protected indexes into > arrays prove to be particularly valuable (which they have not thus far), > explicit cooperation from the compiler will be required to permit them > to be safely used." > > So AFAIU validation that rcu_dereference receives a pointer as parameter > is done on purpose. What Mathieu said! On the other hand, I am starting to believe that explicit cooperation from compilers might actually be forthcoming in my lifetime, so there might well be that... Thanx, Paul