Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2471628pxb; Tue, 12 Oct 2021 07:20:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkRzLFf2+VxTUAKVQdRuwnRozM2QLRMEoHIWtYG8kRv7BP0HnJCdWYZtI52ZLfNtcluwsX X-Received: by 2002:a63:4f0d:: with SMTP id d13mr22651267pgb.169.1634048413414; Tue, 12 Oct 2021 07:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634048413; cv=none; d=google.com; s=arc-20160816; b=HCnw5psdLfRmNcydszvKEDXhS5NOl/wwlmBAdx9uLztlPhGS3P7TB/WqGCbt2DiHYG aXHUzrTgOGo9lcdHzq/+k0WrMH3uX7Xlq3f7++siS8yo97ZL6eLI4ZAH0h2sSWLG/dMW MrPycyuR0Z+Pzza7liQad5OxAF0DBmnWlGe9RUX9CuRjOMqjY6kwNHFN/MiRMsFDnplV ar0i+UzEj6+SNnQwihlozha2KcHiH2wNylk7FxyXoUDraL2uCy2A5IxX00jsCh0HKXS7 dIHj6UZl+y7Y+BDwQpBuk1s1/S8bAnltgh3VQcFTuC42dKUxoAvxNZ9gAMxXsoq/JpO2 T1cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=oDnCBhtt2kYndLvbZ2dFBdBvvOim1KjLRvBSV4K13jM=; b=h/UCu80DShmlRulOqzA9HikbbIT6wpZcOH0IVlq5AF5GSzAYZgC7L7iju9ywm2VWcU FHQW6CVekG8lpppXTA1ZLM9a/+fpzSQ6APsPst/sl80BKUnaQ3L/WQDmzYxCXCnbtOls Wqnyy/kNO8GHceclpnq6iNclRzd9d2YWVSdVG8KmqkY4xh63jiGZmptXsDid/q1gM2tc +jlPXUmsWw91QLBHq4LGNms5VMB+QhwEA/LVucAqgk3v8Ldgu68cKaTf9stRv1M+HlMd xEx/YUwrEsFvyW7cKdPX9sOa5IPTTiJAJbjLQY0tAK1S1uQs5udXzpqQz3Fn0jTVJx07 XSaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=qHFA3Ihr; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 24si15806463pgm.239.2021.10.12.07.19.59; Tue, 12 Oct 2021 07:20:13 -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=@efficios.com header.s=default header.b=qHFA3Ihr; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237168AbhJLOUH (ORCPT + 99 others); Tue, 12 Oct 2021 10:20:07 -0400 Received: from mail.efficios.com ([167.114.26.124]:37390 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236695AbhJLOUG (ORCPT ); Tue, 12 Oct 2021 10:20:06 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4BD2E362C62; Tue, 12 Oct 2021 10:18:04 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 0DNMGIKTscHv; Tue, 12 Oct 2021 10:18:03 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id AB87C362C61; Tue, 12 Oct 2021 10:18:03 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com AB87C362C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1634048283; bh=oDnCBhtt2kYndLvbZ2dFBdBvvOim1KjLRvBSV4K13jM=; h=Date:From:To:Message-ID:MIME-Version; b=qHFA3IhrvM/jvCrRxBuQ5z0V3oJe7BPP2XLjfE7I7j2j/hL40ExC1JOaXfJTjt3bE jOsOpVSc6c1y1cGAV2+8uPV+xt8RqBzzRrTmazZvCfC9rEegqXStdTlcUxaF4KYN6h H7XSIouCsZ6ibCi3cf8RtqT3g9WwpcdbPOpUOmFi0oZRKFpNzVFfj4oCmD3vi+CZaz JfFatJwx19qX+Pm26RSh9tVA1a7elmsOIawr0RDSC2HnxmxKErDs6npCf1kg5HrNT5 5OyYh97yO869J2TvfJIvDnO/E/VBH9yJ3tfwp4OYBQElRnCtP8d1HvzXtxSVbKU2DL BN9K3yKFfy2oA== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id fAOI71LUIkg8; Tue, 12 Oct 2021 10:18:03 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 90253362CEE; Tue, 12 Oct 2021 10:18:03 -0400 (EDT) Date: Tue, 12 Oct 2021 10:18:03 -0400 (EDT) From: Mathieu Desnoyers To: David Laight Cc: rostedt , linux-kernel , Linus Torvalds , Paul , 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 Message-ID: <364516086.11428.1634048283470.JavaMail.zimbra@efficios.com> In-Reply-To: <4dbff8032f874a6f921ba0555c94eeaf@AcuMS.aculab.com> References: <20211005094728.203ecef2@gandalf.local.home> <505004021.2637.1633446912223.JavaMail.zimbra@efficios.com> <4dbff8032f874a6f921ba0555c94eeaf@AcuMS.aculab.com> Subject: Re: [RFC][PATCH] rcu: Use typeof(p) instead of typeof(*p) * MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_4156 (ZimbraWebClient - FF93 (Linux)/8.8.15_GA_4156) Thread-Topic: Use typeof(p) instead of typeof(*p) * Thread-Index: Ade+e4X0oj4GW2UzTF+XE9nyZN8f2yyzmkpu Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Oct 11, 2021, at 4:39 AM, David Laight David.Laight@ACULAB.COM wrote: > From: Mathieu Desnoyers >> Sent: 05 October 2021 16:15 >> >> ----- 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 ? > > Could you pass the pointer to something like: > static __always_inline void foo(void *arg) {}; > > That would fail for integers. > Not sure whether CFI bleats about function pointers though. > That would indeed validate that a pointer is being passed to rcu_dereference() and RCU_INITIALIZER(). However it would not solve this other issue: in Steven's patch, rcu_dereference_raw is changed like so: #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)); \ }) and AFAIU the __force __kernel attributes end up applying to the pointer rather than the object pointed to, which changes the semantic. So checking the pointer argument is not the only issue here. As Linus pointed out, it might indeed be simpler to just keep declaring the structure in public headers. Thanks, Mathieu > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, > UK > Registration No: 1397386 (Wales) -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com