[{"id":3676669,"web_url":"http://patchwork.ozlabs.org/comment/3676669/","msgid":"<eca4c119-65a8-ac84-3869-4064aa1f0829@linux.intel.com>","list_archive_url":null,"date":"2026-04-13T11:33:29","subject":"Re: [PATCH v4 07/24] PCI/sysfs: Convert PCI resource files to static\n attributes","submitter":{"id":83553,"url":"http://patchwork.ozlabs.org/api/people/83553/","name":"Ilpo Järvinen","email":"ilpo.jarvinen@linux.intel.com"},"content":"On Sat, 11 Apr 2026, Krzysztof Wilczyński wrote:\n\n> Currently, the PCI resource files (resourceN, resourceN_wc) are\n> dynamically created by pci_create_sysfs_dev_files(), called from\n> both pci_bus_add_device() and the pci_sysfs_init() late_initcall,\n> with only a sysfs_initialized flag for synchronisation.  This has\n> caused \"duplicate filename\" warnings and boot panics when both\n> paths race on the same device.\n> \n> This is especially likely on Devicetree-based platforms, where the\n> PCI host controllers are platform drivers that probe via the driver\n> model, which can happen during or after the late_initcall.  As such,\n> pci_bus_add_device() and pci_sysfs_init() are more likely to overlap.\n> \n> Thus, convert to static const attributes with three attribute groups\n> (I/O, UC, WC), each with an .is_bin_visible callback that checks\n> resource flags, BAR length, and non_mappable_bars.  A .bin_size\n> callback provides pci_resource_len() to the kernfs node for correct\n> stat and lseek behaviour.\n> \n> As part of this conversion:\n> \n>   - Rename pci_read_resource_io() and pci_write_resource_io() to\n>     pci_read_resource() and pci_write_resource() since the callbacks\n>     are no longer I/O-specific in the static attribute context.\n> \n>   - Remove pci_create_resource_files(), pci_remove_resource_files(),\n>     and pci_create_attr() which are no longer needed.\n> \n>   - Move the __weak stubs outside the #if guard so they remain\n>     available for callers converted in subsequent commits.\n> \n> Platforms that do not define the HAVE_PCI_MMAP macro or the\n> ARCH_GENERIC_PCI_MMAP_RESOURCE macro, such as Alpha architecture,\n> continue using their platform-specific resource file creation.\n> \n> For reference, the dynamic creation dates back to the pre-Git era:\n> \n>   https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/drivers/pci/pci-sysfs.c?id=42298be0eeb5ae98453b3374c36161b05a46c5dc\n> \n> The write-combine support was added in commit 45aec1ae72fc (\"x86: PAT\n> export resource_wc in pci sysfs\").\n> \n> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>\n> ---\n>  drivers/pci/pci-sysfs.c | 242 +++++++++++++++++++++-------------------\n>  include/linux/pci.h     |   2 -\n>  2 files changed, 127 insertions(+), 117 deletions(-)\n> \n> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c\n> index ca0074674acc..2922905ff070 100644\n> --- a/drivers/pci/pci-sysfs.c\n> +++ b/drivers/pci/pci-sysfs.c\n> @@ -1200,14 +1200,14 @@ static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,\n>  #endif\n>  }\n>  \n> -static ssize_t pci_read_resource_io(struct file *filp, struct kobject *kobj,\n> +static ssize_t pci_read_resource(struct file *filp, struct kobject *kobj,\n>  \t\t\t\t    const struct bin_attribute *attr, char *buf,\n>  \t\t\t\t    loff_t off, size_t count)\n>  {\n>  \treturn pci_resource_io(filp, kobj, attr, buf, off, count, false);\n>  }\n>  \n> -static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj,\n> +static ssize_t pci_write_resource(struct file *filp, struct kobject *kobj,\n>  \t\t\t\t     const struct bin_attribute *attr, char *buf,\n>  \t\t\t\t     loff_t off, size_t count)\n>  {\n> @@ -1261,129 +1261,136 @@ static const struct bin_attribute dev_resource##_bar##_wc_attr = {\t\t\\\n>  \t.mmap = pci_mmap_resource_wc,\t\t\t\t\t\t\\\n>  }\n>  \n> -/**\n> - * pci_remove_resource_files - cleanup resource files\n> - * @pdev: dev to cleanup\n> - *\n> - * If we created resource files for @pdev, remove them from sysfs and\n> - * free their resources.\n> - */\n> -static void pci_remove_resource_files(struct pci_dev *pdev)\n> +static inline umode_t\n> +__pci_resource_attr_is_visible(struct kobject *kobj,\n> +\t\t\t       const struct bin_attribute *a,\n> +\t\t\t       int bar, bool write_combine,\n> +\t\t\t       unsigned long flags)\n>  {\n> -\tint i;\n> +\tstruct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));\n>  \n> -\tfor (i = 0; i < PCI_STD_NUM_BARS; i++) {\n> -\t\tstruct bin_attribute *res_attr;\n> -\n> -\t\tres_attr = pdev->res_attr[i];\n> -\t\tif (res_attr) {\n> -\t\t\tsysfs_remove_bin_file(&pdev->dev.kobj, res_attr);\n> -\t\t\tkfree(res_attr);\n> -\t\t}\n> -\n> -\t\tres_attr = pdev->res_attr_wc[i];\n> -\t\tif (res_attr) {\n> -\t\t\tsysfs_remove_bin_file(&pdev->dev.kobj, res_attr);\n> -\t\t\tkfree(res_attr);\n> -\t\t}\n> -\t}\n> -}\n> -\n> -static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)\n> -{\n> -\t/* allocate attribute structure, piggyback attribute name */\n> -\tint name_len = write_combine ? 13 : 10;\n> -\tstruct bin_attribute *res_attr;\n> -\tchar *res_attr_name;\n> -\tint retval;\n> -\n> -\tres_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);\n> -\tif (!res_attr)\n> -\t\treturn -ENOMEM;\n> -\n> -\tres_attr_name = (char *)(res_attr + 1);\n> -\n> -\tsysfs_bin_attr_init(res_attr);\n> -\tif (write_combine) {\n> -\t\tsprintf(res_attr_name, \"resource%d_wc\", num);\n> -\t\tres_attr->mmap = pci_mmap_resource_wc;\n> -\t} else {\n> -\t\tsprintf(res_attr_name, \"resource%d\", num);\n> -\t\tif (pci_resource_flags(pdev, num) & IORESOURCE_IO) {\n> -\t\t\tres_attr->read = pci_read_resource_io;\n> -\t\t\tres_attr->write = pci_write_resource_io;\n> -\t\t\tif (arch_can_pci_mmap_io())\n> -\t\t\t\tres_attr->mmap = pci_mmap_resource_uc;\n> -\t\t} else {\n> -\t\t\tres_attr->mmap = pci_mmap_resource_uc;\n> -\t\t}\n> -\t}\n> -\tif (res_attr->mmap) {\n> -\t\tres_attr->f_mapping = iomem_get_mapping;\n> -\t\t/*\n> -\t\t * generic_file_llseek() consults f_mapping->host to determine\n> -\t\t * the file size. As iomem_inode knows nothing about the\n> -\t\t * attribute, it's not going to work, so override it as well.\n> -\t\t */\n> -\t\tres_attr->llseek = pci_llseek_resource;\n> -\t}\n> -\tres_attr->attr.name = res_attr_name;\n> -\tres_attr->attr.mode = 0600;\n> -\tres_attr->size = pci_resource_len(pdev, num);\n> -\tres_attr->private = (void *)(unsigned long)num;\n> -\tretval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);\n> -\tif (retval) {\n> -\t\tkfree(res_attr);\n> -\t\treturn retval;\n> -\t}\n> -\n> -\tif (write_combine)\n> -\t\tpdev->res_attr_wc[num] = res_attr;\n> -\telse\n> -\t\tpdev->res_attr[num] = res_attr;\n> -\n> -\treturn 0;\n> -}\n> -\n> -/**\n> - * pci_create_resource_files - create resource files in sysfs for @dev\n> - * @pdev: dev in question\n> - *\n> - * Walk the resources in @pdev creating files for each resource available.\n> - */\n> -static int pci_create_resource_files(struct pci_dev *pdev)\n> -{\n> -\tint i;\n> -\tint retval;\n> -\n> -\t/* Skip devices with non-mappable BARs */\n>  \tif (pdev->non_mappable_bars)\n>  \t\treturn 0;\n>  \n> -\t/* Expose the PCI resources from this device as files */\n> -\tfor (i = 0; i < PCI_STD_NUM_BARS; i++) {\n> +\tif (!pci_resource_len(pdev, bar))\n> +\t\treturn 0;\n\nHi,\n\nDid you accidently forget to address some of the comments as I thought you \nwere agreeing to changing this to resource_assigned() but I found no \nresource_assigned() from entire series?","headers":{"Return-Path":"\n <linux-pci+bounces-52425-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=S0XvF9dk;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-pci+bounces-52425-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=\"S0XvF9dk\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=192.198.163.8","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.intel.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvQKF4BSzz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 21:33:53 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id CA0D830120D4\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 11:33:46 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 728C33BBA17;\n\tMon, 13 Apr 2026 11:33:44 +0000 (UTC)","from mgamail.intel.com (mgamail.intel.com [192.198.163.8])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id C11093264F7;\n\tMon, 13 Apr 2026 11:33:42 +0000 (UTC)","from fmviesa009.fm.intel.com ([10.60.135.149])\n  by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Apr 2026 04:33:42 -0700","from ijarvine-mobl1.ger.corp.intel.com (HELO localhost)\n ([10.245.245.63])\n  by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Apr 2026 04:33:33 -0700"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776080024; cv=none;\n b=Fh8cFIxoeYOcwBuYpOr5hiPoDNYYRWGwxPQq06MTjrW38OTpKqkTaBTuVcnyhMIqDZasZBgVlG67MaZwD22NrDkSrcP0ZCdE7Nrm1LeO45hqWCVHANJIWdcQkaPQSFtF7tJMOTTV2zdYG60XCVBodioT9N1Jc21nhuhImsUW5eg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776080024; c=relaxed/simple;\n\tbh=GTCKNZw5ZA4+F2UX1Lc+WkH6dsotMD/7hwFxEdmg10w=;\n\th=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References:\n\t MIME-Version:Content-Type;\n b=nKZ1woeI2Qd5JMM84SBze51LnyMdr27hUdQNDt5InRFCDNfObMZ0706iyhZerP/SQMLgijVAX2FZpf6Mm6DwZo2tMT0V0zK1B+R0d3CBGlGIl8soVppYHutE9F2WV3zBzWRJHkqQGIvCVnzhZ6Gu3yMmXt5axHZf/GkBbFZowq0=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com;\n spf=pass smtp.mailfrom=linux.intel.com;\n dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=S0XvF9dk; arc=none smtp.client-ip=192.198.163.8","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n  t=1776080023; x=1807616023;\n  h=from:date:to:cc:subject:in-reply-to:message-id:\n   references:mime-version;\n  bh=GTCKNZw5ZA4+F2UX1Lc+WkH6dsotMD/7hwFxEdmg10w=;\n  b=S0XvF9dks/smhol0At9wqXdLvLz1zsJ64MalZavuqJ7gqAx1wQkvpbqi\n   xYl0TEtEtZfbhpsv4j5DiWO2Tr2D4rGyCyiiALNNclsGCN4MSDznlBBfP\n   s6qP9SOm0L5sS/UqgcmO0rZK9NxL2Q/6i0c6N6MBkGe0DUJjw5uL5sZva\n   bO3d9+u8uV+0Q/laVccWAdz5nnftCRCJ4T2IIt/IcTg6hNexEVqx9OfdW\n   O6ejniuCfEcSQCFAG2N2WqPnP/Ex7Y3XAQTBQDwgWmdPzrrxQqhsqqNdc\n   zOqyju0cn2VeLW4EarqFJ32PtfgHKeN2tPF90naCZMPDwrDpLw5Tr4xj+\n   Q==;","X-CSE-ConnectionGUID":["nldj48pBRS2T44QSkc+tOQ==","9KDOc8NYQn+oZbaM1eeHMQ=="],"X-CSE-MsgGUID":["XcdLoJSQQxGGFmAbh+m1HA==","ASfdxeGQT8KxN8XgI6GeFA=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11757\"; a=\"94585522\"","E=Sophos;i=\"6.23,177,1770624000\";\n   d=\"scan'208\";a=\"94585522\"","E=Sophos;i=\"6.23,177,1770624000\";\n   d=\"scan'208\";a=\"223276752\""],"X-ExtLoop1":"1","From":"=?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com>","Date":"Mon, 13 Apr 2026 14:33:29 +0300 (EEST)","To":"=?iso-8859-2?q?Krzysztof_Wilczy=F1ski?= <kwilczynski@kernel.org>","cc":"Bjorn Helgaas <bhelgaas@google.com>, Bjorn Helgaas <helgaas@kernel.org>,\n  Manivannan Sadhasivam <mani@kernel.org>,\n  Lorenzo Pieralisi <lpieralisi@kernel.org>,\n  Magnus Lindholm <linmag7@gmail.com>, Matt Turner <mattst88@gmail.com>,\n  Richard Henderson <richard.henderson@linaro.org>,\n  Christophe Leroy <chleroy@kernel.org>,\n  Madhavan Srinivasan <maddy@linux.ibm.com>,\n  Michael Ellerman <mpe@ellerman.id.au>, Nicholas Piggin <npiggin@gmail.com>,\n  Dexuan Cui <decui@microsoft.com>,\n =?iso-8859-2?q?Krzysztof_Ha=B3asa?= <khalasa@piap.pl>,\n  Lukas Wunner <lukas@wunner.de>, Oliver O'Halloran <oohall@gmail.com>,\n  Saurabh Singh Sengar <ssengar@microsoft.com>,\n  Shuan He <heshuan@bytedance.com>,\n  Srivatsa Bhat <srivatsabhat@microsoft.com>, linux-pci@vger.kernel.org,\n  linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org","Subject":"Re: [PATCH v4 07/24] PCI/sysfs: Convert PCI resource files to static\n attributes","In-Reply-To":"<20260411080148.471335-8-kwilczynski@kernel.org>","Message-ID":"<eca4c119-65a8-ac84-3869-4064aa1f0829@linux.intel.com>","References":"<20260411080148.471335-1-kwilczynski@kernel.org>\n <20260411080148.471335-8-kwilczynski@kernel.org>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"8323328-991724749-1776080009=:962\""}}]