From patchwork Fri Oct 13 09:14:04 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: 152440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1758773vqb; Fri, 13 Oct 2023 02:14:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSMFntO4g1TMcjLBoy2U627I0QXGb4swFUh2qLgc707wCD1MJSZm/R1ZSQb0ihkqjnoCks X-Received: by 2002:a05:6a00:3386:b0:6b2:51a0:e1c9 with SMTP id cm6-20020a056a00338600b006b251a0e1c9mr1357803pfb.1.1697188483704; Fri, 13 Oct 2023 02:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697188483; cv=none; d=google.com; s=arc-20160816; b=usIEn5uwFWbUJcsuOfKiO5ci5dN5ODANmb7sQBpKf3DLBHO2nXj9QOjxP/nlASM6V3 xH0uMtdIqDP5DhD4z5JbZ7ICrI40I2Yen0acnjz3Tow2YV7lESdxc7nFiUUBLs7yoHov IwtwkgEhGKyCxciqlNFiqYS5P7IKsrdpdU1eCmWprgvhIAr+PqlZf5z2SMMnKwLnZjXY uw+LCAuuYgVQ/UHFoDPlH5BwBg0I4E4kT2YrWP0paIXBWm+rd/DZexlivya33V6TZQW0 xuiq1LXGeHmz16cez4KZFhpnppQx/f2VvBLE9gF9RR4fltTaVxmIg3AnW9CTUQmuw5No 9JTA== 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=JXoy92x7s272DXAiZXjUYPhfFtA82gP22Z6+rTxNQxo=; fh=lO/G4f2MZ1MNXrqD0x4k0tKEYk45PQHmudrxpm+iK4w=; b=yXBroeTTaZT/3Dvc7vfbzf8KET2VLBpnDxCSzQAjucK7Q2zCGU0zle3xxtX/ZgYXyK ORP8IhfXeBgxJA5hr0uA3iL4aTRNy23qGuncXaJA6PcwMsyrCswUweQWz7zbWOs6pp2z Xd1A4Gocs+hXLMzrZeD+PjoBi8IIcTmbrWFD1BM7Vts7ih0NeIt8dAgnn9vkh//Zz5F9 st9GfXabHcmqyvtPMoJHqRxiRXnvWL8UfwhV1bYzy4eYzpTD/I9fN+Jfx6rD4EbYLiH/ y3USWGDrDSXtJTK3+21vfuEYLVRGnHEl4sihbc9yDuYu396sWlQ+fe2PTCou68TOXIxL Fy6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2w28x1l3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=O62c0Xyu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bx13-20020a056a00428d00b00690c0055246si16270619pfb.294.2023.10.13.02.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 02:14:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2w28x1l3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=O62c0Xyu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 6E09480A32ED; Fri, 13 Oct 2023 02:14:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbjJMJOO (ORCPT + 19 others); Fri, 13 Oct 2023 05:14:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjJMJOK (ORCPT ); Fri, 13 Oct 2023 05:14:10 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58097B7; Fri, 13 Oct 2023 02:14:07 -0700 (PDT) Date: Fri, 13 Oct 2023 09:14:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697188445; 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=JXoy92x7s272DXAiZXjUYPhfFtA82gP22Z6+rTxNQxo=; b=2w28x1l3tK8DVI48mctwy0mHDOWCaPqZmqVxehmZp73Og/9sKoSzx0VAnEsKCUxZUM+JZq oudxH83Lf8CvKsu4n79nVVX8+bgIc6VV0dWpgew//2rah/ZfvURuu0sDJjeEpILrYnQfhN emQxzVo9TaDhv9s7dglA9PMR10EbMUHx7anPll6RxTX1bXw8VU9cBMKXJD84XPA4lhujTQ z4LueOAissr9qz46ZLgSl+qpXAaFm3xFwrb0dyS+zJqUXOQqX0vthKyNVI35iCvfaZtw4s aaoj5+xWL85u3iOLZDajLvb0Oz/NfarzOzheYW/kk1LG+6FQ1AEi4+ylxwjzOg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697188445; 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=JXoy92x7s272DXAiZXjUYPhfFtA82gP22Z6+rTxNQxo=; b=O62c0XyuF+lkDpmnPmjIHCekg6knmYQEcazcXRPf/rMnNjfqqynEEsmLkPDW2VZzBujVY9 cVikve3J6meAa0BQ== 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: <169718844432.3135.15889232861404181753.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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 13 Oct 2023 02:14:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779631111414327227 X-GMAIL-MSGID: 1779631111414327227 The following commit has been merged into the locking/core branch of tip: Commit-ID: 0bb27df504fb8d3c53f8dfdf9bee09731a90672f Gitweb: https://git.kernel.org/tip/0bb27df504fb8d3c53f8dfdf9bee09731a90672f Author: Ingo Molnar AuthorDate: Fri, 13 Oct 2023 10:15:46 +02:00 Committer: Ingo Molnar CommitterDate: Fri, 13 Oct 2023 10:41:55 +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 Cc: 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) {