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 9E2AA388365 for ; Mon, 23 Mar 2026 23:58:57 +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=1774310339; cv=none; b=k7Ev+IJfvIoaVxGJlDdMf+1vrUuScFQvKVeZveW4JFbcWCoKwkYxHWmHQC2g0dkTqnEJUNq3prpnotmXzUUNDK3QPRF8dxBwi6/QGDzFwvOK82gN7zLidzTnv8biBEYID1hYRSJIzsl6VrDa/sf+f7PlVLyjtkiBKDJPv8dL0Mw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310339; c=relaxed/simple; bh=+0b5yfHhqKc5WRkrCQm2Jd3F6UU1rPdRTjAvF2KhK0Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MwMWqPl70lGvqKlGO0BO9JsLNDECEXEVtdNZLYONaONcvC5o2rvQyxEXZk3+A4OTBV9qY8RNMx0puu7iAS0rKdBXPp57pSe/OJKyN371JT+Zf+qpRD1Na1bXBGI5Xl6Q7fmZ6Vr8RV5knrlD5L3Zu2b+c9T2mpm29JzSywITNns= 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=o2ibxz68; 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--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="o2ibxz68" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2b079b4a8c3so3148685ad.3 for ; Mon, 23 Mar 2026 16:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310337; x=1774915137; 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=i6NpvLJAkS4c52+WboP6wAkf2PbPQKSMM3U4nd1tgoo=; b=o2ibxz68IXVTcIRdHzzqBa25/gq1A2igO71wTFgztZP/Ct2yhr0W7TM4nPTlvb6uXT a675CAbJ7xrdXRDTnpLslUarYiYWAPoniZYniKrCjcb5eDKN+6Oz33cjQnjtw9dWRwPm eta35Qgbx0E9/UkKofRss8tJe+TDO7xWZwyP71mNKZ4r+TLqWDvyLOxv51W438S9q/Hn oHd36fHDLbH3zIDV4WEob31theMxppbT69D90N+TEe6+R0dalhZQqrpZ8m/HcFq5shpK CytSn3es3Nw274l75XtO66yDCC7EaIJXZg5627sC6FArk8CIEPQDdskqL2aJYvoZcVGu 0unA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310337; x=1774915137; 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=i6NpvLJAkS4c52+WboP6wAkf2PbPQKSMM3U4nd1tgoo=; b=QoHfL6F9zmtGNeDAopmBmzoic+BqrOrkggb7hZPfFEEz3bXooqaqRal2UjX2PWogw9 LZM4yFSyUyiGHpG2g5RGeGhzJnY8t2FJovuEC7vsSp1jcqaodEpL1rt1JXLQ1SFNrgdR MGUQU2XH5J6CqHqNE+UMXjpFZWe/vEkaUqERE0pumPBhD9ghAXBy5aevgjlDjTeD/iVh 0IZm/Az0TMbAKCXDpElibJQzcmPCON1MjdTedoac86i9Fc/HdyIvy3Twu/BmtdMs5xnC DzHeKyJK3oPx1HqXRAp9YtqgNLbiA7jZbtPWlUlY3t7HOJcTRtk5y6GmzVfymhlJQiG2 6sjw== X-Forwarded-Encrypted: i=1; AJvYcCWSiRj3j5R448bgPPmjFp7+RUhfHmAsDwoIdgLdaC2/HCpWBmZEsPipJQsmY5nRuE5zf0HcWN3TFSU=@vger.kernel.org X-Gm-Message-State: AOJu0YzQDxKfGeTQX9ThYbD5S7fK4bAG3dhCOdxYl+KTHWAyfMvs2mEM Yf4XXWsp1IGp5B4ssjyydCPZ0+AMGGsyGJuLiP8MmgKLhKFTqnO/2Xqhtpt++lvYCtico7guLH5 nDw+Bdf1pebIEiQ== X-Received: from plgd12.prod.google.com ([2002:a17:902:cecc:b0:2a8:71ec:6799]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f984:b0:2ae:c795:6b4a with SMTP id d9443c01a7336-2b0826d73f3mr94191885ad.11.1774310336851; Mon, 23 Mar 2026 16:58:56 -0700 (PDT) Date: Mon, 23 Mar 2026 23:58:03 +0000 In-Reply-To: <20260323235817.1960573-1-dmatlack@google.com> Precedence: bulk X-Mailing-List: linux-doc@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-12-dmatlack@google.com> Subject: [PATCH v3 11/24] vfio/pci: Store incoming Live Update state in struct vfio_pci_core_device 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-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 | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 81f941323641..d7c472cf4729 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -568,7 +568,7 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) if (!vfio_vga_disabled() && vfio_pci_is_vga(pdev)) vdev->has_vga = true; - + vdev->liveupdate_incoming_state = NULL; return 0; out_free_zdev: diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c index 6f760ace7065..8d6681e1d328 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -226,6 +226,7 @@ static int match_device(struct device *dev, const void *arg) static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) { struct vfio_pci_core_device_ser *ser; + struct vfio_pci_core_device *vdev; struct vfio_device *device; struct file *file; int ret = 0; @@ -246,6 +247,9 @@ static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) goto out; } + vdev = container_of(device, struct vfio_pci_core_device, vdev); + vdev->liveupdate_incoming_state = ser; + args->file = file; out: /* Drop the reference from vfio_find_device() */ @@ -255,7 +259,18 @@ static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_op_args *args) static bool vfio_pci_liveupdate_can_finish(struct liveupdate_file_op_args *args) { - return args->retrieve_status > 0; + struct vfio_pci_core_device *vdev; + struct vfio_device *device; + + if (args->retrieve_status <= 0) + return false; + + device = vfio_device_from_file(args->file); + vdev = 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; } static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *args) diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index 2ebba746c18f..0c508dd8d1ac 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -26,6 +26,7 @@ #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1) struct vfio_pci_core_device; +struct vfio_pci_core_device_ser; struct vfio_pci_region; struct p2pdma_provider; struct dma_buf_attachment; @@ -142,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; }; enum vfio_pci_io_width { -- 2.53.0.983.g0bb29b3bc5-goog