From patchwork Thu Jul 29 23:32: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: 12410097 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 E0156C4338F for ; Thu, 29 Jul 2021 23:32:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2B0260F23 for ; Thu, 29 Jul 2021 23:32:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233341AbhG2Xc6 (ORCPT ); Thu, 29 Jul 2021 19:32:58 -0400 Received: from mail-pj1-f43.google.com ([209.85.216.43]:45048 "EHLO mail-pj1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbhG2Xc6 (ORCPT ); Thu, 29 Jul 2021 19:32:58 -0400 Received: by mail-pj1-f43.google.com with SMTP id e2-20020a17090a4a02b029016f3020d867so11852394pjh.3 for ; Thu, 29 Jul 2021 16:32:53 -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=LQO9BjZ87IuTOirQKDMY9xJZve77mpQW3jqbgk9DnKg=; b=XkQnWi1WfMhcBichImBkgGlspJ26lGbACISaqAUBTXj1E0a961DA2jJyY1UTcSCXNs W/Jl4uRs+HLlPXu9A/kWQarCv+8H8INfbUNtFaOFMGjIgdxokcaIcgFi12hrQviVtH+w ZUdj/5tnB/cm24fV54v1x9WuRdc+pMEkx/eeWyYNJBwvPCdIgf7ljSkFyb91iQuAVri+ sUTa9LGVNOvzMPAEkci6QoVgn03vidOUI7Oq0Q4Qlk6Ad4Fc9Jt5wKAB4PElZ44TodPZ BM16dhd+EtDZU54856xL02hxq10vrhRTQl0/w0gwboiFT4fvPNLuhx4kxQgmAioIlHM+ xWOg== X-Gm-Message-State: AOAM532W/ioN4tUNK6MWXyJO1SNyYnUvS4Yol7sVAAprPw1GjfzdjqT4 XCt+uaZBg5HkrqVRy+7XwCg= X-Google-Smtp-Source: ABdhPJwrl0tWRmALfe549CHQC8Zv+T3pir64aApusb9goKvIv9+GoLy5W+ZKxgAJ5oegTvkIL7FXiQ== X-Received: by 2002:a05:6a00:148e:b029:331:5b07:c89a with SMTP id v14-20020a056a00148eb02903315b07c89amr7629353pfu.41.1627601573458; Thu, 29 Jul 2021 16:32:53 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id d22sm4843325pfo.88.2021.07.29.16.32.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 16:32:53 -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 v3 1/2] sysfs: Invoke iomem_get_mapping() from the sysfs open callback Date: Thu, 29 Jul 2021 23:32:34 +0000 Message-Id: <20210729233235.1508920-2-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729233235.1508920-1-kw@linux.com> References: <20210729233235.1508920-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. Also, 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. 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 Reviewed-by: Dan Williams Acked-by: Bjorn Helgaas --- drivers/pci/pci-sysfs.c | 6 +++--- fs/sysfs/file.c | 2 +- include/linux/sysfs.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d63df7c1820..76e5545d0e73 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); 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 a12556a4b93a..d5bcc897583c 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -176,7 +176,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 Thu Jul 29 23:32: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: 12410099 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 395B6C4338F for ; Thu, 29 Jul 2021 23:33:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B5AA60F4B for ; Thu, 29 Jul 2021 23:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234299AbhG2XdE (ORCPT ); Thu, 29 Jul 2021 19:33:04 -0400 Received: from mail-pl1-f180.google.com ([209.85.214.180]:34684 "EHLO mail-pl1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbhG2XdE (ORCPT ); Thu, 29 Jul 2021 19:33:04 -0400 Received: by mail-pl1-f180.google.com with SMTP id d1so8856711pll.1 for ; Thu, 29 Jul 2021 16:32:59 -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=6T89ZET1uZxz7012CVHYYU1Wf5+KMJNNw9LfH+Awp7U=; b=k52GPol6PPw4OLy6mD1tN9eBIP9FJmx/SdFExF8WVEQs1jwon+Zm62iVDfhlR620NZ 88bCP6FSM1xddupAUcQr4Ja9Y/AZQRkpTLw+JuwjOZ/Sp1yt+Cdp/kbep0mPkZqYTME8 U16T2oXqaIkyYQU5GmI+k+GScAT5mrEdZl8c3cu+nFPNeMwt3JW0W8znZ5/b33PZkTEx Gh90uDcV8kDr0QtZg+Obnw3bcv/mRwMp0epnlGaBA05caFJfAK6SCTD0TjvzPeshoiw3 ZofNF0JEOtJ++VuzIu4ffnqCTUHUww1Svs1w+p/KVB8biNuyODcyIvduJAhjdjanpZLR 8OLg== X-Gm-Message-State: AOAM530Pgm5zUvX941VW1hduS5/mFR5nWagpqDZh3/0BRKnKUGk6CYmF kXxLcdogIXhofwDvVTzXSHs= X-Google-Smtp-Source: ABdhPJytKJRfPJnSf9PVIBQtXXq6qHhvdTw0BUfgmucgRlQPwP5/0GpADUgtPKQssxhsaUv0gkLENg== X-Received: by 2002:a63:2116:: with SMTP id h22mr5864724pgh.410.1627601579551; Thu, 29 Jul 2021 16:32:59 -0700 (PDT) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id d22sm4843325pfo.88.2021.07.29.16.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 16:32:59 -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 v3 2/2] sysfs: Rename struct bin_attribute member to f_mapping Date: Thu, 29 Jul 2021 23:32:35 +0000 Message-Id: <20210729233235.1508920-3-kw@linux.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210729233235.1508920-1-kw@linux.com> References: <20210729233235.1508920-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 Acked-by: Bjorn Helgaas --- 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 76e5545d0e73..f65382915f01 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 d5bcc897583c..e3f1e8ac1f85 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -176,7 +176,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 *,