From patchwork Fri Jun 25 23:31:17 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: 12346001 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,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 8DD96C48BC2 for ; Fri, 25 Jun 2021 23:31:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EB536197D for ; Fri, 25 Jun 2021 23:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbhFYXdn (ORCPT ); Fri, 25 Jun 2021 19:33:43 -0400 Received: from mail-ej1-f54.google.com ([209.85.218.54]:35467 "EHLO mail-ej1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhFYXdm (ORCPT ); Fri, 25 Jun 2021 19:33:42 -0400 Received: by mail-ej1-f54.google.com with SMTP id gn32so17686377ejc.2 for ; Fri, 25 Jun 2021 16:31:21 -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=6vG+NOqMTvgE/MrGwqlyoFMFVmU3GLHtwmmG0GVPzgE=; b=UMeo9je+ABGj/DOjfUAkZnwv/ndR8O7P4uY9tMxdZisxc/js3zI4JsijSrxN+0z0rS 8F5eGxBxv1jS8W79Dwl45xhU1e1hafdaYUtwDJDQBDZyJ+EjZQybGNLQbxRxG7lp7SRU Vip9Nxxj6HtyqRtxmmucwJihc16CdcRUVjvvYWNurCd4H9MT/DZ+Txpjh4wRTkQ+Mq05 kFQl7DOqAUmQSdgGvDvZ9IjFuW0ZVvL5Dv4ldFvzyQ3gWkHmIn8Q/zA6Nqgz97W5hKOf Gd8iZm9MJGByErtbYjFD4G7nA0in7EWCUb/EouuYPhBEb9100ZsSdDc9jQrou+gf2Wfo V9+g== X-Gm-Message-State: AOAM532S2jC6yoferbRkBUCSBdszg16d6ZikX8u6qgdXQKzDJW4SxgaE syKKAGTSEqwdtE0A0RR/SFs= X-Google-Smtp-Source: ABdhPJyhzLSmbfepP9uTnTKlqSbzsBTAMJbFE6jFTi5A9gyDsHLFm18ozXZr4vGXOIubIGSGZmZTxA== X-Received: by 2002:a17:906:698a:: with SMTP id i10mr13342417ejr.499.1624663880713; Fri, 25 Jun 2021 16:31:20 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id b8sm4741015edr.42.2021.06.25.16.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 16:31:20 -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 1/2] sysfs: Invoke iomem_get_mapping() from the sysfs open callback Date: Fri, 25 Jun 2021 23:31:17 +0000 Message-Id: <20210625233118.2814915-2-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210625233118.2814915-1-kw@linux.com> References: <20210625233118.2814915-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. Co-authored-by: Dan Williams Suggested-by: Dan Williams Signed-off-by: Krzysztof Wilczyński Signed-off-by: Dan Williams --- 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 Fri Jun 25 23:31:18 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: 12346005 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,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 60A81C2B9F4 for ; Fri, 25 Jun 2021 23:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42B1861954 for ; Fri, 25 Jun 2021 23:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbhFYXdr (ORCPT ); Fri, 25 Jun 2021 19:33:47 -0400 Received: from mail-ed1-f54.google.com ([209.85.208.54]:40933 "EHLO mail-ed1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbhFYXdr (ORCPT ); Fri, 25 Jun 2021 19:33:47 -0400 Received: by mail-ed1-f54.google.com with SMTP id t3so15617740edc.7 for ; Fri, 25 Jun 2021 16:31:23 -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=4GSicSMy/nF6trnS/MfRL+W4ghg4phn0UKLi5jH9tX0=; b=dHh2I8uFDjmv4hg0aVa6hD6TImzsFuNkpVoNOvplAZVO9D0jo7r2weQksRFqtoJi7O os8MbiSi4AXSSRjaEqwDWU/qgRPI3vHjG4tsEAMsGSNSw8IXjClSy/NfFm9rDx2jlnps DdeNFZ/M4W/9jb+BarOz5sZPz3xd06rD0aoMMzQscGz/JdVp778/0ELl/hujJ6pU3uV8 PvKdtBnmcFm4LwTz+9vR7Bao6PkLCXsTnmV9zjso5Z2VbllSfzrxcU6Luxn5YcfsROME hqBLyMjLxhQKq5sRbxWRSsJf+o/3iU/V07hp64nj3SLxmwPU6IXTszU4g4COvGOTmCry BKGA== X-Gm-Message-State: AOAM530NnrLF4MyDi2HL0pIZxHtega6/guB4yFMiBHrnU2FJEpETGf6N 2L2lajTXoqtVy7hoD5BMztw= X-Google-Smtp-Source: ABdhPJxcwVf9Ujl44620E7ruXJyLFgSSTjsl1l7fOmqWeKzz9Qf8o+1gglnW9qFQ+OBy56Qtdtd6bA== X-Received: by 2002:aa7:c256:: with SMTP id y22mr18306948edo.177.1624663881680; Fri, 25 Jun 2021 16:31:21 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id b8sm4741015edr.42.2021.06.25.16.31.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Jun 2021 16:31:21 -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 2/2] PCI/sysfs: Pass iomem_get_mapping() as a function pointer Date: Fri, 25 Jun 2021 23:31:18 +0000 Message-Id: <20210625233118.2814915-3-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210625233118.2814915-1-kw@linux.com> References: <20210625233118.2814915-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. Co-authored-by: Dan Williams 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);