Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3183308rdb; Tue, 6 Feb 2024 09:23:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqEv05lGo8Snm1Gp8WYburjhVJiPZU6UUfo95vXOIi502mFboL0yjGOuzLUp5zXADyLkDa X-Received: by 2002:a37:c201:0:b0:784:8531:50f2 with SMTP id i1-20020a37c201000000b00784853150f2mr3100103qkm.29.1707240221301; Tue, 06 Feb 2024 09:23:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707240221; cv=pass; d=google.com; s=arc-20160816; b=SeY9fJjhvEIeHLcJlKvhlWq9QDvyI6FAmt8ZFCqtThbFOIxXzTT1p13423xDe2skhE 908nstbB8i7VYlI1EF+P7Z9xTXTkEzYISbju5KDReeiz5k5BUTOy7ojq9+OeE33UVmWi Orm1Y+3Yl0b5VkhEn/7YodBffarip7VLxoMwcZf4Z2Cbd9oqXWVicXXtuwYlyLoNLxoi VzGCvf1UxnvaCXEIVDZkwK3221t/U1nYL4iwOEwArA0mKKUkY39dDDrhiMozHgzgP8VE CFgOG8BkMSYvvAnYCT/yQp5xRsMY/yUJ868r1WQruXr1RYZHnA+mFOAi/iiCxXSPpLtw hMCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=cG3NwI3/xHkEXH1rG7nrxAudNqme4F5gP5ctqfLdcdM=; fh=SQv0JogUiHAU14Nk+lLJCw1L9vnzNv8uDySFKzXp/Uc=; b=GJNQHCUFRiY9nKNy/uC9k/HJtmfNRcMun6p6FjdF2AhFVgTCixSrSJdNmHR7G8/YXm vTxrnEOVzGcpWTHNmSFxfxykfHGQEHMXtlmd+tXumkpQwOn4q5SSzFpvkg8QOuMW3vlA wuR6PAlY0NpiasXJ+3bYTQahv1bl24IcvE7EbK8vNKVOwNRLjzmZETQT7s9Pk46aJOde EhGr90Pf8hQNtO7OBo6yV8e2VJRRkrR9MkwRgD04/vWqgoHwCBmGxDteUXM8aP6CUkGA J5i41hZk+xsLb1R6GPpWXRiYMPuL1lwT7Knv8kdqCCayDd0LtZj/Hb6HuMbKk4l9Zq5w 79WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0UbiIuB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55362-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCXvnImI0Rmyurgm19jWb0kmSkj4bQaJi9zXz7buAn7uSYjDkzzlVnUKcQXzvVbgag0xO0nOjar8zW6Sj6kVQqTHnPgN6Y7MME4yOfUK2g== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w20-20020a05620a095400b007855bf84bf6si2648239qkw.144.2024.02.06.09.23.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:23:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P0UbiIuB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-55362-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55362-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 0DFC91C22E29 for ; Tue, 6 Feb 2024 17:23:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 722C18F6E; Tue, 6 Feb 2024 17:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="P0UbiIuB" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 E29958F68; Tue, 6 Feb 2024 17:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240213; cv=none; b=Q3foSvEmsRcIL49pAvhi0m/NVMi7UfJ196wdpJp9Kc4tuwJJfddyldUE3cyLFVNGDY7fYG4Wmj7vr0K3sX6XOx/88fgRBErbFKiw8++a8/YyS9QrkM4AeX5fPcjzlkFWSsxlxMLXQz++SbkmY5LytXx0xXtwJR0iUWImvUHsOEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707240213; c=relaxed/simple; bh=8JZuQFl5Ktp+sBXs223hELh4OCBn2C06QW6nfIbxPBA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lkA7T2qeAO2Cp5qL1hH+/bL/TBJobG/I0/VUMKrMw0SgvwkyFbPAmz/awy1b4O6XnBtTtCgD55wBEqwD8AxQ3voT7+hxt2ZJz8DyYDUYYpjvX9+Qoc94FpDo8IUge0FcjEw9ZSRtligiQVgeauwCSzzE45FdWqmfbwAQffPvm74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=P0UbiIuB; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707240212; x=1738776212; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=8JZuQFl5Ktp+sBXs223hELh4OCBn2C06QW6nfIbxPBA=; b=P0UbiIuB5BoDOP76geca/1kQpBTs0p/ndiSnuIV5TdAJJBlt1lNJtCEO 3PL9JXwHMYMi3m+I1CduNSFHQdO90H8e8n/Zyv1LBL+Fufz6xFbGgsj0+ myF8PDRWI6c2P2sOPloOOo3g+/Guyy2o4OTgDYTa9zjQQZKjDY3LEy1lv XLUVDtx7IHWKbR2Rc9kUObSajidKwTaCW56w9tlZ1R5VbpH/5Nn4Vtz7M fMV7Rm2DYwrjR92mB92RKEAalNwIlm31Uakx1eRbIYzeIMwLcGISumzQJ FTn0linDn5anhb/Z3oFCINTDAg5hv+VTNuUrL4kbKps4sDpyw3Fxmnpey g==; X-IronPort-AV: E=McAfee;i="6600,9927,10976"; a="950189" X-IronPort-AV: E=Sophos;i="6.05,247,1701158400"; d="scan'208";a="950189" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 09:23:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,247,1701158400"; d="scan'208";a="5678183" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [10.246.113.99]) ([10.246.113.99]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 09:23:30 -0800 Message-ID: Date: Tue, 6 Feb 2024 10:23:29 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2 v3] cleanup: Add cond_guard() to conditional guards Content-Language: en-US To: "Fabio M. De Francesco" , Peter Zijlstra , Dan Williams , linux-kernel@vger.kernel.org Cc: linux-cxl@vger.kernel.org, Jonathan Cameron , Ingo Molnar , Ira Weiny References: <20240206121301.7225-1-fabio.maria.de.francesco@linux.intel.com> <20240206121301.7225-2-fabio.maria.de.francesco@linux.intel.com> From: Dave Jiang In-Reply-To: <20240206121301.7225-2-fabio.maria.de.francesco@linux.intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/6/24 5:13 AM, 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. > > Cc: Dave Jiang > Cc: Jonathan Cameron > Cc: Peter Zijlstra > Suggested-by: Dan Williams > Suggested-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco Reviewed-by: Dave Jiang > --- > include/linux/cleanup.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h > index c2d09bc4f976..d70454e9f8dc 100644 > --- a/include/linux/cleanup.h > +++ b/include/linux/cleanup.h > @@ -134,6 +134,16 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ > * an anonymous instance of the (guard) class, not recommended for > * conditional locks. > * > + * cond_guard(name, fail, args...): > + * a guard to be used with the conditional variants of locks, like > + * down_read_trylock() or mutex_lock_interruptible. 'fail' is a > + * statement or statement-expression that is executed if waiting for a > + * lock is interrupted or if a _trylock() fails in case of contention. > + * > + * Example: > + * > + * cond_guard(mutex_intr, return -EINTR, &mutex); > + * > * scoped_guard (name, args...) { }: > * similar to CLASS(name, scope)(args), except the variable (with the > * explicit name 'scope') is declard in a for-loop such that its scope is > @@ -165,6 +175,11 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \ > > #define __guard_ptr(_name) class_##_name##_lock_ptr > > +#define cond_guard(_name, _fail, args...) \ > + CLASS(_name, scope)(args); \ > + if (!__guard_ptr(_name)(&scope)) _fail; \ > + else > + > #define scoped_guard(_name, args...) \ > for (CLASS(_name, scope)(args), \ > *done = NULL; __guard_ptr(_name)(&scope) && !done; done = (void *)1)