Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1987018imu; Fri, 14 Dec 2018 04:07:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/WCZoV5eg6dWMEJw+i12RyZcuKTKd8iQkbtl4X+rZjzDcQgzBAli0xRgQnZn025MkkY25EC X-Received: by 2002:a17:902:848d:: with SMTP id c13mr2618387plo.257.1544789236479; Fri, 14 Dec 2018 04:07:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789236; cv=none; d=google.com; s=arc-20160816; b=tEXUCkCHi9dgodajFMWRh3bHYAHwqamwRyqaxj5GqAjQ6feevuEmM63Ld4QpXc/Qj9 QALkGXaI2hFrt5DRVgiVpwHrA8VKRKvQWD/poCKSINZLu1SBGrv7pMYz+XG2YTmiEvTS T8ZkQiIHJQFpG04aRXLcBBAVDeGR8+CKg3GpVOjlDCPz9gReLYD/BheI8TBtSTAK/N2d Cb3MbwCtp0CtkFVB7XufwoiU0OK6SWPFXwK91NmNz8z9zj16KNZ3b8XL147ZXfQSSNqv t2len88VC0YOCLsTm4Hl8XE5hZDfpJVArqDb+ljuMpi1l10nGsgitwRmnQzGnoGiROfq 6jzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HDl/529MMFSW6B8topruSOCClIGVrH2gIf7FBHT82go=; b=wpAtPr021NGv2JOLL/cS6YCB+rcE7esSdlTjn88ZW3tMdH0J6DTXDjQwCe6WDUpyAE x/CHxa9hfvK/AWVnEIum8YK2re6FvLKGW4fnFvsQm6pgpdLA54lToKKzVOzDeKd2oJkM 39cA2yM9nEBwy5mu+2zqOwWymE1v8X25fWIDfIB/xyJcPllhdIt7P5Jl8b6qTFoGmDHz Ebyete5obROGMvws/qWFhHz8wTl39zUjHSwZqU+FT9pyJ4+2ywYdNIWuKpa552mnhqZZ x7lB0QyjUuubIXvWiueL43NO9TdPkJgEzwF53srICr5e2JG1eZ4MTNMXYgzVXlvl4C4q e0EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PpOJBv8f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si198061pfw.200.2018.12.14.04.07.00; Fri, 14 Dec 2018 04:07:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PpOJBv8f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730599AbeLNMEy (ORCPT + 99 others); Fri, 14 Dec 2018 07:04:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:49598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730564AbeLNMEw (ORCPT ); Fri, 14 Dec 2018 07:04:52 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 A02C221486; Fri, 14 Dec 2018 12:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789091; bh=NKIlcCtcJSna1lPcLdO86HJt13VRN3oMTVYTVR3sCaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PpOJBv8fIi5WhbY0PfSOC2nh9j6G6d/cttxjk2/tzHjU3SlPDeveULuFYDX09DLTX n4HH63bvHmrjUzXOu2UyMN6yBgyr4SzSdT3CKY1jl8Ghsv3cMgrhMeYpJmTl84Sh2g jVQDoPjqBmeECn3+xI3ILw/jMUY8J2FkQ4XJyyWM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mika Westerberg , Sasha Levin Subject: [PATCH 4.19 090/142] thunderbolt: Prevent root port runtime suspend during NVM upgrade Date: Fri, 14 Dec 2018 12:59:35 +0100 Message-Id: <20181214115750.652229713@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1830b6eeda1fed42d85f2388f79c926331a9b2d0 ] During NVM upgrade process the host router is hot-removed for a short while. During this time it is possible that the root port is moved into D3cold which would be fine if the root port could trigger PME on itself. However, many systems actually do not implement it so what happens is that the root port goes into D3cold and never wakes up unless userspace does PCI config space access, such as running 'lscpi'. For this reason we explicitly prevent the root port from runtime suspending during NVM upgrade. Signed-off-by: Mika Westerberg Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/thunderbolt/switch.c | 40 ++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 7442bc4c6433..dd9ae6f5d19c 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -864,6 +864,30 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR(key, 0600, key_show, key_store); +static void nvm_authenticate_start(struct tb_switch *sw) +{ + struct pci_dev *root_port; + + /* + * During host router NVM upgrade we should not allow root port to + * go into D3cold because some root ports cannot trigger PME + * itself. To be on the safe side keep the root port in D0 during + * the whole upgrade process. + */ + root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); + if (root_port) + pm_runtime_get_noresume(&root_port->dev); +} + +static void nvm_authenticate_complete(struct tb_switch *sw) +{ + struct pci_dev *root_port; + + root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); + if (root_port) + pm_runtime_put(&root_port->dev); +} + static ssize_t nvm_authenticate_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -913,10 +937,18 @@ static ssize_t nvm_authenticate_store(struct device *dev, sw->nvm->authenticating = true; - if (!tb_route(sw)) + if (!tb_route(sw)) { + /* + * Keep root port from suspending as long as the + * NVM upgrade process is running. + */ + nvm_authenticate_start(sw); ret = nvm_authenticate_host(sw); - else + if (ret) + nvm_authenticate_complete(sw); + } else { ret = nvm_authenticate_device(sw); + } pm_runtime_mark_last_busy(&sw->dev); pm_runtime_put_autosuspend(&sw->dev); } @@ -1336,6 +1368,10 @@ static int tb_switch_add_dma_port(struct tb_switch *sw) if (ret <= 0) return ret; + /* Now we can allow root port to suspend again */ + if (!tb_route(sw)) + nvm_authenticate_complete(sw); + if (status) { tb_sw_info(sw, "switch flash authentication failed\n"); tb_switch_set_uuid(sw); -- 2.19.1