From nobody Mon Dec 1 23:06:45 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 5BB0E345CD6 for ; Wed, 26 Nov 2025 19:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764185789; cv=none; b=sRIqfE9WSxOXmSb2NAv5srGyVuy4Iz1UvK9BYKauhKWZcPzGLlktgsBJaciciU8Vn7fwBcTLsK8JC4k5sTgYViZt5MyAfBFaq+/XJwL2rMc9dS0YHUTyvx4jOTZmclsNIxOUvq/wHBI8YUje6G0hkPwMALvDTFufzd5z5ZVV89w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764185789; c=relaxed/simple; bh=J7pVIwlaC2a90b7nwtyp8yiJuohGfw3mOEce/82UxtI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qttdLdrJziUikYSdZfGsZqTlVuDIvHuMtUS8+9EaCDfes4mVyozUijMYXZ/DAY2yrb3xf5s7mdYp9fTzkCkHs5zWFhtdPlE9gyAK8vavshXrw9dQozyT1m9fm+qOX9ZQrR46maYauVNcBwCsRwCeiSmyCj86DHpd4HWCRjzi7Po= 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=dwVL6vOD; arc=none smtp.client-ip=209.85.216.73 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="dwVL6vOD" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-341616a6fb7so95820a91.0 for ; Wed, 26 Nov 2025 11:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764185786; x=1764790586; 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=qxDgVkCfvUIBjknMGYFc0YAO25izn9/Vb7Fr5WcLn8I=; b=dwVL6vODunu314pHy+b2J1h+eW4lRroED9tEH94HXDe+9H+ZEr68PVqSE2ZLm9Lo02 aAggeJRVjcR+sNsP6v5A2InKO889aGBQowHXlyVUtRiBAAkt37Wn3pz4vXAcLk2qzdje F9Ziizhs81Cw/8DFC8NJVZFWQjUZ/JWSXMvusLWp7kg+sI4ljYZCbUqSaJ0yPWk0kign qi5CB6ugbl4EVTJhtLLHkZGOQEqnt4YsbRPzqe/XXiyqCHNQICn4yALQjo6fSGoj0OH1 S3vp/Uv2qdT7dpWF26PPBnxXKVLXr4wTKyW4Xm7I+QZfrfwT6CY6OQz9D0xCl+tz3Ith Q5bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764185786; x=1764790586; 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=qxDgVkCfvUIBjknMGYFc0YAO25izn9/Vb7Fr5WcLn8I=; b=VCEyBlenWP8zwa0VsOGBRugyk+psFJGg2+OJ8Ga+fEjlgeJrpH4bhl2dpbnYLRyr0E oCg9TJMup6i7RAxHjtIxcOnId4HpPWCuMWrmsvT3FqWg72vBPJRONxQV3N57zQo1AZWK Kv9CBvxz9BXqrR4nPWW5ycSZ4ZhK8EukM18t1ebC2MOgD1qXtAviesljSbRgpLd7ZYSA sjJwTF6wnRaYq3j6w0jkPv1xi2kRWsEGtSgj3RMFKFhzrrw6SyJICEhzUa8TrTZxJnmt R9MdCEFv7pf4mcxJjnMy70LQSBX4VqUSEKzGLLkBccFUdtPTSrRLsoYfoJDn91EvKvRM fQbg== X-Forwarded-Encrypted: i=1; AJvYcCU/ERhzKJi8mvq9ml6W0d1GHIDepVse5XyYQ+jlaTe3Omx42maFLWeidx5meFNTgcKzK0XE1kqJA8Zl65o=@vger.kernel.org X-Gm-Message-State: AOJu0YzMeXeMVotMpLaQmYdQYQX7ZfuWuyHdhuuFeXAs4uUq7+Q7ufbJ UtbH2ggDeqOVW6O8ILpufM9WfEtpyaowpeU5LSl73Oq4cXrxqTkVjHBDT7ZIm+Yg03X2X1L3bAC 3RCXRZkZaG4hTMQ== X-Google-Smtp-Source: AGHT+IGz6vSeW4fFPlsbH/YbzCbOjEAX4lyHpEhDzDf7WPVwipOugVcvT745U9YgzvArnPjB+ggooe0srOWMJQ== X-Received: from pjpo2.prod.google.com ([2002:a17:90a:9f82:b0:340:5c38:986c]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:394c:b0:340:54a1:d703 with SMTP id 98e67ed59e1d1-34733f5d318mr22023223a91.35.1764185786500; Wed, 26 Nov 2025 11:36:26 -0800 (PST) Date: Wed, 26 Nov 2025 19:35:57 +0000 In-Reply-To: <20251126193608.2678510-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: <20251126193608.2678510-1-dmatlack@google.com> X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog Message-ID: <20251126193608.2678510-11-dmatlack@google.com> Subject: [PATCH 10/21] vfio/pci: Skip reset of preserved device after Live Update From: David Matlack To: Alex Williamson Cc: Adithya Jayachandran , Alex Mastro , Alistair Popple , Andrew Morton , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Josh Hilke , Kevin Tian , kvm@vger.kernel.org, Leon Romanovsky , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, Lukas Wunner , Mike Rapoport , Parav Pandit , Pasha Tatashin , Philipp Stanner , Pratyush Yadav , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Tomita Moeko , Vipin Sharma , William Tu , Yi Liu , Yunxiang Li , 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 | 22 +++++++++++++++++----- drivers/vfio/pci/vfio_pci_liveupdate.c | 1 + include/linux/kho/abi/vfio_pci.h | 2 ++ include/linux/vfio_pci_core.h | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index b09fe0993e04..c3b30f08a788 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -482,12 +482,24 @@ 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) - goto out_disable_device; + if (vdev->liveupdate_state) { + /* + * This device was handed off by vfio-pci from a previous kernel + * via Live Update, so it does not need to be reset. + */ + vdev->reset_works =3D vdev->liveupdate_state->reset_works; + } else { + /* + * If reset fails because of the device lock, fail this path + * entirely. + */ + ret =3D pci_try_reset_function(pdev); + if (ret =3D=3D -EAGAIN) + goto out_disable_device; + + vdev->reset_works =3D !ret; + } =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 0fb29bd3ae3b..bcaf9de8a823 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -59,6 +59,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate= _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 err =3D kho_preserve_folio(folio); if (err) diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_= pci.h index 9bf58a2f3820..6c3d3c6dfc09 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -34,10 +34,12 @@ * * @bdf: The device's PCI bus, device, and function number. * @domain: The device's PCI domain number (segment). + * @reset_works: Non-zero if the device supports function resets. */ struct vfio_pci_core_device_ser { u16 bdf; u16 domain; + u8 reset_works; } __packed; =20 #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 56ff6452562d..3421721a1615 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -15,6 +15,7 @@ #include #include #include +#include =20 #ifndef VFIO_PCI_CORE_H #define VFIO_PCI_CORE_H --=20 2.52.0.487.g5c8c507ade-goog