aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/nommu-mmap.txt8
-rw-r--r--block/blk-core.c2
-rw-r--r--drivers/char/mem.c64
-rw-r--r--drivers/mtd/mtdchar.c72
-rw-r--r--drivers/mtd/mtdconcat.c10
-rw-r--r--drivers/mtd/mtdcore.c80
-rw-r--r--drivers/mtd/mtdpart.c1
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c2
-rw-r--r--fs/9p/v9fs.c2
-rw-r--r--fs/afs/volume.c2
-rw-r--r--fs/aio.c14
-rw-r--r--fs/btrfs/disk-io.c3
-rw-r--r--fs/char_dev.c24
-rw-r--r--fs/cifs/connect.c2
-rw-r--r--fs/coda/inode.c2
-rw-r--r--fs/configfs/configfs_internal.h2
-rw-r--r--fs/configfs/inode.c18
-rw-r--r--fs/configfs/mount.c11
-rw-r--r--fs/ecryptfs/main.c2
-rw-r--r--fs/exofs/super.c2
-rw-r--r--fs/ncpfs/inode.c2
-rw-r--r--fs/ramfs/file-nommu.c7
-rw-r--r--fs/ramfs/inode.c22
-rw-r--r--fs/romfs/mmap-nommu.c10
-rw-r--r--fs/ubifs/super.c2
-rw-r--r--include/linux/backing-dev.h33
-rw-r--r--include/linux/cdev.h2
-rw-r--r--include/linux/fs.h23
-rw-r--r--include/linux/mtd/mtd.h2
-rw-r--r--mm/backing-dev.c7
-rw-r--r--mm/nommu.c69
-rw-r--r--security/security.c13
32 files changed, 169 insertions, 346 deletions
diff --git a/Documentation/nommu-mmap.txt b/Documentation/nommu-mmap.txt
index 8e1ddec2c78a..ae57b9ea0d41 100644
--- a/Documentation/nommu-mmap.txt
+++ b/Documentation/nommu-mmap.txt
@@ -43,12 +43,12 @@ and it's also much more restricted in the latter case:
43 even if this was created by another process. 43 even if this was created by another process.
44 44
45 - If possible, the file mapping will be directly on the backing device 45 - If possible, the file mapping will be directly on the backing device
46 if the backing device has the BDI_CAP_MAP_DIRECT capability and 46 if the backing device has the NOMMU_MAP_DIRECT capability and
47 appropriate mapping protection capabilities. Ramfs, romfs, cramfs 47 appropriate mapping protection capabilities. Ramfs, romfs, cramfs
48 and mtd might all permit this. 48 and mtd might all permit this.
49 49
50 - If the backing device device can't or won't permit direct sharing, 50 - If the backing device device can't or won't permit direct sharing,
51 but does have the BDI_CAP_MAP_COPY capability, then a copy of the 51 but does have the NOMMU_MAP_COPY capability, then a copy of the
52 appropriate bit of the file will be read into a contiguous bit of 52 appropriate bit of the file will be read into a contiguous bit of
53 memory and any extraneous space beyond the EOF will be cleared 53 memory and any extraneous space beyond the EOF will be cleared
54 54
@@ -220,7 +220,7 @@ directly (can't be copied).
220 220
221The file->f_op->mmap() operation will be called to actually inaugurate the 221The file->f_op->mmap() operation will be called to actually inaugurate the
222mapping. It can be rejected at that point. Returning the ENOSYS error will 222mapping. It can be rejected at that point. Returning the ENOSYS error will
223cause the mapping to be copied instead if BDI_CAP_MAP_COPY is specified. 223cause the mapping to be copied instead if NOMMU_MAP_COPY is specified.
224 224
225The vm_ops->close() routine will be invoked when the last mapping on a chardev 225The vm_ops->close() routine will be invoked when the last mapping on a chardev
226is removed. An existing mapping will be shared, partially or not, if possible 226is removed. An existing mapping will be shared, partially or not, if possible
@@ -232,7 +232,7 @@ want to handle it, despite the fact it's got an operation. For instance, it
232might try directing the call to a secondary driver which turns out not to 232might try directing the call to a secondary driver which turns out not to
233implement it. Such is the case for the framebuffer driver which attempts to 233implement it. Such is the case for the framebuffer driver which attempts to
234direct the call to the device-specific driver. Under such circumstances, the 234direct the call to the device-specific driver. Under such circumstances, the
235mapping request will be rejected if BDI_CAP_MAP_COPY is not specified, and a 235mapping request will be rejected if NOMMU_MAP_COPY is not specified, and a
236copy mapped otherwise. 236copy mapped otherwise.
237 237
238IMPORTANT NOTE: 238IMPORTANT NOTE:
diff --git a/block/blk-core.c b/block/blk-core.c
index 3ad405571dcc..928aac29bccd 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -607,7 +607,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
607 q->backing_dev_info.ra_pages = 607 q->backing_dev_info.ra_pages =
608 (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 608 (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
609 q->backing_dev_info.state = 0; 609 q->backing_dev_info.state = 0;
610 q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; 610 q->backing_dev_info.capabilities = 0;
611 q->backing_dev_info.name = "block"; 611 q->backing_dev_info.name = "block";
612 q->node = node_id; 612 q->node = node_id;
613 613
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 4c58333b4257..9a6b63783a94 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -287,13 +287,24 @@ static unsigned long get_unmapped_area_mem(struct file *file,
287 return pgoff << PAGE_SHIFT; 287 return pgoff << PAGE_SHIFT;
288} 288}
289 289
290/* permit direct mmap, for read, write or exec */
291static unsigned memory_mmap_capabilities(struct file *file)
292{
293 return NOMMU_MAP_DIRECT |
294 NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC;
295}
296
297static unsigned zero_mmap_capabilities(struct file *file)
298{
299 return NOMMU_MAP_COPY;
300}
301
290/* can't do an in-place private mapping if there's no MMU */ 302/* can't do an in-place private mapping if there's no MMU */
291static inline int private_mapping_ok(struct vm_area_struct *vma) 303static inline int private_mapping_ok(struct vm_area_struct *vma)
292{ 304{
293 return vma->vm_flags & VM_MAYSHARE; 305 return vma->vm_flags & VM_MAYSHARE;
294} 306}
295#else 307#else
296#define get_unmapped_area_mem NULL
297 308
298static inline int private_mapping_ok(struct vm_area_struct *vma) 309static inline int private_mapping_ok(struct vm_area_struct *vma)
299{ 310{
@@ -721,7 +732,10 @@ static const struct file_operations mem_fops = {
721 .write = write_mem, 732 .write = write_mem,
722 .mmap = mmap_mem, 733 .mmap = mmap_mem,
723 .open = open_mem, 734 .open = open_mem,
735#ifndef CONFIG_MMU
724 .get_unmapped_area = get_unmapped_area_mem, 736 .get_unmapped_area = get_unmapped_area_mem,
737 .mmap_capabilities = memory_mmap_capabilities,
738#endif
725}; 739};
726 740
727#ifdef CONFIG_DEVKMEM 741#ifdef CONFIG_DEVKMEM
@@ -731,7 +745,10 @@ static const struct file_operations kmem_fops = {
731 .write = write_kmem, 745 .write = write_kmem,
732 .mmap = mmap_kmem, 746 .mmap = mmap_kmem,
733 .open = open_kmem, 747 .open = open_kmem,
748#ifndef CONFIG_MMU
734 .get_unmapped_area = get_unmapped_area_mem, 749 .get_unmapped_area = get_unmapped_area_mem,
750 .mmap_capabilities = memory_mmap_capabilities,
751#endif
735}; 752};
736#endif 753#endif
737 754
@@ -760,16 +777,9 @@ static const struct file_operations zero_fops = {
760 .read_iter = read_iter_zero, 777 .read_iter = read_iter_zero,
761 .aio_write = aio_write_zero, 778 .aio_write = aio_write_zero,
762 .mmap = mmap_zero, 779 .mmap = mmap_zero,
763}; 780#ifndef CONFIG_MMU
764 781 .mmap_capabilities = zero_mmap_capabilities,
765/* 782#endif
766 * capabilities for /dev/zero
767 * - permits private mappings, "copies" are taken of the source of zeros
768 * - no writeback happens
769 */
770static struct backing_dev_info zero_bdi = {
771 .name = "char/mem",
772 .capabilities = BDI_CAP_MAP_COPY | BDI_CAP_NO_ACCT_AND_WRITEBACK,
773}; 783};
774 784
775static const struct file_operations full_fops = { 785static const struct file_operations full_fops = {
@@ -783,22 +793,22 @@ static const struct memdev {
783 const char *name; 793 const char *name;
784 umode_t mode; 794 umode_t mode;
785 const struct file_operations *fops; 795 const struct file_operations *fops;
786 struct backing_dev_info *dev_info; 796 fmode_t fmode;
787} devlist[] = { 797} devlist[] = {
788 [1] = { "mem", 0, &mem_fops, &directly_mappable_cdev_bdi }, 798 [1] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
789#ifdef CONFIG_DEVKMEM 799#ifdef CONFIG_DEVKMEM
790 [2] = { "kmem", 0, &kmem_fops, &directly_mappable_cdev_bdi }, 800 [2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET },
791#endif 801#endif
792 [3] = { "null", 0666, &null_fops, NULL }, 802 [3] = { "null", 0666, &null_fops, 0 },
793#ifdef CONFIG_DEVPORT 803#ifdef CONFIG_DEVPORT
794 [4] = { "port", 0, &port_fops, NULL }, 804 [4] = { "port", 0, &port_fops, 0 },
795#endif 805#endif
796 [5] = { "zero", 0666, &zero_fops, &zero_bdi }, 806 [5] = { "zero", 0666, &zero_fops, 0 },
797 [7] = { "full", 0666, &full_fops, NULL }, 807 [7] = { "full", 0666, &full_fops, 0 },
798 [8] = { "random", 0666, &random_fops, NULL }, 808 [8] = { "random", 0666, &random_fops, 0 },
799 [9] = { "urandom", 0666, &urandom_fops, NULL }, 809 [9] = { "urandom", 0666, &urandom_fops, 0 },
800#ifdef CONFIG_PRINTK 810#ifdef CONFIG_PRINTK
801 [11] = { "kmsg", 0644, &kmsg_fops, NULL }, 811 [11] = { "kmsg", 0644, &kmsg_fops, 0 },
802#endif 812#endif
803}; 813};
804 814
@@ -816,12 +826,7 @@ static int memory_open(struct inode *inode, struct file *filp)
816 return -ENXIO; 826 return -ENXIO;
817 827
818 filp->f_op = dev->fops; 828 filp->f_op = dev->fops;
819 if (dev->dev_info) 829 filp->f_mode |= dev->fmode;
820 filp->f_mapping->backing_dev_info = dev->dev_info;
821
822 /* Is /dev/mem or /dev/kmem ? */
823 if (dev->dev_info == &directly_mappable_cdev_bdi)
824 filp->f_mode |= FMODE_UNSIGNED_OFFSET;
825 830
826 if (dev->fops->open) 831 if (dev->fops->open)
827 return dev->fops->open(inode, filp); 832 return dev->fops->open(inode, filp);
@@ -846,11 +851,6 @@ static struct class *mem_class;
846static int __init chr_dev_init(void) 851static int __init chr_dev_init(void)
847{ 852{
848 int minor; 853 int minor;
849 int err;
850
851 err = bdi_init(&zero_bdi);
852 if (err)
853 return err;
854 854
855 if (register_chrdev(MEM_MAJOR, "mem", &memory_fops)) 855 if (register_chrdev(MEM_MAJOR, "mem", &memory_fops))
856 printk("unable to get major %d for memory devs\n", MEM_MAJOR); 856 printk("unable to get major %d for memory devs\n", MEM_MAJOR);
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 53563955931b..55fa27ecf4e1 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -49,7 +49,6 @@ static DEFINE_MUTEX(mtd_mutex);
49 */ 49 */
50struct mtd_file_info { 50struct mtd_file_info {
51 struct mtd_info *mtd; 51 struct mtd_info *mtd;
52 struct inode *ino;
53 enum mtd_file_modes mode; 52 enum mtd_file_modes mode;
54}; 53};
55 54
@@ -59,10 +58,6 @@ static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig)
59 return fixed_size_llseek(file, offset, orig, mfi->mtd->size); 58 return fixed_size_llseek(file, offset, orig, mfi->mtd->size);
60} 59}
61 60
62static int count;
63static struct vfsmount *mnt;
64static struct file_system_type mtd_inodefs_type;
65
66static int mtdchar_open(struct inode *inode, struct file *file) 61static int mtdchar_open(struct inode *inode, struct file *file)
67{ 62{
68 int minor = iminor(inode); 63 int minor = iminor(inode);
@@ -70,7 +65,6 @@ static int mtdchar_open(struct inode *inode, struct file *file)
70 int ret = 0; 65 int ret = 0;
71 struct mtd_info *mtd; 66 struct mtd_info *mtd;
72 struct mtd_file_info *mfi; 67 struct mtd_file_info *mfi;
73 struct inode *mtd_ino;
74 68
75 pr_debug("MTD_open\n"); 69 pr_debug("MTD_open\n");
76 70
@@ -78,10 +72,6 @@ static int mtdchar_open(struct inode *inode, struct file *file)
78 if ((file->f_mode & FMODE_WRITE) && (minor & 1)) 72 if ((file->f_mode & FMODE_WRITE) && (minor & 1))
79 return -EACCES; 73 return -EACCES;
80 74
81 ret = simple_pin_fs(&mtd_inodefs_type, &mnt, &count);
82 if (ret)
83 return ret;
84
85 mutex_lock(&mtd_mutex); 75 mutex_lock(&mtd_mutex);
86 mtd = get_mtd_device(NULL, devnum); 76 mtd = get_mtd_device(NULL, devnum);
87 77
@@ -95,43 +85,26 @@ static int mtdchar_open(struct inode *inode, struct file *file)
95 goto out1; 85 goto out1;
96 } 86 }
97 87
98 mtd_ino = iget_locked(mnt->mnt_sb, devnum);
99 if (!mtd_ino) {
100 ret = -ENOMEM;
101 goto out1;
102 }
103 if (mtd_ino->i_state & I_NEW) {
104 mtd_ino->i_private = mtd;
105 mtd_ino->i_mode = S_IFCHR;
106 mtd_ino->i_data.backing_dev_info = mtd->backing_dev_info;
107 unlock_new_inode(mtd_ino);
108 }
109 file->f_mapping = mtd_ino->i_mapping;
110
111 /* You can't open it RW if it's not a writeable device */ 88 /* You can't open it RW if it's not a writeable device */
112 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { 89 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
113 ret = -EACCES; 90 ret = -EACCES;
114 goto out2; 91 goto out1;
115 } 92 }
116 93
117 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL); 94 mfi = kzalloc(sizeof(*mfi), GFP_KERNEL);
118 if (!mfi) { 95 if (!mfi) {
119 ret = -ENOMEM; 96 ret = -ENOMEM;
120 goto out2; 97 goto out1;
121 } 98 }
122 mfi->ino = mtd_ino;
123 mfi->mtd = mtd; 99 mfi->mtd = mtd;
124 file->private_data = mfi; 100 file->private_data = mfi;
125 mutex_unlock(&mtd_mutex); 101 mutex_unlock(&mtd_mutex);
126 return 0; 102 return 0;
127 103
128out2:
129 iput(mtd_ino);
130out1: 104out1:
131 put_mtd_device(mtd); 105 put_mtd_device(mtd);
132out: 106out:
133 mutex_unlock(&mtd_mutex); 107 mutex_unlock(&mtd_mutex);
134 simple_release_fs(&mnt, &count);
135 return ret; 108 return ret;
136} /* mtdchar_open */ 109} /* mtdchar_open */
137 110
@@ -148,12 +121,9 @@ static int mtdchar_close(struct inode *inode, struct file *file)
148 if ((file->f_mode & FMODE_WRITE)) 121 if ((file->f_mode & FMODE_WRITE))
149 mtd_sync(mtd); 122 mtd_sync(mtd);
150 123
151 iput(mfi->ino);
152
153 put_mtd_device(mtd); 124 put_mtd_device(mtd);
154 file->private_data = NULL; 125 file->private_data = NULL;
155 kfree(mfi); 126 kfree(mfi);
156 simple_release_fs(&mnt, &count);
157 127
158 return 0; 128 return 0;
159} /* mtdchar_close */ 129} /* mtdchar_close */
@@ -1117,6 +1087,13 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
1117 ret = mtd_get_unmapped_area(mtd, len, offset, flags); 1087 ret = mtd_get_unmapped_area(mtd, len, offset, flags);
1118 return ret == -EOPNOTSUPP ? -ENODEV : ret; 1088 return ret == -EOPNOTSUPP ? -ENODEV : ret;
1119} 1089}
1090
1091static unsigned mtdchar_mmap_capabilities(struct file *file)
1092{
1093 struct mtd_file_info *mfi = file->private_data;
1094
1095 return mtd_mmap_capabilities(mfi->mtd);
1096}
1120#endif 1097#endif
1121 1098
1122/* 1099/*
@@ -1160,27 +1137,10 @@ static const struct file_operations mtd_fops = {
1160 .mmap = mtdchar_mmap, 1137 .mmap = mtdchar_mmap,
1161#ifndef CONFIG_MMU 1138#ifndef CONFIG_MMU
1162 .get_unmapped_area = mtdchar_get_unmapped_area, 1139 .get_unmapped_area = mtdchar_get_unmapped_area,
1140 .mmap_capabilities = mtdchar_mmap_capabilities,
1163#endif 1141#endif
1164}; 1142};
1165 1143
1166static const struct super_operations mtd_ops = {
1167 .drop_inode = generic_delete_inode,
1168 .statfs = simple_statfs,
1169};
1170
1171static struct dentry *mtd_inodefs_mount(struct file_system_type *fs_type,
1172 int flags, const char *dev_name, void *data)
1173{
1174 return mount_pseudo(fs_type, "mtd_inode:", &mtd_ops, NULL, MTD_INODE_FS_MAGIC);
1175}
1176
1177static struct file_system_type mtd_inodefs_type = {
1178 .name = "mtd_inodefs",
1179 .mount = mtd_inodefs_mount,
1180 .kill_sb = kill_anon_super,
1181};
1182MODULE_ALIAS_FS("mtd_inodefs");
1183
1184int __init init_mtdchar(void) 1144int __init init_mtdchar(void)
1185{ 1145{
1186 int ret; 1146 int ret;
@@ -1193,23 +1153,11 @@ int __init init_mtdchar(void)
1193 return ret; 1153 return ret;
1194 } 1154 }
1195 1155
1196 ret = register_filesystem(&mtd_inodefs_type);
1197 if (ret) {
1198 pr_err("Can't register mtd_inodefs filesystem, error %d\n",
1199 ret);
1200 goto err_unregister_chdev;
1201 }
1202
1203 return ret;
1204
1205err_unregister_chdev:
1206 __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
1207 return ret; 1156 return ret;
1208} 1157}
1209 1158
1210void __exit cleanup_mtdchar(void) 1159void __exit cleanup_mtdchar(void)
1211{ 1160{
1212 unregister_filesystem(&mtd_inodefs_type);
1213 __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd"); 1161 __unregister_chrdev(MTD_CHAR_MAJOR, 0, 1 << MINORBITS, "mtd");
1214} 1162}
1215 1163
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index b9000563b9f4..eacc3aac7327 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -732,8 +732,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
732 732
733 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks; 733 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
734 734
735 concat->mtd.backing_dev_info = subdev[0]->backing_dev_info;
736
737 concat->subdev[0] = subdev[0]; 735 concat->subdev[0] = subdev[0];
738 736
739 for (i = 1; i < num_devs; i++) { 737 for (i = 1; i < num_devs; i++) {
@@ -761,14 +759,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
761 subdev[i]->flags & MTD_WRITEABLE; 759 subdev[i]->flags & MTD_WRITEABLE;
762 } 760 }
763 761
764 /* only permit direct mapping if the BDIs are all the same
765 * - copy-mapping is still permitted
766 */
767 if (concat->mtd.backing_dev_info !=
768 subdev[i]->backing_dev_info)
769 concat->mtd.backing_dev_info =
770 &default_backing_dev_info;
771
772 concat->mtd.size += subdev[i]->size; 762 concat->mtd.size += subdev[i]->size;
773 concat->mtd.ecc_stats.badblocks += 763 concat->mtd.ecc_stats.badblocks +=
774 subdev[i]->ecc_stats.badblocks; 764 subdev[i]->ecc_stats.badblocks;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 4c611871d7e6..ff38a1df22f7 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -43,33 +43,7 @@
43 43
44#include "mtdcore.h" 44#include "mtdcore.h"
45 45
46/* 46static struct backing_dev_info mtd_bdi = {
47 * backing device capabilities for non-mappable devices (such as NAND flash)
48 * - permits private mappings, copies are taken of the data
49 */
50static struct backing_dev_info mtd_bdi_unmappable = {
51 .capabilities = BDI_CAP_MAP_COPY,
52};
53
54/*
55 * backing device capabilities for R/O mappable devices (such as ROM)
56 * - permits private mappings, copies are taken of the data
57 * - permits non-writable shared mappings
58 */
59static struct backing_dev_info mtd_bdi_ro_mappable = {
60 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
61 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
62};
63
64/*
65 * backing device capabilities for writable mappable devices (such as RAM)
66 * - permits private mappings, copies are taken of the data
67 * - permits non-writable shared mappings
68 */
69static struct backing_dev_info mtd_bdi_rw_mappable = {
70 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
71 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
72 BDI_CAP_WRITE_MAP),
73}; 47};
74 48
75static int mtd_cls_suspend(struct device *dev, pm_message_t state); 49static int mtd_cls_suspend(struct device *dev, pm_message_t state);
@@ -365,6 +339,22 @@ static struct device_type mtd_devtype = {
365 .release = mtd_release, 339 .release = mtd_release,
366}; 340};
367 341
342#ifndef CONFIG_MMU
343unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
344{
345 switch (mtd->type) {
346 case MTD_RAM:
347 return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
348 NOMMU_MAP_READ | NOMMU_MAP_WRITE;
349 case MTD_ROM:
350 return NOMMU_MAP_COPY | NOMMU_MAP_DIRECT | NOMMU_MAP_EXEC |
351 NOMMU_MAP_READ;
352 default:
353 return NOMMU_MAP_COPY;
354 }
355}
356#endif
357
368/** 358/**
369 * add_mtd_device - register an MTD device 359 * add_mtd_device - register an MTD device
370 * @mtd: pointer to new MTD device info structure 360 * @mtd: pointer to new MTD device info structure
@@ -380,19 +370,7 @@ int add_mtd_device(struct mtd_info *mtd)
380 struct mtd_notifier *not; 370 struct mtd_notifier *not;
381 int i, error; 371 int i, error;
382 372
383 if (!mtd->backing_dev_info) { 373 mtd->backing_dev_info = &mtd_bdi;
384 switch (mtd->type) {
385 case MTD_RAM:
386 mtd->backing_dev_info = &mtd_bdi_rw_mappable;
387 break;
388 case MTD_ROM:
389 mtd->backing_dev_info = &mtd_bdi_ro_mappable;
390 break;
391 default:
392 mtd->backing_dev_info = &mtd_bdi_unmappable;
393 break;
394 }
395 }
396 374
397 BUG_ON(mtd->writesize == 0); 375 BUG_ON(mtd->writesize == 0);
398 mutex_lock(&mtd_table_mutex); 376 mutex_lock(&mtd_table_mutex);
@@ -1237,17 +1215,9 @@ static int __init init_mtd(void)
1237 if (ret) 1215 if (ret)
1238 goto err_reg; 1216 goto err_reg;
1239 1217
1240 ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); 1218 ret = mtd_bdi_init(&mtd_bdi, "mtd");
1241 if (ret)
1242 goto err_bdi1;
1243
1244 ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
1245 if (ret)
1246 goto err_bdi2;
1247
1248 ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
1249 if (ret) 1219 if (ret)
1250 goto err_bdi3; 1220 goto err_bdi;
1251 1221
1252 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops); 1222 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
1253 1223
@@ -1260,11 +1230,7 @@ static int __init init_mtd(void)
1260out_procfs: 1230out_procfs:
1261 if (proc_mtd) 1231 if (proc_mtd)
1262 remove_proc_entry("mtd", NULL); 1232 remove_proc_entry("mtd", NULL);
1263err_bdi3: 1233err_bdi:
1264 bdi_destroy(&mtd_bdi_ro_mappable);
1265err_bdi2:
1266 bdi_destroy(&mtd_bdi_unmappable);
1267err_bdi1:
1268 class_unregister(&mtd_class); 1234 class_unregister(&mtd_class);
1269err_reg: 1235err_reg:
1270 pr_err("Error registering mtd class or bdi: %d\n", ret); 1236 pr_err("Error registering mtd class or bdi: %d\n", ret);
@@ -1277,9 +1243,7 @@ static void __exit cleanup_mtd(void)
1277 if (proc_mtd) 1243 if (proc_mtd)
1278 remove_proc_entry("mtd", NULL); 1244 remove_proc_entry("mtd", NULL);
1279 class_unregister(&mtd_class); 1245 class_unregister(&mtd_class);
1280 bdi_destroy(&mtd_bdi_unmappable); 1246 bdi_destroy(&mtd_bdi);
1281 bdi_destroy(&mtd_bdi_ro_mappable);
1282 bdi_destroy(&mtd_bdi_rw_mappable);
1283} 1247}
1284 1248
1285module_init(init_mtd); 1249module_init(init_mtd);
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a3e3a7d074d5..e779de315ade 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -378,7 +378,6 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
378 378
379 slave->mtd.name = name; 379 slave->mtd.name = name;
380 slave->mtd.owner = master->owner; 380 slave->mtd.owner = master->owner;
381 slave->mtd.backing_dev_info = master->backing_dev_info;
382 381
383 /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone 382 /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone
384 * to have the same data be in two different partitions. 383 * to have the same data be in two different partitions.
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index a3367bfb1456..d5b149c5542d 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -987,7 +987,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
987 if (err) 987 if (err)
988 goto out_free; 988 goto out_free;
989 lsi->lsi_flags |= LSI_BDI_INITIALIZED; 989 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
990 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY; 990 lsi->lsi_bdi.capabilities = 0;
991 err = ll_bdi_register(&lsi->lsi_bdi); 991 err = ll_bdi_register(&lsi->lsi_bdi);
992 if (err) 992 if (err)
993 goto out_free; 993 goto out_free;
diff --git a/fs/9p/v9fs.c b/fs/9p/v9fs.c
index 6894b085f0ee..620d93489539 100644
--- a/fs/9p/v9fs.c
+++ b/fs/9p/v9fs.c
@@ -335,7 +335,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
335 } 335 }
336 init_rwsem(&v9ses->rename_sem); 336 init_rwsem(&v9ses->rename_sem);
337 337
338 rc = bdi_setup_and_register(&v9ses->bdi, "9p", BDI_CAP_MAP_COPY); 338 rc = bdi_setup_and_register(&v9ses->bdi, "9p");
339 if (rc) { 339 if (rc) {
340 kfree(v9ses->aname); 340 kfree(v9ses->aname);
341 kfree(v9ses->uname); 341 kfree(v9ses->uname);
diff --git a/fs/afs/volume.c b/fs/afs/volume.c
index 2b607257820c..d142a2449e65 100644
--- a/fs/afs/volume.c
+++ b/fs/afs/volume.c
@@ -106,7 +106,7 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params)
106 volume->cell = params->cell; 106 volume->cell = params->cell;
107 volume->vid = vlocation->vldb.vid[params->type]; 107 volume->vid = vlocation->vldb.vid[params->type];
108 108
109 ret = bdi_setup_and_register(&volume->bdi, "afs", BDI_CAP_MAP_COPY); 109 ret = bdi_setup_and_register(&volume->bdi, "afs");
110 if (ret) 110 if (ret)
111 goto error_bdi; 111 goto error_bdi;
112 112
diff --git a/fs/aio.c b/fs/aio.c
index 1b7893ecc296..6f13d3fab07f 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -165,15 +165,6 @@ static struct vfsmount *aio_mnt;
165static const struct file_operations aio_ring_fops; 165static const struct file_operations aio_ring_fops;
166static const struct address_space_operations aio_ctx_aops; 166static const struct address_space_operations aio_ctx_aops;
167 167
168/* Backing dev info for aio fs.
169 * -no dirty page accounting or writeback happens
170 */
171static struct backing_dev_info aio_fs_backing_dev_info = {
172 .name = "aiofs",
173 .state = 0,
174 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK | BDI_CAP_MAP_COPY,
175};
176
177static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages) 168static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages)
178{ 169{
179 struct qstr this = QSTR_INIT("[aio]", 5); 170 struct qstr this = QSTR_INIT("[aio]", 5);
@@ -185,7 +176,7 @@ static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages)
185 176
186 inode->i_mapping->a_ops = &aio_ctx_aops; 177 inode->i_mapping->a_ops = &aio_ctx_aops;
187 inode->i_mapping->private_data = ctx; 178 inode->i_mapping->private_data = ctx;
188 inode->i_mapping->backing_dev_info = &aio_fs_backing_dev_info; 179 inode->i_mapping->backing_dev_info = &noop_backing_dev_info;
189 inode->i_size = PAGE_SIZE * nr_pages; 180 inode->i_size = PAGE_SIZE * nr_pages;
190 181
191 path.dentry = d_alloc_pseudo(aio_mnt->mnt_sb, &this); 182 path.dentry = d_alloc_pseudo(aio_mnt->mnt_sb, &this);
@@ -230,9 +221,6 @@ static int __init aio_setup(void)
230 if (IS_ERR(aio_mnt)) 221 if (IS_ERR(aio_mnt))
231 panic("Failed to create aio fs mount."); 222 panic("Failed to create aio fs mount.");
232 223
233 if (bdi_init(&aio_fs_backing_dev_info))
234 panic("Failed to init aio fs backing dev info.");
235
236 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC); 224 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
237 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC); 225 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC);
238 226
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8c63419a7f70..afc4092989cd 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1715,8 +1715,7 @@ static int setup_bdi(struct btrfs_fs_info *info, struct backing_dev_info *bdi)
1715{ 1715{
1716 int err; 1716 int err;
1717 1717
1718 bdi->capabilities = BDI_CAP_MAP_COPY; 1718 err = bdi_setup_and_register(bdi, "btrfs");
1719 err = bdi_setup_and_register(bdi, "btrfs", BDI_CAP_MAP_COPY);
1720 if (err) 1719 if (err)
1721 return err; 1720 return err;
1722 1721
diff --git a/fs/char_dev.c b/fs/char_dev.c
index 67b2007f10fe..ea06a3d0364c 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -24,27 +24,6 @@
24 24
25#include "internal.h" 25#include "internal.h"
26 26
27/*
28 * capabilities for /dev/mem, /dev/kmem and similar directly mappable character
29 * devices
30 * - permits shared-mmap for read, write and/or exec
31 * - does not permit private mmap in NOMMU mode (can't do COW)
32 * - no readahead or I/O queue unplugging required
33 */
34struct backing_dev_info directly_mappable_cdev_bdi = {
35 .name = "char",
36 .capabilities = (
37#ifdef CONFIG_MMU
38 /* permit private copies of the data to be taken */
39 BDI_CAP_MAP_COPY |
40#endif
41 /* permit direct mmap, for read, write or exec */
42 BDI_CAP_MAP_DIRECT |
43 BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP |
44 /* no writeback happens */
45 BDI_CAP_NO_ACCT_AND_WRITEBACK),
46};
47
48static struct kobj_map *cdev_map; 27static struct kobj_map *cdev_map;
49 28
50static DEFINE_MUTEX(chrdevs_lock); 29static DEFINE_MUTEX(chrdevs_lock);
@@ -575,8 +554,6 @@ static struct kobject *base_probe(dev_t dev, int *part, void *data)
575void __init chrdev_init(void) 554void __init chrdev_init(void)
576{ 555{
577 cdev_map = kobj_map_init(base_probe, &chrdevs_lock); 556 cdev_map = kobj_map_init(base_probe, &chrdevs_lock);
578 if (bdi_init(&directly_mappable_cdev_bdi))
579 panic("Failed to init directly mappable cdev bdi");
580} 557}
581 558
582 559
@@ -590,4 +567,3 @@ EXPORT_SYMBOL(cdev_del);
590EXPORT_SYMBOL(cdev_add); 567EXPORT_SYMBOL(cdev_add);
591EXPORT_SYMBOL(__register_chrdev); 568EXPORT_SYMBOL(__register_chrdev);
592EXPORT_SYMBOL(__unregister_chrdev); 569EXPORT_SYMBOL(__unregister_chrdev);
593EXPORT_SYMBOL(directly_mappable_cdev_bdi);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 2a772da16b83..d3aa999ab785 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -3446,7 +3446,7 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
3446 int referral_walks_count = 0; 3446 int referral_walks_count = 0;
3447#endif 3447#endif
3448 3448
3449 rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY); 3449 rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs");
3450 if (rc) 3450 if (rc)
3451 return rc; 3451 return rc;
3452 3452
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index b945410bfcd5..82ec68b59208 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -183,7 +183,7 @@ static int coda_fill_super(struct super_block *sb, void *data, int silent)
183 goto unlock_out; 183 goto unlock_out;
184 } 184 }
185 185
186 error = bdi_setup_and_register(&vc->bdi, "coda", BDI_CAP_MAP_COPY); 186 error = bdi_setup_and_register(&vc->bdi, "coda");
187 if (error) 187 if (error)
188 goto unlock_out; 188 goto unlock_out;
189 189
diff --git a/fs/configfs/configfs_internal.h b/fs/configfs/configfs_internal.h
index bd4a3c167091..a315677e44d3 100644
--- a/fs/configfs/configfs_internal.h
+++ b/fs/configfs/configfs_internal.h
@@ -70,8 +70,6 @@ extern int configfs_is_root(struct config_item *item);
70 70
71extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *); 71extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *);
72extern int configfs_create(struct dentry *, umode_t mode, int (*init)(struct inode *)); 72extern int configfs_create(struct dentry *, umode_t mode, int (*init)(struct inode *));
73extern int configfs_inode_init(void);
74extern void configfs_inode_exit(void);
75 73
76extern int configfs_create_file(struct config_item *, const struct configfs_attribute *); 74extern int configfs_create_file(struct config_item *, const struct configfs_attribute *);
77extern int configfs_make_dirent(struct configfs_dirent *, 75extern int configfs_make_dirent(struct configfs_dirent *,
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 5946ad98053f..0ad6b4d6de00 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -50,12 +50,6 @@ static const struct address_space_operations configfs_aops = {
50 .write_end = simple_write_end, 50 .write_end = simple_write_end,
51}; 51};
52 52
53static struct backing_dev_info configfs_backing_dev_info = {
54 .name = "configfs",
55 .ra_pages = 0, /* No readahead */
56 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
57};
58
59static const struct inode_operations configfs_inode_operations ={ 53static const struct inode_operations configfs_inode_operations ={
60 .setattr = configfs_setattr, 54 .setattr = configfs_setattr,
61}; 55};
@@ -137,7 +131,7 @@ struct inode *configfs_new_inode(umode_t mode, struct configfs_dirent *sd,
137 if (inode) { 131 if (inode) {
138 inode->i_ino = get_next_ino(); 132 inode->i_ino = get_next_ino();
139 inode->i_mapping->a_ops = &configfs_aops; 133 inode->i_mapping->a_ops = &configfs_aops;
140 inode->i_mapping->backing_dev_info = &configfs_backing_dev_info; 134 inode->i_mapping->backing_dev_info = &noop_backing_dev_info;
141 inode->i_op = &configfs_inode_operations; 135 inode->i_op = &configfs_inode_operations;
142 136
143 if (sd->s_iattr) { 137 if (sd->s_iattr) {
@@ -283,13 +277,3 @@ void configfs_hash_and_remove(struct dentry * dir, const char * name)
283 } 277 }
284 mutex_unlock(&dir->d_inode->i_mutex); 278 mutex_unlock(&dir->d_inode->i_mutex);
285} 279}
286
287int __init configfs_inode_init(void)
288{
289 return bdi_init(&configfs_backing_dev_info);
290}
291
292void configfs_inode_exit(void)
293{
294 bdi_destroy(&configfs_backing_dev_info);
295}
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index f6c285833390..da94e41bdbf6 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -145,19 +145,13 @@ static int __init configfs_init(void)
145 if (!config_kobj) 145 if (!config_kobj)
146 goto out2; 146 goto out2;
147 147
148 err = configfs_inode_init();
149 if (err)
150 goto out3;
151
152 err = register_filesystem(&configfs_fs_type); 148 err = register_filesystem(&configfs_fs_type);
153 if (err) 149 if (err)
154 goto out4; 150 goto out3;
155 151
156 return 0; 152 return 0;
157out4:
158 pr_err("Unable to register filesystem!\n");
159 configfs_inode_exit();
160out3: 153out3:
154 pr_err("Unable to register filesystem!\n");
161 kobject_put(config_kobj); 155 kobject_put(config_kobj);
162out2: 156out2:
163 kmem_cache_destroy(configfs_dir_cachep); 157 kmem_cache_destroy(configfs_dir_cachep);
@@ -172,7 +166,6 @@ static void __exit configfs_exit(void)
172 kobject_put(config_kobj); 166 kobject_put(config_kobj);
173 kmem_cache_destroy(configfs_dir_cachep); 167 kmem_cache_destroy(configfs_dir_cachep);
174 configfs_dir_cachep = NULL; 168 configfs_dir_cachep = NULL;
175 configfs_inode_exit();
176} 169}
177 170
178MODULE_AUTHOR("Oracle"); 171MODULE_AUTHOR("Oracle");
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index d9eb84bda559..1895d60f4122 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -520,7 +520,7 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
520 goto out; 520 goto out;
521 } 521 }
522 522
523 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); 523 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs");
524 if (rc) 524 if (rc)
525 goto out1; 525 goto out1;
526 526
diff --git a/fs/exofs/super.c b/fs/exofs/super.c
index 95965503afcb..fcc2e565f540 100644
--- a/fs/exofs/super.c
+++ b/fs/exofs/super.c
@@ -836,7 +836,7 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)
836 goto free_sbi; 836 goto free_sbi;
837 } 837 }
838 838
839 ret = bdi_setup_and_register(&sbi->bdi, "exofs", BDI_CAP_MAP_COPY); 839 ret = bdi_setup_and_register(&sbi->bdi, "exofs");
840 if (ret) { 840 if (ret) {
841 EXOFS_DBGMSG("Failed to bdi_setup_and_register\n"); 841 EXOFS_DBGMSG("Failed to bdi_setup_and_register\n");
842 dput(sb->s_root); 842 dput(sb->s_root);
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index e31e589369a4..a699a3fc62c0 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -560,7 +560,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
560 server = NCP_SBP(sb); 560 server = NCP_SBP(sb);
561 memset(server, 0, sizeof(*server)); 561 memset(server, 0, sizeof(*server));
562 562
563 error = bdi_setup_and_register(&server->bdi, "ncpfs", BDI_CAP_MAP_COPY); 563 error = bdi_setup_and_register(&server->bdi, "ncpfs");
564 if (error) 564 if (error)
565 goto out_fput; 565 goto out_fput;
566 566
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index bbafbde3471a..f6ab41b39612 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -34,7 +34,14 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
34 unsigned long flags); 34 unsigned long flags);
35static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma); 35static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma);
36 36
37static unsigned ramfs_mmap_capabilities(struct file *file)
38{
39 return NOMMU_MAP_DIRECT | NOMMU_MAP_COPY | NOMMU_MAP_READ |
40 NOMMU_MAP_WRITE | NOMMU_MAP_EXEC;
41}
42
37const struct file_operations ramfs_file_operations = { 43const struct file_operations ramfs_file_operations = {
44 .mmap_capabilities = ramfs_mmap_capabilities,
38 .mmap = ramfs_nommu_mmap, 45 .mmap = ramfs_nommu_mmap,
39 .get_unmapped_area = ramfs_nommu_get_unmapped_area, 46 .get_unmapped_area = ramfs_nommu_get_unmapped_area,
40 .read = new_sync_read, 47 .read = new_sync_read,
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index d365b1c4eb3c..ad4d712002f4 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -50,14 +50,6 @@ static const struct address_space_operations ramfs_aops = {
50 .set_page_dirty = __set_page_dirty_no_writeback, 50 .set_page_dirty = __set_page_dirty_no_writeback,
51}; 51};
52 52
53static struct backing_dev_info ramfs_backing_dev_info = {
54 .name = "ramfs",
55 .ra_pages = 0, /* No readahead */
56 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK |
57 BDI_CAP_MAP_DIRECT | BDI_CAP_MAP_COPY |
58 BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP,
59};
60
61struct inode *ramfs_get_inode(struct super_block *sb, 53struct inode *ramfs_get_inode(struct super_block *sb,
62 const struct inode *dir, umode_t mode, dev_t dev) 54 const struct inode *dir, umode_t mode, dev_t dev)
63{ 55{
@@ -67,7 +59,7 @@ struct inode *ramfs_get_inode(struct super_block *sb,
67 inode->i_ino = get_next_ino(); 59 inode->i_ino = get_next_ino();
68 inode_init_owner(inode, dir, mode); 60 inode_init_owner(inode, dir, mode);
69 inode->i_mapping->a_ops = &ramfs_aops; 61 inode->i_mapping->a_ops = &ramfs_aops;
70 inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info; 62 inode->i_mapping->backing_dev_info = &noop_backing_dev_info;
71 mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); 63 mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
72 mapping_set_unevictable(inode->i_mapping); 64 mapping_set_unevictable(inode->i_mapping);
73 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 65 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
@@ -267,19 +259,9 @@ static struct file_system_type ramfs_fs_type = {
267int __init init_ramfs_fs(void) 259int __init init_ramfs_fs(void)
268{ 260{
269 static unsigned long once; 261 static unsigned long once;
270 int err;
271 262
272 if (test_and_set_bit(0, &once)) 263 if (test_and_set_bit(0, &once))
273 return 0; 264 return 0;
274 265 return register_filesystem(&ramfs_fs_type);
275 err = bdi_init(&ramfs_backing_dev_info);
276 if (err)
277 return err;
278
279 err = register_filesystem(&ramfs_fs_type);
280 if (err)
281 bdi_destroy(&ramfs_backing_dev_info);
282
283 return err;
284} 266}
285fs_initcall(init_ramfs_fs); 267fs_initcall(init_ramfs_fs);
diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
index ea06c7554860..7da9e2153953 100644
--- a/fs/romfs/mmap-nommu.c
+++ b/fs/romfs/mmap-nommu.c
@@ -70,6 +70,15 @@ static int romfs_mmap(struct file *file, struct vm_area_struct *vma)
70 return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS; 70 return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS;
71} 71}
72 72
73static unsigned romfs_mmap_capabilities(struct file *file)
74{
75 struct mtd_info *mtd = file_inode(file)->i_sb->s_mtd;
76
77 if (!mtd)
78 return NOMMU_MAP_COPY;
79 return mtd_mmap_capabilities(mtd);
80}
81
73const struct file_operations romfs_ro_fops = { 82const struct file_operations romfs_ro_fops = {
74 .llseek = generic_file_llseek, 83 .llseek = generic_file_llseek,
75 .read = new_sync_read, 84 .read = new_sync_read,
@@ -77,4 +86,5 @@ const struct file_operations romfs_ro_fops = {
77 .splice_read = generic_file_splice_read, 86 .splice_read = generic_file_splice_read,
78 .mmap = romfs_mmap, 87 .mmap = romfs_mmap,
79 .get_unmapped_area = romfs_get_unmapped_area, 88 .get_unmapped_area = romfs_get_unmapped_area,
89 .mmap_capabilities = romfs_mmap_capabilities,
80}; 90};
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 106bf20629ce..ed93dc6ae245 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2017,7 +2017,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
2017 * Read-ahead will be disabled because @c->bdi.ra_pages is 0. 2017 * Read-ahead will be disabled because @c->bdi.ra_pages is 0.
2018 */ 2018 */
2019 c->bdi.name = "ubifs", 2019 c->bdi.name = "ubifs",
2020 c->bdi.capabilities = BDI_CAP_MAP_COPY; 2020 c->bdi.capabilities = 0;
2021 err = bdi_init(&c->bdi); 2021 err = bdi_init(&c->bdi);
2022 if (err) 2022 if (err)
2023 goto out_close; 2023 goto out_close;
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index e936cea856dc..478f95d92d73 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -114,7 +114,7 @@ int bdi_register(struct backing_dev_info *bdi, struct device *parent,
114 const char *fmt, ...); 114 const char *fmt, ...);
115int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev); 115int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
116void bdi_unregister(struct backing_dev_info *bdi); 116void bdi_unregister(struct backing_dev_info *bdi);
117int __must_check bdi_setup_and_register(struct backing_dev_info *, char *, unsigned int); 117int __must_check bdi_setup_and_register(struct backing_dev_info *, char *);
118void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages, 118void bdi_start_writeback(struct backing_dev_info *bdi, long nr_pages,
119 enum wb_reason reason); 119 enum wb_reason reason);
120void bdi_start_background_writeback(struct backing_dev_info *bdi); 120void bdi_start_background_writeback(struct backing_dev_info *bdi);
@@ -228,42 +228,17 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
228 * BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting 228 * BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting
229 * BDI_CAP_NO_WRITEBACK: Don't write pages back 229 * BDI_CAP_NO_WRITEBACK: Don't write pages back
230 * BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages 230 * BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
231 *
232 * These flags let !MMU mmap() govern direct device mapping vs immediate
233 * copying more easily for MAP_PRIVATE, especially for ROM filesystems.
234 *
235 * BDI_CAP_MAP_COPY: Copy can be mapped (MAP_PRIVATE)
236 * BDI_CAP_MAP_DIRECT: Can be mapped directly (MAP_SHARED)
237 * BDI_CAP_READ_MAP: Can be mapped for reading
238 * BDI_CAP_WRITE_MAP: Can be mapped for writing
239 * BDI_CAP_EXEC_MAP: Can be mapped for execution
240 *
241 * BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold. 231 * BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold.
242 */ 232 */
243#define BDI_CAP_NO_ACCT_DIRTY 0x00000001 233#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
244#define BDI_CAP_NO_WRITEBACK 0x00000002 234#define BDI_CAP_NO_WRITEBACK 0x00000002
245#define BDI_CAP_MAP_COPY 0x00000004 235#define BDI_CAP_NO_ACCT_WB 0x00000004
246#define BDI_CAP_MAP_DIRECT 0x00000008 236#define BDI_CAP_STABLE_WRITES 0x00000008
247#define BDI_CAP_READ_MAP 0x00000010 237#define BDI_CAP_STRICTLIMIT 0x00000010
248#define BDI_CAP_WRITE_MAP 0x00000020
249#define BDI_CAP_EXEC_MAP 0x00000040
250#define BDI_CAP_NO_ACCT_WB 0x00000080
251#define BDI_CAP_STABLE_WRITES 0x00000200
252#define BDI_CAP_STRICTLIMIT 0x00000400
253
254#define BDI_CAP_VMFLAGS \
255 (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
256 238
257#define BDI_CAP_NO_ACCT_AND_WRITEBACK \ 239#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
258 (BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB) 240 (BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
259 241
260#if defined(VM_MAYREAD) && \
261 (BDI_CAP_READ_MAP != VM_MAYREAD || \
262 BDI_CAP_WRITE_MAP != VM_MAYWRITE || \
263 BDI_CAP_EXEC_MAP != VM_MAYEXEC)
264#error please change backing_dev_info::capabilities flags
265#endif
266
267extern struct backing_dev_info default_backing_dev_info; 242extern struct backing_dev_info default_backing_dev_info;
268extern struct backing_dev_info noop_backing_dev_info; 243extern struct backing_dev_info noop_backing_dev_info;
269 244
diff --git a/include/linux/cdev.h b/include/linux/cdev.h
index fb4591977b03..f8763615a5f2 100644
--- a/include/linux/cdev.h
+++ b/include/linux/cdev.h
@@ -30,6 +30,4 @@ void cdev_del(struct cdev *);
30 30
31void cd_forget(struct inode *); 31void cd_forget(struct inode *);
32 32
33extern struct backing_dev_info directly_mappable_cdev_bdi;
34
35#endif 33#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 42efe13077b6..1dada399aa23 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1502,6 +1502,26 @@ struct block_device_operations;
1502#define HAVE_COMPAT_IOCTL 1 1502#define HAVE_COMPAT_IOCTL 1
1503#define HAVE_UNLOCKED_IOCTL 1 1503#define HAVE_UNLOCKED_IOCTL 1
1504 1504
1505/*
1506 * These flags let !MMU mmap() govern direct device mapping vs immediate
1507 * copying more easily for MAP_PRIVATE, especially for ROM filesystems.
1508 *
1509 * NOMMU_MAP_COPY: Copy can be mapped (MAP_PRIVATE)
1510 * NOMMU_MAP_DIRECT: Can be mapped directly (MAP_SHARED)
1511 * NOMMU_MAP_READ: Can be mapped for reading
1512 * NOMMU_MAP_WRITE: Can be mapped for writing
1513 * NOMMU_MAP_EXEC: Can be mapped for execution
1514 */
1515#define NOMMU_MAP_COPY 0x00000001
1516#define NOMMU_MAP_DIRECT 0x00000008
1517#define NOMMU_MAP_READ VM_MAYREAD
1518#define NOMMU_MAP_WRITE VM_MAYWRITE
1519#define NOMMU_MAP_EXEC VM_MAYEXEC
1520
1521#define NOMMU_VMFLAGS \
1522 (NOMMU_MAP_READ | NOMMU_MAP_WRITE | NOMMU_MAP_EXEC)
1523
1524
1505struct iov_iter; 1525struct iov_iter;
1506 1526
1507struct file_operations { 1527struct file_operations {
@@ -1536,6 +1556,9 @@ struct file_operations {
1536 long (*fallocate)(struct file *file, int mode, loff_t offset, 1556 long (*fallocate)(struct file *file, int mode, loff_t offset,
1537 loff_t len); 1557 loff_t len);
1538 void (*show_fdinfo)(struct seq_file *m, struct file *f); 1558 void (*show_fdinfo)(struct seq_file *m, struct file *f);
1559#ifndef CONFIG_MMU
1560 unsigned (*mmap_capabilities)(struct file *);
1561#endif
1539}; 1562};
1540 1563
1541struct inode_operations { 1564struct inode_operations {
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 031ff3a9a0bd..3301c4c289d6 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -408,4 +408,6 @@ static inline int mtd_is_bitflip_or_eccerr(int err) {
408 return mtd_is_bitflip(err) || mtd_is_eccerr(err); 408 return mtd_is_bitflip(err) || mtd_is_eccerr(err);
409} 409}
410 410
411unsigned mtd_mmap_capabilities(struct mtd_info *mtd);
412
411#endif /* __MTD_MTD_H__ */ 413#endif /* __MTD_MTD_H__ */
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 0ae0df55000b..16c68958aeda 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -17,8 +17,6 @@ static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
17struct backing_dev_info default_backing_dev_info = { 17struct backing_dev_info default_backing_dev_info = {
18 .name = "default", 18 .name = "default",
19 .ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_CACHE_SIZE, 19 .ra_pages = VM_MAX_READAHEAD * 1024 / PAGE_CACHE_SIZE,
20 .state = 0,
21 .capabilities = BDI_CAP_MAP_COPY,
22}; 20};
23EXPORT_SYMBOL_GPL(default_backing_dev_info); 21EXPORT_SYMBOL_GPL(default_backing_dev_info);
24 22
@@ -513,13 +511,12 @@ EXPORT_SYMBOL(bdi_destroy);
513 * For use from filesystems to quickly init and register a bdi associated 511 * For use from filesystems to quickly init and register a bdi associated
514 * with dirty writeback 512 * with dirty writeback
515 */ 513 */
516int bdi_setup_and_register(struct backing_dev_info *bdi, char *name, 514int bdi_setup_and_register(struct backing_dev_info *bdi, char *name)
517 unsigned int cap)
518{ 515{
519 int err; 516 int err;
520 517
521 bdi->name = name; 518 bdi->name = name;
522 bdi->capabilities = cap; 519 bdi->capabilities = 0;
523 err = bdi_init(bdi); 520 err = bdi_init(bdi);
524 if (err) 521 if (err)
525 return err; 522 return err;
diff --git a/mm/nommu.c b/mm/nommu.c
index b51eadf6d952..13af96f35a4b 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -946,9 +946,6 @@ static int validate_mmap_request(struct file *file,
946 return -EOVERFLOW; 946 return -EOVERFLOW;
947 947
948 if (file) { 948 if (file) {
949 /* validate file mapping requests */
950 struct address_space *mapping;
951
952 /* files must support mmap */ 949 /* files must support mmap */
953 if (!file->f_op->mmap) 950 if (!file->f_op->mmap)
954 return -ENODEV; 951 return -ENODEV;
@@ -957,28 +954,22 @@ static int validate_mmap_request(struct file *file,
957 * - we support chardevs that provide their own "memory" 954 * - we support chardevs that provide their own "memory"
958 * - we support files/blockdevs that are memory backed 955 * - we support files/blockdevs that are memory backed
959 */ 956 */
960 mapping = file->f_mapping; 957 if (file->f_op->mmap_capabilities) {
961 if (!mapping) 958 capabilities = file->f_op->mmap_capabilities(file);
962 mapping = file_inode(file)->i_mapping; 959 } else {
963
964 capabilities = 0;
965 if (mapping && mapping->backing_dev_info)
966 capabilities = mapping->backing_dev_info->capabilities;
967
968 if (!capabilities) {
969 /* no explicit capabilities set, so assume some 960 /* no explicit capabilities set, so assume some
970 * defaults */ 961 * defaults */
971 switch (file_inode(file)->i_mode & S_IFMT) { 962 switch (file_inode(file)->i_mode & S_IFMT) {
972 case S_IFREG: 963 case S_IFREG:
973 case S_IFBLK: 964 case S_IFBLK:
974 capabilities = BDI_CAP_MAP_COPY; 965 capabilities = NOMMU_MAP_COPY;
975 break; 966 break;
976 967
977 case S_IFCHR: 968 case S_IFCHR:
978 capabilities = 969 capabilities =
979 BDI_CAP_MAP_DIRECT | 970 NOMMU_MAP_DIRECT |
980 BDI_CAP_READ_MAP | 971 NOMMU_MAP_READ |
981 BDI_CAP_WRITE_MAP; 972 NOMMU_MAP_WRITE;
982 break; 973 break;
983 974
984 default: 975 default:
@@ -989,9 +980,9 @@ static int validate_mmap_request(struct file *file,
989 /* eliminate any capabilities that we can't support on this 980 /* eliminate any capabilities that we can't support on this
990 * device */ 981 * device */
991 if (!file->f_op->get_unmapped_area) 982 if (!file->f_op->get_unmapped_area)
992 capabilities &= ~BDI_CAP_MAP_DIRECT; 983 capabilities &= ~NOMMU_MAP_DIRECT;
993 if (!file->f_op->read) 984 if (!file->f_op->read)
994 capabilities &= ~BDI_CAP_MAP_COPY; 985 capabilities &= ~NOMMU_MAP_COPY;
995 986
996 /* The file shall have been opened with read permission. */ 987 /* The file shall have been opened with read permission. */
997 if (!(file->f_mode & FMODE_READ)) 988 if (!(file->f_mode & FMODE_READ))
@@ -1010,29 +1001,29 @@ static int validate_mmap_request(struct file *file,
1010 if (locks_verify_locked(file)) 1001 if (locks_verify_locked(file))
1011 return -EAGAIN; 1002 return -EAGAIN;
1012 1003
1013 if (!(capabilities & BDI_CAP_MAP_DIRECT)) 1004 if (!(capabilities & NOMMU_MAP_DIRECT))
1014 return -ENODEV; 1005 return -ENODEV;
1015 1006
1016 /* we mustn't privatise shared mappings */ 1007 /* we mustn't privatise shared mappings */
1017 capabilities &= ~BDI_CAP_MAP_COPY; 1008 capabilities &= ~NOMMU_MAP_COPY;
1018 } else { 1009 } else {
1019 /* we're going to read the file into private memory we 1010 /* we're going to read the file into private memory we
1020 * allocate */ 1011 * allocate */
1021 if (!(capabilities & BDI_CAP_MAP_COPY)) 1012 if (!(capabilities & NOMMU_MAP_COPY))
1022 return -ENODEV; 1013 return -ENODEV;
1023 1014
1024 /* we don't permit a private writable mapping to be 1015 /* we don't permit a private writable mapping to be
1025 * shared with the backing device */ 1016 * shared with the backing device */
1026 if (prot & PROT_WRITE) 1017 if (prot & PROT_WRITE)
1027 capabilities &= ~BDI_CAP_MAP_DIRECT; 1018 capabilities &= ~NOMMU_MAP_DIRECT;
1028 } 1019 }
1029 1020
1030 if (capabilities & BDI_CAP_MAP_DIRECT) { 1021 if (capabilities & NOMMU_MAP_DIRECT) {
1031 if (((prot & PROT_READ) && !(capabilities & BDI_CAP_READ_MAP)) || 1022 if (((prot & PROT_READ) && !(capabilities & NOMMU_MAP_READ)) ||
1032 ((prot & PROT_WRITE) && !(capabilities & BDI_CAP_WRITE_MAP)) || 1023 ((prot & PROT_WRITE) && !(capabilities & NOMMU_MAP_WRITE)) ||
1033 ((prot & PROT_EXEC) && !(capabilities & BDI_CAP_EXEC_MAP)) 1024 ((prot & PROT_EXEC) && !(capabilities & NOMMU_MAP_EXEC))
1034 ) { 1025 ) {
1035 capabilities &= ~BDI_CAP_MAP_DIRECT; 1026 capabilities &= ~NOMMU_MAP_DIRECT;
1036 if (flags & MAP_SHARED) { 1027 if (flags & MAP_SHARED) {
1037 printk(KERN_WARNING 1028 printk(KERN_WARNING
1038 "MAP_SHARED not completely supported on !MMU\n"); 1029 "MAP_SHARED not completely supported on !MMU\n");
@@ -1049,21 +1040,21 @@ static int validate_mmap_request(struct file *file,
1049 } else if ((prot & PROT_READ) && !(prot & PROT_EXEC)) { 1040 } else if ((prot & PROT_READ) && !(prot & PROT_EXEC)) {
1050 /* handle implication of PROT_EXEC by PROT_READ */ 1041 /* handle implication of PROT_EXEC by PROT_READ */
1051 if (current->personality & READ_IMPLIES_EXEC) { 1042 if (current->personality & READ_IMPLIES_EXEC) {
1052 if (capabilities & BDI_CAP_EXEC_MAP) 1043 if (capabilities & NOMMU_MAP_EXEC)
1053 prot |= PROT_EXEC; 1044 prot |= PROT_EXEC;
1054 } 1045 }
1055 } else if ((prot & PROT_READ) && 1046 } else if ((prot & PROT_READ) &&
1056 (prot & PROT_EXEC) && 1047 (prot & PROT_EXEC) &&
1057 !(capabilities & BDI_CAP_EXEC_MAP) 1048 !(capabilities & NOMMU_MAP_EXEC)
1058 ) { 1049 ) {
1059 /* backing file is not executable, try to copy */ 1050 /* backing file is not executable, try to copy */
1060 capabilities &= ~BDI_CAP_MAP_DIRECT; 1051 capabilities &= ~NOMMU_MAP_DIRECT;
1061 } 1052 }
1062 } else { 1053 } else {
1063 /* anonymous mappings are always memory backed and can be 1054 /* anonymous mappings are always memory backed and can be
1064 * privately mapped 1055 * privately mapped
1065 */ 1056 */
1066 capabilities = BDI_CAP_MAP_COPY; 1057 capabilities = NOMMU_MAP_COPY;
1067 1058
1068 /* handle PROT_EXEC implication by PROT_READ */ 1059 /* handle PROT_EXEC implication by PROT_READ */
1069 if ((prot & PROT_READ) && 1060 if ((prot & PROT_READ) &&
@@ -1095,7 +1086,7 @@ static unsigned long determine_vm_flags(struct file *file,
1095 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags); 1086 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags);
1096 /* vm_flags |= mm->def_flags; */ 1087 /* vm_flags |= mm->def_flags; */
1097 1088
1098 if (!(capabilities & BDI_CAP_MAP_DIRECT)) { 1089 if (!(capabilities & NOMMU_MAP_DIRECT)) {
1099 /* attempt to share read-only copies of mapped file chunks */ 1090 /* attempt to share read-only copies of mapped file chunks */
1100 vm_flags |= VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; 1091 vm_flags |= VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
1101 if (file && !(prot & PROT_WRITE)) 1092 if (file && !(prot & PROT_WRITE))
@@ -1104,7 +1095,7 @@ static unsigned long determine_vm_flags(struct file *file,
1104 /* overlay a shareable mapping on the backing device or inode 1095 /* overlay a shareable mapping on the backing device or inode
1105 * if possible - used for chardevs, ramfs/tmpfs/shmfs and 1096 * if possible - used for chardevs, ramfs/tmpfs/shmfs and
1106 * romfs/cramfs */ 1097 * romfs/cramfs */
1107 vm_flags |= VM_MAYSHARE | (capabilities & BDI_CAP_VMFLAGS); 1098 vm_flags |= VM_MAYSHARE | (capabilities & NOMMU_VMFLAGS);
1108 if (flags & MAP_SHARED) 1099 if (flags & MAP_SHARED)
1109 vm_flags |= VM_SHARED; 1100 vm_flags |= VM_SHARED;
1110 } 1101 }
@@ -1157,7 +1148,7 @@ static int do_mmap_private(struct vm_area_struct *vma,
1157 * shared mappings on devices or memory 1148 * shared mappings on devices or memory
1158 * - VM_MAYSHARE will be set if it may attempt to share 1149 * - VM_MAYSHARE will be set if it may attempt to share
1159 */ 1150 */
1160 if (capabilities & BDI_CAP_MAP_DIRECT) { 1151 if (capabilities & NOMMU_MAP_DIRECT) {
1161 ret = vma->vm_file->f_op->mmap(vma->vm_file, vma); 1152 ret = vma->vm_file->f_op->mmap(vma->vm_file, vma);
1162 if (ret == 0) { 1153 if (ret == 0) {
1163 /* shouldn't return success if we're not sharing */ 1154 /* shouldn't return success if we're not sharing */
@@ -1346,7 +1337,7 @@ unsigned long do_mmap_pgoff(struct file *file,
1346 if ((pregion->vm_pgoff != pgoff || rpglen != pglen) && 1337 if ((pregion->vm_pgoff != pgoff || rpglen != pglen) &&
1347 !(pgoff >= pregion->vm_pgoff && pgend <= rpgend)) { 1338 !(pgoff >= pregion->vm_pgoff && pgend <= rpgend)) {
1348 /* new mapping is not a subset of the region */ 1339 /* new mapping is not a subset of the region */
1349 if (!(capabilities & BDI_CAP_MAP_DIRECT)) 1340 if (!(capabilities & NOMMU_MAP_DIRECT))
1350 goto sharing_violation; 1341 goto sharing_violation;
1351 continue; 1342 continue;
1352 } 1343 }
@@ -1385,7 +1376,7 @@ unsigned long do_mmap_pgoff(struct file *file,
1385 * - this is the hook for quasi-memory character devices to 1376 * - this is the hook for quasi-memory character devices to
1386 * tell us the location of a shared mapping 1377 * tell us the location of a shared mapping
1387 */ 1378 */
1388 if (capabilities & BDI_CAP_MAP_DIRECT) { 1379 if (capabilities & NOMMU_MAP_DIRECT) {
1389 addr = file->f_op->get_unmapped_area(file, addr, len, 1380 addr = file->f_op->get_unmapped_area(file, addr, len,
1390 pgoff, flags); 1381 pgoff, flags);
1391 if (IS_ERR_VALUE(addr)) { 1382 if (IS_ERR_VALUE(addr)) {
@@ -1397,10 +1388,10 @@ unsigned long do_mmap_pgoff(struct file *file,
1397 * the mapping so we'll have to attempt to copy 1388 * the mapping so we'll have to attempt to copy
1398 * it */ 1389 * it */
1399 ret = -ENODEV; 1390 ret = -ENODEV;
1400 if (!(capabilities & BDI_CAP_MAP_COPY)) 1391 if (!(capabilities & NOMMU_MAP_COPY))
1401 goto error_just_free; 1392 goto error_just_free;
1402 1393
1403 capabilities &= ~BDI_CAP_MAP_DIRECT; 1394 capabilities &= ~NOMMU_MAP_DIRECT;
1404 } else { 1395 } else {
1405 vma->vm_start = region->vm_start = addr; 1396 vma->vm_start = region->vm_start = addr;
1406 vma->vm_end = region->vm_end = addr + len; 1397 vma->vm_end = region->vm_end = addr + len;
@@ -1411,7 +1402,7 @@ unsigned long do_mmap_pgoff(struct file *file,
1411 vma->vm_region = region; 1402 vma->vm_region = region;
1412 1403
1413 /* set up the mapping 1404 /* set up the mapping
1414 * - the region is filled in if BDI_CAP_MAP_DIRECT is still set 1405 * - the region is filled in if NOMMU_MAP_DIRECT is still set
1415 */ 1406 */
1416 if (file && vma->vm_flags & VM_SHARED) 1407 if (file && vma->vm_flags & VM_SHARED)
1417 ret = do_mmap_shared_file(vma); 1408 ret = do_mmap_shared_file(vma);
diff --git a/security/security.c b/security/security.c
index 18b35c63fc0c..a0442b20f001 100644
--- a/security/security.c
+++ b/security/security.c
@@ -726,16 +726,15 @@ static inline unsigned long mmap_prot(struct file *file, unsigned long prot)
726 return prot | PROT_EXEC; 726 return prot | PROT_EXEC;
727 /* 727 /*
728 * ditto if it's not on noexec mount, except that on !MMU we need 728 * ditto if it's not on noexec mount, except that on !MMU we need
729 * BDI_CAP_EXEC_MMAP (== VM_MAYEXEC) in this case 729 * NOMMU_MAP_EXEC (== VM_MAYEXEC) in this case
730 */ 730 */
731 if (!(file->f_path.mnt->mnt_flags & MNT_NOEXEC)) { 731 if (!(file->f_path.mnt->mnt_flags & MNT_NOEXEC)) {
732#ifndef CONFIG_MMU 732#ifndef CONFIG_MMU
733 unsigned long caps = 0; 733 if (file->f_op->mmap_capabilities) {
734 struct address_space *mapping = file->f_mapping; 734 unsigned caps = file->f_op->mmap_capabilities(file);
735 if (mapping && mapping->backing_dev_info) 735 if (!(caps & NOMMU_MAP_EXEC))
736 caps = mapping->backing_dev_info->capabilities; 736 return prot;
737 if (!(caps & BDI_CAP_EXEC_MAP)) 737 }
738 return prot;
739#endif 738#endif
740 return prot | PROT_EXEC; 739 return prot | PROT_EXEC;
741 } 740 }