From nobody Sun Feb 8 14:10:30 2026 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (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 646BE26ED45 for ; Wed, 4 Feb 2026 01:01:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770166872; cv=none; b=NbNJvlAYi9w0pR6TrtAyuZ/9dqAJh/D/ap4BIIzozG1SdvWGYqVWpwdifv586qfHLq+4CKijwgNqcejGeUdrcWc53123QPDNauz5iGvH+4bvtSgExqLvfM56iXc/ZJbfSnyKyC/p/JbrQpDfhQDQsXaA0FYc7fSTA+mfNY9C2xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770166872; c=relaxed/simple; bh=0xtJ+pqCo/uE1p9MpFM/9m9xzVYuLjsVR39VzqvKZ/c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XQa2NlAlvTNqsJ2ziRrHbsrIekl1gzVqUVOQWSnNNlzZ0geOI/d41MdX+me7S8/jP6/N7yr4NNp6fZqkQB59NwbJE1ZM+zdyYanvFWfVuJOLKX7a0lZkiBziipQlst7h9LKRoqXUQzmsVnVOP7KQbicS6Vu+QhvF+9k+3toPacs= 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=mB2jinRy; arc=none smtp.client-ip=209.85.160.73 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="mB2jinRy" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-40a585edd8aso648958fac.3 for ; Tue, 03 Feb 2026 17:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770166869; x=1770771669; 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=A3FiC1IXjLa+0JqDoxdMPEgWbheV2hH/CBO7B1cQRs0=; b=mB2jinRyCejaTJu333RBfbMRNG5YUZ/QHtE26tp4VH28gJRxDf5hCZez80dFO49PwQ FtYISwNOsgZ8bRko+IzcJ7xOE+BrYwzvuF5JXoYNyzKspKzVcO3zHE2OPJ9ijRU4kPtK lFeuycyjChm3dRgtsb9NaaDf4B4d4BrLGIv1QHFaZsyb42tmvCi25O7v083u8oFOom3z YT2pok9NwjvOms/6tT2cZ+v86MO9wZk7wt/TOa5YqIPn6d96VVquHxHprbejkbQKyr7G dW4z4wGL5v5VHz4AX69kmAxGJ5NBfDnbXHyvWFgStlGNMtV4V9zOh3V2I3Advbnl31g/ 9l+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770166869; x=1770771669; 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=A3FiC1IXjLa+0JqDoxdMPEgWbheV2hH/CBO7B1cQRs0=; b=mDXj6gKEz5nsweoqcVwDUM+x3mhmbd4rPf4ZBpi0vvddDgwOUe/JeHf7SOfm8je3lk w9BrQvINAEMYGYpU/+WC1l1wOjTy9rBPTp2k/bxaYNDEWIfoXw8fPHqVPzlK/X1kGC7u Th/s15U4/uRM65+w9v3BCOeky/K1f+jAVQQXNjCioljPqzhhYBxn6/oQHJEytHkZ9kYZ hvKc3lCe+rrZLJBkjLFgUAH2pgvkk4CbQLv8xJ1dKF1Wnm83t8U23+0SfVXy/N5NxWMh LcG12YVCvnPYJi67pYHE4xrNUcLN/8a3CHlDbhGXelmOR80hpsKnUKDPSxp7bHfsr2kZ /NvQ== X-Forwarded-Encrypted: i=1; AJvYcCXZho+KmeywAtzbUnGrwtw6/YtQCR6LniJIcynOmb8MtNM1lxlEc1tSJ9EfqUAm2x86t2nRflyuBDNCbdQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwTJhR2STM8k+37Tv0e1z5a2kxAdk1E/qOPrd31X6F1sfhAeIzM oNp8HOZmI0VTRxk0JHkWpBFLWcexjCEIR01p5/zp0rSpV28bRk5DccgvjmLLNisT8Pvx1uD9+yD JbPiAnqiQJQ== X-Received: from oagg5-n2.prod.google.com ([2002:a05:6871:5:20b0:404:63d0:3ed2]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:400d:b0:40a:5f51:c9e5 with SMTP id 586e51a60fabf-40a5f522243mr32311fac.42.1770166869395; Tue, 03 Feb 2026 17:01:09 -0800 (PST) Date: Wed, 4 Feb 2026 01:00:56 +0000 In-Reply-To: <20260204010057.1079647-1-rananta@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260204010057.1079647-1-rananta@google.com> X-Mailer: git-send-email 2.53.0.rc2.204.g2597b5adb4-goog Message-ID: <20260204010057.1079647-8-rananta@google.com> Subject: [PATCH v3 7/8] vfio: selftests: Add helpers to alloc/free vfio_pci_device From: Raghavendra Rao Ananta To: David Matlack , Alex Williamson , Alex Williamson Cc: Vipin Sharma , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Raghavendra Rao Ananta Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper, vfio_pci_device_alloc(), to allocate 'struct vfio_pci_device'. The subsequent test patch will utilize this to get the struct with very minimal initialization done. Internally, let vfio_pci_device_init() also make use of this function and later do the full initialization. Symmetrically, add a free variant, vfio_pci_device_free(), to be used in a similar fashion. No functional change intended. --- .../vfio/lib/include/libvfio/vfio_pci_device.h | 2 ++ .../selftests/vfio/lib/vfio_pci_device.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_devi= ce.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 4ebdc00e20fc..3eabead717bb 100644 --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h @@ -38,6 +38,8 @@ struct vfio_pci_device { #define dev_info(_dev, _fmt, ...) printf("%s: " _fmt, (_dev)->bdf, ##__VA_= ARGS__) #define dev_err(_dev, _fmt, ...) fprintf(stderr, "%s: " _fmt, (_dev)->bdf,= ##__VA_ARGS__) =20 +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iomm= u *iommu); +void vfio_pci_device_free(struct vfio_pci_device *device); struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu= *iommu); void vfio_pci_device_cleanup(struct vfio_pci_device *device); =20 diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/tes= ting/selftests/vfio/lib/vfio_pci_device.c index f15065f53156..6f3f65021bd6 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -397,7 +397,7 @@ static void vfio_pci_iommufd_setup(struct vfio_pci_devi= ce *device, vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); } =20 -struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu= *iommu) +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iomm= u *iommu) { struct vfio_pci_device *device; =20 @@ -408,6 +408,20 @@ struct vfio_pci_device *vfio_pci_device_init(const cha= r *bdf, struct iommu *iomm device->iommu =3D iommu; device->bdf =3D bdf; =20 + return device; +} + +void vfio_pci_device_free(struct vfio_pci_device *device) +{ + free(device); +} + +struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu= *iommu) +{ + struct vfio_pci_device *device; + + device =3D vfio_pci_device_alloc(bdf, iommu); + if (iommu->mode->container_path) vfio_pci_container_setup(device, bdf, NULL); else @@ -440,5 +454,5 @@ void vfio_pci_device_cleanup(struct vfio_pci_device *de= vice) if (device->group_fd) VFIO_ASSERT_EQ(close(device->group_fd), 0); =20 - free(device); + vfio_pci_device_free(device); } --=20 2.53.0.rc2.204.g2597b5adb4-goog