Message ID | 20240904125155.461886-3-o-takashi@sakamocchi.jp (mailing list archive) |
---|---|
State | Accepted |
Commit | 4f55ad754d6b7b6fa4ebcfd8c50f7e53e661a78e |
Headers | show |
Series | firewire: use sleepable workqueue to handle 1394 OHCI IT/IR context events | expand |
On Wed, 04 Sep 2024 14:51:51 +0200, Takashi Sakamoto wrote: > > In the previous commit, the workqueue is added per the instance of fw_card > structure for isochronous contexts. The workqueue is designed to be used by > the implementation of fw_card_driver structure underlying the fw_card. > > This commit adds some local APIs to be used by the implementation. > > Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> > --- > drivers/firewire/core-iso.c | 30 ++++++++++++++++++++++++++++-- > drivers/firewire/core.h | 10 ++++++++++ > include/linux/firewire.h | 1 + > 3 files changed, 39 insertions(+), 2 deletions(-) > > diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c > index 101433b8bb51..af76fa1823f1 100644 > --- a/drivers/firewire/core-iso.c > +++ b/drivers/firewire/core-iso.c > @@ -211,21 +211,47 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush); > > int fw_iso_context_flush_completions(struct fw_iso_context *ctx) > { > + int err; > + > trace_isoc_outbound_flush_completions(ctx); > trace_isoc_inbound_single_flush_completions(ctx); > trace_isoc_inbound_multiple_flush_completions(ctx); > > - return ctx->card->driver->flush_iso_completions(ctx); > + might_sleep(); > + > + // Avoid dead lock due to programming mistake. > + if (WARN_ON(current_work() == &ctx->work)) > + return 0; Maybe WARN_ON_ONCE() would be safer if it's supposed to be called frequently. Otherwise it can spam too much. Ditto for fw_iso_context_stop(). thanks, Takashi
Hi, On Wed, Sep 04, 2024 at 06:07:20PM +0200, Takashi Iwai wrote: > On Wed, 04 Sep 2024 14:51:51 +0200, > Takashi Sakamoto wrote: > > > > In the previous commit, the workqueue is added per the instance of fw_card > > structure for isochronous contexts. The workqueue is designed to be used by > > the implementation of fw_card_driver structure underlying the fw_card. > > > > This commit adds some local APIs to be used by the implementation. > > > > Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> > > --- > > drivers/firewire/core-iso.c | 30 ++++++++++++++++++++++++++++-- > > drivers/firewire/core.h | 10 ++++++++++ > > include/linux/firewire.h | 1 + > > 3 files changed, 39 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c > > index 101433b8bb51..af76fa1823f1 100644 > > --- a/drivers/firewire/core-iso.c > > +++ b/drivers/firewire/core-iso.c > > @@ -211,21 +211,47 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush); > > > > int fw_iso_context_flush_completions(struct fw_iso_context *ctx) > > { > > + int err; > > + > > trace_isoc_outbound_flush_completions(ctx); > > trace_isoc_inbound_single_flush_completions(ctx); > > trace_isoc_inbound_multiple_flush_completions(ctx); > > > > - return ctx->card->driver->flush_iso_completions(ctx); > > + might_sleep(); > > + > > + // Avoid dead lock due to programming mistake. > > + if (WARN_ON(current_work() == &ctx->work)) > > + return 0; > > Maybe WARN_ON_ONCE() would be safer if it's supposed to be called > frequently. Otherwise it can spam too much. > Ditto for fw_iso_context_stop(). Thanks for your suggestion. Indeed, the kernel API would be called so frequently, and the *_ONCE macro would be safer. I'll post another patch for it, since posting updated series of changes to all of receivers is a bit cumbersome to me... Thanks Takashi Sakamoto
diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c index 101433b8bb51..af76fa1823f1 100644 --- a/drivers/firewire/core-iso.c +++ b/drivers/firewire/core-iso.c @@ -211,21 +211,47 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush); int fw_iso_context_flush_completions(struct fw_iso_context *ctx) { + int err; + trace_isoc_outbound_flush_completions(ctx); trace_isoc_inbound_single_flush_completions(ctx); trace_isoc_inbound_multiple_flush_completions(ctx); - return ctx->card->driver->flush_iso_completions(ctx); + might_sleep(); + + // Avoid dead lock due to programming mistake. + if (WARN_ON(current_work() == &ctx->work)) + return 0; + + disable_work_sync(&ctx->work); + + err = ctx->card->driver->flush_iso_completions(ctx); + + enable_work(&ctx->work); + + return err; } EXPORT_SYMBOL(fw_iso_context_flush_completions); int fw_iso_context_stop(struct fw_iso_context *ctx) { + int err; + trace_isoc_outbound_stop(ctx); trace_isoc_inbound_single_stop(ctx); trace_isoc_inbound_multiple_stop(ctx); - return ctx->card->driver->stop_iso(ctx); + might_sleep(); + + // Avoid dead lock due to programming mistake. + if (WARN_ON(current_work() == &ctx->work)) + return 0; + + err = ctx->card->driver->stop_iso(ctx); + + cancel_work_sync(&ctx->work); + + return err; } EXPORT_SYMBOL(fw_iso_context_stop); diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h index 96ae366889e0..2874f316156a 100644 --- a/drivers/firewire/core.h +++ b/drivers/firewire/core.h @@ -159,6 +159,16 @@ int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count); int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card, enum dma_data_direction direction); +static inline void fw_iso_context_init_work(struct fw_iso_context *ctx, work_func_t func) +{ + INIT_WORK(&ctx->work, func); +} + +static inline void fw_iso_context_queue_work(struct fw_iso_context *ctx) +{ + queue_work(ctx->card->isoc_wq, &ctx->work); +} + /* -topology */ diff --git a/include/linux/firewire.h b/include/linux/firewire.h index 10e135d60824..72f497b61739 100644 --- a/include/linux/firewire.h +++ b/include/linux/firewire.h @@ -511,6 +511,7 @@ union fw_iso_callback { struct fw_iso_context { struct fw_card *card; + struct work_struct work; int type; int channel; int speed;
In the previous commit, the workqueue is added per the instance of fw_card structure for isochronous contexts. The workqueue is designed to be used by the implementation of fw_card_driver structure underlying the fw_card. This commit adds some local APIs to be used by the implementation. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> --- drivers/firewire/core-iso.c | 30 ++++++++++++++++++++++++++++-- drivers/firewire/core.h | 10 ++++++++++ include/linux/firewire.h | 1 + 3 files changed, 39 insertions(+), 2 deletions(-)