From nobody Mon Feb 9 13:00:57 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 663EB35E536 for ; Thu, 29 Jan 2026 21:25: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=1769721955; cv=none; b=rY3m9dnI2nfFKrtAyxZG6tKHLfhCJn2OAJAYCphXg457/EzsAFkuHXWoSOL6K7tMy7uVq5/BeQXZx7P0cnBU41ni9m3XNJlBkBGoTVaGNcgESE6yEF377PjlMEYS8FtN+xj6pmfOJXlO3g4Qgv8Pp/BzFMTQoGDDsgkT2kEs1HI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769721955; c=relaxed/simple; bh=6IdtaI14wSLFnlm3AePOxVdQnZ5Ce/BaKfnD8oLedO0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=O3CC1ujZhzEmH6gCdxXXcYDUmzA7DK/Ey7ZTpiG/XmnWb80k0IIwp/cuJD627rymBKgy4+1gE/FvOtSL6XQWfISg9avdlawEODEoMuXmXYIjc33rjZG1v06Ylj4Zzpzf6JZCUB7LWccs4Id5B2P7phyw1A6D+y1XDyCarT5+CyI= 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=2b2iQaws; 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="2b2iQaws" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-34c93f0849dso1506142a91.1 for ; Thu, 29 Jan 2026 13:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769721952; x=1770326752; 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=cEITHmxK+p0fg2PKlGTWLUl48Yr7XTXbjGIRUwhwM+A=; b=2b2iQawsuPGFdxNaG5DH0hw0rX+Sqvp6lcSMbvGtXOPbhnGelfqgN3xGH8EIEeaqLM MWu+vEK8CeOtWWmjKilHqHyrBwyaXmEe46T9N+cw5YAXzBwF9T8blgw1yE+JxCy/Jxco Pxo2hJ+Jxf/qwb9gO6AoYjGm1Z+iX+in76+iq2cuwkei8ZGaV3jevtB9ODT4pQuJ7re/ 6TFO29PI7rslUwKTqHnG1A524axdk9oAhdD5huZ2N8TOU+8yayQPfX/9fezyK9B5AkGU t3EE3LQcNqDBMJ5LYwz8P5dllqo0HzvspUHB/e/CXHBRon9adexg1bP5Oi1YIHovGq3u CbIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769721952; x=1770326752; 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=cEITHmxK+p0fg2PKlGTWLUl48Yr7XTXbjGIRUwhwM+A=; b=f8XEVYmH7GYaiNoMpCgY9Q6evDTJrmhNpyEiKL1nXfwQqFgbOiuXsnRZqD/Nir1aBC dXEEeI3gN3OEjOD6dGddlF9c6k6wkqGHlSQdsdIYx+9HbxI2oCABZra3+K8hWrgh+bVq Du/+yX8Cz8/6Brow4guYZgqtIUhki2i+d0Xv5EGNK6aKhp2O9SyHQnlKbNYq6pzUFOr7 W9WksY1JK5W9WKsVQCN8uUorNTp5IIH3R3Bh41Mvg9a8RW3Fz0B/paK+VJHAORgV/VDB 5H6vbQ7iCEVRNrVv0LQuGN5yzsfqC/LA5dLhQGqbEw43H/ltTAcWCkR1+og2fDkKvol0 D2AQ== X-Forwarded-Encrypted: i=1; AJvYcCXuHv9pkPQiGkOk4kjKn0NhwKah6HLe9hUx3egRoAiq+rXCMnjWT+T4oCgKg+1PoGyCeOA5WkmNrpmwRL4=@vger.kernel.org X-Gm-Message-State: AOJu0YzhypcFa1n/jVBnkXKTb+D+2G09DQKOiwJ4BcKWnKoY6JSPzGzF 5Q388o3KafSRpQOvmnjVeBnZe86RGTf3Bij1JvT+czzxnFzliZXdinqSxd9yDDjwRbWn5jTHWLB OqtDZoBWZejfknw== X-Received: from pjk11.prod.google.com ([2002:a17:90b:558b:b0:34c:489a:f4c9]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c10:b0:353:2972:74a4 with SMTP id 98e67ed59e1d1-35429af8f7amr3444629a91.13.1769721952367; Thu, 29 Jan 2026 13:25:52 -0800 (PST) Date: Thu, 29 Jan 2026 21:24:56 +0000 In-Reply-To: <20260129212510.967611-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: <20260129212510.967611-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.rc1.225.gd81095ad13-goog Message-ID: <20260129212510.967611-10-dmatlack@google.com> Subject: [PATCH v2 09/22] vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device From: David Matlack To: Alex Williamson Cc: Adithya Jayachandran , Alexander Graf , Alex Mastro , Alistair Popple , Andrew Morton , Ankit Agrawal , Bjorn Helgaas , Chris Li , David Matlack , David Rientjes , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , 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, Lukas Wunner , "=?UTF-8?q?Micha=C5=82=20Winiarski?=" , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pranjal Shrivastava , Pratyush Yadav , Raghavendra Rao Ananta , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , "=?UTF-8?q?Thomas=20Hellstr=C3=B6m?=" , Tomita Moeko , Vipin Sharma , Vivek Kasireddy , William Tu , Yi Liu , Zhu Yanjun Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Stash a pointer to a device's incoming Live Updated state in struct vfio_pci_core_device. This will enable subsequent commits to use the preserved state when initializing the device. To enable VFIO to safely access this pointer during device enablement, require that the device is fully enabled before returning true from can_finish(). This is synchronized by vfio_pci_core.c setting vdev->liveupdate_incoming_state to NULL under dev_set lock once it's done using it. Signed-off-by: David Matlack --- drivers/vfio/pci/vfio_pci_core.c | 2 +- drivers/vfio/pci/vfio_pci_liveupdate.c | 17 ++++++++++++++++- include/linux/vfio_pci_core.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 3a11e6f450f7..b01b94d81e28 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -569,7 +569,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *v= dev) if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev)) vdev->has_vga =3D true; =20 - + vdev->liveupdate_incoming_state =3D NULL; return 0; =20 out_free_zdev: diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index ad915352303f..1ad7379c70c4 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -131,6 +131,7 @@ static int match_device(struct device *dev, const void = *arg) static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *ar= gs) { struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; struct vfio_device *device; struct file *file; int ret; @@ -160,6 +161,9 @@ static int vfio_pci_liveupdate_retrieve(struct liveupda= te_file_op_args *args) goto out; } =20 + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + vdev->liveupdate_incoming_state =3D ser; + args->file =3D file; =20 out: @@ -171,7 +175,18 @@ static int vfio_pci_liveupdate_retrieve(struct liveupd= ate_file_op_args *args) =20 static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args = *args) { - return args->retrieved; + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + + if (!args->retrieved) + return false; + + device =3D vfio_device_from_file(args->file); + vdev =3D container_of(device, struct vfio_pci_core_device, vdev); + + /* Check that vdev->liveupdate_incoming_state is no longer in use. */ + guard(mutex)(&device->dev_set->lock); + return !vdev->liveupdate_incoming_state; } =20 static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *arg= s) diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 1ac86896875c..350c30f84a13 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -143,6 +143,7 @@ struct vfio_pci_core_device { struct notifier_block nb; struct rw_semaphore memory_lock; struct list_head dmabufs; + struct vfio_pci_core_device_ser *liveupdate_incoming_state; }; =20 enum vfio_pci_io_width { --=20 2.53.0.rc1.225.gd81095ad13-goog