Commit 5da6185b authored by David Howells's avatar David Howells Committed by Linus Torvalds

[PATCH] NOMMU: Set BDI capabilities for /dev/mem and /dev/kmem

Set the backing device info capabilities for /dev/mem and /dev/kmem to
permit direct sharing under no-MMU conditions and full mapping capabilities
under MMU conditions.  Make the BDI used by these available to all directly
mappable character devices.

Also comment the capabilities for /dev/zero.

[akpm@osdl.org: ifdef reductions]
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0ec76a11
...@@ -238,6 +238,32 @@ static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, ...@@ -238,6 +238,32 @@ static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
} }
#endif #endif
#ifndef CONFIG_MMU
static unsigned long get_unmapped_area_mem(struct file *file,
unsigned long addr,
unsigned long len,
unsigned long pgoff,
unsigned long flags)
{
if (!valid_mmap_phys_addr_range(pgoff, len))
return (unsigned long) -EINVAL;
return pgoff;
}
/* can't do an in-place private mapping if there's no MMU */
static inline int private_mapping_ok(struct vm_area_struct *vma)
{
return vma->vm_flags & VM_MAYSHARE;
}
#else
#define get_unmapped_area_mem NULL
static inline int private_mapping_ok(struct vm_area_struct *vma)
{
return 1;
}
#endif
static int mmap_mem(struct file * file, struct vm_area_struct * vma) static int mmap_mem(struct file * file, struct vm_area_struct * vma)
{ {
size_t size = vma->vm_end - vma->vm_start; size_t size = vma->vm_end - vma->vm_start;
...@@ -245,6 +271,9 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma) ...@@ -245,6 +271,9 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size)) if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
return -EINVAL; return -EINVAL;
if (!private_mapping_ok(vma))
return -ENOSYS;
vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff, vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
size, size,
vma->vm_page_prot); vma->vm_page_prot);
...@@ -782,6 +811,7 @@ static const struct file_operations mem_fops = { ...@@ -782,6 +811,7 @@ static const struct file_operations mem_fops = {
.write = write_mem, .write = write_mem,
.mmap = mmap_mem, .mmap = mmap_mem,
.open = open_mem, .open = open_mem,
.get_unmapped_area = get_unmapped_area_mem,
}; };
static const struct file_operations kmem_fops = { static const struct file_operations kmem_fops = {
...@@ -790,6 +820,7 @@ static const struct file_operations kmem_fops = { ...@@ -790,6 +820,7 @@ static const struct file_operations kmem_fops = {
.write = write_kmem, .write = write_kmem,
.mmap = mmap_kmem, .mmap = mmap_kmem,
.open = open_kmem, .open = open_kmem,
.get_unmapped_area = get_unmapped_area_mem,
}; };
static const struct file_operations null_fops = { static const struct file_operations null_fops = {
...@@ -815,6 +846,10 @@ static const struct file_operations zero_fops = { ...@@ -815,6 +846,10 @@ static const struct file_operations zero_fops = {
.mmap = mmap_zero, .mmap = mmap_zero,
}; };
/*
* capabilities for /dev/zero
* - permits private mappings, "copies" are taken of the source of zeros
*/
static struct backing_dev_info zero_bdi = { static struct backing_dev_info zero_bdi = {
.capabilities = BDI_CAP_MAP_COPY, .capabilities = BDI_CAP_MAP_COPY,
}; };
...@@ -862,9 +897,13 @@ static int memory_open(struct inode * inode, struct file * filp) ...@@ -862,9 +897,13 @@ static int memory_open(struct inode * inode, struct file * filp)
switch (iminor(inode)) { switch (iminor(inode)) {
case 1: case 1:
filp->f_op = &mem_fops; filp->f_op = &mem_fops;
filp->f_mapping->backing_dev_info =
&directly_mappable_cdev_bdi;
break; break;
case 2: case 2:
filp->f_op = &kmem_fops; filp->f_op = &kmem_fops;
filp->f_mapping->backing_dev_info =
&directly_mappable_cdev_bdi;
break; break;
case 3: case 3:
filp->f_op = &null_fops; filp->f_op = &null_fops;
......
...@@ -19,11 +19,30 @@ ...@@ -19,11 +19,30 @@
#include <linux/kobj_map.h> #include <linux/kobj_map.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/backing-dev.h>
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
#include <linux/kmod.h> #include <linux/kmod.h>
#endif #endif
/*
* capabilities for /dev/mem, /dev/kmem and similar directly mappable character
* devices
* - permits shared-mmap for read, write and/or exec
* - does not permit private mmap in NOMMU mode (can't do COW)
* - no readahead or I/O queue unplugging required
*/
struct backing_dev_info directly_mappable_cdev_bdi = {
.capabilities = (
#ifdef CONFIG_MMU
/* permit private copies of the data to be taken */
BDI_CAP_MAP_COPY |
#endif
/* permit direct mmap, for read, write or exec */
BDI_CAP_MAP_DIRECT |
BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP),
};
static struct kobj_map *cdev_map; static struct kobj_map *cdev_map;
static DEFINE_MUTEX(chrdevs_lock); static DEFINE_MUTEX(chrdevs_lock);
...@@ -461,3 +480,4 @@ EXPORT_SYMBOL(cdev_del); ...@@ -461,3 +480,4 @@ EXPORT_SYMBOL(cdev_del);
EXPORT_SYMBOL(cdev_add); EXPORT_SYMBOL(cdev_add);
EXPORT_SYMBOL(register_chrdev); EXPORT_SYMBOL(register_chrdev);
EXPORT_SYMBOL(unregister_chrdev); EXPORT_SYMBOL(unregister_chrdev);
EXPORT_SYMBOL(directly_mappable_cdev_bdi);
...@@ -23,5 +23,7 @@ void cdev_del(struct cdev *); ...@@ -23,5 +23,7 @@ void cdev_del(struct cdev *);
void cd_forget(struct inode *); void cd_forget(struct inode *);
extern struct backing_dev_info directly_mappable_cdev_bdi;
#endif #endif
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment