Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp527362rdb; Thu, 15 Feb 2024 07:26:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWoAgmtoz6hwuuXOKBj8akKAHxF1kUz/mGa6j9+h9zRTH/NOtwXwC/owiB/MqZkczvmvV/DsLzqoNytUOebeYQ3N6UZOAlSCePdHkDNuA== X-Google-Smtp-Source: AGHT+IGJVr4xiYTnyhhHHp8cq3uHxh7g6x2l3FPULxNYpXfMGYmqj1G5dwuz1K8oIxkwq9UZBLUp X-Received: by 2002:a17:902:b20a:b0:1d9:a647:5579 with SMTP id t10-20020a170902b20a00b001d9a6475579mr1851267plr.1.1708010762664; Thu, 15 Feb 2024 07:26:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708010762; cv=pass; d=google.com; s=arc-20160816; b=RFONB0xA9J9Ru11oJSsoDfxqFVlWhNRW04v8DuJePgjfDVjdBhYiQKzDmgrtNON7Wp AQ5rdDzlMCCXgQGoQvaXk64GddTv+fDT9im8KGO1ZHC/F4koiPX0Ji4kKfcWNrwS2Hae zlzQhi0SOAusXRtO3s+npq9NNjJWhr7BAjxcl5OeatnP3E2LoJg6klEfoPmyRwCM/QIj XyqkNdMBtueCNdhjDCiXhYlYrPZgBLZA+OAAGHU0BaMgssOKh6J7yQlET6nhCEK4SSfi 3YPSf6+oUKgj6Er/CZSbBcrphQ4gKJ0b/RnOCKmGPv6H/uUMXC7V4cLcdQ2Bf9bcciQP 5JIg== 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:references:in-reply-to :organization:message-id:date:subject:cc:to:from:dkim-signature; bh=sG36a/Rxj23h+IRnfFPeioc/Thbi7lmOmLob4W7Nh28=; fh=h+341R79v2Ps6wm2ho9Xau8Jt9ErTQEbQ4Cgia9Iha8=; b=p0FoCxPYRSOohZXgdaYEvG6NM1IXlAJ0gg0909ltKZlIVVL5C0coZODPUim24cOIhD dVh9Yv5zHNXk5QUR4yyCX6bZe301ZtY+x6osoWBbn6VPcEeIt/5hEbtODsLRuoygxenx cNXze2a8+yQ+GFs0XLrgm6JANnC+7QTZ+yj40v1SrcE2ierMjNHqwUtIaxVprtiyDfJu keG7WYrzjc76pNl4exv3wYInP3xBZrKBLkwSkCoVOb14T6nXoaRc4KNklvjFRjixMTxd bhq0OAPdJlA6RQSSiDJ+DnKDwoqOrEu0MvnyqVBEO+zptPlMOjOC6LnQlInFx0zTVGvi 00cQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JS53fqJN; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-66959-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66959-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 e11-20020a170902cf4b00b001db4e181742si1298405plg.42.2024.02.15.07.26.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:26:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66959-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; dkim=pass header.i=@intel.com header.s=Intel header.b=JS53fqJN; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-66959-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66959-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 C8AA2B2B759 for ; Thu, 15 Feb 2024 13:12:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7042212FF7F; Thu, 15 Feb 2024 13:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JS53fqJN" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 E407312F595; Thu, 15 Feb 2024 13:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708002770; cv=none; b=hZzO488iC6w2kL1pAXU1XBnzMLCvLzm6xs63j5N4ha5PbpF8oUf8N+jNVHvhogk6y+SlwOznKvX0Y/8Hg5tGM0rxxfwxxHhcJ6Hmxd/lC3+G7Ccs5y3g9eM/6ktNoix/Treo9egXsXfTbaaDgTdLn9lL33005zQS8L1yZd22zWA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708002770; c=relaxed/simple; bh=f5naG3H0m5jjSQTWaScUfYqNDrTUuPCFedrqUbopnOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jSkRO2DxsHXbJlq+ZB6lFpof8sENGQ6SRw27mlkkbbsbOsRLMpcc5l4sNuPlayQBSVlw0df/nyk+bAfPzi3l22UF4BifBq8Ucunx6KFnjcsoQWQQAncPRCoN0B4HxxOTZGGkWgiz0dcrUiJMmTXfCFc23TsDTXVnwT4aR+ycqUY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JS53fqJN; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708002769; x=1739538769; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f5naG3H0m5jjSQTWaScUfYqNDrTUuPCFedrqUbopnOA=; b=JS53fqJNebRVW9fEfr3P2rT5HkREc0J7SU8LWIeC5DIvt88PMuJDhFMM PDxNyOaC2nAXYiKaXW1FI9obZkAdznHaU55XbUtSDV8RsfcJlhWLi77uC TCLzkSswC1PJh83+AgyiUMaH2moaBVX0C2GTkSYwP37//A0l/y6eSAOEm 4AYA3iQS19PEHw095iXwxOOWMYp8PYDzh9CpTGPWcXRhDBHapNxP2eBZ2 QX+QA0Cmb3HA0Tg9bMpsZ6z70lx9Ge0f+qTZ3S4QoAzVQyoZdJGNEPEWe OBpS7f4cAnped3kb7RY22PUB+j36YRFfleE28wDbBZDpTAUOTq1YV+rYI A==; X-IronPort-AV: E=McAfee;i="6600,9927,10984"; a="12632313" X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="12632313" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 05:12:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,161,1705392000"; d="scan'208";a="3682346" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.localnet) ([10.213.3.132]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2024 05:12:35 -0800 From: "Fabio M. De Francesco" To: Jonathan Cameron Cc: Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, Ingo Molnar , Dave Jiang , Ira Weiny Subject: Re: [PATCH 1/2 v4] cleanup: Add cond_guard() to conditional guards Date: Thu, 15 Feb 2024 14:12:31 +0100 Message-ID: <2768675.PYKUYFuaPT@fdefranc-mobl3> Organization: intel In-Reply-To: <20240215102642.000067c5@Huawei.com> References: <20240208130424.59568-1-fabio.maria.de.francesco@linux.intel.com> <20240214180452.00000974@Huawei.com> <20240215102642.000067c5@Huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Thursday, 15 February 2024 11:26:42 CET Jonathan Cameron wrote: > 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... > > ? > Yes, certainly. Your solution is more elegant. We can reuse __UNIQUE_ID(). There is no need of a new helper macro. Thanks. But with s/cond_class/cond_guard/ and s/guard/scope/ (I think that "scope" makes the purpose of that variable clearer). I think I'll wait a bit more in case someone else wants to comment and then I'll submit v5. Fabio > > > Jonathan > > > > > Fabio