From: Martin Oliveira <martin.oliveira@eideticom.com>
To: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, linux-mm@kvack.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Logan Gunthorpe <logang@deltatee.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Tejun Heo <tj@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Marciniszyn <mike.marciniszyn@intel.com>,
Michael Guralnik <michaelgur@nvidia.com>,
Martin Oliveira <martin.oliveira@eideticom.com>,
Dan Williams <dan.j.williams@intel.com>,
Ard Biesheuvel <ardb@kernel.org>,
Valentine Sinitsyn <valesini@yandex-team.ru>,
Lukas Wunner <lukas@wunner.de>
Subject: [PATCH 2/6] sysfs: add mmap_allocates parameter to struct bin_attribute
Date: Wed, 5 Jun 2024 13:29:30 -0600 [thread overview]
Message-ID: <20240605192934.742369-3-martin.oliveira@eideticom.com> (raw)
In-Reply-To: <20240605192934.742369-1-martin.oliveira@eideticom.com>
Now that a struct kernfs_ops can have an "mmap_allocates" parameter to
avoid the page_mkwrite() operator, the struct bin_attribute needs a way
to choose the appropriate kernfs_ops.
Introduce a "mmap_allocates" boolean on struct bin_attribute to achieve
that.
Co-developed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Martin Oliveira <martin.oliveira@eideticom.com>
---
fs/sysfs/file.c | 25 +++++++++++++++++++------
include/linux/sysfs.h | 1 +
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d1995e2d6c94..77c21009ceee 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -264,6 +264,15 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
.llseek = sysfs_kf_bin_llseek,
};
+static const struct kernfs_ops sysfs_bin_kfops_mmap_allocates = {
+ .read = sysfs_kf_bin_read,
+ .write = sysfs_kf_bin_write,
+ .mmap = sysfs_kf_bin_mmap,
+ .open = sysfs_kf_bin_open,
+ .llseek = sysfs_kf_bin_llseek,
+ .mmap_allocates = true,
+};
+
int sysfs_add_file_mode_ns(struct kernfs_node *parent,
const struct attribute *attr, umode_t mode, kuid_t uid,
kgid_t gid, const void *ns)
@@ -323,16 +332,20 @@ int sysfs_add_bin_file_mode_ns(struct kernfs_node *parent,
const struct kernfs_ops *ops;
struct kernfs_node *kn;
- if (battr->mmap)
- ops = &sysfs_bin_kfops_mmap;
- else if (battr->read && battr->write)
+ if (battr->mmap) {
+ if (battr->mmap_allocates)
+ ops = &sysfs_bin_kfops_mmap_allocates;
+ else
+ ops = &sysfs_bin_kfops_mmap;
+ } else if (battr->read && battr->write) {
ops = &sysfs_bin_kfops_rw;
- else if (battr->read)
+ } else if (battr->read) {
ops = &sysfs_bin_kfops_ro;
- else if (battr->write)
+ } else if (battr->write) {
ops = &sysfs_bin_kfops_wo;
- else
+ } else {
ops = &sysfs_file_kfops_empty;
+ }
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (!attr->ignore_lockdep)
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index a7d725fbf739..190b4b9355df 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -294,6 +294,7 @@ struct bin_attribute {
struct attribute attr;
size_t size;
void *private;
+ bool mmap_allocates;
struct address_space *(*f_mapping)(void);
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
char *, loff_t, size_t);
--
2.34.1
next prev parent reply other threads:[~2024-06-05 19:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 19:29 [PATCH 0/6] Enable P2PDMA in Userspace RDMA Martin Oliveira
2024-06-05 19:29 ` [PATCH 1/6] kernfs: create vm_operations_struct without page_mkwrite() Martin Oliveira
2024-06-05 21:43 ` Bjorn Helgaas
2024-06-06 20:54 ` Greg Kroah-Hartman
2024-06-06 21:32 ` Logan Gunthorpe
2024-06-07 5:03 ` Christoph Hellwig
2024-06-07 16:16 ` Logan Gunthorpe
2024-06-07 19:18 ` Greg Kroah-Hartman
2024-06-05 19:29 ` Martin Oliveira [this message]
2024-06-05 19:29 ` [PATCH 3/6] PCI/P2PDMA: create VMA without page_mkwrite() operator Martin Oliveira
2024-06-05 21:45 ` Bjorn Helgaas
2024-06-05 19:29 ` [PATCH 4/6] mm/gup: handle ZONE_DEVICE pages in folio_fast_pin_allowed() Martin Oliveira
2024-06-05 19:29 ` [PATCH 5/6] mm/gup: allow FOLL_LONGTERM & FOLL_PCI_P2PDMA Martin Oliveira
2024-06-05 19:29 ` [PATCH 6/6] RDMA/umem: add support for P2P RDMA Martin Oliveira
2024-06-10 12:11 ` Jason Gunthorpe
2024-06-06 8:53 ` [PATCH 0/6] Enable P2PDMA in Userspace RDMA Zhu Yanjun
2024-06-06 21:32 ` Martin Oliveira
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240605192934.742369-3-martin.oliveira@eideticom.com \
--to=martin.oliveira@eideticom.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bhelgaas@google.com \
--cc=dan.j.williams@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=lukas@wunner.de \
--cc=michaelgur@nvidia.com \
--cc=mike.marciniszyn@intel.com \
--cc=rafael@kernel.org \
--cc=tj@kernel.org \
--cc=valesini@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox