Skip to content

Commit 6ea9e7b

Browse files
author
Stefan Richter
committed
firewire: core: use non-reentrant workqueue with rescuer
firewire-core manages the following types of work items: fw_card.br_work: - resets the bus on a card and possibly sends a PHY packet before that - does not sleep for long or not at all - is scheduled via fw_schedule_bus_reset() by - firewire-ohci's pci_probe method - firewire-ohci's set_config_rom method, called by kernelspace protocol drivers and userspace drivers which add/remove Configuration ROM descriptors - userspace drivers which use the bus reset ioctl - itself if the last reset happened less than 2 seconds ago fw_card.bm_work: - performs bus management duties - usually does not (but may in corner cases) sleep for long - is scheduled via fw_schedule_bm_work() by - firewire-ohci's self-ID-complete IRQ handler tasklet - firewire-core's fw_device.work instances whenever the root node device was (successfully or unsuccessfully) discovered, refreshed, or rediscovered - itself in case of resource allocation failures or in order to obey the 125ms bus manager arbitration interval fw_device.work: - performs node probe, update, shutdown, revival, removal; including kernel driver probe, update, shutdown and bus reset notification to userspace drivers - usually sleeps moderately long, in corner cases very long - is scheduled by - firewire-ohci's self-ID-complete IRQ handler tasklet via the core's fw_node_event - firewire-ohci's pci_remove method via core's fw_destroy_nodes/ fw_node_event - itself during retries, e.g. while a node is powering up iso_resource.work: - accesses registers at the Isochronous Resource Manager node - usually does not (but may in corner cases) sleep for long - is scheduled via schedule_iso_resource() by - the owning userspace driver at addition and removal of the resource - firewire-core's fw_device.work instances after bus reset - itself in case of resource allocation if necessary to obey the 1000ms reallocation period after bus reset fw_card.br_work instances should not, and instances of the others must not, be executed in parallel by multiple CPUs -- but were not protected against that. Hence allocate a non-reentrant workqueue for them. fw_device.work may be used in the memory reclaim path in case of SBP-2 device updates. Hence we need a workqueue with rescuer and cannot use system_nrt_wq. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de> Reviewed-by: Tejun Heo <tj@kernel.org>
1 parent 13882a8 commit 6ea9e7b

5 files changed

Lines changed: 36 additions & 16 deletions

File tree

‎drivers/firewire/core-card.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset)
228228

229229
/* Use an arbitrary short delay to combine multiple reset requests. */
230230
fw_card_get(card);
231-
if (!schedule_delayed_work(&card->br_work,
232-
delayed ? DIV_ROUND_UP(HZ, 100) : 0))
231+
if (!queue_delayed_work(fw_wq, &card->br_work,
232+
delayed ? DIV_ROUND_UP(HZ, 100) : 0))
233233
fw_card_put(card);
234234
}
235235
EXPORT_SYMBOL(fw_schedule_bus_reset);
@@ -241,7 +241,7 @@ static void br_work(struct work_struct *work)
241241
/* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
242242
if (card->reset_jiffies != 0 &&
243243
time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
244-
if (!schedule_delayed_work(&card->br_work, 2 * HZ))
244+
if (!queue_delayed_work(fw_wq, &card->br_work, 2 * HZ))
245245
fw_card_put(card);
246246
return;
247247
}

‎drivers/firewire/core-cdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void release_iso_resource(struct client *, struct client_resource *);
149149
static void schedule_iso_resource(struct iso_resource *r, unsigned long delay)
150150
{
151151
client_get(r->client);
152-
if (!schedule_delayed_work(&r->work, delay))
152+
if (!queue_delayed_work(fw_wq, &r->work, delay))
153153
client_put(r->client);
154154
}
155155

‎drivers/firewire/core-device.c‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ struct fw_device *fw_device_get_by_devt(dev_t devt)
725725
return device;
726726
}
727727

728+
struct workqueue_struct *fw_wq;
729+
730+
static void fw_schedule_device_work(struct fw_device *device,
731+
unsigned long delay)
732+
{
733+
queue_delayed_work(fw_wq, &device->work, delay);
734+
}
735+
728736
/*
729737
* These defines control the retry behavior for reading the config
730738
* rom. It shouldn't be necessary to tweak these; if the device
@@ -750,7 +758,7 @@ static void fw_device_shutdown(struct work_struct *work)
750758
if (time_before64(get_jiffies_64(),
751759
device->card->reset_jiffies + SHUTDOWN_DELAY)
752760
&& !list_empty(&device->card->link)) {
753-
schedule_delayed_work(&device->work, SHUTDOWN_DELAY);
761+
fw_schedule_device_work(device, SHUTDOWN_DELAY);
754762
return;
755763
}
756764

@@ -862,7 +870,7 @@ static int lookup_existing_device(struct device *dev, void *data)
862870
fw_notify("rediscovered device %s\n", dev_name(dev));
863871

864872
PREPARE_DELAYED_WORK(&old->work, fw_device_update);
865-
schedule_delayed_work(&old->work, 0);
873+
fw_schedule_device_work(old, 0);
866874

867875
if (current_node == card->root_node)
868876
fw_schedule_bm_work(card, 0);
@@ -953,7 +961,7 @@ static void fw_device_init(struct work_struct *work)
953961
if (device->config_rom_retries < MAX_RETRIES &&
954962
atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
955963
device->config_rom_retries++;
956-
schedule_delayed_work(&device->work, RETRY_DELAY);
964+
fw_schedule_device_work(device, RETRY_DELAY);
957965
} else {
958966
if (device->node->link_on)
959967
fw_notify("giving up on config rom for node id %x\n",
@@ -1019,7 +1027,7 @@ static void fw_device_init(struct work_struct *work)
10191027
FW_DEVICE_INITIALIZING,
10201028
FW_DEVICE_RUNNING) == FW_DEVICE_GONE) {
10211029
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1022-
schedule_delayed_work(&device->work, SHUTDOWN_DELAY);
1030+
fw_schedule_device_work(device, SHUTDOWN_DELAY);
10231031
} else {
10241032
if (device->config_rom_retries)
10251033
fw_notify("created device %s: GUID %08x%08x, S%d00, "
@@ -1098,7 +1106,7 @@ static void fw_device_refresh(struct work_struct *work)
10981106
if (device->config_rom_retries < MAX_RETRIES / 2 &&
10991107
atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
11001108
device->config_rom_retries++;
1101-
schedule_delayed_work(&device->work, RETRY_DELAY / 2);
1109+
fw_schedule_device_work(device, RETRY_DELAY / 2);
11021110

11031111
return;
11041112
}
@@ -1131,7 +1139,7 @@ static void fw_device_refresh(struct work_struct *work)
11311139
if (device->config_rom_retries < MAX_RETRIES &&
11321140
atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
11331141
device->config_rom_retries++;
1134-
schedule_delayed_work(&device->work, RETRY_DELAY);
1142+
fw_schedule_device_work(device, RETRY_DELAY);
11351143

11361144
return;
11371145
}
@@ -1158,7 +1166,7 @@ static void fw_device_refresh(struct work_struct *work)
11581166
gone:
11591167
atomic_set(&device->state, FW_DEVICE_GONE);
11601168
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1161-
schedule_delayed_work(&device->work, SHUTDOWN_DELAY);
1169+
fw_schedule_device_work(device, SHUTDOWN_DELAY);
11621170
out:
11631171
if (node_id == card->root_node->node_id)
11641172
fw_schedule_bm_work(card, 0);
@@ -1214,7 +1222,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12141222
* first config rom scan half a second after bus reset.
12151223
*/
12161224
INIT_DELAYED_WORK(&device->work, fw_device_init);
1217-
schedule_delayed_work(&device->work, INITIAL_DELAY);
1225+
fw_schedule_device_work(device, INITIAL_DELAY);
12181226
break;
12191227

