From mboxrd@z Thu Jan 1 00:00:00 1970 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 C8C983C13F5 for ; Thu, 23 Apr 2026 21:23:39 +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=1776979424; cv=none; b=S/MpqdBaUQE1K+C6IwqnJzHmP4x5+sDCND8rUM50AiXwdvCEVhTbjSoYcWm8jcV7CzjDt4wKCCR09tCgLYVmxlrRXWs6aVewphRwqNAd+ZcNhS0YbFGK4a1+iiScbp2V3AFivKNgXWkshNomBOK06i3tG4durDIGrBjLONkUllc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776979424; c=relaxed/simple; bh=Oe8MwOihG5BzjH99EK3y2Iy4j4M/3j0maoUzCe5H9s8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WnOt7hKJlGrAxboFoO1iNx0z1H8gJzCq+4aaWt1eVnM36aFmzoeok+lAhWBMAeocYML4do0y7QDHmGMD8HsyGTMqP4//fXWvgZuKizEjG656Qhy2C/mJkI59EKXi5NjEOMn4XxrlwM68zS15sM/MTTAp2JqfwI/EEutM7eOR+6w= 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=S6Yg/35I; 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="S6Yg/35I" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2b242b9359aso70728535ad.0 for ; Thu, 23 Apr 2026 14:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776979418; x=1777584218; 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=NDSmr3KzvFf45fqXLLacm4Nig+LS/n/kl38OHtIvfGo=; b=S6Yg/35I+BOb4hlpM7fzMitlnY4VsnIm8RupHp0/S0Bs1Bi9GhkNJoPAuow9rzY+vH ustao6je+FQe+CEwUTr/JgUaCeehxRbwLbaVcupthpdSpZ4L7kOgB0UTvQvU5etRR3HD QCsLDtGOo1VZs8zLzhUlPdHdPb1ZnbqF59ZDdaYRnQ8Iaa7TT7t/ZPAkjoVqxbSrPbaH oyCaNehedELWVERJ+buwkQvhjc5g4shwm4F3SHsZ/z/RPjcn778jZ6amThx8037XTcGD wQrcfJUCLw8Ej5pzHTOhkTLs+9H/Rwet4hCqtrsK+HFlyKW24P2T2BzKgGGYE++mGss+ uQ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776979418; x=1777584218; 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=NDSmr3KzvFf45fqXLLacm4Nig+LS/n/kl38OHtIvfGo=; b=ZrBu5KhZE/rsWLfDevN4gzM7VPVoRlgHvbYmVtuwEaXDxPR2lHwNAKBhvU0YiJYsHD GaeFUpKNY6QUAbJ4JRSi2qs/JfFAQAH0ZBXJa2cM9UyCcOXQ83R8puv5WBG9vd12xqbl YeEzftQXYTvyOgbt0uxDTthjWj4NW0u7kJ0GjDbrbg6agyCTXkdhzv/ZFWXaHDfhubzY bX1gLNyXnEBFmRUccCErU1OjSM82b79xdrfV/FMa7srOqCvpKvfctSbLIgdLKn3JRjIy rxJjLxT+CcG6ZkvJSBLEVRYTlLyG2FTk2+91up19yBhPYWmSChGpX6dwHEUAhmeuC09x Fn1Q== X-Forwarded-Encrypted: i=1; AFNElJ+fFg4JYyMl24HA/i0LB353VV0AC1ywO90EG35XppOdY7kncLQRoSvUaYlWor9n3nuaT6ZtUcAqAie3B0o=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5ncdzawM/TUTaGYuR6m1i6FkfHiqRsnGk58HY3UkU7RmPT3Cs w5dc73F+wukYvbSpctQpjhaF9WQZe/UT84iF/6y+sYXqGi1tLbtMymvQZS2/vwZ08KrTsCSx6f1 zTFsAS0m846OTNw== X-Received: from plov1.prod.google.com ([2002:a17:902:8d81:b0:2ae:c54f:d5ad]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ba94:b0:2b4:5c0d:314b with SMTP id d9443c01a7336-2b5f9f83342mr210260195ad.38.1776979417788; Thu, 23 Apr 2026 14:23:37 -0700 (PDT) Date: Thu, 23 Apr 2026 21:23:14 +0000 In-Reply-To: <20260423212316.3431746-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: <20260423212316.3431746-1-dmatlack@google.com> X-Mailer: git-send-email 2.54.0.rc2.544.gc7ae2d5bb8-goog Message-ID: <20260423212316.3431746-11-dmatlack@google.com> Subject: [PATCH v4 10/11] PCI: liveupdate: Do not disable bus mastering on preserved devices during kexec From: David Matlack To: iommu@lists.linux.dev, 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 , Joerg Roedel , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Robin Murphy , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Will Deacon , 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 minimize downtime and 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 | 4 ++++ drivers/pci/pci-driver.c | 31 ++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c index 25c86cd4c173..2a4a139623a6 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 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 outoing preserved devices + * during kexec. This allows preserved devices to issue memory transactions + * throughout the Live Update. */ #define pr_fmt(fmt) "PCI: liveupdate: " fmt diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index d10ece0889f0..05584bc76332 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -531,6 +531,27 @@ static void pci_device_remove(struct device *dev) pci_dev_put(pci_dev); } +/* + * Disable bus mastering on the device so that it does not perform memory + * transactions during kexec. + * + * Don't touch devices that are being preserved across kexec for Live + * Update or that are in D3cold or unknown states. + */ +static void pci_clear_master_for_shutdown(struct pci_dev *pci_dev) +{ + if (!kexec_in_progress) + return; + + if (pci_liveupdate_outgoing(pci_dev)) + return; + + if (pci_dev->current_state > PCI_D3hot) + return; + + pci_clear_master(pci_dev); +} + static void pci_device_shutdown(struct device *dev) { struct pci_dev *pci_dev = to_pci_dev(dev); @@ -541,15 +562,7 @@ static void pci_device_shutdown(struct device *dev) if (drv && drv->shutdown) drv->shutdown(pci_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. - * 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)) - pci_clear_master(pci_dev); + pci_clear_master_for_shutdown(pci_dev); } #ifdef CONFIG_PM_SLEEP -- 2.54.0.rc2.544.gc7ae2d5bb8-goog