Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3412692rdb; Wed, 13 Sep 2023 11:10:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHB9Gpy7kAXQRy1HldK96DJii630J6821pUviZeLTNFXGNfuDhNIc0/4DOwaQuyqC1Yrkcu X-Received: by 2002:a05:6a20:3c8a:b0:10f:be0:4dce with SMTP id b10-20020a056a203c8a00b0010f0be04dcemr3803008pzj.8.1694628635125; Wed, 13 Sep 2023 11:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694628635; cv=none; d=google.com; s=arc-20160816; b=sWzixaPc9+Zw8PWFfU7rDgYLo49ejifWlD+4TvJHXZuoP7qeBFQ18ULwEJJ+ElO1fR n5IKXY5zZkq12lpMUhEzwjQ560fTP6mrf+UuyRIC8oLl+8W60ynD7EJ0DlMvicOCIMws bMewJJ9O7UNi+s7XqMNkkO1Qvpmg3NsJA24n1aDj6MexoSCXXdQqDfvuuonS9tvvfma3 hLOU9l5p+ycb1QTsGaYJe4cJg8XBYqJwQyOl/lk7NCXpvGxeecJMjzGQnF/aBpUMa8wA og7Uv/CgFK4zqqJ/rSqu5crpiArOYyDUZPVTtwdwScZzmE/DUQU/IhODTbTmusMUiLP+ FdMw== 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:message-id:subject:cc:to:from:date:dkim-signature; bh=iABk60dwatWobxRjc3Fair6PpujlXQNgr6XGkMBYTOU=; fh=UgBAXmnivFk7kQi7sQlRYuWmRxo2ocd12zIZQ50jSes=; b=ft3cT5hYhOULI9mF9iVpR5Slua0KQt8524JjyC7zvHtkgBlAihHJLYWks8Hx+08BaT mDiGQqQwOSIXR0eoGzaTe9bwRA1ezk8pTY11erkgGxC7hrg9AbG+EQnvXec2EodQMfW+ f2P+ncTwSJb7mxn4yv0Q9/RhS0N7GPXoTbdtmASz6theH6JaxxTA4DwZuBDShhev/e2/ S42L0FsTmAikblI5ixpzSoM4dA166oLqHj4N8GmKfVMIahdfAVDC9zbizdsOevD0f/jK 8imTwh/+DO7gjW34nZZotuDdgbCJpcl1c/fs7+JPQQjqNtGFDRGemV+uOLCgXSIoxZA7 t1DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dA22QlWS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t13-20020a056a00138d00b0068ff659af62si3055692pfg.106.2023.09.13.11.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 11:10:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dA22QlWS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 56BC582E1E0C; Wed, 13 Sep 2023 08:51:56 -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 S230014AbjIMPvx (ORCPT + 99 others); Wed, 13 Sep 2023 11:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjIMPvt (ORCPT ); Wed, 13 Sep 2023 11:51:49 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E0AFECCD for ; Wed, 13 Sep 2023 08:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694620261; 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; bh=iABk60dwatWobxRjc3Fair6PpujlXQNgr6XGkMBYTOU=; b=dA22QlWSDsjKlU1e1MJ5CdNu1aTK12NJ/aAIyJy+ZcKpFUFYs29D0oWr+VHLP9guZST684 o3AeYann9ipLbmVOT0QOMzfM0zzs4I9j1NvOJ/m6U8xTK6UiZZ0J6mh/7rzFKXIWKSVeWF oyn1p9CzHQouGBzdbvzNlXwyLLg2zKs= 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-661-X13l6M4sMwm8QOibNTuw-A-1; Wed, 13 Sep 2023 11:50:57 -0400 X-MC-Unique: X13l6M4sMwm8QOibNTuw-A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 D423981652F; Wed, 13 Sep 2023 15:50:56 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.76]) by smtp.corp.redhat.com (Postfix) with SMTP id 5E22810F1BE7; Wed, 13 Sep 2023 15:50:54 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 13 Sep 2023 17:50:04 +0200 (CEST) Date: Wed, 13 Sep 2023 17:50:00 +0200 From: Oleg Nesterov To: Boqun Feng , Ingo Molnar , Peter Zijlstra , Rik van Riel , Thomas Gleixner , Waiman Long , Will Deacon Cc: Alexey Gladkov , "Eric W. Biederman" , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] seqlock: introduce seqprop_lock/unlock Message-ID: <20230913155000.GA26248@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230913154907.GA26210@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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]); Wed, 13 Sep 2023 08:51:56 -0700 (PDT) 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 pete.vger.email which can be used to take/release the corresponding lock. Thanks to the previous patch, it is trivial to pass 2 arguments to the new __seqprop_##lockname##_lock/unlock "methods", plus we do not loose the type info and thus the new seqprop's are "type safe". So for example void func(seqcount_rwlock_t *s, rwlock_t *l) { seqprop_lock(s, l); } happily compiles, but this one void func(seqcount_rwlock_t *s, spinlock_t *l) { seqprop_lock(s, l); } doesn't. Signed-off-by: Oleg Nesterov --- include/linux/seqlock.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index 41e36f8afad4..9831683a0102 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -241,6 +241,21 @@ static __always_inline void \ __seqprop_##lockname##_assert(const seqcount_##lockname##_t *s) \ { \ __SEQ_LOCK(lockdep_assert_held(s->lock)); \ +} \ + \ +static __always_inline void \ +__seqprop_##lockname##_lock(seqcount_##lockname##_t *s, \ + locktype *lock) \ +{ \ + __SEQ_LOCK(WARN_ON_ONCE(s->lock != lock)); \ + lockbase##_lock(lock); \ +} \ + \ +static __always_inline void \ +__seqprop_##lockname##_unlock(seqcount_##lockname##_t *s, \ + locktype *lock) \ +{ \ + lockbase##_unlock(lock); \ } /* @@ -306,6 +321,12 @@ SEQCOUNT_LOCKNAME(mutex, struct mutex, true, mutex) #define seqprop_preemptible(s) __seqprop(s, preemptible)(s) #define seqprop_assert(s) __seqprop(s, assert)(s) +/* seqcount_t doesn't have these methods */ +static inline void __seqprop_lock (seqcount_t *s, void *l) { BUILD_BUG(); } +static inline void __seqprop_unlock (seqcount_t *s, void *l) { BUILD_BUG(); } +#define seqprop_lock(s, l) __seqprop(s, lock)(s, l) +#define seqprop_unlock(s, l) __seqprop(s, unlock)(s, l) + /** * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier * @s: Pointer to seqcount_t or any of the seqcount_LOCKNAME_t variants -- 2.25.1.362.g51ebf55