From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 C6F9B3A48F4 for ; Tue, 12 May 2026 22:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778625031; cv=none; b=JpW1thKtjQlT1bteAZAI9oPD/0H6dVz2kfmm5Y83oLsUotAZmT7QYcEgpDjBpdEeLyy/EputCXOPWXZgLwxZqC930xaLsR5JYg7g+33/UdyOmbI371lOGL3QOmWNjJguN9K0H5RwhA1B08BGark1xiDxlNbZgR0wzTp12Wohqog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778625031; c=relaxed/simple; bh=OIEfn+/2+DaJyxRNqncYOzG1Bc1ehsDrVLl6kwMt7/s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=avL0oWX9BAE2Cp5t+MLkIBYChiEBLmxr4Dnl5THGS4CMTZ30UtjSluwFVUXMMX8BeagXaHYDQiWmsjBVUfXNyVhaTYBD7dwTmjJ4YcD3xCOLp59Gxh9hqN0k8sgrhJGTvB5sccPhn9J0Af7TKqvz7QwVjlhVRRjyQtw4SckLOJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ik5o48IB; arc=none smtp.client-ip=74.125.82.54 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=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ik5o48IB" Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-12c8d0945b3so10c88.0 for ; Tue, 12 May 2026 15:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778625029; x=1779229829; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fUE3ggTXLdFmMqzX5xEOlnUW7TclhTbhVIB3cc1f9SI=; b=ik5o48IB6msp5gT2s6/CkKGWg3qwtP2g3dN+eXf8+u5DVObH3dqJu3gtbBggU3uChN pEIcRMRX/30zIKqj07GL8iIjbjuza/+UvcKyGA2DO5DkgRT8gBbMj/nfOtDd3NtfB3GA v03eWpx0kOxG13qF+gNUfFIYu2wDGJpZIrAxBNFpmGUjNTz/6V5sc2WGllK8pyo7LS0H ERa+B7PnYInXOG3bI3zn49Y/dj2pOacyCWR1/eABthC5ITedPrvjQvIHd+zwUZduZI1j e6sInmY84QRhE9g5qDPXaihJHew7eNbadcUGcuifarJjK+Z3nyOZmOhGq+8Fgc8pAn01 O/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778625029; x=1779229829; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fUE3ggTXLdFmMqzX5xEOlnUW7TclhTbhVIB3cc1f9SI=; b=qWE/t0dHFjp+fMo8KIOvy9RBdrBtqWLlUvku1ownemO7HEKQv5WUx+/fIfhF92dnig 7Vvbq3OVInWsMBKOwwgBBQPv+Ln1tY21dPWMpb5TsAeGhNUeLYHAce4E9+K6Hfn1PdOR yzZYwXlbBlYEiunZJZhRZvQIQ8CnZxagnse85g6VbqDfftoT4h3GNr90wuOLKWyYU6pb XnObTQMXfwq+LI9Wa0MIikdtfGF7AqqgZMJsX9QK6lTr/ahcQYM7y0Dcr/G1Mgf6Y74c rSD4LSez9oa7u5poN/0F9rCgQYF01ph6UrVVBnvyQMKgLdTe0IWZnXGsA84kceaO3Tnu BVRQ== X-Forwarded-Encrypted: i=1; AFNElJ+H2JMygPlbF3xjmulNWBDfQwJfo2pn12a9hEW9bve1hGOkfD/2yfosjZXpkBon4k1mzhIKKOZyCX/u7hw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+BnKb9WoFUVXT3p9YG1fKvztItzP9MROqqCI7wB0wR43MxHcC otAtFMvDba6OpikR63cKkV21fpYt1cA9yznMr7e3zEUe6oNblXEcJOG0GVF4gzViVyGwM3lZRzh L8kMjFUNl X-Gm-Gg: Acq92OG40g0Y5QOeYdmKLZNnesRK/iaGkOf7dMkEhG310gxfYRSGCQBMSJn7Bbyvo5f HHy/bkGlYTNBYWcFTyMo7zSqB/D9e2EkJjheEmbWTGnqfH4KkF01Hf8n3/2ADCrDqBoMWE9p04y vAF1fJNykPFxPrU+fqdzZGKrZG6E5RWLlUnCZ+YPmTKI7/65fOHz7NFM8ltEExAMz7C3UgFDIa2 quFPOOXr+qyKeSdQQ3pRRR2T492mB2b2ZF71ZwmQooGyiaKfVeAIcLG5t4NImG0MMD0gf51u4x7 sEfnHo2FTz1iE72+3pkgvUyhYfo4z4Gmwxc37k6yP7O4K7ShzU+lmu8NhzK50pMdHF+0RWOXAc5 F2eFdhU5DlB6TMLMiQmuNv5cUikdYnXlEsUwTVJw+2/CyJ8q2Ko/YOIIuLoO9SGQ7DEINy1lOPU BENy0XWau/KMgCkpjVRe1oYY46jNcUmXiJbqS460jUj0XgXLs1JEQlAlNJAGFeMuZtFZAmHWnx X-Received: by 2002:a05:7022:1003:b0:12c:6fd2:948d with SMTP id a92af1059eb24-1340bb51480mr107152c88.10.1778625028123; Tue, 12 May 2026 15:30:28 -0700 (PDT) Received: from google.com (176.13.105.34.bc.googleusercontent.com. [34.105.13.176]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2f8893441absm26473316eec.31.2026.05.12.15.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 15:30:27 -0700 (PDT) Date: Tue, 12 May 2026 15:30:23 -0700 From: Vipin Sharma To: Raghavendra Rao Ananta Cc: David Matlack , Alex Williamson , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 7/8] vfio: selftests: Add helpers to alloc/free vfio_pci_device Message-ID: <20260512223013.GG3046123.vipinsh@google.com> References: <20260505212838.1698034-1-rananta@google.com> <20260505212838.1698034-8-rananta@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260505212838.1698034-8-rananta@google.com> On Tue, May 05, 2026 at 09:28:37PM +0000, Raghavendra Rao Ananta wrote: > 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 6b855fbcb4a22..94dc5fcecbeb6 100644 > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > @@ -421,7 +421,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; > > @@ -432,6 +432,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 > @@ -464,5 +478,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.54.0.545.g6539524ca2-goog > Reviewed-by: Vipin Sharma