From c817a67ecba7c3c2aaa104796d78f160af60920d Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 27 Jun 2013 15:06:14 +0100 Subject: kobject: delayed kobject release: help find buggy drivers Implement debugging for kobject release functions. kobjects are reference counted, so the drop of the last reference to them is not predictable. However, the common case is for the last reference to be the kobject's removal from a subsystem, which results in the release function being immediately called. This can hide subtle bugs, which can occur when another thread holds a reference to the kobject at the same time that a kobject is removed. This results in the release method being delayed. In order to make these kinds of problems more visible, the following patch implements a delayed release; this has the effect that the release function will be out of order with respect to the removal of the kobject in the same manner that it would be if a reference was being held. This provides us with an easy way to allow driver writers to debug their drivers and fix otherwise hidden problems. Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- include/linux/kobject.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 939b11268c8..de6dcbcc6ef 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -26,6 +26,7 @@ #include #include #include +#include #define UEVENT_HELPER_PATH_LEN 256 #define UEVENT_NUM_ENVP 32 /* number of env pointers */ @@ -65,6 +66,9 @@ struct kobject { struct kobj_type *ktype; struct sysfs_dirent *sd; struct kref kref; +#ifdef CONFIG_DEBUG_KOBJECT_RELEASE + struct delayed_work release; +#endif unsigned int state_initialized:1; unsigned int state_in_sysfs:1; unsigned int state_add_uevent_sent:1; -- cgit v1.2.3-18-g5258 From fa6fdb33b486a8afc5439c504da8d581e142c77d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:55 -0700 Subject: driver core: bus_type: add dev_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add dev_groups to struct bus_type which should be used instead of dev_attrs. dev_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 22b546a5859..3aec4a68b1d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @dev_groups: Default attributes of the devices on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -104,8 +105,9 @@ struct bus_type { const char *dev_name; struct device *dev_root; struct bus_attribute *bus_attrs; - struct device_attribute *dev_attrs; + struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; + const struct attribute_group **dev_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-18-g5258 From ed0617b5c0bcd7fd04053568aa0cc19a977a1f26 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:56 -0700 Subject: driver core: bus_type: add drv_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add drv_groups to struct bus_type which should be used instead of drv_attrs. drv_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 3aec4a68b1d..94d987f128b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -67,6 +67,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. * @dev_groups: Default attributes of the devices on the bus. + * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -106,8 +107,9 @@ struct bus_type { struct device *dev_root; struct bus_attribute *bus_attrs; struct device_attribute *dev_attrs; /* use dev_groups instead */ - struct driver_attribute *drv_attrs; + struct driver_attribute *drv_attrs; /* use drv_groups instead */ const struct attribute_group **dev_groups; + const struct attribute_group **drv_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-18-g5258 From 12478ba077adf8b53be6101b80dd8a65e4df9ea6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:57 -0700 Subject: driver core: bus_type: add bus_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add bus_groups to struct bus_type which should be used instead of bus_attrs. bus_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 94d987f128b..26e23b22ed0 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @bus_groups: Default attributes of the bus. * @dev_groups: Default attributes of the devices on the bus. * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver @@ -105,9 +106,10 @@ struct bus_type { const char *name; const char *dev_name; struct device *dev_root; - struct bus_attribute *bus_attrs; + struct bus_attribute *bus_attrs; /* use bus_groups instead */ struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; /* use drv_groups instead */ + const struct attribute_group **bus_groups; const struct attribute_group **dev_groups; const struct attribute_group **drv_groups; -- cgit v1.2.3-18-g5258 From bd0eae4e1cd5c4ff7c2a9ebcb3e78ea4631251ef Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:19 -0700 Subject: PPS: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the pps class code to use the correct field. Cc: Rodolfo Giometti Signed-off-by: Greg Kroah-Hartman --- include/linux/pps_kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h index 7db3eb93a07..1d2cd21242e 100644 --- a/include/linux/pps_kernel.h +++ b/include/linux/pps_kernel.h @@ -80,7 +80,7 @@ struct pps_device { * Global variables */ -extern struct device_attribute pps_attrs[]; +extern const struct attribute_group *pps_groups[]; /* * Internal functions. -- cgit v1.2.3-18-g5258 From 6853152689d47b4a1eb9f38a25a18f3f8b7a60de Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 20 Aug 2013 16:48:54 -0700 Subject: sysfs.h: fix __BIN_ATTR_RW() __BIN_ATTR_RW() wasn't passing in the _size field. As it would break the build if this macro was ever used, it's obvious no one had ever tried to use it before. Fix it so that it can be used. Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 9e8a9b555ad..0f04958623d 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -153,7 +153,7 @@ struct bin_attribute { #define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name, \ (S_IWUSR | S_IRUGO), _name##_read, \ - _name##_write) + _name##_write, _size) #define __BIN_ATTR_NULL __ATTR_NULL -- cgit v1.2.3-18-g5258 From 37a7bd6255b415afe197489b5cd1f9568a7ae058 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:01 -0500 Subject: drivers: base: reduce add_memory_section() for boot-time only Now that add_memory_section() is only called from boot time, reduce the logic and remove the enum. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- include/linux/memory.h | 1 - 1 file changed, 1 deletion(-) (limited to 'include') diff --git a/include/linux/memory.h b/include/linux/memory.h index 85c31a8e290..4c89fb0c8f4 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -125,7 +125,6 @@ extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Date: Tue, 20 Aug 2013 16:05:05 -0500 Subject: drivers: base: use standard device online/offline for state change There are two ways to set the online/offline state for a memory block: echo 0|1 > online and echo online|online_kernel|online_movable|offline > state. The state attribute can online a memory block with extra data, the "online type", where the online attribute uses a default online type of ONLINE_KEEP, same as echo online > state. Currently there is a state_mutex that provides consistency between the memory block state and the underlying memory. The problem is that this code does a lot of things that the common device layer can do for us, such as the serialization of the online/offline handlers using the device lock, setting the dev->offline field, and calling kobject_uevent(). This patch refactors the online/offline code to allow the common device_[online|offline] functions to be used. The result is a simpler and more common code path for the two state setting mechanisms. It also removes the state_mutex from the struct memory_block as the memory block device lock provides the state consistency. No functional change is intended by this patch. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- include/linux/memory.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/linux/memory.h b/include/linux/memory.h index 4c89fb0c8f4..9a6bbf76452 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -25,16 +25,9 @@ struct memory_block { unsigned long start_section_nr; unsigned long end_section_nr; - unsigned long state; - int section_count; - - /* - * This serializes all state change requests. It isn't - * held during creation because the control files are - * created long after the critical areas during - * initialization. - */ - struct mutex state_mutex; + unsigned long state; /* serialized by the dev->lock */ + int section_count; /* serialized by mem_sysfs_mutex */ + int online_type; /* for passing data to online routine */ int phys_device; /* to which fru does this belong? */ void *hw; /* optional pointer to fw/hw data */ int (*phys_callback)(struct memory_block *); -- cgit v1.2.3-18-g5258 From 3e9b2bae8369661070622d05570cbcdfa01770e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:47:50 -0700 Subject: sysfs: add sysfs_create/remove_groups() These functions are being open-coded in 3 different places in the driver core, and other driver subsystems will want to start doing this as well, so move it to the sysfs core to keep it all in one place, where we know it is written properly. Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 0f04958623d..4dbb9d31daa 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -215,10 +215,14 @@ void sysfs_delete_link(struct kobject *dir, struct kobject *targ, int __must_check sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp); +int __must_check sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp); void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp); +void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group); void sysfs_remove_file_from_group(struct kobject *kobj, -- cgit v1.2.3-18-g5258 From 5da5c9c899dc456d6eb43aae3e8d4e853b7f5306 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 17:47:05 -0700 Subject: sysfs: fix up minor coding style issues in sysfs.h As long as we are cleaning up sysfs coding style issues, don't forget the main sysfs.h file, so fix up the space issues there as well. Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 4dbb9d31daa..a864b8d918e 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -51,9 +51,9 @@ do { \ static struct lock_class_key __key; \ \ (attr)->key = &__key; \ -} while(0) +} while (0) #else -#define sysfs_attr_init(attr) do {} while(0) +#define sysfs_attr_init(attr) do {} while (0) #endif struct attribute_group { @@ -69,7 +69,7 @@ struct attribute_group { * for examples.. */ -#define __ATTR(_name,_mode,_show,_store) { \ +#define __ATTR(_name, _mode, _show, _store) { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ .show = _show, \ .store = _store, \ @@ -119,7 +119,7 @@ struct bin_attribute { void *private; 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 *, + ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, char *, loff_t, size_t); int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, struct vm_area_struct *vma); @@ -168,8 +168,8 @@ struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size) struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) struct sysfs_ops { - ssize_t (*show)(struct kobject *, struct attribute *,char *); - ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); + ssize_t (*show)(struct kobject *, struct attribute *, char *); + ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); const void *(*namespace)(struct kobject *, const struct attribute *); }; -- cgit v1.2.3-18-g5258 From 3e1026b3fa2f61d33ce6a9e42a22398cc4ab8e58 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 22 Aug 2013 10:25:34 -0700 Subject: sysfs.h: remove attr_name() macro Gotta love a macro that doesn't reduce the typing you have to do. Also, only the driver core, and one network driver uses this. The driver core functions will be going away soon, and I'll convert the network driver soon to not need this as well, so delete it for now before anyone else gets some bright ideas and wants to use it. Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index a864b8d918e..b5a9d9b26bd 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -108,8 +108,6 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) -#define attr_name(_attr) (_attr).attr.name - struct file; struct vm_area_struct; -- cgit v1.2.3-18-g5258 From a65fcce75a75c0d41b938f86d09d42b6f1733309 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 15:02:01 -0700 Subject: sysfs: create __ATTR_WO() This creates the macro __ATTR_WO() for write-only attributes, instead of having to "open define" them. Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index b5a9d9b26bd..69c1ff00362 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -80,6 +80,11 @@ struct attribute_group { .show = _name##_show, \ } +#define __ATTR_WO(_name) { \ + .attr = { .name = __stringify(_name), .mode = S_IWUSR }, \ + .store = _name##_store, \ +} + #define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO), \ _name##_show, _name##_store) -- cgit v1.2.3-18-g5258 From 1130c55c757660ac83bd2de220f08580c56b6855 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 15:02:56 -0700 Subject: driver core: create write-only attribute macros for devices and drivers This creates the macros DRIVER_ATTR_WO() and DEVICE_ATTR_WO() for write-only attributes for drivers and devices. Signed-off-by: Greg Kroah-Hartman --- include/linux/device.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/linux/device.h b/include/linux/device.h index 26e23b22ed0..0ed94b5f67f 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -277,6 +277,8 @@ struct driver_attribute { struct driver_attribute driver_attr_##_name = __ATTR_RW(_name) #define DRIVER_ATTR_RO(_name) \ struct driver_attribute driver_attr_##_name = __ATTR_RO(_name) +#define DRIVER_ATTR_WO(_name) \ + struct driver_attribute driver_attr_##_name = __ATTR_WO(_name) extern int __must_check driver_create_file(struct device_driver *driver, const struct driver_attribute *attr); @@ -534,6 +536,8 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, struct device_attribute dev_attr_##_name = __ATTR_RW(_name) #define DEVICE_ATTR_RO(_name) \ struct device_attribute dev_attr_##_name = __ATTR_RO(_name) +#define DEVICE_ATTR_WO(_name) \ + struct device_attribute dev_attr_##_name = __ATTR_WO(_name) #define DEVICE_ULONG_ATTR(_name, _mode, _var) \ struct dev_ext_attribute dev_attr_##_name = \ { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } -- cgit v1.2.3-18-g5258 From f799878000c5a9a1e6a311dfd4faa50601dcb1f8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 27 Aug 2013 17:24:49 -0700 Subject: sysfs: add sysfs_create/remove_groups for when SYSFS is not enabled We need these functions for when CONFIG_SYSFS=n. Reported-by: Fengguang Wu Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 69c1ff00362..e647a1aa072 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -350,6 +350,11 @@ static inline int sysfs_create_group(struct kobject *kobj, return 0; } +static inline int sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ +} + static inline int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp) { @@ -361,6 +366,11 @@ static inline void sysfs_remove_group(struct kobject *kobj, { } +static inline void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ +} + static inline int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group) { -- cgit v1.2.3-18-g5258 From 3159269ef484954985cbbf1ff89976f090a18b24 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 26 Aug 2013 09:58:30 +0200 Subject: debugfs: provide debugfs_create_x64() when disabled commit 15b0beaa332b3923cc ("Add x64 support to debugfs") added debugfs_create_x64(), but forgot to provide it when debugfs is disabled, causing problems when code tries to use it even then. Provide the appropriate static inline. Cc: Huang Ying Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- include/linux/debugfs.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index d68b4ea7343..263489d0788 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -192,6 +192,13 @@ static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode, return ERR_PTR(-ENODEV); } +static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode, + struct dentry *parent, + u64 *value) +{ + return ERR_PTR(-ENODEV); +} + static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode, struct dentry *parent, size_t *value) -- cgit v1.2.3-18-g5258 From 574979c617eb9593f8dfbb804da3f0e00f8bf28e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 28 Aug 2013 09:51:41 -0700 Subject: sysfs: sysfs_create_groups returns a value. When I included the "empty" function for sysfs_create_groups() when CONFIG_SYSFS=n, I forgot to return a value for it, so things blew up the build. This patch fixes that, stupid me. Reported-by: kbuild test robot Signed-off-by: Greg Kroah-Hartman --- include/linux/sysfs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e647a1aa072..11baec7c9b2 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -353,6 +353,7 @@ static inline int sysfs_create_group(struct kobject *kobj, static inline int sysfs_create_groups(struct kobject *kobj, const struct attribute_group **groups) { + return 0; } static inline int sysfs_update_group(struct kobject *kobj, -- cgit v1.2.3-18-g5258