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 696424C0425 for ; Tue, 5 May 2026 21:28:50 +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=1778016531; cv=none; b=RVuY7e8aZ6vWxfUWg6vznlcbetOmmGnMzT9RAXZyyR+3GxQDfUAsmTAhZQ1yeVBATZIHCQB7yFKc86aEAmKzVzo6ANfk07mj+vGZvLHPv+iGgfNl7TNYVRQVkEl1N8iXOjVA9GwzzSTaqyJ5cFvQ/Wnjpe3yCs7dehKnWrQHm4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778016531; c=relaxed/simple; bh=nWWEHlDRK/55H9sc+sSWQt7sjQhogZRCW4tUvpUazfU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aVkIgKeDLbv0mId5/C6p/LzgO7d46TsqMyrxKCY+YCOiwZRk6Vv3LgrGzypKH1P+5J9mCeLQFar92W0XQT+0gmGuqkabcGvJragfgu86bLTiEbzu/XALi9FHQmSJkaVjc7CypBW2AojnMHIwrG8DUzDx3nQuwt0ZRD8lVpdqMak= 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=Qv20H/vi; 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="Qv20H/vi" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-6961e8fa90bso11854625eaf.0 for ; Tue, 05 May 2026 14:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778016527; x=1778621327; 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=/ycq5rNhvfEuPJ4FnDxTrIkEq4BYeEOANTDKltW6JNU=; b=Qv20H/vi6NRYLSvG3zZ68HbU/vT2RLQwmMRdI6IOq+X4H3RPA/A/RXWTobKsYynOkc Zq+rc9QLjBQhXRITjomonq/veysMV0t4gKPUfLKd8vhU2BHObRwTF+IjDclIzNK82bKM d3Gnb9Os0mA/XGqdFJVPmpqXmvJA61sxd9FX9vJtd+Qi32otZDJITphP1rp8T2UvV562 BcdtgrUktPdwdq4EHQAP8oTPhSJtk/QrwUVmnzNnpmfanX6PPTvTYnjAs87UisUyhO4v n+kfKSsZ30m3qFURIDcLQGZHipzqp3vK1hHo1yzt3WvIqbvwm/CAWMQ8vrSSQB9VNGMn HN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778016527; x=1778621327; 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=/ycq5rNhvfEuPJ4FnDxTrIkEq4BYeEOANTDKltW6JNU=; b=YOY8Tfn092a8FN/iw9eiVSAyMp9nkX6HVY8Ai92WRK8JuW2YrxAqPtPche/2pN8YVo aE+GSCtH6JIA2ksuoGadtMLa/W1jZQ4TGSohyifTnW+01EFS5miITuVyPSluIYCWek1r oafAfDsQmC7cZsY14FbY0CYg4iArS9DHX/t6XFiFuDlOOgwcvgObl4m2HFCSsvHSchwT XKBY7f6JeXxhn61cBDfMRn5InOy8KHDxl26GlsBKYBUP2ZBTKW79kkboLE+eADyHgsH3 KXmmnW0mKleurvlAqhvCCbWLU0hlUq5moPN+g5VEs5LMkEPJOoEQo6z+NOapQSjNUmyq 463A== X-Forwarded-Encrypted: i=1; AFNElJ95uSjT7WiynACSgbTJnfzZqNy9Ko04mCpYAXQ8OfDMbU8g/zBiBuZCyqgUt3rzZBt7ajUq+wzMsnrq4Hc=@vger.kernel.org X-Gm-Message-State: AOJu0YwQx/UNholXoETexwDrjr0TXdePZLMMVh3vXXNMlO6gV7cnl96D GSCMIwndNPUN3qq8PW4z07ZytTuaDr89i40xGtZvin8ETsmvXOW6EzCKPT4RathTGytOn0lRwzX fCi09HYyQHA== X-Received: from ilbdz7-n1.prod.google.com ([2002:a05:6e02:4407:10b0:4f9:ee58:8f69]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:81e:b0:696:7f04:eca2 with SMTP id 006d021491bc7-69998c90567mr355495eaf.9.1778016527078; Tue, 05 May 2026 14:28:47 -0700 (PDT) Date: Tue, 5 May 2026 21:28:37 +0000 In-Reply-To: <20260505212838.1698034-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: <20260505212838.1698034-1-rananta@google.com> X-Mailer: git-send-email 2.54.0.545.g6539524ca2-goog Message-ID: <20260505212838.1698034-8-rananta@google.com> Subject: [PATCH v8 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 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