Re: [PATCH RFC v2 13/15] vfio/nvgrace-egm: expose the egm size through sysfs

From: Alex Williamson

Date: Wed Mar 04 2026 - 18:23:15 EST


On Mon, 23 Feb 2026 15:55:12 +0000
<ankita@xxxxxxxxxx> wrote:

> From: Ankit Agrawal <ankita@xxxxxxxxxx>
>
> To allocate the EGM, the userspace need to know its size. Currently,
> there is no easy way for the userspace to determine that.
>
> Make nvgrace-egm expose the size through sysfs that can be queried
> by the userspace from <char_dev_path>/egm_size.
> E.g. on a 2-socket system, it is present at
> /sys/class/egm/egm4
> /sys/class/egm/egm5
>
> It also shows up at <aux_device path>/egm_size.
> /sys/devices/pci0008:00/0008:00:00.0/0008:01:00.0/nvgrace_gpu_vfio_pci.egm.4/egm/egm4/egm_size
> /sys/devices/pci0018:00/0018:00:00.0/0018:01:00.0/nvgrace_gpu_vfio_pci.egm.5/egm/egm5/egm_size
>

But we like to de-privilege QEMU and even pass file handles, how does
QEMU know the EGM size without trawling through sysfs? It seems there
needs to be a primary interface to learn the size through the chardev.

Also no Documentation/ABI/testing/ entry.

> Signed-off-by: Ankit Agrawal <ankita@xxxxxxxxxx>
> ---
> drivers/vfio/pci/nvgrace-gpu/egm.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c
> index 918979d8fcd4..2e4024c25e8a 100644
> --- a/drivers/vfio/pci/nvgrace-gpu/egm.c
> +++ b/drivers/vfio/pci/nvgrace-gpu/egm.c
> @@ -365,6 +365,32 @@ static char *egm_devnode(const struct device *device, umode_t *mode)
> return NULL;
> }
>
> +static ssize_t egm_size_show(struct device *dev, struct device_attribute *attr,
> + char *buf)
> +{
> + struct chardev *egm_chardev = container_of(dev, struct chardev, device);
> + struct nvgrace_egm_dev *egm_dev =
> + egm_chardev_to_nvgrace_egm_dev(egm_chardev);
> +
> + return sysfs_emit(buf, "0x%lx\n", egm_dev->egmlength);

Should the size be in decimal, %zu?

> +}
> +
> +static DEVICE_ATTR_RO(egm_size);
> +
> +static struct attribute *attrs[] = {
> + &dev_attr_egm_size.attr,
> + NULL,
> +};
> +
> +static struct attribute_group attr_group = {
> + .attrs = attrs,
> +};

const?

> +
> +static const struct attribute_group *attr_groups[2] = {

No need to explicitly size the array, []. Thanks,

Alex

> + &attr_group,
> + NULL
> +};
> +
> static int __init nvgrace_egm_init(void)
> {
> int ret;
> @@ -386,6 +412,7 @@ static int __init nvgrace_egm_init(void)
> }
>
> class->devnode = egm_devnode;
> + class->dev_groups = attr_groups;
>
> ret = auxiliary_driver_register(&egm_driver);
> if (!ret)