From nobody Thu Apr 2 22:03:12 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 5D4173876BD for ; Mon, 23 Mar 2026 23:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310341; cv=none; b=VdvyfWQY7QdkDltjfWhuwC5fyQTTv5dADxxI6j9aHa9hXr23CxaJ734n4X0DIR7R/JbNlBBkHExoZzQ8yDk0BpWMYcWyXLCXWPeXpxh7PRZhD3PEIjQ4hPV+NAiCae4Cwv+VHsQNhEBUzGP0UPpWGNS1xuppGvefXobaUZhGjto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310341; c=relaxed/simple; bh=YnyFu7Hq5DfkB2TP1cJWlWPeBT9cbNudoys76NodHZs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=d/S6dfV8KGJw0sPQ2vh7JonozvfE++7zUISQ9fXgIUZft6RAiKdXorGf8a5xsPWmnJGm+7jkDFDiX4k6X/yKtT7fuALV4MWVCZmRrWNC7Spjxg6/Ul2g9tWl6WkX3wIvqf2qSn/ybT8lZMShwKoNJsMQPpUI7ztyAI51XDc5qMI= 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=qHoH3/1q; arc=none smtp.client-ip=209.85.214.202 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="qHoH3/1q" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2b069bfa817so8365915ad.3 for ; Mon, 23 Mar 2026 16:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310339; x=1774915139; 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=WDvzsZ/wW7otbfhEhu+LWvOHypwI+AXZcNsT2i6QVdU=; b=qHoH3/1qrDc4Llk2/CjdmQ5F+FP364nEtKTdWQnSA+Aq0mjTS3KiiMBqQO0aD2IxfT 30/YPj2MJMudFABAIgGABWxSqdZb5XGCiqA8tfS1fiIizdebEV3Y0m7+5ekOMFvObXAK JhxaUbgiscB1Y/CDHuSYXdlq4HcKBvhIObzPEI3KqKJ/T/58WPh+GbKtzqjqpZQ/Wbi+ C98iu1eBMhTS+rv0QwtpnBtghxO0T96RWnpX1jdzdIKBySG7n7RUj2p5E98wLt9HVuFP B659dpJf4RXvE8TL6eiUFzkUGtX/K8Covb94i0raIgP8Zh1jxaIXDYHGtrw1SR0795ON cgXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310339; x=1774915139; 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=WDvzsZ/wW7otbfhEhu+LWvOHypwI+AXZcNsT2i6QVdU=; b=TKtlTaHGUup/1r7ZoiYU2OAZHs8fMLErWt+5Hd6Q57UFii2kLhBEaOBaVCNBn8WTcP D22qFqDbaV+ur/tm/BUYJxUPi/x8CziCq7jsawAgaVc/SayI1d7BKa03PuYebjcVsdkN djTVPl+krNIwEG5G9lBY1f3jUWMe5q0ajnB3TAS//g3tnzWCZ/CrqK3b5Qvttkei2FDC GvoRtH19YLa3dyzsabgkQsR0QOlxIQqv6l2IX/Byj83HoOuY+OWD8Aq5NiA9KZ8VLDvR r+xEG4y1n7mQdx5pYKCpOmhbhlHr2ZjNzmV6zoq9Z0XNRORnGbF6DjF8yrhIvKd/+kU/ V7Zw== X-Forwarded-Encrypted: i=1; AJvYcCUNYAldfC6ICB+DYt1ppfj8zuY8vHFNMwnNBFUMHLUnov/Xj8mTkd5+E2LVcz6/E0wHGrMv6x+nR7NE0vc=@vger.kernel.org X-Gm-Message-State: AOJu0YwYJVGiWLycomdMHU9UCs8iii3S9jaSc/u01/z3hXa6xiQF8+/i Z5fUV3jSzbpinUidcjxxUYkuLaNA33AhKY8rr89T5ynFKl9BR+wuS0mFCcS6kBfpHz240VUMF0K eE0d0t6gXrjcCyQ== X-Received: from pldt15.prod.google.com ([2002:a17:903:40cf:b0:2b0:59ce:931b]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1c7:b0:2b0:5fa5:a68c with SMTP id d9443c01a7336-2b0826b9030mr140489925ad.9.1774310338569; Mon, 23 Mar 2026 16:58:58 -0700 (PDT) Date: Mon, 23 Mar 2026 23:58:04 +0000 In-Reply-To: <20260323235817.1960573-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: <20260323235817.1960573-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog Message-ID: <20260323235817.1960573-13-dmatlack@google.com> Subject: [PATCH v3 12/24] vfio/pci: Skip reset of preserved device after Live Update From: David Matlack To: Alex Williamson , Bjorn Helgaas Cc: Adithya Jayachandran , Alexander Graf , Alex Mastro , Andrew Morton , Ankit Agrawal , Arnd Bergmann , Askar Safin , "Borislav Petkov (AMD)" , Chris Li , Dapeng Mi , David Matlack , David Rientjes , Feng Tang , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Kees Cook , Kevin Tian , kexec@lists.infradead.org, kvm@vger.kernel.org, Leon Romanovsky , Leon Romanovsky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Li RongQing , Lukas Wunner , Marco Elver , "=?UTF-8?q?Micha=C5=82=20Winiarski?=" , Mike Rapoport , Parav Pandit , Pasha Tatashin , "Paul E. McKenney" , Pawan Gupta , "Peter Zijlstra (Intel)" , Pranjal Shrivastava , Pratyush Yadav , Raghavendra Rao Ananta , Randy Dunlap , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Vipin Sharma , Vivek Kasireddy , William Tu , Yi Liu , Zhu Yanjun Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vipin Sharma Do not reset the device when a Live Update preserved vfio-pci device is retrieved and first enabled. vfio_pci_liveupdate_freeze() guarantees the device is reset prior to Live Update, so there's no reason to reset it again after Live Update. Since VFIO normally uses the initial reset to detect if the device supports function resets, pass that from the previous kernel via struct vfio_pci_core_dev_ser. Signed-off-by: Vipin Sharma Signed-off-by: David Matlack --- drivers/vfio/pci/vfio_pci_core.c | 31 ++++++++++++++++++++++---- drivers/vfio/pci/vfio_pci_liveupdate.c | 4 ++++ include/linux/kho/abi/vfio_pci.h | 4 +++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index d7c472cf4729..849a3b57d56b 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -494,6 +495,30 @@ static const struct dev_pm_ops vfio_pci_core_pm_ops = =3D { NULL) }; =20 +static int vfio_pci_core_probe_reset(struct vfio_pci_core_device *vdev) +{ + int ret; + + /* + * This device was preserved by the previous kernel across a Live + * Update, so it does not need to be reset and reset_works can be + * inherited from the previous kernel. + */ + if (vdev->liveupdate_incoming_state) { + vdev->reset_works =3D vdev->liveupdate_incoming_state->reset_works; + return 0; + } + + ret =3D pci_try_reset_function(vdev->pdev); + + /* Bail if the device lock cannot be acquired. */ + if (ret =3D=3D -EAGAIN) + return ret; + + vdev->reset_works =3D !ret; + return 0; +} + int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev =3D vdev->pdev; @@ -514,12 +539,10 @@ int vfio_pci_core_enable(struct vfio_pci_core_device = *vdev) if (ret) goto out_power; =20 - /* If reset fails because of the device lock, fail this path entirely */ - ret =3D pci_try_reset_function(pdev); - if (ret =3D=3D -EAGAIN) + ret =3D vfio_pci_core_probe_reset(vdev); + if (ret) goto out_disable_device; =20 - vdev->reset_works =3D !ret; pci_save_state(pdev); vdev->pci_saved_state =3D pci_store_saved_state(pdev); if (!vdev->pci_saved_state) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 8d6681e1d328..874c821bf6eb 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -91,6 +91,9 @@ * kernel guarantees the these will not change across a kexec when a de= vice * is preserved. * + * * Whether or not the device supports function resets. This is necessar= y to + * avoid resetting the device after kexec to probe for reset support. + * * Since the kernel is not yet prepared to preserve all parts of the devic= e and * its dependencies (such as DMA mappings), VFIO currently resets and rest= ores * preserved devices back into an idle state during kexec, before handing = off @@ -162,6 +165,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupda= te_file_op_args *args) =20 ser->bdf =3D pci_dev_id(pdev); ser->domain =3D pci_domain_nr(pdev->bus); + ser->reset_works =3D vdev->reset_works; =20 args->serialized_data =3D virt_to_phys(ser); return 0; diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_= pci.h index 876aaf81dd92..c057794a044f 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -26,7 +26,7 @@ * incrementing the version number in the VFIO_PCI_LUO_FH_COMPATIBLE strin= g. */ =20 -#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" +#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v2" =20 /** * struct vfio_pci_core_device_ser - Serialized state of a single VFIO PCI @@ -34,10 +34,12 @@ * * @domain: The device's PCI domain number (segment). * @bdf: The device's PCI bus, device, and function number. + * @reset_works: Non-zero if the device supports function resets. */ struct vfio_pci_core_device_ser { u32 domain; u16 bdf; + u8 reset_works; } __packed; =20 #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ --=20 2.53.0.983.g0bb29b3bc5-goog