sysfs: Support zapping of binary attr mmaps
We want to be able to revoke pci mmaps so that the same access rules
applies as for /dev/kmem. Revoke support for devmem was added in
3234ac664a
("/dev/mem: Revoke mappings when a driver claims the
region").
The simplest way to achieve this is by having the same filp->f_mapping
for all mappings, so that unmap_mapping_range can find them all, no
matter through which file they've been created. Since this must be set
at open time we need sysfs support for this.
Add an optional mapping parameter bin_attr, which is only consulted
when there's also an mmap callback, since without mmap support
allowing to adjust the ->f_mapping makes no sense.
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Kees Cook <keescook@chromium.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: linux-mm@kvack.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: linux-media@vger.kernel.org
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cc: Nayna Jain <nayna@linux.ibm.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20201127164131.2244124-12-daniel.vetter@ffwll.ch
This commit is contained in:
parent
71a1d8ed90
commit
74b3019539
|
@ -170,6 +170,16 @@ static int sysfs_kf_bin_mmap(struct kernfs_open_file *of,
|
||||||
return battr->mmap(of->file, kobj, battr, vma);
|
return battr->mmap(of->file, kobj, battr, vma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sysfs_kf_bin_open(struct kernfs_open_file *of)
|
||||||
|
{
|
||||||
|
struct bin_attribute *battr = of->kn->priv;
|
||||||
|
|
||||||
|
if (battr->mapping)
|
||||||
|
of->file->f_mapping = battr->mapping;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr)
|
void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr)
|
||||||
{
|
{
|
||||||
struct kernfs_node *kn = kobj->sd, *tmp;
|
struct kernfs_node *kn = kobj->sd, *tmp;
|
||||||
|
@ -241,6 +251,7 @@ static const struct kernfs_ops sysfs_bin_kfops_mmap = {
|
||||||
.read = sysfs_kf_bin_read,
|
.read = sysfs_kf_bin_read,
|
||||||
.write = sysfs_kf_bin_write,
|
.write = sysfs_kf_bin_write,
|
||||||
.mmap = sysfs_kf_bin_mmap,
|
.mmap = sysfs_kf_bin_mmap,
|
||||||
|
.open = sysfs_kf_bin_open,
|
||||||
};
|
};
|
||||||
|
|
||||||
int sysfs_add_file_mode_ns(struct kernfs_node *parent,
|
int sysfs_add_file_mode_ns(struct kernfs_node *parent,
|
||||||
|
|
|
@ -164,11 +164,13 @@ __ATTRIBUTE_GROUPS(_name)
|
||||||
|
|
||||||
struct file;
|
struct file;
|
||||||
struct vm_area_struct;
|
struct vm_area_struct;
|
||||||
|
struct address_space;
|
||||||
|
|
||||||
struct bin_attribute {
|
struct bin_attribute {
|
||||||
struct attribute attr;
|
struct attribute attr;
|
||||||
size_t size;
|
size_t size;
|
||||||
void *private;
|
void *private;
|
||||||
|
struct address_space *mapping;
|
||||||
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
|
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
|
||||||
char *, loff_t, size_t);
|
char *, loff_t, size_t);
|
||||||
ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
|
ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
|
||||||
|
|
Loading…
Reference in New Issue