Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2845701rwd; Fri, 26 May 2023 12:08:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63h2YerqRZfGCqH2/B6hiSYplBlSmfUTcgNa/xrVV4Wi40IS3CYNWUEz3+YEMKRLCOMuEI X-Received: by 2002:a05:6a20:441f:b0:10a:dafc:aef5 with SMTP id ce31-20020a056a20441f00b0010adafcaef5mr494004pzb.34.1685128095056; Fri, 26 May 2023 12:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685128095; cv=none; d=google.com; s=arc-20160816; b=zolqxl3XHOLP2BihtolrcEX7IwljHjZWQQrjlCHogcYoJdEeuPs91uzZYiQOrlHBkv gz3IdZyhT3FcLwA8XOslJUz4D01FYevGBmxLpV0RwfseD7fkrPaHVBvTvSfxN6JUHM42 +mE3kC0hd6qBWg9khzgllpxOuls2QaVEW7EP+w7UcLoozvSgbR8kChI9GSEbZyswOJM4 9hS3oEo2iQbF67fD1mY2eP/C0RYtTXq+p2gwRUpTkO3vGWsQ8xHgrX1GsFyOmxThtF8x eLzV1MRu6NpD9IqnxOriFwHZapDIfn713rZR/92NiEPWrBDKbh5DildRJGsK1FyYF5lH DC5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=l9gW2VXa2A5baAgf65KnUVTdVX+nM4KBjAb0pb4V13g=; b=ErS9XafjwQbgmSQ9IbmaUabQ+iVU1yjocRbIJxSNTFPzAtsFsw3/XfeQeeBmCwJt2H 8HxzMrixqngVfihJ32kzTh+RNhJVuzwiJNmK4pGoCRjyCE6UWAQ5ewiHjoQVxE/eywY8 5AmESxhCq9N1k6VWKmwPu23nYy6jNKdmwfx5K9J1Zrnycg0JDD5lXpsOppqh3OlOgZfh 5m4Rf8Gog5CiD+VNLKGsIocaOiKNuOWvjW0WxHc83MNZEE61sn8ZBNG9oMs675+0crVz QRCLHa7NGRr5epe+STbsGtnjGpBV+bhJuPJMGQSjTtgLd/AZG2RrNuOJ9RuFrv3ZZ/F4 6TYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PZ6ay2nc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bu17-20020a632951000000b005346d98e74asi4067189pgb.36.2023.05.26.12.08.02; Fri, 26 May 2023 12:08:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PZ6ay2nc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233433AbjEZSua (ORCPT + 99 others); Fri, 26 May 2023 14:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230064AbjEZSu3 (ORCPT ); Fri, 26 May 2023 14:50:29 -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 D736A13D for ; Fri, 26 May 2023 11:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685126979; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l9gW2VXa2A5baAgf65KnUVTdVX+nM4KBjAb0pb4V13g=; b=PZ6ay2ncrJ71tWI+Cj5VLMxaSb2PGJJuGsCafrPDbAXO7zscagrZz3Se9RHVvweQEukI5s PFRx3drjun39obDmf+6SZD5qu2VFjHmu3o7kpEsVkVUn3gJOaJARYVCpziQ6VfUkLBwya2 dYZqQq70EmbcEJ1bK5G3lTfggl+5CwI= 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-498-Cu3RT8TzMue2tp8jbuO0pg-1; Fri, 26 May 2023 14:49:37 -0400 X-MC-Unique: Cu3RT8TzMue2tp8jbuO0pg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 23081101A52C; Fri, 26 May 2023 18:49:36 +0000 (UTC) Received: from [10.22.32.123] (unknown [10.22.32.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87B37492B00; Fri, 26 May 2023 18:49:34 +0000 (UTC) Message-ID: Date: Fri, 26 May 2023 14:49:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [RFC][PATCH 1/2] locking: Introduce __cleanup__ based guards Content-Language: en-US To: Peter Zijlstra , torvalds@linux-foundation.org, keescook@chromium.org, gregkh@linuxfoundation.org, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, ojeda@kernel.org, ndesaulniers@google.com, mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, paulmck@kernel.org, frederic@kernel.org, quic_neeraju@quicinc.com, joel@joelfernandes.org, josh@joshtriplett.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, qiang1.zhang@intel.com, rcu@vger.kernel.org, tj@kernel.org, tglx@linutronix.de References: <20230526150549.250372621@infradead.org> <20230526151946.960406324@infradead.org> From: Waiman Long In-Reply-To: <20230526151946.960406324@infradead.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/26/23 11:05, Peter Zijlstra wrote: > Use __attribute__((__cleanup__(func))) to buid various guards: > > - ptr_guard() > - void_guard() / void_scope() > - lock_guard() / lock_scope() > - double_lock_guard() / double_lock_scope() > > Where the _guard thingies are variables with scope-based cleanup and > the _scope thingies are basically do-once for-loops with the same. > > The CPP is rather impenetrable -- but I'll attempt to write proper > comments if/when people think this is worth pursuing. > > Actual usage in the next patch > > Signed-off-by: Peter Zijlstra (Intel) > --- > include/linux/compiler_attributes.h | 2 > include/linux/irqflags.h | 7 ++ > include/linux/guards.h | 118 ++++++++++++++++++++++++++++++++++++ > include/linux/mutex.h | 5 + > include/linux/preempt.h | 4 + > include/linux/rcupdate.h | 3 > include/linux/sched/task.h | 2 > include/linux/spinlock.h | 23 +++++++ > 8 files changed, 164 insertions(+) That is an interesting idea and may help to simplify some of the common code patterns that we have in the kernel. The macros are a bit hard to read and understand though I thought I got a rough idea of what they are trying to do. BTW, do we have a use case for double_lock_guard/double_lock_scope? I can envision a nested lock_scope inside a lock_scope, but taking 2 auto locks of the same type at init time and then unlock them at exit just doesn't make sense to me. Cheers, Longman