Skip to content

Commit

Permalink
Merge tag 'driver-core-5.8-rc6' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/gregkh/driver-core into master

Pull driver core fixes from Greg KH:
 "Here are 3 driver core fixes for 5.8-rc6.

  They resolve some issues found with the deferred probe code for some
  types of devices on some embedded systems. They have been tested a
  bunch and have been in linux-next for a while with no reported issues"

* tag 'driver-core-5.8-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
  driver core: Avoid deferred probe due to fw_devlink_pause/resume()
  driver core: Rename dev_links_info.defer_sync to defer_hook
  driver core: Don't do deferred probe in parallel with kernel_init thread
  • Loading branch information
Linus Torvalds committed Jul 16, 2020
2 parents 6a058f0 + 2451e74 commit 50ad1c2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
1 change: 0 additions & 1 deletion drivers/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
extern int devres_release_all(struct device *dev);
extern void device_block_probing(void);
extern void device_unblock_probing(void);
extern void driver_deferred_probe_force_trigger(void);

/* /sys/devices directory */
extern struct kset *devices_kset;
Expand Down
44 changes: 32 additions & 12 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static DEFINE_MUTEX(wfs_lock);
static LIST_HEAD(deferred_sync);
static unsigned int defer_sync_state_count = 1;
static unsigned int defer_fw_devlink_count;
static LIST_HEAD(deferred_fw_devlink);
static DEFINE_MUTEX(defer_fw_devlink_lock);
static bool fw_devlink_is_permissive(void);

Expand Down Expand Up @@ -754,11 +755,11 @@ static void __device_links_queue_sync_state(struct device *dev,
*/
dev->state_synced = true;

if (WARN_ON(!list_empty(&dev->links.defer_sync)))
if (WARN_ON(!list_empty(&dev->links.defer_hook)))
return;

get_device(dev);
list_add_tail(&dev->links.defer_sync, list);
list_add_tail(&dev->links.defer_hook, list);
}

/**
Expand All @@ -776,8 +777,8 @@ static void device_links_flush_sync_list(struct list_head *list,
{
struct device *dev, *tmp;

list_for_each_entry_safe(dev, tmp, list, links.defer_sync) {
list_del_init(&dev->links.defer_sync);
list_for_each_entry_safe(dev, tmp, list, links.defer_hook) {
list_del_init(&dev->links.defer_hook);

if (dev != dont_lock_dev)
device_lock(dev);
Expand Down Expand Up @@ -815,12 +816,12 @@ void device_links_supplier_sync_state_resume(void)
if (defer_sync_state_count)
goto out;

list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_sync) {
list_for_each_entry_safe(dev, tmp, &deferred_sync, links.defer_hook) {
/*
* Delete from deferred_sync list before queuing it to
* sync_list because defer_sync is used for both lists.
* sync_list because defer_hook is used for both lists.
*/
list_del_init(&dev->links.defer_sync);
list_del_init(&dev->links.defer_hook);
__device_links_queue_sync_state(dev, &sync_list);
}
out:
Expand All @@ -838,8 +839,8 @@ late_initcall(sync_state_resume_initcall);

static void __device_links_supplier_defer_sync(struct device *sup)
{
if (list_empty(&sup->links.defer_sync) && dev_has_sync_state(sup))
list_add_tail(&sup->links.defer_sync, &deferred_sync);
if (list_empty(&sup->links.defer_hook) && dev_has_sync_state(sup))
list_add_tail(&sup->links.defer_hook, &deferred_sync);
}

static void device_link_drop_managed(struct device_link *link)
Expand Down Expand Up @@ -1052,7 +1053,7 @@ void device_links_driver_cleanup(struct device *dev)
WRITE_ONCE(link->status, DL_STATE_DORMANT);
}

list_del_init(&dev->links.defer_sync);
list_del_init(&dev->links.defer_hook);
__device_links_no_driver(dev);

device_links_write_unlock();
Expand Down Expand Up @@ -1244,6 +1245,12 @@ static void fw_devlink_link_device(struct device *dev)
fw_ret = -EAGAIN;
} else {
fw_ret = -ENODEV;
/*
* defer_hook is not used to add device to deferred_sync list
* until device is bound. Since deferred fw devlink also blocks
* probing, same list hook can be used for deferred_fw_devlink.
*/
list_add_tail(&dev->links.defer_hook, &deferred_fw_devlink);
}

if (fw_ret == -ENODEV)
Expand Down Expand Up @@ -1312,6 +1319,9 @@ void fw_devlink_pause(void)
*/
void fw_devlink_resume(void)
{
struct device *dev, *tmp;
LIST_HEAD(probe_list);

mutex_lock(&defer_fw_devlink_lock);
if (!defer_fw_devlink_count) {
WARN(true, "Unmatched fw_devlink pause/resume!");
Expand All @@ -1323,9 +1333,19 @@ void fw_devlink_resume(void)
goto out;

device_link_add_missing_supplier_links();
driver_deferred_probe_force_trigger();
list_splice_tail_init(&deferred_fw_devlink, &probe_list);
out:
mutex_unlock(&defer_fw_devlink_lock);

/*
* bus_probe_device() can cause new devices to get added and they'll
* try to grab defer_fw_devlink_lock. So, this needs to be done outside
* the defer_fw_devlink_lock.
*/
list_for_each_entry_safe(dev, tmp, &probe_list, links.defer_hook) {
list_del_init(&dev->links.defer_hook);
bus_probe_device(dev);
}
}
/* Device links support end. */

Expand Down Expand Up @@ -2172,7 +2192,7 @@ void device_initialize(struct device *dev)
INIT_LIST_HEAD(&dev->links.consumers);
INIT_LIST_HEAD(&dev->links.suppliers);
INIT_LIST_HEAD(&dev->links.needs_suppliers);
INIT_LIST_HEAD(&dev->links.defer_sync);
INIT_LIST_HEAD(&dev->links.defer_hook);
dev->links.status = DL_DEV_NO_DRIVER;
}
EXPORT_SYMBOL_GPL(device_initialize);
Expand Down
5 changes: 0 additions & 5 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ static void driver_deferred_probe_trigger(void)
if (!driver_deferred_probe_enable)
return;

driver_deferred_probe_force_trigger();
}

void driver_deferred_probe_force_trigger(void)
{
/*
* A successful probe means that all the devices in the pending list
* should be triggered to be reprobed. Move all the deferred devices
Expand Down
5 changes: 3 additions & 2 deletions include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ enum dl_dev_state {
* @suppliers: List of links to supplier devices.
* @consumers: List of links to consumer devices.
* @needs_suppliers: Hook to global list of devices waiting for suppliers.
* @defer_sync: Hook to global list of devices that have deferred sync_state.
* @defer_hook: Hook to global list of devices that have deferred sync_state or
* deferred fw_devlink.
* @need_for_probe: If needs_suppliers is on a list, this indicates if the
* suppliers are needed for probe or not.
* @status: Driver status information.
Expand All @@ -442,7 +443,7 @@ struct dev_links_info {
struct list_head suppliers;
struct list_head consumers;
struct list_head needs_suppliers;
struct list_head defer_sync;
struct list_head defer_hook;
bool need_for_probe;
enum dl_dev_state status;
};
Expand Down

0 comments on commit 50ad1c2

Please sign in to comment.