From nobody Tue Apr 7 16:13:27 2026 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81F1F3DA7E2 for ; Thu, 12 Mar 2026 15:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773331015; cv=none; b=Cm5lwxRlQ/CacuB7AqS6B80Pdrm6r2hwURdcjyzasyEBcD92RwZ1rzfJS5CSPZp2hBC6+eCqdkJ0tdai4XYfWyLm1y3Rd0B21HZqUMP/RIbrCJ1Wd44RxmgAn/YOHwquTN2ZI1i0sIw/6xRhpjNWyfT0OXWOo1zDLiB8Vx5f7Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773331015; c=relaxed/simple; bh=Yfl32e/wH1s1fkSBmCkA0l5uMrhboi+dTtlW0Ww5QD4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=THYHmiug+MKn2GwQZI9bAnq8C9xeRFWhgA47SPUqw6xAFuBZHfeuzSBHS4PX5hb8z2HBvh+cvjC/8LhDGtQkQVvrUzP+JqOOMp++si5YlrY5oNv3uzkcyTg3FKgycLBQoESIezpdRyGkXsF9KInp275fFUmPlK9h9W3YF9r+zyg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Sp6dT90h; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Sp6dT90h" Received: from DESKTOP-0403QTC.corp.microsoft.com (unknown [52.148.138.235]) by linux.microsoft.com (Postfix) with ESMTPSA id EFC4B20B6F15; Thu, 12 Mar 2026 08:56:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EFC4B20B6F15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1773331013; bh=6C5HqNSNlEXnphrTuI5WMJTUuVyBmzclsZEl1pFAJmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sp6dT90he5TB472gC+2sQoU1xJirIipV0ygV75bDlFlyCl3Su0+45XCgHZumUDQDc BAZPwgtztN9dJt0OwzN6o/yt2WatoNlbNJlmCbqnW1ZiVvKA2jeelORU5lKZTGnX4q SBqPtIkHsFY7z85Z0MTGWB/2IF0uPFLmjtsEEvMI= From: Jacob Pan To: linux-kernel@vger.kernel.org, "iommu@lists.linux.dev" , Jason Gunthorpe , Alex Williamson , Joerg Roedel , David Matlack , Robin Murphy , Nicolin Chen , "Tian, Kevin" , Yi Liu Cc: skhawaja@google.com, pasha.tatashin@soleen.com, Will Deacon , Jacob Pan , Baolu Lu Subject: [PATCH V2 09/11] vfio:selftest: Handle VFIO noiommu cdev Date: Thu, 12 Mar 2026 08:56:35 -0700 Message-Id: <20260312155637.376854-10-jacob.pan@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260312155637.376854-1-jacob.pan@linux.microsoft.com> References: <20260312155637.376854-1-jacob.pan@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With unsafe DMA noiommu mode, the vfio devices are prefixed with noiommu-, e.g. /dev/vfio/ |-- devices | `-- noiommu-vfio0 |-- noiommu-0 `-- vfio Let vfio tests, such as luo kexec test, accommodate the noiommu device files. Signed-off-by: Jacob Pan --- .../selftests/vfio/lib/vfio_pci_device.c | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_device.c index 4e5871f1ebc3..15ddeb634a8d 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -290,6 +290,24 @@ static void vfio_pci_device_setup(struct vfio_pci_devi= ce *device) device->msi_eventfds[i] =3D -1; } =20 + +static int is_unsafe_noiommu_mode_enabled(void) +{ + const char *path =3D "/sys/module/vfio/parameters/enable_unsafe_noiommu_m= ode"; + FILE *f; + int c; + + f =3D fopen(path, "re"); + if (!f) + return 0; + + c =3D fgetc(f); + fclose(f); + if (c =3D=3D 'Y' || c =3D=3D 'y') + return 1; + return 0; +} + const char *vfio_pci_get_cdev_path(const char *bdf) { char dir_path[PATH_MAX]; @@ -306,8 +324,11 @@ const char *vfio_pci_get_cdev_path(const char *bdf) VFIO_ASSERT_NOT_NULL(dir, "Failed to open directory %s\n", dir_path); =20 while ((entry =3D readdir(dir)) !=3D NULL) { - /* Find the file that starts with "vfio" */ - if (strncmp("vfio", entry->d_name, 4)) + /* Find the file that starts with "noiommu-vfio" or "vfio" */ + if (is_unsafe_noiommu_mode_enabled()) { + if (strncmp("noiommu-vfio", entry->d_name, strlen("noiommu-vfio"))) + continue; + } else if (strncmp("vfio", entry->d_name, 4)) continue; =20 snprintf(cdev_path, PATH_MAX, "/dev/vfio/devices/%s", entry->d_name); --=20 2.34.1