[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0936d5f3-aef2-0553-408b-07b3bb47e36b@linux.ibm.com>
Date: Tue, 1 Feb 2022 18:06:12 +0100
From: Karsten Graul <kgraul@...ux.ibm.com>
To: Jia-Ju Bai <baijiaju1990@...il.com>, davem@...emloft.net,
kuba@...nel.org
Cc: linux-s390@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [BUG] net: smc: possible deadlock in smc_lgr_free() and
smc_link_down_work()
On 01/02/2022 08:51, Jia-Ju Bai wrote:
> Hello,
>
> My static analysis tool reports a possible deadlock in the smc module in Linux 5.16:
>
> smc_lgr_free()
> mutex_lock(&lgr->llc_conf_mutex); --> Line 1289 (Lock A)
> smcr_link_clear()
> smc_wr_free_link()
> wait_event(lnk->wr_tx_wait, ...); --> Line 648 (Wait X)
>
> smc_link_down_work()
> mutex_lock(&lgr->llc_conf_mutex); --> Line 1683 (Lock A)
> smcr_link_down()
> smcr_link_clear()
> smc_wr_free_link()
> smc_wr_wakeup_tx_wait()
> wake_up_all(&lnk->wr_tx_wait); --> Line 78 (Wake X)
>
> When smc_lgr_free() is executed, "Wait X" is performed by holding "Lock A". If smc_link_down_work() is executed at this time, "Wake X" cannot be performed to wake up "Wait X" in smc_lgr_free(), because "Lock A" has been already hold by smc_lgr_free(), causing a possible deadlock.
>
> I am not quite sure whether this possible problem is real and how to fix it if it is real.
> Any feedback would be appreciated, thanks :)
A deeper analysis showed up that this reported possible deadlock is actually not a problem.
The wait on line 648 in smc_wr.c
wait_event(lnk->wr_tx_wait, (!atomic_read(&lnk->wr_tx_refcnt)));
waits as long as the refcount wr_tx_refcnt is not zero.
Every time when a caller stops using a link wr_tx_refcnt is decreased, and when it reaches
zero the wr_tx_wait is woken up in smc_wr_tx_link_put() in smc_wr.h, line 70:
if (atomic_dec_and_test(&link->wr_tx_refcnt))
wake_up_all(&link->wr_tx_wait);
Multiple callers of smc_wr_tx_link_put() do not run under the llc_conf_mutex lock, and those
who run under this mutex are saved against the wait_event() in smc_wr_free_link().
Thank you for reporting this finding! Which tool did you use for this analysis?
Powered by blists - more mailing lists