Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp381233rdb; Thu, 15 Feb 2024 03:10:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX1dR6xuvO/0Io5wgHktYdoEywbHK88xWXOT0aLjPO39fgfCYkdCvUlq6jWUJ8kmi+12kSnBev69wsM19A1WPSO0RmCEAcgirnhbAYahw== X-Google-Smtp-Source: AGHT+IHBhliLqc84Bwbu4V2rmWDdzry8y03HLODuIUmPeQ1GDzI2efJkz3UF1M21vIirAkgC1753 X-Received: by 2002:a05:6a20:9f91:b0:19e:b614:48ad with SMTP id mm17-20020a056a209f9100b0019eb61448admr1713336pzb.5.1707995438045; Thu, 15 Feb 2024 03:10:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707995438; cv=pass; d=google.com; s=arc-20160816; b=t5qV/2xBvjUX1tiafRA69AtL8jyD7yPOvOAGg9R9r06/1RGuWKkc2LtsofnUW3Ue4I x0gqagDF6U95wQqsr0alOLxK8rCWSdOrSf1EFwgbGqjqZxQczrAe2KKubAlsshe/A47D /ev9nVOKNwuY+j8xeaK8UAtn0tubqmG1rSnP5EAMOq4gjV0GelRjTA71roKsYdYZMRHb XdJsMu+8YsnMPVJviVfue14Y/K65wlbd9/l9LTrJKU+/Ji4w7JGfKcBCkVfjC86FxEKY kQdfogpZvUsD2vLK4DbtcODi6EMJ+GTv9S/uk/lwEVfJo3jRKkPmYlljtJt4+qER4RS1 AoWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=5LVeLymegYgxILtAkfkT6E2OB5IaK7mPf2jV1OaYOpw=; fh=1fBYa+8Pml540vLlrdjBsXlvSPmHDDPa+wyK108iM94=; b=DmUT5e496TQTs/y7APfBbkDhY0wkd+EXAATOAxvWWYXIeUYzpScGQyElXsP9IqupLq P3hjuqd7iLLiTCe4Zbj9j39Q3S27USkG50YtgIfsM2YZqz0EO8x15Qfj+EZzsnt7ItgC jom1uhMfsPuwe8/PRadddXh1G1v/WIt0cb2EfZJnxMbpDc3gS9uzZ7blQ8iJUBirU7/7 Ph6bTJfu0m8rvhw7Gxr0yvlXkAWTBoY8jwVNLzd1FP6HHMBw51rvR69gt/vtqr6a5NnV gkw8J3zw+u1etU5nv2uLYfnrAfB++sCb67UKjF0JVfaViBs40ZIDx8/iA14n2JHwnS62 weUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-66624-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66624-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s18-20020aa78d52000000b006e0381a4a95si931620pfe.402.2024.02.15.03.10.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 03:10:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66624-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-66624-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66624-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DA55CB2E60C for ; Thu, 15 Feb 2024 10:27:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6E9A69D1E; Thu, 15 Feb 2024 10:26:49 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7949C69D05; Thu, 15 Feb 2024 10:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707992809; cv=none; b=GhccxBjcCAHNBHiDYuHSr19hfEdVLc+fsqdDj8KfVDp5F7todqPXb3/kv/v+4mRAUnFPJY1lAGbUwLRqyRbrhuBD7U6MMkQrWzmxSmkhu0hImCHuccAo4dhZ6LojqE0DvxxAOh8rRhGUNRXQkzDR7G4JS8UUkeZf5PsAgSXLBgQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707992809; c=relaxed/simple; bh=20qbWw4eZocIiRgqnsx02KAsr2J5ezEMIV7F1eRgzYQ=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VAuhYccRmQzHWyZeCZ/DHqI+x4WovnP0S/QqJFGKxgvevA4a5FrWg0dxSIN1h/DCkA2pP7O4pso8jdG0GojCSyu7Gw7maUQZewOmaLTSXl7otYoflO+iDozd4oXXXmjIUINikfkFnnI5YtrMjW1/uIA+7m7FFuCVrYB6hKLlwgw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TbB3S0L7Qz67Ldy; Thu, 15 Feb 2024 18:23:16 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 8A0221400D4; Thu, 15 Feb 2024 18:26:43 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 15 Feb 2024 10:26:43 +0000 Date: Thu, 15 Feb 2024 10:26:42 +0000 From: Jonathan Cameron To: "Fabio M. De Francesco" CC: Peter Zijlstra , Dan Williams , , , Ingo Molnar , Dave Jiang , Ira Weiny Subject: Re: [PATCH 1/2 v4] cleanup: Add cond_guard() to conditional guards Message-ID: <20240215102642.000067c5@Huawei.com> In-Reply-To: <20240214180452.00000974@Huawei.com> References: <20240208130424.59568-1-fabio.maria.de.francesco@linux.intel.com> <20240208130424.59568-2-fabio.maria.de.francesco@linux.intel.com> <3917370.kQq0lBPeGt@fdefranc-mobl3> <20240214180452.00000974@Huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500005.china.huawei.com (7.191.163.240) On Wed, 14 Feb 2024 18:04:52 +0000 Jonathan Cameron wrote: > On Tue, 13 Feb 2024 17:51:26 +0100 > "Fabio M. De Francesco" wrote: > > > On Thursday, 8 February 2024 14:04:23 CET Fabio M. De Francesco wrote: > > > Add cond_guard() macro to conditional guards. > > > > > > cond_guard() is a guard to be used with the conditional variants of locks, > > > like down_read_trylock() or mutex_lock_interruptible(). > > > > > > It takes a statement (or statement-expression) that is passed as its > > > second argument. That statement (or statement-expression) is executed if > > > waiting for a lock is interrupted or if a _trylock() fails in case of > > > contention. > > > > > > Usage example: > > > > > > cond_guard(mutex_intr, return -EINTR, &mutex); > > > > > > Consistent with other usage of _guard(), locks are unlocked at the exit of > > > the scope where cond_guard() is called. > > > > > [snip] > > > > > > +#define cond_guard(_name, _fail, args...) \ > > > + CLASS(_name, scope)(args); \ > > > + if (!__guard_ptr(_name)(&scope)) _fail; \ > > > + else { } > > > + > > > > I have converted and tested several functions in drivers/cxl and found that > > there are cases where this macro needs to be called twice in the same scope. > > > > The current implementation fails to compile because any subsequent call to > > cond_guard() redefines "scope". > > > > I have a solution for this, which is to instantiate a differently named > > variable each time cond_guard() is used: > > > > #define __UNIQUE_LINE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__) > > #define cond_guard(_name, _fail, args...) \ > > CLASS(_name, __UNIQUE_LINE_ID(scope))(args); \ > > if (!__guard_ptr(_name)(&__UNIQUE_LINE_ID(scope))) _fail; \ > > else { } > > > > But, before sending v5, I think it's best to wait for comments from those with > > more experience than me. > > Ah. So you can't use __UNIQUE_ID as guard does because we need it to be stable > across the two uses. What you have looks fine to me. > We might end up with someone putting multiple calls in a macro but in my > view anyone doing that level of complexity in a macro is shooting themselves > in the foot. Thought more on this whilst cycling home. Can you use another level of macros in combination with __UNIQUE_ID that guard uses? My skills with macros are very limited so I'm sure I got something wrong, but along the lines of. #define __cond_class(__unique, _name, _fail, args...) \ CLASS(_name, __unique)(args); \ if (!__guard_ptr(_name)(&__unique)) _fail; \ else { } #define cond_class(_name, _fail, args... ) \ __cond_class(__UNIQUE_ID(guard), _name, _fail, args... ? > > Jonathan > > > > > > Fabio > > > > > > > > > >