Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1901539rdb; Wed, 31 Jan 2024 12:37:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJOBjVkHInfTM3icU6KD2wLa0nA70DkHBHmXdIWFVLjYDbZjuAiSDa/OaHxIRltXEk8h8o X-Received: by 2002:a17:90a:b014:b0:296:be2:85be with SMTP id x20-20020a17090ab01400b002960be285bemr275258pjq.9.1706733458146; Wed, 31 Jan 2024 12:37:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706733458; cv=pass; d=google.com; s=arc-20160816; b=yOUtZADQFaaAl8ZVdnrRAkwGl85zeQVcFP0+EoOrnACy8502PFCvrIDraIC/A0KT4W 84wFaYS1mR9o7h6kD0lh5RaxuaHEVLvnljyN/t+64Ig+0GwlbPvl+O6tlnpmlbj2bhmn S+Uu4diojFLlhiNVNXdjALiLDdD98StOYKlGVPTIjVlK3SegmgtUgzM483VW+84patIw 7b7OkQi+ZnsA+LQATIVN5sci9y+AmwPuTpJ6/vT9OnScBKblCCuE9LxOr6lHq54xySU3 fmjAxvwVr3PH8b9wMgK77aPiqvgtgutNcmYL+4xpD9HT+KTUnAn5cbtasjEPSfk9sT4k u4gg== 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=gyHXHxVHUPx5MaIERGDexWhq63UXUpW0Jr576dmstEk=; fh=b9rAPjjwruYuSkRiAGWgMlpDgqJi33MVoXGKbZ8wdw4=; b=spsGvORZoXF9m69SyPMjLLWJFNPzuRhk1QXURxdYPBp/fxCC/gakXUHgsld2Nx8zRZ rmJKs5c/DbWmjUcPV2qszQGy0/xcXDUUHcMMEEYoCNt7uMOrRNL3XX+2G6/6N5xMIbYW uk6xBy/ufoRNitT//pOv6PEgSwoVZyXJmIyZJ1OP5eL3b8W1flbZIwHrF8I1VyiRC5jo bGN14+h7BWI3cAIEjTfgQ7PG+ZkKIgrtemsdTLUEoOzLPDYGGfyZo6lw6GSpJLHJ1qkR qfaNv+Ke8rqA9Th5rtFEfQYbJhY6zOdtCdKCV6l38qWxJV0fifdpfAqDweo/eBZmFWah cOAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XZVOxxJk; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-46465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46465-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; AJvYcCUkX2WKhjtrtzS/sTuRocuw8eSe+OuVhdXiF41CS291WUxpJJBEg/SpP7c7zD4L1XqKHaEYG5WErAhQTB9VsVQUXLddy13N/bPWcFLg2w== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j14-20020a170903024e00b001d9055b6a4bsi4555229plh.418.2024.01.31.12.37.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 12:37:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46465-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; dkim=pass header.i=@intel.com header.s=Intel header.b=XZVOxxJk; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-46465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46465-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 92A95297B04 for ; Wed, 31 Jan 2024 13:09:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D7E07BAF9; Wed, 31 Jan 2024 13:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XZVOxxJk" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 0B25E3770D for ; Wed, 31 Jan 2024 13:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706561; cv=none; b=uxlWRMh7BJ/m/zZnONnd6eoOIzKqP8WRt/Iy+zPCs5tPMa5+NPhWmRc7ky8W8ssCOFDNaLpUFLDfZHMN4VUxqfqDtoBQjlaFxsXZi3EHEQja/e0ltnwqZeSuQImZfMP4koy3n0jJusQ2cdNUFU72vtgK6ccHfeULMrS4d5wwdxc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706706561; c=relaxed/simple; bh=hLnu5IAc3QGNlNKTY3jsLCwnTnvQBY8D4pUs+0Lc3hw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uA7UhloHgfUKPzCpNp9wrZOAjfR2eRUuPFTeojL+ghSjaY+kd53UQlw/hCn0XV/cD25NGt7wWYCwKUU6wPPO5xsRFtVJigozgMXM2zqG//sc/AxbrQ/rpCxrF3uZm7JA3FAeqOp+qY5z+2mvveg8k/hhZmiyrA+cytFzADL52WI= 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=XZVOxxJk; arc=none smtp.client-ip=192.198.163.9 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=1706706560; x=1738242560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hLnu5IAc3QGNlNKTY3jsLCwnTnvQBY8D4pUs+0Lc3hw=; b=XZVOxxJk0uiZTLE5VCdiXqYEh1MZ19OzcdyAGXzu8GNFzVniwzy3ozRm HyMePKAhkojWU0Mx+1r0wkpwl8s1cB26df8yU+CtKt8x1ZEg89S1kIWuJ 1IzBDf6RXJFCMlCEwOKIh6ThgZbNBEO5uigl+EqdNNwSb0DLL6W189bpJ RwxXNBEYCmM37pn99c0zH4/E5xSK2Qz62VOVWqssWhtbRQhOEGkui+V8e rrkCY0beSpMUReGqPPvJZzSQ15NF07H9/6LCSwNKv9i6OrNmsIIfVetkI RF9zM8jSe3QKI+nqu2MADCymZe//xAN1j3diocCOVFA6G+RpA7/6RKM6v Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="10347935" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="10347935" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="822566327" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="822566327" Received: from fdefranc-mobl3.ger.corp.intel.com (HELO fdefranc-mobl3.localnet) ([10.213.21.82]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2024 05:09:16 -0800 From: "Fabio M. De Francesco" To: linux-kernel@vger.kernel.org, Dan Williams Cc: Peter Zijlstra , Dan Williams , Ira Weiny Subject: Re: [RFC PATCH] cleanup: Add cond_guard() to conditional guards Date: Wed, 31 Jan 2024 14:09:13 +0100 Message-ID: <13504735.uLZWGnKmhe@fdefranc-mobl3> Organization: intel In-Reply-To: <65b82555aaf86_5902829447@dwillia2-mobl3.amr.corp.intel.com.notmuch> References: <20240129190100.329791-1-fabio.maria.de.francesco@linux.intel.com> <65b82555aaf86_5902829447@dwillia2-mobl3.amr.corp.intel.com.notmuch> 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 Monday, 29 January 2024 23:23:17 CET Dan Williams wrote: > Fabio M. De Francesco wrote: > > 2) By using cond_guard() it is not possible to release the lock before > > calling other functions from the current one. The lock is held until the > > current function exits. This is not always desirable. > > No, that's not correct, the lock is only held until the exit from the > current scope, and if you call functions from within that scope the lock > remains held. So: > > func1() > { > guard(...)(lock1); > if (condition) { > guard(...)(lock2); > func2(); > } > func3(); > } > > func2() is called with lock1 and lock2 held, func3() is only called with > lock1() held. Dan, If I read your example correctly, this is exactly what I wanted to say by "it's not possible to release the lock before calling other functions from the current one". For example, if we use this (not scoped) cond_guard() in cxl_region_probe(), we end up to the switch() and then possibly call devm_cxl_add_pmem_region() with the cxl_region_rwsem semaphore down, whereas the current code calls a up_read() before the switch. I think that in cxl_region_probe() the only suited conditional guard is scoped_cond_guard(). I know that you don't want an indented success path but in cxl_region_probe but I suspect that scoped_cond_guard() is the only viable solution, otherwise we end up calling the functions that now are called after up_read() with the semaphore still down. I hope that this time I have been clearer. Thanks, Fabio