From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.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 DE14E3271ED for ; Wed, 10 Dec 2025 18:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390463; cv=none; b=ETdMJ7gTDMNGEaitata5N2KQkH+E319yj21h5O9J2/qE0uMaSImKelHMNVcf7koxWIrr8ciR12V500PSBG0ts8T0pYefo8E25H13k6w8n2SHaQo/EcmFoYgNGWyqUy9HZjH9ALRxrRzJ90f83MvaQQmUIQmWJat23ish4xDeYe4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390463; c=relaxed/simple; bh=Gwtk7/V1IbgkADTY4UZ3AYMrnSlS5Y2RNs6HXegXqUk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=kSrWAjaAyo/cj/euHcrqhvodqrJnzV7aMOVQL04WgeYS7kDGWdhcuGJGpQwegecHYnUfpZBV7S/bqX09IDxAxDaT3yqOLj8r3/5+YXxURvV0n1WcC3ODPicugFVHEFnYFPdIeJQZDqHswuINynFhHrFKtpbaAFAY6OABNOhYt5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--rananta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Hh+o5Lwv; arc=none smtp.client-ip=209.85.210.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--rananta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hh+o5Lwv" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-7c70930bdf4so312271a34.2 for ; Wed, 10 Dec 2025 10:14:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765390461; x=1765995261; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=gJPs3sxzYCDJFdqc+QHt5C/KgqWsA0f2Jj2OdmWtv1o=; b=Hh+o5LwvtZWyx3kp/DjgS3a7/t8HWdXgdWIDfiiK+gu71UtgadbmzdNeldX6fOvyNz XjUWorL2kyv3Sbx0tX4uPmJXHh9sz2uMDdqsWzRqdssZ47Miflb9msIPTt+VdHsSHUQJ NWywPmqkxPsCvWjAjvwxK0wN5fK8isbWJ0OMoLOdrBCGPfTAUw79EXu9PD5T1csRcKg/ xK6/ICMqa1ROBhMuij2lY/i9f+Dfl4Y6A+BwgnywPBhNaw/10iZVQnWOmNYo0ktex1A8 YaUqien7Uf6r1dvhpHq27crDb5mcMs1l8NtB3YjP37AyRLI9A8tKSQEiu70qnE9N8mlh D69A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765390461; x=1765995261; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gJPs3sxzYCDJFdqc+QHt5C/KgqWsA0f2Jj2OdmWtv1o=; b=xLN/3D+x1XOjCmsQlg+ORGIuZlHM8fwtIPOYqgdJoXSPjkvo/KqOcZFOltjbm7b6o3 QDUmT9D8KmvB+wx5x1p21sxzZfbthKsGOR6ykPc+E3BIbyR8tkFnUeZUP3ApY42bBBsF eK5Mud/nQyY7CE4yLSvvo98seIGbPmQq4feWAZVspUSfXpanbs2+/Vh8q+n9ci50qbnd 32P8V42zBZ+jgmqW3FbNyYObwOzD5IRLWlUdlkk+9M6Y3dO8Ugx5ub1jnyWIB66pnH0G ivmgkH7f0ANzHUlh0KTdm3lNDJQ8jTds8T6DU5zzakYEJsA0FJhLweRzGjeXMBzu+bsp XIPA== X-Forwarded-Encrypted: i=1; AJvYcCXkX0US/xklIBQvz0cqiyKgbcrFVJPD0zL382tMIzY1JN6KWyjOZqTrDtHsIPzHQXvt5tcxkneqXijrvM4=@vger.kernel.org X-Gm-Message-State: AOJu0YwCEEg9WaU1M1C7lc4Dhprb/e3Bmh555r9x4jICilZKkMES6c05 biMS2/CuPR4ObSITJhkCY/8bOxzX+fFQOnv1BZ6teTpPSP6aUpnqRLwmvwTjsx3XH00YAgEEVZt n3oyN7+sYzA== X-Google-Smtp-Source: AGHT+IFnk3aW3f+FPOvxHQLOPw+dndUuJC5iBNWTkzUAdTVvuwF8AuDQUDNG6dQkKTcWgdDwENf5daJzC0W1 X-Received: from ilbbt5.prod.google.com ([2002:a05:6e02:2485:b0:42e:7be2:3ade]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:1846:b0:659:9a49:9044 with SMTP id 006d021491bc7-65b2abf4186mr1680543eaf.15.1765390460842; Wed, 10 Dec 2025 10:14:20 -0800 (PST) Date: Wed, 10 Dec 2025 18:14:11 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.239.gd5f0c6e74e-goog Message-ID: <20251210181417.3677674-1-rananta@google.com> Subject: [PATCH v2 0/6] vfio: selftest: Add SR-IOV UAPI test From: Raghavendra Rao Ananta To: David Matlack , Alex Williamson , Alex Williamson Cc: Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Raghavendra Rao Ananta Content-Type: text/plain; charset="UTF-8" Hello, This series adds a vfio selftest, vfio_pci_sriov_uapi_test.c, to get some coverage on SR-IOV UAPI handling. Specifically, it includes the following cases that iterates over all the iommu modes: - Setting correct/incorrect/NULL tokens during device init. - Close the PF device immediately after setting the token. - Change/override the PF's token after device init. The test takes care of creating/setting up the VF device, and hence, it can be executed like any other test, simply by passing the PF's BDF to run.sh. For example, $ ./scripts/setup.sh 0000:16:00.1 $ ./scripts/run.sh ./vfio_pci_sriov_uapi_test TAP version 13 1..45 Starting 45 tests from 15 test cases. RUN vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.init_token_match OK vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.init_token_match ok 1 vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.init_token_match RUN vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.pf_early_close OK vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.pf_early_close ok 2 vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.pf_early_close RUN vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.override_token OK vfio_pci_sriov_uapi_test.vfio_type1_iommu_same_uuid.override_token [...] RUN vfio_pci_sriov_uapi_test.iommufd_null_uuid.override_token ... OK vfio_pci_sriov_uapi_test.iommufd_null_uuid.override_token ok 45 vfio_pci_sriov_uapi_test.iommufd_null_uuid.override_token PASSED: 45 / 45 tests passed. Thank you. Raghavendra v2: Suggestions by David Matlack (thank you) - Introduce snprintf_assert() to check against content trucation. - Introduce a new sysfs library to handle all the common vfio/pci sysfs operations. - Rename vfio_pci_container_get_device_fd() to vfio_pci_group_get_device_fd(). - Use a fixed size 'arg' array instead of dynamic allocation in __vfio_pci_group_get_device_fd(). - Exclude vfio_pci_device_init() to accept the 'vf_token' arg. - Move the vfio_pci_sriov_uapi_test.c global variable to the FIXTURE() struct or as TEST_F() local variables. - test_vfio_pci_container_setup() returns 'int' to indicate status. - Skip the test if nr_vfs != 0. - Explicitly set "sriov_drivers_autoprobe" for the PF. - Make sure to bind the VF device to the "vfio-pci" driver. - Cleanup the things done by FIXTURE_SETUP() in FIXTURE_TEARDOWN(). v1: https://lore.kernel.org/all/20251104003536.3601931-1-rananta@google.com/ Raghavendra Rao Ananta (6): vfio: selftests: Introduce snprintf_assert() vfio: selftests: Introduce a sysfs lib vfio: selftests: Extend container/iommufd setup for passing vf_token vfio: selftests: Export more vfio_pci functions vfio: selftests: Add helper to set/override a vf_token vfio: selftests: Add tests to validate SR-IOV UAPI tools/testing/selftests/vfio/Makefile | 1 + .../selftests/vfio/lib/include/libvfio.h | 1 + .../vfio/lib/include/libvfio/assert.h | 5 + .../vfio/lib/include/libvfio/sysfs.h | 16 ++ .../lib/include/libvfio/vfio_pci_device.h | 9 + tools/testing/selftests/vfio/lib/libvfio.mk | 5 +- tools/testing/selftests/vfio/lib/sysfs.c | 151 ++++++++++++ .../selftests/vfio/lib/vfio_pci_device.c | 135 ++++++++--- .../selftests/vfio/vfio_dma_mapping_test.c | 6 +- .../selftests/vfio/vfio_pci_device_test.c | 21 +- .../selftests/vfio/vfio_pci_sriov_uapi_test.c | 215 ++++++++++++++++++ 11 files changed, 515 insertions(+), 50 deletions(-) create mode 100644 tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h create mode 100644 tools/testing/selftests/vfio/lib/sysfs.c create mode 100644 tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c base-commit: d721f52e31553a848e0e9947ca15a49c5674aef3 -- 2.52.0.239.gd5f0c6e74e-goog