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 D653F36A35A for ; Mon, 11 May 2026 23:48:30 +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=1778543312; cv=none; b=SueTtXTevms7Qj7AbKJNQee3zyqjEXwT7rFFKQHJ/kr0fz0ArhbQ6b30yU9cuyz7wfiMNOi6IMw582Nmnrt4HCgs0hETJMLxA466psT1v3fKvRY6X3zs8dI+oh1zFcdiDver85zhnJRVfX18hD2Dsc2XT6+4E/46KoRKs+QBukM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778543312; c=relaxed/simple; bh=tfZtedW2QWnLrxToR7VGh+7wrLdGvMWEp3d3S0hb/FM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i4GHMExLQlk21OzepCZYUrLYKPXREKL+jHdlcea3B3ZF7KIcpDdZkMEllmsQxIlHrYpeUPKNBYxzefGWB9fTcG19lSh66b6d73J+KHRgDHn2auezKTaFzHFWa0LqFYuQ+kZteOid6uSQAi42wbKzQcEkPwe5GyJstK6//y35TQA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B/p9Kbmh; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B/p9Kbmh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2bc7f9b2213so19179125ad.0 for ; Mon, 11 May 2026 16:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778543310; x=1779148110; 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=g2q9EGS/hZY8b1wwaKYU2VBFf9wnakzcnkxpfxUOFzQ=; b=B/p9KbmhjKHSxXtxl/T3Ct4z6gXku9GPt1mDU9TSF2foN6Mqgvyi06BEw1FTQEGrUy flg4qsyVz7aYBuwjzfSECSHtNLKgHJgltsznmWHzvVCE8ymaiKSWUJIOETa7E/KcTeZe nPElRnUvJ1y5tKWQQFAhsIs6FzIDFW3/MoAGa1UeVIz6f1D2Ds5HM1Z9hSFbzKoE7kI3 MUV4LOfPqldlYjbupz9iG8GYi3nOb9MljPy8bUWrzGIoEnhh7n5uDT2rbDzoUprEJ0hI URv5djAU0YLeJGH7WXpFrbYEi4euPhjWWkmWpEbZIQSU4GQeaFqQWv181LpjkNhN44QZ US8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778543310; x=1779148110; 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=g2q9EGS/hZY8b1wwaKYU2VBFf9wnakzcnkxpfxUOFzQ=; b=lPy2xKLf3nctBOZJn1zOe4o6VxUG8KqqfLgnuX307AvGIFG+plLRNnXMWFrjLCFPA5 3/PS/oWlq568gx/gGhSvK+vFmrolXj7N07lHCYZWw8MpAmokKEs4F1hwmJlLcLbSaXSv HE0qKoqReOgd69Oo/aMIM3VTouGx6I+iUEVqv79R57gc8Qa9+dw67YDPEU3PBBaQkblg 0X+BpEKQW7VFZ6LmWqOcEydnvHPNJOKmAAt0BM0JmNYN2pZ5rbUJE3ffofUl22ME/GVe pTe795/51xZTpg7KB3ppqNIPyG8ehzg4p8Gy2oezfOAAOYAAdFkiv5vOVlvAvgiciEKR rPbA== X-Forwarded-Encrypted: i=1; AFNElJ+Zi7bT2W5QTTVLDu9sAqJ7uC9ITZ9QJvAYqUmLrGC1q6U2qGNN4WUM4mExt/VUNCFy7EGnEqnmQ/Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1mlFDgp1HhPbq6zp/XaogYrq2lCFWTiLSn9g7oJVUWRm1kSY+ jEzz/WhBHWAfNrDEstl91RX+sOccUSwnbrEqAtxq3/6mrulOaL2qT04x88ZSOPp8RmM50uir9aX YtphPBfJPQw== X-Received: from plbv16.prod.google.com ([2002:a17:903:44d0:b0:2b2:488e:b71]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b28:b0:2ba:881f:6192 with SMTP id d9443c01a7336-2baf0dd629cmr168833395ad.22.1778543310123; Mon, 11 May 2026 16:48:30 -0700 (PDT) Date: Mon, 11 May 2026 16:47:47 -0700 In-Reply-To: <20260511234802.2280368-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260511234802.2280368-1-vipinsh@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260511234802.2280368-2-vipinsh@google.com> Subject: [PATCH v4 01/16] vfio/pci: Register a file handler with Live Update Orchestrator From: Vipin Sharma To: kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org Cc: ajayachandra@nvidia.com, alex@shazbot.org, amastro@fb.com, ankita@nvidia.com, apopple@nvidia.com, chrisl@kernel.org, corbet@lwn.net, dmatlack@google.com, graf@amazon.com, jacob.pan@linux.microsoft.com, jgg@nvidia.com, jgg@ziepe.ca, jrhilke@google.com, julianr@linux.ibm.com, kevin.tian@intel.com, leon@kernel.org, leonro@nvidia.com, lukas@wunner.de, michal.winiarski@intel.com, parav@nvidia.com, pasha.tatashin@soleen.com, praan@google.com, pratyush@kernel.org, rananta@google.com, rientjes@google.com, rodrigo.vivi@intel.com, rppt@kernel.org, saeedm@nvidia.com, skhan@linuxfoundation.org, skhawaja@google.com, vipinsh@google.com, vivek.kasireddy@intel.com, witu@nvidia.com, yanjun.zhu@linux.dev, yi.l.liu@intel.com Content-Type: text/plain; charset="UTF-8" Register a live update file handler for vfio-pci device files. Add stub implementations of all required callbacks so that registration does not fail (i.e. to avoid breaking git-bisect). This file handler will be extended in subsequent commits to enable a device bound to vfio-pci to run without interruption while the host is going through a kexec Live Update. Put this support behind a new Kconfig VFIO_PCI_LIVEUPDATE that is marked experimental and default-disabled until more of the device preservation support has landed in the kernel. Co-developed-by: David Matlack Signed-off-by: David Matlack Signed-off-by: Vipin Sharma --- MAINTAINERS | 1 + drivers/vfio/pci/Kconfig | 12 +++++ drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/vfio_pci.c | 11 +++- drivers/vfio/pci/vfio_pci_liveupdate.c | 70 ++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_priv.h | 14 ++++++ include/linux/kho/abi/vfio_pci.h | 28 +++++++++++ 7 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 drivers/vfio/pci/vfio_pci_liveupdate.c create mode 100644 include/linux/kho/abi/vfio_pci.h diff --git a/MAINTAINERS b/MAINTAINERS index 42dbac2c2ed3..b6c33c2bcc7c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -27980,6 +27980,7 @@ F: Documentation/ABI/testing/debugfs-vfio F: Documentation/ABI/testing/sysfs-devices-vfio-dev F: Documentation/driver-api/vfio.rst F: drivers/vfio/ +F: include/linux/kho/abi/vfio_pci.h F: include/linux/vfio.h F: include/linux/vfio_pci_core.h F: include/uapi/linux/vfio.h diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig index 296bf01e185e..c12d614fc6c4 100644 --- a/drivers/vfio/pci/Kconfig +++ b/drivers/vfio/pci/Kconfig @@ -42,6 +42,18 @@ config VFIO_PCI_IGD and LPC bridge config space. To enable Intel IGD assignment through vfio-pci, say Y. + +config VFIO_PCI_LIVEUPDATE + bool "VFIO PCI support for Live Update (EXPERIMENTAL)" + depends on PCI_LIVEUPDATE + help + Support for preserving devices bound to vfio-pci across a Live + Update. This option should only be enabled by developers working on + implementing this support. Once enough support has landed in the + kernel, this option will no longer be marked EXPERIMENTAL. + + If you don't know what to do here, say N. + endif config VFIO_PCI_ZDEV_KVM diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 6138f1bf241d..bf296ab1c967 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o vfio-pci-$(CONFIG_VFIO_PCI_IGD) += vfio_pci_igd.o +vfio-pci-$(CONFIG_VFIO_PCI_LIVEUPDATE) += vfio_pci_liveupdate.o obj-$(CONFIG_VFIO_PCI) += vfio-pci.o obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 0c771064c0b8..5038265f3af5 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -264,10 +264,14 @@ static int __init vfio_pci_init(void) vfio_pci_core_set_params(nointxmask, is_disable_vga, disable_idle_d3); + ret = vfio_pci_liveupdate_init(); + if (ret) + return ret; + /* Register and scan for devices */ ret = pci_register_driver(&vfio_pci_driver); if (ret) - return ret; + goto err_liveupdate_cleanup; vfio_pci_fill_ids(); @@ -275,12 +279,17 @@ static int __init vfio_pci_init(void) pr_warn("device denylist disabled.\n"); return 0; + +err_liveupdate_cleanup: + vfio_pci_liveupdate_cleanup(); + return ret; } module_init(vfio_pci_init); static void __exit vfio_pci_cleanup(void) { pci_unregister_driver(&vfio_pci_driver); + vfio_pci_liveupdate_cleanup(); } module_exit(vfio_pci_cleanup); diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c new file mode 100644 index 000000000000..1c74854600ea --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright (c) 2026, Google LLC. + * Vipin Sharma + * David Matlack + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#include "vfio_pci_priv.h" + +static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handler *handler, + struct file *file) +{ + return false; +} + +static int vfio_pci_liveupdate_preserve(struct liveupdate_file_op_args *args) +{ + return -EOPNOTSUPP; +} + +static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args *args) +{ +} + +static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) +{ + return -EOPNOTSUPP; +} + +static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) +{ +} + +static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { + .can_preserve = vfio_pci_liveupdate_can_preserve, + .preserve = vfio_pci_liveupdate_preserve, + .unpreserve = vfio_pci_liveupdate_unpreserve, + .retrieve = vfio_pci_liveupdate_retrieve, + .finish = vfio_pci_liveupdate_finish, + .owner = THIS_MODULE, +}; + +static struct liveupdate_file_handler vfio_pci_liveupdate_fh = { + .ops = &vfio_pci_liveupdate_file_ops, + .compatible = VFIO_PCI_LUO_FH_COMPATIBLE, +}; + +int __init vfio_pci_liveupdate_init(void) +{ + int ret; + + ret = liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); + if (ret && ret != -EOPNOTSUPP) + return ret; + + return 0; +} + +void vfio_pci_liveupdate_cleanup(void) +{ + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); +} diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index fca9d0dfac90..c130ac53c4f9 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -137,4 +137,18 @@ static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, } #endif +#ifdef CONFIG_VFIO_PCI_LIVEUPDATE +int __init vfio_pci_liveupdate_init(void); +void vfio_pci_liveupdate_cleanup(void); +#else +static inline int vfio_pci_liveupdate_init(void) +{ + return 0; +} + +static inline void vfio_pci_liveupdate_cleanup(void) +{ +} +#endif /* CONFIG_VFIO_PCI_LIVEUPDATE */ + #endif diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_pci.h new file mode 100644 index 000000000000..67e8199eec59 --- /dev/null +++ b/include/linux/kho/abi/vfio_pci.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright (c) 2026, Google LLC. + * Vipin Sharma + * David Matlack + */ + +#ifndef _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H +#define _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H + +/** + * DOC: VFIO PCI Live Update ABI + * + * VFIO uses the ABI defined below for preserving device files across a kexec + * reboot using LUO. + * + * Device metadata is serialized into memory which is then handed to the next + * kernel via KHO. + * + * This interface is a contract. Any modification to any of the serialization + * structs defined here constitutes a breaking change. Such changes require + * incrementing the version number in the VFIO_PCI_LUO_FH_COMPATIBLE string. + */ + +#define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" + +#endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ -- 2.54.0.563.g4f69b47b94-goog