From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.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 BDC983ACA72 for ; Tue, 24 Feb 2026 18:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771957547; cv=none; b=sufgIIarWnUNOliuyUNG/2Za5mUtWy14bPAJMMhJhqcfJRY2KyD6s6hg85vAhf/Zd2bCa2bQtsFtgyozhM7/vtQ+DJMY8VGDdFEfadVQu1Yh54p4kAW4nJCDGj3GVIGX3L56aT+RjO/e7Zy0YxoWj1/Bnxr1qRcADKkibVtFbeo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771957547; c=relaxed/simple; bh=VmQzJHJCdVhJpl0lXLHmrt7QhBYTiLTqnSuYTYveJt8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QysVrlJ1yn82DOWAjSRL8l1fDcht6noiirONuYUCyfcl2Lqp6tVUjBpmiUxETgsUlS3EoTdAyGmpITeSk09dYFpUeeVLn/XsZJ+SeCrKvSRUqjHcCRAT4zbxcuyXK2vAzRrfg+fJjbwfLSlQq5YYhxjDE6RXLWcc506sCA26l+c= 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=08RRW07L; arc=none smtp.client-ip=209.85.161.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="08RRW07L" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-66308f16ea1so70199447eaf.2 for ; Tue, 24 Feb 2026 10:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771957544; x=1772562344; 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=X0JgQKedteVjhK5W38tsOG4zN99RY1VmLQMUHBFPZ+M=; b=08RRW07LrFxmudD+s2XYwZXTniSH90haA/icWBHqW8to5rmZrnL4qO64EFDPtEItpW jCy51vkKWdblRsDMdI95XmLo2u5/Xbduz1T0w6bw/VLFN3rQeHyXcT3dtu8SxO6Xf//R 885XPThwWLGjTJtfLs0XewX2KIWSVMgJAk4PSURRZq7PRwmVwLW26iRBqMm41iZd/QJg LJeBoRa51ylIYK5g8bjPyWXJrn6QimZ+Lnp3h1zRJ7AJvZxQpAKcjD57narmTtedbdBt MwYyJi1Gg7+z03XPqKnLllwct8wxFmPQfmoTqGRKKv4O4tsXdI/v+9pFEax2s8SPJZ8d BDfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771957544; x=1772562344; 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=X0JgQKedteVjhK5W38tsOG4zN99RY1VmLQMUHBFPZ+M=; b=Z5ZGp+RQDF0q1O9uQtNL5+eTTRqlPJDy9lWKTW4eAjXQ3ULXX9BEGk9fBphS1I/JgF tjgtxk0yUJL3chMk5bdcpMyOHwSnrKANjTkZ57RcU4YoqaB+z/lFdIBYd8niCu+ERs9M 3Z3o1JLYhlPZB4siDLsM85dtCcVECGlDodXzkG8o4e6UsHeJ9WN5CG9nvZq1Aytv1R72 4RQmgDHmbwN7XHeJPpcjR0Wp1aTliup4jfhYzommXEmQ6dg2fuH0ayC2e7CIg1hmch/+ +866t6CTq5/Z3DWSgoEwciutS18gkFliUdpMl63OHRhQ7G+lDLxv97sS7Xgjrib3LVDk ZpSA== X-Forwarded-Encrypted: i=1; AJvYcCVcdLlnzYfQyGCewL/G6zE3YCwxun4C0Ewm7Pk5667nnWrqIwOg1pQaE89B6oii+3NZWnCn6tDL5d1EyLw=@vger.kernel.org X-Gm-Message-State: AOJu0YzhElswQsgQSdSAznkxK5SJGnuao7FqcMErb+c3GlUDGYxFEfJZ y324BEMX2PhyEbXmaaxQGFakbI7T3WxJrTZr1rODxr1Wl5GkqSnJ9Y5MQerQ+7V6L1EEb6PCl5u A75hFEEkFxA== X-Received: from jajt19.prod.google.com ([2002:a05:6638:2053:b0:5cf:f38:8cf1]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:4b18:b0:66e:9d89:d8bf with SMTP id 006d021491bc7-679c44ebbaamr6942557eaf.54.1771957543578; Tue, 24 Feb 2026 10:25:43 -0800 (PST) Date: Tue, 24 Feb 2026 18:25:31 +0000 In-Reply-To: <20260224182532.3914470-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: <20260224182532.3914470-1-rananta@google.com> X-Mailer: git-send-email 2.53.0.414.gf7e9f6c205-goog Message-ID: <20260224182532.3914470-8-rananta@google.com> Subject: [PATCH v4 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-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 --- .../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_device.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__) +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *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); diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c index f15065f531562..6f3f65021bd6c 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_device *device, vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); } -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 iommu *iommu) { struct vfio_pci_device *device; @@ -408,6 +408,20 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iomm device->iommu = iommu; device->bdf = bdf; + 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 = 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 *device) if (device->group_fd) VFIO_ASSERT_EQ(close(device->group_fd), 0); - free(device); + vfio_pci_device_free(device); } -- 2.53.0.414.gf7e9f6c205-goog