From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793312232; b=C4MvwJ844MNA9qeIV4PvMtJ6sSo/GvWE5n8UbxAYm9lqrkQM3/kW4kGsiO4Xmx+AoJOn +RdFnRU5wtbw4jkBpgB0d8jhEr9dBRZWJt9HpQEWz6sTUnc7CDqnTrUUVcTYuYmGBdakG URaZGIKnhSTSTpg9zvVgTyT/YSuLOnAYlpO5FP+U9gjSSOHraCoNJv4F8bZjoCvQHdfcF bVc0hJJ/bVQpo72t5SWhUvy9Hkxx/e1Glgi/4bo2Go1BBTexYHuIxwmeLRIG7Vom5a4H1 YP0Fyx13TIcdamMbDegaGgtY6iuWaW0fAeCtwrUEnltyZseBfDOrGR2d6ycR58mMHAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793312232; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=2Se0uP/IHXwPO2mC7ObXg6kU02G6XXq9OxfYgp8eCAI=; b=ObEZqqFVFB3peVxBaPcG8Mkw++dkZHTky/4tdg9wsLmGUMoY7X99IkeA3J+SccwW5hwn myN1qme+/vTXJohysxkJRjpuRwik9i40HDLxQ7C/f12QWSuO0IzRsJWF/oHwwVl+84qED 50PsaC5HukpfkWnrp9KKaoX3xHS4Q3y8Js62YvSfAKa6pL3amccuTUP1h/RS1ATJjCIDA io54b4nuIGbHVioMEM621AzdRabnnGcPPGpbBSfa50ojct/vJSoJBKBa9N+sedLUcIYky c7fdlKz07C9F9z9ACOJkydKn2R9NoM8AJH9MMMHTscJ6PU2oP8ZGielhdTYLCdN7Z0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--dmatlack.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=f2dFy6M5; arc=none smtp.remote-ip=209.85.214.198 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 3A4CD606A31C for ; Thu, 29 Oct 2026 22:17:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3A4CD606A31C 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, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=f2dFy6M5 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2ea71803effso1063035ad.3 for ; Thu, 29 Oct 2026 15:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1793312232; x=1793917032; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=2Se0uP/IHXwPO2mC7ObXg6kU02G6XXq9OxfYgp8eCAI=; b=f2dFy6M5D6i6UQWOf0dn9Bg04pSuwldRny+4ugbOBuBGOqGwcAMckavLXEqoMbDhTM fQrzdc04feDEPFDvPkWdD9UNwMFvHF4RT+U8Ya05utIUJi+4YA2nN//Wz3uYD95q0rMp rO5jNYZJuiClQ1TEXTXwMXSDPaVwKgT1JOrpK2Wg4EnRBNkQwylCC5carZwCVU0LfN2t jhx/0YskAOOo6s233vKmBBA2njmYX9LJmZag7wW9zQrYCFgCuTCPTz54eYeX/Xk5LGYI zNmN9AO3RP1SGnQ+YOzuZOrLN+yygBb9oR8iV7GLOjG4WCsVkiqzey1iV7LNvxq6H+V4 CwNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793312232; x=1793917032; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=2Se0uP/IHXwPO2mC7ObXg6kU02G6XXq9OxfYgp8eCAI=; b=t9Gt5KtUDgqLqoW8ajdsU/raBiKo4yHdtRAADSPSHlJpVW2GCXxo3SuYyH8VM8kr0U ksCsMxqM5lS7yI+kdREx6jb4tIQ7INv86j1VpmFr+fVBa2Fco4Le8Cu7tXSraObBIouY N8INO24VCvMQim/SA1V3N1D+8SMsjHIVagsMvW7/BuX5DGUbyD7Y1H723+3mkrdWjSwp u+vdmuWt6aVmPQli+YBeC4ZykkfwZL7hb3SBPGbhw6u8qRpiA1SY6AriDYzkq4snvyBN SKhhzrWU2mACB2madd26TOY4TSjbVGZl7OseH7sm+wBSWSAP8bNrYrJ2RqVL1TfpFg36 Bggg== X-Forwarded-Encrypted: i=1; AKwUvBwIpFwp08FdbIfle76lEX/rZZbsJs29ff2rAp/koGXlYNKo7FBmk1TLt0RhxizAkmZ7JdILJdnUVNks3kI=@vger.kernel.org X-Gm-Message-State: AFq9FYI+K2s71Fy1TkFn2R6QC8E25wKPxCYj0vggxKzn/nGmOecTK7kq F2B3Zf4mp9ng2Pyf2mqQerlCmkDbO1DosxWEHgdIRSvdi8K+GTIM6cMRhmQkI9kUf05sEthbu/l g0URLoCOD4dRq0A== X-Received: from plkk16.prod.google.com ([2002:a17:902:c410:b0:2e9:5f35:6dbc]) (user=dmatlack job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3804:b0:2ea:fb8b:258d with SMTP id d9443c01a7336-2eb36401e95mr7401315ad.6.1793312231450; Thu, 29 Oct 2026 15:17:11 -0700 (PDT) Date: Thu, 29 Oct 2026 22:17:07 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.0.317.g454f8302e1-goog Message-ID: <20261029221710.1871112-1-dmatlack@google.com> Subject: [PATCH 0/3] vfio: selftests: Automatically detect the IOMMU mode From: David Matlack To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Alex Williamson , David Matlack , Paolo Bonzini , Sean Christopherson , Shuah Khan Content-Type: text/plain; charset="UTF-8" This series makes the VFIO selftests library automatically detect which IOMMU mode to use, rather than hardcoding iommufd as the default, and makes tests skip, rather than fail, when the IOMMU mode they need is not available. This was suggested by Sean while reviewing the KVM IRQ test, which currently has to probe for the IOMMU mode itself [1]. iommufd is an optional feature, and VFIO's iommufd support additionally requires CONFIG_VFIO_DEVICE_CDEV. On otherwise functional kernels that only support the legacy VFIO container, the VFIO selftests (and the KVM IRQ test, when using a VFIO device) currently fail with an unhelpful assert: tools/testing/selftests/vfio/lib/iommu.c:448: Assertion Failure Expression: iommu->iommufd > 0 Observed: 0xffffffffffffffff > 0 [errno: 2 - No such file or directory] Patch 1 makes iommu_init(NULL) pick the most preferred IOMMU mode that is available on the current system, and drops the global default_iommu_mode. iommu_modes[] is now ordered by preference: iommufd, vfio_type1v2_iommu, vfio_type1_iommu, iommufd_compat_type1v2, iommufd_compat_type1. A mode is considered available if its container (or /dev/iommu) can be opened and, for container modes, if VFIO_CHECK_EXTENSION reports support for the mode's IOMMU type. iommufd mode additionally requires VFIO device cdevs. Patch 2 adds iommu_mode_is_available() and SKIP_IF_IOMMU_MODE_UNAVAILABLE(), and uses them to skip tests when the IOMMU mode they need is not available. Tests skip via the kselftest harness's SKIP() rather than iommu_init() calling ksft_exit_skip(), since the latter produces malformed TAP output when called from within a harness test. Patch 3 converts the KVM IRQ test to use the VFIO selftests library to pick the IOMMU mode, and drops its probe_iommu_type(). This series is based on vfio/next (vfio-v7.4-rc1). [1] https://lore.kernel.org/kvm/aiIG2L_KdPwuxYA1@google.com/ Testing ----------------------------------------------------------------------- Tested in a QEMU VM with an emulated igb device behind an emulated Intel IOMMU, bound to vfio-pci, on a kernel with CONFIG_IOMMUFD=y, CONFIG_VFIO_DEVICE_CDEV=y, and CONFIG_VFIO_CONTAINER=y. To simulate kernels with fewer IOMMU modes available, /dev/iommu and /dev/vfio/vfio were deleted in the VM: - All IOMMU modes available: All VFIO selftests pass. irq_test -d passes using iommufd. - Only the legacy VFIO container available (/dev/iommu deleted): All VFIO selftests pass, with the iommufd and iommufd_compat variants skipped instead of failing. irq_test -d passes using vfio_type1v2_iommu, and skips if -t iommufd is passed. - No IOMMU mode available (/dev/iommu and /dev/vfio/vfio deleted): vfio_pci_device_test, vfio_pci_driver_test, and irq_test -d all skip with a message explaining why, and with well-formed TAP output. David Matlack (3): vfio: selftests: Automatically detect the IOMMU mode in iommu_init() vfio: selftests: Skip tests when the IOMMU mode is not available KVM: selftests: Use VFIO selftests library to pick IOMMU mode in IRQ test tools/testing/selftests/kvm/irq_test.c | 19 +---- .../vfio/lib/include/libvfio/iommu.h | 30 +++++++- tools/testing/selftests/vfio/lib/iommu.c | 75 ++++++++++++++++--- .../vfio/vfio_dma_mapping_mmio_test.c | 2 + .../selftests/vfio/vfio_dma_mapping_test.c | 4 + .../vfio/vfio_pci_device_init_perf_test.c | 2 + .../selftests/vfio/vfio_pci_device_test.c | 8 +- .../selftests/vfio/vfio_pci_driver_test.c | 9 ++- .../selftests/vfio/vfio_pci_sriov_uapi_test.c | 4 + 9 files changed, 118 insertions(+), 35 deletions(-) base-commit: 076d7e989cb69f6ded7d60f2a080eb909930061b -- 2.56.0.317.g454f8302e1-goog