From nobody Thu Apr 2 22:03:12 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 655FC39184E for ; Mon, 23 Mar 2026 23:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310354; cv=none; b=mA7UPbd3njsQFx4GZCujA1JmVb9zk4xVqFzQTv+ivKuVgJ1a9dfl6k1h/REfKCia3Dy0XbSFfQdmvuLW462lUmVqNwSztSw5RTFO9pL7KTuDwp4PyGXFAMxqN7MoJ7Va7Lx+M5Z3h2nFuFzjUjoYOdTHtS+nrt7LjWwWJFiX1s4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774310354; c=relaxed/simple; bh=T10nGtc1MQS8A8zTtf9tLNZQEznWmOM6Cyw8cPMZCmA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lD9PPDD7xk2+OtTfu8jeTtknVnyNmyo0wAjToMsNKXtVnZASCd8v3jR9EatJV04zix5WAoNDELF317Nxrs6gNgIk0aTSk4O2FxnMkQW9XaFYqck864JmGHthfPNlClclu5Dx8mC+LQtmi6bXnt3OGpRndYAl7nmd3kfZi1qPiiQ= 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=cjlBS0z9; arc=none smtp.client-ip=209.85.216.74 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="cjlBS0z9" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-35a1e725a8fso24245747a91.3 for ; Mon, 23 Mar 2026 16:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774310350; x=1774915150; 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=JUFryWFBPXxe6T+DTeCmqMtrNHQ62SSe5LgDU16cd+0=; b=cjlBS0z9u8LTaguUFDgZppTU+iOwkd5MFUWJGKcEUYmEgnpsVnxTZj7/fDl0JluwUd fepN76z/2z2L9cs42K0nzR4cjpQoK/4DWH00ko27wfIbR7l+vv0axGkwtBn9I9I8ffWl NfT+7G2BaDIPsLfidlx/J7J8KZEbdyh1TlYHi00ZnpU608kqX28EyxDCom7CFEiqE4LA CcsltM16jJKJnp3DU/6yhIb1ChZNlXcb8IEFUOMktSk9xOTmSgzPxwzAGAlYizXUg6sd Dh+HZvTInnJ7QlTQvo5vwKCjQpxVvSBCJFU065SaHn9Tdir1gJrFKG4AKdrW+0kxupVb GLsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774310350; x=1774915150; 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=JUFryWFBPXxe6T+DTeCmqMtrNHQ62SSe5LgDU16cd+0=; b=CJQ2afFeBz2Os9btoPrGed4ftG0Ze0gUDqTicmX/CmDHw5ptnLlILRIU9cfsqj6vSt 10xqGH7dOLHazpbLY6ECJYMILhs5OQx7tuWb5/+L8EfQsEXXx2QKPYrdwkCaDXNZrzov qyC5xvTzbiADkaUeJ1eeb2IvCPWEUq8fY166GpVlOwX2Znu6r/h5NsHvnOXWygOQz34q ekcJaNzhkW2yzcymwXCdsUGXGthQFMRuzpGXo4DOyFSzw4PmmsO9HS4oMp6/pT1MbyL3 Qw43Ucw7N5Rbrqi3Vtyz9hVxsAjqpHh6ckxngf6E2J2SQ53pmwbNKsL/73XKQM6Iimn8 ip3w== X-Forwarded-Encrypted: i=1; AJvYcCVAFUf0K9cbI3kNuHDmF2uBsWSJ+c67UjaTOG+0iQNndeP41s7Zx15cRfnhsADkOemSm0xngi3Q0aNBhKo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxy+VuS+/4DuqOtljosRLU3Ou3a5oE/5U3qPSyZOGgso3RSYQNS gtE63scgWQKTSfSHWr0eL0W0oKwgc1xrkKGqAA3hnBhJexsi63tWa96pMCwbc55FM0EfXub6C/N 3jLkMJl6lGXdq+Q== X-Received: from pjub5.prod.google.com ([2002:a17:90a:cc05:b0:359:f1f1:7bcb]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:1c08:b0:35b:e519:213b with SMTP id 98e67ed59e1d1-35be5192186mr4242377a91.30.1774310349283; Mon, 23 Mar 2026 16:59:09 -0700 (PDT) Date: Mon, 23 Mar 2026 23:58:10 +0000 In-Reply-To: <20260323235817.1960573-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: <20260323235817.1960573-1-dmatlack@google.com> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog Message-ID: <20260323235817.1960573-19-dmatlack@google.com> Subject: [PATCH v3 18/24] vfio: selftests: Add vfio_pci_liveupdate_uapi_test 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a selftest to exercise preserving a various VFIO files through /dev/liveupdate. Ensure that VFIO cdev device files can be preserved and everything else (group-based device files, group files, and container files) all fail. Signed-off-by: David Matlack --- tools/testing/selftests/vfio/Makefile | 1 + .../vfio/vfio_pci_liveupdate_uapi_test.c | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_t= est.c diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftest= s/vfio/Makefile index 9d5e390a61b7..5b6e79593555 100644 --- a/tools/testing/selftests/vfio/Makefile +++ b/tools/testing/selftests/vfio/Makefile @@ -12,6 +12,7 @@ TEST_GEN_PROGS +=3D vfio_iommufd_setup_test TEST_GEN_PROGS +=3D vfio_pci_device_test TEST_GEN_PROGS +=3D vfio_pci_device_init_perf_test TEST_GEN_PROGS +=3D vfio_pci_driver_test +TEST_GEN_PROGS +=3D vfio_pci_liveupdate_uapi_test =20 TEST_FILES +=3D scripts/cleanup.sh TEST_FILES +=3D scripts/lib.sh diff --git a/tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c b= /tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c new file mode 100644 index 000000000000..1d89b08ab0a4 --- /dev/null +++ b/tools/testing/selftests/vfio/vfio_pci_liveupdate_uapi_test.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +static const char *device_bdf; + +FIXTURE(vfio_pci_liveupdate_uapi_test) { + int luo_fd; + int session_fd; + struct iommu *iommu; + struct vfio_pci_device *device; +}; + +FIXTURE_VARIANT(vfio_pci_liveupdate_uapi_test) { + const char *iommu_mode; +}; + +#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode) \ +FIXTURE_VARIANT_ADD(vfio_pci_liveupdate_uapi_test, _iommu_mode) { \ + .iommu_mode =3D #_iommu_mode, \ +} + +FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(); +#undef FIXTURE_VARIANT_ADD_IOMMU_MODE + +FIXTURE_SETUP(vfio_pci_liveupdate_uapi_test) +{ + self->luo_fd =3D luo_open_device(); + ASSERT_GE(self->luo_fd, 0); + + self->session_fd =3D luo_create_session(self->luo_fd, "session"); + ASSERT_GE(self->session_fd, 0); + + self->iommu =3D iommu_init(variant->iommu_mode); + self->device =3D vfio_pci_device_init(device_bdf, self->iommu); +} + +FIXTURE_TEARDOWN(vfio_pci_liveupdate_uapi_test) +{ + vfio_pci_device_cleanup(self->device); + iommu_cleanup(self->iommu); + close(self->session_fd); + close(self->luo_fd); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_device) +{ + int ret; + + ret =3D luo_session_preserve_fd(self->session_fd, self->device->fd, 0); + + /* Preservation should only be supported for VFIO cdev files. */ + ASSERT_EQ(ret, self->iommu->iommufd ? 0 : -ENOENT); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_group_fails) +{ + int ret; + + if (self->iommu->iommufd) + SKIP(return, "iommufd-mode does not have group files"); + + ret =3D luo_session_preserve_fd(self->session_fd, self->device->group_fd,= 0); + ASSERT_EQ(ret, -ENOENT); +} + +TEST_F(vfio_pci_liveupdate_uapi_test, preserve_container_fails) +{ + int ret; + + if (self->iommu->iommufd) + SKIP(return, "iommufd-mode does not have container files"); + + ret =3D luo_session_preserve_fd(self->session_fd, self->iommu->container_= fd, 0); + ASSERT_EQ(ret, -ENOENT); +} + +int main(int argc, char *argv[]) +{ + int fd; + + fd =3D luo_open_device(); + if (fd < 0) + ksft_exit_skip("open(%s) failed: %s, skipping\n", + LUO_DEVICE, strerror(errno)); + + close(fd); + + device_bdf =3D vfio_selftests_get_bdf(&argc, argv); + return test_harness_run(argc, argv); +} --=20 2.53.0.983.g0bb29b3bc5-goog