Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp797554pxb; Tue, 3 Nov 2020 12:49:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyV5YWaEwrVY2uvtn3j3WJ9tMTw52acO+m+IsvwXjs4Qb1TYLnH9+jjAv6uzxM3wZUiDfYw X-Received: by 2002:a17:906:180b:: with SMTP id v11mr9232509eje.466.1604436556995; Tue, 03 Nov 2020 12:49:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604436556; cv=none; d=google.com; s=arc-20160816; b=qS/9sYM3kj7qCULsR34fu5KGUQi9s+5ybTUPLfgRG9GoOGqFqySa60oXTO78+fBMhF ukbUhlGu3+ni770GZPT7sUUzD5z4NooGHGJRo+LW6CiWl+atvXZJDKq0IB0PHsXpPpIp iGnImtiIuxl5Ta4/OWkbQBRxrnKuCBeJeRt93HY8C37x3djPdmA6ojX2cXvzn1eKeVZ2 hQ73XU5Ep1QKq0lbmzdh69NHrClhLIvm4dSrXRwImFICfEa9eVBJyxirt+Ms5dlWW/IL 1eF+tUU69pZFBmh59KilPjHBnylwXfTC60ePHurLL3pt0gEWgPdU/6Is4z3XN1bs0JFj ppWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cSktkVdtz3moEM2fah19M1TYzafelRud76gpFaD8zFg=; b=LNaVQVOEfnICpMUXpjzb0/T7/sp6MUsfefo+MYKxLAAyhufuxE50fuS94ISGH9rwC0 +v5Su8zFezSC633avauXWqvZQ7yMXCx37uU/5ExQbakLyLfP1+fyLRncEKncvrFxNhRp L36XT4hNaQiaRCrDygkPJSwesOlyY4j0T68ElAd7FqdfEKJr+Wb2a0JUabQ5RG90aFGe HuiYROBc6/Rxx7cs/gZ1kV6jykCqSIUFaTRb+yss1TGbFcZK1o1kmq2NV8q0fWBQUyiD UQWfqAPPzyz0moT5w18bHZzzDeZgpztLnqHP0+yiqJgmCkt++j/JDZOlg11xd279zFup LgJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m4Rc1UIG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si14696167edi.606.2020.11.03.12.48.53; Tue, 03 Nov 2020 12:49:16 -0800 (PST) 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=@kernel.org header.s=default header.b=m4Rc1UIG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730463AbgKCUq1 (ORCPT + 99 others); Tue, 3 Nov 2020 15:46:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:35734 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731182AbgKCUqZ (ORCPT ); Tue, 3 Nov 2020 15:46:25 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7AA8E20719; Tue, 3 Nov 2020 20:46:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436385; bh=+TgpZn8slUKhUywr9pCiLOk9QO206ruDjeYarbyQdKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4Rc1UIGvcSAVmmpDlyJknJYjg5HYxuQQW2SC8RyBnF2wypoVN95oD+0CNBPXpUtH WjqMV7SODAyTdhQVoZVll+L6199fgNgwYYewSNNz3qvfOAy2mdyxk19TG3cfXgZTmS pdYXOmEYhU7mmkqTzHxNQPprsPsQv+D/aFuM4FmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiang Chen , "Rafael J. Wysocki" Subject: [PATCH 5.9 220/391] PM: runtime: Remove link state checks in rpm_get/put_supplier() Date: Tue, 3 Nov 2020 21:34:31 +0100 Message-Id: <20201103203401.790987879@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiang Chen commit d12544fb2aa9944b180c35914031a8384ab082c1 upstream. To support runtime PM for hisi SAS driver (the driver is in directory drivers/scsi/hisi_sas), we add device link between scsi_device->sdev_gendev (consumer device) and hisi_hba->dev(supplier device) with flags DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE. After runtime suspended consumers and supplier, unload the dirver which causes a hung. We found that it called function device_release_driver_internal() to release the supplier device (hisi_hba->dev), as the device link was busy, it set the device link state to DL_STATE_SUPPLIER_UNBIND, and then it called device_release_driver_internal() to release the consumer device (scsi_device->sdev_gendev). Then it would try to call pm_runtime_get_sync() to resume the consumer device, but because consumer-supplier relation existed, it would try to resume the supplier first, but as the link state was already DL_STATE_SUPPLIER_UNBIND, so it skipped resuming the supplier and only resumed the consumer which hanged (it sends IOs to resume scsi_device while the SAS controller is suspended). Simple flow is as follows: device_release_driver_internal -> (supplier device) if device_links_busy -> device_links_unbind_consumers -> ... WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND) device_release_driver_internal (consumer device) pm_runtime_get_sync -> (consumer device) ... __rpm_callback -> rpm_get_suppliers -> if link->state == DL_STATE_SUPPLIER_UNBIND -> skip the action of resuming the supplier ... pm_runtime_clean_up_links ... Correct suspend/resume ordering between a supplier device and its consumer devices (resume the supplier device before resuming consumer devices, and suspend consumer devices before suspending the supplier device) should be guaranteed by runtime PM, but the state checks in rpm_get_supplier() and rpm_put_supplier() break this rule, so remove them. Signed-off-by: Xiang Chen [ rjw: Subject and changelog edits ] Cc: All applicable Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/base/power/runtime.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -291,8 +291,7 @@ static int rpm_get_suppliers(struct devi device_links_read_lock_held()) { int retval; - if (!(link->flags & DL_FLAG_PM_RUNTIME) || - READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND) + if (!(link->flags & DL_FLAG_PM_RUNTIME)) continue; retval = pm_runtime_get_sync(link->supplier); @@ -312,8 +311,6 @@ static void rpm_put_suppliers(struct dev list_for_each_entry_rcu(link, &dev->links.suppliers, c_node, device_links_read_lock_held()) { - if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND) - continue; while (refcount_dec_not_one(&link->rpm_active)) pm_runtime_put(link->supplier);