From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 673B244D693 for ; Mon, 18 May 2026 16:47:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779122840; cv=none; b=Mi7oJbicHbyMIeHc1hU3Sv4F6HF3shM9Td0CTe7QqSV4fgahsBAIY00W+D6IVBdMo8/UWy8B0cujabz17Vx4FEl93O+id9VO4a2HJl8JWlTQpPm9/Y0embOH0X8VWVkPK5WerI81bcjY/dhslJ7CeJvzRUYlzwOU4PRDiSx3xM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779122840; c=relaxed/simple; bh=uZJ/xSOMto8dGbxnTVpZw9SBqppTOhKt7BGw30Zdg+A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uZFgytV+XIBdgusEGW/vPxtBfcfM1F/ZW0DOROY1uRWiVGkxkZXQpZaYlV7z+Q6L/vydIT1R3NdHh/1DpSsyETFJmB4Qg7l0IlDKQO+/CxdhjkPVluvdZYOhZxZEY2kqeWSzLlLI9fRCyqElehetvsBxJjEpEr9pN8wDgn4syG8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nKukTcqo; arc=none smtp.client-ip=209.85.214.177 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nKukTcqo" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ba3b9bcf69so305ad.0 for ; Mon, 18 May 2026 09:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779122838; x=1779727638; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=fRb534kT/Y8t4mzJvcjyqqGoTPac4Acgjf8YBCzvDuA=; b=nKukTcqo6THU3OJrpAZjK+bkMEcD/wiQoHRer+Og2CBzHbtgb4Sxvj6QI0GyTuQyoH c45n5GNsFhUTLX42jW7A1iDGbJzepcqxkrQnL8ZYFZ9/2sleWwKrNS44PGA1MNTwiYV4 RN/QCeg87CWqEBqb9FBJ6AE1L8SB7Zb+Fic1/gahaHux++tEmJS5cs4fkZUBx4V88e39 FrejJ/ET+aasIe8L3bLmMBbBvW+Mp/rSNoJnoi3Jt5uTg31e3nRPIW88BBcJKUEhPucU Ko4KIVt0GjTqhxfGBGz8e5dqiuEfPvnhECe+0LvEPS4MH/r86qWzgr8wBfcY2bJApQg6 pVcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779122838; x=1779727638; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fRb534kT/Y8t4mzJvcjyqqGoTPac4Acgjf8YBCzvDuA=; b=HOf+8swI/1PYV9qn6kIorWxek6g3u/CXIG3OLNYyf2zDMf9+5hbTaPMOgmbMmLyvm7 94BkTqMqQ+Ak3o8LBp2q/ozHRje4zRYQaO2c0zgcXGAS/IsHkDzRZHmDaV4P/KqoFLJK 7eJw+nzFTqq2QyFPHgfRAGGRI7hhIV/CVh+0j2QKU5NiieAC+y0DXlzQZWdvUPkdewPx 7joHYfHrplmlL2cjMDRKkQfSnqAmK/2d5LK0+TPJefuPT1N4Gg7CAYBZ6aQqsBNqJqyL SOvMWxfcEjHxyrWksm9O/ekA02hdzg8SlJi/KNaDsstxGPOFVB7QK8Ba2O+PKj9/laUz fvLw== X-Forwarded-Encrypted: i=1; AFNElJ+G9bTM7pjNXTA9FaiRk8dP+7RsMPqywerbRfujrkeBMwvqjBOhJNKYpWiaG3m3+uL7/lmn5Xruk+QptJ8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxery0CuE4o8ZjJyOzO+x7xefR5EMfPAlf20PgNFOrQTDrfE/Zi 2IL33M/V8PX72WrwjW75j+QwyhdaB96jGrxafNw9CJKJZZV/s0dv5ag9Tl0uKdw5Qg== X-Gm-Gg: Acq92OHqSpj/aIUFp2QQJVbiVi6BG6v77YgTd7nBgg2p+oSsFEtjSxUSDeEngVH66/D fB5aB4EFfHnZTZI3c1gG1Ph6zLAKpND9kRw+6Q0Zxu0OWUwWR/lE+Fo4MrxAHxQs3Dv2HyYXOAR fJGuCIchGxzrr1woxl5O3dajxoq7fvnD9IXXdpwYoDiUtannAaWGWbqhhdgyp6wbsL33xTCqc8S iP72xXFqC953Ph2BuqZCAOt15rLqGb9rM7DBdoSVXcCys0Q6IhFXFXTqSkupub8tMEJ+UuJXHuH 5am1RZKVwr5+mePye3gsCZVepuEJSDaB73Z7zcIgwMR88UPg+3DRAQxhQeIsibFbX7sfLRGSJzd 3NTB8n1wJ4dbR3onRfyrop1Xorn8V6rVtn9DcjqShk1I97hbokcx2rkT3svysPOR/5ZbiQ8mN6e 7tI+w3M1PQR68qIMs3JuJNKebcoIZ9P+ihb3j4dUhXdrR50RR3F6DUk3/DhNac54qZyP5fEV8= X-Received: by 2002:a17:902:e550:b0:2b4:6153:e541 with SMTP id d9443c01a7336-2bdb3064621mr2846235ad.3.1779122837181; Mon, 18 May 2026 09:47:17 -0700 (PDT) Received: from google.com (176.13.105.34.bc.googleusercontent.com. [34.105.13.176]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bafb0a3esm14196811a12.0.2026.05.18.09.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 09:47:16 -0700 (PDT) Date: Mon, 18 May 2026 09:47:12 -0700 From: Vipin Sharma To: Zhu Yanjun Cc: kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-pci@vger.kernel.org, ajayachandra@nvidia.com, alex@shazbot.org, amastro@fb.com, ankita@nvidia.com, apopple@nvidia.com, chrisl@kernel.org, corbet@lwn.net, dmatlack@google.com, graf@amazon.com, jacob.pan@linux.microsoft.com, jgg@nvidia.com, jgg@ziepe.ca, jrhilke@google.com, julianr@linux.ibm.com, kevin.tian@intel.com, leon@kernel.org, leonro@nvidia.com, lukas@wunner.de, michal.winiarski@intel.com, parav@nvidia.com, pasha.tatashin@soleen.com, praan@google.com, pratyush@kernel.org, rananta@google.com, rientjes@google.com, rodrigo.vivi@intel.com, rppt@kernel.org, saeedm@nvidia.com, skhan@linuxfoundation.org, skhawaja@google.com, vivek.kasireddy@intel.com, witu@nvidia.com, yi.l.liu@intel.com Subject: Re: [PATCH v4 05/16] vfio: Enforce preserved devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD Message-ID: <20260518164045.GB3281683.vipinsh@google.com> References: <20260511234802.2280368-1-vipinsh@google.com> <20260511234802.2280368-6-vipinsh@google.com> <65228806-6ed3-4577-9037-13fd5eb8f9b6@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <65228806-6ed3-4577-9037-13fd5eb8f9b6@linux.dev> On Sun, May 17, 2026 at 12:04:04PM -0700, Zhu Yanjun wrote: > > 在 2026/5/11 16:47, Vipin Sharma 写道: > > From: David Matlack > > > > Enforce that files for incoming (preserved by previous kernel) VFIO > > devices are retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD rather than by > > opening the corresponding VFIO character device or via > > VFIO_GROUP_GET_DEVICE_FD. > > > > Both of these methods would result in VFIO initializing the device > > without access to the preserved state of the device passed by the > > previous kernel. > > > > Reviewed-by: Pranjal Shrivastava > > Signed-off-by: David Matlack > > Co-developed-by: Vipin Sharma > > Signed-off-by: Vipin Sharma > > --- > > drivers/vfio/device_cdev.c | 8 ++++++++ > > drivers/vfio/group.c | 9 +++++++++ > > drivers/vfio/pci/vfio_pci_liveupdate.c | 6 ++++++ > > drivers/vfio/vfio.h | 18 ++++++++++++++++++ > > 4 files changed, 41 insertions(+) > > > > diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c > > index 1ab07ccaf3ab..4df0495941c6 100644 > > --- a/drivers/vfio/device_cdev.c > > +++ b/drivers/vfio/device_cdev.c > > @@ -49,6 +49,14 @@ static int vfio_device_cdev_open(struct vfio_device *device, struct file **filep > > } > > *filep = file; > > + } else if (vfio_liveupdate_incoming_is_preserved(device)) { > > + /* > > + * Since it is live update preserved device, it must be > > + * retrieved via LIVEUPDATE_SESSION_RETRIEVE_FD instead of > > + * opening /dev/vfio/devices/vfioX. > > + */ > > + ret = -EBUSY; > > + goto err_free_device_file; > > When vfio_liveupdate_incoming_is_preserved(device) returns true, > vfio_device_put_registration(device) is not called in this path. > > Is vfio_device_put_registration(device) instead invoked from the > err_free_device_file error handling path? Yes, at the end of vfio_device_cdev_open(), goto label first frees the device file object and then calls the vfio_device_put_registration(). This is the same error handlign flow as in the if(!file) {} code in the above function.