Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp117557iob; Tue, 17 May 2022 20:48:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4ls0T5q/+4UEzOjZ+dqqU4AsG218NqHmbEEpPJU7GWnBZJ8mC9wptAK6Q5C7Di+N/Bccb X-Received: by 2002:a17:902:e542:b0:15e:8c75:e251 with SMTP id n2-20020a170902e54200b0015e8c75e251mr24938102plf.76.1652845735324; Tue, 17 May 2022 20:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845735; cv=none; d=google.com; s=arc-20160816; b=gOfFgtGEmjbCXz5RulZCCebEvqcJk8tpdTVo0svXFpWrPps7EbBx/qOG60vdxZNB9R obhwmZqAh9/BhbysYcoAh3mBf39U6mmTvrbmP8YNb7tKhsCyislPwUlhBcZjhL7/tV9Y hV38Kn1U0mJ3IMRB3XzIuty1w+Pg2qHSnt4ugAIuOURph23JI+RXI/gVYYWfKCFcmI5k socLQzL0PO+K1fMkLonFUBjqmXrbMoqyuvVx6G8dhw6ucIHxUcOlV6iFcHEi0P/jh4Oj 1zKR9fieBcgD765f4DHaIKBVqyjdQUnQGM1AbZ9W2m220xwtlq/pWzmEyZ2w6xpo5vZ6 lY2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uj5rCEgrEME0641i65F/SbR6hoTPj4hzhlWTwqHQqWk=; b=pb0Kmh7Um9teSBb5MFI8B8ihZzh26l+JZWT8YG4A8DsKFOBeSMY29VRCwqo/6dFILU aUmozgJ/Zd540qxwEu4Jux1kwfh9YADTBUhTfJfcUyR8DVcbEM59ixNVDv7af48DKqvB 6g76wGcPJVTTvjk2A67hcMnyu86yfEeti+pRb5kDIPc/YUS9KY73YYQxZpaRnZ5bH++0 0unRlB3LYff7p6Pyv+KKrw0qemg9JH8u3Rlv92BSz6+w7mIo3qK2dhivWZO0nm4a+J3m dbdz3jDlJ4cYv3zATXLSl17JThr5TJ7osSFF1tA3MikfC4Ri4qh4/GYuWTfLdkQNzis7 ZxWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RcFydaN3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i64-20020a62c143000000b005182ee53568si102924pfg.359.2022.05.17.20.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:48:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RcFydaN3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1AC995B3E1; Tue, 17 May 2022 20:31:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345389AbiEQLmt (ORCPT + 99 others); Tue, 17 May 2022 07:42:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238852AbiEQLmp (ORCPT ); Tue, 17 May 2022 07:42:45 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 519BF27FFE for ; Tue, 17 May 2022 04:42:44 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id 16so21421766lju.13 for ; Tue, 17 May 2022 04:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=uj5rCEgrEME0641i65F/SbR6hoTPj4hzhlWTwqHQqWk=; b=RcFydaN3PbLyev6mS4qntlxs4M51b7yJgGfZ8ex/bJuWNY0MSRmcIhwi52CSHHNZdN ptBAimz8cIO2HJN9H/Ig0xRPIxLfJCNPWQ4+PPpm1u4UiJ/7LDS8rR/9UqByvZlpXKKd PMrrZUBBzxyVPDbd6F8cBquq4HN7wkJ+jAm+nTco1smdGWT92QvDiX0L0QsGSXitoGY7 C/SMR6Bc4k4+9+KRvHwCh8OIsbvDO87DGgOvuIxuHz0qBdwCFF71dHc0k9MI41RKFExh NSZ0DnGvT6jTrZMTXXuv6Wk56JTbW7jqg1PhfR6n3Dy2cKXOTTkR1xy69Z5mzIhThqpi B+Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=uj5rCEgrEME0641i65F/SbR6hoTPj4hzhlWTwqHQqWk=; b=JxMTXoddkKet3WGKHeDtsqzAtYMQvcGo+j0BykjtVI7mDeZ4mlFNxGCeomSWSBSuEu ti0ACdthV8mtf8VSUfNWca2Xv1R807R7bBVah+sNYZonTaFSaAqykqGyjvbPipexWr+O JY+/S45vMKpxOxdkkLrrroeSPT3eCrdR5aIOLyn+5y3PgbleHAjC+iRvsAbPDn/NuG9r PO/ZvLUwIHY2wWveiopsHkzvlfNSUFSc59dBlnFM2zReqLYBLgVma/Ceu7tmAPFqij+W LFmI2f8zH5115DdSI+cgsYeF2QKvYSNh9BNytw7otTFO8itwHWHlFMVJ5gZfjsmhL1iy Z3Zg== X-Gm-Message-State: AOAM532E7YD27AiXv3s5+zpyaXcMdCwoRYa6v7DI+Le/Dxa1W936fFAg xSRI94kKJRL3jpOe0k2IuZEzwg== X-Received: by 2002:a2e:81a:0:b0:250:a331:d0b1 with SMTP id 26-20020a2e081a000000b00250a331d0b1mr14297265lji.363.1652787762678; Tue, 17 May 2022 04:42:42 -0700 (PDT) Received: from [192.168.0.17] (78-11-189-27.static.ip.netia.com.pl. [78.11.189.27]) by smtp.gmail.com with ESMTPSA id j20-20020a2e8014000000b0024f3d1dae96sm1874136ljg.30.2022.05.17.04.42.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 May 2022 04:42:42 -0700 (PDT) Message-ID: <2ce7a871-3e55-ae50-955c-bf04a443aba3@linaro.org> Date: Tue, 17 May 2022 13:42:41 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH net v2] NFC: hci: fix sleep in atomic context bugs in nfc_hci_hcp_message_tx Content-Language: en-US To: Duoming Zhou , linux-kernel@vger.kernel.org Cc: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, gregkh@linuxfoundation.org, alexander.deucher@amd.com, broonie@kernel.org, netdev@vger.kernel.org References: <20220517105526.114421-1-duoming@zju.edu.cn> From: Krzysztof Kozlowski In-Reply-To: <20220517105526.114421-1-duoming@zju.edu.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/05/2022 12:55, Duoming Zhou wrote: > 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 changes allocation mode of kzalloc and alloc_skb from > GFP_KERNEL to GFP_ATOMIC and changes mutex_lock to spin_lock in > order to prevent atomic context from sleeping. > > Fixes: 2130fb97fecf ("NFC: st21nfca: Adding support for secure element") > Signed-off-by: Duoming Zhou > --- > Changes in v2: > - Change mutex_lock to spin_lock. > > include/net/nfc/hci.h | 3 ++- > net/nfc/hci/core.c | 18 +++++++++--------- > net/nfc/hci/hcp.c | 10 +++++----- > 3 files changed, 16 insertions(+), 15 deletions(-) > > diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h > index 756c11084f6..8f66e6e6b91 100644 > --- a/include/net/nfc/hci.h > +++ b/include/net/nfc/hci.h > @@ -103,7 +103,8 @@ struct nfc_hci_dev { > > bool shutting_down; > > - struct mutex msg_tx_mutex; > + /* The spinlock is used to protect resources related with hci message TX */ > + spinlock_t msg_tx_spin; > > struct list_head msg_tx_queue; > > diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c > index ceb87db57cd..fa22f9fe5fc 100644 > --- a/net/nfc/hci/core.c > +++ b/net/nfc/hci/core.c > @@ -68,7 +68,7 @@ static void nfc_hci_msg_tx_work(struct work_struct *work) > struct sk_buff *skb; > int r = 0; > > - mutex_lock(&hdev->msg_tx_mutex); > + spin_lock(&hdev->msg_tx_spin); > if (hdev->shutting_down) > goto exit; How did you test your patch? Did you check, really check, that this can be an atomic (non-sleeping) section? I have doubts because I found at least one path leading to device_lock (which is a mutex) called within your new code. Before sending a new version, please wait for discussion to reach some consensus. The quality of these fixes is really poor. :( Best regards, Krzysztof