Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1684980lqe; Mon, 8 Apr 2024 17:44:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW3RCfJpyHXQRA8jzb+rwHbl7nD5xFkxGXVlReL6NHHJbKx+1jovX4rOux5+jn6G3d+ynvY5lDgG4DG9lTGhCkYqNbFgot02xa+0iSXzQ== X-Google-Smtp-Source: AGHT+IFAGo7J/Y79Yk9I1kTr3w9/TphaQ9OTLb1ZtUKyTlgRp2mSL0pObJuScBMEpjexSwhsyLFb X-Received: by 2002:a05:6a00:3a03:b0:6ea:b9ef:f482 with SMTP id fj3-20020a056a003a0300b006eab9eff482mr12259010pfb.24.1712623444639; Mon, 08 Apr 2024 17:44:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712623444; cv=pass; d=google.com; s=arc-20160816; b=zSPkb/uJQUa52hqoPuA1oC8RIx3U0wedtKrSDk+032xVnrzT1MaJYW1+SKPA3XZWOp KhCfvEGXbdxbgek+o4Cd6dwP+Gzjy/AB2Qy+kvCOKKRkpKl5iDvwCAouwc1GFwrViRx5 BWSe5Zq5nvpJ9OrTPC5WJcJIyYNGPrOXCix2hrsDfBRjkr0tlad1fOwWjNXq1ktkJitk nWjNsAINKG0eckdU8CjDWPFHSnTmzCK+4BDrr38LWwjW3KsZY+Pblxe/iYKQfACv0sJg iJ44j6K/TUY3ZtEIR2i9OIpDayQOKY6YibLx1JpE6TeLOuX9SxmD/r/n/iLAn8nT8NQ0 spZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uOUdpCbOM54JeGzqkT5CWY45hJdFZMr4+oUzu1mCIZI=; fh=uJ7g+uWLl/qQeMP1gUwlnaPOBUQNBx1hxNdzMwMJn3Y=; b=WuuSQtfS2ghRGCunjn2nrmYkcBP1jffUPTZHEQ2w7N8Jcc4c/g8LHTuD/eK8p+shH1 A2zA8xBORoo5b2bXSpAiV8B9De93lNEgG+tczp0Sha6qo/edo6GX/YZd6Kmq4IjGSohn tiCWBG99VOtRTYfi4tWGdRDRi44btthcVr6b8D+omb87SEvRMYP/vJ8QBox+dqsRdOYm /jd4FpRWlV3mx7UQlhllDnZe0uRXwQsDJFE0boMb9GW5+EqWXGgfkBbm2NNbFf1ocLqg 4mQDQSXQrFk64i3EIbP0S50mycL7txcdYQrykL68k7HXgcsHJUVocvaZI/dkSheodni3 pIow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lRsLvak+; 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-136052-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136052-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 v67-20020a632f46000000b005dc4190c756si7615883pgv.866.2024.04.08.17.44.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 17:44:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136052-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=lRsLvak+; 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-136052-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136052-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 98E5AB23920 for ; Tue, 9 Apr 2024 00:43:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E509D567D; Tue, 9 Apr 2024 00:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lRsLvak+" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 D162A15C3; Tue, 9 Apr 2024 00:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712623405; cv=none; b=YZO4bn29OwEAMjmgiPrwusjLu5QjXOtPO7aGnSoOZFxyKgFWdrOpjvrDfAWSFu7UhymVGLxH5aGnj8w4rV0xz7NpIUqLPi/9EpFhwNA7qy6hpwBr5i1jPo+Bt5sO2hTNLXFKo8TLKbELGdYX8bAuAOGZ3MnKIVjS8kq9gSiEl7E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712623405; c=relaxed/simple; bh=1aI4ho1DPT61jrjNxaxtPRo7yIfF3GJHyqhXxYEgWW4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HLw5A6GE3Mo7gLj3jj0HYPTomPfFIVNzxeNb0apAVW+22FXB9xO13YPNF3GhosE86L3uy0d3QM6UrwOYsp6DEA5r/dhoCrzYQ59qdhhX8XSF8LD8N807GykbdCo7VbZF3EzubdBR8ZaylaxEKkiBIOWr7YAG/aHxNZaxFmD87zI= 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=lRsLvak+; arc=none smtp.client-ip=198.175.65.13 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=1712623403; x=1744159403; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=1aI4ho1DPT61jrjNxaxtPRo7yIfF3GJHyqhXxYEgWW4=; b=lRsLvak+taU5UISTP2XaKB+2PhqarYSPLOK5Ky2gliAh9Y66ii6FD0Cx pv7ALibJecD+oo9XM+Gg6g0IZFQQIq4g8uFb/axnVt4PQY7XWIBu5xj6w /QDKv5NF3/1kTdwsv3V3NhsuX7BzSaIuepu01C1TYIp0r+AWiRlQCmJDj mwdmYCqkBpkmcXsDJiXqczdAqMdsLcoxlshHpt/pcOp/BQP3JA31laNwn j7uJKLpJgmGkvibz7oJj7cvRRjbDYldxdBEJZa87a8BZZCkTT8NmvqTg3 1fZ1lwDqNoHRSECPV23+yY32plLO8Am9dAYUFqn4dlxetUuKLJkc1lVin A==; X-CSE-ConnectionGUID: 7o0jA+HNTC6ou6hKSBK6RQ== X-CSE-MsgGUID: jg2FauJBRweVxKAUwGGFKA== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="19075140" X-IronPort-AV: E=Sophos;i="6.07,188,1708416000"; d="scan'208";a="19075140" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 17:43:17 -0700 X-CSE-ConnectionGUID: ASMfITtESEWg+r1BXJk1PQ== X-CSE-MsgGUID: LTqIP4DKSSqjEp1GmnW6AA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,188,1708416000"; d="scan'208";a="24763419" Received: from aschofie-mobl2.amr.corp.intel.com (HELO aschofie-mobl2) ([10.209.37.24]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 17:43:11 -0700 Date: Mon, 8 Apr 2024 17:43:10 -0700 From: Alison Schofield To: Ira Weiny Cc: Dave Jiang , Fan Ni , Jonathan Cameron , Navneet Singh , Dan Williams , Davidlohr Bueso , Vishal Verma , linux-btrfs@vger.kernel.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 05/26] cxl/core: Simplify cxl_dpa_set_mode() Message-ID: References: <20240324-dcd-type2-upstream-v1-0-b7b00d623625@intel.com> <20240324-dcd-type2-upstream-v1-5-b7b00d623625@intel.com> 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-Disposition: inline In-Reply-To: <20240324-dcd-type2-upstream-v1-5-b7b00d623625@intel.com> On Sun, Mar 24, 2024 at 04:18:08PM -0700, Ira Weiny wrote: > cxl_dpa_set_mode() checks the mode for validity two times, once outside > of the DPA RW semaphore and again within. Not true. It only checks mode once before the lock. It checks for capacity after the lock. If it didn't check mode before the lock, then unsupported modes would fall through. > The function is not in a critical path. Implying what here? OK to check twice (even though it wasn't) or OK to expand scope of locking. > Prior to Dynamic Capacity the extra check was not much > of an issue. The addition of DC modes increases the complexity of > the check. > > Simplify the mode check before adding the more complex DC modes. > The addition of the DC mode check doesn't seem complex. Pardon my picking at the words, but if you'd like to refactor the function, just say so. The final result is a bit more readable, but also adding the DC mode checks without refactoring would read fine also. and...a bit spacing nit below - > Signed-off-by: Ira Weiny > > --- > Changes for v1: > [iweiny: new patch] > [Jonathan: based on getting rid of the loop in cxl_dpa_set_mode] > [Jonathan: standardize on resource_size() == 0] > --- > drivers/cxl/core/hdm.c | 45 ++++++++++++++++++--------------------------- > 1 file changed, 18 insertions(+), 27 deletions(-) > > diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c > index 7d97790b893d..66b8419fd0c3 100644 > --- a/drivers/cxl/core/hdm.c > +++ b/drivers/cxl/core/hdm.c > @@ -411,44 +411,35 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, > struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); > struct cxl_dev_state *cxlds = cxlmd->cxlds; > struct device *dev = &cxled->cxld.dev; > - int rc; > > + guard(rwsem_write)(&cxl_dpa_rwsem); > + if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) > + return -EBUSY; > + > + /* > + * Check that the mode is supported by the current partition > + * configuration > + */ > switch (mode) { > case CXL_DECODER_RAM: > + if (!resource_size(&cxlds->ram_res)) { > + dev_dbg(dev, "no available ram capacity\n"); > + return -ENXIO; > + } > + break; > case CXL_DECODER_PMEM: > + if (!resource_size(&cxlds->pmem_res)) { > + dev_dbg(dev, "no available pmem capacity\n"); > + return -ENXIO; > + } > break; > default: > dev_dbg(dev, "unsupported mode: %d\n", mode); > return -EINVAL; > } > delete extra line > - down_write(&cxl_dpa_rwsem); > - if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { > - rc = -EBUSY; > - goto out; > - } > - > - /* > - * Only allow modes that are supported by the current partition > - * configuration > - */ > - if (mode == CXL_DECODER_PMEM && !resource_size(&cxlds->pmem_res)) { > - dev_dbg(dev, "no available pmem capacity\n"); > - rc = -ENXIO; > - goto out; > - } > - if (mode == CXL_DECODER_RAM && !resource_size(&cxlds->ram_res)) { > - dev_dbg(dev, "no available ram capacity\n"); > - rc = -ENXIO; > - goto out; > - } > - > cxled->mode = mode; > - rc = 0; > -out: > - up_write(&cxl_dpa_rwsem); > - > - return rc; insert blank line > + return 0; > } > > int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) > > -- > 2.44.0 >