[PATCH 05/13] sysfs: support get_unmapped_area callback for binary file
Hou Tao
houtao at huaweicloud.com
Fri Dec 19 20:04:38 PST 2025
From: Hou Tao <houtao1 at huawei.com>
Add support for ->get_unmapped_area callback for binary sysfs file. The
following patch will use it to support compound page for p2pdma device
memory when the device memory is mapped into userspace.
Signed-off-by: Hou Tao <houtao1 at huawei.com>
---
fs/sysfs/file.c | 15 +++++++++++++++
include/linux/sysfs.h | 4 ++++
2 files changed, 19 insertions(+)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 3825e780cc58..e843795ebdc2 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -164,6 +164,20 @@ static ssize_t sysfs_kf_bin_write(struct kernfs_open_file *of, char *buf,
return battr->write(of->file, kobj, battr, buf, pos, count);
}
+static unsigned long sysfs_kf_bin_get_unmapped_area(struct kernfs_open_file *of,
+ unsigned long uaddr, unsigned long len,
+ unsigned long pgoff, unsigned long flags)
+{
+ const struct bin_attribute *battr = of->kn->priv;
+ struct kobject *kobj;
+
+ if (!battr->get_unmapped_area)
+ return -EOPNOTSUPP;
+
+ kobj = sysfs_file_kobj(of->kn);
+ return battr->get_unmapped_area(of->file, kobj, battr, uaddr, len, pgoff, flags);
+}
+
static int sysfs_kf_bin_mmap(struct kernfs_open_file *of,
struct vm_area_struct *vma)
{
@@ -268,6 +282,7 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
.mmap = sysfs_kf_bin_mmap,
.open = sysfs_kf_bin_open,
.llseek = sysfs_kf_bin_llseek,
+ .get_unmapped_area = sysfs_kf_bin_get_unmapped_area,
};
int sysfs_add_file_mode_ns(struct kernfs_node *parent,
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index c33a96b7391a..f4a50f244f4d 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -321,6 +321,10 @@ struct bin_attribute {
loff_t, int);
int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr,
struct vm_area_struct *vma);
+ unsigned long (*get_unmapped_area)(struct file *, struct kobject *,
+ const struct bin_attribute *attr,
+ unsigned long uaddr, unsigned long len,
+ unsigned long pgoff, unsigned long flags);
};
/**
--
2.29.2
More information about the Linux-nvme
mailing list