Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp353969rdg; Thu, 12 Oct 2023 07:34:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGR6/PfH2bNKKiQySIQ+XiDiZVX5vA3EvC5cjN9S1nRPkd2vdPLOhIT6ldGGgWYubt8RWvE X-Received: by 2002:a05:6870:ad08:b0:1e9:8d44:a5cf with SMTP id nt8-20020a056870ad0800b001e98d44a5cfmr5674161oab.17.1697121277635; Thu, 12 Oct 2023 07:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697121277; cv=none; d=google.com; s=arc-20160816; b=gz3rXJ4iUa//eRRf1X4smkFMAZRKZwU7VPIFNkXQt7WzdG1Qqy6QvCybQ6VFsjlrtq s9p38fP8un2WjycIrcn5OWDBW9bS+hUwlQ4np4M6MJw9ljln1FKhXo+DlWu9rEyrOI7n FocDL8ZOi68vh7oPELFAJwdEVci+wHV39RksCsClMKXQ93n5a6oYEenObp0u32Sd66+w KVnrcaJ069TIMFVDOVIM2xMsrqX096WrS3LjzgCk0QXNEL1+CWWt7tcoAjfyarmgqCno bhXTkNqlV/fwAn/3IRZW6w/cP3AexJj0RPPDZoBT9+bN02W3PZHP+OIOC/cZ3ssJtfIf oFqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kjD/zSOLO+IWRgc+ciy7+kba7RJqZ7Ml7ojDfBUl9Rg=; fh=9Anu/xS0FThiK+xJgFxROatCrv9gNGrU8+NgNF+Jvyg=; b=WhuOnZtMKnZ2dEHUQkN718aplz9ciTjUHerNIR0xZSFSZjW4hiAj0uIlolPtRi4b7P TrlFYCOG0n6YTRUWc7uxiFfpjW0pYZnFKKnp1S+IfNaorePvvJNNcNZhFLt22r7Y0II8 F8A3LULnB3U37FjvH+Abms3rdu2VF8cn0L2feDDu8WU4+XIMmGzUQjBVyFUtnaiusrn7 0H9GTYxqjtqniFoM0hmEoa52TfGt2+vGyDlgtQjsW09fGDXPbDb8JXPYoUq/ruoX7rcF z8TrvbYib41eKYaDEfSaFCDKl5ZYc1OpOzqG5ZeoHxPl2dudj6UaWNXuja8Ua2OAm92F RZoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fXv98M3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ca23-20020a056a02069700b0057759a5b7dasi2828947pgb.827.2023.10.12.07.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 07:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fXv98M3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A6E3A8245A76; Thu, 12 Oct 2023 07:34:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233260AbjJLOeX (ORCPT + 99 others); Thu, 12 Oct 2023 10:34:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231750AbjJLOeV (ORCPT ); Thu, 12 Oct 2023 10:34:21 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D4FCC for ; Thu, 12 Oct 2023 07:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697121214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kjD/zSOLO+IWRgc+ciy7+kba7RJqZ7Ml7ojDfBUl9Rg=; b=fXv98M3IIJS7joIIh7QDd5AQn4bAORIjDCR5JQl3fts3AITH4XciiPCe2i5OF+HsyPHnY0 03g8+OkeyObpZRWSYdCsXCW4pXmXv3IdBQhTLPSPACDKi91BWUHefrWr/dyeU9vqwQRzsd jZEeC0fLYjp9yXJgGZ5GxdQlAd4cW/U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-362-2YdBp-vTNZaiNHZmPowIJw-1; Thu, 12 Oct 2023 10:33:29 -0400 X-MC-Unique: 2YdBp-vTNZaiNHZmPowIJw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 626538DBAEE; Thu, 12 Oct 2023 14:33:29 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.172]) by smtp.corp.redhat.com (Postfix) with SMTP id 9D7951C060DF; Thu, 12 Oct 2023 14:33:27 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 12 Oct 2023 16:32:30 +0200 (CEST) Date: Thu, 12 Oct 2023 16:32:27 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: Alexey Gladkov , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] seqlock: change __seqprop() to return the function pointer Message-ID: <20231012143227.GA16143@redhat.com> References: <20231012143158.GA16133@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012143158.GA16133@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 12 Oct 2023 07:34:34 -0700 (PDT) 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 --- 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 b9a30c62ffe4..bf1435ffe24f 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 -- 2.25.1.362.g51ebf55