From mboxrd@z Thu Jan 1 00:00:00 1970 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 5DB4E38E5C6 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-2b0565d77a6so10203095ad.2 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=Rj9LPNdaSRjK7Tz33YlO0K8wdA3hAdIr2/MWIXIwzHMmlUvfDyxObeLl4mQOPozxjt Ld78nSHSSloe2Nl7LIk1Y0Je3SY3iW/mjEMIUVm8NIDxozNS/hNkObomuuizNDL0eJy1 un36EPXdn8iLc23/AzyKm/voo2lzwAgnCSzBdiNfcYrwW+HTShtotJmPkRlnctJ68hHC PX3nTsY6rTbIHmvhT7e4jw6qHv2DMHxEyVrSnGRUcxWrGOwjuv4wXuKuc1J38OvzZ7P4 fQ3qw7MWSO/1WEfJKnzN7xpU/E+ub8QzF0FJHa6DPtx+L+t7njZYLR2sx8LeIFGAyNTs ZT+w== X-Forwarded-Encrypted: i=1; AJvYcCXwYJ/Qeh7oVx/V0RgNTBKd1AsGgaZ2ArPxzaaaopi+tA9RsjBx4hCU6JGbpQGb2HJ39psgfy9i+BU=@vger.kernel.org X-Gm-Message-State: AOJu0YzA2TjD5areeb0T0nqnPnrKrimZG0Xb3VnZ5qINvSHz+ogxzxA+ LwkBwOEJ68a3A+vxGhNwYG9XnSJ6cnoY7DAVvbTkiegDL27gP2k1IaLdnPHC2+dKuGp9JPwUCP7 DNagiMyBiAKiiVA== 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-doc@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-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_core.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 = { NULL) }; +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 = vdev->liveupdate_incoming_state->reset_works; + return 0; + } + + ret = pci_try_reset_function(vdev->pdev); + + /* Bail if the device lock cannot be acquired. */ + if (ret == -EAGAIN) + return ret; + + vdev->reset_works = !ret; + return 0; +} + int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) { struct pci_dev *pdev = vdev->pdev; @@ -514,12 +539,10 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) if (ret) goto out_power; - /* If reset fails because of the device lock, fail this path entirely */ - ret = pci_try_reset_function(pdev); - if (ret == -EAGAIN) + ret = vfio_pci_core_probe_reset(vdev); + if (ret) goto out_disable_device; - vdev->reset_works = !ret; pci_save_state(pdev); vdev->pci_saved_state = 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 device * is preserved. * + * * Whether or not the device supports function resets. This is necessary 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 device and * its dependencies (such as DMA mappings), VFIO currently resets and restores * preserved devices back into an idle state during kexec, before handing off @@ -162,6 +165,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) ser->bdf = pci_dev_id(pdev); ser->domain = pci_domain_nr(pdev->bus); + ser->reset_works = vdev->reset_works; args->serialized_data = 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 string. */ -#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" +#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v2" /** * 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; #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ -- 2.53.0.983.g0bb29b3bc5-goog