Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3485739pxb; Mon, 4 Apr 2022 18:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4o8vLTsV8R76mcdP3pTRhAWXCL9R5YefMpQkXJuUu5G1h1hFYYOnYLBlp+r86ubw0uHCp X-Received: by 2002:a17:90a:cd:b0:1ca:5385:2bf5 with SMTP id v13-20020a17090a00cd00b001ca53852bf5mr1196812pjd.47.1649122219869; Mon, 04 Apr 2022 18:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649122219; cv=none; d=google.com; s=arc-20160816; b=OKkdHMOLHEMwB/Oei8J8Nhnhxk+LxetB4jXtqDI8qPgPOq+8gQNc9tX0JtRG9ByezZ +68/lEpuBNACcmu5t5dqqPcXG/Hg09H/ZAI030qsMYYtVKDYPNfpl8f+cPcUCB3qwvzQ b1G+SxOWjxZ0iPYFkCVRkBKHSrLD/k2wLO13+iPK6IpKLETejx1FWQpfhaDuAvpP7qyP B2/Gg6y57lkfAbbihRJB/Zz+UF/phPImdAglYf80Jk8ChLX+wX5tv7/ZS5OG/Tis1QDM +G3B/eH25QfZnhiqesi5TKV+CzWoNpHYbzrav5dG8Gu0g7WWHqeHY266ax+/Hs24l749 22GA== 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=JCkFQmR3J8LZjOOyCd1t2e0OGoSs7KtLyKUoW26knHs=; b=HyQaM3Gst/Isf8V12YfWQRcf9U5eGD1xzCZtnChI9Aw0u60d+vMn9TKJP/lQIRcoYL Xn0PLWaWDqKY7bin3f1UuwXFQk8BHOR/tcYdVwnL9xI2C4ejMGjHVrSNuHW5xL5w0MnW ODm6d0OrtXVzXB3vVis6hMNX2mhOUuJZqiS7lQkBZiEzTxMpUS8k5mxDsd+x9d9ygTI0 JBGMydJjPUn/XYhAbOXp2t9mET6WT4ZD03rO3gRvGi3hl8JHCWUfNYsvFKzoxlEjSh3Q jDsUZQemhfDCUNk9Qb6xPcKZnlHI3VnzXq+fJSvD38E8biKrNQYSzsIuWfmlf1GLWj33 kMKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lRGsbEam; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m12-20020a056a00080c00b004fa7ebac146si12643307pfk.28.2022.04.04.18.30.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 18:30:19 -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=@gmail.com header.s=20210112 header.b=lRGsbEam; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C128C70F73; Mon, 4 Apr 2022 17:19:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357023AbiDCLns (ORCPT + 99 others); Sun, 3 Apr 2022 07:43:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238157AbiDCLnq (ORCPT ); Sun, 3 Apr 2022 07:43:46 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BAB93968F for ; Sun, 3 Apr 2022 04:41:53 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id ot30so4655546ejb.12 for ; Sun, 03 Apr 2022 04:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=JCkFQmR3J8LZjOOyCd1t2e0OGoSs7KtLyKUoW26knHs=; b=lRGsbEamAiM8kcLuqp0FhVR3ULvkFzZMKSlIlCQknQKBo9GbFh0c/bj5SPRofOytLK 8/DgXds35Tf+liTuhQJsOY1+H6A85bsRWMSuLDL30SPK0se/eQPxUjClUpnOGtI7cu2Y ybtlW5PzXRKqnXuR5FNwsZyd5L7on060woH8fphzB9FCBTYZpXxASY+FSGgaxkZmIpwd wmNAtSo1mJ10h+50NtwiZyKAFrhZASu2+DXBFPi8OAawt/Vhjx7I/bsjk1DV14aaRktf 6E1H47gokJB7ZNIgwteaHWLVsxfGuw21dM5V6t3tRBgRFbX6EmwSQWQBOawY0LOAJ2PT p0/A== 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=JCkFQmR3J8LZjOOyCd1t2e0OGoSs7KtLyKUoW26knHs=; b=gf4k4kdyUK3c2xC1Wc2w7CAxhBAZWBYbbuvev3zTGotMHIK3d/oyj5C9MKa1rxJc2K sDy22Ohp0EmmasuV9mcZYnqxAWrBSOAdFIYDlWL6lGNl4XqOkgr2NzEnjV3WGiAFAU+j YdIKGEnXTZjGzH1xHx14wpvkw6vCkmpzHjUJXiQxGxw6PJuaJdDvdvigBmTB7MV1FOO8 K2i/i8vwjcNQ2FWPk950DUZBCkqktkKCckZpzdIppn4XMnMx+dqFWHAr3E9zYUmMbym+ PTtQqEXp4dE7HyUWu1tlcyk2Zy37w6oMVOdvUb2aj9mFVscgSYjVfzy9pU2ahTyZ7OBC Zfwg== X-Gm-Message-State: AOAM531gL7dpbeVwQ2ffqGeOFYNt5fIBHe3+nkhmSZU5rwu10xHmgjGf Ymu7RnVnpEYOzMiAfm52Ock= X-Received: by 2002:a17:907:6e21:b0:6e1:c1ab:d0e0 with SMTP id sd33-20020a1709076e2100b006e1c1abd0e0mr6871592ejc.358.1648986111630; Sun, 03 Apr 2022 04:41:51 -0700 (PDT) Received: from [192.168.0.253] (ip5f5abb55.dynamic.kabel-deutschland.de. [95.90.187.85]) by smtp.gmail.com with ESMTPSA id h30-20020a056402095e00b00412b81dd96esm3666478edz.29.2022.04.03.04.41.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Apr 2022 04:41:51 -0700 (PDT) Message-ID: Date: Sun, 3 Apr 2022 13:41:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: staging: r8188eu: how to handle nested mutex under spinlock Content-Language: en-US To: "Fabio M. De Francesco" Cc: Greg KH , Larry Finger , Phillip Potter , "open list:STAGING SUBSYSTEM" , Linux Kernel Mailing List References: <356c24cf-625b-eea2-2c04-ce132d881cac@gmail.com> <1813843.tdWV9SEqCh@leap> <942bbcb6-725d-9b47-5dfe-f105d30ea6b7@gmail.com> <7365301.EvYhyI6sBW@leap> From: Michael Straube In-Reply-To: <7365301.EvYhyI6sBW@leap> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 4/3/22 13:17, Fabio M. De Francesco wrote: > On domenica 3 aprile 2022 13:08:35 CEST Michael Straube wrote: >> On 4/3/22 12:49, Fabio M. De Francesco wrote: >>> On domenica 3 aprile 2022 12:43:04 CEST Fabio M. De Francesco wrote: >>>> On sabato 2 aprile 2022 22:47:27 CEST Michael Straube wrote: >>>>> Hi all, >>>>> >>>>> smatch reported a sleeping in atomic context. >>>>> >>>>> rtw_set_802_11_disassociate() <- disables preempt >>>>> -> _rtw_pwr_wakeup() >>>>> -> ips_leave() >>>>> >>>>> rtw_set_802_11_disassociate() takes a spinlock and ips_leave() uses a >>>>> mutex. >>>>> >>>>> I'm fairly new to the locking stuff, but as far as I know this is not a >>>>> false positive since mutex can sleep, but that's not allowed under a >>>>> spinlock. >>>>> >>>>> What is the best way to handle this? >>>>> I'm not sure if converting the mutex to a spinlock (including all the >>>>> other places where the mutex is used) is the right thing to do? >>>>> >>>>> thanks, >>>>> Michael >>>>> >>>> Hi Michael, >>>> >>>> No, this is a false positive: ips_leave is never called under spinlocks. >>>> Some time ago I blindly trusted Smatch and submitted a patch for what you >>>> are reporting just now again. Soon after submission I realized it and >>>> then I had to ask Greg to discard my patch. >>>> >>>> Please read the related thread: >>>> >>>> [PATCH] staging: r8188eu: Use kzalloc() with GFP_ATOMIC in atomic context >>>> https://lore.kernel.org/lkml/20220206225943.7848-1-fmdefrancesco@gmail.com/ >>>> >>>> Thanks, >>>> >>>> Fabio >>> >>> I'm sorry, the correct link is the following: >>> [PATCH v2 2/2] staging: r8188eu: Use kzalloc() with GFP_ATOMIC in atomic context >>> https://lore.kernel.org/lkml/20220208180426.27455-3-fmdefrancesco@gmail.com/ >>> >>> Fabio >>> >> >> Hi Fabio, >> >> Ah I see now, thanks. Well, I think the code is not very clear and easy >> to follow here. Perhaps we should refactor this area someday to avoid >> future confusions. >> >> regards, >> Michael >> > Soon after I sent the email above, I read yours anew. The issue I were trying > to address were different than what you noticed today. I didn't even see that > we were in nested mutexes under spinlocks and bottom halves disabled. I just > saw those kmalloc() with GFP_KERNEL. > > You are noticing something one layer up. And you are right, this is a real > issue. Larry's suggestion is the only correct one for fixing this. > > I've analyzed and reviewed some code in the tty layer that implements the > same solution that Larry is talking about. Let me find the link and I'll > soon send it to you, so that you might be inspired from that implementation. > > Sorry for the confusion. > > Thanks, > > Fabio > > > Hi Fabio, wait.. rtw_set_802_11_disassociate() calls rtw_pwr_wakeup() only if check_fwstate(pmlmepriv, _FW_LINKED) is true. if (check_fwstate(pmlmepriv, _FW_LINKED)) { rtw_disassoc_cmd(padapter, 0, true); rtw_indicate_disconnect(padapter); rtw_free_assoc_resources(padapter, 1); rtw_pwr_wakeup(padapter); } in rtw_pwr_wakeup() there is the same check and if it is true the function returns before calling ips_leave(). if (check_fwstate(pmlmepriv, _FW_LINKED)) { ret = _SUCCESS; goto exit; } if (rf_off == pwrpriv->rf_pwrstate) { if (_FAIL == ips_leave(padapter)) { ret = _FAIL; goto exit; } } So ips_leave() is not called in atomic context in this case and smatch reports indeed a false positive, or am I wrong? I have not checked the other calls to rtw_pwr_wakeup(). regards, Michael