From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CC4CC44508 for ; Fri, 10 Jul 2026 21:26:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Vh0w4YZ9EkCKSJvWXCxWBgNBQIG8ERULbiy01R/Xx2Q=; b=3pHUOjF4RcdpkZc5/a/4aWrVkF i1agabkMY/R1tZsRa8xu/OZ7dxlkr0B5AdlYLobC6LSPiSiXop8pjREyxr/ksFpgm35Pm7GXr/Wnm dGiGbRqogtSrHYP+m05GHQYP4gHxUpTUFz8F1yuRUgrdxZQtvGlJFDArnQUpWKXjaBEezu7aVTDj1 e2AwF564vG/wrm/X3HZwB6DapMuOAzk+Z3nQSKTIMk1NL+8ygAGJjoUb8BLuKbLfCz2k1QTq+v/Kk 2pVswL7qG7W3QWVwoZ8kbAdc0uNf+MG15ZGQcGCkugFvo6+Vh9STWw1+/HwDBcDYMxTra+Opl5gHh Ys+LrKkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wiIk1-00000005pYo-0VSb; Fri, 10 Jul 2026 21:26:37 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wiIjw-00000005pR1-2kDx for kexec@lists.infradead.org; Fri, 10 Jul 2026 21:26:33 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-8423f544944so1111674b3a.3 for ; Fri, 10 Jul 2026 14:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783718791; x=1784323591; darn=lists.infradead.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=Vh0w4YZ9EkCKSJvWXCxWBgNBQIG8ERULbiy01R/Xx2Q=; b=AIgoxio2Atrq0sIqYY9ALAS7oWpCi8AKxWYtWpWVJXCG2Y6MjRv7LvEhg8GwPc53Zx 8MVe9q2MpiMCTW8fKLN/VjlCDFWGFkr+x3SQdqrS2kNHqWxYxOjVAcnupcq5FzLF6wnj cFPtx3jqMIr2c+SlRGeERE4vhKOlZUrpzft2noLacbMbgmniy2J/SMTHZzbwGqqwXD3L udo4TIXB39w6w3+7hQuGh5+pjPj08ZFK9oUJIT9xrAlmpq5PjEEVUDbbZLQUbb3zYbP3 0U9tMfsILMxDDl47xZmVa5xvgQ0D9n4PbyK5PYyfhZIh2IA/UYnISsek+kDjQTd0TGGF YurQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783718791; x=1784323591; 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=Vh0w4YZ9EkCKSJvWXCxWBgNBQIG8ERULbiy01R/Xx2Q=; b=M8z1pH37ZMK4PHogp74MIk6ze00gBOJSw/DsS/xUz2kzVVhZsBAhfqXKUBdbpOE2Pr WITJ+HBxmAmHC8/2ZYISyXqGtkPgcLEAxyiEKAnChkZfSuW7MnjOZdXBd6EjhHTV3n72 mxN/ufeQzZSWBRWruhtAVrgHMuzEmU4QmCi/b2P7QYdLvi1r3k2g0vEdGbzJm46JTsbK e9QqM/Qw22yYKcwzvP05co78YoKdNNWTG79n2bNnm2YquW+di4ykpOQZtseBHtMUX5oh mpxtHGDNQqTFUT1j07cbc3wBg0pZVt5/DCmhJYal5HgceIOY/X9oVRfrOKrs0rmTmz2F eQnw== X-Gm-Message-State: AOJu0Yzy3e/DxKfemW67HBjsuG7Sccnf+8T7sZkQkywsjuR2TAhIWp86 BmMfAkPtmyGJXpVU7UJHatQ6QarIdYRHE/kv3pWOuj7fJbE0Gy4ySAN3wYygo0ETmZXQjfugA6N 7lvIFjjJaiF18wPmnQNLCMhPacxu6YDLG9Ww4jCQY2ast5tgyf8LnBPNZRn8PE1z46Hb1VE6H5e 5vA09wYaZ10QfmVMDv7Y4X456O54Kl+L4wsByEFS+C9ybsKPxCzBU= X-Received: from pfbfe24.prod.google.com ([2002:a05:6a00:2f18:b0:848:401c:994]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:14c3:b0:847:9c06:2bef with SMTP id d2e1a72fcca58-8488971669emr605929b3a.29.1783718791168; Fri, 10 Jul 2026 14:26:31 -0700 (PDT) Date: Fri, 10 Jul 2026 21:26:13 +0000 In-Reply-To: <20260710212616.1351130-1-dmatlack@google.com> Mime-Version: 1.0 References: <20260710212616.1351130-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.795.g602f6c329a-goog Message-ID: <20260710212616.1351130-11-dmatlack@google.com> Subject: [PATCH v7 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-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260710_142632_701132_6B8711A4 X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org 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). Reviewed-by: Pranjal Shrivastava 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 74a11e520f0d..64052892ea84 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -352,6 +352,11 @@ static int pci_liveupdate_unpreserve_device(struct pci_flb_outgoing *outgoing, s { 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; @@ -422,6 +427,11 @@ static int __pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing, s static int pci_liveupdate_preserve_device(struct pci_flb_outgoing *outgoing, 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); @@ -713,6 +723,12 @@ void pci_liveupdate_cleanup_device(struct pci_dev *dev) } } +void pci_liveupdate_freeze(struct pci_dev *dev) +{ + guard(rwsem_write)(&pci_liveupdate.rwsem); + dev->liveupdate.frozen = 1; +} + 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 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) { } +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 f36778e62ac1..51616e4327d3 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" @@ -536,6 +537,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 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 previous * kernel. Unlike @incoming, this field is not cleared after * the device is finished 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; @@ -31,6 +33,7 @@ struct pci_liveupdate { u16 acs_ctrl; bool inherit_buses; bool was_preserved; + bool frozen; }; struct pci_dev; -- 2.55.0.795.g602f6c329a-goog