From patchwork Thu Oct 12 18:35:54 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: 152114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1427351vqb; Thu, 12 Oct 2023 11:36:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuBFCWqtHGItcbVQSFIHgSQFlPTv2R/29P6YHUanbBf7hy/qsu+YpwJPsxpm8tgS7U8eLn X-Received: by 2002:a17:902:ea0c:b0:1c2:c60:8388 with SMTP id s12-20020a170902ea0c00b001c20c608388mr26960655plg.6.1697135786366; Thu, 12 Oct 2023 11:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697135786; cv=none; d=google.com; s=arc-20160816; b=EfebPIulzZw64Nzpf+96XeXCvJ/wp1/rXoV8l+2+2NFZHTcVit8Dy0jmVMc75SJNVu G9ywoiKT1oKS2ijSYVrLRScjslRDtdKaJmGQHkvDOFFKZkAfTPs0eU1PlBlEDaxKbXIs Zwb0huIgGeZMaziuVg6T8lF0tA9iNeCWxFipMdx1zxu7Yf3SqodAz7YbROImyJI+4YYT jjHQqDNSzrpkEL2mND6vujFd33CoKTlyHEN/bBLKSrflZpXE08MtX5TrSNBkjSw8/4cA YnwW/QCie4531uhpDkkWi0BcejQjJ824eOBdYJWlTBmwc1b33zjzueyvtomWl3odF4yh 9W8A== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=L2nIrcLmRRoEjLnrmI7Wbsm+A7PZaXBdayO8FQILJ/I=; fh=kFB9uQyxVvjm2R0ul7wxypzO2CDQ/Wd3RLAPUv0GPQE=; b=G/ZfGRSBzKVkdbl0znj+F0f/MSd2WBstzx9LCNpMKofVGdmA0dIzpNEkZREFiS9YC/ OoJven5MZ69noHJ/o054bPqtr20osXM49ewmw1gcLFnPeTSNP9UKBjA6Rdep46lR+R3t uZGnP6zuyKZq788vkYTjjDbc077xwhIhTVaA2Mc1/rQ09FNNItx415RV+6r0Y6oB75fm 3hoCDjzJaCBMwjOo9hwv5w7PGy3hYDP+DQZeHaTjWyZeq7UowPzXPkqSkLfo0qajXdcM JcSr8kA2Dz4exlbm634SrZ2YqJuzL2OKqSvQl4eUA2zcyLhEjDV7H0H29uTZYlZCIWzR pg7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fMAhcxBE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id g22-20020a170902869600b001c426636990si2557225plo.637.2023.10.12.11.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 11:36:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fMAhcxBE; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 9DC7280A5286; Thu, 12 Oct 2023 11:36:23 -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 S235770AbjJLSgM (ORCPT + 19 others); Thu, 12 Oct 2023 14:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235787AbjJLSgG (ORCPT ); Thu, 12 Oct 2023 14:36:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9CFDA; Thu, 12 Oct 2023 11:35:56 -0700 (PDT) Date: Thu, 12 Oct 2023 18:35:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697135755; 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: in-reply-to:in-reply-to:references:references; bh=L2nIrcLmRRoEjLnrmI7Wbsm+A7PZaXBdayO8FQILJ/I=; b=fMAhcxBE9/b3hrvmpSlWE4U3Z/g/aUU99fiadOpPOnxwH8idfeUQgIU8bqzazxrSeFRGNG alf4378AeoG+OcW9NVJGuq1GHLwmWRJxMgzLAfittocF2/0iblL8p0RuFob72caiAgWzTe vljv8HvdmF0P8ai+ks8xDe3Uen3MkR+Rqvjt4n2eaW02JfrravfS1oXYfhW34OLTBAW1qh n9MVEkTbCO32xle2hYumBa4MG5pKASUcwx4zlQVFiwQl9CPP1W3yYx3YGpTzLIN2Mbpdku nMDooxFYl7/osza6cciV7bHmRz77AjznV9QML/dtzP8trnkRuHj1SyvfKLiUdQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697135755; 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: in-reply-to:in-reply-to:references:references; bh=L2nIrcLmRRoEjLnrmI7Wbsm+A7PZaXBdayO8FQILJ/I=; b=ZbQ8yM0JkoLuCuwKcVBbqPLSM1sxlTALMnKV+PBDIm/MFWrHZswaM4q4jOatxxeCiaRcIY YDVCunJsb/Zs9/AA== From: "tip-bot2 for Oleg Nesterov" 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: Change __seqprop() to return the function pointer Cc: Oleg Nesterov , Ingo Molnar , Peter Zijlstra , Waiman Long , Will Deacon , Thomas Gleixner , Linus Torvalds , "Paul E. McKenney" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231012143227.GA16143@redhat.com> References: <20231012143227.GA16143@redhat.com> MIME-Version: 1.0 Message-ID: <169713575405.3135.4365014722583581048.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]); Thu, 12 Oct 2023 11:36:23 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779575854226022571 X-GMAIL-MSGID: 1779575854226022571 The following commit has been merged into the locking/core branch of tip: Commit-ID: e6115c6f7a0ce3388cc60b69a284facf78b5dbfd Gitweb: https://git.kernel.org/tip/e6115c6f7a0ce3388cc60b69a284facf78b5dbfd Author: Oleg Nesterov AuthorDate: Thu, 12 Oct 2023 16:32:27 +02:00 Committer: Ingo Molnar CommitterDate: Thu, 12 Oct 2023 20:18:21 +02:00 locking/seqlock: Change __seqprop() to return the function pointer This simplifies the macro and makes it easy to add the new seqprop's with 2 or more args. Plus this way we do not lose the type info, the (void*) type cast is no longer needed. And the latter reveals the problem: a lot of seqcount_t helpers pass the "const seqcount_t *s" argument to __seqprop_ptr(seqcount_t *s) but (before this patch) "(void *)(s)" masked the problem. So this patch changes __seqprop_ptr() and __seqprop_##lockname##_ptr() to accept the "const LOCKNAME *s" argument. This is not nice either, they need to drop the constness on return because these helpers are used by both the readers and writers, but at least it is clear what's going on. Signed-off-by: Oleg Nesterov Signed-off-by: Ingo Molnar Cc: Peter Zijlstra Cc: Waiman Long Cc: Will Deacon Cc: Thomas Gleixner Cc: Linus Torvalds Cc: Paul E. McKenney Link: https://lore.kernel.org/r/20231012143227.GA16143@redhat.com --- include/linux/seqlock.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 7e7109d..4b8dcd3 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -200,9 +200,9 @@ typedef struct seqcount_##lockname { \ } seqcount_##lockname##_t; \ \ static __always_inline seqcount_t * \ -__seqprop_##lockname##_ptr(seqcount_##lockname##_t *s) \ +__seqprop_##lockname##_ptr(const seqcount_##lockname##_t *s) \ { \ - return &s->seqcount; \ + return (void *)&s->seqcount; /* drop const */ \ } \ \ static __always_inline unsigned \ @@ -247,9 +247,9 @@ __seqprop_##lockname##_assert(const seqcount_##lockname##_t *s) \ * __seqprop() for seqcount_t */ -static inline seqcount_t *__seqprop_ptr(seqcount_t *s) +static inline seqcount_t *__seqprop_ptr(const seqcount_t *s) { - return s; + return (void *)s; /* drop const */ } static inline unsigned __seqprop_sequence(const seqcount_t *s) @@ -292,19 +292,19 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) #define SEQCNT_WW_MUTEX_ZERO(name, lock) SEQCOUNT_LOCKNAME_ZERO(name, lock) #define __seqprop_case(s, lockname, prop) \ - seqcount_##lockname##_t: __seqprop_##lockname##_##prop((void *)(s)) + seqcount_##lockname##_t: __seqprop_##lockname##_##prop #define __seqprop(s, prop) _Generic(*(s), \ - seqcount_t: __seqprop_##prop((void *)(s)), \ + seqcount_t: __seqprop_##prop, \ __seqprop_case((s), raw_spinlock, prop), \ __seqprop_case((s), spinlock, prop), \ __seqprop_case((s), rwlock, prop), \ __seqprop_case((s), mutex, prop)) -#define seqprop_ptr(s) __seqprop(s, ptr) -#define seqprop_sequence(s) __seqprop(s, sequence) -#define seqprop_preemptible(s) __seqprop(s, preemptible) -#define seqprop_assert(s) __seqprop(s, assert) +#define seqprop_ptr(s) __seqprop(s, 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) /** * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier