From patchwork Tue Sep 1 18:44:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 11749357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D9AB14E5 for ; Tue, 1 Sep 2020 18:47:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 015B820767 for ; Tue, 1 Sep 2020 18:47:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OQ/Uki1D"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="g0AbURRG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 015B820767 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=QUzUJvnmV4eiHxoe03v6MacH0dPuoTjnWsh5JlBBXQM=; b=OQ/Uki1D2QNMWIGJw/VSmEpzzJ uYcQWTiOqSLLTrB0V5Pq8+0JNso8J+lptLhAIKYKeav8initwmLr06bsdrvPeDVbwLUGrjB9Ka7YL xwr5DQC4IeOzdr8J+AgQfahLUZjLpVUR6UxMk7W8jKzxboJQMu79eqyus7b5KUR5AitdcBWaWsD21 YA4w+BLbKZEc1QVzHOYpKpF1FmNqzpikbPRfJ7EjsbL+xuctoeBddAliHD3Qquq+sjYLmjlwhRGoA tMBpzzCdxhP6CpS08SwamLQ6dLev9qDRZ26adTEJsGjIuWRGWqcZVD+IeluyQPoEJ2zA6Ty54v9lu MRhpyzCA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDBH9-0007B2-Jg; Tue, 01 Sep 2020 18:44:59 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDBH6-00078b-Hb for linux-arm-kernel@lists.infradead.org; Tue, 01 Sep 2020 18:44:57 +0000 Received: by mail-qt1-x84a.google.com with SMTP id w15so1722236qtv.11 for ; Tue, 01 Sep 2020 11:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=lzhpqq8bzD/FsaCTfkvt8bsW4hhopaei7M9mtOQ3b7A=; b=g0AbURRGuByGLoi+yDQWo3qk5VT8Y8gTd1nXll8yg8pR3A+kjAmWplpHcfk0+zOGIo KsLMPMVlxScwnCLKfSMCqdWD8+iX8p/onFM8QmcSZH6utZKed3sd+z7uBRmLahFsIjj/ MlTzqniO6cUe9Q3GS8H7BAbdlCo+tqw4EiHXiSbagNyyxRS9yH615tjjaORSHXIYP2LV VMoJMegISpjs4KPE7XAnCybNiFW/D/Wr4LYRQHqZm1we9HhO0xLOBXT3v5oP7mT9O8/U VJ/CprcRHopb0GP1Ftlf0jI3ZEdfiHhgTWpv+Vf1hlhQvH/aE0Kz+C5pp16/DqKIpohL YmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=lzhpqq8bzD/FsaCTfkvt8bsW4hhopaei7M9mtOQ3b7A=; b=MqN7jfMH4jUooFukovlqCss2d4bpZAhTSBdQqCL7OTNirWyoCuPeoIukgalHpdkhX6 75qF7YfSGMIqfqMVrDAhyuKeMhvBElnVdO1kE8VKJE2F1pkWYCp6KjySoGU8ZZXmz6UC ZHYiMi5XHwzxl19TUDUvP+K9y61j2fbpTIyn+aDaYUTApt4tDxKJGsOkvtJpNM0nP4yu 6bMD06lNemxpBDf7dexNqih+7H5unBfZ7wWOHD/ie94b07g5gcwIC54ASXQxlCqx/EUB WubpzPM712nexQzlhh4dtbrY/dNosslCrh0MkiKM3I7QtiEeJ4E1l2nIWYuN+Kd8eGTj pvvQ== X-Gm-Message-State: AOAM533LXxq39/Kv/UmYu88fb+Hy5occCt/5KSiPKMVivKrKuZscbK9S e5Br5eiVjG3/S96dTJq40nczY4hskkxDyuU= X-Google-Smtp-Source: ABdhPJzh8gaRFmSXXD1HZfckYU1uQH2CHBg2Z8WbzU3UOWT8yr6hfKlXtXxkxUNQSHLtC6QtkJxinFdWAK4L6OQ= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:11:7220:84ff:fe09:fedc]) (user=saravanak job=sendgmr) by 2002:a0c:9b89:: with SMTP id o9mr3313403qve.77.1598985889330; Tue, 01 Sep 2020 11:44:49 -0700 (PDT) Date: Tue, 1 Sep 2020 11:44:44 -0700 Message-Id: <20200901184445.1736658-1-saravanak@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.402.g5ffc5be6b7-goog Subject: [PATCH v2] driver core: Fix device_pm_lock() locking for device links From: Saravana Kannan To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Saravana Kannan X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200901_144456_603507_5BC3D388 X-CRM114-Status: GOOD ( 14.93 ) X-Spam-Score: -8.2 (--------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-8.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:84a listed in] [list.dnswl.org] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.5 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dong Aisheng , Peng Fan , Dong Aisheng , Stephen Boyd , kernel-team@android.com, naresh.kamboju@linaro.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, Sascha Hauer , m.szyprowski@samsung.com, Shawn Guo , linux@roeck-us.net, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This commit fixes two issues: 1. The lockdep warning reported by Dong Aisheng [1]. It is a warning about a cycle (dpm_list_mtx --> kn->active#3 --> fw_lock) that was introduced when device-link devices were added to expose device link information in sysfs. The patch that "introduced" this cycle can't be reverted because it's fixes a real SRCU issue and also ensures that the device-link device is deleted as soon as the device-link is deleted. This is important to avoid sysfs name collisions if the device-link is create again immediately (this can happen a lot with deferred probing). 2. Inconsistency in grabbing device_pm_lock() during device link deletion Some device link deletion code paths grab device_pm_lock(), while others don't. The device_pm_lock() is grabbed during device_link_add() because it checks if the supplier is in the dpm_list and also reorders the dpm_list. However, when a device link is deleted, it does not do either of those and therefore device_pm_lock() is not necessary. Dropping the device_pm_lock() in all the device link deletion paths removes the inconsistency in locking. Thanks to Stephen Boyd for helping me understand the lockdep splat. Fixes: 843e600b8a2b ("driver core: Fix sleeping in invalid context during device link deletion") [1] - https://lore.kernel.org/lkml/CAA+hA=S4eAreb7vo69LAXSk2t5=DEKNxHaiY1wSpk4xTp9urLg@mail.gmail.com/ Reported-by: Dong Aisheng Signed-off-by: Saravana Kannan Tested-by: Peng Fan --- Cc'ing everyone from the original thread [1] -Saravana drivers/base/core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index f6f620aa9408..07e5ceb40bb1 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -807,9 +807,7 @@ static void device_link_put_kref(struct device_link *link) void device_link_del(struct device_link *link) { device_links_write_lock(); - device_pm_lock(); device_link_put_kref(link); - device_pm_unlock(); device_links_write_unlock(); } EXPORT_SYMBOL_GPL(device_link_del); @@ -830,7 +828,6 @@ void device_link_remove(void *consumer, struct device *supplier) return; device_links_write_lock(); - device_pm_lock(); list_for_each_entry(link, &supplier->links.consumers, s_node) { if (link->consumer == consumer) { @@ -839,7 +836,6 @@ void device_link_remove(void *consumer, struct device *supplier) } } - device_pm_unlock(); device_links_write_unlock(); } EXPORT_SYMBOL_GPL(device_link_remove);