From nobody Mon Feb 9 08:56:01 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 A870C376BE3 for ; Tue, 3 Feb 2026 22:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770156613; cv=none; b=lrb2esHxprugudH4cVydzu0vTygrShVz0lE9mX93kdyxRaxaEocnJ1qNjfZmvfcJ98YNbJRJ7zuArOkg3cExajMfmXp/36YOGS4pmcmGCsVoAeLdJwimOlhbB68IYs8ROzfOUxW8BvI5HBkbBOGa38nacWdUak4p2LzsYJrBQ/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770156613; c=relaxed/simple; bh=OvnjKmtuP+/pnyWLrwtRVT2pKYDknDMFSdYGBTZusD8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IMsL+aMdMBWxW0gg2U5yd75ZQfgvm/uQl6GaZNNLeGDCCAyYJfgNHORUgJgxh3lFmhzNU1fSFKiQEkxB/JF7LQr+NVobhyTftH/eVQ04pKuV5Blli+6qoMKDeD0Ck51Kv4rJXwsFpp4l0WIakfw6sx+BzcdpnKK8o12XV8BNTh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aXQlxC9U; arc=none smtp.client-ip=209.85.210.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--skhawaja.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aXQlxC9U" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-81f8c209cfbso3314668b3a.2 for ; Tue, 03 Feb 2026 14:10:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770156611; x=1770761411; 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=/8ncc0FKC3TXUBMo9gNfkA/biCGmORiTT+jCw4LASx4=; b=aXQlxC9UVztklrIzfWpZev/rwSmUKlvraxtoY5lfgHt/QeO1hxJl+lnQRKrGJcKEGL Gk1/ca2Q7pf5Q11WoTGLYViBevkmo6aW454pmyCDGCaW8we/f6UxzbSKSCHQ4GaSH6gZ 8qizJ79pp2lbnZzUsa4iBg5NyymBPMFZRM6YEjtTKfGLAplSnTQ2Hxp9JSW4B5hmS/Yc eyXqvfyBpDiA4MooFTFuulxWEs0Vjykgjs/Cz7vD2ZNcu9pcJLn5vJCXtpcMMw1Eupr3 6B+alAOc5TAMWNwkkM9i99hbhVOJqWtP2+yKa+t7APffXiWcSRl7x1UN783xBBduPAQw kncA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770156611; x=1770761411; 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=/8ncc0FKC3TXUBMo9gNfkA/biCGmORiTT+jCw4LASx4=; b=YBbpZ9GbnoYoQZwUtBNTD5XUi01jn1kRKhC29Qp9qwjwNooo0b3Ko0B3JCQ+VtCox7 S1d6fDzeV4z/tKRkaAZhUfnCXaujMBwjjB1aZ++wz2PfDngd6t8PLvuovebJtXclHs/n 5yWVRSHF0+NTFRJSC0ZHDNPj1xTyl5GZOutb9vay1J1lNX0NsYDAPILvEzhgMVLGMRlO MK8W7TVVrDRDGiY0JWai5WDIIMJW+ysnvsc0QN4FdVQaYhOuiazl/MzAB7QnEaYi2nsI viL/GWjL8EotfDuK3PdlEa9CHFYGuwtCKWjUPbsQYooPAncoqsEN5LC34LrxOb7ORt4D Tp3w== X-Forwarded-Encrypted: i=1; AJvYcCVmm0FCuNYz864SQ/s80cJXHZWl5mLJvSDai0WT+t721HAht4QTpU1KFaxC62QpgtsBwDbiQtvZylrWKqM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywiw7xs2gqbxBxzRq3fAziHjzXzsIG8lc1KXU6Ayx7ZutvqhrLr hyooghQunO5FKl30Ba6XEIenC7qK9DT7iz6X0t+tIG+SUy5XjDuHH41jNgTXS8/dltHj2/S06Ef E6kmKX6QH072EKg== X-Received: from pfblr43.prod.google.com ([2002:a05:6a00:73ab:b0:7dd:8bba:6394]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2e8f:b0:821:81ef:5de8 with SMTP id d2e1a72fcca58-8241c1ab516mr847226b3a.12.1770156610959; Tue, 03 Feb 2026 14:10:10 -0800 (PST) Date: Tue, 3 Feb 2026 22:09:47 +0000 In-Reply-To: <20260203220948.2176157-1-skhawaja@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260203220948.2176157-1-skhawaja@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260203220948.2176157-14-skhawaja@google.com> Subject: [PATCH 13/14] vfio/pci: Preserve the iommufd state of the vfio cdev From: Samiullah Khawaja To: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe Cc: Samiullah Khawaja , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , Pasha Tatashin , David Matlack , Andrew Morton , Chris Li , Pranjal Shrivastava , Vipin Sharma , YiFei Zhu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the vfio cdev is attached to an iommufd, preserve the state of the attached iommufd also. Basically preserve the iommu state of the device and also the attached domain. The token returned by the preservation API will be used to restore/rebind to the iommufd state after liveupdate. Signed-off-by: Samiullah Khawaja --- drivers/vfio/pci/vfio_pci_liveupdate.c | 28 +++++++++++++++++++++++++- include/linux/kho/abi/vfio_pci.h | 10 +++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index c52d6bdb455f..af6fbfb7a65c 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "vfio_pci_priv.h" =20 @@ -39,6 +40,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate= _file_op_args *args) struct vfio_pci_core_device_ser *ser; struct vfio_pci_core_device *vdev; struct pci_dev *pdev; + u64 token =3D 0; =20 vdev =3D container_of(device, struct vfio_pci_core_device, vdev); pdev =3D vdev->pdev; @@ -49,15 +51,32 @@ static int vfio_pci_liveupdate_preserve(struct liveupda= te_file_op_args *args) if (vfio_pci_is_intel_display(pdev)) return -EINVAL; =20 +#if CONFIG_IOMMU_LIVEUPDATE + /* If iommufd is attached, preserve the underlying domain */ + if (device->iommufd_attached) { + int err =3D iommufd_device_preserve(args->session, + device->iommufd_device, + &token); + if (err < 0) + return err; + } +#endif + ser =3D kho_alloc_preserve(sizeof(*ser)); - if (IS_ERR(ser)) + if (IS_ERR(ser)) { + if (device->iommufd_attached) + iommufd_device_unpreserve(args->session, + device->iommufd_device, token); + return PTR_ERR(ser); + } =20 pci_liveupdate_outgoing_preserve(pdev); =20 ser->bdf =3D pci_dev_id(pdev); ser->domain =3D pci_domain_nr(pdev->bus); ser->reset_works =3D vdev->reset_works; + ser->iommufd_ser.token =3D token; =20 args->serialized_data =3D virt_to_phys(ser); return 0; @@ -66,6 +85,13 @@ static int vfio_pci_liveupdate_preserve(struct liveupdat= e_file_op_args *args) static void vfio_pci_liveupdate_unpreserve(struct liveupdate_file_op_args = *args) { struct vfio_device *device =3D vfio_device_from_file(args->file); + struct vfio_pci_core_device_ser *ser; + + ser =3D phys_to_virt(args->serialized_data); + if (device->iommufd_attached) + iommufd_device_unpreserve(args->session, + device->iommufd_device, + ser->iommufd_ser.token); =20 pci_liveupdate_outgoing_unpreserve(to_pci_dev(device->dev)); kho_unpreserve_free(phys_to_virt(args->serialized_data)); diff --git a/include/linux/kho/abi/vfio_pci.h b/include/linux/kho/abi/vfio_= pci.h index 6c3d3c6dfc09..d01bd58711c2 100644 --- a/include/linux/kho/abi/vfio_pci.h +++ b/include/linux/kho/abi/vfio_pci.h @@ -28,6 +28,15 @@ =20 #define VFIO_PCI_LUO_FH_COMPATIBLE "vfio-pci-v1" =20 +/** + * struct vfio_iommufd_ser - Serialized state of the attached iommufd. + * + * @token: The token of the bound iommufd state. + */ +struct vfio_iommufd_ser { + u32 token; +} __packed; + /** * struct vfio_pci_core_device_ser - Serialized state of a single VFIO PCI * device. @@ -40,6 +49,7 @@ struct vfio_pci_core_device_ser { u16 bdf; u16 domain; u8 reset_works; + struct vfio_iommufd_ser iommufd_ser; } __packed; =20 #endif /* _LINUX_LIVEUPDATE_ABI_VFIO_PCI_H */ --=20 2.53.0.rc2.204.g2597b5adb4-goog