12201228
case FW_NODE_INITIATED_RESET:
@@ -1230,7 +1238,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12301238
FW_DEVICE_RUNNING,
12311239
FW_DEVICE_INITIALIZING) == FW_DEVICE_RUNNING) {
12321240
PREPARE_DELAYED_WORK(&device->work, fw_device_refresh);
1233-
schedule_delayed_work(&device->work,
1241+
fw_schedule_device_work(device,
12341242
device->is_local ? 0 : INITIAL_DELAY);
12351243
}
12361244
break;
@@ -1245,7 +1253,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12451253
device->generation = card->generation;
12461254
if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
12471255
PREPARE_DELAYED_WORK(&device->work, fw_device_update);
1248-
schedule_delayed_work(&device->work, 0);
1256+
fw_schedule_device_work(device, 0);
12491257
}
12501258
break;
12511259

@@ -1270,7 +1278,7 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
12701278
if (atomic_xchg(&device->state,
12711279
FW_DEVICE_GONE) == FW_DEVICE_RUNNING) {
12721280
PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
1273-
schedule_delayed_work(&device->work,
1281+
fw_schedule_device_work(device,
12741282
list_empty(&card->link) ? 0 : SHUTDOWN_DELAY);
12751283
}
12761284
break;

‎drivers/firewire/core-transaction.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/string.h>
3737
#include <linux/timer.h>
3838
#include <linux/types.h>
39+
#include <linux/workqueue.h>
3940

4041
#include <asm/byteorder.h>
4142

@@ -1213,13 +1214,21 @@ static int __init fw_core_init(void)
12131214
{
12141215
int ret;
12151216

1217+
fw_wq = alloc_workqueue(KBUILD_MODNAME,
1218+
WQ_NON_REENTRANT | WQ_MEM_RECLAIM, 0);
1219+
if (!fw_wq)
1220+
return -ENOMEM;
1221+
12161222
ret = bus_register(&fw_bus_type);
1217-
if (ret < 0)
1223+
if (ret < 0) {
1224+
destroy_workqueue(fw_wq);
12181225
return ret;
1226+
}
12191227

12201228
fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
12211229
if (fw_cdev_major < 0) {
12221230
bus_unregister(&fw_bus_type);
1231+
destroy_workqueue(fw_wq);
12231232
return fw_cdev_major;
12241233
}
12251234

@@ -1235,6 +1244,7 @@ static void __exit fw_core_cleanup(void)
12351244
{
12361245
unregister_chrdev(fw_cdev_major, "firewire");
12371246
bus_unregister(&fw_bus_type);
1247+
destroy_workqueue(fw_wq);
12381248
idr_destroy(&fw_device_idr);
12391249
}
12401250

‎drivers/firewire/core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ void fw_cdev_handle_phy_packet(struct fw_card *card, struct fw_packet *p);
140140
extern struct rw_semaphore fw_device_rwsem;
141141
extern struct idr fw_device_idr;
142142
extern int fw_cdev_major;
143+
struct workqueue_struct;
144+
extern struct workqueue_struct *fw_wq;
143145

144146
struct fw_device *fw_device_get_by_devt(dev_t devt);
145147
int fw_device_set_broadcast_channel(struct device *dev, void *gen);

0 commit comments

Comments
 (0)