[{"id":3676668,"web_url":"http://patchwork.ozlabs.org/comment/3676668/","msgid":"<eca4c119-65a8-ac84-3869-4064aa1f0829@linux.intel.com>","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 <linuxppc-dev+bounces-19681-incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linuxppc-dev@lists.ozlabs.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=AmkRuOA7;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=2404:9400:21b9:f100::1; helo=lists.ozlabs.org;\n envelope-from=linuxppc-dev+bounces-19681-incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=patchwork.ozlabs.org)","lists.ozlabs.org;\n arc=none smtp.remote-ip=192.198.163.8","lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com","lists.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=AmkRuOA7;\n\tdkim-atps=neutral","lists.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=linux.intel.com\n (client-ip=192.198.163.8; helo=mgamail.intel.com;\n envelope-from=ilpo.jarvinen@linux.intel.com; receiver=lists.ozlabs.org)"],"Received":["from lists.ozlabs.org (lists.ozlabs.org\n [IPv6:2404:9400:21b9:f100::1])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvQK81nq7z1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 21:33:48 +1000 (AEST)","from boromir.ozlabs.org (localhost [127.0.0.1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4fvQK73b2zz2yjV;\n\tMon, 13 Apr 2026 21:33:47 +1000 (AEST)","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 lists.ozlabs.org (Postfix) with ESMTPS id 4fvQK56kwvz2yS9\n\tfor <linuxppc-dev@lists.ozlabs.org>; Mon, 13 Apr 2026 21:33:44 +1000 (AEST)","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=lists.ozlabs.org; s=201707; t=1776080027;\n\tcv=none;\n b=AmXCnJduXDG3u8pN58TRsbcvHlbttX+0EI2vq2CjVXxtJZGiGpHSaAQs7g4cYsa4or0gxAgc3uT7gtnvafh4t26tinT8vRlbD2mqv6b54YDXEdWowtvXhISLCFoYg/Ta6IuCt/KhOfdZuV+12Kaw2ZoGaU70gX9a2pIGA1aiWv5b7Dg4KzJ7/RZAvC4XINZOFxAxxIvO1uUv8/H3jO0VXdpK7AZ/WPq7Evmnr0ZpirAkDQcMldQlQ98vEotGoKgZd3Usz24a3QNUy+vD7OOgjLwnwDb0e1G6fkT1Qy56Arbx30unJWsRQU4CJxPx8yqJUmYJM8QIHSrOoCDSOWSWzA==","ARC-Message-Signature":"i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707;\n\tt=1776080027; c=relaxed/relaxed;\n\tbh=L5dcw1G24FMpjiJoJ/5rNv1Ogh6lKPKtCWj8N8/VhRU=;\n\th=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References:\n\t MIME-Version:Content-Type;\n b=J0rcbLmO7BMTLgdSDK9MnWX+xu7iqEkGvrLvin7JR4S1hn/Mw0Eo+/958ogr3akrckRcNtAbQhjLiH4hCTYEsLP0v8jL7L5DwMUpF90grfRoir5IFpWfI3De0dmXH8NoNNGozdN0QkZ9OMseX9E2GxCPoNAMTx/ObisduEvSyGksO6DtQdh7S2544wIzI6r+mcEaZ5pIi8RVT98Y4oIJ0i1X66Pcljg8Hp5PfIzNM91uyRnjOyKqZQgYlEZLwS9B7agRtVHKvaVXBKrmE+8A2SQBIs78PxuiImMoU3aVBLBSkWYQ6DfAZM7LKBxvV49JsQr5gy68v09Ph1OBnEJXug==","ARC-Authentication-Results":"i=1; lists.ozlabs.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com;\n dkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=AmkRuOA7; dkim-atps=neutral;\n spf=pass (client-ip=192.198.163.8; helo=mgamail.intel.com;\n envelope-from=ilpo.jarvinen@linux.intel.com;\n receiver=lists.ozlabs.org) smtp.mailfrom=linux.intel.com","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n  t=1776080027; x=1807616027;\n  h=from:date:to:cc:subject:in-reply-to:message-id:\n   references:mime-version;\n  bh=GTCKNZw5ZA4+F2UX1Lc+WkH6dsotMD/7hwFxEdmg10w=;\n  b=AmkRuOA7EHfY3tAzLsbYEDdsnNGJCPE9WJnt0KLMjXf8VDnSuAujRpWX\n   JinnVxQRE36DnAYMRwbq8arxhi5GzOFbUp4AyIFzIOpqFMwH6W5UkLoCx\n   M4ZaiCNnMNZdqlrLsTw4vN70ZUgIhAHx5e4jKK5PbJFfro/C6oqmV6VYo\n   6vfkMrCJwtdN3l0aqXBlUsDiYTKanZ3MvEisddn5l1UK5zZPRK1V1oYdO\n   04XUlItplszIsE9BglhiCGvZTUz11hl+zHA1KcxX5bqlUVPzQyRiDvKpu\n   L89irzIjbXtwRxeeMDTBgTSQHPbvX1DfiGfMJ5/njvMtgHlGjmFQq8AMd\n   g==;","X-CSE-ConnectionGUID":["w+SYoBqDT4SPHm1vJQ2Sqg==","9KDOc8NYQn+oZbaM1eeHMQ=="],"X-CSE-MsgGUID":["5nz5hSonS+aZzEvDDeKLnw==","ASfdxeGQT8KxN8XgI6GeFA=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11757\"; a=\"94585528\"","E=Sophos;i=\"6.23,177,1770624000\";\n   d=\"scan'208\";a=\"94585528\"","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>","X-Mailing-List":"linuxppc-dev@lists.ozlabs.org","List-Id":"<linuxppc-dev.lists.ozlabs.org>","List-Help":"<mailto:linuxppc-dev+help@lists.ozlabs.org>","List-Owner":"<mailto:linuxppc-dev+owner@lists.ozlabs.org>","List-Post":"<mailto:linuxppc-dev@lists.ozlabs.org>","List-Archive":"<https://lore.kernel.org/linuxppc-dev/>,\n  <https://lists.ozlabs.org/pipermail/linuxppc-dev/>","List-Subscribe":"<mailto:linuxppc-dev+subscribe@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-digest@lists.ozlabs.org>,\n  <mailto:linuxppc-dev+subscribe-nomail@lists.ozlabs.org>","List-Unsubscribe":"<mailto:linuxppc-dev+unsubscribe@lists.ozlabs.org>","Precedence":"list","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"8323328-991724749-1776080009=:962\"","X-Spam-Status":"No, score=-2.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,\n\tDKIM_VALID,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=disabled\n\tversion=4.0.1 OzLabs 8","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on lists.ozlabs.org"}}]