From nobody Mon Dec 1 23:06:46 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 B40B4343210 for ; Wed, 26 Nov 2025 19:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764185787; cv=none; b=OIrKcjACiHMuKFKXWH9d17/D5hYYWSFUCOPywlAD32cpTkk9gMLeFxjpcRnxO1HfGf6E/tk51JxiQ5d0GlKQrKnXDJXvC+ah2GG/iCeof/h6Zta/MLs1KePVc+bX19Upu8Oq9a9GX6hW3G+HLfxVnREbYO6iAlXNL03nPbRNFf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764185787; c=relaxed/simple; bh=dYwaWyRIbjLSPJvPfwfi39/44Tve6NUTV8wbCVJRFAE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XjkE2+NXgXxmoOPyEBeYDcr7fMTP6JwBXgtO+rhv2agpMzNOgzt2MaeMsxu7AI+WaP3uFyf1cfGOmvmWLMXpiU9v1Nyi/Uw2JTxhHaKprS+zpODKQzDo3cn0wdblEtdrIfd7MXtcI8PluvIWCjF07gYEaJVoqso2cj+jC/n5mwA= 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=q4asNFnU; arc=none smtp.client-ip=209.85.214.201 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="q4asNFnU" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2982dec5ccbso1690655ad.3 for ; Wed, 26 Nov 2025 11:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764185785; x=1764790585; 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=oupTdIgiJcobDgdLCKQ4bCK5hBmMGc7yRUjoOu6trk8=; b=q4asNFnUx0t6QIitaPgc/5GLpLQXvY3BXVGEPex4Bu52KS7bXAnIBQ8xm6c9ht6dt9 8GChiubJAM5zGLZI4WeOsIFLVFNucWneMjVUxodYmHjxJi1Qg8UQTKDKJ2C1DHA/yxTo roXPZ0lnlEGa7y2ekykT1ITMbHzFsxg1C7L35TFpNqrJOxgDxY+SU14bC+C6pb8hgOq7 jMFkyL0bDGbI5J0dRoSVZpQA3yr+buqGnRnJX7W6MNUz5sJciFAT/lfBPxGjjt15bFaR WAMC8IwrelECwS2OnPnfgThhaFUzwNmPF8JU68DvH9U3g5WHANnp85+lLI7NTdMDS1DG pINw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764185785; x=1764790585; 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=oupTdIgiJcobDgdLCKQ4bCK5hBmMGc7yRUjoOu6trk8=; b=D27qk/4k/P43cJMUO5HwBRUNeMX+E+H/KXmE7j9gLTim7BCw9xH50pDH5jI09ShLDR z0Fvwea5y/DKtojNM/7A5XAtgevv+rVZrDyRyEJUHnYQzG2ZJo4Xv4zuMlBzNxLpQ/ol 0+0E6BIUwl4Z2bqMakPWIESH2H5BZOReRRDKyXIXdMyb+XbmhLXTeG5hc51q/cf0OREV e4CTcQkRS29RUAxOnbvdGOuT7Udrk1XcVqmCQpJqDRS4jxjQthvvp23eYJsRX09qdbtg gKtTKpQ1fKiMmOVIld1PNGy1RlZDx52j1D0ZV2s4CqrFSyB5mL2tTwucB75QDDCt8I6w 8a+g== X-Forwarded-Encrypted: i=1; AJvYcCVP1qL8Ye2ZQmSdcvC8HG0UKfq10ZsL9AqpoqTiS6LzKhjy91DiKEjwuWXR61lBr5KJWlGhnIbG0TeLeJg=@vger.kernel.org X-Gm-Message-State: AOJu0YwTkWbFR7TU3gR8q47G4w3d+N5KGISwUz/GGqDVREHqFGI+Yr88 ksEoJLi9DtUc0mDbUnKJWUo0vFGk4Vo9gRudebJ9u5De5IaEkRZx79KE05sV+Odb60IdheTDtMA nfsGfrZZ28t6tSQ== X-Google-Smtp-Source: AGHT+IF1dFRpdgEXNa+eADLtxGLANbMQ+v0Qp/LYDBPxS4oxJSeNtN05AVnZrSpiBB35n+k+Bh9kmPafil/o6A== X-Received: from pjbmf13.prod.google.com ([2002:a17:90b:184d:b0:341:c8a:bd40]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:ace:b0:295:350a:f9b8 with SMTP id d9443c01a7336-29b6c685132mr215591725ad.29.1764185785065; Wed, 26 Nov 2025 11:36:25 -0800 (PST) Date: Wed, 26 Nov 2025 19:35:56 +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-10-dmatlack@google.com> Subject: [PATCH 09/21] vfio/pci: Store Live Update state in struct vfio_pci_core_device 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" Stash a pointer to a device's Live Updated state in struct vfio_pci_core_device. This will enable subsequent commits to use the preserved state when enabling 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(). Signed-off-by: David Matlack --- drivers/vfio/pci/vfio_pci_core.c | 1 + drivers/vfio/pci/vfio_pci_liveupdate.c | 20 +++++++++++++++++++- include/linux/vfio_pci_core.h | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_c= ore.c index 7dcf5439dedc..b09fe0993e04 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -536,6 +536,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_state =3D NULL; =20 return 0; =20 diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 7669c65bde17..0fb29bd3ae3b 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -145,6 +145,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 folio *folio; struct file *file; @@ -186,6 +187,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_state =3D ser; + args->file =3D file; =20 out: @@ -197,7 +201,21 @@ 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); + + /* + * Ensure VFIO is done using vdev->liveupdate_state, which means its + * safe for vfio_pci_liveupdate_finish() to free it. + */ + guard(mutex)(&device->dev_set->lock); + return !vdev->liveupdate_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 f541044e42a2..56ff6452562d 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -94,6 +94,12 @@ struct vfio_pci_core_device { struct vfio_pci_core_device *sriov_pf_core_dev; struct notifier_block nb; struct rw_semaphore memory_lock; + + /* + * State passed by the previous kernel during a Live Update. Only + * safe to access when first opening the device. + */ + struct vfio_pci_core_device_ser *liveupdate_state; }; =20 /* Will be exported for vfio pci drivers usage */ --=20 2.52.0.487.g5c8c507ade-goog