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 5AA0F47B404 for ; Fri, 27 Feb 2026 23:39:38 +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=1772235580; cv=none; b=rpFPy9dKxTYiXtfzY6jqiHNizFcQI/gqMFxiGYXdAkOzQzr3ksXdR3FP3bjKJUj9n4IwW0r0WMmL2ZP09FZgURG1Kny3+eyJSc5bY9HvsgM1YwVCCfBbPzvjEpzNrQcF/kYuvISvIEP7j+rhtvNWhWD3qpNX+CzZgD5aq0nZQ4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772235580; c=relaxed/simple; bh=Zea1mJb1nV+2ZNc0sYa8z4jFdj6XxBzN4tc0WpNB6wM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uO1iL8WZBuwk8I1xHb9gNLhobvWCQFdWWf4ZaBD9pPbbHoL1xJ+lBHVsSGrYO8H4/x7Ek/PnpYWHiRr9SYSxsnGLm0vV2hJ5z0hxAjd9v0vhOaYgrGG0a9TohtM60xTHM6aaX8gj0r1UtOD1PBcrVJM1rYZ5OktCDDaSiC47pzE= 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=zqvNl+Ny; 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="zqvNl+Ny" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-679c6ef156dso22953255eaf.1 for ; Fri, 27 Feb 2026 15:39:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772235577; x=1772840377; 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=zp13jkTAk6bWujFIQ+dHCM/k/mA1jLnbVAVVBxM74mU=; b=zqvNl+NyQAD/YlVCOwmxb5RDUeG8vStVA4fDP4fvBov6Usfl9QaloA8E4D6GnP9pA2 8ZUFPAmKbsLMursD4Z8j3Kcta6u7W42yR7cJ7Pj3IN9F4LejVa51mOcmgsTgT7+qH4qe vyPocKpgRPufWxhubvSTEEqkbpm1ute8gY7ENRmYuu/JHlY0PI99/kVInSLODQlCW2sG xlNnfOaZ/kmdZ2Pgrd2Pu2mU61BWbGRypChK8HFeuBKcMAUYiylU7aQIdQW5oT9pvCv/ aP60NF1bBbvChSR4h7ZbafNpP0Hk3wWwrybmOK2o+nHH2CIZ92HnXrUL+bw6ErwBLYpQ TGOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772235577; x=1772840377; 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=zp13jkTAk6bWujFIQ+dHCM/k/mA1jLnbVAVVBxM74mU=; b=uwDH2nqaH35N7ubfi8d3jur+Bt+1pHfmvdxjIuw9YM5rCpmaqydarFSRFdb9WCa6GC VPEsBqd0c2uphBBmw83iYyj4EtFMGhTbUMbuRW1qLl6HM2Fn9SK7ic9TmxvqjUpHJdxq CqsTwegCz+b77Tg5NWK9rBxPhK89radzAshQyvcBQKrVBRuvl681HHg01b8SSg3rRvHL KQu4y9AvhFqEmMCQd9zMt0pYB+QnTyEMMl+GTjX6hD36wgFGiA/IniX2u74GW+2MHadl cJXuseE+vDzqE+UjIuqnvMivIV8VyI4Ca7mcXXGiPFBBVXfrg0/0t3UHhR6mfc3nx0iQ VYBA== X-Forwarded-Encrypted: i=1; AJvYcCW5QxwhcJsCrdR4C9vZr6NUV0owzHxFsk/sSWYqdPwLQeRit20Ee7MQW07uykp5yKGAa1dYGTFcf20WMmU=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+SbDUyjFL0FbUAzvYsLZPGhOHV2vWOF9hOZ5NkyrPMZIuRZyX WckJU+ykiCDD5r9yMatuk5SAewkloGRlfwtw8kmB+/vl22xWKWjMGLT+7WERxpXHvsWwlol4na8 k59sDDywp2A== X-Received: from iols21.prod.google.com ([2002:a5d:9155:0:b0:957:7945:e822]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:828:b0:672:9d81:a765 with SMTP id 006d021491bc7-679faf73307mr2755566eaf.65.1772235577276; Fri, 27 Feb 2026 15:39:37 -0800 (PST) Date: Fri, 27 Feb 2026 23:39:27 +0000 In-Reply-To: <20260227233928.84530-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: <20260227233928.84530-1-rananta@google.com> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260227233928.84530-8-rananta@google.com> Subject: [PATCH v5 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 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_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 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_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; @@ -430,6 +430,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 @@ -462,5 +476,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.473.g4a7958ca14-goog