From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C0BB7F36BA7 for ; Sat, 11 Apr 2026 08:02:29 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4ft5jt4fWnz2ypW; Sat, 11 Apr 2026 18:02:10 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=172.234.252.31 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775894530; cv=none; b=U61sRoNUZuqAwAFBE8cVELdqHubjrapXC0EJWjlxhcnkuUtnp8j0CtRSCyNEX7WXmXy1frUo52414/Jc62pbD0v0flHXNlV7/bEu69jYvEXTAB5PlUPa/s10+Pbq+wpPpyGEWaH4CrIxQFmmBuilP3MwfDLdqQ9YYMnEoC2R3Psd8g8Jbt3z7MRCFlACM9d0P1x6+BRMObJ/XBxx7eLIEToFw9wQLlamn1JqI58jw8cUoHUAAjzxZI12uEFGTVcZNkHaSeXPprPHdag0Fz6cs9OY1n83/moKtgAemP2iTsqelsxOz85VzeVTYAGU3ST4QnUc1eUKaDVWMhWx4uX/OQ== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1775894530; c=relaxed/relaxed; bh=mCbrZ9cEa2ffcOKFTYY1hWjOtPoJOynRc3FM6uguhqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DqSFQSWJDpkCDvpdVi8ktHky5vAAYsEkHq/QXAi7a5mMGU+p5HDeoXhPilaj62712PO5dNtbiAjLTYcdtQEV+qL4YHEpUJmli2HH12SiUGNqmotooVekoe489HB/dXfIu03pgFMk9Ki6LPK+nRSsYPmHMny1aJNGBO9s9TNP6pi19XeG9piNO3X13XGyG/Z7G2r3i4T42FLy7F3niIvKg/XesGOVeYEjalartA8qnhSPp+HLIuE/dndmnfLTcxSHwaOIbntT5xdcOTUXMssgOmK/6AhTHjJ7LjifbgO37CsxQFFc0vrEW0j7jpmSEcvon6LTDKTUSHRM5nhXZqxLUQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=sX9GlRlQ; dkim-atps=neutral; spf=pass (client-ip=172.234.252.31; helo=sea.source.kernel.org; envelope-from=kwilczynski@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=sX9GlRlQ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=172.234.252.31; helo=sea.source.kernel.org; envelope-from=kwilczynski@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4ft5js64g8z2ymg for ; Sat, 11 Apr 2026 18:02:09 +1000 (AEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id B0A3443771; Sat, 11 Apr 2026 08:02:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B1B0C4CEF7; Sat, 11 Apr 2026 08:02:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775894527; bh=H0WndVWw8wLHCufLJXaP5uTZO+d0TQtPZDWQ71hp9UI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sX9GlRlQKtlstIWMrItda1yAZOGEnfnSjqtpwwnLNuixgU3SGTeNF86UNKiozdy0C 0IAUB7UqsCWAh9i9HuQoB6SSB+Q8HWCXMechhh6DrJkoIgqwOJVOLz6YMmiFsjIG+M o9bbauN+U3p5NyMOO80/8WsgQYvLAT2zl/ZgifW08FY/FN/0bj1lO66nr+Mx6idF4w QNDBX3nyozlW5Clf3LDuzHYphYFEcdvasmoKrUVNOA1JyGINKZpvx7s6PhFT++Ioqd j9y6wyt2yauwWw6fM/HbX7zAP7yHQpAIS+Ygtu3JRev0drhg9kKgcUK7T/3x8cGH9j 7WWtFinv/wWIg== From: =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Bjorn Helgaas , Manivannan Sadhasivam , Lorenzo Pieralisi , Magnus Lindholm , Matt Turner , Richard Henderson , Christophe Leroy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Dexuan Cui , =?UTF-8?q?Krzysztof=20Ha=C5=82asa?= , Lukas Wunner , "Oliver O'Halloran" , Saurabh Singh Sengar , Shuan He , Srivatsa Bhat , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 04/24] PCI/sysfs: Use BAR length in pci_llseek_resource() when attr->size is zero Date: Sat, 11 Apr 2026 08:01:28 +0000 Message-ID: <20260411080148.471335-5-kwilczynski@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260411080148.471335-1-kwilczynski@kernel.org> References: <20260411080148.471335-1-kwilczynski@kernel.org> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both legacy and resource attributes set .f_mapping = iomem_get_mapping, so the default generic_file_llseek() would consult iomem_inode for the file size, which knows nothing about the attribute. That is why this custom llseek callback exists. Currently, the legacy and resource attributes have .size set at creation time, as such, using the attr->size is sufficient. However, the upcoming static resource attributes will have .size == 0 set, since they are const, and the .bin_size callback will be used to provide the real size to kernfs instead. Thus, update pci_llseek_resource() to derive the file size from the BAR using pci_resource_len() instead of reading the attr->size directly. The custom pci_llseek_resource() helper has been added in commit 24de09c16f97 ("PCI: Implement custom llseek for sysfs resource entries"). Signed-off-by: Krzysztof WilczyƄski --- drivers/pci/pci-sysfs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 6783c6168445..73a9ae9d289b 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -909,11 +909,21 @@ static const struct attribute_group pci_dev_config_attr_group = { */ static __maybe_unused loff_t pci_llseek_resource(struct file *filep, - struct kobject *kobj __always_unused, + struct kobject *kobj, const struct bin_attribute *attr, loff_t offset, int whence) { - return fixed_size_llseek(filep, offset, whence, attr->size); + struct pci_dev *pdev; + int bar; + + if (attr->size) + return fixed_size_llseek(filep, offset, whence, attr->size); + + pdev = to_pci_dev(kobj_to_dev(kobj)); + bar = (unsigned long)attr->private; + + return fixed_size_llseek(filep, offset, whence, + pci_resource_len(pdev, bar)); } #ifdef HAVE_PCI_LEGACY -- 2.53.0