NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx
authorDuoming Zhou <duoming@zju.edu.cn>
Wed, 18 May 2022 11:57:33 +0000 (19:57 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 20 May 2022 00:54:02 +0000 (17:54 -0700)
commitb413b0cb008646e9f24ce5253cb3cf7ee217aff6
tree714c44985ca40de1a3b9a2299dcc424578ae81b8
parent582a2dbc72ac5dd2b3ae4f75bccd4b4c73bb0e1f
NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx

There are sleep in atomic context bugs when the request to secure
element of st21nfca is timeout. The root cause is that kzalloc and
alloc_skb with GFP_KERNEL parameter and mutex_lock are called in
st21nfca_se_wt_timeout which is a timer handler. The call tree shows
the execution paths that could lead to bugs:

   (Interrupt context)
st21nfca_se_wt_timeout
  nfc_hci_send_event
    nfc_hci_hcp_message_tx
      kzalloc(..., GFP_KERNEL) //may sleep
      alloc_skb(..., GFP_KERNEL) //may sleep
      mutex_lock() //may sleep

This patch moves the operations that may sleep into a work item.
The work item will run in another kernel thread which is in
process context to execute the bottom half of the interrupt.
So it could prevent atomic context from sleeping.

Fixes: 2130fb97fecf ("NFC: st21nfca: Adding support for secure element")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220518115733.62111-1-duoming@zju.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/nfc/st21nfca/se.c
drivers/nfc/st21nfca/st21nfca.h