From mboxrd@z Thu Jan 1 00:00:00 1970 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 23A7A231AF4; Wed, 4 Dec 2024 17:12:50 +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=1733332370; cv=none; b=qvc/zmQSyFxhcNuDOrXlhkZA+337WN9FxydD2jem6t/SM8OnqAeucEIxV3CNBE+dNSahRjHVch/44ZZvZwxmU4BXyGj4PvTgBzymflTrs9/GLcOu8LxAOBPQq3iIlfbfPzQ2U1c+Wvc8luBEnrM6/DNMiRaA6L2dpdIY1YsbWfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733332370; c=relaxed/simple; bh=+DSOcSN36hHwURdw2ODcs92UNCbE7AuLFPiehLo63PI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ioXlQczWUhWZjiTh1lkjtblZI+o7gZSvmENpEXH5an8s12vZvGOh1JnUWz/LKOJfcco4trTZpUWbx2Zclo2hH4HZgjZwSZw9u1KrKcq2oBTjRShuPhhWO3gzJ79kOhJMJ9RrYHzSqaBaq1dnVJYAdOuarYuYDRJ9YfZcUOF7zqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XZtIMYF3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XZtIMYF3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBCAEC4CECD; Wed, 4 Dec 2024 17:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733332370; bh=+DSOcSN36hHwURdw2ODcs92UNCbE7AuLFPiehLo63PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZtIMYF3LqUsOc/JBGaIv5JezIWICTEeq2rn4d+H5TjOf9JXugxCT+u1H56Finmry HVOcFE7/gz1ZQ4eUhdea8uA/8AelVTtLqhSG+oefhK4TNlm/4/pMal8i2lDeE9typy aK+8YJuqQieUwoCxrojqkRrlgYti2gkfSA+wZki49efIymE5DpgTb/pCxWr9sy8rbt R4efO2NOPxzzGnHqrF9uvoGcS9jYg4EjXO/9EpBvoKd1Cvj1NHeVi+miWSmBtf8+rj vfTKgzP2fmdQRLs2RMXo+U+WQc+MN+McuIDAIh4rr5Z7mvzJjdfe0pWbyP8TuxkWAh /woX+bqgKLNgQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Keith Busch , Bjorn Helgaas , Alex Williamson , Amey Narkhede , Sasha Levin , ilpo.jarvinen@linux.intel.com, mariusz.tkaczyk@linux.intel.com, linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 6.6 08/12] PCI: Add 'reset_subordinate' to reset hierarchy below bridge Date: Wed, 4 Dec 2024 11:01:05 -0500 Message-ID: <20241204160115.2216718-8-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204160115.2216718-1-sashal@kernel.org> References: <20241204160115.2216718-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.63 Content-Transfer-Encoding: 8bit From: Keith Busch [ Upstream commit 2fa046449a82a7d0f6d9721dd83e348816038444 ] The "bus" and "cxl_bus" reset methods reset a device by asserting Secondary Bus Reset on the bridge leading to the device. These only work if the device is the only device below the bridge. Add a sysfs 'reset_subordinate' attribute on bridges that can assert Secondary Bus Reset regardless of how many devices are below the bridge. This resets all the devices below a bridge in a single command, including the locking and config space save/restore that reset methods normally do. This may be the only way to reset devices that don't support other reset methods (ACPI, FLR, PM reset, etc). Link: https://lore.kernel.org/r/20241025222755.3756162-1-kbusch@meta.com Signed-off-by: Keith Busch [bhelgaas: commit log, add capable(CAP_SYS_ADMIN) check] Signed-off-by: Bjorn Helgaas Reviewed-by: Alex Williamson Reviewed-by: Amey Narkhede Signed-off-by: Sasha Levin --- Documentation/ABI/testing/sysfs-bus-pci | 11 +++++++++++ drivers/pci/pci-sysfs.c | 26 +++++++++++++++++++++++++ drivers/pci/pci.c | 2 +- drivers/pci/pci.h | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index ecf47559f495b..7f3e6bc3ff0ff 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -163,6 +163,17 @@ Description: will be present in sysfs. Writing 1 to this file will perform reset. +What: /sys/bus/pci/devices/.../reset_subordinate +Date: October 2024 +Contact: linux-pci@vger.kernel.org +Description: + This is visible only for bridge devices. If you want to reset + all devices attached through the subordinate bus of a specific + bridge device, writing 1 to this will try to do it. This will + affect all devices attached to the system through this bridge + similiar to writing 1 to their individual "reset" file, so use + with caution. + What: /sys/bus/pci/devices/.../vpd Date: February 2008 Contact: Ben Hutchings diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 3317b93547167..92e8ac85f58e8 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -517,6 +517,31 @@ static ssize_t bus_rescan_store(struct device *dev, static struct device_attribute dev_attr_bus_rescan = __ATTR(rescan, 0200, NULL, bus_rescan_store); +static ssize_t reset_subordinate_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pci_bus *bus = pdev->subordinate; + unsigned long val; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (kstrtoul(buf, 0, &val) < 0) + return -EINVAL; + + if (val) { + int ret = __pci_reset_bus(bus); + + if (ret) + return ret; + } + + return count; +} +static DEVICE_ATTR_WO(reset_subordinate); + #if defined(CONFIG_PM) && defined(CONFIG_ACPI) static ssize_t d3cold_allowed_store(struct device *dev, struct device_attribute *attr, @@ -621,6 +646,7 @@ static struct attribute *pci_dev_attrs[] = { static struct attribute *pci_bridge_attrs[] = { &dev_attr_subordinate_bus_number.attr, &dev_attr_secondary_bus_number.attr, + &dev_attr_reset_subordinate.attr, NULL, }; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 93f2f4dcf6d69..fb702d17ed9a7 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -6068,7 +6068,7 @@ EXPORT_SYMBOL_GPL(pci_probe_reset_bus); * * Same as above except return -EAGAIN if the bus cannot be locked */ -static int __pci_reset_bus(struct pci_bus *bus) +int __pci_reset_bus(struct pci_bus *bus) { int rc; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index d5e9010a135a1..83cd646bde3f0 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -46,6 +46,7 @@ bool pci_reset_supported(struct pci_dev *dev); void pci_init_reset_methods(struct pci_dev *dev); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int pci_bus_error_reset(struct pci_dev *dev); +int __pci_reset_bus(struct pci_bus *bus); struct pci_cap_saved_data { u16 cap_nr; -- 2.43.0