[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250904040828.319452-13-ankita@nvidia.com>
Date: Thu, 4 Sep 2025 04:08:26 +0000
From: <ankita@...dia.com>
To: <ankita@...dia.com>, <jgg@...dia.com>, <alex.williamson@...hat.com>,
<yishaih@...dia.com>, <skolothumtho@...dia.com>, <kevin.tian@...el.com>,
<yi.l.liu@...el.com>, <zhiw@...dia.com>
CC: <aniketa@...dia.com>, <cjia@...dia.com>, <kwankhede@...dia.com>,
<targupta@...dia.com>, <vsethi@...dia.com>, <acurrid@...dia.com>,
<apopple@...dia.com>, <jhubbard@...dia.com>, <danw@...dia.com>,
<anuaggarwal@...dia.com>, <mochs@...dia.com>, <kjaju@...dia.com>,
<dnigam@...dia.com>, <kvm@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [RFC 12/14] vfio/nvgrace-egm: Introduce ioctl to share retired pages
From: Ankit Agrawal <ankita@...dia.com>
nvgrace-egm module stores the list of retired page offsets to be made
available for usermode processes. Introduce an ioctl to share the
information with the userspace.
The ioctl is called by usermode apps such as QEMU to get the retired
page offsets. The usermode apps are expected to take appropriate action
to communicate the list to the VM.
Signed-off-by: Ankit Agrawal <ankita@...dia.com>
---
MAINTAINERS | 1 +
drivers/vfio/pci/nvgrace-gpu/egm.c | 67 ++++++++++++++++++++++++++++++
include/uapi/linux/egm.h | 26 ++++++++++++
3 files changed, 94 insertions(+)
create mode 100644 include/uapi/linux/egm.h
diff --git a/MAINTAINERS b/MAINTAINERS
index ec6bc10f346d..bd2d2d309d92 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -26481,6 +26481,7 @@ M: Ankit Agrawal <ankita@...dia.com>
L: kvm@...r.kernel.org
S: Supported
F: drivers/vfio/pci/nvgrace-gpu/egm.c
+F: include/uapi/linux/egm.h
VFIO PCI DEVICE SPECIFIC DRIVERS
R: Jason Gunthorpe <jgg@...dia.com>
diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c
index 7a026b4d98f7..2cb100e39c4b 100644
--- a/drivers/vfio/pci/nvgrace-gpu/egm.c
+++ b/drivers/vfio/pci/nvgrace-gpu/egm.c
@@ -5,6 +5,7 @@
#include <linux/vfio_pci_core.h>
#include <linux/nvgrace-egm.h>
+#include <linux/egm.h>
#define MAX_EGM_NODES 4
@@ -90,11 +91,77 @@ static int nvgrace_egm_mmap(struct file *file, struct vm_area_struct *vma)
vma->vm_page_prot);
}
+static long nvgrace_egm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+ unsigned long minsz = offsetofend(struct egm_retired_pages_list, count);
+ struct egm_retired_pages_list info;
+ void __user *uarg = (void __user *)arg;
+ struct chardev *egm_chardev = file->private_data;
+
+ if (copy_from_user(&info, uarg, minsz))
+ return -EFAULT;
+
+ if (info.argsz < minsz || !egm_chardev)
+ return -EINVAL;
+
+ switch (cmd) {
+ case EGM_RETIRED_PAGES_LIST:
+ int ret;
+ unsigned long retired_page_struct_size = sizeof(struct egm_retired_pages_info);
+ struct egm_retired_pages_info tmp;
+ struct h_node *cur_page;
+ struct hlist_node *tmp_node;
+ unsigned long bkt;
+ int count = 0, index = 0;
+
+ hash_for_each_safe(egm_chardev->htbl, bkt, tmp_node, cur_page, node)
+ count++;
+
+ if (info.argsz < (minsz + count * retired_page_struct_size)) {
+ info.argsz = minsz + count * retired_page_struct_size;
+ info.count = 0;
+ goto done;
+ } else {
+ hash_for_each_safe(egm_chardev->htbl, bkt, tmp_node, cur_page, node) {
+ /*
+ * This check fails if there was an ECC error
+ * after the usermode app read the count of
+ * bad pages through this ioctl.
+ */
+ if (minsz + index * retired_page_struct_size >= info.argsz) {
+ info.argsz = minsz + index * retired_page_struct_size;
+ info.count = index;
+ goto done;
+ }
+
+ tmp.offset = cur_page->mem_offset;
+ tmp.size = PAGE_SIZE;
+
+ ret = copy_to_user(uarg + minsz +
+ index * retired_page_struct_size,
+ &tmp, retired_page_struct_size);
+ if (ret)
+ return -EFAULT;
+ index++;
+ }
+
+ info.count = index;
+ }
+ break;
+ default:
+ return -EINVAL;
+ }
+
+done:
+ return copy_to_user(uarg, &info, minsz) ? -EFAULT : 0;
+}
+
static const struct file_operations file_ops = {
.owner = THIS_MODULE,
.open = nvgrace_egm_open,
.release = nvgrace_egm_release,
.mmap = nvgrace_egm_mmap,
+ .unlocked_ioctl = nvgrace_egm_ioctl,
};
static void egm_chardev_release(struct device *dev)
diff --git a/include/uapi/linux/egm.h b/include/uapi/linux/egm.h
new file mode 100644
index 000000000000..d157fbb5e305
--- /dev/null
+++ b/include/uapi/linux/egm.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved
+ */
+
+#ifndef _UAPIEGM_H
+#define _UAPIEGM_H
+
+#define EGM_TYPE ('E')
+
+struct egm_retired_pages_info {
+ __aligned_u64 offset;
+ __aligned_u64 size;
+};
+
+struct egm_retired_pages_list {
+ __u32 argsz;
+ /* out */
+ __u32 count;
+ /* out */
+ struct egm_retired_pages_info retired_pages[];
+};
+
+#define EGM_RETIRED_PAGES_LIST _IO(EGM_TYPE, 100)
+
+#endif /* _UAPIEGM_H */
--
2.34.1
Powered by blists - more mailing lists