* [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
@ 2017-01-18 20:30 Oliver Hartkopp
2017-01-18 20:40 ` Oliver Hartkopp
2017-01-28 16:42 ` Michael Josenhans
0 siblings, 2 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2017-01-18 20:30 UTC (permalink / raw)
To: linux-can; +Cc: Michael Josenhans, Oliver Hartkopp
When removing a bcm tx operation either a hrtimer or a tasklet might run.
As the hrtimer triggers its associated tasklet and vice versa we need to
take care to mutually terminate both handlers.
Reported-by: Michael Josenhans <michael.josenhans@web.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
net/can/bcm.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 21ac75390e3d..a7dc80c8e724 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct list_head *ops,
static void bcm_remove_op(struct bcm_op *op)
{
- hrtimer_cancel(&op->timer);
- hrtimer_cancel(&op->thrtimer);
-
- if (op->tsklet.func)
- tasklet_kill(&op->tsklet);
+ if (op->tsklet.func) {
+ while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
+ test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
+ hrtimer_active(&op->timer)) {
+ hrtimer_cancel(&op->timer);
+ tasklet_kill(&op->tsklet);
+ }
+ }
- if (op->thrtsklet.func)
- tasklet_kill(&op->thrtsklet);
+ if (op->thrtsklet.func) {
+ while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
+ test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
+ hrtimer_active(&op->thrtimer)) {
+ hrtimer_cancel(&op->thrtimer);
+ tasklet_kill(&op->thrtsklet);
+ }
+ }
if ((op->frames) && (op->frames != &op->sframe))
kfree(op->frames);
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
2017-01-18 20:30 [PATCH] can: fix hrtimer/tasklet termination in bcm op removal Oliver Hartkopp
@ 2017-01-18 20:40 ` Oliver Hartkopp
2017-01-28 16:42 ` Michael Josenhans
1 sibling, 0 replies; 5+ messages in thread
From: Oliver Hartkopp @ 2017-01-18 20:40 UTC (permalink / raw)
To: Michael Josenhans; +Cc: linux-can
Hi Michael,
thanks for your bug report!
I created and tested this patch with some weird settings using a 1 usec
cycle together with TX_SETUP and TX_DELETE.
Can you please check this patch with your setup?
Best regards,
Oliver
On 01/18/2017 09:30 PM, Oliver Hartkopp wrote:
> When removing a bcm tx operation either a hrtimer or a tasklet might run.
> As the hrtimer triggers its associated tasklet and vice versa we need to
> take care to mutually terminate both handlers.
>
> Reported-by: Michael Josenhans <michael.josenhans@web.de>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> ---
> net/can/bcm.c | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 21ac75390e3d..a7dc80c8e724 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct list_head *ops,
>
> static void bcm_remove_op(struct bcm_op *op)
> {
> - hrtimer_cancel(&op->timer);
> - hrtimer_cancel(&op->thrtimer);
> -
> - if (op->tsklet.func)
> - tasklet_kill(&op->tsklet);
> + if (op->tsklet.func) {
> + while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
> + test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
> + hrtimer_active(&op->timer)) {
> + hrtimer_cancel(&op->timer);
> + tasklet_kill(&op->tsklet);
> + }
> + }
>
> - if (op->thrtsklet.func)
> - tasklet_kill(&op->thrtsklet);
> + if (op->thrtsklet.func) {
> + while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
> + test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
> + hrtimer_active(&op->thrtimer)) {
> + hrtimer_cancel(&op->thrtimer);
> + tasklet_kill(&op->thrtsklet);
> + }
> + }
>
> if ((op->frames) && (op->frames != &op->sframe))
> kfree(op->frames);
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
2017-01-18 20:30 [PATCH] can: fix hrtimer/tasklet termination in bcm op removal Oliver Hartkopp
2017-01-18 20:40 ` Oliver Hartkopp
@ 2017-01-28 16:42 ` Michael Josenhans
2017-01-28 17:25 ` Oliver Hartkopp
1 sibling, 1 reply; 5+ messages in thread
From: Michael Josenhans @ 2017-01-28 16:42 UTC (permalink / raw)
To: Oliver Hartkopp, linux-can
When removing a bcm tx operation either a hrtimer or a tasklet might run.
As the hrtimer triggers its associated tasklet and vice versa we need to
take care to mutually terminate both handlers.
Reported-by: Michael Josenhans <michael.josenhans@web.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Michael Josenhans <michael.josenhans@web.de>
> ---
> net/can/bcm.c | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index 21ac75390e3d..a7dc80c8e724 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct list_head *ops,
>
> static void bcm_remove_op(struct bcm_op *op)
> {
> - hrtimer_cancel(&op->timer);
> - hrtimer_cancel(&op->thrtimer);
> -
> - if (op->tsklet.func)
> - tasklet_kill(&op->tsklet);
> + if (op->tsklet.func) {
> + while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
> + test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
> + hrtimer_active(&op->timer)) {
> + hrtimer_cancel(&op->timer);
> + tasklet_kill(&op->tsklet);
> + }
> + }
>
> - if (op->thrtsklet.func)
> - tasklet_kill(&op->thrtsklet);
> + if (op->thrtsklet.func) {
> + while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
> + test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
> + hrtimer_active(&op->thrtimer)) {
> + hrtimer_cancel(&op->thrtimer);
> + tasklet_kill(&op->thrtsklet);
> + }
> + }
>
> if ((op->frames) && (op->frames != &op->sframe))
> kfree(op->frames);
> --
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
2017-01-28 16:42 ` Michael Josenhans
@ 2017-01-28 17:25 ` Oliver Hartkopp
2017-01-30 10:06 ` Marc Kleine-Budde
0 siblings, 1 reply; 5+ messages in thread
From: Oliver Hartkopp @ 2017-01-28 17:25 UTC (permalink / raw)
To: Michael Josenhans, Marc Kleine-Budde; +Cc: linux-can
On 01/28/2017 05:42 PM, Michael Josenhans wrote:
> When removing a bcm tx operation either a hrtimer or a tasklet might run.
> As the hrtimer triggers its associated tasklet and vice versa we need to
> take care to mutually terminate both handlers.
>
> Reported-by: Michael Josenhans <michael.josenhans@web.de>
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> Tested-by: Michael Josenhans <michael.josenhans@web.de>
Thanks for testing!
@Marc: This is a candidate for stable too.
Best regards,
Oliver
>> ---
>> net/can/bcm.c | 23 ++++++++++++++++-------
>> 1 file changed, 16 insertions(+), 7 deletions(-)
>>
>> diff --git a/net/can/bcm.c b/net/can/bcm.c
>> index 21ac75390e3d..a7dc80c8e724 100644
>> --- a/net/can/bcm.c
>> +++ b/net/can/bcm.c
>> @@ -734,14 +734,23 @@ static struct bcm_op *bcm_find_op(struct
>> list_head *ops,
>>
>> static void bcm_remove_op(struct bcm_op *op)
>> {
>> - hrtimer_cancel(&op->timer);
>> - hrtimer_cancel(&op->thrtimer);
>> -
>> - if (op->tsklet.func)
>> - tasklet_kill(&op->tsklet);
>> + if (op->tsklet.func) {
>> + while (test_bit(TASKLET_STATE_SCHED, &op->tsklet.state) ||
>> + test_bit(TASKLET_STATE_RUN, &op->tsklet.state) ||
>> + hrtimer_active(&op->timer)) {
>> + hrtimer_cancel(&op->timer);
>> + tasklet_kill(&op->tsklet);
>> + }
>> + }
>>
>> - if (op->thrtsklet.func)
>> - tasklet_kill(&op->thrtsklet);
>> + if (op->thrtsklet.func) {
>> + while (test_bit(TASKLET_STATE_SCHED, &op->thrtsklet.state) ||
>> + test_bit(TASKLET_STATE_RUN, &op->thrtsklet.state) ||
>> + hrtimer_active(&op->thrtimer)) {
>> + hrtimer_cancel(&op->thrtimer);
>> + tasklet_kill(&op->thrtsklet);
>> + }
>> + }
>>
>> if ((op->frames) && (op->frames != &op->sframe))
>> kfree(op->frames);
>> --
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: fix hrtimer/tasklet termination in bcm op removal
2017-01-28 17:25 ` Oliver Hartkopp
@ 2017-01-30 10:06 ` Marc Kleine-Budde
0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2017-01-30 10:06 UTC (permalink / raw)
To: Oliver Hartkopp, Michael Josenhans; +Cc: linux-can
[-- Attachment #1.1: Type: text/plain, Size: 875 bytes --]
On 01/28/2017 06:25 PM, Oliver Hartkopp wrote:
> On 01/28/2017 05:42 PM, Michael Josenhans wrote:
>
>> When removing a bcm tx operation either a hrtimer or a tasklet might run.
>> As the hrtimer triggers its associated tasklet and vice versa we need to
>> take care to mutually terminate both handlers.
>>
>> Reported-by: Michael Josenhans <michael.josenhans@web.de>
>> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
>> Tested-by: Michael Josenhans <michael.josenhans@web.de>
>
> Thanks for testing!
>
> @Marc: This is a candidate for stable too.
added to can.
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-01-30 10:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-18 20:30 [PATCH] can: fix hrtimer/tasklet termination in bcm op removal Oliver Hartkopp
2017-01-18 20:40 ` Oliver Hartkopp
2017-01-28 16:42 ` Michael Josenhans
2017-01-28 17:25 ` Oliver Hartkopp
2017-01-30 10:06 ` Marc Kleine-Budde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).