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 B555634402F for ; Wed, 26 Nov 2025 19:36:22 +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=1764185784; cv=none; b=cAYYCLHlt1tWqFjRRveOqu9tejL3wm2wAkgUOqtkjLlCBJLfRQo/F0OqLWW8kI9WpUaEk6BkEoHGM5kd/SdVE+BM7s41VbiyVc3R3U5UJE/PabWzO7Bser4nkjlRyreUk5Lp5OvRZGrMrpJYls+oHPQMgERQ3fF5ELmHQZNwdhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764185784; c=relaxed/simple; bh=HzMrzWRCLtgSmquMMa2P4U7RJKBy8Y6HK2PaCjHpnGw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZpGKl2pb8kmF/cN2nFa64vRNWzShCF7Jv9SFN9pYtHHTjIxXxpMlW2sl4xyHS/8KdSw/d03q+SRyL3o/VDjg6PJTTWUx2zoI2OQdkauAYEz/CzCih2mKi8n3jSGu3joKLuI2dw0XlxxD5ZamvnMjdKazqxy8YwdY1wxX1HEIH0Y= 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=KjLgK782; 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="KjLgK782" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-297dde580c8so3707055ad.1 for ; Wed, 26 Nov 2025 11:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764185782; x=1764790582; 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=Oq/yr6BWXlg1Xcrv4iWHhg15TfmkXzU0vPtqwC0SJKQ=; b=KjLgK782aOUBR9A8sLsTlj9ZVqmwzXa6sndJ6BVc6Ymg+Z4ej4B4qo8prYXdW0dCjW OaVzINZquF6F21gmQHkwqH7FTDx5GVAwNqcxlD6cIG8gFemTVA069qzvZLo3d2B0t3oR lVzxIsoS87jQufLANOOrun2IoZIcN10BiTeMLS/yIog8LC/T+z2wSb3i3jXxG4O53E3A WHg6Z0ijzn+XDpFIecUzw6/HeeCRldYnEgt5+Ni6MSGhUYeddVss04W79iI9sefyF6bT aPUX6RH3m+Llj4SaGM/TkDTVqcfclb85+vLb44i6uPKBYPCm000PSGv4MCw4b296TNKA OR4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764185782; x=1764790582; 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=Oq/yr6BWXlg1Xcrv4iWHhg15TfmkXzU0vPtqwC0SJKQ=; b=onn5CvL3w88H9BxRQsBCt0JHiVkPoFq+QInCwFIq7zweU3wi/Brfvwv7iN5JTdOWVD DYr4ftNgFtsAprdPyJFVjDCrvnJR2Ch0L+P0EOHMuzYcxVYGUaFj0MFbkcTtg36p0TUv NmZcwl8rRjqY8Otp20Svb0Ndi20yyrLFaumnYevUN2dn/9Ta83uHSv1GB4/qOgGZupOA U4EfhZqsf0PZD78WiKRLQDIpYlb7/jMnS9tKF7jUCjrnbLqwF3yxjSmmjyWKBTikAL/W uCtUCCU3tVYFpPsv/ftQcE+Yjl0K4Z+rljeaavlMUgo+pVP6cNB4bqYrkn5ZroD7JNZU KvYQ== X-Forwarded-Encrypted: i=1; AJvYcCVmArsxg/On92yLbLtCkKDvKu7fnkv/OUKM6W2/JG7/dufLEx4SlkU7N566ufrHQKr/SirIq5aEHLLf+MA=@vger.kernel.org X-Gm-Message-State: AOJu0YzNkuej0s1BYVDtHJ9qBqmcdioFE599n6dRwQssJNijyZmIJONQ TScmp/M7BSoeWoG0ldLKNBDYltyhkB80hJGhaKcQjZnH16xHiY3jTE79j25tTNa3X1Tlcdmb3eG 5BBMbLB/BhDPL9Q== X-Google-Smtp-Source: AGHT+IFWOeNwF25aWnbYsfeGo4vdcfOTzNrl8hAriCkFnQsDtZekeoeRfF6D6GNT5dSECm+ci49u7/PdsBRstw== X-Received: from plblq5.prod.google.com ([2002:a17:903:1445:b0:268:4e0:9c09]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:dac3:b0:299:e031:16d with SMTP id d9443c01a7336-29bab148c3emr87405365ad.33.1764185782017; Wed, 26 Nov 2025 11:36:22 -0800 (PST) Date: Wed, 26 Nov 2025 19:35:54 +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-8-dmatlack@google.com> Subject: [PATCH 07/21] vfio/pci: Notify PCI subsystem about devices preserved across Live Update 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" Notify the PCI subsystem about devices vfio-pci is preserving across Live Update by registering the vfio-pci liveupdate file handler with the PCI subsystem's FLB handler. Notably this will ensure that devices preserved through vfio-pci do not go through auto-probing in the next kernel (i.e. preventing them from being bound to a different driver). This also enables VFIO to detect that a device was preserved before userspace first retrieves the file from it, which will be used in subsequent commits. Signed-off-by: David Matlack --- drivers/vfio/pci/vfio_pci_liveupdate.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index b7451007fca4..7669c65bde17 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -64,6 +64,7 @@ static int vfio_pci_liveupdate_preserve(struct liveupdate= _file_op_args *args) if (err) goto error; =20 + pci_liveupdate_outgoing_preserve(pdev); args->serialized_data =3D virt_to_phys(ser); return 0; =20 @@ -75,8 +76,10 @@ 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_pci_core_device_ser *ser =3D phys_to_virt(args->serialized_da= ta); + struct vfio_device *device =3D vfio_device_from_file(args->file); struct folio *folio =3D virt_to_folio(ser); =20 + pci_liveupdate_outgoing_unpreserve(to_pci_dev(device->dev)); kho_unpreserve_folio(folio); folio_put(folio); } @@ -199,8 +202,11 @@ static bool vfio_pci_liveupdate_can_finish(struct live= update_file_op_args *args) =20 static void vfio_pci_liveupdate_finish(struct liveupdate_file_op_args *arg= s) { + struct vfio_device *device =3D vfio_device_from_file(args->file); struct folio *folio; =20 + pci_liveupdate_incoming_finish(to_pci_dev(device->dev)); + folio =3D virt_to_folio(phys_to_virt(args->serialized_data)); folio_put(folio); } @@ -223,10 +229,24 @@ static struct liveupdate_file_handler vfio_pci_liveup= date_fh =3D { =20 int __init vfio_pci_liveupdate_init(void) { + int ret; + if (!liveupdate_enabled()) return 0; =20 - return liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); + ret =3D liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); + if (ret) + return ret; + + ret =3D pci_liveupdate_register_fh(&vfio_pci_liveupdate_fh); + if (ret) + goto error; + + return 0; + +error: + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); + return ret; } =20 void vfio_pci_liveupdate_cleanup(void) @@ -234,5 +254,6 @@ void vfio_pci_liveupdate_cleanup(void) if (!liveupdate_enabled()) return; =20 + WARN_ON_ONCE(pci_liveupdate_unregister_fh(&vfio_pci_liveupdate_fh)); liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); } --=20 2.52.0.487.g5c8c507ade-goog