Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp348426rdf; Fri, 3 Nov 2023 02:31:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOP4mAMDItCitMigUx/f54N+Xck/2X7k4tzQS95v0HsCjiXC+dq6RiLBH670Hj+0T7pMEx X-Received: by 2002:a05:6359:3085:b0:168:d283:ffb5 with SMTP id rg5-20020a056359308500b00168d283ffb5mr11055926rwb.9.1699003897547; Fri, 03 Nov 2023 02:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699003897; cv=none; d=google.com; s=arc-20160816; b=A7pp9fzjXCnln2J4YOuWvlRFDczTQHijXIQrtb6O9uHgYOMq0qFxgkKH1eK0IiGIkT 789qZGOBuhWvSz0QR10H973HZhk1SVa+PfopvaxvMzdb2zqPleDxQ2wYRgjSZxI6aT/V Q2fJovnEvkGbItJQIooLF0DQqdeJn8Qlelh41G0iV+vuVzSy/TsKv3rdL5ZjzPYiZ4UI RSrDXZvl5nYM0XkKaTFPF/0RhgeR/2T9b4gn5r3wsSKlY0fYmlE9YYmN9XFTjXfYCUT5 wuwyV1kY9zRRB00p36p1Hou+Rbqrkd9i/lKHTu19JoncQ+dBkBoXfNfyvI7gwaCclG8Q 4nZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OucduKe3do9JjkGIoFVFJ8LJOWYEah2/DkTkX62AbB8=; fh=C7yqEzcI5kWdyjcFjcLS6VRRuRpPp5h17KpFelfkmQo=; b=RlzZR1HIE0se2pVN2zKeVLn4ZVZUPtfu7ByoAJN6Dba/nEJbf+cdV+2qA6T+u3zR4M 3oIlidNA6nehOaLJaMfbafnZnjP7Wy65CKT6JIf5x6rA94VvfeoaVIRwVharYm3gUENV drDwYbL9SokK+KB+9hODNMdhkQm0nBfVsQWWHWQqYwpogcNwproD/n5SoEKf8vmS6SP0 uiS7evendAuwMgOe/0dzALVEbq5YSqx7apbp3+McU3dcLoQ+tX0czQyfwzWmivp6nTjF QrRwFd3gBxe4FptfK73QcRYu2xXYVG5WPW7KGaIpbaleyK9xjS06yYay7oxaXawnMVHE kTOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="Bqq/p3sF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b69-20020a633448000000b005bd0f2c2671si1203251pga.626.2023.11.03.02.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 02:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="Bqq/p3sF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 643CF8092D91; Fri, 3 Nov 2023 02:30:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347141AbjKCJaj (ORCPT + 99 others); Fri, 3 Nov 2023 05:30:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347134AbjKCJah (ORCPT ); Fri, 3 Nov 2023 05:30:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93C8AD46 for ; Fri, 3 Nov 2023 02:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=OucduKe3do9JjkGIoFVFJ8LJOWYEah2/DkTkX62AbB8=; b=Bqq/p3sFcacB8uurIhbxgJxjqz jtRHAil5rYRvhUFJBhuxv3+d8VitU7VclnXK69WgvqPC8PBhDzB8O+0Vtqfy3qcapmdXOqvYR4lI9 tqyoSPIZ3yRPZzOmdLaoVNyDqUjZSnOKKAiuB3L0ppOjqFFJYZSE6EwLMpnNDGJIEtDPvpBlIPLDb CgMdVrD0/WMShyUXMVHMelfWL6n70EuZ644bGcPjdJbg/g5zzGfizQsDBlA31zPgsmO/bPd6vQmPm qoNq9ROYCOHNnyrTo9W2EUjbR9Hu1W64PqA37qeC4HsvIclisEP4uXuQ9q1ri/bFZVGzXXt5e51QC Vd6g8HYg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qyqVT-004and-5C; Fri, 03 Nov 2023 09:30:23 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 831E130027B; Fri, 3 Nov 2023 10:30:23 +0100 (CET) Date: Fri, 3 Nov 2023 10:30:23 +0100 From: Peter Zijlstra To: Oleg Nesterov Cc: Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , Greg Kroah-Hartman , Eric Biederman Subject: Re: [PATCH 1/2] cleanup: Add conditional guard support Message-ID: <20231103093023.GA8262@noisy.programming.kicks-ass.net> References: <20231102104429.025835330@infradead.org> <20231102110706.460851167@infradead.org> <20231102144009.GA9680@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231102144009.GA9680@redhat.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 02:30:46 -0700 (PDT) On Thu, Nov 02, 2023 at 03:40:11PM +0100, Oleg Nesterov wrote: > On 11/02, Peter Zijlstra wrote: > > > > include/linux/cleanup.h | 52 ++++++++++++++++++++++++++++++++++++++++++++--- > > interesting... I don't know anything about cleanup.h, will > read this code and the patch later, but I guess I understand > the idea. > > Stupid/offtopic question... Can't we change guard() > > -#define guard(_name) \ > - CLASS(_name, __UNIQUE_ID(guard)) > +#define guard(_name, args...) \ > + CLASS(_name, __UNIQUE_ID(guard))(args) > > and update the current users? > > To me > > guard(rcu); > guard(spinlock, &lock); > > looks better than > > guard(rcu)(); > // doesn't match scoped_guard(spinlock, &lock) > guard(spinlock)(&lock); > > And this will make guard() consistent with scoped_guard(). > > No? Yes (and you're not the only one to have noticed), I think an earlier version actually had that. The current form came about in a fairly long thread with Linus. Most notably here: https://lkml.kernel.org/r/CAHk-%3DwgXN1YxGMUFeuC135aeUvqduF8zJJiZZingzS1Pao5h0A%40mail.gmail.com And I don't actually dislike the current guard form, I've been reading it like: guard(&my_mutex); But that is arguably because I've done a fair few years of C++ systems programming before I got involved with this kernel thing. Also, we use a very similar syntax for the static_call thing: static_call(x86_pmu_enable)(event); That said; if we were to do this, then something like: #define __cond_guard(_name, _inst, _fail, args...) \ CLASS(_name, _inst)(args); \ if (!__guard_ptr(_name)(&_inst)) _fail #define cond_guard(_name, _fail, args...) \ __cond_guard(_name, __UNIQUE_ID(guard), _fail, args) cond_guard(spinlock_try, return -EBUSY, &my_lock); Becomes possible. Linus, do you like that enough to suffer a flag day patch as proposed by Oleg?