From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 CC636479876 for ; Tue, 28 Jul 2026 22:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785276641; cv=none; b=P3gDArjxun+EiDbbKi6sAaEP1gPLy8e90I9A5OPbgNewEBYWsN8SbXzcZvHoN0nDsxzIB81P4FwVfO+zQrqdi8iIFhScTaYVbl2izUnY5yctqf5aB6pVrWvnJzIjwzIZoZUewpVXZBQNI/VKGjwwrorlcgH/bnEjQwiuK+BCosc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785276641; c=relaxed/simple; bh=Id2EXN7u2JnUsjGrJCRWIUKTzOIUMuw+FP7kXvrtnNI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LquCU1HvU4xkFSrY6CXc0vGWLkEg3op2Mb1AqAqh+5NGHm4h+PvoIu0OrrmVof788cO1BBrI6r6IFjN6dU3njFRiWZ6D72G+3BmsrX/92x2UKacpQfaBIh8oTRENDgsPJDS8YsA/DrueLc2GTo0fcDWwSkQHdrgh0DKfz+KTJEM= 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=dRCnojzg; arc=none smtp.client-ip=209.85.215.200 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="dRCnojzg" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-ca860baea9fso469542a12.2 for ; Tue, 28 Jul 2026 15:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785276630; x=1785881430; 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=kK9fmvYx94bqGyeMgzsYcbMKuj2faWTY3fQuvgNhZiw=; b=dRCnojzgIDKPrUZUb36s/nqtCtg/XYVHuwMDW6N1zz2WK866dkOkDVZIfgrfTiK4PC /5LiL9YsdwxeyDewRtyOHZ8rir5ZqhWb7YXMUcAqQ2jzkxHZ/0eKryTsCIAkrEJoSZz1 asNC3zafr3wFITPIfDhNCcUOClJPAygW8Am0z42jbKcP4LFOlT/tzw2lA4tpBokiya0p ZXznd0prnqxeSFL/TE7K/nZmV+MrTqhAG1A7Qc9fhTTWRNsxUul7QZYG25vZwsHc5HuQ 4oYtwpYKDcUreWsG/hzSXbNlHew1kd75CE6ksitCcbCX3VGISSIJDvTTa3ZA51y5FsU/ n4xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785276630; x=1785881430; 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=kK9fmvYx94bqGyeMgzsYcbMKuj2faWTY3fQuvgNhZiw=; b=C4jCv+Tr5bQ7h7s+1NeyMLx42a2LJwjr1BetzDhseoMgN7B2UgwOi/EM5I7IwfkBe8 srkwQwwvdr/hJrlS94YKUMIVT36esKpVtIvg/4AnWQGq77EP4koAmOo0KL/j8N6vj1qq df3k+8qrV9jDs5ds9dUdZ3toujq7COj/TyRuf2W2WW8UItei/DL/wQbMaBeTaOcBbgAO Ao/0Qc3RpM9YpaEHymPDlNhO5DnK0SKCo2dmbAyCzJSjiuWP1fduFVmkDc7f0nQwjEYY 7ubaygjXLV+PHorTDhh8LxMZmg/OotalHBcGQ633Gbkpctz9k19uObcNto9c0AjA6/WD bVDg== X-Forwarded-Encrypted: i=1; AHgh+RoBrgT+AFZvRlV9z1tLHAXA/LliM/hc2J4ZanCGVmx6nPYiTMd847xAVA0KrLko54zgDWtgkbRcBCCndeE=@vger.kernel.org X-Gm-Message-State: AOJu0YxLMMKYbYApkCZEcrwq5Y63Nyg2MADioJBDyryk8gTeVDYmI/Yd hCpGMOd0uqtTAKxtBr4tcjoEPL18tpJS7/eflxqIprxZOxg4kpGcwmWDPSRpljA1yIwGyfAUT8w KyQ+k0QuZwTfTkQ== X-Received: from pfik11.prod.google.com ([2002:aa7:820b:0:b0:84e:40d2:2e74]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:39a9:b0:845:3914:f039 with SMTP id d2e1a72fcca58-84e93203c18mr4669411b3a.26.1785276630227; Tue, 28 Jul 2026 15:10:30 -0700 (PDT) Date: Tue, 28 Jul 2026 22:10:05 +0000 In-Reply-To: <20260728221007.2098560-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: <20260728221007.2098560-1-dmatlack@google.com> X-Mailer: git-send-email 2.55.0.487.gaf234c4eb3-goog Message-ID: <20260728221007.2098560-12-dmatlack@google.com> Subject: [PATCH v8 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-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). Reviewed-by: Pranjal Shrivastava Reviewed-by: Pasha Tatashin 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 65bcecb1b64e..32b73ebf71f7 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -132,6 +132,10 @@ * * The PCI core adopts ARI Forwarding Enable on all bridges with downstream * 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 devices + * during kexec. This allows preserved devices to issue memory transactions + * throughout the Live Update. */ #define pr_fmt(fmt) "PCI: liveupdate: " fmt @@ -879,6 +883,13 @@ int pci_liveupdate_adopt_ari(struct pci_dev *dev) return 0; } +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 unstable!\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 49d07fd02132..9c31fb60207d 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); void pci_liveupdate_cache_adopted_acs_controls(struct pci_dev *dev); int pci_liveupdate_enable_adopted_acs_controls(struct pci_dev *dev); int pci_liveupdate_adopt_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) { @@ -55,6 +56,11 @@ static inline int pci_liveupdate_adopt_ari(struct pci_dev *dev) { return -EINVAL; } + +static inline bool pci_liveupdate_is_outgoing(struct pci_dev *dev) +{ + return false; +} #endif #endif /* DRIVERS_PCI_LIVEUPDATE_H */ diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 51616e4327d3..47cb3dcaa927 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 <= PCI_D3hot)) + if (kexec_in_progress && !pci_liveupdate_is_outgoing(pci_dev) && + pci_dev->current_state <= PCI_D3hot) pci_clear_master(pci_dev); } -- 2.55.0.487.gaf234c4eb3-goog