diff mbox series

[v2,1/3] sysfs: Invoke iomem_get_mapping() from the sysfs open callback

Message ID 20210626125735.2868256-2-kw@linux.com (mailing list archive)
State Superseded
Delegated to: Bjorn Helgaas
Headers show
Series Allow deferred execution of iomem_get_mapping() | expand

Commit Message

Krzysztof Wilczyński June 26, 2021, 12:57 p.m. UTC
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 <dan.j.williams@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Krzysztof Wilczyński <kw@linux.com>
---
 fs/sysfs/file.c       | 2 +-
 include/linux/sysfs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

kernel test robot June 26, 2021, 8:07 p.m. UTC | #1
Hi "Krzysztof,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on pci/next]
[also build test ERROR on driver-core/driver-core-testing linus/master v5.13-rc7 next-20210625]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Krzysztof-Wilczy-ski/Allow-deferred-execution-of-iomem_get_mapping/20210626-205836
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: i386-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/e2a3b2d0e981d30bc58d044387dc17e55ab6ee03
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Krzysztof-Wilczy-ski/Allow-deferred-execution-of-iomem_get_mapping/20210626-205836
        git checkout e2a3b2d0e981d30bc58d044387dc17e55ab6ee03
        # save the attached .config to linux build tree
        make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

Note: the linux-review/Krzysztof-Wilczy-ski/Allow-deferred-execution-of-iomem_get_mapping/20210626-205836 HEAD eef095b16d6c52c82c68e26f94558e39dc49f4ae builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>):

   drivers/pci/pci-sysfs.c: In function 'pci_create_attr':
>> drivers/pci/pci-sysfs.c:1198:21: error: assignment to 'struct address_space * (*)(void)' from incompatible pointer type 'struct address_space *' [-Werror=incompatible-pointer-types]
    1198 |   res_attr->mapping = iomem_get_mapping();
         |                     ^
   cc1: some warnings being treated as errors


vim +1198 drivers/pci/pci-sysfs.c

45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1165  
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1166  static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1167  {
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1168  	/* allocate attribute structure, piggyback attribute name */
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1169  	int name_len = write_combine ? 13 : 10;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1170  	struct bin_attribute *res_attr;
bd5174dfb6f171 Bjorn Helgaas                 2016-03-10  1171  	char *res_attr_name;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1172  	int retval;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1173  
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1174  	res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
bd5174dfb6f171 Bjorn Helgaas                 2016-03-10  1175  	if (!res_attr)
bd5174dfb6f171 Bjorn Helgaas                 2016-03-10  1176  		return -ENOMEM;
bd5174dfb6f171 Bjorn Helgaas                 2016-03-10  1177  
bd5174dfb6f171 Bjorn Helgaas                 2016-03-10  1178  	res_attr_name = (char *)(res_attr + 1);
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1179  
a07e4156a2ee63 Eric W. Biederman             2010-02-11  1180  	sysfs_bin_attr_init(res_attr);
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1181  	if (write_combine) {
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1182  		pdev->res_attr_wc[num] = res_attr;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1183  		sprintf(res_attr_name, "resource%d_wc", num);
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1184  		res_attr->mmap = pci_mmap_resource_wc;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1185  	} else {
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1186  		pdev->res_attr[num] = res_attr;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1187  		sprintf(res_attr_name, "resource%d", num);
8633328be24267 Alex Williamson               2010-07-19  1188  		if (pci_resource_flags(pdev, num) & IORESOURCE_IO) {
8633328be24267 Alex Williamson               2010-07-19  1189  			res_attr->read = pci_read_resource_io;
8633328be24267 Alex Williamson               2010-07-19  1190  			res_attr->write = pci_write_resource_io;
e854d8b2a82ef7 David Woodhouse               2017-04-12  1191  			if (arch_can_pci_mmap_io())
e854d8b2a82ef7 David Woodhouse               2017-04-12  1192  				res_attr->mmap = pci_mmap_resource_uc;
e854d8b2a82ef7 David Woodhouse               2017-04-12  1193  		} else {
e854d8b2a82ef7 David Woodhouse               2017-04-12  1194  			res_attr->mmap = pci_mmap_resource_uc;
e854d8b2a82ef7 David Woodhouse               2017-04-12  1195  		}
8633328be24267 Alex Williamson               2010-07-19  1196  	}
636b21b50152d4 Daniel Vetter                 2021-02-04  1197  	if (res_attr->mmap)
636b21b50152d4 Daniel Vetter                 2021-02-04 @1198  		res_attr->mapping = iomem_get_mapping();
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1199  	res_attr->attr.name = res_attr_name;
e2154044dd4168 Kelsey Skunberg               2019-08-13  1200  	res_attr->attr.mode = 0600;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1201  	res_attr->size = pci_resource_len(pdev, num);
dca40b186b757c David Woodhouse               2017-04-12  1202  	res_attr->private = (void *)(unsigned long)num;
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1203  	retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
b562ec8f74e4ed Bjorn Helgaas                 2016-03-10  1204  	if (retval)
b562ec8f74e4ed Bjorn Helgaas                 2016-03-10  1205  		kfree(res_attr);
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1206  
45aec1ae72fc59 venkatesh.pallipadi@intel.com 2008-03-18  1207  	return retval;
b19441af185559 Greg Kroah-Hartman            2006-08-28  1208  }
b19441af185559 Greg Kroah-Hartman            2006-08-28  1209  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

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 *,