2023-03-27 19:35:10

by Sean Anderson

[permalink] [raw]
Subject: [PATCH 1/2] soc: fsl: qbman: Always disable interrupts when taking cgr_lock

smp_call_function_single disables IRQs when executing the callback. To
prevent deadlocks, we must disable IRQs when taking cgr_lock elsewhere.
This is already done by qman_update_cgr and qman_delete_cgr; fix the
other lockers.

Fixes: c535e923bb97 ("soc/fsl: Introduce DPAA 1.x QMan device driver")
Signed-off-by: Sean Anderson <[email protected]>
---

drivers/soc/fsl/qbman/qman.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
index 739e4eee6b75..ff870ca07596 100644
--- a/drivers/soc/fsl/qbman/qman.c
+++ b/drivers/soc/fsl/qbman/qman.c
@@ -1456,7 +1456,7 @@ static void qm_congestion_task(struct work_struct *work)
union qm_mc_result *mcr;
struct qman_cgr *cgr;

- spin_lock(&p->cgr_lock);
+ spin_lock_irq(&p->cgr_lock);
qm_mc_start(&p->p);
qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCONGESTION);
if (!qm_mc_result_timeout(&p->p, &mcr)) {
@@ -1476,7 +1476,7 @@ static void qm_congestion_task(struct work_struct *work)
list_for_each_entry(cgr, &p->cgr_cbs, node)
if (cgr->cb && qman_cgrs_get(&c, cgr->cgrid))
cgr->cb(p, cgr, qman_cgrs_get(&rr, cgr->cgrid));
- spin_unlock(&p->cgr_lock);
+ spin_unlock_irq(&p->cgr_lock);
qman_p_irqsource_add(p, QM_PIRQ_CSCI);
}

@@ -2440,7 +2440,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
preempt_enable();

cgr->chan = p->config->channel;
- spin_lock(&p->cgr_lock);
+ spin_lock_irq(&p->cgr_lock);

if (opts) {
struct qm_mcc_initcgr local_opts = *opts;
@@ -2477,7 +2477,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32 flags,
qman_cgrs_get(&p->cgrs[1], cgr->cgrid))
cgr->cb(p, cgr, 1);
out:
- spin_unlock(&p->cgr_lock);
+ spin_unlock_irq(&p->cgr_lock);
put_affine_portal();
return ret;
}
--
2.35.1.1320.gc452695387.dirty


2023-03-31 11:10:22

by Camelia Alexandra Groza

[permalink] [raw]
Subject: RE: [PATCH 1/2] soc: fsl: qbman: Always disable interrupts when taking cgr_lock

> -----Original Message-----
> From: Sean Anderson <[email protected]>
> Sent: Monday, March 27, 2023 22:29
> To: Leo Li <[email protected]>; [email protected]; linux-arm-
> [email protected]
> Cc: Scott Wood <[email protected]>; [email protected]; David S .
> Miller <[email protected]>; Claudiu Manoil <[email protected]>;
> Roy Pledge <[email protected]>; Vladimir Oltean
> <[email protected]>; Camelia Alexandra Groza
> <[email protected]>; Sean Anderson <[email protected]>
> Subject: [PATCH 1/2] soc: fsl: qbman: Always disable interrupts when taking
> cgr_lock
>
> smp_call_function_single disables IRQs when executing the callback. To
> prevent deadlocks, we must disable IRQs when taking cgr_lock elsewhere.
> This is already done by qman_update_cgr and qman_delete_cgr; fix the
> other lockers.
>
> Fixes: c535e923bb97 ("soc/fsl: Introduce DPAA 1.x QMan device driver")
> Signed-off-by: Sean Anderson <[email protected]>
> ---
>
> drivers/soc/fsl/qbman/qman.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
> index 739e4eee6b75..ff870ca07596 100644
> --- a/drivers/soc/fsl/qbman/qman.c
> +++ b/drivers/soc/fsl/qbman/qman.c
> @@ -1456,7 +1456,7 @@ static void qm_congestion_task(struct work_struct
> *work)
> union qm_mc_result *mcr;
> struct qman_cgr *cgr;
>
> - spin_lock(&p->cgr_lock);
> + spin_lock_irq(&p->cgr_lock);
> qm_mc_start(&p->p);
> qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCONGESTION);
> if (!qm_mc_result_timeout(&p->p, &mcr)) {
> @@ -1476,7 +1476,7 @@ static void qm_congestion_task(struct work_struct
> *work)
> list_for_each_entry(cgr, &p->cgr_cbs, node)
> if (cgr->cb && qman_cgrs_get(&c, cgr->cgrid))
> cgr->cb(p, cgr, qman_cgrs_get(&rr, cgr->cgrid));
> - spin_unlock(&p->cgr_lock);
> + spin_unlock_irq(&p->cgr_lock);
> qman_p_irqsource_add(p, QM_PIRQ_CSCI);
> }

