From patchwork Sat Oct 14 10:29:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 152925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2404605vqb; Sat, 14 Oct 2023 03:30:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMZRkg6qNaWNF+LBeut5GhKMxUqWqVuNDNPEgyHII2ta355aXaL7wqD1Fy2musiW9D91lg X-Received: by 2002:a05:6870:f708:b0:1d5:1a99:537f with SMTP id ej8-20020a056870f70800b001d51a99537fmr31177774oab.2.1697279403471; Sat, 14 Oct 2023 03:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697279403; cv=none; d=google.com; s=arc-20160816; b=aN50BTKEa1VZ6/q7VKV/HLMW+Ws2pxXhNodUwQRgOq3Wnk6wu5DoXHF4Cg1bg4nLGH kQaclysD9bg09bIoY2k6OsnRVWchU8IXaWVLNGIVt0Fje5a7DS2gYYJ2Qe6CDBRYHReV mwwzbSD/D3qQX6k3MLlFJXA7/HcrQxTbXttZQlU+aAbkOa4KzRZ74yaoynOzoKes+F0b zc6OLBwY7CZT+aq/KI5N/jYv7qR5a+8PoXmis/gDr4PcJ+jF7qu74JebYLA9mJOzIMtG UPbahTpzSliBNDv2XjCdYURjJo0Hmh0q6qLKEeRrfbWH60U9vKtF92oPUkwXXvS+9YUB M1cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=eE+poOiRRwrdwN/fZ4h4/pg7LGMoOCv7Xn+HsYY3yV8=; fh=lO/G4f2MZ1MNXrqD0x4k0tKEYk45PQHmudrxpm+iK4w=; b=NWiq0drXMNdOuXwEkhoSrHbjb4/57qRAD9Hdqu2aXjizUsvujRAuaYejT9rG1gjMTJ xiuemJUQe/ELt4ObbITx4MQ1AOI2mEY/aYNOg2lNvdiNiYH6ierZi1yVR4z9Cfhdm5oC tLNVUt0Y8La0VQycUi5njVsfYEOw2kRZ2tbCoF17np29HnMgGK898FMHcH5DaTQKCcGH I+pmWP63Ujavg1FAayn+irj9eJAWyiJjrn4h0GhJNAdUb3YSMzdkZOtqbHi3RU8+yKuk C0LOT+ptlXK0Trhq/Sk6oS7w0olxy4zxJ5IMpTznYcfqdR8Hzn3dmk7QUr026pZ0z9oD A27w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ivZ5MQYS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wMqTVbvo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id s7-20020a635247000000b0056357813fc2si6435369pgl.183.2023.10.14.03.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 03:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ivZ5MQYS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wMqTVbvo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 453AF801BCA4; Sat, 14 Oct 2023 03:30:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233018AbjJNK3Q (ORCPT + 20 others); Sat, 14 Oct 2023 06:29:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232937AbjJNK3P (ORCPT ); Sat, 14 Oct 2023 06:29:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FEB5A2; Sat, 14 Oct 2023 03:29:13 -0700 (PDT) Date: Sat, 14 Oct 2023 10:29:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697279350; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eE+poOiRRwrdwN/fZ4h4/pg7LGMoOCv7Xn+HsYY3yV8=; b=ivZ5MQYSWP776eH5qHrKWywfAcZ4TtnO4uYjOqTjm6Sli8kWy+km8oIA5LD9JK6lIv1z1m gCwXamLA8Ft6YqhHDMIOAuRF3z6bC+DaD45IiW5OjgYRYcjZmhy2WWfjKiXM93xgenAVpT yFaoPydvGS4am/0LIeV4//WCoq+AShfJIzffEoRH9rS9uy0C0s/rLeHUl5aJI43l0pxIXg pZwy92G/V9erHDQqzvHnakzIs7uUxw2rk2Jo+0H3gVQIebk1ZMhfECHi701s+GUDCRrTrf 7qaA8S1uDwfWAKPMQ+o0PjzHyGdzvkhNG44KvpFzbNJBkWDbPEg9vEM9QJe9Jw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697279350; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=eE+poOiRRwrdwN/fZ4h4/pg7LGMoOCv7Xn+HsYY3yV8=; b=wMqTVbvoq6zLujsaJLS9kvlnyQrgXsWgg+tytMQiyan8viXSVsxKCY0+jyhy4J4vAPctp8 jYE0nKj/eFr/plCw== From: "tip-bot2 for Ingo Molnar" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] locking/seqlock: Propagate 'const' pointers within read-only methods, remove forced type casts Cc: Ingo Molnar , Oleg Nesterov , Linus Torvalds , Peter Zijlstra , Waiman Long , Will Deacon , Thomas Gleixner , "Paul E. McKenney" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169727934984.3135.3212674170316933544.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 14 Oct 2023 03:30:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779726447686292888 X-GMAIL-MSGID: 1779726447686292888 The following commit has been merged into the locking/core branch of tip: Commit-ID: 886ee55eabac0d46faf8bc0b22207ca2740847ba Gitweb: https://git.kernel.org/tip/886ee55eabac0d46faf8bc0b22207ca2740847ba Author: Ingo Molnar AuthorDate: Fri, 13 Oct 2023 10:15:46 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 14 Oct 2023 11:06:15 +02:00 locking/seqlock: Propagate 'const' pointers within read-only methods, remove forced type casts Currently __seqprop_ptr() is an inline function that must chose to either use 'const' or non-const seqcount related pointers - but this results in the undesirable loss of 'const' propagation, via a forced type cast. The easiest solution would be to turn the pointer wrappers into macros that pass through whatever type is passed to them - but the clever maze of seqlock API instantiation macros relies on the GCC CPP '##' macro extension, which isn't recursive, so inline functions must be used here. So create two wrapper variants instead: 'ptr' and 'const_ptr', and pick the right one for the codepaths that are const: read_seqcount_begin() and read_seqcount_retry(). This cleans up type handling and allows the removal of all type forcing. No change in functionality. Signed-off-by: Ingo Molnar Reviewed-by: Oleg Nesterov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Waiman Long Cc: Will Deacon Cc: Thomas Gleixner Cc: Paul E. McKenney --- include/linux/seqlock.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 4b8dcd3..80f21d2 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -200,9 +200,15 @@ typedef struct seqcount_##lockname { \ } seqcount_##lockname##_t; \ \ static __always_inline seqcount_t * \ -__seqprop_##lockname##_ptr(const seqcount_##lockname##_t *s) \ +__seqprop_##lockname##_ptr(seqcount_##lockname##_t *s) \ { \ - return (void *)&s->seqcount; /* drop const */ \ + return &s->seqcount; \ +} \ + \ +static __always_inline const seqcount_t * \ +__seqprop_##lockname##_const_ptr(const seqcount_##lockname##_t *s) \ +{ \ + return &s->seqcount; \ } \ \ static __always_inline unsigned \ @@ -247,9 +253,14 @@ __seqprop_##lockname##_assert(const seqcount_##lockname##_t *s) \ * __seqprop() for seqcount_t */ -static inline seqcount_t *__seqprop_ptr(const seqcount_t *s) +static inline seqcount_t *__seqprop_ptr(seqcount_t *s) +{ + return s; +} + +static inline const seqcount_t *__seqprop_const_ptr(const seqcount_t *s) { - return (void *)s; /* drop const */ + return s; } static inline unsigned __seqprop_sequence(const seqcount_t *s) @@ -302,6 +313,7 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) __seqprop_case((s), mutex, prop)) #define seqprop_ptr(s) __seqprop(s, ptr)(s) +#define seqprop_const_ptr(s) __seqprop(s, const_ptr)(s) #define seqprop_sequence(s) __seqprop(s, sequence)(s) #define seqprop_preemptible(s) __seqprop(s, preemptible)(s) #define seqprop_assert(s) __seqprop(s, assert)(s) @@ -353,7 +365,7 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) */ #define read_seqcount_begin(s) \ ({ \ - seqcount_lockdep_reader_access(seqprop_ptr(s)); \ + seqcount_lockdep_reader_access(seqprop_const_ptr(s)); \ raw_read_seqcount_begin(s); \ }) @@ -419,7 +431,7 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) * Return: true if a read section retry is required, else false */ #define __read_seqcount_retry(s, start) \ - do___read_seqcount_retry(seqprop_ptr(s), start) + do___read_seqcount_retry(seqprop_const_ptr(s), start) static inline int do___read_seqcount_retry(const seqcount_t *s, unsigned start) { @@ -439,7 +451,7 @@ static inline int do___read_seqcount_retry(const seqcount_t *s, unsigned start) * Return: true if a read section retry is required, else false */ #define read_seqcount_retry(s, start) \ - do_read_seqcount_retry(seqprop_ptr(s), start) + do_read_seqcount_retry(seqprop_const_ptr(s), start) static inline int do_read_seqcount_retry(const seqcount_t *s, unsigned start) {