Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp252824lqr; Wed, 5 Jun 2024 05:17:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUcLo6AoUelrbAps0iXZLFKc02enHdwjLmpIp7SVFsD8n2cGLs2Rn3s6PdHGPFjwlYySulGerYh0HSBj8U5zVrtbtFeImUMbBRurW1RzA== X-Google-Smtp-Source: AGHT+IERyaSLN+0JIsKtEpzSsNTrTd2l++gSRIAGRjAgTxW/CNwO6y/m+aCQURMb1R3ufrnOR1Gc X-Received: by 2002:a05:6a20:7493:b0:1b0:3190:96d6 with SMTP id adf61e73a8af0-1b2b703cf19mr2958788637.34.1717589828109; Wed, 05 Jun 2024 05:17:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717589828; cv=pass; d=google.com; s=arc-20160816; b=tuZE09wpCY+qckBRnfBqV3QC5mCoiaSIfl98n3fhl1rub6jsE5wvOgvbn4R4R/BjqQ gHYXzkn5iQvGT2VUiPkKb9Inab7N7FATeYpY3y2/5WtCrIrHTaSgjYpjdSgWMStwvDNu oGoNIJcfsMKmeS/sXTOGJ4C9HMjC0FfUobSRfGp2wRbTJ3e3ui7wIwvhTIzsusoJ1sAP A5/wXahUKYbAx2dQHB5Lt7Av1e1QyDI31T/uG8d8O9DjLUB0usbqAbqh5GWDlyMzfDMO igIgpF6LG3clBFuqlNIT6W8alSRIZez7I1P16cM3hw0JhJ/uU2ccOoSL7uTW/ClzXmmF 5PaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Mdjmx7etQJIz+n56g+IbRk2eAfZ/n8VrNM0EQXlevD4=; fh=BoIkqdCzZt/CmVXabhaw61ChjmuT0JSCPXx0slemzDc=; b=Ql3SV7KopQM75hlOFYUeac8hNWCd2ZYZ6NFuxalVb7Qx6arn1xgPVU0NonzWC139wd CfeQyKmjNEZJZjVnceFN2sfowT4iPBr/dBSfbCtzPdOVo0HWoGkjgBCYMkqO/mVeAlpC 7JuJgglrW+iA1DdEvM0DwaV7TH7brBBGyV8p2zR95dJqnfhoXSWYWItGhckifPKWIKp8 EmKOVnJkH5FJIS5dErKxzkiwvsvUJ/8hWQO0L1K17pTuNmj6ulj5CMIYCIxwEqjxH+/I ADs6V3nSPsIzifhxXcb3ZqtXS2DX4zIAnmhFpFBKUYdnkQeKX6SVzTgSGmCDSYUU0t0z 269w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b0YsRj8r; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35b40c212si2485833a12.562.2024.06.05.05.17.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:17:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b0YsRj8r; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202354-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202354-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C1D17B254C5 for ; Wed, 5 Jun 2024 12:04:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 119131A3BA3; Wed, 5 Jun 2024 11:52:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b0YsRj8r" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3266F1A2FD9; Wed, 5 Jun 2024 11:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588320; cv=none; b=BA0G6tV8cF8LeWeP1ZhkQ9OpOIDKW3IwQzd1YIY4J2ggJQq1bZskDQjYkHvYZDr2gacm53d7ONijBDdpAWJ7wpgBLY7AItMKu7Frlu4S9D/PsGlUZ+auuZiV/W3PI7FxN22d97v2raFEPKgLnIfHt7RGY/ZVp/DY2c8BWLkpxV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588320; c=relaxed/simple; bh=GfBw9xyioKxp7porRMxoMZgGzTbaY0W78q0oLcabsmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pydIgGPVPv7/lRjTzROoiAp2jCTxp586kT2yxsZuGX9s8yTSTzeJcxnEGa0h1EqeCtx1l6NpNqozZpz+UvBdVGDHB4gnineTAhO+p3gI8U9i//fzcEvC96pWSyiF1Tr66bYG8BN1gvqimz6v+Z1eBTzAr7r8RcvbHezw4sVZxF0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b0YsRj8r; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DD55C4AF07; Wed, 5 Jun 2024 11:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588320; bh=GfBw9xyioKxp7porRMxoMZgGzTbaY0W78q0oLcabsmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b0YsRj8rNcF1thB1dN4pWXtyPtV6iYd2ql6C1GdSqY6pRt8+Lk/amzNrogsPtType 5SgzqUN6Aa+RCl5nP+J0rkR9Ij0yds9cO7xq1LuW8mDHFLzp/xln40SqtuyY6PR8S+ gTGHiRjKLdgqSZZWxrheuirrlyUfRqJhPQDNNZ985MGr6CmoR76HVuCN5lm3Q6/869 7600Q7H1lSTNTIuiE7GTzVjk/fBjyG+Jzz3fY7gtf21yaVAL/1LYyUyW/oSD6C5D4j lW237AIX4x0CSSrwZaIqbmtP/Hyg6xkxmHbEf3enzKgX1no3/asoSug7d2fW9SO9C9 360GFzbmbhlSw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Mika Westerberg , Bjorn Helgaas , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 23/24] PCI: Do not wait for disconnected devices when resuming Date: Wed, 5 Jun 2024 07:50:33 -0400 Message-ID: <20240605115101.2962372-23-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605115101.2962372-1-sashal@kernel.org> References: <20240605115101.2962372-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.12 Content-Transfer-Encoding: 8bit From: Ilpo Järvinen [ Upstream commit 6613443ffc49d03e27f0404978f685c4eac43fba ] On runtime resume, pci_dev_wait() is called: pci_pm_runtime_resume() pci_pm_bridge_power_up_actions() pci_bridge_wait_for_secondary_bus() pci_dev_wait() While a device is runtime suspended along with its PCI hierarchy, the device could get disconnected. In such case, the link will not come up no matter how long pci_dev_wait() waits for it. Besides the above mentioned case, there could be other ways to get the device disconnected while pci_dev_wait() is waiting for the link to come up. Make pci_dev_wait() exit if the device is already disconnected to avoid unnecessary delay. The use cases of pci_dev_wait() boil down to two: 1. Waiting for the device after reset 2. pci_bridge_wait_for_secondary_bus() The callers in both cases seem to benefit from propagating the disconnection as error even if device disconnection would be more analoguous to the case where there is no device in the first place which return 0 from pci_dev_wait(). In the case 2, it results in unnecessary marking of the devices disconnected again but that is just harmless extra work. Also make sure compiler does not become too clever with dev->error_state and use READ_ONCE() to force a fetch for the up-to-date value. Link: https://lore.kernel.org/r/20240208132322.4811-1-ilpo.jarvinen@linux.intel.com Reported-by: Mika Westerberg Tested-by: Mika Westerberg Signed-off-by: Ilpo Järvinen Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/pci.c | 5 +++++ include/linux/pci.h | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9d5d08a420f1a..0658b374d988c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1250,6 +1250,11 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout) for (;;) { u32 id; + if (pci_dev_is_disconnected(dev)) { + pci_dbg(dev, "disconnected; not waiting\n"); + return -ENOTTY; + } + pci_read_config_dword(dev, PCI_COMMAND, &id); if (!PCI_POSSIBLE_ERROR(id)) break; diff --git a/include/linux/pci.h b/include/linux/pci.h index 213109d3c601d..b692472616efb 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2519,7 +2519,12 @@ static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev) static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) { - return dev->error_state == pci_channel_io_perm_failure; + /* + * error_state is set in pci_dev_set_io_state() using xchg/cmpxchg() + * and read w/o common lock. READ_ONCE() ensures compiler cannot cache + * the value (e.g. inside the loop in pci_dev_wait()). + */ + return READ_ONCE(dev->error_state) == pci_channel_io_perm_failure; } void pci_request_acs(void); -- 2.43.0