From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (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 65B6E51DDEF for ; Tue, 13 Oct 2026 16:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791908753; cv=none; b=Ps0+kob3PpwuQ1V+Y/MHUY6uYjXhcvxndqvSl4gnt6DISE6h5+6jJSsXMJvSIzKwpzIDkFRpMAM6deVS2x1aLK7fdY+XN7Xgwe5A8nwQgYY1kwOq6sfYU5ZzxHx1IoreHZOoWnI/CJCzVVYO7KJmjjVB4DmuOMM2aZu6krmGDFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791908753; c=relaxed/simple; bh=nhzSFAfNWlHwihhSycSS9aSmYrWooZzpcArnEryhqEo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mxpcJSeOYixYvNUhqNnTUPt+vJv7+FZDFhLMtzLOukszPwq3tAOcjoQCDoZjxwSqohVtD3QmiBoux1qbGVJyZwq8TPGTqUMQErlH8MjtCxUvRGxndMi0Z3zppZcxSf34g54EqBNVoGmZYymCixneJuAw9bgk2yqq9DKrL0c3AeM= 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=oh1YQ81i; arc=none smtp.client-ip=209.85.214.197 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="oh1YQ81i" Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2e60bb65626so33698635ad.0 for ; Tue, 13 Oct 2026 09:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791908749; x=1792513549; 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=GUqD4Ux5OAYgjaajPXSrWaI1PYIhs/xbAlAZjVaS8QQ=; b=oh1YQ81iVaN8c2Ny0ZzElnXcKhWQEDc3ZvgguP8rQRnjPumw0SDdV/wNolDPzMFkTw jRNYdMNnmg0O8PYjzr1uHX/mWgC3EW/ZPtMPmkqWxchv/6ydB7npte3iD5tQZPpuKrmp ceHiNu9P9Wk9r9/aN7VIhzv55LU6vgYx+YUm+aF42RvNX207zI7xgs8ZZAW7zaZWR/HM Fz/iIX0tn7h3dSZuDeAWyNWbe6aGe+zaBnZW2Ks2EPNBN5g1HUABwlHwqjYKvf5WgYJC ZHP87Q+8jAEbnqJWpCh7rJvadEM5oYmGWAzj9cFBwhy2E/92BoSvfP+S8xczH7OMrV/4 9Ogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791908749; x=1792513549; 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=GUqD4Ux5OAYgjaajPXSrWaI1PYIhs/xbAlAZjVaS8QQ=; b=zZlw7p+s/DmI4tWUlqq4KDzmlpGd8HeOiVoqoFY++XPLUAM1ScaSo0OfKH3+Dn64JE 7zSHUbIOdrXEPDqxrPlp2dKh2vfvqGYe4CDihOjgKA7n0V8sCnHj0IhPCgcMtzRmauiX RrRiLB+GxvmfBGnSHs+y3M05WWujudXKiFca10IvQu4HRzC7pSgHzyKm/c9x16eUF4hM kK4WgGJg2GnY2jeoeSHs3RkU1lRdXgugfyHSMfA8uMkX+a+rqqbkYck5QpQNJsoQho2X IIijncBn4VSoYcEre5xbAHB/R8wJnry+riCdoPv635APiF9e2Yb4ir+T+NR1Ek7B8XIL 0lEQ== X-Forwarded-Encrypted: i=1; AKwUvBzm+n798bYMTXgHkzA06pAsqTDEd6n0GhBtLHUWVlui7QqDhUVsgcNCo9xkzEP9V+xwc0O667p4wOY=@vger.kernel.org X-Gm-Message-State: AFq9FYJrQ/yEQ7CUGIF7D1MwHTT9b78U3F6WJNr87XQlS9I32BzKa9kk Q9C7/Lnfm+o4WYmSb3AT7Zed6pzEX/Y0CBE4O1Bbh6mJLxjXrD02FyiLkqahialv66fipUY3M9+ 4mqSGwrQuqICBjA== X-Received: from plbg2.prod.google.com ([2002:a17:902:d1c2:b0:2e8:31af:11b0]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2305:b0:2dd:ad73:5b56 with SMTP id d9443c01a7336-2e842cd12bamr86769775ad.17.1791908749286; Tue, 13 Oct 2026 09:25:49 -0700 (PDT) Date: Tue, 13 Oct 2026 16:25:28 +0000 In-Reply-To: <20261013162529.1928093-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261013162529.1928093-1-dmatlack@google.com> X-Mailer: git-send-email 2.56.0.385.gd3acb90ef8-goog Message-ID: <20261013162529.1928093-13-dmatlack@google.com> Subject: [PATCH v10 12/13] 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 , Randy Dunlap , 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 Reviewed-by: Samiullah Khawaja Reviewed-by: Bjorn Helgaas 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 38b7815fe7d4..6f92d4ddca2b 100644 --- a/drivers/pci/liveupdate.c +++ b/drivers/pci/liveupdate.c @@ -193,6 +193,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 @@ -973,6 +977,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 5aac19f7bee6..333ddd8f36c5 100644 --- a/drivers/pci/liveupdate.h +++ b/drivers/pci/liveupdate.h @@ -18,6 +18,7 @@ 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); 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) { @@ -51,6 +52,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 dff60a03204f..c1ac2ef025e2 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -569,11 +569,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.56.0.385.gd3acb90ef8-goog