Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp822701pxb; Tue, 3 Nov 2020 13:32:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJy89J9nJ+uukTphOpXJj/1ULUUsang2oXAFCHV7097ciz00RaCj1yN8K8M6/0PTfkuSZ3f5 X-Received: by 2002:a17:906:7e0e:: with SMTP id e14mr21418474ejr.238.1604439159160; Tue, 03 Nov 2020 13:32:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439159; cv=none; d=google.com; s=arc-20160816; b=V8ZzrB1cnZAxuS8t1waeWjCvKi0C11ZPNIAhOJwv1ty6Be6V45CEKK4X+17HbGCYQI VDKG2z7QadeKvjknSybV9i/p1utbVvICN/ESvC2WVZRpVTpzZDjNyPmkYC8CrgTMreKi 5OhI/AyGu/amRVIyD1f4ZjCQpzDaUQ1M8oec6HmlyC3bMR0ruypnzSs1Iq73atLGlzO7 5pOhFFvhGh5ZEijohawb0U2evejhAEmWGnOzGLfxiSGIhh5ZnAw+EzCZHqIpnC5gxpAm g5b6TIyyfyFiQV/Ce5pGUOeXHx6V/r+fI77oUTGOI1LwJQDjYrfUyJh7ZBNOhSorNHpF TKAA== 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=L32GbcF+smWZOBrlafTbTxwljKAxm4Egf0HsOfOEETss+KHiPmIFlXZx18eGuj03yy 1lJ6KuKi2V1eH0u9fuJj90+B7PoMZ/VfsaWWx3ll2knO/tVBmQ28Fz53MWW8jo9ePo2T W/ZryqqmMCCcL8jy9by2XJAlmznuoFDDQ6/5Bauf2shmS9nmKeaBBcwabllu0ccOD+jd 0TQRNT8mt4paxywPVutQniIhOLH78H8mYPb2pcKPY6b7CRk3wdiF239kbnOiSB/uJ2ps CI22oWYNfMej01EEI7nhUISo2IA8TzA8mODA5dKUywP0dtfNa3GYp1OPnOkzObTJBmET 9gdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n80DK8XF; 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 y23si5680380eds.334.2020.11.03.13.32.15; Tue, 03 Nov 2020 13:32:39 -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=n80DK8XF; 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 S1732234AbgKCV3o (ORCPT + 99 others); Tue, 3 Nov 2020 16:29:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:33582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733030AbgKCU6x (ORCPT ); Tue, 3 Nov 2020 15:58:53 -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 570A522226; Tue, 3 Nov 2020 20:58:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437132; bh=+TgpZn8slUKhUywr9pCiLOk9QO206ruDjeYarbyQdKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n80DK8XF43/WOX9jdp5O5cm2Zr7hGOr5hW0d9E1ooqLo3gfWHPgvaTpLypr3IBd9K cUqS+mcEPAWn1PpSeVyeK0+kCKf4bcaysGcbnawhNzI9WXuJKj+As7zqR9XeKBwQ2L KoNIYIgDadHY1z1gi1+sKw8Kotv97x/IylqOPMZE= 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.4 121/214] PM: runtime: Remove link state checks in rpm_get/put_supplier() Date: Tue, 3 Nov 2020 21:36:09 +0100 Message-Id: <20201103203302.210176223@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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);