From nobody Mon Feb 9 04:14:36 2026 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 6B553185E4A for ; Sat, 18 Oct 2025 00:07:34 +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=1760746056; cv=none; b=ekfVF0SfcW5zxgqeNnNrLqEtbLgn3CoSbgab3SV/U6w8e4pJW7ReU9fL+ybAXZRABZPX/jIHBx+D2QMB2K+BAJ3OzEPC2tgHGjwgsix4ZZxPyepWVNk4b9P2HB8YYBEoshpUeDSdShEMQ2blUX7oSPR5Enz4pKgsR3osLDCenWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760746056; c=relaxed/simple; bh=Vz1emZSFssQs0+YdiAhMnV1XqK+h1rcwL5bhHE+USAs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PDCqObNwC3fqPRok34dhSW78E0HRKLpslHCo6X1V0iw7T6pt9xTlxyt5ZEuznbsrUbHhBQMUrmf0v9BE1p0w/aSs6A1n5udMxjXK7yIyLvJOTJfY4np0esZDcDQpCYklIB3X+WLRaDDj2E/2ABawm7kOlIoy7orgh6hEhkgRM+0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--vipinsh.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=r/fvEjjf; 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--vipinsh.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="r/fvEjjf" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-28a5b8b12bbso54595835ad.2 for ; Fri, 17 Oct 2025 17:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760746054; x=1761350854; 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=yIRcwATFxVO1gYHmeyRDqu9oMXg8jJOvYeDFaGHRVhk=; b=r/fvEjjfsCtoWhCTv0je1iCzroYsxTgEp0bbQWgUb3cvfj6N2fEqhdisCsqXP21dFp Y8mL0b8cCufcQrlc3Wf9Pqr+T/XoiGCOpo1KJg4gadjISsjD7ry3thvZkpG80lfvhaVB X9LPTx8+r+k30DIILkPHKZWm1OCAckqQzShDeeBf6/cA5PXzdPU0Rvjhy4ejIqO7n5BY pDf/CsWVZbCB23Jv9eLAU2TR5P91vkoJadEPEkdU3gtM/HvCirB9NFarP68Kka4uDftz 2wflEk8a3LnC/pGxbSYdx2mMFapkO9pmDGkY6ePm3bCI6+ztH64MieEtTVEEnNjWkXq8 q/ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760746054; x=1761350854; 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=yIRcwATFxVO1gYHmeyRDqu9oMXg8jJOvYeDFaGHRVhk=; b=IiDlFomwlQfRhnlw6vVIInnuW9IXXJXX0pJ3plZK6ODY7ZU1V16tyrA88ajlcmRTuO lo6e2C8BSAsdyEy/dKPfLxumD4xMq0XLWuT0vgoUa0PndGKOn6ShkKtmxYMcS3sunzlC PJDYzCavBdiSXhtFForvzLv1eOIezwmCB8mTU1ablEa0vNpmgm3v7KvNtY1T+xJ9z312 wm++gLN2apYZFgvB+kvhlCyJZMJfym4PkK6yyM4OpdNe8o1X1cJJS971UcXN2IhjTxNg IkZPetMogw3vQWmvO4AU6C4sRJMB2G9tP7PgqRI23FsF8cD8S/nZLIWsPKPz/Bq6TTMK 2Img== X-Forwarded-Encrypted: i=1; AJvYcCVaRnfbZMrPhKFIKJr9L+3zLKnjaqJ5xw+mHhovOsWjzkDKBvzU0hF0+mrkfToqNtNWCmNCLWABtP3G69Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yzat7jcHAzN4/uDKKFZtR7P74h57AlT19oFMCmhyq/8S/SaEBKE o01tsM9+7Q/E5tGeJe40KJ1Ms+lcEy1Gfepmffpz1JeymBlCpFbagBuS7+CzIs/EGEKWfA1Wuu6 NafUht+LZdw== X-Google-Smtp-Source: AGHT+IEmJd19+BB5PjOWAQmwa3QYicq41jg2KgMlRdI0Qd+a/0AOATqoFt4XxbQkB/KEUkYDvJMU7BdKVEY5 X-Received: from pllb6.prod.google.com ([2002:a17:902:e946:b0:290:bbbe:b3d4]) (user=vipinsh job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1106:b0:27e:f07c:8413 with SMTP id d9443c01a7336-290c9cf8f3amr67057365ad.9.1760746053570; Fri, 17 Oct 2025 17:07:33 -0700 (PDT) Date: Fri, 17 Oct 2025 17:06:58 -0700 In-Reply-To: <20251018000713.677779-1-vipinsh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251018000713.677779-1-vipinsh@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251018000713.677779-7-vipinsh@google.com> Subject: [RFC PATCH 06/21] vfio/pci: Accept live update preservation request for VFIO cdev From: Vipin Sharma To: bhelgaas@google.com, alex.williamson@redhat.com, pasha.tatashin@soleen.com, dmatlack@google.com, jgg@ziepe.ca, graf@amazon.com Cc: pratyush@kernel.org, gregkh@linuxfoundation.org, chrisl@kernel.org, rppt@kernel.org, skhawaja@google.com, parav@nvidia.com, saeedm@nvidia.com, kevin.tian@intel.com, jrhilke@google.com, david@redhat.com, jgowans@amazon.com, dwmw2@infradead.org, epetron@amazon.de, junaids@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Return true in can_preserve() callback of live update file handler, if VFIO can preserve the passed VFIO cdev file. Return -EOPNOTSUPP from prepare() callback for now to fail any attempt to preserve VFIO cdev in live update. The VFIO cdev opened check ensures that the file is actually used for VFIO cdev and not for VFIO device FD which can be obtained from the VFIO group. Returning true from can_preserve() tells Live Update Orchestrator that VFIO can try to preserve the given file during live update. Actual preservation logic will be added in future patches, therefore, for now, prepare call will fail. Signed-off-by: Vipin Sharma --- drivers/vfio/pci/vfio_pci_liveupdate.c | 16 +++++++++++++++- drivers/vfio/vfio_main.c | 3 ++- include/linux/vfio.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio= _pci_liveupdate.c index 088f7698a72c..2ce2c11cb51c 100644 --- a/drivers/vfio/pci/vfio_pci_liveupdate.c +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c @@ -8,10 +8,17 @@ */ =20 #include +#include #include =20 #include "vfio_pci_priv.h" =20 +static int vfio_pci_liveupdate_prepare(struct liveupdate_file_handler *han= dler, + struct file *file, u64 *data) +{ + return -EOPNOTSUPP; +} + static int vfio_pci_liveupdate_retrieve(struct liveupdate_file_handler *ha= ndler, u64 data, struct file **file) { @@ -21,10 +28,17 @@ static int vfio_pci_liveupdate_retrieve(struct liveupda= te_file_handler *handler, static bool vfio_pci_liveupdate_can_preserve(struct liveupdate_file_handle= r *handler, struct file *file) { - return -EOPNOTSUPP; + struct vfio_device *device =3D vfio_device_from_file(file); + + if (!device) + return false; + + guard(mutex)(&device->dev_set->lock); + return vfio_device_cdev_opened(device); } =20 static const struct liveupdate_file_ops vfio_pci_luo_fops =3D { + .prepare =3D vfio_pci_liveupdate_prepare, .retrieve =3D vfio_pci_liveupdate_retrieve, .can_preserve =3D vfio_pci_liveupdate_can_preserve, .owner =3D THIS_MODULE, diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 38c8e9350a60..4cb47c1564f4 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1386,7 +1386,7 @@ const struct file_operations vfio_device_fops =3D { #endif }; =20 -static struct vfio_device *vfio_device_from_file(struct file *file) +struct vfio_device *vfio_device_from_file(struct file *file) { struct vfio_device_file *df =3D file->private_data; =20 @@ -1394,6 +1394,7 @@ static struct vfio_device *vfio_device_from_file(stru= ct file *file) return NULL; return df->device; } +EXPORT_SYMBOL_GPL(vfio_device_from_file); =20 /** * vfio_file_is_valid - True if the file is valid vfio file diff --git a/include/linux/vfio.h b/include/linux/vfio.h index eb563f538dee..2443d24aa237 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -385,4 +385,6 @@ int vfio_virqfd_enable(void *opaque, int (*handler)(voi= d *, void *), void vfio_virqfd_disable(struct virqfd **pvirqfd); void vfio_virqfd_flush_thread(struct virqfd **pvirqfd); =20 +struct vfio_device *vfio_device_from_file(struct file *file); + #endif /* VFIO_H */ --=20 2.51.0.858.gf9c4a03a3a-goog