[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251220040446.274991-6-houtao@huaweicloud.com>
Date: Sat, 20 Dec 2025 12:04:38 +0800
From: Hou Tao <houtao@...weicloud.com>
To: linux-kernel@...r.kernel.org
Cc: linux-pci@...r.kernel.org,
linux-mm@...ck.org,
linux-nvme@...ts.infradead.org,
Bjorn Helgaas <bhelgaas@...gle.com>,
Logan Gunthorpe <logang@...tatee.com>,
Alistair Popple <apopple@...dia.com>,
Leon Romanovsky <leonro@...dia.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Tejun Heo <tj@...nel.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Danilo Krummrich <dakr@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
David Hildenbrand <david@...nel.org>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Keith Busch <kbusch@...nel.org>,
Jens Axboe <axboe@...nel.dk>,
Christoph Hellwig <hch@....de>,
Sagi Grimberg <sagi@...mberg.me>,
houtao1@...wei.com
Subject: [PATCH 05/13] sysfs: support get_unmapped_area callback for binary file
From: Hou Tao <houtao1@...wei.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@...wei.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
Powered by blists - more mailing lists