From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00989286D5C; Fri, 6 Feb 2026 20:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770410928; cv=none; b=BJv1KW13REZXg/0oUAO8qHDs/zG8Vd2GUF5dEab0XfDX/7bv7B2JCkJrFhiV+XpFPi+jjf4EiNdSQ+AQXqJFigI51xNJZ4UK4j/XbU5V8zxZmeEqMEh17enlqGGdj91+lDxcWVwMKl4/gc29DnCjVmfhP48wev0BJZySTOfuZU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770410928; c=relaxed/simple; bh=sewls7mFlNxIVyLdmPeLP+fjx/8nqmWgNZT5L7hNZD0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iKvsPkfFGcnagJV2nnpbtkPCyOhHtoFlBxdVWvDmkSqL21+2XhgWd8AT2LC4WkMijXArybhX1k7yDqMPqleJ3kku61tdB6FBWezpu6wIduJh9v8ZHRgzeEqR1boV53yOmWE8TOvH93VJBNzGo762U7ZhfO0Ikqyv5YKHsT+KbXc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b=gqQ/rNW6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PtrfSzYR; arc=none smtp.client-ip=202.12.124.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=shazbot.org header.i=@shazbot.org header.b="gqQ/rNW6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PtrfSzYR" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id E03997A006D; Fri, 6 Feb 2026 15:48:45 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 06 Feb 2026 15:48:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1770410925; x=1770497325; bh=0PWlIAQoyUVJP6ckfGtooQ0hzJjpmashNbmqxfQHqeA=; b= gqQ/rNW6Au9rxXl/WadhAbwdLaHQmOE+b+ORS6D3HNpFhneHD2Z3oaWVOV2d55Ms rEBIWEiUi76WdOI3PlbdH7o5DMKKIr6w8DHyOaxA7L4mX+pljMDHiJ8mJ3/llQki ABbHDMcl/r8V2SlDQyGtmVckntjEY7ZHIu+1zJtS++Bu2xZd/orgQ9+BBUUwUMNY O+lTfUSYifYEv6M1PcuQByPWugStlia8AjeooV0V8uCEMxjy8vjGjNd4/4bsC7LI WhJm2CYx8gfjNz5uPwKeAFPcRdKHYfuLe+h2bHNHDFISjTujnZBZ9Q3qXJ3jLaf3 xnN5K3JxxUms9ZNuYMLokQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1770410925; x= 1770497325; bh=0PWlIAQoyUVJP6ckfGtooQ0hzJjpmashNbmqxfQHqeA=; b=P trfSzYRP6Bid4ocaSNUjm8B6jpc86HxwT9CiUIXkXznXygUCIW7+IwXEBZwMoPS+ IgceFNMbvNlnP2F+NfIGiql3zirJAFCIU7C5+dkWHbtG42De+cDE/XCcOjuvv+4t uqmJNKFqlf+Q0V3jhqdcTcZ2r/7WGmUr0IOuP2G2eyKfFPxjLSnEFBRAZ+Ru5afo zI1vqpJkfldCPmQr5p4Z8r5vnHv+7hkY0YLZAhlYQBneLaEsDJAQvok/auiojAlN WuPu4Hdac40jtL5XLT26flRDehHRnX5E3w4k+RTQ8lbO3LrEQXcl43xSLMpdELNj FBv5D3w/Nc0Khlwg+NBkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddukeeludejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkjghfofggtgfgsehtjeertdertddvnecuhfhrohhmpeetlhgvgicu hghilhhlihgrmhhsohhnuceorghlvgigsehshhgriigsohhtrdhorhhgqeenucggtffrrg htthgvrhhnpedvkeefjeekvdduhfduhfetkedugfduieettedvueekvdehtedvkefgudeg veeuueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grlhgvgiesshhhrgiisghothdrohhrghdpnhgspghrtghpthhtohepjedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheprhgrnhgrnhhtrgesghhoohhglhgvrdgtohhmpdhrtg hpthhtohepughmrghtlhgrtghksehgohhoghhlvgdrtghomhdprhgtphhtthhopegrlhgv gidrfihilhhlihgrmhhsohhnsehrvgguhhgrthdrtghomhdprhgtphhtthhopehvihhpih hnshhhsehgohhoghhlvgdrtghomhdprhgtphhtthhopehjrhhhihhlkhgvsehgohhoghhl vgdrtghomhdprhgtphhtthhopehkvhhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 6 Feb 2026 15:48:44 -0500 (EST) Date: Fri, 6 Feb 2026 13:48:43 -0700 From: Alex Williamson To: Raghavendra Rao Ananta Cc: David Matlack , Alex Williamson , Vipin Sharma , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/8] vfio: selftests: Introduce a sysfs lib Message-ID: <20260206134843.4ab04ee2@shazbot.org> In-Reply-To: <20260204010057.1079647-4-rananta@google.com> References: <20260204010057.1079647-1-rananta@google.com> <20260204010057.1079647-4-rananta@google.com> X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 4 Feb 2026 01:00:52 +0000 Raghavendra Rao Ananta wrote: > Introduce a sysfs library to handle the common reads/writes to the > PCI sysfs files, for example, getting the total number of VFs supported > by the device via /sys/bus/pci/devices/$BDF/sriov_totalvfs. The library > will be used in the upcoming test patch to configure the VFs for a given > PF device. > > Opportunistically, move vfio_pci_get_group_from_dev() to this library as > it falls under the same bucket. Rename it to sysfs_iommu_group_get() to > align with other function names. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../selftests/vfio/lib/include/libvfio.h | 1 + > .../vfio/lib/include/libvfio/sysfs.h | 12 ++ > tools/testing/selftests/vfio/lib/libvfio.mk | 1 + > tools/testing/selftests/vfio/lib/sysfs.c | 136 ++++++++++++++++++ > .../selftests/vfio/lib/vfio_pci_device.c | 22 +-- > 5 files changed, 151 insertions(+), 21 deletions(-) > create mode 100644 tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h > create mode 100644 tools/testing/selftests/vfio/lib/sysfs.c > > diff --git a/tools/testing/selftests/vfio/lib/include/libvfio.h b/tools/testing/selftests/vfio/lib/include/libvfio.h > index 279ddcd70194..bbe1d7616a64 100644 > --- a/tools/testing/selftests/vfio/lib/include/libvfio.h > +++ b/tools/testing/selftests/vfio/lib/include/libvfio.h > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > #include > #include > > diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h b/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h > new file mode 100644 > index 000000000000..c48d5ef00ba6 > --- /dev/null > +++ b/tools/testing/selftests/vfio/lib/include/libvfio/sysfs.h > @@ -0,0 +1,12 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +#ifndef SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_SYSFS_H > +#define SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_SYSFS_H > + > +int sysfs_sriov_totalvfs_get(const char *bdf); > +int sysfs_sriov_numvfs_get(const char *bdf); > +void sysfs_sriov_numvfs_set(const char *bdfs, int numvfs); > +char *sysfs_sriov_vf_bdf_get(const char *pf_bdf, int i); > +unsigned int sysfs_iommu_group_get(const char *bdf); > +char *sysfs_driver_get(const char *bdf); > + > +#endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_SYSFS_H */ > diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/selftests/vfio/lib/libvfio.mk > index 9f47bceed16f..b7857319c3f1 100644 > --- a/tools/testing/selftests/vfio/lib/libvfio.mk > +++ b/tools/testing/selftests/vfio/lib/libvfio.mk > @@ -6,6 +6,7 @@ LIBVFIO_SRCDIR := $(selfdir)/vfio/lib > LIBVFIO_C := iommu.c > LIBVFIO_C += iova_allocator.c > LIBVFIO_C += libvfio.c > +LIBVFIO_C += sysfs.c > LIBVFIO_C += vfio_pci_device.c > LIBVFIO_C += vfio_pci_driver.c > > diff --git a/tools/testing/selftests/vfio/lib/sysfs.c b/tools/testing/selftests/vfio/lib/sysfs.c > new file mode 100644 > index 000000000000..f01598ff15d7 > --- /dev/null > +++ b/tools/testing/selftests/vfio/lib/sysfs.c > @@ -0,0 +1,136 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +#include > +#include > +#include > +#include > +#include > + > +#include > + > +static int sysfs_val_get(const char *component, const char *name, > + const char *file) > +{ > + char path[PATH_MAX]; > + char buf[32]; > + int fd; > + > + snprintf_assert(path, PATH_MAX, "/sys/bus/pci/%s/%s/%s", component, name, file); > + fd = open(path, O_RDONLY); > + if (fd < 0) > + return fd; > + > + VFIO_ASSERT_GT(read(fd, buf, ARRAY_SIZE(buf)), 0); > + VFIO_ASSERT_EQ(close(fd), 0); > + > + return strtol(buf, NULL, 0); I'm surprised we're not sanitizing the strtol() here, ie. errno = 0; ret = strtol(buf, NULL, 0); VFIO_ASSERT_EQ(errno, 0, "sysfs path \"%s\" is not an integer: \"%s\"\n", path, buf); return ret; We also need that sign-off on 7/8. Thanks, Alex