can: fix hrtimer/tasklet termination in bcm op removal
Subsystems (2)
Oliver Hartkopp
maintainerPATCH 1/1 can: fix hrtimer/tasklet termination in bcm op removal
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.
--- net/can/bcm.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
net/can/bcm.c +16 -7
@@ -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);
Signature · 1 line
2.11.0
Oliver Hartkopp
maintainerHi 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
Quoted 46 lines · 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 <[email protected]>Signed-off-by Oliver Hartkopp <[email protected]>--- net/can/bcm.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)net/can/bcm.c +16
-7@@ -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);
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.
Quoted 40 lines
--- net/can/bcm.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)net/can/bcm.c +16
-8@@ -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); --
Oliver Hartkopp
maintainerQuoted 7 lines · Michael Josenhans
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 <[email protected]>Signed-off-by Oliver Hartkopp <[email protected]>Tested-by Michael Josenhans <[email protected]>
Thanks for testing!
@Marc: This is a candidate for stable too.
Best regards,
Oliver
Quoted 41 lines
Quoted 41 lines
--- net/can/bcm.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)net/can/bcm.c +16
-7@@ -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);--
Marc Kleine-Budde
maintainerQuoted 6 lines · Oliver Hartkopp
Quoted 4 lines · Michael Josenhans
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.
Quoted 7 lines
Quoted 3 lines
Reported-by Michael Josenhans <[email protected]>Signed-off-by Oliver Hartkopp <[email protected]>Tested-by Michael Josenhans <[email protected]>Thanks for testing!
@Marc: This is a candidate for stable too.
added to can.
Marc
Signature · 4 lines
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 |