From nobody Wed Apr 8 23:38:27 2026 Received: from mail-oi1-f202.google.com (mail-oi1-f202.google.com [209.85.167.202]) (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 82CD53F7A90 for ; Thu, 2 Apr 2026 17:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775151072; cv=none; b=GZK2+PPY7LQObpbTkmG+JLexM/B9AGgleZ8juaG6K5hrKM4PeWIN4bHJtysw6T6LD/6+/ozq2hO64Iqc+T7//oZG8kdDUazp7h3iJ3X+hB3XedB/qQu/cO7IaODb0EFI8XzzGp+MOMCdgIkj2SttMFRjZwg4Phq8nO71MSuwDIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775151072; c=relaxed/simple; bh=JvspclGG//MbGhKd05tl7x7zTJzEXGzkxs42ikNGdSg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F3RkS1FsiIiy1RoTqF6WAQambW26MgjFY7G6Y2348qBmZjR4QLavJu2wQJir/yMXrCxF2dZC+tUsosyAlvOl6pok/G2cft7etAj88v7pVAeeKzUIYa7NoZwYIVgxVAuHzqGKNtRtnHYPw8ZgDj6P545p39nMVj/AnIbrnVJGZrQ= 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=pVkeId73; arc=none smtp.client-ip=209.85.167.202 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="pVkeId73" Received: by mail-oi1-f202.google.com with SMTP id 5614622812f47-466ef11c4baso2361156b6e.1 for ; Thu, 02 Apr 2026 10:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775151070; x=1775755870; 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=B0ib/Tb14sQxCq5zPTYDnrbZcYfKDUfA5Bwx4aPAdsY=; b=pVkeId733giV/Nw5L7Dr7mSYkf44MQZNPkRhy62qN9uFF49rjDop/hwp34eWjQn88j +pi0/GQVbDa8GJBCtbnw3hAKTEJxELtMk2TU95K+X8d/s+K82OFSN44jXgNIOOAb1zI1 6uAbzn5vOrAXn3KCu8YXdWRik5WPuhouZvh9u96EGrMiLoPqKkCFZ/ISi1MhUkx2Iic8 AIpVhOLKQv3MJILFGfd4/g61JumfJVcLw0WfcjKaSQleLCBpTaqhjKWPCrWSM3kh/MkC y4q5ymI1el2w1NZUmVuEz5jM4I+Avp+6Ioe9MrMooDQHLTpLe1gJfqhF4aq5ST0nSRMa Y2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775151070; x=1775755870; 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=B0ib/Tb14sQxCq5zPTYDnrbZcYfKDUfA5Bwx4aPAdsY=; b=H1qLXUE1XL4/7PcdmLavIBUYJL9MhAaaKp7Cw681C1JqtDy5fIAqSiE5F8ZySFVqaV /dv4W62yObjX/dPBpRidWJOpstrQzE2NmBbFVOqi4C3OUdzffKsKFwcossg6PGrb8pd6 gyUqAGpiU47JEIxN5+BN7XQhadF36nYcgAtEGD9Ol2MifZYvbEAz+z4imYrF+sCsZDOZ 0KKzC0e66vaV8bdAFUewIYgV562nSZycf+WuASCnbQJd/XpJKmFfDX3ruFbL7OjqVKrp fOv65pO2VjMUR4Iln2UzOPwaNjhovOzyniPxPWk70lYRrx5ngYXYfQfwOKCA6RkZeQxC 8Kjg== X-Forwarded-Encrypted: i=1; AJvYcCXWK+sbnZ3JKsCxqXequhWin67dudfpw7NXzEgA0TAFKnU6ShpYlxg+2i9NnrRtj/eKbUy3n3aFl3xd/eI=@vger.kernel.org X-Gm-Message-State: AOJu0Yxl42jO5msaVt22dV/VyoJeXFOgHKph2rGEQkqqZImaSc11EMeS mugWyvv08HXV6TRhXAzZhA7BXDwQG7QsXPDCusUKJseZ9cJy0Xk466nj99Z3bVfFCWAmKL62RQV rGZmyiB3zLg== X-Received: from ilqu13.prod.google.com ([2002:a92:cccd:0:b0:4f8:aea6:eab7]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a54:4e82:0:b0:464:82c5:567c with SMTP id 5614622812f47-46ef8314beemr88833b6e.41.1775151070223; Thu, 02 Apr 2026 10:31:10 -0700 (PDT) Date: Thu, 2 Apr 2026 17:30:58 +0000 In-Reply-To: <20260402173059.1018805-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: <20260402173059.1018805-1-rananta@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260402173059.1018805-8-rananta@google.com> Subject: [PATCH v7 7/8] vfio: selftests: Add helpers to alloc/free vfio_pci_device From: Raghavendra Rao Ananta To: David Matlack , 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. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: David Matlack --- .../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 4ebdc00e20fca..3eabead717bbd 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 4673b148f8c44..4ff76970e3791 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -419,7 +419,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 @@ -430,6 +430,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 @@ -462,5 +476,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.1213.gd9a14994de-goog