From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795041442; b=jsjdzDgJCvdxjTTvb+vJTtygOeiEhiodUCmm7UyVYfWVWtirhPH5qOD6vByN1ztrU42W r5QtjQHQLf6n4rWwWwHZOzxaJ8osImPEDrStYDnItgZlUUx7uBURdBZLzi43kjXgV/jBO +RGs5vMAW5bcVPkPctE+vyR7RN4iL5wXYkIDqSdUd2ZUreRwxpm2Rr/UK049jcF1GLhY7 LnNry8y8IL7BXCjRQvWjCIcTKYUaU6d6Q0M9fJNAqc9VgDADMLeFfB4Dcy5RznWxCoDCN tm0tWWlN4KagdkNPzzX7UZPdZg6ZuprNZvFesNVBln4FHzsLlkXPKEHkJ56Y6hSvhSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795041442; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=HNkkfP2cevkFVfIGomWPdBlTDGkki6pISPgO29QlZFU=; b=HNW8SgeBQcnmXUPt+v0otYTEBf+iGRd1TIY5nGFewpvhynN/Gw6QoS6waoZG5ug9DxS/ 0ysHdJRAw6LPRhImLuuKDq4bpf9oAhEOY5plx713P8TUO0a5Umdhsv1ps8g4cYKymAdmT VdGgpvaM8BnY0b5smgs4gKVxA7qka8IkYyoxnjRMvLSz3z1nFXCTT+nA8XwekCgErqKct poNTs0W9/30YQIo5p3sEhEK2/6hIphaE526yhKVLV8MRZcVgngHlphNM09JHJ90cPABbT 2vYxGApiR4HW7Id+xVjrhF/tQPhmaeU5sObmnr817mGMNnKp1MizVxpC6grvlWp5ddg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=GKZ3TwgD; arc=none smtp.remote-ip=209.85.167.200 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4025760A382D for ; Wed, 18 Nov 2026 22:37:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4025760A382D 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.a=rsa-sha256 header.s=20260707 header.b=GKZ3TwgD Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-5384e381fbbso1172151b6e.2 for ; Wed, 18 Nov 2026 14:37:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795041441; x=1795646241; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HNkkfP2cevkFVfIGomWPdBlTDGkki6pISPgO29QlZFU=; b=GKZ3TwgDVpOhVv4K2Yl13YrEs3+5DcsK77RtcT2ZRw0y8zVT5a0R5AhqhOKIk1j5ac tq5L9VkTF9MK6W6KHgSaIupcuMsIMzB3Na3ESPZwp6MToNsCjzpG1mW9dnC6Q+0gzNig jiXgITzuE2ymGwiba/4S1Y60bbqifLP1j4UnMWrgxi7BeujxYwkqounc2/WBn/tov4PI taSelONdCawtt1M89XTOAaOxsLuNSIwvCNi6OLlDmLyg8C8OXGGcCwB5eFd40MKscY8s W9u2s6MxvtoeHnzU3ngfvlCArrNipao2cgGFLBGFv14hi0CZOVyllYCnLhdJw+XsDu5V WL6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795041441; x=1795646241; h=content-type: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:content-type; bh=HNkkfP2cevkFVfIGomWPdBlTDGkki6pISPgO29QlZFU=; b=X/KDygQ5nDaCNou/cZjbcUcGVwMSe/vl3h+JLCIsqBP09GkUSiBAGUDIiUnUbIglCr yaOsZ1VyMa3Q3qWoXrNR52AMXPeiCxuZvBWw5rRRuwLJH9wmw/2/LlAm20mFbUNuuV0x BIYWcOhn4Z/t/R2iXMlpZX7ghAJTTe7qbmecj1Rvo/F5KmOgaVlCm4uA3lZ2qjUGycLi hJkBDKjlo0r4LX8w0mNeuTqAXaKKGAEIXnVZs9oAopmo0PlahGTiRSmRyKp9BCSz1s0e 3vY4FiVOrJXzxB6Dcar/FGKVC80rnaOA64HbzQk/lbEx4n3UTO3BoZOPGLEWA+Bqhkyb olwA== X-Forwarded-Encrypted: i=1; AL+hErFk3sTRk6DHWRYppgtvJXdN0J8EQXPEZV6V2+IGAerlhrMnHKtUGo0A6ZquoVrOjH4VtTRgf369310=@vger.kernel.org X-Gm-Message-State: APuU4Z+syc3hw2mUZBizHhlvdZExJjk2QYu4XLYmKZO3l86owgRK+qGs sqOn/M7mxpSAgtn0CNKwC3q+RIFlCJnsTp/CKsW05hBPErWWQjsKbWr3kzc5fg9aDdDD0Pa4spz B63mW2OXxb1BeCQ== X-Received: from ilbek7-n2.prod.google.com ([2002:a05:6e02:4f07:20b0:549:da41:90bc]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:3385:b0:4c4:9f7e:92ce with SMTP id 5614622812f47-57741723d34mr4740022b6e.38.1795041441133; Wed, 18 Nov 2026 14:37:21 -0800 (PST) Date: Wed, 18 Nov 2026 22:37:02 +0000 In-Reply-To: <20261118223704.3286085-1-dmatlack@google.com> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261118223704.3286085-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.1.708.g77570a6a1d-goog Message-ID: <20261118223704.3286085-12-dmatlack@google.com> Subject: [PATCH v11 11/13] 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 , Alex Williamson , Bjorn Helgaas , Chris Down , 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 , Randy Dunlap , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , William Tu , Yi Liu 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. The PCI core freezes every device in pci_device_shutdown(), not just preserved ones, so that no device can be preserved or unpreserved after its shutdown starts. Signed-off-by: David Matlack Reviewed-by: Pranjal Shrivastava Reviewed-by: Pasha Tatashin Reviewed-by: Samiullah Khawaja Reviewed-by: Bjorn Helgaas --- drivers/pci/liveupdate.c | 19 +++++++++++++++++++ drivers/pci/liveupdate.h | 5 +++++ drivers/pci/pci-driver.c | 2 ++ include/linux/pci_liveupdate.h | 3 +++ 4 files changed, 29 insertions(+) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index a45ad86370d5..e26d2f5c2338 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -126,6 +126,9 @@ * * The device cannot require device-specific quirks to enable Access * Control Services (ACS). * + * In addition, a device cannot be preserved or unpreserved once the PCI core + * has started shutting it down (pci_device_shutdown()). + * * Driver Binding * ============== * @@ -520,6 +523,11 @@ static int pci_liveupdate_unpreserve_device(struct pci_flb_outgoing *outgoing, { struct pci_dev_ser *dev_ser = dev->liveupdate.outgoing; + 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; @@ -569,6 +577,11 @@ static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing, return -EINVAL; } + if (dev->liveupdate.frozen) { + pci_warn(dev, "Cannot preserve device after it is frozen!\n"); + return -EINVAL; + } + if (dev_ser) { /* * Endpoint devices can only be preserved once. Bridges are @@ -784,6 +797,12 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev) pci_WARN(dev, 1, "Destroying incoming-preserved device!\n"); } +void pci_liveupdate_freeze(struct pci_dev *dev) +{ + guard(rwsem_write)(&pci_liveupdate.rwsem); + dev->liveupdate.frozen = true; +} + static int pci_liveupdate_finish_device(struct pci_ser *ser, struct pci_dev *dev) { if (!dev->liveupdate.incoming) { diff --git a/drivers/pci/liveupdate.h b/drivers/pci/liveupdate.h index e1c1d2fa00e4..03211dbebc7b 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_preserve_bus_numbers(void); bool pci_liveupdate_refuse_bus_numbers(struct pci_bus *bus, struct pci_dev *dev); int pci_liveupdate_adopt_acs(struct pci_dev *dev); @@ -31,6 +32,10 @@ static inline void pci_liveupdate_cleanup_device(struct pci_dev *dev) { } +static inline void pci_liveupdate_freeze(struct pci_dev *dev) +{ +} + static inline bool pci_liveupdate_preserve_bus_numbers(void) { return false; diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 7efe808cdf0c..8b11bd3dc5bc 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" @@ -559,6 +560,7 @@ static void pci_device_shutdown(struct device *dev) struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_driver *drv = pci_dev->driver; + pci_liveupdate_freeze(pci_dev); pm_runtime_resume(dev); if (drv && drv->shutdown) diff --git a/include/linux/pci_liveupdate.h b/include/linux/pci_liveupdate.h index d45a5b524909..bb79348769b7 100644 --- a/include/linux/pci_liveupdate.h +++ b/include/linux/pci_liveupdate.h @@ -21,11 +21,14 @@ * set up, i.e. it was matched to state preserved by the previous * kernel. Unlike @incoming, this is never cleared, so it stays * true after the device finishes participating in Live Update. + * @frozen: True if the outgoing preservation status of this device is frozen + * and thus cannot be changed. */ struct pci_liveupdate { struct pci_dev_ser *outgoing; struct pci_dev_ser *incoming; bool was_incoming; + bool frozen; }; struct pci_dev; -- 2.56.1.703.gf848ed807c-goog