From patchwork Mon Feb 17 14:48:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978022 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 5C6642222D1; Mon, 17 Feb 2025 14:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803756; cv=pass; b=aDFFPVjd2YFu6t/nE8WGjadzAzL+ZeCuGKkuSkegmkKPgQM1zb6/G/S2KNGP2mBFjyaVfuZLp3N6j2JvDtXlrxGkllvKykTjoyjrAxNp33Lrfd45J6UY9m7RNqG2p9F3P72HPxFjqBiYJDzxwOpCJpQAIiC982Ys077rj7gdUUo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803756; c=relaxed/simple; bh=j5rnVvhXjS0fp4vLFcuKjku1Vrlif66jGXAN8K5ae1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J+piPdAcWfWHhzEjKksOCemucX/1wIfmAvpRqGEA7WfLQxEV/VTBlgTigLpjQZCWMd69Dn4m8+i5MCsUJYx8l9uYVyRSNVxkrYWVpe/+C7zYIsl8zCZYS7fBo8kD4ShyHTfcjuxGBi71RhFSJXU9Giv3bHmyvI+u7MqkKxIAwkQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=EHPo0kUX; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="EHPo0kUX" ARC-Seal: i=1; a=rsa-sha256; t=1739803736; cv=none; d=zohomail.com; s=zohoarc; b=VayC5VItgDuM/XfaxgiO594QQUnuCWKDidKxkaYshVXW18Q0nZqdkWEPkB8LZQZrQxAxq5DJqDJl4OJPFVR5WL67xCauKPd4w4ff+FHOpn4+UaV8iXAhHiCwj6diHeqLt+I13U07gqOp2z4X4C4YAlmNQDiWj0wSanaRhnIJKLc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803736; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=AaEsjabfvnngmW6hr/bb/k32BBpUycgG3kyIthmnuxk=; b=Gl2J7JtbPu3lhPT8rQcQcLL4bIPSxmtXFv49EH68MtOjiX3LK72WQMegTHVTgNrLNZEUV03h6BmYOt0QrG1Vsgfz7jvy5NoaIW2eM1nMSZ4k4UavmgCv4MRKcbvdKgtTGxgckf+t6oQyPpu9UNEh4w43ZJivw03K0IvCnnYfG+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803735; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=AaEsjabfvnngmW6hr/bb/k32BBpUycgG3kyIthmnuxk=; b=EHPo0kUXaBNgIVlRaEhNxfPLN0rjJZA7Mg/tIaNd2crhbjjiGM6caVwWGe1y9CKf j8S716B3/uXqlPSDx1ISa7T1GGJIKS+EeUGL43rB2YyvDL6kBEJPriziNgC0noe9H+C 00f2XVuxjIMazBXU06YVZZVo9SkgpsmudmGlFV8k= Received: by mx.zohomail.com with SMTPS id 1739803733054890.5990768616672; Mon, 17 Feb 2025 06:48:53 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 1/7] cxl/core: Use guard() to replace open-coded down_read/write() Date: Mon, 17 Feb 2025 22:48:22 +0800 Message-Id: <20250217144828.30651-2-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr08011227acac204fb3c8151c99a25145000070faa0f88922971c0cb1f3c5b7c9238d8e89a12c859171f0d6:zu080112272954007862cf36919bfa9c6e0000561f126de9b1c9b03846b8e44b797a08001aa80b7090d7e7d0:rf0801122dcb291df8be0a02025bd6eb960000341cc8f31c880c43310d4f9ebf2905145411140c7e35de049ba43fe7949a27:ZohoMail X-ZohoMailClient: External Some down/up_read() and down/up_write() cases can be replaced by a guard() simply to drop explicit unlock invoked. It helps to align coding style with current CXL subsystem's. Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield --- v2: - Drop some local variables. (Jonathan) --- drivers/cxl/core/hdm.c | 15 +++++---------- drivers/cxl/core/memdev.c | 9 +++------ drivers/cxl/core/port.c | 8 ++------ drivers/cxl/core/region.c | 8 +++----- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 50e6a45b30ba..4a578092377e 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -213,13 +213,12 @@ void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds) { struct resource *p1, *p2; - down_read(&cxl_dpa_rwsem); + guard(rwsem_read)(&cxl_dpa_rwsem); for (p1 = cxlds->dpa_res.child; p1; p1 = p1->sibling) { __cxl_dpa_debug(file, p1, 0); for (p2 = p1->child; p2; p2 = p2->sibling) __cxl_dpa_debug(file, p2, 1); } - up_read(&cxl_dpa_rwsem); } EXPORT_SYMBOL_NS_GPL(cxl_dpa_debug, "CXL"); @@ -250,9 +249,8 @@ static void __cxl_dpa_release(struct cxl_endpoint_decoder *cxled) static void cxl_dpa_release(void *cxled) { - down_write(&cxl_dpa_rwsem); + guard(rwsem_write)(&cxl_dpa_rwsem); __cxl_dpa_release(cxled); - up_write(&cxl_dpa_rwsem); } /* @@ -362,14 +360,11 @@ EXPORT_SYMBOL_NS_GPL(devm_cxl_dpa_reserve, "CXL"); resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled) { - resource_size_t size = 0; - - down_read(&cxl_dpa_rwsem); + guard(rwsem_read)(&cxl_dpa_rwsem); if (cxled->dpa_res) - size = resource_size(cxled->dpa_res); - up_read(&cxl_dpa_rwsem); + return resource_size(cxled->dpa_res); - return size; + return 0; } resource_size_t cxl_dpa_resource_start(struct cxl_endpoint_decoder *cxled) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index ae3dfcbe8938..98c05426aa4a 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -564,10 +564,9 @@ EXPORT_SYMBOL_NS_GPL(is_cxl_memdev, "CXL"); void set_exclusive_cxl_commands(struct cxl_memdev_state *mds, unsigned long *cmds) { - down_write(&cxl_memdev_rwsem); + guard(rwsem_write)(&cxl_memdev_rwsem); bitmap_or(mds->exclusive_cmds, mds->exclusive_cmds, cmds, CXL_MEM_COMMAND_ID_MAX); - up_write(&cxl_memdev_rwsem); } EXPORT_SYMBOL_NS_GPL(set_exclusive_cxl_commands, "CXL"); @@ -579,10 +578,9 @@ EXPORT_SYMBOL_NS_GPL(set_exclusive_cxl_commands, "CXL"); void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, unsigned long *cmds) { - down_write(&cxl_memdev_rwsem); + guard(rwsem_write)(&cxl_memdev_rwsem); bitmap_andnot(mds->exclusive_cmds, mds->exclusive_cmds, cmds, CXL_MEM_COMMAND_ID_MAX); - up_write(&cxl_memdev_rwsem); } EXPORT_SYMBOL_NS_GPL(clear_exclusive_cxl_commands, "CXL"); @@ -590,9 +588,8 @@ static void cxl_memdev_shutdown(struct device *dev) { struct cxl_memdev *cxlmd = to_cxl_memdev(dev); - down_write(&cxl_memdev_rwsem); + guard(rwsem_write)(&cxl_memdev_rwsem); cxlmd->cxlds = NULL; - up_write(&cxl_memdev_rwsem); } static void cxl_memdev_unregister(void *_cxlmd) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 78a5c2c25982..2c59d65bc18b 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -549,13 +549,9 @@ static ssize_t decoders_committed_show(struct device *dev, struct device_attribute *attr, char *buf) { struct cxl_port *port = to_cxl_port(dev); - int rc; - - down_read(&cxl_region_rwsem); - rc = sysfs_emit(buf, "%d\n", cxl_num_decoders_committed(port)); - up_read(&cxl_region_rwsem); - return rc; + guard(rwsem_read)(&cxl_region_rwsem); + return sysfs_emit(buf, "%d\n", cxl_num_decoders_committed(port)); } static DEVICE_ATTR_RO(decoders_committed); diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e8d11a988fd9..d8a71f9f9fa5 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3208,7 +3208,6 @@ static int match_region_by_range(struct device *dev, const void *data) struct cxl_region_params *p; struct cxl_region *cxlr; const struct range *r = data; - int rc = 0; if (!is_cxl_region(dev)) return 0; @@ -3216,12 +3215,11 @@ static int match_region_by_range(struct device *dev, const void *data) cxlr = to_cxl_region(dev); p = &cxlr->params; - down_read(&cxl_region_rwsem); + guard(rwsem_read)(&cxl_region_rwsem); if (p->res && p->res->start == r->start && p->res->end == r->end) - rc = 1; - up_read(&cxl_region_rwsem); + return 1; - return rc; + return 0; } /* Establish an empty region covering the given HPA range */ From patchwork Mon Feb 17 14:48:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978023 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 F15572222D1; Mon, 17 Feb 2025 14:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803765; cv=pass; b=t9+Vzgnh7BHqVK0hAKTFg1h2z4DDZTpL0BVRSIvjKagcFRnsUl0cLmz3ANtez+/xeVQDu53Uadq9pO0f+rPyGs5dFoLwNCA3ymR5JoGZydL1FTV2Do6RSoiBFeUndjoijB6E3QacnY+ayFrsMVxfaX52b83xSk8705Q2TRue9xs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803765; c=relaxed/simple; bh=59rRgjb0cfIfcixcA1SyakLEuxESLq0IMjQVuUxKvEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jPYdTMSvhSplPK7XwVGmKqFoNR5TsDQ5zEFuaH+gPp6BOGGiRRxJvkDKAXMLi0ubjYztmQ0UmcPgsfn1KM6QEtkDkJh2d0f4Sv6Qm29v3MGF167PZENmMKhwPeyP7qyq0Qk+Xdh33eg90dLI99X6oEzGmS5/JH6jEyUnaERIkis= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=dpj/V96S; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="dpj/V96S" ARC-Seal: i=1; a=rsa-sha256; t=1739803746; cv=none; d=zohomail.com; s=zohoarc; b=j52ffYrdgTP2eQBJ49pGdUCBSCdvmGLXcPOWdDIKdoQweZa/3/fEak6cCG2HO34iVJuW4C4ZwRDn51NpJdkdcKy8FeyZYMd4hKFo4OyEiiaj/t82Fo9oAJ+ZiYWWpkIHNlOBYZMs+XrMjChdcRyTPzMfFWrnlFlCiIiwLLCXVks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803746; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=seuYo98AeaFca7POQcm0B/jpqa2QyKqq1zrS29bL+Ic=; b=N9wPr4aym1nJt/O5rm9WSXCnHq5pX1ae4mSxadF0tN+zoThFPCj/7WJwu/S3lhNTcFWdzYxcQFk+DNG+SO0FQ3w30HffMidEOOZr/NweiPABMp2D7YIaAjAKjPwaK0hyH2Mv51MxAQUABfbais6EQHi6uCKCMz7Ka+qTmOuXlD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803745; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=seuYo98AeaFca7POQcm0B/jpqa2QyKqq1zrS29bL+Ic=; b=dpj/V96SonBUNgP5Q/TviyDrReB7cTd4/wgvkcHybi/gbn7V9pIaHzl6bdzjDkp1 m3m/jt1OqeZAfiMAC1kTtpQOjp5rknUw6ta8li1LcgXDsd7Zhutu2R9JC6gyZwi8h15 BeIn5X6G3tl+tHhiO0BAn9KuUgFO6qDb+ZJnjkiU= Received: by mx.zohomail.com with SMTPS id 173980374316427.75530296649265; Mon, 17 Feb 2025 06:49:03 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 2/7] cxl/core: cxl_mem_sanitize() cleanup Date: Mon, 17 Feb 2025 22:48:23 +0800 Message-Id: <20250217144828.30651-3-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr0801122795f226f8f51db3ff794a656b000046a0d02f0b361dbf095587db9da9ae4d9262013105ee374cab:zu080112278a4417fcfbe9d77a2fc5be2f00007f4a866045a52dde8702c48203cbc2dec658b2337ccca872ef:rf0801122d6cfd8d2233f879107f64026f00005629bf270c07f4fbbc87f232c0e07406174f087f7d105e3af89d565de3a6b4:ZohoMail X-ZohoMailClient: External In cxl_mem_sanitize(), the down_read() and up_read() for cxl_region_rwsem can be simply replaced by a guard(rwsem_read), and the local variable 'rc' can be removed. Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield --- drivers/cxl/core/mbox.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 548564c770c0..0601297af0c9 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1222,23 +1222,19 @@ int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd) { struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); struct cxl_port *endpoint; - int rc; /* synchronize with cxl_mem_probe() and decoder write operations */ guard(device)(&cxlmd->dev); endpoint = cxlmd->endpoint; - down_read(&cxl_region_rwsem); + guard(rwsem_read)(&cxl_region_rwsem); /* * Require an endpoint to be safe otherwise the driver can not * be sure that the device is unmapped. */ if (endpoint && cxl_num_decoders_committed(endpoint) == 0) - rc = __cxl_mem_sanitize(mds, cmd); - else - rc = -EBUSY; - up_read(&cxl_region_rwsem); + return __cxl_mem_sanitize(mds, cmd); - return rc; + return -EBUSY; } static int add_dpa_res(struct device *dev, struct resource *parent, From patchwork Mon Feb 17 14:48:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978024 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 13726222596; Mon, 17 Feb 2025 14:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803778; cv=pass; b=ARoT0Hg2Aoygc8lAh61ig7Y85NsI2O4uS/BQ/jpI8cXvQ5LAdZofaM5k7ZlB3yLgv41cNE28bmRT2tigpBIWShjqW8SHn2QInz+TknKZ2mXYCDHxD7kLSaHnbezvVv9xikRlj8nbY5sNwhCs9yagsWzY01hHKmUR479nyaELWss= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803778; c=relaxed/simple; bh=at+D77xhBCQv3TXVg3YLeQXMmx8vzJzFzSGSD7CTzIE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fQ+I3Dn/sBGMGj+ksZXHcNq07AKAdv8omx5Kwzwl/eWqNJh3vintpBeTMWy0wzqueRjcf7oHWT69iWgDAD4b/F6LTpwa4TV6M4uKMZAevjWN1H2y6x6x5Yo8QTS9UreNuZyka17hymgjk91WWGxqagAWUrA7vNCvDiEotZ+/PeA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=bNdp1imx; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="bNdp1imx" ARC-Seal: i=1; a=rsa-sha256; t=1739803757; cv=none; d=zohomail.com; s=zohoarc; b=V5BDFT1m32CLMmL2uq1SctHV+ctx1pz2nANZZHfn51LJRBbDZ2hS2Mzk6zuORwHSGzRK5FjfqQBy4nb0NbkImk7ey1M81WU9Ypyzl6KmJWCJE5blyuDjhuNc0tCdBZJWhdokS+KCjR4NyEXRB5AkPdPNvEbUsiGHiVR044dmqd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803757; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=vZ4AbqtxvA/XdTRpEb45TpkQeirAJecUksAnhpHB9mU=; b=apiD/FBNNZcXgNr4ig2iF2Ap66d7NMDcWhis/DTr/ZRGnwzIBJhd3nDLCnZGU4mAYov/EMnZq6pugTuxm1gECIEWfGhVMZevByQ1ox6G1Xq/aBE3vdnvylqksBozxe8TvtQL3a87x+J2vYjanBBtayfBA99WUHJZqw7nItjNiYY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803757; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=vZ4AbqtxvA/XdTRpEb45TpkQeirAJecUksAnhpHB9mU=; b=bNdp1imxWypUPvISKAjv47gOIXN2DA7avYWQ6P1ABGAetlmQpf7ttz7AD9YTch/7 fFD15H+DaBnH9V+bFSg7hggAfMT7HT4HeWSPL0rPG7TDcLneYOd24vKYGi4e7evUrPK 9QjcP3fpY80ZEYjYiXGNXjqMW/6fbb1kVMWMmFuo= Received: by mx.zohomail.com with SMTPS id 1739803754315852.1927748164743; Mon, 17 Feb 2025 06:49:14 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 3/7] cxl/memdev: cxl_memdev_ioctl() cleanup Date: Mon, 17 Feb 2025 22:48:24 +0800 Message-Id: <20250217144828.30651-4-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr08011227957a81ebafd8ad2a52fb16fd00005d60d321eec5b6b4b9de04752d26e218e0e90f7e314d9a022e:zu08011227f8fed950e5bf5fe4bba566e700002b786b09415c7703ff58fedac56f79fdd79bfa2d332be5a5b8:rf0801122d215f26e1822a2759fb9c516800003e0f8b3723fc842170562d19aea6a0c8c35fccf454f63726b48dd5a8c568d6:ZohoMail X-ZohoMailClient: External In cxl_memdev_ioctl(), the down_read(&cxl_memdev_rwsem) and up_read(&cxl_memdev_rwsem) can be replaced by a guard(rwsem_read)(&cxl_memdev_rwsem), it helps to remove the open-coded up_read(&cxl_memdev_rwsem). Besides, the local var 'rc' can be also removed to make the code more cleaner. Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield --- drivers/cxl/core/memdev.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 98c05426aa4a..6f90dcd626f9 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -668,15 +668,13 @@ static long cxl_memdev_ioctl(struct file *file, unsigned int cmd, { struct cxl_memdev *cxlmd = file->private_data; struct cxl_dev_state *cxlds; - int rc = -ENXIO; - down_read(&cxl_memdev_rwsem); + guard(rwsem_read)(&cxl_memdev_rwsem); cxlds = cxlmd->cxlds; if (cxlds && cxlds->type == CXL_DEVTYPE_CLASSMEM) - rc = __cxl_memdev_ioctl(cxlmd, cmd, arg); - up_read(&cxl_memdev_rwsem); + return __cxl_memdev_ioctl(cxlmd, cmd, arg); - return rc; + return -ENXIO; } static int cxl_memdev_open(struct inode *inode, struct file *file) From patchwork Mon Feb 17 14:48:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978025 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 C40BA223324; Mon, 17 Feb 2025 14:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803791; cv=pass; b=PwEComnIMcifhr4WpC4VFwXb4Wdzyuy4pn/K1Z4npk9ME/vK0HYJrIuwoTJhvggorWxNf1lUUfbI4SVmnqltqs18YOMIhzNQRiZvacttE11iWhpp2VMhof1S5jErhWbg4h2sLFuW1eGYnq4fNXas60tdzPVTPQ56BuxXn6zVTCo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803791; c=relaxed/simple; bh=1FkAUqTty3d7vuzR1pxX8pP9dLgtx+UOp3YDgSeskPQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jtmA4X62mw0dMjr8cGic+XMyr5rISgmx6yOLvnF7qeKZJL4yA98WIukKiFYkLAIR76oS2trdNKUB+oSzZpPWDxD01/JBPzeah2wNR0M829p5abKBt3HpBn9wV7ZYYYvS5qGsw7O+A1SRK/9+cK0ao/wXsCtf2F5v/w8lozokwUk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=N8z7xsy/; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="N8z7xsy/" ARC-Seal: i=1; a=rsa-sha256; t=1739803768; cv=none; d=zohomail.com; s=zohoarc; b=GSWG37s5bdPqqHD2yv0ee+qYtutJS9eKVr+5mihTBg62anUJBgWJgtuJShR/aFK3vrfss80oVH4lU2XXiUMRfUAxR4sSBGEkXfQ+3uodl4VVPvT2vLAyh/GX3DoXzYBYSJeS/niZs6zS0dT43rqsYDQCzirGvvqdbguqbUbxgh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803768; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=+mlZk31zofzRORFSVPS6rIRxE3VbHvcdGYG1A+JhSGI=; b=LLOa6RkN0XViyLxA278ku8ZgnsNENLNkIdyK156MwYPgGdZ1Uxah8iK2KT34E/a5tMYPrRSaq7EmTXpuPb+ExLvQfDf879I3V9n7Y3DVd/PBpZ3DSzJmn4JE2GYQ1iWBv86LMN8P+EKCiAJfV3rLaDe7TybGzuD+mDcZbCcYq/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803767; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=+mlZk31zofzRORFSVPS6rIRxE3VbHvcdGYG1A+JhSGI=; b=N8z7xsy/ghBf6Tfr4E4Dx+W/qSJRZ4hvxZ4luT8l4qMDtVxPhjZmTBUvDNTqKSKb nvX2TZ16QFX/i70rwjmHp6EZ+WSVXvySoLiTN0wnzwEmTS2DoHedCmbBZzbLnTZgsDD +KObavXxKcZKtOQb98YpSJ4eNCfod40HYYh59IxQ= Received: by mx.zohomail.com with SMTPS id 1739803764974919.182094874602; Mon, 17 Feb 2025 06:49:24 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 4/7] cxl/core: Use guard() to drop the goto pattern of cxl_dpa_free() Date: Mon, 17 Feb 2025 22:48:25 +0800 Message-Id: <20250217144828.30651-5-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr080112278b6ecf97784c241d977590780000149296f73421664c9c5744797e1ff0253aa46d5c24bad258c8:zu080112278b7329716ba05e01e922103700005107c85808d8b7b15aded6999d45b6d804028dcedbb17aea80:rf0801122dc82ac33beabc0b24907af4a20000173845c03f0bb6a735fd29f16c2dcd59980b23bfa2ad5e4957fc266f5a146d:ZohoMail X-ZohoMailClient: External cxl_dpa_free() has a goto pattern to call up_write() for cxl_dpa_rwsem, it can be removed by using a guard() to replace the down_write() and up_write(). Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield --- drivers/cxl/core/hdm.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 4a578092377e..874a791f8292 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -382,35 +382,27 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled) { struct cxl_port *port = cxled_to_port(cxled); struct device *dev = &cxled->cxld.dev; - int rc; - down_write(&cxl_dpa_rwsem); - if (!cxled->dpa_res) { - rc = 0; - goto out; - } + guard(rwsem_write)(&cxl_dpa_rwsem); + if (!cxled->dpa_res) + return 0; if (cxled->cxld.region) { dev_dbg(dev, "decoder assigned to: %s\n", dev_name(&cxled->cxld.region->dev)); - rc = -EBUSY; - goto out; + return -EBUSY; } if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { dev_dbg(dev, "decoder enabled\n"); - rc = -EBUSY; - goto out; + return -EBUSY; } if (cxled->cxld.id != port->hdm_end) { dev_dbg(dev, "expected decoder%d.%d\n", port->id, port->hdm_end); - rc = -EBUSY; - goto out; + return -EBUSY; } + devm_cxl_dpa_release(cxled); - rc = 0; -out: - up_write(&cxl_dpa_rwsem); - return rc; + return 0; } int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, From patchwork Mon Feb 17 14:48:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978030 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 B78E22222D1; Mon, 17 Feb 2025 14:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803927; cv=pass; b=Pm5k5tXLIk0teZldC/6qsaBnKnVoj1tgK7yjcgo+RXEOalYkMve8BIbQVRkIzdV/mOKQjSmT2A3AKAM95bJWxrp7Kd7jpsVc6ULTvI89FoWN9E7/GVZF8bbEZCMc9MFNq+IjyTBNPKFGYgjWJI9bxxyBiQx/JG5wc6akTakSnKw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803927; c=relaxed/simple; bh=CMU0oC5OqZfOfX3TUGRzV6xGk9VpKd3fVn4+DmGjr/M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BegvAv4/BeaVtrArWs/IWy70W2FkTDQHPquprF3uGiIUbYw3bfkzQNUmb/QMaq5x8Jr6qajkRgTV07lLvVEYZh4p2lpOPeTLwignn/9Rnh+EMjubSqkRFKLltulcNMP6VKgOnVYW3oQ7WCc67F+IrVZF0VSWoz7bxMdifEtBX2Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=IfRtTPGq; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="IfRtTPGq" ARC-Seal: i=1; a=rsa-sha256; t=1739803778; cv=none; d=zohomail.com; s=zohoarc; b=Sh77v+CqXjwXA2ckIXYeC8GWKl+CoU17/Ij9jOtVfrYAJeMefPPRt6NTIsTaQ4F/TpGrv9uKsJjPSwX6Ctlx6W0unjbcnxzU0Skh6rtcUp55zDsFEgnVcFEuzLs+NhpPHFOw7l/ZyfrDTGxx76yF536LrwqpKmBQMciLhbE6DtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803778; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=UBTwBPzFp5F5/5KTauGoDs85/B0rlCeCpCRsH73OvuE=; b=kYwAFXa2zZ8w0ekdAF5Niy15pXsp3vf/BW71249Al8I1wCcUf5atjgWVklen1HC7CMNTTYaSpLGW2eI8DgTHfGk4H4Qiltw/1r5IFUNMiP+4eqWjH4GnjGQJZEGmQ0CjpL4ecoPNVutakhZyqarnLSfChauV2IZIyptNhFjOmRk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803777; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=UBTwBPzFp5F5/5KTauGoDs85/B0rlCeCpCRsH73OvuE=; b=IfRtTPGqfVpzOjZkgyXab2Sc32ZzpGfB29+yuyug7uz0FdxxCD+dYYdgh0/G7Fh6 NaJ15Giu+6zJWPdhyYWa51g93yzAYX81nN+FAkZ9bLeoDyoEVmxtPK7FiDpnNkW4/5v Ob8PQi5t3QyONzpmPzy2ilMEaI82muJ8HazKZRCw= Received: by mx.zohomail.com with SMTPS id 1739803775573102.290568107931; Mon, 17 Feb 2025 06:49:35 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 5/7] cxl/core: Use guard() to drop goto pattern of cxl_dpa_alloc() Date: Mon, 17 Feb 2025 22:48:26 +0800 Message-Id: <20250217144828.30651-6-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr080112275d074be819fc2935b176da3600009a1dd890bc7708c32f22f433548c65c354c38b6f46e7576260:zu080112275322b8c484c65ee0f1fd9bce0000c575d7b372fecf17294a5b12d881d8bbd98d9ff179e6fb94a5:rf0801122d280512da356b3612724f41be000055e6ca8760a22fc51ff0373fa823d38b8c2049a0d54ac02e8258514d71a86e:ZohoMail X-ZohoMailClient: External In cxl_dpa_alloc(), some checking and operations need to be protected by a rwsem called cxl_dpa_rwsem, so there is a goto pattern in cxl_dpa_alloc() to release the rwsem. The goto pattern can be optimized by using guard() to hold the rwsem. Creating a new function called __cxl_dpa_alloc() to include all checking and operations needed to be procted by cxl_dpa_rwsem. Using guard(rwsem_write()) to hold cxl_dpa_rwsem at the beginning of the new function. Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield Reviewed-by: Dan Williams --- drivers/cxl/core/hdm.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 874a791f8292..1edbf7873471 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -442,29 +442,25 @@ int cxl_dpa_set_mode(struct cxl_endpoint_decoder *cxled, return 0; } -int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) +static int __cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) { struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); resource_size_t free_ram_start, free_pmem_start; - struct cxl_port *port = cxled_to_port(cxled); struct cxl_dev_state *cxlds = cxlmd->cxlds; struct device *dev = &cxled->cxld.dev; resource_size_t start, avail, skip; struct resource *p, *last; - int rc; - down_write(&cxl_dpa_rwsem); + guard(rwsem_write)(&cxl_dpa_rwsem); if (cxled->cxld.region) { dev_dbg(dev, "decoder attached to %s\n", dev_name(&cxled->cxld.region->dev)); - rc = -EBUSY; - goto out; + return -EBUSY; } if (cxled->cxld.flags & CXL_DECODER_F_ENABLE) { dev_dbg(dev, "decoder enabled\n"); - rc = -EBUSY; - goto out; + return -EBUSY; } for (p = cxlds->ram_res.child, last = NULL; p; p = p->sibling) @@ -504,21 +500,24 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) skip = skip_end - skip_start + 1; } else { dev_dbg(dev, "mode not set\n"); - rc = -EINVAL; - goto out; + return -EINVAL; } if (size > avail) { dev_dbg(dev, "%pa exceeds available %s capacity: %pa\n", &size, cxl_decoder_mode_name(cxled->mode), &avail); - rc = -ENOSPC; - goto out; + return -ENOSPC; } - rc = __cxl_dpa_reserve(cxled, start, size, skip); -out: - up_write(&cxl_dpa_rwsem); + return __cxl_dpa_reserve(cxled, start, size, skip); +} + +int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, unsigned long long size) +{ + struct cxl_port *port = cxled_to_port(cxled); + int rc; + rc = __cxl_dpa_alloc(cxled, size); if (rc) return rc; From patchwork Mon Feb 17 14:48:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978031 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 AD277223328; Mon, 17 Feb 2025 14:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803936; cv=pass; b=aIEv1DqKBFg/8h747xEu/mOq+ezC3WzXREHsTbuUAzWXuYVOZBBw/n9UKewWSe4fShDeN917tNojKFYJDnib+9w/zcc/20I2KBfI2KsGReSvY3HLxDSak0zMAWW1n25LvbyQ4qK0EaUk60ABS/QEpT0s2Eq0aGeVMQCuQyv9ycU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803936; c=relaxed/simple; bh=RiB1oXhMD5rMP5CbSPhagMBU8X4ZPgknYiSKpVbHubI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KsuO1ZCjYWcRIFya3rxRG0aKomd6CCZaDQMUWJw5PEyO14VHylRxVfeJ7+l676IJXxgqVhiIaviVlr+9RjXWZtKQ9YI1kLWZHS1py53b5m/EikAre070Ini/ueZQHD8l0ULJqQDvzBrlpYmarBD9010awnXibJSyW9UNSz7hfI0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=drISJy0h; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="drISJy0h" ARC-Seal: i=1; a=rsa-sha256; t=1739803789; cv=none; d=zohomail.com; s=zohoarc; b=OEyDTQFE3PL/rMaep9wLKOvMx09kC1ebYIqwkfEFs5q/PyoohyLk3+W866ie3l2vNyceWc0N5A+86vO0bkUgZX+KP4VO51G6KfDxqr88BSXiTKNKuwyN/FPZAK/38QAMEACBX3xwHhZI96VR7qIxK4KuQJHYgYmKBkyqNBSFYoE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803789; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=fwSLwPfrZMT8HZvx/0S2Jc6bVi6NXmFLmVbTwY6Loqo=; b=YvJgL18afOj35blO2UZyfTByg+7cyNRntg8ni8b0dSFZFNT/y7lIk/IKbRT3tBQXSMO7iKoiQVRQM3TwTZclW6vTxCi5C7yQ/UhZkRanDARI9yTFVRcCqfASMqiN1Ucpax/etrss0CsA22l6tkYdCMKERqHKPA5l6CqHHDY5Bwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803789; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=fwSLwPfrZMT8HZvx/0S2Jc6bVi6NXmFLmVbTwY6Loqo=; b=drISJy0hhCXcxT/bnL634+Gju9y3gQzTDTaT5UiJXwPULhlRJh3FeN/QRxuURNG+ zJ/37drqtVrBCnH6n6LQLyujKkCjhNMGbc0FYcLDts68+LV5EAbFf9pLcCazfvE5zEY oQV3FMm9r29gcoChEXkq2I08i0FrtdVujNCRsHJU= Received: by mx.zohomail.com with SMTPS id 173980378657025.23360537786118; Mon, 17 Feb 2025 06:49:46 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming , Jonathan Cameron Subject: [PATCH v2 6/7] cxl/region: Drop goto pattern in cxl_dax_region_alloc() Date: Mon, 17 Feb 2025 22:48:27 +0800 Message-Id: <20250217144828.30651-7-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr080112272c5dc6440b0446e6588a766f00001b0dec5e1aa36b1ef08c2fff4b5f878ab81e8eaf7d6b074e9a:zu080112274dfe11115d82755fbbbc9214000048773d70501f33f8ddf947b8ee4fad21aac94e977a758c942a:rf0801122d0813314a8608b029609f6c1f000018e4b981a75ca902e9d6f3e6e096f74db99aaab4175851196d58a21a24b9b5:ZohoMail X-ZohoMailClient: External In cxl_dax_region_alloc(), there is a goto pattern to release the rwsem cxl_region_rwsem when the function returns, the down_read() and up_read can be replaced by a guard(rwsem_read) then the goto pattern can be removed. Reviewed-by: Jonathan Cameron Signed-off-by: Li Ming Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield --- drivers/cxl/core/region.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index d8a71f9f9fa5..320a3f218131 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3038,17 +3038,13 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) struct cxl_dax_region *cxlr_dax; struct device *dev; - down_read(&cxl_region_rwsem); - if (p->state != CXL_CONFIG_COMMIT) { - cxlr_dax = ERR_PTR(-ENXIO); - goto out; - } + guard(rwsem_read)(&cxl_region_rwsem); + if (p->state != CXL_CONFIG_COMMIT) + return ERR_PTR(-ENXIO); cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); - if (!cxlr_dax) { - cxlr_dax = ERR_PTR(-ENOMEM); - goto out; - } + if (!cxlr_dax) + return ERR_PTR(-ENOMEM); cxlr_dax->hpa_range.start = p->res->start; cxlr_dax->hpa_range.end = p->res->end; @@ -3061,8 +3057,6 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) dev->parent = &cxlr->dev; dev->bus = &cxl_bus_type; dev->type = &cxl_dax_region_type; -out: - up_read(&cxl_region_rwsem); return cxlr_dax; } From patchwork Mon Feb 17 14:48:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Ming X-Patchwork-Id: 13978032 Received: from sender4-pp-o94.zoho.com (sender4-pp-o94.zoho.com [136.143.188.94]) (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 1E1C42248AC; Mon, 17 Feb 2025 14:52:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.94 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803949; cv=pass; b=jjpMF52PiuwBPtvR0qr4kyo3NcwrVioWx/F1TV0NuF6CAvEnq9a46BOjofix7pvtiwrluVj9Zeew5oZMOQA2kcDbYHrrdeZW/teBN0xl0beYHdERbzd7BmB2JaBSrf5gDO1W0znbYiPHotOMWuJ/bZfFygGWrn17yCkIoboRT0s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739803949; c=relaxed/simple; bh=JRmCF9LjmJYKWivhjQ6n8IMZFxSXDeNdiP8wgPC7wg0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EkkZGQ5h2PeTNLYz7333gduhTT6310n1Xw+Yf2bS4icVps5TRLkmzLVBaNgsTMop9vkrL06p/f5NO5Hds9AsKS5rSYz3Ja6PbUDC/MM6Tn5TFSiD6nzecyGU5ZHxB5UZDSZG8YHaZjEYQrve5MZrYeVi5LVkBr6NE0DEAYL/QJ8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com; spf=pass smtp.mailfrom=zohomail.com; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b=TW/TVcc6; arc=pass smtp.client-ip=136.143.188.94 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=zohomail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zohomail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zohomail.com header.i=ming.li@zohomail.com header.b="TW/TVcc6" ARC-Seal: i=1; a=rsa-sha256; t=1739803806; cv=none; d=zohomail.com; s=zohoarc; b=UqiwUddfNdEJ/ycmxXdmA38GekVPzC7NL83fV3PdbunGGkpW6BZWqBg/mz4jExLuehulmOar8psrWw0AZbsH72dDH27ioAcXgTbXsgeHcZ6/rrK+tTd2mNjcbO2xbVWmAqf5A0pFyBRk7+poykB50JNs3/2ifC24z6Dl7xirPkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1739803806; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=u5TjcDD2fVC5Z7fmg3HTZT6iZIZPELI9FVatCCA70pE=; b=JCObFY58kyM/3qfU+hAY6rnwKW7vc+YW4EJSIFVrDEIYBrnt1IWnU5SsVQk2qb+aJ+nwSCz7UDsB0QUl6NQYQ3W8xl64UBR2HE9MMg2j71WMMuIfSZHFBwdsqAgaegonNS2m3xWjK/aDb2xJDxFxPEXZEePKmSuZGSPUv3x6idU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zohomail.com; spf=pass smtp.mailfrom=ming.li@zohomail.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1739803806; s=zm2022; d=zohomail.com; i=ming.li@zohomail.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID:Reply-To; bh=u5TjcDD2fVC5Z7fmg3HTZT6iZIZPELI9FVatCCA70pE=; b=TW/TVcc6KoDGSDzqzNLWxrpINcDFMI7E9zZAO83NE9Ib/LB7/BNAkA69CRhKCD6d 93doKC2o251DrvXKPZqiYwJTWJLFEbjIBzH3lgtaC8xKsCR51yPPrjuhxxDK4KycWja mphbbfrvlBGGnOzb889zmvUy7BLnwTRS+jLz5sac= Received: by mx.zohomail.com with SMTPS id 173980380247995.30722494540043; Mon, 17 Feb 2025 06:50:02 -0800 (PST) From: Li Ming To: dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Li Ming Subject: [PATCH v2 7/7] cxl/region: Drop goto pattern of construct_region() Date: Mon, 17 Feb 2025 22:48:28 +0800 Message-Id: <20250217144828.30651-8-ming.li@zohomail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250217144828.30651-1-ming.li@zohomail.com> References: <20250217144828.30651-1-ming.li@zohomail.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Feedback-ID: rr080112270a1b3a40a4862390f0c7011f0000a6533c9e532b319b72bcea67a4ff7b47a766f9ac6b7a87cf67:zu08011227637483a4a31eb2f0b8ceb2e6000059b8d4e13f7089160e231c8be7dbb43f030a73e70a3b9635e1:rf0801122d5c87afa6af03d5275597f33e000026a3925e33887a0b88a34465cb4731f8771e61e7a209610abb740fad050b8a:ZohoMail X-ZohoMailClient: External Some operations need to be protected by the cxl_region_rwsem in construct_region(). Currently, construct_region() uses down_write() and up_write() for the cxl_region_rwsem locking, so there is a goto pattern after down_write() invoked to release cxl_region_rwsem. construct region() can be optimized to remove the goto pattern. The changes are creating a new function called construct_auto_region() which will include all checking and operations protected by the cxl_region_rwsem, and using guard(rwsem_write) to replace down_write() and up_write() in construct_auto_region(). Signed-off-by: Li Ming Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Reviewed-by: Alison Schofield Reviewed-by: Dan Williams --- v2: - Rename __construct_region() to construct_auto_region(). (Jonathan and Dave) --- drivers/cxl/core/region.c | 71 +++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 320a3f218131..7a9e51aba9f4 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3216,49 +3216,31 @@ static int match_region_by_range(struct device *dev, const void *data) return 0; } -/* Establish an empty region covering the given HPA range */ -static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, - struct cxl_endpoint_decoder *cxled) +static int construct_auto_region(struct cxl_region *cxlr, + struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) { struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); - struct cxl_port *port = cxlrd_to_port(cxlrd); struct range *hpa = &cxled->cxld.hpa_range; struct cxl_region_params *p; - struct cxl_region *cxlr; struct resource *res; int rc; - do { - cxlr = __create_region(cxlrd, cxled->mode, - atomic_read(&cxlrd->region_id)); - } while (IS_ERR(cxlr) && PTR_ERR(cxlr) == -EBUSY); - - if (IS_ERR(cxlr)) { - dev_err(cxlmd->dev.parent, - "%s:%s: %s failed assign region: %ld\n", - dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), - __func__, PTR_ERR(cxlr)); - return cxlr; - } - - down_write(&cxl_region_rwsem); + guard(rwsem_write)(&cxl_region_rwsem); p = &cxlr->params; if (p->state >= CXL_CONFIG_INTERLEAVE_ACTIVE) { dev_err(cxlmd->dev.parent, "%s:%s: %s autodiscovery interrupted\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__); - rc = -EBUSY; - goto err; + return -EBUSY; } set_bit(CXL_REGION_F_AUTO, &cxlr->flags); res = kmalloc(sizeof(*res), GFP_KERNEL); - if (!res) { - rc = -ENOMEM; - goto err; - } + if (!res) + return -ENOMEM; *res = DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa), dev_name(&cxlr->dev)); @@ -3281,7 +3263,7 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, rc = sysfs_update_group(&cxlr->dev.kobj, get_cxl_region_target_group()); if (rc) - goto err; + return rc; dev_dbg(cxlmd->dev.parent, "%s:%s: %s %s res: %pr iw: %d ig: %d\n", dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), __func__, @@ -3290,14 +3272,39 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, /* ...to match put_device() in cxl_add_to_region() */ get_device(&cxlr->dev); - up_write(&cxl_region_rwsem); - return cxlr; + return 0; +} -err: - up_write(&cxl_region_rwsem); - devm_release_action(port->uport_dev, unregister_region, cxlr); - return ERR_PTR(rc); +/* Establish an empty region covering the given HPA range */ +static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, + struct cxl_endpoint_decoder *cxled) +{ + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); + struct cxl_port *port = cxlrd_to_port(cxlrd); + struct cxl_region *cxlr; + int rc; + + do { + cxlr = __create_region(cxlrd, cxled->mode, + atomic_read(&cxlrd->region_id)); + } while (IS_ERR(cxlr) && PTR_ERR(cxlr) == -EBUSY); + + if (IS_ERR(cxlr)) { + dev_err(cxlmd->dev.parent, + "%s:%s: %s failed assign region: %ld\n", + dev_name(&cxlmd->dev), dev_name(&cxled->cxld.dev), + __func__, PTR_ERR(cxlr)); + return cxlr; + } + + rc = construct_auto_region(cxlr, cxlrd, cxled); + if (rc) { + devm_release_action(port->uport_dev, unregister_region, cxlr); + return ERR_PTR(rc); + } + + return cxlr; } int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)