Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp759394rdh; Wed, 14 Feb 2024 10:25:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVF8gEk/ipn9bVM7gciWYcmv6+SFuNH9lc1LOmGKYIz8uL0sCR1xJZQ3YLww0gSftWZ92/KDBrdwSH+vaqo7OwTQl10UUkY0f2+JTtQCQ== X-Google-Smtp-Source: AGHT+IG+DsQk/ABUlwhluWNRXCzsxHpVQy7MBT4LPPXAV8HFB0mTrZ69ubFVGpqEODmoNOmh5Qrw X-Received: by 2002:a17:902:da81:b0:1d9:8bb5:7497 with SMTP id j1-20020a170902da8100b001d98bb57497mr4562068plx.40.1707935106571; Wed, 14 Feb 2024 10:25:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707935106; cv=pass; d=google.com; s=arc-20160816; b=Hxwp2y/5LzhnpIIauInP3++LUTq81YLtuVpHXTLEWN0SAAKH8LkoLyD+SBqzCeT+mR YZmUA68nbuAO6GxQa5AlZtDMM241uaWKvN77hn94feeNxF5aPLb7YcR2nnkiSXjUudtD Xp4LG/CBmKV1cnuIbSUZDbw8ugc2HQd7Ygs5BYbUC/wBAXeeETx0q6Pg0P26Tk0r8z0u QEVJPeaFZ9aQmRS4/4mpEYRgz1ETduh3crCWZYobge5APcFjEUYq0pOBNJUuewYE7/hr +yKC0mPlMVSgmCdKegpEiehyRo4HEm0laoq0VQh4PH5Z7oQaxpXvru9/cgss8ty/aTd+ 6IOw== 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=TJnighzG+mM2S+bLCvA/A4inws9XM/af7xYG6X3HnzY=; fh=iknCbVSnPMFjrdtfEMLDVBPHToW+vNadddORNTPFqRY=; b=mUxvhSnwGdkWJ0Ke83QPIWBxGuk9JC4iOJSYAukajoYVnYSI6Ck+RRPI2kpM3KLWB1 GGKnmA6RZ4Tb3XDnhKELpJOVDo6sQ6zMPEsW30JQSOWrV/leyg+/e9pG7x01PKHm8JIC PBxNtn2xgPfI4sY1UZ1V9lgkpZ/uYvHU5bBbytkwSsWDqkSz8lbMXZTnX9McfZ2+owxB aXu+2ttVxBBioSxYSUjyH/qH8FuJeCIO5lHjTLxXbm1yp6If9bP00eR9M6ZPatMzsgZq fMnsoe1AY7Or9UTa1dseDZN+j59IL6gxKhTqTa3hbDahsZbRy2xigak8a+UeOGxVGQpw KdgA==; 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-65774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65774-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=2; AJvYcCUyPlnUYTamu8O3pjTSAGixs+c/v8Z0oUVyvoYiGGKjZ6j4vAZdR8I+6uNoRePf0ezAz96oX1zGEHPPfihVHXtTwMGWyju5+EeFKnb0sA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h5-20020a170902f70500b001db5b4036ecsi1457019plo.86.2024.02.14.10.25.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:25:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-65774-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65774-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 776DF298A54 for ; Wed, 14 Feb 2024 18:10:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 50C9D12DDB2; Wed, 14 Feb 2024 18:04:59 +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 49ACC1292DB; Wed, 14 Feb 2024 18:04:55 +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=1707933898; cv=none; b=XWkFJn0hferKHz8Fc1bZpG6bY8R5PISVRdwTUiOkTQWvdKTi8RSuN55BtAhT9B6s9ahvcxYB7J9lxFXOEXZgSUb3NMKni4PgRc4nJ5DAryBgBKOUWydAAIExPqHRB2lXZPVzWu5qlpqNzRYZDybREKGeySh/Xq67+XKrCdlgJt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707933898; c=relaxed/simple; bh=1opVNwI5g0qTfL7RCSwClpE248xDSuhAxDOStvKcVJI=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ez84ekcnLhIFMYy93zPf1jeRt+zJOiWCTtfcko6OLwtZAIzGXaTvoG9AuOc1PGnbutrkSvI4gLN7TFWRebmnu2Hhp52sLtENuqfRNGT25yHGpng6nijAc9xika8Qz53sMF0B1GCekyynKmNmkAkC5Uyj2gW5APNP2Q72z0neyZ8= 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.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TZmFx2cqfz6JB0p; Thu, 15 Feb 2024 02:00:53 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 8034B140682; Thu, 15 Feb 2024 02:04:53 +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; Wed, 14 Feb 2024 18:04:53 +0000 Date: Wed, 14 Feb 2024 18:04:52 +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: <20240214180452.00000974@Huawei.com> In-Reply-To: <3917370.kQq0lBPeGt@fdefranc-mobl3> 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> 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: lhrpeml100002.china.huawei.com (7.191.160.241) To lhrpeml500005.china.huawei.com (7.191.163.240) 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. Jonathan > > Fabio > > > >