genirq: Check irq disabled & masked states in irq_shutdown
PATCH v2 1/1 genirq: Check irq disabled & masked states in irq_shutdown
If a irq is already disabled & masked, free_irq may cause a unbalanced irq shutdown/disable/mask, for example:
devm_request_irq->irq_startup->irq_enabledisable_irq <-- disabled and maskeddevm_free_irq->irq_shutdown <-- try to disable it again
This would confuse some pinctrl drivers which would control clk in irq_enable/irq_disable, for example pinctrl-rockchip/pinctrl-nomadik.
This patch add a state check in irq_shutdown to prevent that.
v2: Rewrite commit message.
---
Changes in v2:
Rewrite commit message.
kernel/irq/chip.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/irq/chip.c +7 -1
@@ -206,14 +206,20 @@ int irq_startup(struct irq_desc *desc, bool resend)void irq_shutdown (struct irq_desc *desc) { -irq_state_set_disabled (desc); desc->depth =1 ; + +if (unlikely (irqd_irq_disabled (&desc->irq_data) && +irqd_irq_masked (&desc->irq_data))) + goto out; + +irq_state_set_disabled (desc);if (desc->irq_data.chip->irq_shutdown) desc->irq_data.chip->irq_shutdown (&desc->irq_data);else if (desc->irq_data.chip->irq_disable) desc->irq_data.chip->irq_disable (&desc->irq_data);else desc->irq_data.chip->irq_mask (&desc->irq_data); +out:irq_domain_deactivate_irq (&desc->irq_data);irq_state_set_masked (desc); }
Signature · 1 line
2.1.4
Quoted 2 lines · Jeffy Chen
If a irq is already disabled & masked,
free_irqmay cause a unbalanced irq shutdown/disable/mask, for example:
No, it's not. irq_shutdown/disable/mask are low level access functions which can be invoked at any given time.
The only interface which has refcounting is disable/enable_irq().
Quoted 8 lines
devm_request_irq->irq_startup->irq_enabledisable_irq<-- disabled and maskeddevm_free_irq->irq_shutdown<-- try to disable it againThis would confuse some pinctrl drivers which would control clk in irq_enable/irq_disable, for example pinctrl-rockchip/pinctrl-nomadik.
This patch add a state check in
irq_shutdownto prevent that.
Please read Documentation/process/SubmittingPatches and search for "this patch".
Quoted 5 lines
kernel/irq/chip.c +0
-0
kernel/irq/chip.c int irq_startup(struct irq_desc *desc, bool resend) · line 213
Quoted 9 lines
kernel/irq/chip.c +4
-1@@ -206,14 +206,20 @@ int irq_startup(struct irq_desc *desc, bool resend)void irq_shutdown (struct irq_desc *desc) { -irq_state_set_disabled (desc); desc->depth =1 ; + +if (unlikely (irqd_irq_disabled (&desc->irq_data) && +irqd_irq_masked (&desc->irq_data))) + goto out;
This is just wrong.
It's perfectly legit to call disable_irq() and then free_irq(). Still free_irq() has to be able to invoke chip->irq_shutdown(). Preventing that will leave some interrupt chips in a half initialized state.
The irq core does not guarntee that the unmask/mask enable/disable startup/shutdown callbacks are perfectly balanced. irq_shutdown() is only one place where this can happen. This needs more thought than this 'works for me' hackery.
Thanks,
tglx
Hi Thomas,
Quoted 9 lines · Thomas Gleixner
Quoted 2 lines · Jeffy Chen
If a irq is already disabled & masked,
free_irqmay cause a unbalanced irq shutdown/disable/mask, for example:No, it's not. irq_shutdown/disable/mask are low level access functions which can be invoked at any given time.
The only interface which has refcounting is disable/enable_irq().
but i think it still be good trying to make them balance, at least for irq enable/disable :)
Quoted 5 lines
Quoted 5 lines
devm_request_irq->irq_startup->irq_enabledisable_irq<-- disabled and maskeddevm_free_irq->irq_shutdown<-- try to disable it again
Quoted 7 lines
Quoted 4 lines
This would confuse some pinctrl drivers which would control clk in irq_enable/irq_disable, for example pinctrl-rockchip/pinctrl-nomadik.
This patch add a state check in
irq_shutdownto prevent that.Please read
Documentation/process/SubmittingPatchesand search for "this patch".
oops
Quoted 18 lines
Quoted 6 lines
kernel/irq/chip.c +0
-0kernel/irq/chip.c int irq_startup(struct irq_desc *desc, bool resend) · line 213
Quoted 9 lines
kernel/irq/chip.c +4
-1@@ -206,14 +206,20 @@ int irq_startup(struct irq_desc *desc, bool resend)void irq_shutdown (struct irq_desc *desc) { -irq_state_set_disabled (desc); desc->depth =1 ; + +if (unlikely (irqd_irq_disabled (&desc->irq_data) && +irqd_irq_masked (&desc->irq_data))) + goto out;This is just wrong.
Quoted 3 lines
It's perfectly legit to call
disable_irq()and thenfree_irq(). Stillfree_irq()has to be able to invokechip->irq_shutdown(). Preventing that will leave some interrupt chips in a half initialized state.
right, irq_shutdown is not just to disable irq, may also do some cleanups. will upload new patch.
Quoted 12 lines
The irq core does not guarntee that the unmask/mask enable/disable startup/shutdown callbacks are perfectly balanced.
irq_shutdown()is only one place where this can happen. This needs more thought than this 'works for me' hackery.Thanks,
tglx
Quoted 6 lines · jeffy
Quoted 5 lines · Thomas Gleixner
Quoted 2 lines · Jeffy Chen
If a irq is already disabled & masked,
free_irqmay cause a unbalanced irq shutdown/disable/mask, for example:
Quoted 6 lines
Quoted 4 lines
No, it's not. irq_shutdown/disable/mask are low level access functions which can be invoked at any given time.
The only interface which has refcounting is disable/enable_irq().
but i think it still be good trying to make them balance, at least for irq enable/disable :)
If we make them balanced then we do it proper and not just for the single issue you are facing. And we do not try. We analyze it proper and fix it.
It's not rocket science, but yes it takes a bit longer than cobbling something together which works just for you.
Thanks,
tglx