Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp670617rdf; Fri, 3 Nov 2023 11:18:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCDzm+OpLJK3hCLYQjE+G3L04kBSmWQG7QA09UHmSIsnqU+M7Ph1atwIlZeCCI8ypgVpa7 X-Received: by 2002:a05:6358:3406:b0:168:d2b5:db9 with SMTP id h6-20020a056358340600b00168d2b50db9mr25906214rwd.6.1699035484371; Fri, 03 Nov 2023 11:18:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699035484; cv=none; d=google.com; s=arc-20160816; b=dU7fP4dNolDzZKIssao3uCp3YCizmgpyNNxSS4xyokfqAqEguqPhz3TaI3l2f2Z34i 6LbAsreiTME2j9IulRAygcigJ5elSUUkc5BRAYYcEaHt5iGZoLZo9Y7WUxOmEAPFkR++ SyCRIL+FKB4cunjd/0W7mTcmId0bG2pBwuK0NKIFx0xASmAstMFL8LP7AF+Vm/5Y+beX l5SzBOAZqiCHRTX9mbkybRwYIVDT7oVh5DyMVIKU5Ny44ptSd4xB5zL2hw34whwbSA8U micKBL6xVwQH5nm3SEKUqoTYqObIfZlZI/Rrjelntsu+qTse8SFBCuUcE9TDZgchok4z L7/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3y5T7cq892SnU83dYVfN20NJ59cVSzusXtbdmjUBa/c=; fh=CxQygqbhPGomH6vFqZcaaBxpY/uv0Gkw2oKIZBHdmjo=; b=tbLCdC7GAhe88DOz/JqNIdT+S4d9wZTXhYoF89zu43Kx0LvbI3cbZDzcvEnq1A301L /bM+TIBTMaa9Nu/URizc5dJSXyiEaa65aGrO0JfiReFrpl1RDAmkclQoIrmnbW9cB+6u CjfpJVLyPTM+E2FLBMQ1btcXUrkS0swYrUdPFWKIdxOFDtYZpXoPuEMcmFTDxtfiPmg8 AT/Xq/LjEEjbqJ4XcIe2kNbYDGm92JPbF5ezfjQd7VivOP3lJDnNr5VJ7pVaZzh1n2NU Lj8W7kRjfDt1tFrHbLr7qKgcWRf8/ss+Vh4+z6YAMJx6l9DhWfhzLL4t7UK+wv/3wtyo nL6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OK0C+0hb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 78-20020a630151000000b005895c80c902si1898551pgb.438.2023.11.03.11.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 11:18:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OK0C+0hb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id D23E18062939; Fri, 3 Nov 2023 11:17:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbjKCSR3 (ORCPT + 99 others); Fri, 3 Nov 2023 14:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjKCSR2 (ORCPT ); Fri, 3 Nov 2023 14:17:28 -0400 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C03781B9 for ; Fri, 3 Nov 2023 11:17:21 -0700 (PDT) Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-3580b94ac2eso9765655ab.0 for ; Fri, 03 Nov 2023 11:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1699035441; x=1699640241; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3y5T7cq892SnU83dYVfN20NJ59cVSzusXtbdmjUBa/c=; b=OK0C+0hbKN7I2u+2M84KOE65racriMSTBdXOhjoQROkl4lkXu3squI5fzUDW34+o1S D8Ppz+DMWaaXuJPnn3rJdeWXErsJ3mCSZas80N0/ng8WEGp00PH+tzeKiU4Qbq7nD0J+ rk7wxBBCOoBX1eSSnH22FT6CoE6bXkmeITUVs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699035441; x=1699640241; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3y5T7cq892SnU83dYVfN20NJ59cVSzusXtbdmjUBa/c=; b=m0Ty5gVAffCAbwR+L4GM1Ys40wAOw7hYmSyfa4inxGs4UkohVXIZpdiWIC32mixKVR 8OrV2xNz0/HPS4H5dJs2o9y3wtCI0oGxr9YBhHiUVWquMcp+xlsQXf/NZpXzkrxzg6zF qDq6eX9BIXzcOL+j2WUPu/sJII6F9RmRdN4sNm20bn4ERe0khIzhG+A3CCQB6ARCxhyP 8l6JmCCKJKnI4l/+PNwQaQHxWqjrAKiNXHYxXY9rWF8R54EZqIM/cGmRIDRo6BNQLL0h r3FqT7ufWYnPKxjz6HeoHu5Yk5MxFaTJQt1nL3gEbOOBwoO0EaCBkagBqgDoL4xUjacv Xdhg== X-Gm-Message-State: AOJu0YzURQwy3eOCNMy9nCAm9NXCyGcmG03Fr4ivEBjWJB83UT+REAVT l4ybxETaLTcGFS355JRAdThnJqHGosHENNSZE3O7pase X-Received: by 2002:a05:6e02:320e:b0:359:3ba1:7745 with SMTP id cd14-20020a056e02320e00b003593ba17745mr13630925ilb.0.1699035440965; Fri, 03 Nov 2023 11:17:20 -0700 (PDT) Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com. [209.85.208.43]) by smtp.gmail.com with ESMTPSA id t12-20020a056e02060c00b00357a2b367ccsm704880ils.42.2023.11.03.11.17.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Nov 2023 11:17:20 -0700 (PDT) Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5435336ab0bso3970435a12.1 for ; Fri, 03 Nov 2023 11:17:20 -0700 (PDT) X-Received: by 2002:a17:907:86a7:b0:9dd:bd42:4ec2 with SMTP id qa39-20020a17090786a700b009ddbd424ec2mr673300ejc.10.1699035438864; Fri, 03 Nov 2023 11:17:18 -0700 (PDT) MIME-Version: 1.0 References: <20231102104429.025835330@infradead.org> <20231102110706.460851167@infradead.org> <20231102144009.GA9680@redhat.com> <20231103093023.GA8262@noisy.programming.kicks-ass.net> In-Reply-To: <20231103093023.GA8262@noisy.programming.kicks-ass.net> From: Linus Torvalds Date: Fri, 3 Nov 2023 08:17:01 -1000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] cleanup: Add conditional guard support To: Peter Zijlstra Cc: Oleg Nesterov , x86@kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , Greg Kroah-Hartman , Eric Biederman Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.3 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,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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 11:17:58 -0700 (PDT) On Thu, 2 Nov 2023 at 23:30, Peter Zijlstra wrote: > > On Thu, Nov 02, 2023 at 03:40:11PM +0100, Oleg Nesterov wrote: > > > > 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(). [...] > 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? I don't find myself caring too much whether we have that "double grouping" of the guard type-vs-arguments or the "(type, arg...)" syntax. I honestly think that "guard(spinlock)(&lock)" makes it more visually obvious that the first argument is the "type of guard", while "guard(spinlock, &lock)" makes it look like the two arguments are somehow at the same level, which they most definitely aren't. But I also can't find it in myself to care too much about something that is so purely syntactic, and that I suspect should be abstracted away anyway to just become "guard_spinlock(&lock)" with a trivial helper macro. Linus