From nobody Thu Apr 2 22:03:12 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 D4A59386545 for ; Mon, 23 Mar 2026 23:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310335; cv=none; b=AxiX0q9VXfPKahDHWqOoQyfT2yDbgAaAKgemjkGLfWZYus6oU6lxiQxIEr3xDZAgS4xUvfgHnHxNCTy0Gnk8/97T6gHk2s+YyPlWAnY3+unG5v/YaaAy6mWkGcLAiYwBSnd+NAQh6wYfxFHfD8vi91hRSZuPjT212hWuK2TQiIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310335; c=relaxed/simple; bh=PBlaixBFERkwnraELbaSfRJMLkjw7p/DT3tIx1ijTEg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GNf0AG+pJvP1QQr4gJfd1on6G4h6c5p+DBxLHlDQukpibSQw98JzGdQUKXZhDdX247ETH58Hqooi2VLqSvdQVdEQY1coCz8xnQYaX1gnuNS566QRstkbJ7d9k1kNa/6u85GUBx88AFFoXEF4HT998zeLKMrNdOOxTgPf/fkwXK4= 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=ZiF04+ZA; arc=none smtp.client-ip=209.85.216.74 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="ZiF04+ZA" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-35a1e725a8fso24244137a91.3 for ; Mon, 23 Mar 2026 16:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310333; x=1774915133; 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=FxGJfmbE6y6D4fg7v0R8cmHFXmMbzFJlr4dbGGaFVKE=; b=ZiF04+ZAJ6wsl9QhyvqABMNwvUHXKldkY0AemS7SUo0vutKxPbtIUY2QXwEeryz+Gb v4JRthi91fBxgKcIPG3HRL7Mp42u5/rDOJkAmuQLgM9/kFUXhouDzfi8oMZ/CjeDI8fv qdIomlJSLGZhGlJ7UE701ik8TSSxShE9DBnXlmp2ZA8SjEom5ceT6TT6vJ4rhlf0h5uQ iaPn9tj+1O7/yNQpLIr/TE42kIhmbdqSonxutB7hX31VoDnWRfThCHcCGgFi/lty1t7h A68TLaKqPEC1Jb2qCYhjMWdo79+Jir99UucMpIHBvpJaAGo/HUWzl7mUL8cUGIjiKaA1 /oNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310333; x=1774915133; 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=FxGJfmbE6y6D4fg7v0R8cmHFXmMbzFJlr4dbGGaFVKE=; b=K0ir7TkEz+OXMBzkbS9V9KVRsUi6F969S0PfpPuy4gssImNvO7uDP9HtJf+A8ipboD RVsVWvrtE+N0eKhUSieh9OL8YZeLszqoOVhP5PptoJleEbXFzzrXIymbyIl6T/EBRZOs EdonRC1k96Iz0r1F69wTpB6KvVFd06S/TGLkaH69TglkU2SDapgFP3m+fj2EfG0J03jE D/1sCJwmAoUIguWzyL6EAltFdyyh3kp6csGRbk+cIQFrV4gK9NIloGvPFlryrduZQqI/ VfDiIkF7UarWx49CNdlcKIrpqAx8iBSd68fhglsuUNaxSa1tKhjFh6FA1GOfK5P9KRDe 2+Tg== X-Forwarded-Encrypted: i=1; AJvYcCVoB6J+AyESyfjGAC3dopUvun69/BEBd3Fe6QX64SxxWoBwOPL1xpDrqDCAMYLQMaDUuHdNpIMhCkYD03M=@vger.kernel.org X-Gm-Message-State: AOJu0YyqJDr7oXNxoa2Lr+26dBNsmPwR4dcimhJKQkaai6RbbIyoPZik ro5Ms3bqeKqs8K+qHVWBzPTII6YxLU7L5A+3aafu+vazXME+smpu4sjYqwc5Xmmy/8f6Iwp0itV EvLXFmWCJzUcQVg== X-Received: from pjbca11.prod.google.com ([2002:a17:90a:f30b:b0:359:84f3:a9d]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:384b:b0:35b:9ae3:9080 with SMTP id 98e67ed59e1d1-35bd2c62dc6mr13468908a91.14.1774310333147; Mon, 23 Mar 2026 16:58:53 -0700 (PDT) Date: Mon, 23 Mar 2026 23:58:01 +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-10-dmatlack@google.com> Subject: [PATCH v3 09/24] vfio/pci: Notify PCI subsystem about devices preserved across 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" Notify the PCI subsystem about devices vfio-pci is preserving across Live Update by registering the vfio-pci liveupdate file handler with the PCI subsystem's FLB handler. Notably this will ensure that devices preserved through vfio-pci will have their PCI bus numbers preserved across Live Update, allowing VFIO to use BDF as a key to identify the device across the Live Update and (in the future) allow the device to continue DMA operations across the Live Update. This also enables VFIO to detect that a device was preserved before userspace first retrieves the file from it, which will be used in subsequent commits. Signed-off-by: David Matlack --- drivers/vfio/pci/vfio_pci_liveupdate.c | 44 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 4b83a02401aa..b960ec3ffbf2 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -67,6 +67,9 @@ * interrupts on the device will cause the ``reboot(LINUX_REBOOT_CMD_KE= XEC)`` * syscall (to initiate the kexec) to fail. * + * In addition, the device must meet all of the restrictions imposed by the + * core PCI layer documented at :doc:`/PCI/liveupdate`. + * * Preservation Behavior * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * @@ -136,23 +139,37 @@ static int vfio_pci_liveupdate_preserve(struct liveup= date_file_op_args *args) struct vfio_pci_core_device_ser *ser; struct vfio_pci_core_device *vdev; struct pci_dev *pdev; + int ret; =20 vdev =3D container_of(device, struct vfio_pci_core_device, vdev); pdev =3D vdev->pdev; =20 + ret =3D pci_liveupdate_preserve(pdev); + if (ret) + return ret; + ser =3D kho_alloc_preserve(sizeof(*ser)); - if (IS_ERR(ser)) - return PTR_ERR(ser); + if (IS_ERR(ser)) { + ret =3D PTR_ERR(ser); + goto err_unpreserve; + } =20 ser->bdf =3D pci_dev_id(pdev); ser->domain =3D pci_domain_nr(pdev->bus); =20 args->serialized_data =3D virt_to_phys(ser); return 0; + +err_unpreserve: + pci_liveupdate_unpreserve(pdev); + return ret; } =20 static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args = *args) { + struct vfio_device *device =3D vfio_device_from_file(args->file); + + pci_liveupdate_unpreserve(to_pci_dev(device->dev)); kho_unpreserve_free(phys_to_virt(args->serialized_data)); } =20 @@ -213,6 +230,10 @@ static int vfio_pci_liveupdate_retrieve(struct liveupd= ate_file_op_args *args) if (!device) return -ENODEV; =20 + ret =3D pci_liveupdate_retrieve(to_pci_dev(device->dev)); + if (ret) + goto out; + file =3D vfio_device_liveupdate_cdev_open(device); if (IS_ERR(file)) { ret =3D PTR_ERR(file); @@ -233,6 +254,9 @@ static bool vfio_pci_liveupdate_can_finish(struct liveu= pdate_file_op_args *args) =20 static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *arg= s) { + struct vfio_device *device =3D vfio_device_from_file(args->file); + + pci_liveupdate_finish(to_pci_dev(device->dev)); kho_restore_free(phys_to_virt(args->serialized_data)); } =20 @@ -257,13 +281,23 @@ int __init vfio_pci_liveupdate_init(void) int ret; =20 ret =3D liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); - if (ret && ret !=3D -EOPNOTSUPP) - return ret; + if (ret) + goto err_return; + + ret =3D pci_liveupdate_register_flb(&vfio_pci_liveupdate_fh); + if (ret) + goto err_unregister; =20 return 0; + +err_unregister: + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); +err_return: + return (ret =3D=3D -EOPNOTSUPP) ? 0 : ret; } =20 void vfio_pci_liveupdate_cleanup(void) { - liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); + pci_liveupdate_unregister_flb(&vfio_pci_liveupdate_fh); + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); } --=20 2.53.0.983.g0bb29b3bc5-goog