From nobody Sun May 24 20:33:27 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEB73372059 for ; Fri, 22 May 2026 20:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481456; cv=none; b=jR1jWn8kRhu43FrfYmTFJTqI2+V5L2EgC6YPYuGCrnAralphZPvCUiimGdNNd8BSPC72TaQLomtzqqRyu2JkglLWv+HRu6ui84rqaKUVOxgtKDNi0dSFmzVTVlAoym7mhLE9YJ7Ny28WqI8ZEObeBoJME5z4sgN53TlJyHfHJn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481456; c=relaxed/simple; bh=I2+gT++65lvtozlVKIs++3OD+iHIOOhS9g2DosLpoBI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=X7KYKfCNyLX7wjVQv7DsSM7rlE+nmMY+1cXxtG2jMTzMsDx/7g/dFezg9YvygJ5MwmY+S7Nt8LBUIzt1B3aRaCt1wGM7e3CPhyNdm7nY3+dZ/6a2j+x1VJdxCMhcKKGWNn3Nc5PKE6acUT/+As2/vM22QQPEQsfvN89Cz6/OsT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=M45G7cqM; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="M45G7cqM" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3663d5e9bf4so7327375a91.1 for ; Fri, 22 May 2026 13:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481453; x=1780086253; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=knIrKIlKmxQWCfX61YATY4qsIQQ1NYNHXNjPVJJrvCw=; b=M45G7cqMeM+VVPmIw+Gmye4vjOI1dC5NmfXNIcYJX3ERePh8OF9mA4QQSuKJclKbHu v6OYc/5XRkBEPdxdqSjFGITP767jycAZsq2td8adOxzffRny6p7Xqmensu18UtiRkBG9 HldDI2tm+qv4UFm7DM79AWIS7Lv+UYsJM0NCr8YeFR9CzZRwtSLb7af/vJhUTSNNkMLJ UCa17TCoPYs10ftHXG4aON1Ahn3QEA1QWJDOl3mWmlQtlk+v+tHEvfEgYPIea6IZ9QfQ O39YuPTRbTScyzldbyuuzRek+Yhp7moJ6pez3zopOM3vQJMPkYUXjRTlcTbw1hR+3T7i 68UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481453; x=1780086253; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=knIrKIlKmxQWCfX61YATY4qsIQQ1NYNHXNjPVJJrvCw=; b=U2MzQsph2A5+Bbd0TkrSZj1lCGRP1uTfJO63ugD79X+QPSQmV1EJbLN2l4C4J/ZHBy sVhW3beu/Yr1VIkxoyC0WMC77EjCcjd7ku8gJngAJ0V6lLRDrSFxDKhsJK7zAbYQbyeM EEsnZjAstgMFaXYkMSS3Qfm2CDCsKRhFKXC4aWJxHKnjIbLD9OuTUm9PQEtpyhOMi2RH jJbb55cszGQAz07JQbYXSu/mlzV0SRrp1aY00LHDg1wTe2m1XN08QC6tlAT9Jf8oynPm k9i5EOLy7+T6Xsx4HCdQC+3H1jQvHtpS6/u4sbQAvuROE2sw+91x4xskCX33Rt/XgQ/D 2XWQ== X-Forwarded-Encrypted: i=1; AFNElJ+iDO0BxqZfA9zJI/JQdQjbq1EBo3J7lidfT/LswEgCJsUCY1OWCchDyRtRUMBEMTDY/ZMMpt1TLWzRkko=@vger.kernel.org X-Gm-Message-State: AOJu0Yya0hVCeHUh3pm7QW3hfwB7Je61HU7/GKunpLU+YIZYTvkXUyj+ gMa6NQ+35xOmlvf22nfn0BGsaQz9a2JsgSfWjmKvAHQcZpqGHRYDNh3RuKZL/XAWL3sWHjbUSs2 vcCrZ5x0PpOmoQw== X-Received: from pjbqx3.prod.google.com ([2002:a17:90b:3e43:b0:366:2773:30a2]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3fc7:b0:35b:9894:f6f9 with SMTP id 98e67ed59e1d1-36a6765a2e6mr5125973a91.18.1779481452889; Fri, 22 May 2026 13:24:12 -0700 (PDT) Date: Fri, 22 May 2026 20:23:59 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-2-dmatlack@google.com> Subject: [PATCH v6 01/12] PCI: liveupdate: Set up FLB handler for the PCI core From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set up a File-Lifecycle-Bound (FLB) handler for the PCI core to enable it to participate in the preservation of PCI devices across Live Update. Essentially, this commit enables the PCI core to allocate a struct (struct pci_ser) and preserve it across a Live Update whenever at least one device is preserved. Preserving PCI devices across Live Update is built on top of the Live Update Orchestrator's (LUO) support for file preservation. Drivers are expected to expose a file to userspace to represent a single PCI device and support preservation of that file. This is intended primarily to support preservation of PCI devices bound to VFIO drivers. This commit enables drivers to register their liveupdate_file_handler with the PCI core so that the PCI core can do its own tracking and enforcement of which devices are preserved. pci_liveupdate_register_flb(driver_file_handler); pci_liveupdate_unregister_flb(driver_file_handler); When the first file (with a handler registered with the PCI core) is preserved, the PCI core will be notified to allocate its tracking struct (pci_ser). When the last file is unpreserved (i.e. preservation cancelled) the PCI core will be notified to free struct pci_ser. This struct is preserved across a Live Update using KHO and can be fetched by the PCI core during early boot (e.g. during device enumeration) so that it knows which devices were preserved. Note: This commit only allocates struct pci_ser and preserves it across Live Update. A subsequent commit will add an API for drivers to tell the PCI core exactly which devices are being preserved. Note: There is no reason to check for kho_is_enabled() since it can be assumed to return true. If KHO was not enabled then Live Update would not be enabled and these routines would never run. Signed-off-by: David Matlack --- MAINTAINERS | 10 +++ drivers/pci/Kconfig | 15 ++++ drivers/pci/Makefile | 1 + drivers/pci/liveupdate.c | 145 +++++++++++++++++++++++++++++++++ include/linux/kho/abi/pci.h | 61 ++++++++++++++ include/linux/pci.h | 1 + include/linux/pci_liveupdate.h | 30 +++++++ 7 files changed, 263 insertions(+) create mode 100644 drivers/pci/liveupdate.c create mode 100644 include/linux/kho/abi/pci.h create mode 100644 include/linux/pci_liveupdate.h diff --git a/MAINTAINERS b/MAINTAINERS index 2fb1c75afd16..6c618830cf61 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20530,6 +20530,16 @@ L: linux-pci@vger.kernel.org S: Supported F: Documentation/PCI/pci-error-recovery.rst =20 +PCI LIVE UPDATE +M: David Matlack +L: kexec@lists.infradead.org +L: linux-pci@vger.kernel.org +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: drivers/pci/liveupdate.c +F: include/linux/kho/abi/pci.h +F: include/linux/pci_liveupdate.h + PCI MSI DRIVER FOR ALTERA MSI IP L: linux-pci@vger.kernel.org S: Orphan diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 33c88432b728..10c9b65aa242 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -328,6 +328,21 @@ config VGA_ARB_MAX_GPUS Reserves space in the kernel to maintain resource locking for multiple GPUS. The overhead for each GPU is very small. =20 +config PCI_LIVEUPDATE + bool "PCI Live Update Support" + depends on PCI && LIVEUPDATE + help + Enable PCI core support for preserving PCI devices across Live + Update. This, in combination with support in a device's driver, + enables PCI devices to run and perform memory transactions + uninterrupted during a kexec for Live Update. + + This option should only be enabled by users who plan to use Live + Update for kernel upgrades and require preserving PCI devices during + those upgrades. + + If unsure, say N. + source "drivers/pci/hotplug/Kconfig" source "drivers/pci/controller/Kconfig" source "drivers/pci/endpoint/Kconfig" diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 41ebc3b9a518..e8d003cb6757 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_PROC_FS) +=3D proc.o obj-$(CONFIG_SYSFS) +=3D pci-sysfs.o slot.o obj-$(CONFIG_ACPI) +=3D pci-acpi.o obj-$(CONFIG_GENERIC_PCI_IOMAP) +=3D iomap.o +obj-$(CONFIG_PCI_LIVEUPDATE) +=3D liveupdate.o endif =20 obj-$(CONFIG_OF) +=3D of.o diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c new file mode 100644 index 000000000000..737e7b9366db --- /dev/null +++ b/drivers/pci/liveupdate.c @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2026, Google LLC. + * David Matlack + */ + +/** + * DOC: PCI Live Update + * + * The PCI subsystem participates in the Live Update process to enable dri= vers + * to preserve their PCI devices across kexec. + * + * File-Lifecycle-Bound (FLB) Data + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D + * + * PCI device preservation across Live Update is built on top of the Live = Update + * Orchestrator's (LUO) support for file preservation across kexec. Drivers + * are expected to expose a file to represent a single PCI device and supp= ort + * preservation of that file with ``ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)`= `. + * This allows userspace to control the preservation of devices and ensure + * proper lifecycle management while a device is preserved. The first inte= nded + * use-case is preserving vfio-pci device files. + * + * The PCI core maintains its own state about what devices are being prese= rved + * across Live Update using a feature called File-Lifecycle-Bound (FLB) da= ta in + * LUO. Essentially, this allows the PCI core to allocate struct pci_ser = when + * the first device (file) is preserved and free it when the last device (= file) + * is unpreserved. After kexec, the PCI core can fetch the struct pci_ser = (which + * was constructed by the previous kernel) from LUO at any time (e.g. duri= ng + * enumeration) so that it knows which devices were preserved. + * + * To enable the PCI core to be notified whenever a file representing a de= vice + * is preserved, drivers must register their struct liveupdate_file_handle= r with + * the PCI core by using the following APIs: + * + * * ``pci_liveupdate_register_flb(driver_file_handler)`` + * * ``pci_liveupdate_unregister_flb(driver_file_handler)`` + */ + +#define pr_fmt(fmt) "PCI: liveupdate: " fmt + +#include +#include +#include +#include +#include +#include +#include + +static int pci_flb_preserve(struct liveupdate_flb_op_args *args) +{ + struct pci_dev *dev =3D NULL; + u32 max_nr_devices =3D 0; + struct pci_ser *ser; + unsigned long size; + + /* + * Allocate enough space to preserve all devices that are currently + * present on the system. Extra padding can be added to this in the + * future to increase the chances that there is enough room to preserve + * devices that are not yet present on the system (e.g. VFs, hot-plugged + * devices). + */ + for_each_pci_dev(dev) + max_nr_devices++; + + size =3D struct_size_t(struct pci_ser, devices, max_nr_devices); + + ser =3D kho_alloc_preserve(size); + if (IS_ERR(ser)) + return PTR_ERR(ser); + + pr_debug("Preserved struct pci_ser with room for %u devices\n", + max_nr_devices); + + ser->max_nr_devices =3D max_nr_devices; + ser->nr_devices =3D 0; + + args->obj =3D ser; + args->data =3D virt_to_phys(ser); + return 0; +} + +static void pci_flb_unpreserve(struct liveupdate_flb_op_args *args) +{ + struct pci_ser *ser =3D args->obj; + + WARN_ON(ser->nr_devices); + kho_unpreserve_free(ser); + pr_debug("Unpreserved struct pci_ser\n"); +} + +static int pci_flb_retrieve(struct liveupdate_flb_op_args *args) +{ + args->obj =3D phys_to_virt(args->data); + return 0; +} + +static void pci_flb_finish(struct liveupdate_flb_op_args *args) +{ + kho_restore_free(args->obj); +} + +static struct liveupdate_flb_ops pci_liveupdate_flb_ops =3D { + .preserve =3D pci_flb_preserve, + .unpreserve =3D pci_flb_unpreserve, + .retrieve =3D pci_flb_retrieve, + .finish =3D pci_flb_finish, + .owner =3D THIS_MODULE, +}; + +static struct liveupdate_flb pci_liveupdate_flb =3D { + .ops =3D &pci_liveupdate_flb_ops, + .compatible =3D PCI_LUO_FLB_COMPATIBLE, +}; + +/** + * pci_liveupdate_register_flb() - Register a file handler with the PCI co= re + * @fh: The file handler to register. + * + * Drivers should call pci_liveupdate_register_flb() to register their + * struct liveupdate_file_handler with the PCI core. This enables the PCI = core + * to allocate its outgoing struct pci_ser whenever the first device is + * preserved, and free it when the last device is unpreserved. + * + * Return: 0 on success, <0 on failure. + */ +int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh) +{ + pr_debug("Registering file handler \"%s\"\n", fh->compatible); + return liveupdate_register_flb(fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_register_flb); + +/** + * pci_liveupdate_unregister_flb() - Unregister a file handler with the PC= I core + * @fh: The file handler to unregister. + */ +void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh) +{ + pr_debug("Unregistering file handler \"%s\"\n", fh->compatible); + liveupdate_unregister_flb(fh, &pci_liveupdate_flb); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_unregister_flb); diff --git a/include/linux/kho/abi/pci.h b/include/linux/kho/abi/pci.h new file mode 100644 index 000000000000..6ebcf817fff4 --- /dev/null +++ b/include/linux/kho/abi/pci.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2026, Google LLC. + * David Matlack + */ + +#ifndef _LINUX_KHO_ABI_PCI_H +#define _LINUX_KHO_ABI_PCI_H + +#include +#include +#include + +/** + * DOC: PCI File-Lifecycle Bound (FLB) Live Update ABI + * + * This header defines the ABI for preserving core PCI state across kexec = using + * Live Update File-Lifecycle Bound (FLB) data. + * + * This interface is a contract. Any modification to any of the serializat= ion + * structs defined here constitutes a breaking change. Such changes require + * incrementing the version number in the PCI_LUO_FLB_COMPATIBLE string. + */ + +#define PCI_LUO_FLB_COMPATIBLE "pci-v1" + +/** + * struct pci_dev_ser - Serialized state about a single PCI device. + * + * @domain: The device's PCI domain number (segment). + * @bdf: The device's PCI bus, device, and function number. + * @padding: Padding to naturally align struct pci_dev_ser. + */ +struct pci_dev_ser { + u32 domain; + u16 bdf; + u16 padding; +} __packed; + +/** + * struct pci_ser - PCI Subsystem Live Update State + * + * This struct tracks state about all devices that are being preserved acr= oss + * a Live Update for the next kernel. + * + * @max_nr_devices: The length of the devices[] flexible array. + * @nr_devices: The number of devices that were preserved. + * @devices: Flexible array of pci_dev_ser structs for each device. + */ +struct pci_ser { + u32 max_nr_devices; + u32 nr_devices; + struct pci_dev_ser devices[]; +} __packed; + +/* Ensure all elements of devices[] are naturally aligned. */ +static_assert(offsetof(struct pci_ser, devices) % sizeof(unsigned long) = =3D=3D 0); +static_assert(sizeof(struct pci_dev_ser) % sizeof(unsigned long) =3D=3D 0); + +#endif /* _LINUX_KHO_ABI_PCI_H */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 2c4454583c11..8cadeeab86fd 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -42,6 +42,7 @@ #include =20 #include +#include =20 #define PCI_STATUS_ERROR_BITS (PCI_STATUS_DETECTED_PARITY | \ PCI_STATUS_SIG_SYSTEM_ERROR | \ diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h new file mode 100644 index 000000000000..8ec98beefcb4 --- /dev/null +++ b/include/linux/pci_liveupdate.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Live Update support (Public/Driver API) + * + * Copyright (c) 2026, Google LLC. + * David Matlack + */ +#ifndef LINUX_PCI_LIVEUPDATE_H +#define LINUX_PCI_LIVEUPDATE_H + +#include +#include + +struct pci_dev; + +#ifdef CONFIG_PCI_LIVEUPDATE +int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh); +void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh); +#else +static inline int pci_liveupdate_register_flb(struct liveupdate_file_handl= er *fh) +{ + return -EOPNOTSUPP; +} + +static inline void pci_liveupdate_unregister_flb(struct liveupdate_file_ha= ndler *fh) +{ +} +#endif + +#endif /* LINUX_PCI_LIVEUPDATE_H */ --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8356381B02 for ; Fri, 22 May 2026 20:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481456; cv=none; b=YPk5ZuF+uH6E3soFd+dcNVQT0DxsCUhBbvgbFAYBoLETQH0itRvPQ/Kksm0wSDP7X0pk1gFtUQG5mPSKNEJDwe22vrQtCYDdtQHyoZRXTebdEx73N5Epj2XAmkkbKepxFG08J3jvVxrppzNNd6N5HzmOgUBNMwMKSI9wJ6TZbbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481456; c=relaxed/simple; bh=nckBbbDSYkIhtad4whkba0hiycJmchkPdk77V7Mx8AM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jEKbP5NbLIiBkFhdS2pV/OOWOn3d/iJYHdog1UdNfcbzhPls7MpTbj3ELtJpD7a/8J5WoXCuneGYbVKKaUXTk85NrnZZF41VvmeUPM/llz/7otskB5HNbN0L0C+gPKzGI/jfkK/yvf1H2AwY50gnHzNtaM+hejL5wM0gywN1C5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QitmK5aE; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QitmK5aE" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-82fa2165c3eso4872095b3a.0 for ; Fri, 22 May 2026 13:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481454; x=1780086254; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5BsKApi6L+qeqFEzWFS09/i8PEXb73/HfwpwzmTZ0gY=; b=QitmK5aEqmUi+50YqldyTNQeniHOLwW9zTpdvraK/X2iIkM2jl1pBPD+wt9GMrfGrG cZSMOs1TdwM5h8x+/DdBdgaLNpACR/qLE1+dAan4fqOgp+UUpabLghX6hcFej2XZ9f3T QVScJqIqOOljJ/Ctg8v3S5a4JAVrtp+8GVvVGS8weBVSBTzfzl/LqDM1Gqb/gLqdKKPS 4sJUt2s8yfWVrmtfjT+Rxe85mIAGxl1Aw+yy6UauWXZvcyJygDMpIq72apyWy8rohwNf DbBdOr8ksr4aIrCjv+JRGVY4S/WYysVFCaexTxzUKlUnRhB15XnIwpNIqQ59bVPtLp30 rEyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481454; x=1780086254; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5BsKApi6L+qeqFEzWFS09/i8PEXb73/HfwpwzmTZ0gY=; b=ILzVIcwoUy/Ghn0XVgiPq+su29EoqIcGfhcFj+4pNThKk10Gfi4ZcVMxZiM5eUWYmT wBKidFustB3tV2ac2k8KLtAfELlU75z80Jt4FTNvCCkAbiMSu6IJ0fFDsftKHMPkkQSB w/NA9x6tV3Yu2dpFp/4+Z7/EtBIv7uwMbvMN+m6s00FO5pAmft67Nzg6nBbKNcYOvTKP PVXx7ArKAde5FOKJVGoNtrqK6zwix8x3HY9Fkr929usXoyqhPHPTRQt45+T7+aDaAjq+ 0nDdxIaJEaLq8MXuQTO0hWXXSMB9A6SnNfv8NQlrbSdynIHxzEdWsJzTXeU84SpfGl1n NCOQ== X-Forwarded-Encrypted: i=1; AFNElJ/yvfdTYaAnqp6kJuQy0aZ4c3jyWFMiaOIMI+KYrORlyEvwgE0RzewVxto8dqjmZqN2VwEFWV3szM/WGos=@vger.kernel.org X-Gm-Message-State: AOJu0YwemOjGDv9dKlW48GiZzlC2tvgQ0XIyvhbE5GXJgbCkBOg8BeWj iv7gzYABlcgOuowNcIF10CNpzO99JOngiI75DqVbn6zf0rD5plTq9jDelEuVLgo/qSlc8eGf6wC t0d14jtFAxIWBCA== X-Received: from pfbbk29.prod.google.com ([2002:aa7:831d:0:b0:83d:3c25:eb8b]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:44c7:b0:837:7e7d:3d9 with SMTP id d2e1a72fcca58-8415f3a3d22mr5271624b3a.44.1779481453749; Fri, 22 May 2026 13:24:13 -0700 (PDT) Date: Fri, 22 May 2026 20:24:00 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-3-dmatlack@google.com> Subject: [PATCH v6 02/12] PCI: liveupdate: Track outgoing preserved PCI devices From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add APIs to allow drivers to notify the PCI core of which devices are being preserved across a Live Update for the next kernel, i.e. "outgoing" devices. Drivers must notify the PCI core when devices are preserved so that the PCI core can update its FLB data (struct pci_ser) and track the list of outgoing devices. pci_liveupdate_preserve() notifies the PCI core that a device must be preserved across Live Update. pci_liveupdate_unpreserve() reverses this (cancels the preservation of the device). This tracking ensures the PCI core is fully aware of which devices may need special handling during shutdown and kexec, and so that it can be handed off to the next kernel. Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 167 +++++++++++++++++++++++++++++++++ drivers/pci/liveupdate.h | 21 +++++ drivers/pci/probe.c | 2 + include/linux/kho/abi/pci.h | 9 +- include/linux/pci.h | 3 + include/linux/pci_liveupdate.h | 21 +++++ 6 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 drivers/pci/liveupdate.h diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 737e7b9366db..065d5af822f7 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -36,6 +36,26 @@ * * * ``pci_liveupdate_register_flb(driver_file_handler)`` * * ``pci_liveupdate_unregister_flb(driver_file_handler)`` + * + * Device Tracking + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Drivers must notify the PCI core when specific devices are preserved or + * unpreserved with the following APIs: + * + * * ``pci_liveupdate_preserve(pci_dev)`` + * * ``pci_liveupdate_unpreserve(pci_dev)`` + * + * This allows the PCI core to keep its FLB data (struct pci_ser) up to da= te + * with the list of **outgoing** preserved devices for the next kernel. + * + * Restrictions + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * The PCI core enforces the following restrictions on which devices can be + * preserved. These may be relaxed in the future: + * + * * The device cannot be a Virtual Function (VF). */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -48,6 +68,21 @@ #include #include =20 +#include "liveupdate.h" + +/** + * struct pci_liveupdate_global - Global state for PCI Live Update support + * @rwsem: Reader/writer semaphore used to protect the incoming and outgoi= ng + * FLBs, and the references to them in struct pci_dev. + */ +struct pci_liveupdate_global { + struct rw_semaphore rwsem; +}; + +static struct pci_liveupdate_global pci_liveupdate =3D { + .rwsem =3D __RWSEM_INITIALIZER(pci_liveupdate.rwsem), +}; + static int pci_flb_preserve(struct liveupdate_flb_op_args *args) { struct pci_dev *dev =3D NULL; @@ -115,6 +150,138 @@ static struct liveupdate_flb pci_liveupdate_flb =3D { .compatible =3D PCI_LUO_FLB_COMPATIBLE, }; =20 +static struct pci_ser *pci_liveupdate_flb_get_outgoing(void) +{ + struct pci_ser *ser =3D NULL; + int ret; + + ret =3D liveupdate_flb_get_outgoing(&pci_liveupdate_flb, (void **)&ser); + if (ret) + return ERR_PTR(ret); + + if (!ser) + return ERR_PTR(-ENOENT); + + return ser; +} + +static void pci_liveupdate_unpreserve_device(struct pci_ser *ser, struct p= ci_dev *dev) +{ + struct pci_dev_ser *dev_ser =3D dev->liveupdate.outgoing; + + if (!dev_ser) { + pci_warn(dev, "Cannot unpreserve device that is not preserved\n"); + return; + } + + pci_info(dev, "Device will no longer be preserved across next Live Update= \n"); + ser->nr_devices--; + memset(dev_ser, 0, sizeof(*dev_ser)); + dev->liveupdate.outgoing =3D NULL; +} + +static int pci_liveupdate_preserve_device(struct pci_ser *ser, struct pci_= dev *dev) +{ + int i; + + if (dev->liveupdate.outgoing) + return -EBUSY; + + if (ser->nr_devices =3D=3D ser->max_nr_devices) + return -ENOSPC; + + for (i =3D 0; i < ser->max_nr_devices; i++) { + /* + * Start searching at index ser->nr_devices. This should result + * in a constant time search under expected conditions (devices + * are not getting unpreserved). + */ + int index =3D (ser->nr_devices + i) % ser->max_nr_devices; + struct pci_dev_ser *dev_ser =3D &ser->devices[index]; + + if (dev_ser->refcount) + continue; + + pci_info(dev, "Device will be preserved across next Live Update\n"); + ser->nr_devices++; + + dev_ser->domain =3D pci_domain_nr(dev->bus); + dev_ser->bdf =3D pci_dev_id(dev); + dev_ser->refcount =3D 1; + + dev->liveupdate.outgoing =3D dev_ser; + return 0; + } + + return -ENOSPC; +} + +/** + * pci_liveupdate_preserve() - Preserve a PCI device across Live Update + * @dev: The PCI device to preserve. + * + * pci_liveupdate_preserve() notifies the PCI core that a PCI device shoul= d be + * preserved across the next Live Update. Drivers are expected to call + * pci_liveupdate_preserve() from their struct liveupdate_file_handler + * preserve() callback to ensure the outgoing struct pci_ser is already se= t up. + * + * Returns: 0 on success, <0 on failure. + */ +int pci_liveupdate_preserve(struct pci_dev *dev) +{ + struct pci_ser *ser =3D NULL; + + if (dev->is_virtfn) + return -EINVAL; + + guard(rwsem_write)(&pci_liveupdate.rwsem); + + ser =3D pci_liveupdate_flb_get_outgoing(); + if (IS_ERR(ser)) + return PTR_ERR(ser); + + return pci_liveupdate_preserve_device(ser, dev); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_preserve); + +/** + * pci_liveupdate_unpreserve() - Cancel preservation of a PCI device + * @dev: The PCI device to unpreserve. + * + * pci_liveupdate_unpreserve() notifies the PCI core that a PCI device sho= uld no + * longer be preserved across the next Live Update. Drivers are expected t= o call + * pci_liveupdate_unpreserve() from their struct liveupdate_file_handler + * unpreserve() callback to ensure the outgoing struct pci_ser is already = set + * up. + */ +void pci_liveupdate_unpreserve(struct pci_dev *dev) +{ + struct pci_ser *ser =3D NULL; + + guard(rwsem_write)(&pci_liveupdate.rwsem); + + ser =3D pci_liveupdate_flb_get_outgoing(); + if (IS_ERR(ser)) { + pci_warn(dev, "Cannot unpreserve device without outgoing Live Update sta= te\n"); + return; + } + + pci_liveupdate_unpreserve_device(ser, dev); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_unpreserve); + +void pci_liveupdate_cleanup_device(struct pci_dev *dev) +{ + /* + * It should be safe to READ_ONCE() outside of the rwsem during cleanup + * since there should no longer be any references to @dev on the system. + */ + if (READ_ONCE(dev->liveupdate.outgoing)) { + pci_WARN(dev, 1, "Destroying outgoing-preserved device!\n"); + pci_liveupdate_unpreserve(dev); + } +} + /** * pci_liveupdate_register_flb() - Register a file handler with the PCI co= re * @fh: The file handler to register. diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h new file mode 100644 index 000000000000..b2335581f8d0 --- /dev/null +++ b/drivers/pci/liveupdate.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * PCI Live Update support (core API) + * + * Copyright (c) 2026, Google LLC. + * David Matlack + */ +#ifndef DRIVERS_PCI_LIVEUPDATE_H +#define DRIVERS_PCI_LIVEUPDATE_H + +#include + +#ifdef CONFIG_PCI_LIVEUPDATE +void pci_liveupdate_cleanup_device(struct pci_dev *dev); +#else +static inline void pci_liveupdate_cleanup_device(struct pci_dev *dev) +{ +} +#endif + +#endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b63cd0c310bc..b88109a8dfe4 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -24,6 +24,7 @@ #include #include #include +#include "liveupdate.h" #include "pci.h" =20 static struct resource busn_resource =3D { @@ -2490,6 +2491,7 @@ static void pci_release_dev(struct device *dev) =20 pci_dev =3D to_pci_dev(dev); pci_release_capabilities(pci_dev); + pci_liveupdate_cleanup_device(pci_dev); pci_release_of_node(pci_dev); pcibios_release_device(pci_dev); pci_bus_put(pci_dev->bus); diff --git a/include/linux/kho/abi/pci.h b/include/linux/kho/abi/pci.h index 6ebcf817fff4..85def616703d 100644 --- a/include/linux/kho/abi/pci.h +++ b/include/linux/kho/abi/pci.h @@ -23,19 +23,22 @@ * incrementing the version number in the PCI_LUO_FLB_COMPATIBLE string. */ =20 -#define PCI_LUO_FLB_COMPATIBLE "pci-v1" +#define PCI_LUO_FLB_COMPATIBLE "pci-v2" =20 /** * struct pci_dev_ser - Serialized state about a single PCI device. * * @domain: The device's PCI domain number (segment). * @bdf: The device's PCI bus, device, and function number. - * @padding: Padding to naturally align struct pci_dev_ser. + * @refcount: Reference count used by the PCI core to keep track of whethe= r it + * is done using a device's struct pci_dev_ser. The value of the + * refcount is equal to 1 when the struct pci_dev_ser is in use= , and + * 0 otherwise. */ struct pci_dev_ser { u32 domain; u16 bdf; - u16 padding; + u16 refcount; } __packed; =20 /** diff --git a/include/linux/pci.h b/include/linux/pci.h index 8cadeeab86fd..a7c3722b1e77 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -594,6 +594,9 @@ struct pci_dev { u8 tph_mode; /* TPH mode */ u8 tph_req_type; /* TPH requester type */ #endif +#ifdef CONFIG_PCI_LIVEUPDATE + struct pci_liveupdate liveupdate; +#endif }; =20 static inline struct pci_dev *pci_physfn(struct pci_dev *dev) diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index 8ec98beefcb4..cfcfbfa73af7 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -8,14 +8,26 @@ #ifndef LINUX_PCI_LIVEUPDATE_H #define LINUX_PCI_LIVEUPDATE_H =20 +#include #include #include +#include + +/** + * struct pci_liveupdate - PCI Live Update state for a struct pci_dev + * @outgoing: State preserved for the next kernel. + */ +struct pci_liveupdate { + struct pci_dev_ser *outgoing; +}; =20 struct pci_dev; =20 #ifdef CONFIG_PCI_LIVEUPDATE int pci_liveupdate_register_flb(struct liveupdate_file_handler *fh); void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh); +int pci_liveupdate_preserve(struct pci_dev *dev); +void pci_liveupdate_unpreserve(struct pci_dev *dev); #else static inline int pci_liveupdate_register_flb(struct liveupdate_file_handl= er *fh) { @@ -25,6 +37,15 @@ static inline int pci_liveupdate_register_flb(struct liv= eupdate_file_handler *fh static inline void pci_liveupdate_unregister_flb(struct liveupdate_file_ha= ndler *fh) { } + +static inline int pci_liveupdate_preserve(struct pci_dev *dev) +{ + return -EOPNOTSUPP; +} + +static inline void pci_liveupdate_unpreserve(struct pci_dev *dev) +{ +} #endif =20 #endif /* LINUX_PCI_LIVEUPDATE_H */ --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB17438239F for ; Fri, 22 May 2026 20:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481457; cv=none; b=h4nxrTxiSJbiMwgyT4orXmhB7bM4Va0XNDXrSxu+ZjmqKpAcbbR7vAElib+I7e5Q8MnhkKppC03s6YGpoYRD0nF69whtIpfLCUbAlbTOcBf5ZB89DUlV4mmcrhQ5/vlbcPWizlpdHCBCvCK/liHsyJoTmyBLRmIQNyqBFww9w5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481457; c=relaxed/simple; bh=dhC8rqI3i9ihTMWh3pEZNZs1wxVxws/nIw7f91D26B8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ceDZ5iLbEpEVrDFt2VAn0tQRBr3gP87fQn0X2qRrVhH2xHg6YJymdiTadzGNEmHu8+tzUjhy+jfEkqlnO4AgboVd90v1mEv1rMshQfw2PORtlRlrF5ku9/YQOQ/GF798MBpAj7YBDk61pf63qmHgMug90Y4ER8dFELh51uOwkvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q5GxOwAq; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q5GxOwAq" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2babc42244aso180264115ad.3 for ; Fri, 22 May 2026 13:24:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481455; x=1780086255; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=O7EM8yO5UABmCYyvloFksBNZ5H9Ralyj3Xc5krkoLm8=; b=q5GxOwAqwH3qYvcSCYbOPedCPth67HYif8Zp3dNXFJlICx6a8acSLAz71ywK+7ZNr8 oqQd5gszhDlhtJAN/rIZM5uuhHWKJlBWy69G4LpBoNvCYYV8a4gBjMCeVGzqI6b+L01q vn8epwZ8m8a5H5P0uUpTmvoHZuaj74FBGnhydUVRCtewW92seIFbUNuciLjfgKgiN7nt 6jlBduSsKOok+IHu7LkOn5RPxtlOX5php4rHwyCnM/9G5tUV9rVBjinTsNQCRz0CAVmQ Sy5jfaXcLiNIbUeV1OUc4kaxWyuKpG25sHOQtEXWB8GzFDa1mje5rs/PtwdNJDoh6Kuf svqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481455; x=1780086255; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O7EM8yO5UABmCYyvloFksBNZ5H9Ralyj3Xc5krkoLm8=; b=ilmN7CM0pB3f+HEtjQx5i/574dUuGvO12jSzsSwWyGesaO61OlJuMFJb3MgcgmqL/N vcAGWVvq1uC9e1dfOz74MRcbwSOX9Nn26mkdsx6G5ZdAx5G971pXsrLMmzmOUJJ7Xo6C 4+nWybOfAf7eccWddFmsRJV5s4n9/kUTcAxK8WvRce2o0bhh7gMhXn/75UnJSRWlFpiE uZJ9M42/mjqGupUEX8fbbCDA/tg+REO2lsIaVelM2c+XLeBO5YrPeKBUaV4NkqsKzdDP sqq9PPGVbQ9R0oL7HAqcYV+dy/CL/xN8noFENZ2d0wCOTvxnVQyVcLhZ4Qaal6fKwSFh wZBA== X-Forwarded-Encrypted: i=1; AFNElJ8pV2up0nUVBYfw/KqFBcg+IR0of5e8EXrYemkfN3N5wBVpo9taCFNzzImr5umEJlfzE2l++qpGQGdhBAI=@vger.kernel.org X-Gm-Message-State: AOJu0YyZ7Vq0jzwoOAr1ioIFcCJadCFXeat0TnsLfVi9ZNJeQLjhc+wV b1uf1dbpJsHsXWLkImzY2k/ARt2TQmPPPdHPkNDMe5B+F/b20DraSO5NdVbZUys3ZyThwveMU84 EpmdOhlUh3koPug== X-Received: from pldw18.prod.google.com ([2002:a17:902:ca12:b0:2be:22cf:75b2]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b43:b0:2b7:abc0:3bd7 with SMTP id d9443c01a7336-2beb035b8edmr57115215ad.9.1779481454632; Fri, 22 May 2026 13:24:14 -0700 (PDT) Date: Fri, 22 May 2026 20:24:01 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-4-dmatlack@google.com> Subject: [PATCH v6 03/12] PCI: liveupdate: Track incoming preserved PCI devices From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During PCI enumeration, the previous kernel might have passed state about devices that were preserved across kexec. The PCI core needs to fetch this state to identify which devices are "incoming" and require special handling. Add pci_liveupdate_setup_device() which is called during device setup to fetch the serialized state (struct pci_ser) from the Live Update Orchestrator. The first time this happens, pci_flb_retrieve() will run and convert the array of pci_dev_ser structs into an xarray so that it can be looked up efficiently. If a device is found in the xarray, the PCI core stores a pointer to its state in dev->liveupdate_incoming and holds a reference to the incoming FLB until pci_liveupdate_finish() is called by the driver. This ensures proper lifecycle management for incoming preserved devices and allows the PCI core and drivers to apply specific Live Update logic to them in subsequent commits. Drivers can check if a device is an incoming preserved device (e.g. during probe) by calling pci_liveupdate_is_incoming(). CONFIG_64BIT is now required to enable CONFIG_PCI_LIVEUPDATE so that the domain and bdf can be guaranteed to fit in an unsigned long and be used as the xarray key. Signed-off-by: David Matlack --- MAINTAINERS | 1 + drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 230 ++++++++++++++++++++++++++++++++- drivers/pci/liveupdate.h | 5 + drivers/pci/probe.c | 3 + include/linux/pci_liveupdate.h | 13 ++ 6 files changed, 251 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 6c618830cf61..0e262c0ceb43 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20537,6 +20537,7 @@ L: linux-pci@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git F: drivers/pci/liveupdate.c +F: drivers/pci/liveupdate.h F: include/linux/kho/abi/pci.h F: include/linux/pci_liveupdate.h =20 diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 10c9b65aa242..e68ae5c172d4 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -330,7 +330,7 @@ config VGA_ARB_MAX_GPUS =20 config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE + depends on PCI && LIVEUPDATE && 64BIT help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver, diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 065d5af822f7..96c43b84532c 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -49,6 +49,20 @@ * This allows the PCI core to keep its FLB data (struct pci_ser) up to da= te * with the list of **outgoing** preserved devices for the next kernel. * + * After kexec, whenever a device is enumerated, the PCI core will check i= f it + * is an **incoming** preserved device (i.e. preserved by the previous ker= nel) + * by checking the incoming FLB data (struct pci_ser). + * + * Drivers must notify the PCI core when an **incoming** device is done + * participating in the incoming Live Update with the following API: + * + * * ``pci_liveupdate_finish(pci_dev)`` + * + * The PCI core does not enforce any ordering of ``pci_liveupdate_finish()= `` and + * ``pci_liveupdate_preserve()``. i.e. A PCI device can be **outgoing** + * (preserved for next kernel) and **incoming** (preserved by previous ker= nel) + * at the same time. + * * Restrictions * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * @@ -83,6 +97,21 @@ static struct pci_liveupdate_global pci_liveupdate =3D { .rwsem =3D __RWSEM_INITIALIZER(pci_liveupdate.rwsem), }; =20 +/** + * struct pci_flb_incoming - Incoming PCI FLB object + * @ser: The incoming struct pci_ser from the previous kernel. + * @xa: Xarray used to quickly lookup devices in @ser. + */ +struct pci_flb_incoming { + struct pci_ser *ser; + struct xarray xa; +}; + +static unsigned long pci_ser_xa_key(u32 domain, u16 bdf) +{ + return (unsigned long)domain << 16 | bdf; +} + static int pci_flb_preserve(struct liveupdate_flb_op_args *args) { struct pci_dev *dev =3D NULL; @@ -128,13 +157,49 @@ static void pci_flb_unpreserve(struct liveupdate_flb_= op_args *args) =20 static int pci_flb_retrieve(struct liveupdate_flb_op_args *args) { - args->obj =3D phys_to_virt(args->data); + struct pci_ser *ser =3D phys_to_virt(args->data); + struct pci_flb_incoming *incoming; + int ret =3D -ENOMEM; + u32 i; + + incoming =3D kmalloc_obj(*incoming); + if (!incoming) + goto err_restore_free; + + incoming->ser =3D ser; + xa_init(&incoming->xa); + + for (i =3D 0; i < incoming->ser->max_nr_devices; i++) { + struct pci_dev_ser *dev_ser =3D &incoming->ser->devices[i]; + unsigned long key; + + if (!dev_ser->refcount) + continue; + + key =3D pci_ser_xa_key(dev_ser->domain, dev_ser->bdf); + ret =3D xa_insert(&incoming->xa, key, dev_ser, GFP_KERNEL); + if (ret) + goto err_xa_destroy; + } + + args->obj =3D incoming; return 0; + +err_xa_destroy: + xa_destroy(&incoming->xa); + kfree(incoming); +err_restore_free: + kho_restore_free(ser); + return ret; } =20 static void pci_flb_finish(struct liveupdate_flb_op_args *args) { - kho_restore_free(args->obj); + struct pci_flb_incoming *incoming =3D args->obj; + + xa_destroy(&incoming->xa); + kho_restore_free(incoming->ser); + kfree(incoming); } =20 static struct liveupdate_flb_ops pci_liveupdate_flb_ops =3D { @@ -270,6 +335,91 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_liveupdate_unpreserve); =20 +static struct pci_flb_incoming *pci_liveupdate_flb_get_incoming(void) +{ + struct pci_flb_incoming *incoming =3D NULL; + int ret; + + ret =3D liveupdate_flb_get_incoming(&pci_liveupdate_flb, (void **)&incomi= ng); + + /* Live Update is not enabled. */ + if (ret =3D=3D -EOPNOTSUPP) + return NULL; + + /* Live Update is enabled, but there is no incoming FLB data. */ + if (ret =3D=3D -ENODATA) + return NULL; + + /* + * Live Update is enabled and there is incoming FLB data, but none of it + * matches pci_liveupdate_flb.compatible. + * + * This could mean that no PCI FLB data was passed by the previous + * kernel, but it could also mean the previous kernel used a different + * compatibility string (i.e. a different ABI). + */ + if (ret =3D=3D -ENOENT) { + pr_info_once("No incoming FLB matched %s\n", pci_liveupdate_flb.compatib= le); + return NULL; + } + + /* + * There is incoming FLB data that matches pci_liveupdate_flb.compatible + * but it cannot be retrieved. + */ + if (ret) { + WARN_ONCE(ret, "Failed to retrieve incoming FLB data\n"); + return NULL; + } + + return incoming; +} + +static void pci_liveupdate_flb_put_incoming(void) +{ + liveupdate_flb_put_incoming(&pci_liveupdate_flb); +} + +void pci_liveupdate_setup_device(struct pci_dev *dev) +{ + struct pci_flb_incoming *incoming; + struct pci_dev_ser *dev_ser; + unsigned long key; + + guard(rwsem_write)(&pci_liveupdate.rwsem); + + incoming =3D pci_liveupdate_flb_get_incoming(); + if (!incoming) + return; + + key =3D pci_ser_xa_key(pci_domain_nr(dev->bus), pci_dev_id(dev)); + dev_ser =3D xa_load(&incoming->xa, key); + + /* This device was not preserved across Live Update */ + if (!dev_ser) { + pci_liveupdate_flb_put_incoming(); + return; + } + + /* + * This device was preserved, but has already been probed and gone + * through pci_liveupdate_finish(). This can happen if PCI core probes + * the same device multiple times, e.g. due to hotplug. + */ + if (!dev_ser->refcount) { + pci_liveupdate_flb_put_incoming(); + return; + } + + pci_info(dev, "Device was preserved by previous kernel across Live Update= \n"); + dev->liveupdate.incoming =3D dev_ser; + + /* + * Hold the ref on the incoming FLB until pci_liveupdate_finish() so + * that dev->liveupdate.incoming does not get freed while it is in use. + */ +} + void pci_liveupdate_cleanup_device(struct pci_dev *dev) { /* @@ -280,7 +430,83 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev) pci_WARN(dev, 1, "Destroying outgoing-preserved device!\n"); pci_liveupdate_unpreserve(dev); } + + if (READ_ONCE(dev->liveupdate.incoming)) { + pci_WARN(dev, 1, "Destroying incoming-preserved device!\n"); + pci_liveupdate_finish(dev); + } +} + +static void pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_d= ev *dev) +{ + if (!dev->liveupdate.incoming) { + pci_warn(dev, "Cannot finish preserving an unpreserved device\n"); + return; + } + + if (dev->liveupdate.incoming->refcount !=3D 1) { + pci_WARN(dev, 1, "Preserved device has a corrupted refcount!\n"); + return; + } + + /* + * Drop the refcount so this device does not get treated as an incoming + * device again, e.g. in case pci_liveupdate_setup_device() gets called + * again because the device is hot-plugged. + */ + dev->liveupdate.incoming->refcount =3D 0; + + pci_info(dev, "Device is finished participating in Live Update\n"); + dev->liveupdate.incoming =3D NULL; + ser->nr_devices--; + pci_liveupdate_flb_put_incoming(); +} + +/** + * pci_liveupdate_finish() - Finish the preservation of a PCI device + * @dev: The PCI device + * + * pci_liveupdate_finish() notifies the PCI core that a PCI device that was + * preserved across the previous Live Update has finished participating in= Live + * Update. Drivers must call pci_liveupdate_finish() from their struct + * liveupdate_file_handler finish() callback to ensure the incoming struct + * pci_ser is allocated. + */ +void pci_liveupdate_finish(struct pci_dev *dev) +{ + struct pci_flb_incoming *incoming; + + guard(rwsem_write)(&pci_liveupdate.rwsem); + + incoming =3D pci_liveupdate_flb_get_incoming(); + if (!incoming) { + pci_warn(dev, "Cannot finish preserving device without incoming FLB\n"); + return; + } + + pci_liveupdate_finish_device(incoming->ser, dev); + pci_liveupdate_flb_put_incoming(); +} +EXPORT_SYMBOL_GPL(pci_liveupdate_finish); + +/** + * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved + * @dev: The PCI device to check + * + * Check if a device was preserved across Live Update by the previous kern= el, + * i.e. the device is incoming-preserved. Note that a device is only consi= dered + * incoming-preserved prior to pci_liveupdate_finish(). It is up to driver= s to + * synchronize usage of pci_liveupdate_is_incoming() with their own call to + * pci_liveupdate_finish() to avoid acting on stale data. + * + * Returns: True if the device is incoming-preserved, false otherwise. + */ +bool pci_liveupdate_is_incoming(struct pci_dev *dev) +{ + guard(rwsem_read)(&pci_liveupdate.rwsem); + return dev->liveupdate.incoming; } +EXPORT_SYMBOL_GPL(pci_liveupdate_is_incoming); =20 /** * pci_liveupdate_register_flb() - Register a file handler with the PCI co= re diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index b2335581f8d0..eaaa3559fd77 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -11,8 +11,13 @@ #include =20 #ifdef CONFIG_PCI_LIVEUPDATE +void pci_liveupdate_setup_device(struct pci_dev *dev); void pci_liveupdate_cleanup_device(struct pci_dev *dev); #else +static inline void pci_liveupdate_setup_device(struct pci_dev *dev) +{ +} + static inline void pci_liveupdate_cleanup_device(struct pci_dev *dev) { } diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b88109a8dfe4..2e2be8af6976 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2070,6 +2070,8 @@ int pci_setup_device(struct pci_dev *dev) if (pci_early_dump) early_dump_pci_device(dev); =20 + pci_liveupdate_setup_device(dev); + /* Need to have dev->class ready */ dev->cfg_size =3D pci_cfg_space_size(dev); =20 @@ -2193,6 +2195,7 @@ int pci_setup_device(struct pci_dev *dev) default: /* unknown header */ pci_err(dev, "unknown header type %02x, ignoring device\n", dev->hdr_type); + pci_liveupdate_cleanup_device(dev); pci_release_of_node(dev); return -EIO; =20 diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index cfcfbfa73af7..cfdc3d62ec02 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -16,9 +16,11 @@ /** * struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. + * @incoming: State preserved by the previous kernel. */ struct pci_liveupdate { struct pci_dev_ser *outgoing; + struct pci_dev_ser *incoming; }; =20 struct pci_dev; @@ -28,6 +30,8 @@ int pci_liveupdate_register_flb(struct liveupdate_file_ha= ndler *fh); void pci_liveupdate_unregister_flb(struct liveupdate_file_handler *fh); int pci_liveupdate_preserve(struct pci_dev *dev); void pci_liveupdate_unpreserve(struct pci_dev *dev); +void pci_liveupdate_finish(struct pci_dev *dev); +bool pci_liveupdate_is_incoming(struct pci_dev *dev); #else static inline int pci_liveupdate_register_flb(struct liveupdate_file_handl= er *fh) { @@ -46,6 +50,15 @@ static inline int pci_liveupdate_preserve(struct pci_dev= *dev) static inline void pci_liveupdate_unpreserve(struct pci_dev *dev) { } + +static inline void pci_liveupdate_finish(struct pci_dev *dev) +{ +} + +static inline bool pci_liveupdate_is_incoming(struct pci_dev *dev) +{ + return false; +} #endif =20 #endif /* LINUX_PCI_LIVEUPDATE_H */ --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91B75384235 for ; Fri, 22 May 2026 20:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481458; cv=none; b=dGxqQUvZ/NbHLRsYA9WI2JxSaug//kJ3uMX7Wa4dDrvI6F91b3pSbdWURWtXXwT5zNdHVyB/CeFh+VFZUp3OdcBC/UB6LzKY1xx1p7x4u/aEjN2BxYwUHwCtfcsraWRvDnFsRuwyLu/Cz1j5NkleqrT1IiiBnH1D6WmiesDhhZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481458; c=relaxed/simple; bh=YRZsIIO/eWIDHTrvcJinj7ZXVV78Jb+4bEPHJAE5AyU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=FJJI4jONcwMJB/8iwOqDRD2TMX4BXc+2jP5O8d+6LqKIg2fTCx0KXia3p38qcrtluvNvoPhXZqlgUZS+SEyoYwEvsb6kN7VHgOyiJf++HQKSZACtcRDEIzUBFwCB45h3Xe5zK1c1yKf1nOIqQTPWILwQpF8j0HIw01tr4NVNvOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kti41HZI; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kti41HZI" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-36641bb3d97so4682907a91.3 for ; Fri, 22 May 2026 13:24:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481456; x=1780086256; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lI5mS1q2qOObabKUBbKfb1QQJkZ/uNYoefmzXL5rBmg=; b=kti41HZIqxt2dZcw2LHqWpyzMDaystJ57HkAbu4dtrnm7ohTA9MnoQ0uUEjpXV7OvM KE+Jf9lZotZOwg5FoMZFVU7qJlWm6/i8Z0vcaNrpPSi3F7yNiRzqGtcMasvFKoVj4S8F njg98uUxLdVD8qOrn0RNgJcdlrDZFt1pcVkRsWPO18xcnvDSmSx/Acu6OcA3vIqyHseS b1NoCflQXVnYFCrSjnjaxVZVf8Y4qxioaMFojqB4ixhc0a8zC++txvhrnNBTHvN2NE/b cFAwQiH1kydblogUDCL2hbojgYtHnZW21A1BnmvI0AYF9HaoHPjaTptE8SVt3wTtTkvd XbVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481456; x=1780086256; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lI5mS1q2qOObabKUBbKfb1QQJkZ/uNYoefmzXL5rBmg=; b=JexWs+hL+QYbINpxbxWr9TBqYa2lZ6N9ISluIllwx7GsknLTddP+GW9pTej88Lgh8T m3o+9Xpcu3VF3TRuMkaU8wb2L0bZnKTWzAfxMEyVZ/up/Cb+FWfxkNhdFHf5T1tdft77 CICZhAVm/THr1dhWottnwFo5X6kzsaLfdzGTa2TVqik2VNg2iigI/xzs4YT+WOaIWE9H 0PdrX+8L5i/K/iYzSjwvAug44DQFccBxH2NZvokyvXRPsG6zv/1S/7s2mygtz38mNgiO G8Jr4+onw6cCuziC4ijy4H1oj+Dxk9AKhfJyC4+IwA651EG4S4a8Jy5umPoUph/yQtZt oPvA== X-Forwarded-Encrypted: i=1; AFNElJ9GYMqBqVjqQdE39yx+zQ2yV4+HjF1k4OQDdK+jiHD7aMWR6TIiSaY7WpTjxXxYESuUkt3aWmy3ZG18p08=@vger.kernel.org X-Gm-Message-State: AOJu0YzCbC1I/2CAIWWx9/yXLmsWjWw5dt1sbAk/pFkd5gUkk73WPbQQ x037RVv8/Zw9fEch2a3dQulJxORI0fmZOG5NQ03+GFEAl7YH58qJv98krVBWdi47RYkFVPgumLa SZ4RyxKloTZQBfg== X-Received: from pjyv15.prod.google.com ([2002:a17:90a:e98f:b0:365:ca4c:7afb]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1a8e:b0:368:78da:803 with SMTP id 98e67ed59e1d1-36a674f81fbmr5156953a91.12.1779481455496; Fri, 22 May 2026 13:24:15 -0700 (PDT) Date: Fri, 22 May 2026 20:24:02 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-5-dmatlack@google.com> Subject: [PATCH v6 04/12] PCI: liveupdate: Document driver binding responsibilities From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document how driver binding works during a Live Update and what the PCI core expects of drivers and users. Note that this is only a description of the current division of responsibilities. These can change in the future if we decide. Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 96c43b84532c..4f2ec6ffdd16 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -70,6 +70,22 @@ * preserved. These may be relaxed in the future: * * * The device cannot be a Virtual Function (VF). + * + * Driver Binding + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * In the outgoing kernel, it is the driver's responsibility to ensure tha= t it + * does not release a device between pci_liveupdate_preserve() and + * pci_liveupdate_unpreserve(). + * + * In the incoming kernel, it is the driver's responsibility to ensure tha= t it + * does not release a preserved device between probe() and + * pci_liveupdate_finish(). + * + * It is the user's responsibility to ensure that incoming preserved devic= es are + * bound to the correct driver. i.e. The PCI core does not protect against= a + * device getting preserved by driver A in the outgoing kernel and then ge= tting + * bound to driver B in the incoming kernel. */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ED63384CCB for ; Fri, 22 May 2026 20:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481459; cv=none; b=o12Jwrjsy7mL8up2mw0WPGwxxHsQLLSP7lcrzOUNDdXifYHfuZBdANmqgDJyjhZJrn5paafJIYsDCMcS9udV22RyhWDvMSUHGyTkBZz3UCBfzKoU9MQjBs1cM4z+aAj4craBqS2i8KUGX3PUCBNwTJqKGWPVE0BQZclxgUac0ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481459; c=relaxed/simple; bh=GDbQ9PBK+SH7NBlxXyWCko/j1KI2JfV15RzVb+Cl0x0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hLQMeIGXsfafPWGbQ/rtq+MLZfes9Rsljiyx4AxN6+WsEQgc1/op8ArcyO8CTkeRNoz4TcjtcHxQpcvLzNJhKodM6eCQXt6z0xYl5w2RfTvcDF/9PWO40AADuJgxiw/ZRPTjUgGye0CFq0B+GEBYTLUW3+f223CeEaY3mEdE1pE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ubUJSnyD; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ubUJSnyD" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-368b15eeb3bso15349733a91.2 for ; Fri, 22 May 2026 13:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481457; x=1780086257; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=35prD7a6muthxJ5uOKWSGr8dWxpX6CiZ2+eQPVuLFrU=; b=ubUJSnyDiqugVjytsBa7NzAfMOCVFqRLBRgl0LIxwBnVBEQo0L6sSP72cdvCwjebx0 vvUaBdzMVv+GE7SMnXrrKx8BqvV5nKsJJgY/LfUmbWl4DF8dcIft/NKkUfb5Z2ca62b8 yBkVtq9bUECYcgr9UaHVVltqlBd4wSoersu+pjHViX7wglv8vEjnARXLHV4Vfqv+SFny EUzrEUx4gJieqQEaWv2393BhB1cpgdRCCGXhzN27ldllxk58HFMEOCBQaDVqnKv5glt/ 95CVQ7y3hbI36t3qP5qVFYk/jbKgp+chLdjPlQrzryAy7iDJFRz4AQS5r1DGSn3Df9cT dwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481457; x=1780086257; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=35prD7a6muthxJ5uOKWSGr8dWxpX6CiZ2+eQPVuLFrU=; b=CevWvB0oWp6mTlz1JZdks9oDxzw5CmJv0mWNaoao9vCiwnlOoo+jMm4BnoAGUs3Rn6 q21W1VytBR7dMkT+HHgsZYwe48Ux164QTAMtvHs2VNFKknWyM5wKEyRCYWN6DYcA3NUk P63m3iToVs6fGvvqjcyySRwOmCASI4aCQNoDHguqpiLhH5kFOavxaX6LTHTLZf1PcnAQ uFspZdjOadlT9COoI033SToiiTPbvp+CSpiyOe4zb4EonyWxn/k9Tp+3jBN0q1Jus+rT 6JBATHY+KWpyJuaCZxyWXjnpUIoiPGKmhedCpbRUOfSJFYIGJ91OGeRDc7t8iwsgFAsw U72Q== X-Forwarded-Encrypted: i=1; AFNElJ/2KHhNLCwNzpVuH7aX3RwFfWFfF0kPYQ+CSWucxsm7Mx1ypYYKcVC0MMJay2+PMpa8n0sxMELAHSfrJRU=@vger.kernel.org X-Gm-Message-State: AOJu0YzNmwdx8MpvPbeB3TfW7lD4zoDAG6crfzVd45GEyDcj5leG4MBO 4YXe1cYYoHSfo+4IsIf2MB7hxiMu1C8ISU+sEgT6acI8Y6LLpZZQSb1GYRKWA9f3r2I/Ij3Re/y r9sA0P1GZRNzCqA== X-Received: from pgbcb21.prod.google.com ([2002:a05:6a02:715:b0:c81:2646:5294]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5746:b0:364:78a5:8d40 with SMTP id 98e67ed59e1d1-36a67639d6dmr5223710a91.20.1779481456386; Fri, 22 May 2026 13:24:16 -0700 (PDT) Date: Fri, 22 May 2026 20:24:03 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-6-dmatlack@google.com> Subject: [PATCH v6 05/12] PCI: liveupdate: Keep bus numbers constant during Live Update From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" During a Live Update, preserved devices must be allowed to continue performing memory transactions so the kernel cannot change the fabric topology, including bus numbers, since that would require disabling and flushing any memory transactions first. To keep bus numbers constant, always inherit the secondary and subordinate bus numbers assigned to bridges during scanning, instead of assigning new ones, if any PCI devices are being preserved. Note that the kernel inherits bus numbers even on bridges without any downstream endpoints that were preserved. This avoids accidentally assigning a bridge a new window that overlaps with a preserved device that is downstream of a different bridge. If a bridge is scanned with a broken topology or has no bus numbers set during a Live Update, refuse to assign it new bus numbers and refuse to enumerate devices below it until the Live Update is finished. This is a safety measure to prevent topology conflicts. Require that CONFIG_CARDBUS is not enabled to enable CONFIG_PCI_LIVEUPDATE since inheriting bus numbers on PCI-to-CardBus bridges requires additional work but is not a priority at the moment. Signed-off-by: David Matlack --- .../admin-guide/kernel-parameters.txt | 6 +- drivers/pci/Kconfig | 2 +- drivers/pci/liveupdate.c | 83 ++++++++++++++++++- drivers/pci/liveupdate.h | 14 ++++ drivers/pci/probe.c | 17 +++- include/linux/pci_liveupdate.h | 4 + 6 files changed, 119 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 4d0f545fb3ec..a64af71c2705 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5138,7 +5138,11 @@ Kernel parameters explicitly which ones they are. assign-busses [X86] Always assign all PCI bus numbers ourselves, overriding - whatever the firmware may have done. + whatever the firmware may have done. Ignored + during a Live Update, where the kernel must + inherit the PCI topology (including bus numbers) + to avoid interrupting ongoing memory + transactions of preserved devices. usepirqmask [X86] Honor the possible IRQ mask stored in the BIOS $PIR table. This is needed on some systems with broken BIOSes, notably diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index e68ae5c172d4..a597fede1b3b 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig @@ -330,7 +330,7 @@ config VGA_ARB_MAX_GPUS =20 config PCI_LIVEUPDATE bool "PCI Live Update Support" - depends on PCI && LIVEUPDATE && 64BIT + depends on PCI && LIVEUPDATE && 64BIT && !CARDBUS help Enable PCI core support for preserving PCI devices across Live Update. This, in combination with support in a device's driver, diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 4f2ec6ffdd16..2421bc218916 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -86,6 +86,21 @@ * bound to the correct driver. i.e. The PCI core does not protect against= a * device getting preserved by driver A in the outgoing kernel and then ge= tting * bound to driver B in the incoming kernel. + * + * BDF Stability + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * The PCI core guarantees that preserved devices can be identified by the= same + * bus, device, and function numbers for as long as they are preserved + * (including across kexec). To accomplish this, the PCI core always inher= its + * the secondary and subordinate bus numbers assigned to bridges during sc= anning + * if any device is preserved. This is true even on architectures that alw= ays + * assign new bus numbers during scanning. The kernel assumes the previous + * kernel established a sane bus topology across kexec. + * + * If a misconfigured or unconfigured bridge is encountered during enumera= tion + * while there are preserved devices, its secondary and subordinate bus nu= mbers + * will be cleared and devices below it will not be enumerated. */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -103,7 +118,7 @@ /** * struct pci_liveupdate_global - Global state for PCI Live Update support * @rwsem: Reader/writer semaphore used to protect the incoming and outgoi= ng - * FLBs, and the references to them in struct pci_dev. + * FLBs and references to them in struct pci_dev. */ struct pci_liveupdate_global { struct rw_semaphore rwsem; @@ -396,6 +411,72 @@ static void pci_liveupdate_flb_put_incoming(void) liveupdate_flb_put_incoming(&pci_liveupdate_flb); } =20 +bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, struct pci_dev = *dev, + int pass) +{ + struct pci_dev *parent =3D bus->self; + + /* + * On the second pass, reuse the value that was set on the first pass + * so that the passes are consistent with one another. + */ + if (pass) + return dev->liveupdate.inherit_buses; + + /* + * If the parent bridge is being forced to inherit its bus numbers + * during this scan then this bridge must as well, otherwise the PCI + * core could expand this bridge's reservation beyond its parent (which + * cannot expand). + */ + if (parent && parent->liveupdate.inherit_buses) { + dev->liveupdate.inherit_buses =3D true; + goto out; + } + + /* + * Otherwise, if there are any incoming preserved devices, force the + * bus numbers to be inherited to avoid changing the bus numbers + * assigned to those devices during enumeration. + * + * To keep things simple, inherit bus numbers on all bridges if any PCI + * devices are incoming, to ensure that no bridge's reservation is + * expanded to overlap with a preserved device downstream of a different + * bridge. + */ + scoped_guard(rwsem_read, &pci_liveupdate.rwsem) { + struct pci_flb_incoming *incoming; + + incoming =3D pci_liveupdate_flb_get_incoming(); + if (!incoming) { + dev->liveupdate.inherit_buses =3D false; + goto out; + } + + /* + * It is safe to sample incoming->ser->nr_devices and then + * drop the rwsem since nr_devices will only decrease. Thus the + * only "race" is that the current scan will be overly + * conservative and force bus inheritance. + */ + dev->liveupdate.inherit_buses =3D incoming->ser->nr_devices; + pci_liveupdate_flb_put_incoming(); + } + +out: + return dev->liveupdate.inherit_buses; +} + +void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int pass) +{ + /* + * Clear inherit_buses after the second pass so it can be re-evaluated + * on future scans. + */ + if (pass) + dev->liveupdate.inherit_buses =3D false; +} + void pci_liveupdate_setup_device(struct pci_dev *dev) { struct pci_flb_incoming *incoming; diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index eaaa3559fd77..c763255a8de4 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -13,6 +13,9 @@ #ifdef CONFIG_PCI_LIVEUPDATE void pci_liveupdate_setup_device(struct pci_dev *dev); void pci_liveupdate_cleanup_device(struct pci_dev *dev); +bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, struct pci_dev = *dev, + int pass); +void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int pass); #else static inline void pci_liveupdate_setup_device(struct pci_dev *dev) { @@ -21,6 +24,17 @@ static inline void pci_liveupdate_setup_device(struct pc= i_dev *dev) static inline void pci_liveupdate_cleanup_device(struct pci_dev *dev) { } + +static inline bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, + struct pci_dev *dev, + int pass) +{ + return false; +} + +static inline void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int= pass) +{ +} #endif =20 #endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 2e2be8af6976..19965bfd347d 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1402,6 +1402,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus= , struct pci_dev *dev, int max, unsigned int available_buses, int pass) { + bool liveupdate, assign_new_buses =3D pcibios_assign_all_busses(); struct pci_bus *child; u32 buses; u16 bctl; @@ -1411,6 +1412,10 @@ static int pci_scan_bridge_extend(struct pci_bus *bu= s, struct pci_dev *dev, u8 fixed_sec, fixed_sub; int next_busnr; =20 + liveupdate =3D pci_liveupdate_scan_bridge_begin(bus, dev, pass); + if (liveupdate) + assign_new_buses =3D false; + /* * Make sure the bridge is powered on to be able to access config * space of devices below it. @@ -1454,8 +1459,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus= , struct pci_dev *dev, goto out; } =20 - if ((secondary || subordinate) && - !pcibios_assign_all_busses() && !broken) { + if ((secondary || subordinate) && !assign_new_buses && !broken) { unsigned int cmax, buses; =20 /* @@ -1497,8 +1501,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus= , struct pci_dev *dev, * do in the second pass. */ if (!pass) { - if (pcibios_assign_all_busses() || broken) - + if (assign_new_buses || broken) /* * Temporarily disable forwarding of the * configuration cycles on all bridges in @@ -1512,6 +1515,11 @@ static int pci_scan_bridge_extend(struct pci_bus *bu= s, struct pci_dev *dev, goto out; } =20 + if (liveupdate) { + pci_err(dev, "Cannot reconfigure bridge during Live Update, skipping\n"= ); + goto out; + } + /* Clear errors */ pci_write_config_word(dev, PCI_STATUS, 0xffff); =20 @@ -1572,6 +1580,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus= , struct pci_dev *dev, pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl); =20 pm_runtime_put(&dev->dev); + pci_liveupdate_scan_bridge_end(dev, pass); =20 return max; } diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index cfdc3d62ec02..2be98819e313 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -17,10 +17,14 @@ * struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. * @incoming: State preserved by the previous kernel. + * @inherit_buses: True if the PCI core should inherit the secondary and + * subordinate bus numbers assigned to this device due to + * an ongoing Live Update. */ struct pci_liveupdate { struct pci_dev_ser *outgoing; struct pci_dev_ser *incoming; + bool inherit_buses; }; =20 struct pci_dev; --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51F323859CC for ; Fri, 22 May 2026 20:24:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481460; cv=none; b=ZH0awfbsz/ldnXY1hPYWQz4WGahwqQzPgchKCDp1T2f8HdtTIuBDBjLIafPI6GDgxq4pWOKsU1HmhIua4tEkYvJv/NNNQ58z4Pfurri46zeO/A+BXa2Vt7VmPC08TuYR3rg31eG8kidpPpgYU2LWqMj7b0Tc8mFRnC+JSLDaDHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481460; c=relaxed/simple; bh=LLtHwG/AB1l6x9gZfQ/XR9thSnzbkmf56r9Jcx8CKGc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QEzCeEuX3OTwHkV8+znv/Ji9vOSQtTuHlBqi2ey8g/HarmF+iHmeo5HaxLr6gSa5CatIufpvFm0kyM/Ja0Nm21YefL2vpetEuZL1nce6T1E+cMCYn8caueH+ZVpHS7AL0HGDd+bqUmKBWOveq3OjPplRLrQXaVZAqDQ0HcdE92E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YmuRoNze; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YmuRoNze" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2ba15e384c7so52847435ad.3 for ; Fri, 22 May 2026 13:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481457; x=1780086257; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Aa/nUEfOKJ1QR8NF3ghsapnMDPgIBL9du7ZKGarbXoM=; b=YmuRoNzef2LpSkNd/LFW2o3JlYEsCaJj92Y2E4lBnHFpg2LzzT6ojU+3/nmx+tPhPv Pd05W+cLxKWKi/4k7wySEhZYb4Ynx8xsDhVTwkxLorbQ+FKOoiq/d/y4WhbKQp0urONq Eo4d81KM63FV9x7TaJ2Iyt8KJfrEU90qgT0JTj45mi8VFHUmGjIDp3FHnnBbbZKxYHfl uTUUmrKfxp7xa/rckKmhBTIoQwv4Df5LnnWLvU+1NKa5qD0dAsGUuJ+ciuvHf1z2mr/p 6fV/LXnsCw7HO/7jbJBFifiN0I8wXFKuKSyhHrFAdv2AbMs3wApvF4kpWLBZ8MTvCGPO R8KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481457; x=1780086257; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Aa/nUEfOKJ1QR8NF3ghsapnMDPgIBL9du7ZKGarbXoM=; b=mcwXdZ/AaNUBTvla2af+g76yZR4z+HGdtRTp1aJPvIn071LzhwFh0yMJnAOWXnytvg 8ioS3S8s6lN887OFwt4A7fxCNIr7QLIauHkK+m+JCKnxLYW1PWCqrKQO5mJDz8ajvLPu mZPcG7V7p7wu6J9O9rROXQ/ZnVeNZt35kwT1Ck8bFRmHLFLETrDg1+W9BQBtPm7UrHkk kCRnEeVpEZhc/vNTRByCLBHZ2TKlvvbapu5mt9OCS70HCjoq1yhCAhmnaerObQvbvsSu uTifA2FVqBhHqkOEhLrkjlGggAmfrvv7+y7DT/u7frs/jbRlr6H1ekWDGopj2R+T+L25 /Nvg== X-Forwarded-Encrypted: i=1; AFNElJ890sDQ3Eqjku4S29zstljNr+RWkXTtTLD19Ywz8tDoZnmPD1DXwNVj7b4e+E4wzrMDwq/fupigLYKiZZU=@vger.kernel.org X-Gm-Message-State: AOJu0YxDMhW8XW9qIOZj1pnC7iFBaCEjPjpMZdQlLWrSdEavjpFMLhek C8tZsPTsP8Epc4tFA5yF6TwxLINUEefDMPLASJQQ9fTDtB4qF80Q/cbrOVhLpLqxjhlWN047Ew9 72yDyOfFK3DVhUw== X-Received: from plfh15.prod.google.com ([2002:a17:902:f54f:b0:2b0:ba5a:1fe]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2381:b0:2bc:7486:21cf with SMTP id d9443c01a7336-2beb06423d4mr52826275ad.36.1779481457319; Fri, 22 May 2026 13:24:17 -0700 (PDT) Date: Fri, 22 May 2026 20:24:04 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-7-dmatlack@google.com> Subject: [PATCH v6 06/12] PCI: liveupdate: Auto-preserve upstream bridges across Live Update From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a PCI device is preserved across a Live Update, all of its upstream bridges up to the root port must also be preserved. This enables the PCI core and any drivers bound to the bridges to manage bridges correctly across a Live Update. Notably, this will be used in subsequent commits to ensure that preserved devices can continue performing memory transactions without a disruption or change in routing. To preserve bridges, the PCI core tracks the number of downstream devices preserved under each bridge using a reference count in struct pci_dev_ser. This allows a bridge to remain preserved until all its downstream preserved devices are unpreserved or finish their participation in the Live Update. Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 136 +++++++++++++++++++++++++++++++----- include/linux/kho/abi/pci.h | 5 +- 2 files changed, 122 insertions(+), 19 deletions(-) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 2421bc218916..4c79e19b7f98 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -101,6 +101,18 @@ * If a misconfigured or unconfigured bridge is encountered during enumera= tion * while there are preserved devices, its secondary and subordinate bus nu= mbers * will be cleared and devices below it will not be enumerated. + * + * PCI-to-PCI Bridges + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * Any PCI-to-PCI bridges upstream of a preserved device are automatically + * preserved when the device is preserved. The PCI core keeps track of the + * number of downstream devices that are preserved under a bridge so that = the + * bridge is only unpreserved once all downstream devices are unpreserved. + * + * This enables the PCI core and any drivers bound to the bridge to partic= ipate + * in the Live Update so that preserved endpoints can continue issuing mem= ory + * transactions during the Live Update. */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -261,28 +273,52 @@ static struct pci_ser *pci_liveupdate_flb_get_outgoin= g(void) return ser; } =20 -static void pci_liveupdate_unpreserve_device(struct pci_ser *ser, struct p= ci_dev *dev) +static int pci_liveupdate_unpreserve_device(struct pci_ser *ser, struct pc= i_dev *dev) { struct pci_dev_ser *dev_ser =3D dev->liveupdate.outgoing; =20 if (!dev_ser) { pci_warn(dev, "Cannot unpreserve device that is not preserved\n"); - return; + return -EINVAL; + } + + if (!dev_ser->refcount) { + pci_WARN(dev, 1, "Preserved device has a 0 refcount!\n"); + return -EINVAL; } =20 + if (--dev_ser->refcount) + return 0; + pci_info(dev, "Device will no longer be preserved across next Live Update= \n"); ser->nr_devices--; memset(dev_ser, 0, sizeof(*dev_ser)); dev->liveupdate.outgoing =3D NULL; + return 0; } =20 -static int pci_liveupdate_preserve_device(struct pci_ser *ser, struct pci_= dev *dev) +static int pci_liveupdate_preserve_device_again(struct pci_dev *dev) { - int i; + if (!dev->liveupdate.outgoing->refcount) { + pci_WARN(dev, 1, "Preserved device with 0 refcount!\n"); + return -EINVAL; + } =20 - if (dev->liveupdate.outgoing) + /* + * Endpoint devices should not be preserved more than once. Bridges are + * preserved once for every downstream device that is preserved. + */ + if (!dev->subordinate) return -EBUSY; =20 + dev->liveupdate.outgoing->refcount++; + return 0; +} + +static int __pci_liveupdate_preserve_device(struct pci_ser *ser, struct pc= i_dev *dev) +{ + int i; + if (ser->nr_devices =3D=3D ser->max_nr_devices) return -ENOSPC; =20 @@ -312,6 +348,52 @@ static int pci_liveupdate_preserve_device(struct pci_s= er *ser, struct pci_dev *d return -ENOSPC; } =20 +static int pci_liveupdate_preserve_device(struct pci_ser *ser, struct pci_= dev *dev) +{ + if (dev->liveupdate.outgoing) + return pci_liveupdate_preserve_device_again(dev); + + return __pci_liveupdate_preserve_device(ser, dev); +} + +#define for_each_pci_dev_in_path(_d, _start, _end) \ + for ((_d) =3D (_start); (_d) !=3D (_end); (_d) =3D (_d)->bus->self) + +static void __pci_liveupdate_unpreserve_path(struct pci_ser *ser, + struct pci_dev *start, + struct pci_dev *end) +{ + struct pci_dev *dev; + + for_each_pci_dev_in_path(dev, start, end) { + if (pci_liveupdate_unpreserve_device(ser, dev)) + return; + } +} + +static void pci_liveupdate_unpreserve_path(struct pci_ser *ser, + struct pci_dev *start) +{ + __pci_liveupdate_unpreserve_path(ser, start, /*end=3D*/NULL); +} + +static int pci_liveupdate_preserve_path(struct pci_ser *ser, + struct pci_dev *start) +{ + struct pci_dev *dev; + int ret; + + for_each_pci_dev_in_path(dev, start, NULL) { + ret =3D pci_liveupdate_preserve_device(ser, dev); + if (ret) { + __pci_liveupdate_unpreserve_path(ser, start, dev); + return ret; + } + } + + return 0; +} + /** * pci_liveupdate_preserve() - Preserve a PCI device across Live Update * @dev: The PCI device to preserve. @@ -321,6 +403,9 @@ static int pci_liveupdate_preserve_device(struct pci_se= r *ser, struct pci_dev *d * pci_liveupdate_preserve() from their struct liveupdate_file_handler * preserve() callback to ensure the outgoing struct pci_ser is already se= t up. * + * pci_liveupdate_preserve() automatically preserves all bridges upstream = of + * @dev. + * * Returns: 0 on success, <0 on failure. */ int pci_liveupdate_preserve(struct pci_dev *dev) @@ -336,7 +421,7 @@ int pci_liveupdate_preserve(struct pci_dev *dev) if (IS_ERR(ser)) return PTR_ERR(ser); =20 - return pci_liveupdate_preserve_device(ser, dev); + return pci_liveupdate_preserve_path(ser, dev); } EXPORT_SYMBOL_GPL(pci_liveupdate_preserve); =20 @@ -349,6 +434,9 @@ EXPORT_SYMBOL_GPL(pci_liveupdate_preserve); * pci_liveupdate_unpreserve() from their struct liveupdate_file_handler * unpreserve() callback to ensure the outgoing struct pci_ser is already = set * up. + * + * pci_liveupdate_unpreserve() automatically unpreserves all bridges upstr= eam of + * @dev. */ void pci_liveupdate_unpreserve(struct pci_dev *dev) { @@ -362,7 +450,7 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev) return; } =20 - pci_liveupdate_unpreserve_device(ser, dev); + pci_liveupdate_unpreserve_path(ser, dev); } EXPORT_SYMBOL_GPL(pci_liveupdate_unpreserve); =20 @@ -534,29 +622,41 @@ void pci_liveupdate_cleanup_device(struct pci_dev *de= v) } } =20 -static void pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_d= ev *dev) +static int pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_de= v *dev) { if (!dev->liveupdate.incoming) { pci_warn(dev, "Cannot finish preserving an unpreserved device\n"); - return; + return -EINVAL; } =20 - if (dev->liveupdate.incoming->refcount !=3D 1) { - pci_WARN(dev, 1, "Preserved device has a corrupted refcount!\n"); - return; + if (!dev->liveupdate.incoming->refcount) { + pci_WARN(dev, 1, "Preserved device has a 0 refcount!\n"); + return -EINVAL; } =20 /* - * Drop the refcount so this device does not get treated as an incoming - * device again, e.g. in case pci_liveupdate_setup_device() gets called - * again because the device is hot-plugged. + * Decrement the refcount so this device does not get treated as an + * incoming device again, e.g. in case pci_liveupdate_setup_device() + * gets called again because the device is hot-plugged. */ - dev->liveupdate.incoming->refcount =3D 0; + if (--dev->liveupdate.incoming->refcount) + return 0; =20 pci_info(dev, "Device is finished participating in Live Update\n"); dev->liveupdate.incoming =3D NULL; ser->nr_devices--; pci_liveupdate_flb_put_incoming(); + return 0; +} + +static void pci_liveupdate_finish_path(struct pci_ser *ser, struct pci_dev= *start) +{ + struct pci_dev *dev; + + for_each_pci_dev_in_path(dev, start, NULL) { + if (pci_liveupdate_finish_device(ser, dev)) + return; + } } =20 /** @@ -568,6 +668,8 @@ static void pci_liveupdate_finish_device(struct pci_ser= *ser, struct pci_dev *de * Update. Drivers must call pci_liveupdate_finish() from their struct * liveupdate_file_handler finish() callback to ensure the incoming struct * pci_ser is allocated. + * + * pci_liveupdate_finish() automatically finishes all bridges upstream of = @dev. */ void pci_liveupdate_finish(struct pci_dev *dev) { @@ -581,7 +683,7 @@ void pci_liveupdate_finish(struct pci_dev *dev) return; } =20 - pci_liveupdate_finish_device(incoming->ser, dev); + pci_liveupdate_finish_path(incoming->ser, dev); pci_liveupdate_flb_put_incoming(); } EXPORT_SYMBOL_GPL(pci_liveupdate_finish); diff --git a/include/linux/kho/abi/pci.h b/include/linux/kho/abi/pci.h index 85def616703d..c86518be4ce7 100644 --- a/include/linux/kho/abi/pci.h +++ b/include/linux/kho/abi/pci.h @@ -23,7 +23,7 @@ * incrementing the version number in the PCI_LUO_FLB_COMPATIBLE string. */ =20 -#define PCI_LUO_FLB_COMPATIBLE "pci-v2" +#define PCI_LUO_FLB_COMPATIBLE "pci-v3" =20 /** * struct pci_dev_ser - Serialized state about a single PCI device. @@ -32,7 +32,8 @@ * @bdf: The device's PCI bus, device, and function number. * @refcount: Reference count used by the PCI core to keep track of whethe= r it * is done using a device's struct pci_dev_ser. The value of the - * refcount is equal to 1 when the struct pci_dev_ser is in use= , and + * refcount is equal to the number of preserved devices at or b= elow + * it in the PCI hierarchy when the struct pci_dev_ser is in us= e, and * 0 otherwise. */ struct pci_dev_ser { --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EEFE385D94 for ; Fri, 22 May 2026 20:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481463; cv=none; b=T8hI1yguhpi/q5bLvo4A6ht63ZHH+Gg94UMJNSG0M31pGuKIJpxYuQoVzOxi/TY+6wWHPR1efOsmb8R2xdJ2mJFjKwRZHTHFWJQGtHF3NiOLq99FfrzM1UAx/USkYWVd/Yc96xoHIZzYSvhUunNUlzSKEPKzjCdogli9Jg4nhfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481463; c=relaxed/simple; bh=AmO7W/8gXxOtZVsrp0KtqrBNzzh+t+7NWZozjr0mE5I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eCoeZUPE7Gni8HlhMDa0rs/QvgO5K2K1ROkBOwgw1qfHRoW41R1NrZjXkK5yQ4ZMzJ4LgXNNef8d+/nyrMknqIDPuWJPDxAZZl5uU+M3FsY+lR7AaXp+uugv8wD6zW3ozH8rs7p29srvKLZfpJgwIV2H6R3NdPVBG25gDH+VB5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NXoMwwd0; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NXoMwwd0" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-365e70c39d0so7332458a91.0 for ; Fri, 22 May 2026 13:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481458; x=1780086258; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dMXxmfHGErf7yBzoXqh/yDUR2jlzP0FOZNAJXyHr7Dw=; b=NXoMwwd0KvadGcJFRg9LnDi0To3hwQuoszqH8QZd6P9ucAVwfHqNPWcv6PloyrDNP/ XMDLDOlyuxYtrYvNQf5pM1T5INq5YIRi9bkZZJCqwTl6dGY5RLpKHFmLAVvXDdFZCoO0 gZ6Bg0S2JuUkawtsXomAygfRAqURD1wQykOFKkKfmxzbleWGw+dgPuNvN1aptI/Hp8IY dsA2Lw1hTidfKnqIbp++h6LqAgceW7MC0xW6ewSXo3V/Xmyxz5l3xURoRv1Bo1fgHGn3 Cj4SlanpkzcJTdWdj1yCsp1POJj89JrPLxE1k0j++tJLk/9ZQWN6eyNqLHNtOUkpylod 2RhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481458; x=1780086258; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dMXxmfHGErf7yBzoXqh/yDUR2jlzP0FOZNAJXyHr7Dw=; b=CFKguXV+47zO7cNWB2KeoZyS8Lba3ULMouLeUFzYtDn63lCvYk/XJHMH1CAz4jACXt LnU8QgDzBDEqjcxWEuHcpWUvsrg2AjlAHyc1VtGfUtFM0qn60yh0qxFxbWUr7RnYqvFK ZKpJRS1UaToOz3uAKT0opnsCZ5rfNFcLTXxTQbRm5HzMnXHceKT85kJLcJWl7YAzRXMa AfTvYbvaabULBIfpgPBcmvm9VtjlAJRmZDQCJWFO1LORneQ8F8gOKisIDUP2ySKH4H0c P/kDVz8/5n+zdcdmKxReOjnRRgKruJzzzFvvlnGpDHM7RJMSG89h1nqbfOVEG0TDJqvL HutA== X-Forwarded-Encrypted: i=1; AFNElJ/QzoO9L0MKu441tcyDnxoWLZq7+W71eAj6KL1btxtFRWmcvGNefRKFjKuW+K1iNMV3Rsui+xY6w2RSHug=@vger.kernel.org X-Gm-Message-State: AOJu0YzaMeTR2xAwG1UXkDQYvBROz9wAcmEIICfDm1my4kLYl8ExSozU jIJ3rQwqFTGXMw3ynSS3rmPc8kjvIWRMR9iyFSjt+4QDnBkPhaXeLu/BmiXeZ+2pvVB9ix+NLMt TwRfvj7aQosZZFA== X-Received: from pjbsz6.prod.google.com ([2002:a17:90b:2d46:b0:369:4369:c7f9]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3807:b0:366:10f1:3d91 with SMTP id 98e67ed59e1d1-36a6741dd88mr5140261a91.1.1779481458189; Fri, 22 May 2026 13:24:18 -0700 (PDT) Date: Fri, 22 May 2026 20:24:05 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-8-dmatlack@google.com> Subject: [PATCH v6 07/12] PCI: Refactor matching logic for pci_dev_acs_ops From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the logic to match devices to pci_dev_acs_ops by factoring out the loop and device matching into its own routine. This eliminates some duplicate code between pci_dev_specific_enable_acs() and pci_dev_specific_disable_acs_redir(), and will also be used in a subsequent commit to check if a device requires device-specific enable_acs() during a Live Update. No functional change intended. Signed-off-by: David Matlack --- drivers/pci/quirks.c | 50 ++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index caaed1a01dc0..171caec2bc47 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5384,9 +5384,6 @@ static void pci_quirk_enable_intel_rp_mpc_acs(struct = pci_dev *dev) */ static int pci_quirk_enable_intel_pch_acs(struct pci_dev *dev) { - if (!pci_quirk_intel_pch_acs_match(dev)) - return -ENOTTY; - if (pci_quirk_enable_intel_lpc_acs(dev)) { pci_warn(dev, "Failed to enable Intel PCH ACS quirk\n"); return 0; @@ -5406,9 +5403,6 @@ static int pci_quirk_enable_intel_spt_pch_acs(struct = pci_dev *dev) int pos; u32 cap, ctrl; =20 - if (!pci_quirk_intel_spt_pch_acs_match(dev)) - return -ENOTTY; - pos =3D dev->acs_cap; if (!pos) return -ENOTTY; @@ -5436,9 +5430,6 @@ static int pci_quirk_disable_intel_spt_pch_acs_redir(= struct pci_dev *dev) int pos; u32 cap, ctrl; =20 - if (!pci_quirk_intel_spt_pch_acs_match(dev)) - return -ENOTTY; - pos =3D dev->acs_cap; if (!pos) return -ENOTTY; @@ -5458,22 +5449,25 @@ static int pci_quirk_disable_intel_spt_pch_acs_redi= r(struct pci_dev *dev) static const struct pci_dev_acs_ops { u16 vendor; u16 device; + bool (*match)(struct pci_dev *dev); int (*enable_acs)(struct pci_dev *dev); int (*disable_acs_redir)(struct pci_dev *dev); } pci_dev_acs_ops[] =3D { { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, + .match =3D pci_quirk_intel_pch_acs_match, .enable_acs =3D pci_quirk_enable_intel_pch_acs, }, { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, + .match =3D pci_quirk_intel_spt_pch_acs_match, .enable_acs =3D pci_quirk_enable_intel_spt_pch_acs, .disable_acs_redir =3D pci_quirk_disable_intel_spt_pch_acs_redir, }, }; =20 -int pci_dev_specific_enable_acs(struct pci_dev *dev) +static const struct pci_dev_acs_ops *pci_dev_acs_ops_get(struct pci_dev *d= ev) { const struct pci_dev_acs_ops *p; - int i, ret; + int i; =20 for (i =3D 0; i < ARRAY_SIZE(pci_dev_acs_ops); i++) { p =3D &pci_dev_acs_ops[i]; @@ -5481,33 +5475,29 @@ int pci_dev_specific_enable_acs(struct pci_dev *dev) p->vendor =3D=3D (u16)PCI_ANY_ID) && (p->device =3D=3D dev->device || p->device =3D=3D (u16)PCI_ANY_ID) && - p->enable_acs) { - ret =3D p->enable_acs(dev); - if (ret >=3D 0) - return ret; - } + p->match(dev)) + return p; } =20 + return NULL; +} + +int pci_dev_specific_enable_acs(struct pci_dev *dev) +{ + const struct pci_dev_acs_ops *p =3D pci_dev_acs_ops_get(dev); + + if (p && p->enable_acs) + return p->enable_acs(dev); + return -ENOTTY; } =20 int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) { - const struct pci_dev_acs_ops *p; - int i, ret; + const struct pci_dev_acs_ops *p =3D pci_dev_acs_ops_get(dev); =20 - for (i =3D 0; i < ARRAY_SIZE(pci_dev_acs_ops); i++) { - p =3D &pci_dev_acs_ops[i]; - if ((p->vendor =3D=3D dev->vendor || - p->vendor =3D=3D (u16)PCI_ANY_ID) && - (p->device =3D=3D dev->device || - p->device =3D=3D (u16)PCI_ANY_ID) && - p->disable_acs_redir) { - ret =3D p->disable_acs_redir(dev); - if (ret >=3D 0) - return ret; - } - } + if (p && p->disable_acs_redir) + return p->disable_acs_redir(dev); =20 return -ENOTTY; } --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F072B386562 for ; Fri, 22 May 2026 20:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481462; cv=none; b=de2WIJLHyz/fU7Gl5nliNTCU8QP7rYP/JIsfCdxmIhAhwBqdazM3dM3UbQYHvZyuo95ANeES+v1uuYBHZJ5teA0Z7FMx67iRvhNzj6SrnUXWgTxqYw0Q7YOJP0QJY937rsRz8nicJ4NJ27VOdmOXhXoK3QYaPpqVQ23x/ihKfzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481462; c=relaxed/simple; bh=1vV0uwLZDO9f0jwlmwTLYtqhKwT1lIDL5w/1xm9Frgg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=kfoSGgYE6uWoVit2rIfvClsfxREVpnfXkrZbE+LAyN7I1YGJIhB3G2vk/hRpYOlRV2DEm6AawN2Jj7aNjk+/CeqOzLYgeJmJqgX5NdJWWTkUeaAXQLd4mDlMVM1459jwnAjRkXULvxljW+RrP22SX4b6gxCxcfFb/FD1dXR7ow4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NcDjWuzF; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NcDjWuzF" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2b4678c6171so82005775ad.1 for ; Fri, 22 May 2026 13:24:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481459; x=1780086259; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SPpQo5/8o8XmqfCxBMhae2hXoPWQwl78O5LFi9BXZl8=; b=NcDjWuzF7FhT9i1SRotT/Pa9gJIO8pbN2SWkyb/Sawlftb5VDiCx9KHmwNin3YiM4q L7Q6uoykpAaHHLeYTvuaRC6s3AnoKkkLzSTqRFg/lGEkdtU3C/hpbr//ZgsCV2qQDHlU yJEvzQ/FvJtX7nFnyuz1T7Fp0azlkwLYfHGYkYhnSPoBEDEib6P7LlAipktreM4B0oMj 4MzpTp8MC2wRf1j7WpdL5hpYf8LiqdVRgyqnYhKm08HGDZhBH2n7bdyZWb3aP7ElV1TO uwmapsFhXe64pwjTX+9sZxUBNtCfI+WpwsDAa9cQzhIXHuUkvAxpctjkzQNdOlR/4guj yN7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481459; x=1780086259; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SPpQo5/8o8XmqfCxBMhae2hXoPWQwl78O5LFi9BXZl8=; b=p6aI10Sah0QNrldM3RfXJsrMJ3tjYORbOojidrEPQqVT8ovwCa5OMrAg+XA0UKgblo FwpSa3ciAorpInipGd05DC1aIiIDRz+ovB6zX1VWPc8KD089TKpAaKeyeTfmUKPdn3pz m8lBHoKDbN5EmUgLBBcKt9fcrzIgYfZsvjYszR3WnP7uDbjE1GgFfS92QGPCIv4tH6fb onV6Wmtq03BQz+uLJ5vSAzxLD2pTIUlqXejj71XYPQ7hNj+yw1o6xDrbCtnT+t/Q4VvO QjHCaWm747+2eekpwCVgUKua/AfH1im28mnLvJIFrtnawar9ZI8pnV2+CMBDaOay13Sd in+Q== X-Forwarded-Encrypted: i=1; AFNElJ/t3ixwe4B40qDrF1G7w7L/doDm70GG/sW3nRewXMggxEo/RiSTYwq85IAIwxaoNcP70cgc4j1MBWud+sM=@vger.kernel.org X-Gm-Message-State: AOJu0YzP3S2+zbUEuEhu4S4Wx35UY0vaIBH2+7eLyS9bxpTm2NAAN1H9 SmZtFYDh7pFRFBJBwMruTn2ckQt2ytfZALbG7Mx++EeG6CPt0b6yCdGDO928bhrY500719PnIX3 FFMWO7/0CSvFJ/A== X-Received: from plqu9.prod.google.com ([2002:a17:902:a609:b0:2bd:9b10:8067]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:354b:b0:2bc:db91:f5a7 with SMTP id d9443c01a7336-2beb0735023mr53621445ad.11.1779481459064; Fri, 22 May 2026 13:24:19 -0700 (PDT) Date: Fri, 22 May 2026 20:24:06 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-9-dmatlack@google.com> Subject: [PATCH v6 08/12] PCI: liveupdate: Inherit ACS flags in incoming preserved devices From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inherit Access Control Services (ACS) flags on all incoming preserved devices (endpoints and upstream bridges) during a Live Update. Inheriting ACS flags avoids changing routing rules while memory transactions are in flight from preserved devices. This is also strictly necessary to ensure that IOMMU group assignments do not change across a Live Update for preserved devices, as changing ACS configurations can split or merge IOMMU groups. Cache the inherited ACS controls established by the previous kernel in struct pci_dev so that ACS controls do not change after a reset (pci_restore_state() calls pci_enable_acs()). To simplify ACS inheritance, reject preserving any devices that require quirks to enable ACS as those quirks would also have to take Live Update into account. Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 68 ++++++++++++++++++++++++++++++++++ drivers/pci/liveupdate.h | 11 ++++++ drivers/pci/pci.c | 5 +++ drivers/pci/pci.h | 5 +++ drivers/pci/quirks.c | 7 ++++ include/linux/pci_liveupdate.h | 6 +++ 6 files changed, 102 insertions(+) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 4c79e19b7f98..a93b7ef065f2 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -71,6 +71,9 @@ * * * The device cannot be a Virtual Function (VF). * + * * The device cannot require device-specific quirks to enable Access + * Control Services (ACS). + * * Driver Binding * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * @@ -113,6 +116,18 @@ * This enables the PCI core and any drivers bound to the bridge to partic= ipate * in the Live Update so that preserved endpoints can continue issuing mem= ory * transactions during the Live Update. + * + * Handling Preserved Devices + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + * + * The PCI core treats preserved devices differently than non-preserved de= vices. + * This section enumerates those differences. + * + * * The PCI core inherits all ACS flags enabled on incoming preserved de= vices + * rather than assigning new ones. This ensures that TLPs are routed th= e same + * way after Live Update and ensures that IOMMU groups do not change. N= ote + * that a device will use its inherited ACS flags for the lifetime of i= ts + * struct pci_dev (i.e. even after pci_liveupdate_finish()). */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -126,6 +141,7 @@ #include =20 #include "liveupdate.h" +#include "pci.h" =20 /** * struct pci_liveupdate_global - Global state for PCI Live Update support @@ -319,6 +335,16 @@ static int __pci_liveupdate_preserve_device(struct pci= _ser *ser, struct pci_dev { int i; =20 + /* + * Do not preserve devices that rely on device-specific ACS equivalents + * (for now) since that would complicate keeping ACS constant across + * Live Update. + */ + if (pci_need_dev_specific_enable_acs(dev)) { + pci_warn(dev, "Refusing to preserve device that relies on ACS quirks\n"); + return -EINVAL; + } + if (ser->nr_devices =3D=3D ser->max_nr_devices) return -ENOSPC; =20 @@ -598,6 +624,7 @@ void pci_liveupdate_setup_device(struct pci_dev *dev) =20 pci_info(dev, "Device was preserved by previous kernel across Live Update= \n"); dev->liveupdate.incoming =3D dev_ser; + dev->liveupdate.was_preserved =3D true; =20 /* * Hold the ref on the incoming FLB until pci_liveupdate_finish() so @@ -688,6 +715,47 @@ void pci_liveupdate_finish(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_liveupdate_finish); =20 +void pci_liveupdate_init_acs(struct pci_dev *dev) +{ + guard(rwsem_read)(&pci_liveupdate.rwsem); + + if (!dev->acs_cap || !dev->liveupdate.incoming) + return; + + pci_read_config_word(dev, dev->acs_cap + PCI_ACS_CTRL, &dev->liveupdate.a= cs_ctrl); +} + +int pci_liveupdate_enable_acs(struct pci_dev *dev) +{ + u16 acs_ctrl =3D dev->liveupdate.acs_ctrl; + u16 acs_cap =3D dev->acs_cap; + + /* + * Use liveupdate.was_preserved instead of liveupdate.incoming since the + * device's ACS controls should not change even after the device is + * finished participating in the Live Update. + */ + if (!dev->liveupdate.was_preserved) + return -EINVAL; + + /* + * The previous kernel should not have preserved any devices that + * require device-specific quirks to enable ACS, but if such a device is + * detected, log a big warning and fall back to the normal enable ACS + * path. + */ + if (pci_need_dev_specific_enable_acs(dev)) { + pci_warn(dev, "Device-specific quirk required to enable ACS!\n"); + WARN_ON_ONCE(true); + return -EINVAL; + } + + if (acs_cap) + pci_write_config_word(dev, acs_cap + PCI_ACS_CTRL, acs_ctrl); + + return 0; +} + /** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index c763255a8de4..4e8a01bcb4bb 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -16,6 +16,8 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev); bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, struct pci_dev = *dev, int pass); void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int pass); +void pci_liveupdate_init_acs(struct pci_dev *dev); +int pci_liveupdate_enable_acs(struct pci_dev *dev); #else static inline void pci_liveupdate_setup_device(struct pci_dev *dev) { @@ -35,6 +37,15 @@ static inline bool pci_liveupdate_scan_bridge_begin(stru= ct pci_bus *bus, static inline void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int= pass) { } + +static inline void pci_liveupdate_init_acs(struct pci_dev *dev) +{ +} + +static inline int pci_liveupdate_enable_acs(struct pci_dev *dev) +{ + return -EINVAL; +} #endif =20 #endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 8f7cfcc00090..211df4618164 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -33,6 +33,7 @@ #include #include #include +#include "liveupdate.h" #include "pci.h" =20 DEFINE_MUTEX(pci_slot_mutex); @@ -1017,6 +1018,9 @@ void pci_enable_acs(struct pci_dev *dev) bool enable_acs =3D false; int pos; =20 + if (!pci_liveupdate_enable_acs(dev)) + return; + /* If an iommu is present we start with kernel default caps */ if (pci_acs_enable) { if (pci_dev_specific_enable_acs(dev)) @@ -3657,6 +3661,7 @@ void pci_acs_init(struct pci_dev *dev) =20 pci_read_config_word(dev, pos + PCI_ACS_CAP, &dev->acs_capabilities); pci_disable_broken_acs_cap(dev); + pci_liveupdate_init_acs(dev); } =20 /** diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 4a14f88e543a..b55f3deddd57 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -1062,6 +1062,7 @@ void pci_acs_init(struct pci_dev *dev); void pci_enable_acs(struct pci_dev *dev); #ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); +bool pci_need_dev_specific_enable_acs(struct pci_dev *dev); int pci_dev_specific_enable_acs(struct pci_dev *dev); int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); void pci_disable_broken_acs_cap(struct pci_dev *pdev); @@ -1072,6 +1073,10 @@ static inline int pci_dev_specific_acs_enabled(struc= t pci_dev *dev, { return -ENOTTY; } +static inline bool pci_need_dev_specific_enable_acs(struct pci_dev *dev) +{ + return false; +} static inline int pci_dev_specific_enable_acs(struct pci_dev *dev) { return -ENOTTY; diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 171caec2bc47..59b0b19c3783 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5482,6 +5482,13 @@ static const struct pci_dev_acs_ops *pci_dev_acs_ops= _get(struct pci_dev *dev) return NULL; } =20 +bool pci_need_dev_specific_enable_acs(struct pci_dev *dev) +{ + const struct pci_dev_acs_ops *p =3D pci_dev_acs_ops_get(dev); + + return p && p->enable_acs; +} + int pci_dev_specific_enable_acs(struct pci_dev *dev) { const struct pci_dev_acs_ops *p =3D pci_dev_acs_ops_get(dev); diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index 2be98819e313..2446c6d237ca 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -17,14 +17,20 @@ * struct pci_liveupdate - PCI Live Update state for a struct pci_dev * @outgoing: State preserved for the next kernel. * @incoming: State preserved by the previous kernel. + * @acs_ctrl: ACS features established by the previous kernel. * @inherit_buses: True if the PCI core should inherit the secondary and * subordinate bus numbers assigned to this device due to * an ongoing Live Update. + * @was_preserved: True if this struct pci_dev was preserved by the previo= us + * kernel. Unlike @incoming, this field is not cleared aft= er + * the device is finished participating in Live Update. */ struct pci_liveupdate { struct pci_dev_ser *outgoing; struct pci_dev_ser *incoming; + u16 acs_ctrl; bool inherit_buses; + bool was_preserved; }; =20 struct pci_dev; --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F53387578 for ; Fri, 22 May 2026 20:24:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481464; cv=none; b=b6R4KCeX8QSU4K+ZEuDgqkGPtbv1P8cLLDp2q+Y8OivjkfxpU4Cuf3hWpS7lA41pHCOVKSH1SgUiMO8aeNSgFaF25Fy0tVxyVsk6/xhFvYG83S1Vg7yCXUk/MKJT0aYLvmdSWnkALK8hP7hMsUCmDQdWSeY3bGbDaPQOYFldz+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481464; c=relaxed/simple; bh=M12PKwo0dxZ6h9CLBntX9VgSZgyJgAD7fUgsyUi7EWo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lGDQ2ANy+/EFFjjsBBsesk1ZUUwRF/LxZimVaCWQoYxfxr7la0stzfVFzFWbEz3Glw5qpKxXqZnorFlGYaCKBT/3AqX5kZswj1/FLS21P3wJapZqf+ufek6Z0qyDKwYEOdNsnFMDyuufD33Z3m7mP8iBu1VLnXh7CX3TnFkaM58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FxYK7h4C; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FxYK7h4C" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c8279604464so10651380a12.1 for ; Fri, 22 May 2026 13:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481460; x=1780086260; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=07zUHNcjisF6FOuU9N0CtQnOBIzxNou2anoHgJH+mP8=; b=FxYK7h4Crfrtl9ufsAWbjHdznPyS0vFLwO2WYTtW+NeX/xJfutPDg6CFnia2HDadI/ s7GUqPhf8vJ/nt+qOHtxMpQ0g5zngpBu63bK8J0G6ZufvigJgKrgAhG1m1a7X2Pjw1WR 64mo25KF2A4rAdqcV4pHqKGcC9kq1W2Mc+ghaC+u6127ggjrO/po8FDddAlcWE4jd/PF mDObKbQo2F74NQIijFNTZ3o/re/SRnzcQ1ELFadNAniD1Con8F/3xG4Q4CsKJuqFJw38 o+eCrRepIZEu2ktCvS7VH7hRbkDpdCA1BF72F235r+ZeAkhQ/oGLE4KoeFaFlaug2hUe vlzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481460; x=1780086260; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=07zUHNcjisF6FOuU9N0CtQnOBIzxNou2anoHgJH+mP8=; b=pO+NPgBCM7FeE4OSaPO5P52OLgI2RJU4m8fM41teEvcOXU4J+JFFEgev+lcskDsFYu LjBqi+fmmHqgAjOuUgg60+YExbUsBbXONEfFzQw8+c1wQMZhP7/HHsH9N/+9qT2xxRAs VDam5Xf/ZQL0T1uLYpeR23P3fi7OecNSBzm4d0tZ5X3yvH4Jrn8xrFxIdQyOkoIpBvkn zdrvEG5CqZoz5zlPM1UrbxPiiJIeVxXmJJI42thoyk31SqhoKj0PdGmgsgJ2vO7G5xAy yO7oQmhghoANTccZDys4YjS+sST8mVC/F6oGoBPAjHQUI12lHpngHSMs3T9EMIWGOJ8E a98g== X-Forwarded-Encrypted: i=1; AFNElJ9eBjP0Hwl4PZuXD8f2V9bUoYHPrI5/Piw1+eEIF9MCLY1Lw2GZESsrX9VFCIxDuAMxwwlRIvOeFb5iEB4=@vger.kernel.org X-Gm-Message-State: AOJu0YygMM+DPTOr0k3LbE992LHbQbGZiZHmxiaFNQF2DPTlwk/ZQtmp UVgDKZwqOmz781Jr4AHGjOJHTMJ+2uWtSHFnPoIhwai2O8HN3YhmlKiX0+O8TqrqJ+IJxavdnlG O++HYTD7xrb/b9A== X-Received: from pgt6.prod.google.com ([2002:a63:1346:0:b0:c82:7a06:d5f5]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:d709:b0:3b3:c28:45b3 with SMTP id adf61e73a8af0-3b328e4f8d7mr5132386637.26.1779481459861; Fri, 22 May 2026 13:24:19 -0700 (PDT) Date: Fri, 22 May 2026 20:24:07 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-10-dmatlack@google.com> Subject: [PATCH v6 09/12] PCI: liveupdate: Inherit ARI Forwarding Enable on preserved bridges From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inherit the ARI Forwarding Enable on preserved bridges and update pci_dev->ari_enabled accordingly during a Live Update. This ensures that the preserved devices on the bridge's secondary bus can be identified with the same expanded 8-bit function number after a Live Update. Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 18 ++++++++++++++++++ drivers/pci/liveupdate.h | 6 ++++++ drivers/pci/pci.c | 8 +++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index a93b7ef065f2..701276ef6cfb 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -128,6 +128,10 @@ * way after Live Update and ensures that IOMMU groups do not change. N= ote * that a device will use its inherited ACS flags for the lifetime of i= ts * struct pci_dev (i.e. even after pci_liveupdate_finish()). + * + * * The PCI core inherits ARI Forwarding Enable on all bridges with down= stream + * preserved devices to ensure that all preserved devices on the bridge= 's + * secondary bus are addressable after the Live Update. */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -756,6 +760,20 @@ int pci_liveupdate_enable_acs(struct pci_dev *dev) return 0; } =20 +int pci_liveupdate_configure_ari(struct pci_dev *dev) +{ + u16 val; + + guard(rwsem_read)(&pci_liveupdate.rwsem); + + if (!dev->liveupdate.incoming) + return -EINVAL; + + pcie_capability_read_word(dev, PCI_EXP_DEVCTL2, &val); + dev->ari_enabled =3D !!(val & PCI_EXP_DEVCTL2_ARI); + return 0; +} + /** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index 4e8a01bcb4bb..6f21ec50927b 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -18,6 +18,7 @@ bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus= , struct pci_dev *dev, void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int pass); void pci_liveupdate_init_acs(struct pci_dev *dev); int pci_liveupdate_enable_acs(struct pci_dev *dev); +int pci_liveupdate_configure_ari(struct pci_dev *dev); #else static inline void pci_liveupdate_setup_device(struct pci_dev *dev) { @@ -46,6 +47,11 @@ static inline int pci_liveupdate_enable_acs(struct pci_d= ev *dev) { return -EINVAL; } + +static inline int pci_liveupdate_configure_ari(struct pci_dev *dev) +{ + return -EINVAL; +} #endif =20 #endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 211df4618164..271da55af270 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3495,7 +3495,7 @@ void pci_configure_ari(struct pci_dev *dev) u32 cap; struct pci_dev *bridge; =20 - if (pcie_ari_disabled || !pci_is_pcie(dev) || dev->devfn) + if (!pci_is_pcie(dev) || dev->devfn) return; =20 bridge =3D dev->bus->self; @@ -3506,6 +3506,12 @@ void pci_configure_ari(struct pci_dev *dev) if (!(cap & PCI_EXP_DEVCAP2_ARI)) return; =20 + if (!pci_liveupdate_configure_ari(bridge)) + return; + + if (pcie_ari_disabled) + return; + if (pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI)) { pcie_capability_set_word(bridge, PCI_EXP_DEVCTL2, PCI_EXP_DEVCTL2_ARI); --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6AAB3438B8 for ; Fri, 22 May 2026 20:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481463; cv=none; b=AuG0x0MyLGhcWRl7e/92TjzyjhCSF083sWcDpr781znfbWRK2qtgJDdflnwY3N3TNH8JGkp5lv2kHR9W9bi1TTXrXiwKrq2ww2liVTrz8k2ikUVV39q9dnziAf0a6eleCWMm8EFD46irL3pyxOJt8BkbsVbdSHs4xWFsKhDqWNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481463; c=relaxed/simple; bh=vt29mpxfdN0oynKpwfSKNPgSGC8PTO+Nd0Edazw1zxI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ieh6OoW4ubrUewsiEeU/vciKMzgTU+supIX78/Ky+6ju+tuG+2fbELoXrNhIrIsDaz6CVnsjNfyt1S9VC25vTV6vLCUnQNjTc06wOHHRVFdvDevWHOyVzE6HKLyP7uwKu+xFZZl5qWbVzpucVdXYIYxJfDtNKe/ucE4KL04gcW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hW6XQh/Y; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hW6XQh/Y" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-366344513a3so16024358a91.3 for ; Fri, 22 May 2026 13:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481461; x=1780086261; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n5gRktteoUb/1GJUOFc5t/RbM6I0eXe+lj3sebUBczU=; b=hW6XQh/YG3z/1o2uZJGwCH/Z3VVLev90bLEAbA3VuUe5tWjA0xmyf0PBoXOlWM6r9h bifsIEFxC9Ry8WNTQ+ZtiiORIOJ97Odhyn04SkUXTneUN20dedMheytQv4iQ4YbPTTdg tqDg6uiSA+e731mBDXfA72CxP3SsuHfQzIhGkE5povIPRGbTuK9h38X+/7t9RlOmi3tE zKX/nszskEKWT3Np7TLzyUjVpc8vz7nW5xrm+WBcVV2HlQIeMPfVBOGHhGTvdqjBDwoP zzXaJjhdSzUz25w8IE5zxZ+lg1dyLsiwAYUFxs95WF7rYIldLRt2FYzLD683MJ6n/HXb zg4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481461; x=1780086261; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n5gRktteoUb/1GJUOFc5t/RbM6I0eXe+lj3sebUBczU=; b=r6lqq3KsIjpJCYjKBlhEvyOuqwdoerRs0pplFr7ThYjOfnV6pf5kd+6IoPSdXobW4t Umu+kUIs4bJNk880epTG7C14VxiIUUSHJr0DlLYKrI4UzrXfjUjUvsiJ4yjEuVE+pZin 90txlQTNNsgRlKlJAw3TP77aV9ktcgtMFE7CNb4pKY7qIYuZ/Tf1nv/B6uIizt2XYkwx g7O3X1aFNH0/lk0nbiyTdRoEUyT8oJhsJHGvSezumErAglhF92qtlFs5gDKD7wrogj+f XCFK1XAnBu5++ke8xi7dknFGfR7bespO8Ja+aqBfpECIh+gI4rgX/GGqeTNrAX/wy+yv CApQ== X-Forwarded-Encrypted: i=1; AFNElJ+gV+r8prq3xM6HUOjmUARmzttQMn1GSYrZ51gaAi4VP3hBqgWj3PfS3GYsCp1rMQH+J+YEH8625WMZj1k=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/taWAVTPlitleIzoWfaw9tixkMhqP2dwyUtGquAmRw016pjgQ WxI63GZIkbG4K4TaBghd3p6w62MBu6pA7q8yo1rROIUofLYC9qOtTRjn+gnvKFYlZez3Gi5I0fN 2gibRJ6YpmGtQ3g== X-Received: from pjbtc4.prod.google.com ([2002:a17:90b:5404:b0:36a:81c9:4523]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3ecc:b0:369:d7c6:450a with SMTP id 98e67ed59e1d1-36a671e974emr5405438a91.0.1779481460825; Fri, 22 May 2026 13:24:20 -0700 (PDT) Date: Fri, 22 May 2026 20:24:08 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-11-dmatlack@google.com> Subject: [PATCH v6 10/12] PCI: liveupdate: Freeze preservation status during shutdown From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Freeze a device's outgoing preservation status (preserved or not preserved) during shutdown. This enables the PCI core and drivers to safely make decisions based on the device's preservation status during shutdown. Note that pci_liveupdate_freeze() is triggered by the PCI core rather than from drivers participating in Live Update so that all devices can have their status frozen (i.e. prevent non-preserved devices from getting preserved late). Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 16 ++++++++++++++++ drivers/pci/liveupdate.h | 5 +++++ drivers/pci/pci-driver.c | 2 ++ include/linux/pci_liveupdate.h | 3 +++ 4 files changed, 26 insertions(+) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 701276ef6cfb..d404e64a4e55 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -297,6 +297,11 @@ static int pci_liveupdate_unpreserve_device(struct pci= _ser *ser, struct pci_dev { struct pci_dev_ser *dev_ser =3D dev->liveupdate.outgoing; =20 + if (dev->liveupdate.frozen) { + pci_warn(dev, "Cannot unpreserve device after it is frozen!\n"); + return -EINVAL; + } + if (!dev_ser) { pci_warn(dev, "Cannot unpreserve device that is not preserved\n"); return -EINVAL; @@ -380,6 +385,11 @@ static int __pci_liveupdate_preserve_device(struct pci= _ser *ser, struct pci_dev =20 static int pci_liveupdate_preserve_device(struct pci_ser *ser, struct pci_= dev *dev) { + if (dev->liveupdate.frozen) { + pci_warn(dev, "Cannot preserve device after it is frozen!\n"); + return -EINVAL; + } + if (dev->liveupdate.outgoing) return pci_liveupdate_preserve_device_again(dev); =20 @@ -653,6 +663,12 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev) } } =20 +void pci_liveupdate_freeze(struct pci_dev *dev) +{ + guard(rwsem_write)(&pci_liveupdate.rwsem); + dev->liveupdate.frozen =3D 1; +} + static int pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_de= v *dev) { if (!dev->liveupdate.incoming) { diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index 6f21ec50927b..bcb0bc73d684 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -13,6 +13,7 @@ #ifdef CONFIG_PCI_LIVEUPDATE void pci_liveupdate_setup_device(struct pci_dev *dev); void pci_liveupdate_cleanup_device(struct pci_dev *dev); +void pci_liveupdate_freeze(struct pci_dev *dev); bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, struct pci_dev = *dev, int pass); void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, int pass); @@ -28,6 +29,10 @@ static inline void pci_liveupdate_cleanup_device(struct = pci_dev *dev) { } =20 +static inline void pci_liveupdate_freeze(struct pci_dev *dev) +{ +} + static inline bool pci_liveupdate_scan_bridge_begin(struct pci_bus *bus, struct pci_dev *dev, int pass) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index d10ece0889f0..f7a5e65a7c75 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -21,6 +21,7 @@ #include #include #include +#include "liveupdate.h" #include "pci.h" #include "pcie/portdrv.h" =20 @@ -536,6 +537,7 @@ static void pci_device_shutdown(struct device *dev) struct pci_dev *pci_dev =3D to_pci_dev(dev); struct pci_driver *drv =3D pci_dev->driver; =20 + pci_liveupdate_freeze(pci_dev); pm_runtime_resume(dev); =20 if (drv && drv->shutdown) diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index 2446c6d237ca..150993405754 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -24,6 +24,8 @@ * @was_preserved: True if this struct pci_dev was preserved by the previo= us * kernel. Unlike @incoming, this field is not cleared aft= er * the device is finished participating in Live Update. + * @frozen: True if the outgoing preservation status of this device is fro= zen + * and thus cannot be changed. */ struct pci_liveupdate { struct pci_dev_ser *outgoing; @@ -31,6 +33,7 @@ struct pci_liveupdate { u16 acs_ctrl; bool inherit_buses; bool was_preserved; + bool frozen; }; =20 struct pci_dev; --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAA3A388E5C for ; Fri, 22 May 2026 20:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481465; cv=none; b=KLvV4tWYzaA+3s5Rw19lr2ZjE2nQc4uZDdFVeWpYOsyYSWWXC6k2vYMnnspj0SaJT4Ttwp1FmN7q7YLEDQ+pohmeJ+5/VF5NbaSv27dTBeTXtsNn6fLO0YzZck80q408qdwqa/SiFP7nyPF0WsqCGv4ev2OJZvuQsM1YK4a/QWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481465; c=relaxed/simple; bh=IFpekg4jIy49rcerxosa2lVjkpAOv3scOF7wzuEXqFc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WxTIPjO4shdjcIwr1kM+dZe0AZCFSQKYGIpPgYsENUO6dmFfte6DN4HlrCKtSA291Fz7MFGnLWiDM199OsRIVs1dLnvxOQ53hP0YN450Vw37StHtkuOjPk7O5nGQkfsqsCkwJPO/NAarfHiX6HVAsmJ2WcbWjT4EtYBiD0EgJMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qguJmeAE; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qguJmeAE" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b99eb06178so180066015ad.2 for ; Fri, 22 May 2026 13:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481462; x=1780086262; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ELGOGHy4/KVLZOwsmSfN8vqnsYItcEyHVrWWGLC9A+w=; b=qguJmeAEyNwCF//WtcTI/B7p+Q0MIs0bPYpnm8aj1N8w3Q95W9c42wGvOR4TdrUOJr 5OzHtSSUM4m/m3YMn0BIEwZ9SGyqLm8iG4KlV3JvLDvABA5gMHELreCMhVy+84QkQJbg W5mIpjoLopUxUHmwMuXEDQGRRNM27DvQSyUFN6smbFYAzOdc59l56NGClssvQ8p81Aod J5v+enlS1Z+/W8zBCOk0RSaO/q7T8OgSTVc1+NOTbH7FbOI495mg/QWsPTLjKMTChyHT umPHL4kbEI1zCSRlw3tEU5u4pst841Jn2Vk1erDyZicAF7PFd+WGAR01xx0Wprrc/wGb i4yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481462; x=1780086262; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ELGOGHy4/KVLZOwsmSfN8vqnsYItcEyHVrWWGLC9A+w=; b=Pb66HPQk1rmPRhzpFL8enqkvoWFrOCgGPu1HJGMEYLn6Bbn1xsf9EEGLicZTNjxpwh A10rYcD1s26Xsk4Nna/dvWMbwYRUCWo6DLk6nNXwC7iBgZuIyBJFHMKwAg8qR594AaTd wkkQjTGr1lGBm8gq8+FDDaescicyS9Wze88/8AP8cPIGuFQmXNlkjXB14IAXXenF9GwF U4O7/EdEyZVIicEudI7f49ArfaOIB8PCceTOnMg9vWCn2XgVw+Ucqwyr454qikYKqSpN PD0rrKvH6xvHnvSA6I18oBoJCt3SFjloXQ2ZpU4JhGf+4ESZ6g0hCdSa20vm6mFLdGbd uiLQ== X-Forwarded-Encrypted: i=1; AFNElJ9/TG7P1e7+y786syBKlho2llgSa/9gN8aqXD+WFW1N6TKAxH0cxwXRKEPj9od5xVrkujPZOxpjJpZiOiM=@vger.kernel.org X-Gm-Message-State: AOJu0YxvU8ADFD1f5RnLAOa6Ft8BluliNoLaMRwLC6w6UuHZKaip1Uy2 ZmugsIH4l7I30iOGgbfIRlhlUMCjC1RMD0o8ZGXPiaFhLPv5mn1iEA0ZTmfPshZgSGzuRFX5byL q5TzNH2LvKFaTqQ== X-Received: from plgm11.prod.google.com ([2002:a17:902:f64b:b0:2ae:c50f:f4ec]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2b0e:b0:2bc:7c62:187 with SMTP id d9443c01a7336-2beb06133f5mr57599895ad.29.1779481461788; Fri, 22 May 2026 13:24:21 -0700 (PDT) Date: Fri, 22 May 2026 20:24:09 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-12-dmatlack@google.com> Subject: [PATCH v6 11/12] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Do not disable bus mastering on outgoing preserved devices during pci_device_shutdown() for kexec. Preserved devices must be allowed to perform memory transactions during a Live Update to ensure continuous operation. Clearing the bus mastering bit would prevent these devices from issuing any memory requests while the new kernel boots. Because bridges upstream of preserved endpoint devices are also automatically preserved, this change also avoids clearing bus mastering on them. This is critical because clearing bus mastering on an upstream bridge prevents the bridge from forwarding memory requests upstream (i.e. it would prevent the endpoint device from accessing system RAM and doing peer-to-peer transactions with devices not downstream of the bridge). Signed-off-by: David Matlack --- drivers/pci/liveupdate.c | 11 +++++++++++ drivers/pci/liveupdate.h | 6 ++++++ drivers/pci/pci-driver.c | 7 +++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index d404e64a4e55..a6f2790bc1bf 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -132,6 +132,10 @@ * * The PCI core inherits ARI Forwarding Enable on all bridges with down= stream * preserved devices to ensure that all preserved devices on the bridge= 's * secondary bus are addressable after the Live Update. + * + * * The PCI core does not disable bus mastering on outgoing preserved de= vices + * during kexec. This allows preserved devices to issue memory transact= ions + * throughout the Live Update. */ =20 #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -790,6 +794,13 @@ int pci_liveupdate_configure_ari(struct pci_dev *dev) return 0; } =20 +bool pci_liveupdate_is_outgoing(struct pci_dev *dev) +{ + guard(rwsem_read)(&pci_liveupdate.rwsem); + pci_WARN_ONCE(dev, !dev->liveupdate.frozen, "Preservation status is unsta= ble!\n"); + return dev->liveupdate.outgoing; +} + /** * pci_liveupdate_is_incoming() - Check if a device is incoming-preserved * @dev: The PCI device to check diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index bcb0bc73d684..b266406aaac8 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -20,6 +20,7 @@ void pci_liveupdate_scan_bridge_end(struct pci_dev *dev, = int pass); void pci_liveupdate_init_acs(struct pci_dev *dev); int pci_liveupdate_enable_acs(struct pci_dev *dev); int pci_liveupdate_configure_ari(struct pci_dev *dev); +bool pci_liveupdate_is_outgoing(struct pci_dev *dev); #else static inline void pci_liveupdate_setup_device(struct pci_dev *dev) { @@ -57,6 +58,11 @@ static inline int pci_liveupdate_configure_ari(struct pc= i_dev *dev) { return -EINVAL; } + +static inline bool pci_liveupdate_is_outgoing(struct pci_dev *dev) +{ + return false; +} #endif =20 #endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index f7a5e65a7c75..0b1f8d01d7a5 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -546,11 +546,14 @@ static void pci_device_shutdown(struct device *dev) /* * If this is a kexec reboot, turn off Bus Master bit on the * device to tell it to not continue to do DMA. Don't touch - * devices in D3cold or unknown states. + * devices being preserved for Live Update or in D3cold or + * unknown states. + * * If it is not a kexec reboot, firmware will hit the PCI * devices with big hammer and stop their DMA any way. */ - if (kexec_in_progress && (pci_dev->current_state <=3D PCI_D3hot)) + if (kexec_in_progress && !pci_liveupdate_is_outgoing(pci_dev) && + pci_dev->current_state <=3D PCI_D3hot) pci_clear_master(pci_dev); } =20 --=20 2.54.0.746.g67dd491aae-goog From nobody Sun May 24 20:33:27 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5FDF389118 for ; Fri, 22 May 2026 20:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481466; cv=none; b=pNZCGQeREl0gRZ5E6NWVZ7km3+VENxykmijWW/3B/L5K6OVS46gAWsoiCih7IQBCv+5SDJPAigeiMgK03/qcX86+Lc6Wy1jzWyj/4MSJYO4Q0MoQvGj2eBsJ31r+KRD7q8EmfGq86z8uC79LRDoal06U1R+i2k+L4UNsgPZy9KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779481466; c=relaxed/simple; bh=6ZVk6YJvJGNI1hdkC2SsSYmezEigbBslp8F9CBARniw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rOqv84CvXFlmngXZ3RA34kh2UrBcyFDCYoPLeQg5Yb5o+5UYkJpzOVbn98/bnNRC96EjCKAewW/dW2Hm/wqGfdxhiHhvOURGt+YorlfMV3q22hTiCAjTiY3r1bY3yzSDiEOp5Ze5C8DdkCo+1GuM8bcTOTjIWIvk33FHmj81b48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=apcKP8Zb; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="apcKP8Zb" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c8292e18166so3924528a12.3 for ; Fri, 22 May 2026 13:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779481463; x=1780086263; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jD8Dp8WjVDfBtyvW+7yZYOtj2UMzN2TZIRigqz140zs=; b=apcKP8ZbFfxk9mW1Z5BZ2RJ8HInvFGwLKvWm7oStZiScZvCS+yRmuAqKefsLHXODpt kfQzQYFv3G78oXA6ieimPMuTBOf3fquOUeTAonleDpfSopLeOLYI9Ai04tfBRV7Q5m1V xx8kMNFxrUtlCjlWgZzHHSusyZThTJq7mEQxec/yOCizDms/jQvSH1SxsiBXixNr3jGd OosnbBOcW+kDyWUbG5DVuN0Wh4e82+QM8JRHy0nFZGN84oI/Dq1/PkodTQovc9F68JDr sUvSdcDGdRZx53ddkiokKOY6y0WikVZ9qyEYaIjwtzpC1fXuKodsJnfWAFTYa9fowxBi yGyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779481463; x=1780086263; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jD8Dp8WjVDfBtyvW+7yZYOtj2UMzN2TZIRigqz140zs=; b=njsqtzY5d8Fv98BYguBeDTc8Wn1Zh5pozebNydy3XxNW3bAn7LJhzTAw9+NI1KjfFw ydPCnujlg/Bzskfyb/r7eCYQXRKuBW4HfbO5zlMrAYKZz6WWc6LmUqTjcoUgh4/nxNY7 aDH7smHu89VoAyCf3UxqVBt09l19Pdtpv0PUwyhuSPZw176VUdME9pOVLwtq5Wh31soo LU1jPsCZws+UM15lWMamFMM8w504lLlLvoW5brWIgVtsz3+KH5K24V9dtWjVNZ2CyB3S eF+nASh5iUYJNuZH0pFSuBmmuabg8cxl+olepgJjPB/sPmchR+q80S7PQT/gDu/U/6Al iXqw== X-Forwarded-Encrypted: i=1; AFNElJ/oxY63bOy6w08CS92+uEgjKJ09y111yA62gFsL7zHoCYEKuoyv1vrB+gFj7O1yjCkr3c4k2q3mOIetBMg=@vger.kernel.org X-Gm-Message-State: AOJu0Yyu+3YzJ/Hd4TymAt7a4ppH0BwTar+fPzksVQLN2DGfM3SrP+NJ poaKtelg5RfoAEPYczl4oS6X/klit5KF7bPpw38rwTTwCbsM+boxn1F6N2SpPSgYrN9SAuVw5mh mIVj+Mg1qn+eMkw== X-Received: from pfcs23.prod.google.com ([2002:a05:6a00:6fd7:b0:82f:6a57:a9aa]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:1c8b:b0:82c:7f08:8826 with SMTP id d2e1a72fcca58-8415f15b50emr4877330b3a.17.1779481462682; Fri, 22 May 2026 13:24:22 -0700 (PDT) Date: Fri, 22 May 2026 20:24:10 +0000 In-Reply-To: <20260522202410.3104264-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260522202410.3104264-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260522202410.3104264-13-dmatlack@google.com> Subject: [PATCH v6 12/12] Documentation: PCI: Add documentation for Live Update From: David Matlack To: kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org Cc: Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add documentation files for the PCI subsystem's participation in Live Update. These documentation files are generated from the kernel-doc comments in the PCI Live Update source code. They describe the File-Lifecycle Bound (FLB) API, the device tracking API, and the specific policies applied to preserved devices (such as bus number inheritance and bus mastering preservation). Signed-off-by: David Matlack --- Documentation/PCI/index.rst | 1 + Documentation/PCI/liveupdate.rst | 29 +++++++++++++++++++++++++++ Documentation/core-api/liveupdate.rst | 1 + MAINTAINERS | 1 + 4 files changed, 32 insertions(+) create mode 100644 Documentation/PCI/liveupdate.rst diff --git a/Documentation/PCI/index.rst b/Documentation/PCI/index.rst index 5d720d2a415e..23fb737ac969 100644 --- a/Documentation/PCI/index.rst +++ b/Documentation/PCI/index.rst @@ -20,3 +20,4 @@ PCI Bus Subsystem controller/index boot-interrupts tph + liveupdate diff --git a/Documentation/PCI/liveupdate.rst b/Documentation/PCI/liveupdat= e.rst new file mode 100644 index 000000000000..eba55f8a92ae --- /dev/null +++ b/Documentation/PCI/liveupdate.rst @@ -0,0 +1,29 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D +PCI Support for Live Update +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +.. kernel-doc:: drivers/pci/liveupdate.c + :doc: PCI Live Update + +Driver API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: drivers/pci/liveupdate.c + :export: + +Live Update ABI +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/linux/kho/abi/pci.h + :doc: PCI File-Lifecycle Bound (FLB) Live Update ABI + +.. kernel-doc:: include/linux/kho/abi/pci.h + :internal: + +See Also +=3D=3D=3D=3D=3D=3D=3D=3D + + * :doc:`/core-api/liveupdate` + * :doc:`/core-api/kho/index` diff --git a/Documentation/core-api/liveupdate.rst b/Documentation/core-api= /liveupdate.rst index 5a292d0f3706..d56a7760978a 100644 --- a/Documentation/core-api/liveupdate.rst +++ b/Documentation/core-api/liveupdate.rst @@ -70,3 +70,4 @@ See Also =20 - :doc:`Live Update uAPI ` - :doc:`/core-api/kho/index` +- :doc:`PCI ` diff --git a/MAINTAINERS b/MAINTAINERS index 0e262c0ceb43..6f0b0ebf67cd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20536,6 +20536,7 @@ L: kexec@lists.infradead.org L: linux-pci@vger.kernel.org S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux.git +F: Documentation/PCI/liveupdate.rst F: drivers/pci/liveupdate.c F: drivers/pci/liveupdate.h F: include/linux/kho/abi/pci.h --=20 2.54.0.746.g67dd491aae-goog