From patchwork Sat Jun 26 12:57:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12346441 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E51BC49EA7 for ; Sat, 26 Jun 2021 12:57:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E14B361C30 for ; Sat, 26 Jun 2021 12:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbhFZNAB (ORCPT ); Sat, 26 Jun 2021 09:00:01 -0400 Received: from mail-ej1-f46.google.com ([209.85.218.46]:38851 "EHLO mail-ej1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbhFZNAB (ORCPT ); Sat, 26 Jun 2021 09:00:01 -0400 Received: by mail-ej1-f46.google.com with SMTP id hq39so19806894ejc.5 for ; Sat, 26 Jun 2021 05:57:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xsjHsDPdWs8TcY1m0N+2WCt8b2rnx8PsMgsqmc5Y+4A=; b=hapfOcYhLWlWFqFVxyZU12tEpoVklXWr+/NgYUNuNXeMHY6muQ/o7aKVHDNNi6fobS /OnlIJzAHgwWzdSVx7MBi5oJ4MuS1vw5tjcrnS5gRME5CjbPUMgepawnDc2W4f0yMab/ rpySSSZ7HgP4qhokJ2tY74j8ezAFOiwW3NzhVAuQtZTltz4LBqgBkArRq/Biu7S9OTuF WWT0Ukz6keSpE2lkVkvB7rS0EVav/ztkmgFsjwzI592z8qvfRqekOD4BqvQtJA+Pd0eD GPtxAdkoo9dWexIbEKLAAblg9q33rm/dYYBxEYJ/3cG8wOfp0DHHj8S/WX148PvLnNbZ fg3Q== X-Gm-Message-State: AOAM532eZ3lM7466tNcWr7o9yFemOQQnzQg0Xt1IKP/PUH0b6f6sl5x/ Jr0tmm/F7vaoSRYgaNm64pA= X-Google-Smtp-Source: ABdhPJzxEoD+LvlwKNwPPHNake4JrDGHfuTkH5IhghUt/R010KPmYuzVRMCHhxvS5TBCq9zVmB0NNQ== X-Received: by 2002:a17:906:9bd5:: with SMTP id de21mr15741797ejc.554.1624712258438; Sat, 26 Jun 2021 05:57:38 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id e7sm3755748ejm.93.2021.06.26.05.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Jun 2021 05:57:38 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Dan Williams , Greg Kroah-Hartman , Daniel Vetter , Kees Cook , =?utf-8?q?Pali_Roh=C3=A1r?= , "Oliver O'Halloran" , linux-pci@vger.kernel.org Subject: [PATCH v2 1/3] sysfs: Invoke iomem_get_mapping() from the sysfs open callback Date: Sat, 26 Jun 2021 12:57:33 +0000 Message-Id: <20210626125735.2868256-2-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210626125735.2868256-1-kw@linux.com> References: <20210626125735.2868256-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Defer invocation of the iomem_get_mapping() to the sysfs open callback so that it can be executed as needed when the binary sysfs object has been accessed. To do that, convert the "mapping" member of the struct bin_attribute from a pointer to the struct address_space into a function pointer with a signature that requires the same return type, and then updates the sysfs_kf_bin_open() to invoke provided function should the function pointer be valid. Thus, this change removes the need for the fs_initcalls to complete before any other sub-system that uses the iomem_get_mapping() would be able to invoke it safely without leading to a failure and an Oops related to an invalid iomem_get_mapping() access. Suggested-by: Dan Williams Signed-off-by: Dan Williams Signed-off-by: Krzysztof Wilczyński Reported-by: kernel test robot --- fs/sysfs/file.c | 2 +- include/linux/sysfs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 9aefa7779b29..a3ee4c32a264 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -175,7 +175,7 @@ static int sysfs_kf_bin_open(struct kernfs_open_file *of) struct bin_attribute *battr = of->kn->priv; if (battr->mapping) - of->file->f_mapping = battr->mapping; + of->file->f_mapping = battr->mapping(); return 0; } diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index d76a1ddf83a3..fbb7c7df545c 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -170,7 +170,7 @@ struct bin_attribute { struct attribute attr; size_t size; void *private; - struct address_space *mapping; + struct address_space *(*mapping)(void); ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, From patchwork Sat Jun 26 12:57:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12346445 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39309C49EA5 for ; Sat, 26 Jun 2021 12:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1768861C34 for ; Sat, 26 Jun 2021 12:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229850AbhFZNAE (ORCPT ); Sat, 26 Jun 2021 09:00:04 -0400 Received: from mail-ej1-f42.google.com ([209.85.218.42]:40582 "EHLO mail-ej1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbhFZNAC (ORCPT ); Sat, 26 Jun 2021 09:00:02 -0400 Received: by mail-ej1-f42.google.com with SMTP id d16so16342296ejm.7 for ; Sat, 26 Jun 2021 05:57:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KeHsd8nXNureHN0+p+LqLfCUcfld/0+7qss7Qnv1OLo=; b=KYy7R0OAB7BhfdZn977u6cF92Qa1PUqvG+ruMCpjunGryaiULjHVyW4k+kYawkU1M/ 8NZdZguV0u6Z/LCzxJ5AEZhJK4Tym7Xa4bN6vJWyNy3QSrzoFEPM/gpe6xNlStEmFHpt Es6unKDH3ea9nMt1e7LtFUMfTclQT3D41OOUCyP83K/8nr+MgqoUjBCPidhKqF6qG9vE HhhH2cW0rH4g/dv309ZhbergGDPpTnIfluqxqYgmZrCCRDGmenUjpnoUgTMVWMXqrCHK 5b//tjWs9C459Yrxpc49Zh6FgcQg+QEjAZDHQJ573EnMbjqUNWTM8t6YaVXrDpYWtUGd IWCg== X-Gm-Message-State: AOAM533F8Ym+RSR0DAqe0qLxbcuLnzMiliMzMrNy+rSHmuZ7ylAi4iJI 48tAApck/oXY66wDuioxgz0= X-Google-Smtp-Source: ABdhPJwaeB6yVPvDBSSbLAEayKoBl0l09E9yqjjyRosJtZTLxApp/8q4lv6uN8aunHoBy/bUdpb5XA== X-Received: by 2002:a17:906:ae57:: with SMTP id lf23mr1920636ejb.205.1624712259453; Sat, 26 Jun 2021 05:57:39 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id e7sm3755748ejm.93.2021.06.26.05.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Jun 2021 05:57:39 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Dan Williams , Greg Kroah-Hartman , Daniel Vetter , Kees Cook , =?utf-8?q?Pali_Roh=C3=A1r?= , "Oliver O'Halloran" , linux-pci@vger.kernel.org Subject: [PATCH v2 2/3] PCI/sysfs: Pass iomem_get_mapping() as a function pointer Date: Sat, 26 Jun 2021 12:57:34 +0000 Message-Id: <20210626125735.2868256-3-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210626125735.2868256-1-kw@linux.com> References: <20210626125735.2868256-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The struct bin_attribute requires the "mapping" member to be a function pointer with a signature requiring the return type to be a pointer to the struct address_space. Thus, convert every invocation of iomem_get_mapping() into a function pointer assignment, therefore allowing for the iomem_get_mapping() invocation to be deferred to when the sysfs open callback runs. Suggested-by: Dan Williams Signed-off-by: Krzysztof Wilczyński Reviewed-by: Dan Williams --- drivers/pci/pci-sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index beb8d1f4fafe..cff1c121eb08 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -965,7 +965,7 @@ void pci_create_legacy_files(struct pci_bus *b) b->legacy_io->read = pci_read_legacy_io; b->legacy_io->write = pci_write_legacy_io; b->legacy_io->mmap = pci_mmap_legacy_io; - b->legacy_io->mapping = iomem_get_mapping(); + b->legacy_io->mapping = iomem_get_mapping; pci_adjust_legacy_attr(b, pci_mmap_io); error = device_create_bin_file(&b->dev, b->legacy_io); if (error) @@ -978,7 +978,7 @@ void pci_create_legacy_files(struct pci_bus *b) b->legacy_mem->size = 1024*1024; b->legacy_mem->attr.mode = 0600; b->legacy_mem->mmap = pci_mmap_legacy_mem; - b->legacy_io->mapping = iomem_get_mapping(); + b->legacy_io->mapping = iomem_get_mapping; pci_adjust_legacy_attr(b, pci_mmap_mem); error = device_create_bin_file(&b->dev, b->legacy_mem); if (error) @@ -1195,7 +1195,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) } } if (res_attr->mmap) - res_attr->mapping = iomem_get_mapping(); + res_attr->mapping = iomem_get_mapping; res_attr->attr.name = res_attr_name; res_attr->attr.mode = 0600; res_attr->size = pci_resource_len(pdev, num); From patchwork Sat Jun 26 12:57:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12346443 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4852FC49EA6 for ; Sat, 26 Jun 2021 12:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2556C61C38 for ; Sat, 26 Jun 2021 12:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbhFZNAE (ORCPT ); Sat, 26 Jun 2021 09:00:04 -0400 Received: from mail-ej1-f44.google.com ([209.85.218.44]:44971 "EHLO mail-ej1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbhFZNAD (ORCPT ); Sat, 26 Jun 2021 09:00:03 -0400 Received: by mail-ej1-f44.google.com with SMTP id n2so8681954eju.11 for ; Sat, 26 Jun 2021 05:57:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m/9RgNe62o+MABqNxYIkb3XyaCH+OLLdVkKO/3a82KM=; b=YDqerCYKV3paiYj1yL2HP49cJ50wXHb0PXpY25SW9UALkEF4wprD5IUWl3fiVq3YI1 30ECtqV8uWml/KuduyrWemRONIOHbXmqFIR8tH8/DONv8E2DNCI9xDsw9R80A7i3jb+T JF23kQyJTFy9XwLEdYO0ZDFx4UeJ8IpiAn+OVQp8ckfUnC98YdEvlOQULDUqLLsrkIDX NQ1aSeIOUANSqNgjhjI2yeq4Qg3EOUeFicMgULeOrtpvPARnJJ29zok7x9k+Jb0B60ii 5jbGB22aJ5X4STrn6n/CrzFv1cMKPlxZzsw57nPO/mpb8tb07PFZSO1gvIAqBwOPrueS AmuQ== X-Gm-Message-State: AOAM532tPkOgwv0Jr3LoXCJbeLVIlLSNul1k0i00cJVQ2cR0sXTlLza0 yCjYmAXZn7JEc0FJ72UMkRe6CY7pSo5CUQ== X-Google-Smtp-Source: ABdhPJyAO22+98TU15rsxIPrIvsDPacKmQcC8yoFO+Mz7XbwY89uHVCtG9mJtyWjl+VwQewl9/mc/A== X-Received: by 2002:a17:906:c302:: with SMTP id s2mr15800173ejz.151.1624712260448; Sat, 26 Jun 2021 05:57:40 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id e7sm3755748ejm.93.2021.06.26.05.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Jun 2021 05:57:40 -0700 (PDT) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Dan Williams , Greg Kroah-Hartman , Daniel Vetter , Kees Cook , =?utf-8?q?Pali_Roh=C3=A1r?= , "Oliver O'Halloran" , linux-pci@vger.kernel.org Subject: [PATCH v2 3/3] sysfs: Rename struct bin_attribute member to f_mapping Date: Sat, 26 Jun 2021 12:57:35 +0000 Message-Id: <20210626125735.2868256-4-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210626125735.2868256-1-kw@linux.com> References: <20210626125735.2868256-1-kw@linux.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There are two users of iomem_get_mapping(), the struct file and struct bin_attribute. The former has a member called "f_mapping" and the latter has a member called "mapping", and both are poniters to struct address_space. Rename struct bin_attribute member to "f_mapping" to keep both meaning and the usage consistent with other users of iomem_get_mapping(). Signed-off-by: Krzysztof Wilczyński --- drivers/pci/pci-sysfs.c | 6 +++--- fs/sysfs/file.c | 4 ++-- include/linux/sysfs.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index cff1c121eb08..26cef98d8352 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -965,7 +965,7 @@ void pci_create_legacy_files(struct pci_bus *b) b->legacy_io->read = pci_read_legacy_io; b->legacy_io->write = pci_write_legacy_io; b->legacy_io->mmap = pci_mmap_legacy_io; - b->legacy_io->mapping = iomem_get_mapping; + b->legacy_io->f_mapping = iomem_get_mapping; pci_adjust_legacy_attr(b, pci_mmap_io); error = device_create_bin_file(&b->dev, b->legacy_io); if (error) @@ -978,7 +978,7 @@ void pci_create_legacy_files(struct pci_bus *b) b->legacy_mem->size = 1024*1024; b->legacy_mem->attr.mode = 0600; b->legacy_mem->mmap = pci_mmap_legacy_mem; - b->legacy_io->mapping = iomem_get_mapping; + b->legacy_io->f_mapping = iomem_get_mapping; pci_adjust_legacy_attr(b, pci_mmap_mem); error = device_create_bin_file(&b->dev, b->legacy_mem); if (error) @@ -1195,7 +1195,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) } } if (res_attr->mmap) - res_attr->mapping = iomem_get_mapping; + res_attr->f_mapping = iomem_get_mapping; res_attr->attr.name = res_attr_name; res_attr->attr.mode = 0600; res_attr->size = pci_resource_len(pdev, num); diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index a3ee4c32a264..d019d6ac6ad0 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c @@ -174,8 +174,8 @@ static int sysfs_kf_bin_open(struct kernfs_open_file *of) { struct bin_attribute *battr = of->kn->priv; - if (battr->mapping) - of->file->f_mapping = battr->mapping(); + if (battr->f_mapping) + of->file->f_mapping = battr->f_mapping(); return 0; } diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index fbb7c7df545c..fa5de9b1fa4a 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -170,7 +170,7 @@ struct bin_attribute { struct attribute attr; size_t size; void *private; - struct address_space *(*mapping)(void); + struct address_space *(*f_mapping)(void); ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,