From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793985573; b=qvLBCUaSac0D9iTAu6Zq8UXXGQ+a32AMiz5vdGfI7xneIna3Oyf511T/BlKVDQlBg1lw u9i4+iQfdcEPoms4BJ79ETKSk94rKQexfxKzB+aM4GUJUps+50Hpl6FeRS17ERlVeoRYM TMgYdbNK1Dku55kz41uR3smrtf2LGbFjYXnQhEi9fcep+60GLCZPJIg2DAq5tF8DVOKPT N32U+2JlAyi8qGkkZeIEH6OaNr9SjndIvWbJJ35WpuHIf3Z6y0zqWIxxKzjZ3VZ+rw7SG gujzpmPGmVCThvzUrkj6H5jZZaWvV93ccCK85WP+YQbhznfuY32QH0UNwfrrImlcb4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793985573; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id: Subject:From:To:Cc:X-Mailer:References:In-Reply-To; bh=tEaeh2MQM8Yqh+InUxWcP/c3Ugn8r1gCgilB/e+XZTU=; b=oojdli/5+u0blN9h/vEmTnPRi/ieUYez3yjKZlTyb6I++PbCjc6zCA82+tF3Q/kKEekY sR2Ua2tkCQRWifYbyfCCj30IQG+Zipqdb3d+PJckLABMNs3If6X3FAkerUD9JCMboPELL jJ8QAj8vrxO+iYvxUYfUIRNmf134gfB0R2rkVebfR3a7evchre5nIuJmbxkCBj8u4uCRR exRRWEYEIjKAsWKCK9OKe10+TSDLw4FpJbzKooWCi3SMqm5hYdnYNDF84osWKFxS1QA/z XKatAwi9+j75UBJJJgLe7kYlNTlsBXqdSfaqPFZ5UHfq0TAlF0oECLI662zNHs8MT0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=V3vuG2QG; arc=none smtp.remote-ip=209.85.216.47 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDDFA606A32D for ; Fri, 6 Nov 2026 17:19:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CDDFA606A32D 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=V3vuG2QG Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3b0d0b80fb9so551629a91.1 for ; Fri, 06 Nov 2026 09:19:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793985572; x=1794590372; darn=vger.kernel.org; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=tEaeh2MQM8Yqh+InUxWcP/c3Ugn8r1gCgilB/e+XZTU=; b=V3vuG2QGjhL8r2VuA4Y+96OnzymPavm7o7EgEyvr170YdIQ6DRl7oV53qhL1GcFHq9 pAuFDTumBKjC04cfsqiF/s9mzLQ7MxMB33+iWjjD6M/c6YfzXCbLDc+N7vG+f5wRPHnt YGfusFO0BTgDqxJC3GAGWNZSjKJIGzOR0waqOm65uqs4mfbkFPtcjPreR4HJO5uzAwIM aZJqv3Eu06A17GOsAL38uxdtzasGV3QnNWGft1JdKGB0XYClaHm6eqK5tjUpWsaDDnGv L3j4WwyzVfe0Q7LrBT5u/+m8/nbkT0KO2eRt94r5hQOTgl8rRxeGomxzWEId9K33GS3u IwQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793985572; x=1794590372; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tEaeh2MQM8Yqh+InUxWcP/c3Ugn8r1gCgilB/e+XZTU=; b=s7kgc5guZGMthUJTUX9BDp8iRu/VFXiSHsX1fd2SSZUIRCoMOKoOBVkGKtEMIt/hOV z0le9HxfKuh6rMsZam+XcIycuBwyv2dDrkWA2g3oNueGXmDyBJyqIgOt2LTNdviFAoKR e1Nk2fppvPEH+BtYe4l8GBW/Q2Izm+89V6dZ+c+4U5+dWpIEF+Vm27QLOQ8z5GiaI7Nu wLp3qvG/SPK9w+Sc1tNsfc5fa3VL7QKzapYPu4uvR5kJuHnC98BAnvWNO3jDVxD0rlAH NGJMYR+x177rZ2tBnHDiy7sbF4QUeEprHucL9ARorE90lOhuXXbnf1bRE7gH5/g61Mf/ +3Jg== X-Forwarded-Encrypted: i=1; AL+hErFWfvuGaR+9nbv+JPABs0Vnkm0GMIX06GizAwCbdn+GEn6b5XL6+wyKy+D4InTs20nUiV8RfThLiRRJhyWHs0M=@vger.kernel.org X-Gm-Message-State: APuU4Z+zRvCYuhSLgEAFm1QF1YYrHxw08RXn+x5uadHYAnVsLF5lwPid BIEkp2eYsaUDwd9rbdrxrq6XijexMZTKNVaoe5oKHXG79fObyGxB7xxeEKQ2ffvtlA== X-Gm-Gg: AYBFou37qNWnhOiKnd6oY/bTf2Wv22MfxOtF2eQQc0+QLuC8e2GUUmLiRFT0T2o8RtC tjjVeyCFck4WfIYfJezHmcG8/U9CURpSMeXftWtX+eavLFSzqM4PAthcOeUZz6wckrSuus3XPKU dyO2ZCrF/JqJC/iCKRXSckEH3Cz9fXL7GbDzkQ8SwLzYVB2PU3VrUcKPjsMviZd3lBszDmrDB6O i1+HLv3FPZ/PLcIebhverL1TbUwqEBuHF5ANNj0DC7T7vtbIWWMC2V5qx/C8j94zvj+6x1bW4Kl rCEr2/NlhCDXaP38zFrX1RoEA7aq+Po77tmmHn94dtMj2H6Q+3or23TnZyTWNqjqQO2hz4VjAKf D5Judzx11VM2e1QIJqJTLoCoqAkOVnbGvPdwEa+jIhxSngMyA2Igbgb0bPXsLUHGxloBMc5zPLD RzzKUBBhqrf9pfheQBvJv7phrL49/EiL6ftwxSG2GdiDcLxZqwX96PftMmNSM+oTfMaijEtroiJ OOXeWqPcFmy+AHwF/fKIxBXVaufJ+/KSobfb6f73qaQPLDNC3jrUa2odkWODF+EvYMHq3YRZmXj mO6yd9ZeYVJRde2BuE02GASa9XtyFseaiebZVwPIMdUw/3BUrxmWiGZGi9NlMLh4 X-Received: by 2002:a17:90b:554d:b0:3ac:bfa7:b079 with SMTP id 98e67ed59e1d1-3b0db5edb73mr3411640a91.7.1793985571464; Fri, 06 Nov 2026 09:19:31 -0800 (PST) Received: from localhost (33.79.127.34.bc.googleusercontent.com. [34.127.79.33]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cdb70a7fbcbsm795231a12.25.2026.11.06.09.19.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Nov 2026 09:19:29 -0800 (PST) X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 06 Nov 2026 17:19:28 +0000 Message-Id: Subject: Re: [PATCH v6 11/27] vfio/pci: Retrieve preserved device files after Live Update From: "David Matlack" To: "Vipin Sharma" , , , , , , , Cc: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , X-Mailer: aerc 0.21.0 References: <20261102153656.1431701-1-vipinsh@google.com> <20261102153656.1431701-12-vipinsh@google.com> In-Reply-To: <20261102153656.1431701-12-vipinsh@google.com> On Mon Nov 2, 2026 at 3:36 PM UTC, Vipin Sharma wrote: > During retrieve(): > * Validate the handed-over struct vfio_pci_core_device_ser header, > sizes, and flags. > * Locate the registered vfio-pci device matching the serialized domain > and BDF (requiring device->ops =3D=3D &vfio_pci_ops) under the device > lock. vfio-pci registers the vfio device before its probe completes, > and the probe holds that lock, so a device that is still being probed > is not returned. [...] > * Open and return an anonymous VFIO cdev file via > vfio_device_liveupdate_cdev_open(). Here's an idea for how the device file could be created on retrieve, which I'd like to hear your thoughts on. The patches from Pasha at [1] lets userspace pass a file-handler-specific argument to LIVEUPDATE_SESSION_RETRIEVE_FD. In the next version of the tmpfs series, I'm planning to use that to have userspace create the file and pass it in the argument, and the kernel then restores the preserved file into it. I wonder if VFIO should work the same way, e.g.: struct liveupdate_vfio_retrieve_arg { __u32 size; __s32 fd; }; Userspace would open /dev/vfio/devices/noiommu-vfioX itself and pass the fd. retrieve() would check that it's an unbound vfio-pci cdev file for the preserved device (domain/BDF, noiommu, incoming, cfg_size), attach the incoming state to that file, and LUO would track that file as the retrieved file. VFIO_DEVICE_BIND_IOMMUFD would then take over the device as it does now. Since VFIO preservation is new, the argument could simply be required. I think this could get rid of some of the special handling: - There'd be no need to fake a cdev open with an anonymous inode, so PATCH 09 and PATCH 10 could probably be dropped. - retrieve() wouldn't need to look up the device by BDF, or reason about racing with probe under the device lock. If userspace was able to open the cdev, the device is registered and probed. - The device file would be opened through the normal cdev path, so the usual permission and LSM checks on the device node would apply. - It would be the same model across file types. A few things I think would need care if you go this way. The file check and the attach would need to happen under dev_set->lock so they can't race with a concurrent VFIO_DEVICE_BIND_IOMMUFD on the same fd. And the incoming state should probably be tied to that specific vfio_device_file rather than just the vdev, so only the file passed to RETRIEVE_FD can take over the device. It would also change PATCH 12. Opening the cdev of an incoming device would have to succeed, so the check would move to the first open of the device instead: fail with -EBUSY if the device is incoming and the file being bound doesn't have the incoming state attached. That one check in vfio-pci would also cover VFIO_GROUP_GET_DEVICE_FD, which opens the device right away, so vfio_liveupdate_incoming_is_preserved() and its dev_is_pci() special case could be dropped from the VFIO core. The next tmpfs version will also add a way for a file handler to say a failed retrieve can be retried, and a helper to claim an existing file before restoring into it (so a file LUO already manages, e.g. one that is preserved in an outgoing session, is rejected). Both seem useful here too, e.g. so that a mistake in the argument (wrong fd, an fd for another device, an already bound fd) doesn't make the device unretrievable. I'll Cc you when I send it, and I'm happy to share the branch before then. What do you think? [1] https://lore.kernel.org/kexec/20261103010216.3447716-1-dmatlack@google.= com/