There is one more spin_unlock call in qm_congestion_task on the error path that needs updating:

if (!qm_mc_result_timeout(&p->p, &mcr)) {
spin_unlock(&p->cgr_lock);

Regards,
Camelia

> @@ -2440,7 +2440,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32
> flags,
> preempt_enable();
>
> cgr->chan = p->config->channel;
> - spin_lock(&p->cgr_lock);
> + spin_lock_irq(&p->cgr_lock);
>
> if (opts) {
> struct qm_mcc_initcgr local_opts = *opts;
> @@ -2477,7 +2477,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32
> flags,
> qman_cgrs_get(&p->cgrs[1], cgr->cgrid))
> cgr->cb(p, cgr, 1);
> out:
> - spin_unlock(&p->cgr_lock);
> + spin_unlock_irq(&p->cgr_lock);
> put_affine_portal();
> return ret;
> }
> --
> 2.35.1.1320.gc452695387.dirty

2023-03-31 14:57:43

by Sean Anderson

[permalink] [raw]
Subject: Re: [PATCH 1/2] soc: fsl: qbman: Always disable interrupts when taking cgr_lock

On 3/31/23 06:58, Camelia Alexandra Groza wrote:
>> -----Original Message-----
>> From: Sean Anderson <[email protected]>
>> Sent: Monday, March 27, 2023 22:29
>> To: Leo Li <[email protected]>; [email protected]; linux-arm-
>> [email protected]
>> Cc: Scott Wood <[email protected]>; [email protected]; David S .
>> Miller <[email protected]>; Claudiu Manoil <[email protected]>;
>> Roy Pledge <[email protected]>; Vladimir Oltean
>> <[email protected]>; Camelia Alexandra Groza
>> <[email protected]>; Sean Anderson <[email protected]>
>> Subject: [PATCH 1/2] soc: fsl: qbman: Always disable interrupts when taking
>> cgr_lock
>>
>> smp_call_function_single disables IRQs when executing the callback. To
>> prevent deadlocks, we must disable IRQs when taking cgr_lock elsewhere.
>> This is already done by qman_update_cgr and qman_delete_cgr; fix the
>> other lockers.
>>
>> Fixes: c535e923bb97 ("soc/fsl: Introduce DPAA 1.x QMan device driver")
>> Signed-off-by: Sean Anderson <[email protected]>
>> ---
>>
>> drivers/soc/fsl/qbman/qman.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
>> index 739e4eee6b75..ff870ca07596 100644
>> --- a/drivers/soc/fsl/qbman/qman.c
>> +++ b/drivers/soc/fsl/qbman/qman.c
>> @@ -1456,7 +1456,7 @@ static void qm_congestion_task(struct work_struct
>> *work)
>> union qm_mc_result *mcr;
>> struct qman_cgr *cgr;
>>
>> - spin_lock(&p->cgr_lock);
>> + spin_lock_irq(&p->cgr_lock);
>> qm_mc_start(&p->p);
>> qm_mc_commit(&p->p, QM_MCC_VERB_QUERYCONGESTION);
>> if (!qm_mc_result_timeout(&p->p, &mcr)) {
>> @@ -1476,7 +1476,7 @@ static void qm_congestion_task(struct work_struct
>> *work)
>> list_for_each_entry(cgr, &p->cgr_cbs, node)
>> if (cgr->cb && qman_cgrs_get(&c, cgr->cgrid))
>> cgr->cb(p, cgr, qman_cgrs_get(&rr, cgr->cgrid));
>> - spin_unlock(&p->cgr_lock);
>> + spin_unlock_irq(&p->cgr_lock);
>> qman_p_irqsource_add(p, QM_PIRQ_CSCI);
>> }
>
> There is one more spin_unlock call in qm_congestion_task on the error path that needs updating:
>
> if (!qm_mc_result_timeout(&p->p, &mcr)) {
> spin_unlock(&p->cgr_lock);

Will fix. Thanks.

--Sean

>
>> @@ -2440,7 +2440,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32
>> flags,
>> preempt_enable();
>>
>> cgr->chan = p->config->channel;
>> - spin_lock(&p->cgr_lock);
>> + spin_lock_irq(&p->cgr_lock);
>>
>> if (opts) {
>> struct qm_mcc_initcgr local_opts = *opts;
>> @@ -2477,7 +2477,7 @@ int qman_create_cgr(struct qman_cgr *cgr, u32
>> flags,
>> qman_cgrs_get(&p->cgrs[1], cgr->cgrid))
>> cgr->cb(p, cgr, 1);
>> out:
>> - spin_unlock(&p->cgr_lock);
>> + spin_unlock_irq(&p->cgr_lock);
>> put_affine_portal();
>> return ret;
>> }
>> --
>> 2.35.1.1320.gc452695387.dirty
>