From patchwork Tue Jul 5 23:21:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12907195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 333B2C433EF for ; Tue, 5 Jul 2022 23:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbiGEXWN (ORCPT ); Tue, 5 Jul 2022 19:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbiGEXWM (ORCPT ); Tue, 5 Jul 2022 19:22:12 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B28193F0; Tue, 5 Jul 2022 16:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657063331; x=1688599331; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zm0KOQVEYYEWOhSmHB8yhZfj2F0Gg29XPhX+LCnTORc=; b=mdGOMkJ7d0uBXjLiAbhSyP1c1EpyP4APMNnYWw6HYRB4KrxGg3jJeVLR D3RRrxIZ5D+4ajhBvFBO1Ca7qqb7Zxy+vxBZjHLdSfpj4k2LmCHpm05G6 2v2jodirotfgEY1ib51xFyAJqJYtIBRwFBWuxbr/9K9uYUqPYk2tC+y4v sTsCol47M3BfKI+2CbtWSotrbRk64NS0T7mBGdKz5F2/YFZvq7AmqRTRy glyfJX4a0lcC3JOTwLI6/D0KZ/foJktbnW+WDlkh1GrlIgc2oKmwxDJLA Q/Dooof+X6TJBXUVFMY8ePuPiMYwHwETUa+4mL4+avZxDvLQpvcEx4KTg g==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="283593110" X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="283593110" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:11 -0700 X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="597455659" Received: from adiazinf-mobl.amr.corp.intel.com (HELO localhost) ([10.255.0.103]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:09 -0700 From: ira.weiny@intel.com To: Dan Williams , Matthew Wilcox Cc: Ira Weiny , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alison Schofield , Vishal Verma , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 1/3] xarray: Introduce devm_xa_init() Date: Tue, 5 Jul 2022 16:21:57 -0700 Message-Id: <20220705232159.2218958-2-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220705232159.2218958-1-ira.weiny@intel.com> References: <20220705232159.2218958-1-ira.weiny@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Ira Weiny Many devices may have arrays of resources which are allocated with device managed functions. The objects referenced by the XArray are therefore automatically destroyed without the need for the XArray. Introduce devm_xa_init() which takes care of the destruction of the XArray meta data automatically as well. Cc: Dan Williams Cc: Matthew Wilcox Signed-off-by: Ira Weiny --- The main issue I see with this is defining devm_xa_init() in device.h. This makes sense because a device is required to use the call. However, I'm worried about if users will find the call there vs including it in xarray.h? --- drivers/base/core.c | 20 ++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index 2eede2ec3d64..8c5c20a62744 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2609,6 +2609,26 @@ void devm_device_remove_groups(struct device *dev, } EXPORT_SYMBOL_GPL(devm_device_remove_groups); +static void xa_destroy_cb(void *xa) +{ + xa_destroy(xa); +} + +/** + * devm_xa_init() - Device managed initialization of an empty XArray + * @dev: The device this xarray is associated with + * @xa: XArray + * + * Context: Any context + * Returns: 0 on success, -errno if the action fails to be set + */ +int devm_xa_init(struct device *dev, struct xarray *xa) +{ + xa_init(xa); + return devm_add_action(dev, xa_destroy_cb, xa); +} +EXPORT_SYMBOL(devm_xa_init); + static int device_add_attrs(struct device *dev) { struct class *class = dev->class; diff --git a/include/linux/device.h b/include/linux/device.h index 073f1b0126ac..e06dc63e375b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -978,6 +979,8 @@ int __must_check devm_device_add_group(struct device *dev, void devm_device_remove_group(struct device *dev, const struct attribute_group *grp); +int devm_xa_init(struct device *dev, struct xarray *xa); + /* * Platform "fixup" functions - allow the platform to have their say * about devices and actions that the general device layer doesn't From patchwork Tue Jul 5 23:21:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12907197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A83AACCA47C for ; Tue, 5 Jul 2022 23:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232775AbiGEXWR (ORCPT ); Tue, 5 Jul 2022 19:22:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232650AbiGEXWP (ORCPT ); Tue, 5 Jul 2022 19:22:15 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E50D19C26; Tue, 5 Jul 2022 16:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657063335; x=1688599335; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K+6zhrfQatJA+7vvvGNeZ5EhrPDLmRMbBvly8QQTcho=; b=jGw7xr+EKA2kZIibMmh2l/t4fA/uEavqi5kM9yrHD2Mk4u7aDsFEVzIj PJ+DGvjqfz1DvyzHlEozn7C2VZICZhvQsJzVwnNfH90UKBdgqBtSa09ti zeU3bUhJe+LcP8yXz0iEFdptWtjfEtYC5eRdhvrII1Uolt4GuvmqXXtia JxlN7g5e6dR4UWbnnwnDHUsS03rsnhPdWnGe7ZzsUjL9x275pAsQbHAST SM7T2ZWdRk/65vUgat1805VlsZxNrGV45LBBbBhVozv21pjYo74rKX0S5 FDU1jTC5K0SGfa43cl6NUlMtAz8vH71bJJBe8prnHcnihRhCI2z7vJVQY A==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="263987402" X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="263987402" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:15 -0700 X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="660731827" Received: from adiazinf-mobl.amr.corp.intel.com (HELO localhost) ([10.255.0.103]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:12 -0700 From: ira.weiny@intel.com To: Dan Williams , Matthew Wilcox Cc: Ira Weiny , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alison Schofield , Vishal Verma , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 2/3] pci/doe: Use devm_xa_init() Date: Tue, 5 Jul 2022 16:21:58 -0700 Message-Id: <20220705232159.2218958-3-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220705232159.2218958-1-ira.weiny@intel.com> References: <20220705232159.2218958-1-ira.weiny@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Ira Weiny The XArray being used to store the protocols does not even store allocated objects. Use devm_xa_init() to automatically destroy the XArray when the PCI device goes away. Signed-off-by: Ira Weiny --- drivers/pci/doe.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index 0b02f33ef994..aa36f459d375 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -386,13 +386,6 @@ static int pci_doe_cache_protocols(struct pci_doe_mb *doe_mb) return 0; } -static void pci_doe_xa_destroy(void *mb) -{ - struct pci_doe_mb *doe_mb = mb; - - xa_destroy(&doe_mb->prots); -} - static void pci_doe_destroy_workqueue(void *mb) { struct pci_doe_mb *doe_mb = mb; @@ -440,11 +433,8 @@ struct pci_doe_mb *pcim_doe_create_mb(struct pci_dev *pdev, u16 cap_offset) doe_mb->pdev = pdev; doe_mb->cap_offset = cap_offset; init_waitqueue_head(&doe_mb->wq); - - xa_init(&doe_mb->prots); - rc = devm_add_action(dev, pci_doe_xa_destroy, doe_mb); - if (rc) - return ERR_PTR(rc); + if (devm_xa_init(dev, &doe_mb->prots)) + return ERR_PTR(-ENOMEM); doe_mb->work_queue = alloc_ordered_workqueue("DOE: [%x]", 0, doe_mb->cap_offset); From patchwork Tue Jul 5 23:21:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 12907198 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0439FC433EF for ; Tue, 5 Jul 2022 23:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232926AbiGEXW0 (ORCPT ); Tue, 5 Jul 2022 19:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232865AbiGEXWY (ORCPT ); Tue, 5 Jul 2022 19:22:24 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D2201A3A7; Tue, 5 Jul 2022 16:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657063340; x=1688599340; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pXVHNJCtIuqHam3NNieA0W34pcZC7c81/cpdnlVw4AQ=; b=DtUW+pxk6IlycrHJ6KZ9WgjNHzkdzGfKCp/kdLbk+qL590Hfu3rl5W1A GDnKPmajYtgC2bPadaKMjL2G+9RJlNAdJHb3quzwTOovHedV3FiovNMrC +TtqTjyk8L8tMtbqBsf0j9/P1ni5zuhIHNr3ha1UKN+cztaYEaS6QL/K8 sOwA+qCUKT4Jk4rJV+1F1DXNYCiKy/k8CuSxVSeAGyUuGSCLg7nHpGdUS p2MaaenU1otM6ujRTqU+ooQD8ZOT2N2euNUCz4yLqzJyeH448STlLg+Uu lJYOkJdAg0l8TurNKMeMCDhSVMkXsNT0sBVvn87pWoWBZgOe2WHD1/5oY w==; X-IronPort-AV: E=McAfee;i="6400,9594,10399"; a="345250085" X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="345250085" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:20 -0700 X-IronPort-AV: E=Sophos;i="5.92,248,1650956400"; d="scan'208";a="735338613" Received: from adiazinf-mobl.amr.corp.intel.com (HELO localhost) ([10.255.0.103]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2022 16:22:16 -0700 From: ira.weiny@intel.com To: Dan Williams , Matthew Wilcox Cc: Ira Weiny , Greg Kroah-Hartman , "Rafael J. Wysocki" , Alison Schofield , Vishal Verma , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 3/3] CXL/doe: Use devm_xa_init() Date: Tue, 5 Jul 2022 16:21:59 -0700 Message-Id: <20220705232159.2218958-4-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220705232159.2218958-1-ira.weiny@intel.com> References: <20220705232159.2218958-1-ira.weiny@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Ira Weiny The DOE mailboxes are all allocated with device managed calls. Therefore, the XArray can go away when the device goes away. Use devm_xa_init() and remove the callback needed for xa_destroy(). Signed-off-by: Ira Weiny --- drivers/cxl/pci.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 6228c95fd142..adb8198fc6ad 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -387,11 +387,6 @@ static int cxl_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type, return rc; } -static void cxl_pci_destroy_doe(void *mbs) -{ - xa_destroy(mbs); -} - static void devm_cxl_pci_create_doe(struct cxl_dev_state *cxlds) { struct device *dev = cxlds->dev; @@ -446,8 +441,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (IS_ERR(cxlds)) return PTR_ERR(cxlds); - xa_init(&cxlds->doe_mbs); - if (devm_add_action(&pdev->dev, cxl_pci_destroy_doe, &cxlds->doe_mbs)) + if (devm_xa_init(&pdev->dev, &cxlds->doe_mbs)) return -ENOMEM; cxlds->serial = pci_get_dsn(pdev);