Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2154279ybh; Fri, 17 Jul 2020 10:32:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPqfkZFtszmED7n1KS3cPsGyd5dGI8RhATuJFcCJ/21SwAHvS/RDmsHBDDrhfDN1iqIVdc X-Received: by 2002:aa7:d8c2:: with SMTP id k2mr10156746eds.346.1595007142194; Fri, 17 Jul 2020 10:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595007142; cv=none; d=google.com; s=arc-20160816; b=wJ2h8SV+QwDZ5y+KDcKK5WoeY3hhdF4rDmHBma6v4AT3uHQeSBEYnae3R/mPxJQnUc EaJs2tR4ksCVFAKgoHVdsZ65F7dRAHXFwS23DUHuBXVdZVZw0su8lC5Yi6zMEynWLdzK b/uH2yo6dOTstwgar5b67XLMEIbVeS20UyW+kjHwNAZwz6cpbxjR9NgTlHVQXKKqaWAE +d99GMDW269RBBaVr4KgCVglGpz6tS7nJZb+ODmhJoUX92+U2Zvb82XW6iUAvXcN8fg6 9bBVM2NtARRev6GQ9l16geMi3000IHvTiTiCpvMe0Hf/NKJ3+IWvAGcJHM/KEuAb6Iiq 5PGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=XFgYMGoKiX49l1DrRRroifUSZDfK1GLfBiXM5ZME7LU=; b=HEUKD1f4F69mQmMRSVcg3o8UqJwPLmd4gIfug6pr0Hks06wdr4P7AFKrUbHIDUaGwS XYxjg0wpetKlWwq1MoXE4If8uXAzy+WWIV4981Ulz2rRrY4Z+9uEeEUDvH4VCsa+WsqN bCmRvbh+BeSgF5/cDMuKshlpbGltWYyk+cNgsKTkdp5OO+7FqXEtkns1Dt2RirjYDCda M5+PdaZD33ExJtzxGlM7DZSHJlnJoJpvgfSlozw3CI5gSP7tdnzwLFE9GOZCddZRDb5+ o85MHd0xt83VV4RZMaco4NqfEgLQTpigjGegP+2zdSLJowE0LqjImPEpdgQTOPRQ9+yq Sxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NTAIkpXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e14si5934171edr.380.2020.07.17.10.31.59; Fri, 17 Jul 2020 10:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NTAIkpXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726351AbgGQRbu (ORCPT + 99 others); Fri, 17 Jul 2020 13:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgGQRbu (ORCPT ); Fri, 17 Jul 2020 13:31:50 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC855C0619D2 for ; Fri, 17 Jul 2020 10:31:49 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id a23so4142858pfk.13 for ; Fri, 17 Jul 2020 10:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XFgYMGoKiX49l1DrRRroifUSZDfK1GLfBiXM5ZME7LU=; b=NTAIkpXZs3R0/tyj+kfF1UAEFf7YQPnRv/fOJXVKn9Wipmia8S6aiULGLOTUYLcpVK Ka8rISkOqc5D2/28OFWffArLGdT5OolGAa50rYnPjTfeLh6DY6TQrfXq9aABDoFZiZoM PcgMu24PPM4TsuQwT5TS1mTBugFnF9i8A+JDFumQnDKni0sSBR6EFgc5FMoFpvIPdh0f JlsZuxDwOZDbGFyBHAQNKybPhUVmiijqXmuZ/XhjCKbW/YbuFPhEApvUZbFOX2FIb3hp BIMs6J4XRuB6uFsgZ4+k7YpvCLCLkRbNwbJSpQD/IFsEqqnUYdFe6TkUD4zLeXPpAsnj SAUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XFgYMGoKiX49l1DrRRroifUSZDfK1GLfBiXM5ZME7LU=; b=J/3Ie6C/U1ljHq7moGx9M0Zk14PCEfkCLh07L+nX3OSF93sGKRRdLXPz5+eiR5fMtW YwcOmcyA4KI+1Bw+YnGGHSynyImv1OmLPve6HQs1V1EA3j1d3y5gd+4S6bWmLwuMtu0E 68bTPl5dhd1P/BVFbaW681Ch58VtlV1sBhqOwULVah5EoF4dHfNrkdCfPZXct0hhTU5z 5+LbO/gNlaUY55UQfhc8vL1XmTNA2Kia+m9RsrmjyZQRcjs5CismC6VAh8nSFulEPsd6 TY+UikNrMFh7UF28I8Ysq82p8x+hKuiO434J6aAgpEn/qJJtGaE8gQ/WVuHk0rRLcGKs eSjQ== X-Gm-Message-State: AOAM530vc8v3MIEO4U9dVR1ebDZvyCqV+pIOvpAbyoguEZwV5WNxxGJY UGx4n288UBsiPEWglwk42wGWtv8guDxbW286k0YxWw== X-Received: by 2002:a05:6a00:15c7:: with SMTP id o7mr8670450pfu.51.1595007109035; Fri, 17 Jul 2020 10:31:49 -0700 (PDT) MIME-Version: 1.0 References: <20200716214523.2924704-1-saravanak@google.com> <6b37125c-96f5-c59c-f170-934d68c9bed1@samsung.com> <20200717163434.GA119309@roeck-us.net> In-Reply-To: <20200717163434.GA119309@roeck-us.net> From: Saravana Kannan Date: Fri, 17 Jul 2020 10:31:13 -0700 Message-ID: Subject: Re: [PATCH v2] driver core: Fix sleeping in invalid context during device link deletion To: Guenter Roeck Cc: Marek Szyprowski , Greg Kroah-Hartman , "Rafael J. Wysocki" , Android Kernel Team , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 9:34 AM Guenter Roeck wrote: > > On Fri, Jul 17, 2020 at 12:13:04AM +0200, Marek Szyprowski wrote: > > Hi Saravana, > > > > On 16.07.2020 23:45, Saravana Kannan wrote: > > > Marek and Guenter reported that commit 287905e68dd2 ("driver core: > > > Expose device link details in sysfs") caused sleeping/scheduling while > > > atomic warnings. > > > > > > BUG: sleeping function called from invalid context at kernel/locking/mutex.c:935 > > > in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 12, name: kworker/0:1 > > > 2 locks held by kworker/0:1/12: > > > #0: ee8074a8 ((wq_completion)rcu_gp){+.+.}-{0:0}, at: process_one_work+0x174/0x7dc > > > #1: ee921f20 ((work_completion)(&sdp->work)){+.+.}-{0:0}, at: process_one_work+0x174/0x7dc > > > Preemption disabled at: > > > [] srcu_invoke_callbacks+0xc0/0x154 > > > ----- 8< ----- SNIP > > > [] (device_del) from [] (device_unregister+0x24/0x64) > > > [] (device_unregister) from [] (srcu_invoke_callbacks+0xcc/0x154) > > > [] (srcu_invoke_callbacks) from [] (process_one_work+0x234/0x7dc) > > > [] (process_one_work) from [] (worker_thread+0x44/0x51c) > > > [] (worker_thread) from [] (kthread+0x158/0x1a0) > > > [] (kthread) from [] (ret_from_fork+0x14/0x20) > > > Exception stack(0xee921fb0 to 0xee921ff8) > > > > > > This was caused by the device link device being released in the context > > > of srcu_invoke_callbacks(). There is no need to wait till the RCU > > > callback to release the device link device. So release the device > > > earlier and move the call_srcu() into the device release code. That way, > > > the memory will get freed only after the device is released AND the RCU > > > callback is called. > > > > > > Fixes: 287905e68dd2 ("driver core: Expose device link details in sysfs") > > > Reported-by: Marek Szyprowski > > > Reported-by: Guenter Roeck > > > Signed-off-by: Saravana Kannan > > > --- > > > > > > v1->v2: > > > - Better fix > > > - Changed subject > > > - v1 is this patch https://lore.kernel.org/lkml/20200716050846.2047110-1-saravanak@google.com/ > > > > > > Marek and Guenter, > > > > > > I reproduced the original issue and tested this fix. Seems to work for > > > me. Can you confirm? > > > > Confirmed, this one fixes the issue! :) > > > Same here. > > Tested-by: Guenter Roeck > > Guenter > > > Tested-by: Marek Szyprowski > > Thanks both. Greg, can you review this and pull this into driver-core-next too? -Saravana