Skip to content

Commit ceffc07

Browse files
cotte-ibmLinus Torvalds
authored andcommitted
[PATCH] xip: fs/mm: execute in place
- generic_file* file operations do no longer have a xip/non-xip split - filemap_xip.c implements a new set of fops that require get_xip_page aop to work proper. all new fops are exported GPL-only (don't like to see whatever code use those except GPL modules) - __xip_unmap now uses page_check_address, which is no longer static in rmap.c, and defined in linux/rmap.h - mm/filemap.h is now much more clean, plainly having just Linus' inline funcs moved here from filemap.c - fix includes in filemap_xip to make it build cleanly on i386 Signed-off-by: Carsten Otte <cotte@de.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 420edbc commit ceffc07

8 files changed

Lines changed: 707 additions & 75 deletions

File tree

‎fs/open.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,9 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
808808

809809
/* NB: we're sure to have correct a_ops only after f_op->open */
810810
if (f->f_flags & O_DIRECT) {
811-
if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO) {
811+
if (!f->f_mapping->a_ops ||
812+
((!f->f_mapping->a_ops->direct_IO) &&
813+
(!f->f_mapping->a_ops->get_xip_page))) {
812814
fput(f);
813815
f = ERR_PTR(-EINVAL);
814816
}

‎include/linux/fs.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ struct address_space_operations {
330330
int (*releasepage) (struct page *, int);
331331
ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
332332
loff_t offset, unsigned long nr_segs);
333+
struct page* (*get_xip_page)(struct address_space *, sector_t,
334+
int);
333335
};
334336

335337
struct backing_dev_info;
@@ -1497,6 +1499,22 @@ extern loff_t remote_llseek(struct file *file, loff_t offset, int origin);
14971499
extern int generic_file_open(struct inode * inode, struct file * filp);
14981500
extern int nonseekable_open(struct inode * inode, struct file * filp);
14991501

1502+
#ifdef CONFIG_FS_XIP
1503+
extern ssize_t xip_file_aio_read(struct kiocb *iocb, char __user *buf,
1504+
size_t count, loff_t pos);
1505+
extern ssize_t xip_file_readv(struct file *filp, const struct iovec *iov,
1506+
unsigned long nr_segs, loff_t *ppos);
1507+
extern ssize_t xip_file_sendfile(struct file *in_file, loff_t *ppos,
1508+
size_t count, read_actor_t actor,
1509+
void *target);
1510+
extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
1511+
extern ssize_t xip_file_aio_write(struct kiocb *iocb, const char __user *buf,
1512+
size_t count, loff_t pos);
1513+
extern ssize_t xip_file_writev(struct file *file, const struct iovec *iov,
1514+
unsigned long nr_segs, loff_t *ppos);
1515+
extern int xip_truncate_page(struct address_space *mapping, loff_t from);
1516+
#endif
1517+
15001518
static inline void do_generic_file_read(struct file * filp, loff_t *ppos,
15011519
read_descriptor_t * desc,
15021520
read_actor_t actor)

‎include/linux/rmap.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ static inline void page_dup_rmap(struct page *page)
9292
int page_referenced(struct page *, int is_locked, int ignore_token);
9393
int try_to_unmap(struct page *);
9494

95+
/*
96+
* Called from mm/filemap_xip.c to unmap empty zero page
97+
*/
98+
pte_t *page_check_address(struct page *, struct mm_struct *, unsigned long);
99+
100+
95101
/*
96102
* Used by swapoff to help locate where page is expected in vma.
97103
*/

‎mm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ obj-$(CONFIG_SPARSEMEM) += sparse.o
1919
obj-$(CONFIG_SHMEM) += shmem.o
2020
obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
2121

22+
obj-$(CONFIG_FS_XIP) += filemap_xip.o

‎mm/filemap.c‎

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/blkdev.h>
2929
#include <linux/security.h>
3030
#include <linux/syscalls.h>
31+
#include "filemap.h"
3132
/*
3233
* FIXME: remove all knowledge of the buffer layer from the core VM
3334
*/
@@ -1714,32 +1715,7 @@ int remove_suid(struct dentry *dentry)
17141715
}
17151716
EXPORT_SYMBOL(remove_suid);
17161717

1717-
/*
1718-
* Copy as much as we can into the page and return the number of bytes which
1719-
* were sucessfully copied. If a fault is encountered then clear the page
1720-
* out to (offset+bytes) and return the number of bytes which were copied.
1721-
*/
1722-
static inline size_t
1723-
filemap_copy_from_user(struct page *page, unsigned long offset,
1724-
const char __user *buf, unsigned bytes)
1725-
{
1726-
char *kaddr;
1727-
int left;
1728-
1729-
kaddr = kmap_atomic(page, KM_USER0);
1730-
left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
1731-
kunmap_atomic(kaddr, KM_USER0);
1732-
1733-
if (left != 0) {
1734-
/* Do it the slow way */
1735-
kaddr = kmap(page);
1736-
left = __copy_from_user(kaddr + offset, buf, bytes);
1737-
kunmap(page);
1738-
}
1739-
return bytes - left;
1740-
}
1741-
1742-
static size_t
1718+
size_t
17431719
__filemap_copy_from_user_iovec(char *vaddr,
17441720
const struct iovec *iov, size_t base, size_t bytes)
17451721
{
@@ -1766,52 +1742,6 @@ __filemap_copy_from_user_iovec(char *vaddr,
17661742
return copied - left;
17671743
}
17681744

1769-
/*
1770-
* This has the same sideeffects and return value as filemap_copy_from_user().
1771-
* The difference is that on a fault we need to memset the remainder of the
1772-
* page (out to offset+bytes), to emulate filemap_copy_from_user()'s
1773-
* single-segment behaviour.
1774-
*/
1775-
static inline size_t
1776-
filemap_copy_from_user_iovec(struct page *page, unsigned long offset,
1777-
const struct iovec *iov, size_t base, size_t bytes)
1778-
{
1779-
char *kaddr;
1780-
size_t copied;
1781-
1782-
kaddr = kmap_atomic(page, KM_USER0);
1783-
copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
1784-
base, bytes);
1785-
kunmap_atomic(kaddr, KM_USER0);
1786-
if (copied != bytes) {
1787-
kaddr = kmap(page);
1788-
copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
1789-
base, bytes);
1790-
kunmap(page);
1791-
}
1792-
return copied;
1793-
}
1794-
1795-
static inline void
1796-
filemap_set_next_iovec(const struct iovec **iovp, size_t *basep, size_t bytes)
1797-
{
1798-
const struct iovec *iov = *iovp;
1799-
size_t base = *basep;
1800-
1801-
while (bytes) {
1802-
int copy = min(bytes, iov->iov_len - base);
1803-
1804-
bytes -= copy;
1805-
base += copy;
1806-
if (iov->iov_len == base) {
1807-
iov++;
1808-
base = 0;
1809-
}
1810-
}
1811-
*iovp = iov;
1812-
*basep = base;
1813-
}
1814-
18151745
/*
18161746
* Performs necessary checks before doing a write
18171747
*

‎mm/filemap.h‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* linux/mm/filemap.h
3+
*
4+
* Copyright (C) 1994-1999 Linus Torvalds
5+
*/
6+
7+
#ifndef __FILEMAP_H
8+
#define __FILEMAP_H
9+
10+
#include <linux/types.h>
11+
#include <linux/fs.h>
12+
#include <linux/mm.h>
13+
#include <linux/highmem.h>
14+
#include <linux/uio.h>
15+
#include <linux/config.h>
16+
#include <asm/uaccess.h>
17+
18+
extern size_t
19+
__filemap_copy_from_user_iovec(char *vaddr,
20+
const struct iovec *iov,
21+
size_t base,
22+
size_t bytes);
23+
24+
/*
25+
* Copy as much as we can into the page and return the number of bytes which
26+
* were sucessfully copied. If a fault is encountered then clear the page
27+
* out to (offset+bytes) and return the number of bytes which were copied.
28+
*/
29+
static inline size_t
30+
filemap_copy_from_user(struct page *page, unsigned long offset,
31+
const char __user *buf, unsigned bytes)
32+
{
33+
char *kaddr;
34+
int left;
35+
36+
kaddr = kmap_atomic(page, KM_USER0);
37+
left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
38+
kunmap_atomic(kaddr, KM_USER0);
39+
40+
if (left != 0) {
41+
/* Do it the slow way */
42+
kaddr = kmap(page);
43+
left = __copy_from_user(kaddr + offset, buf, bytes);
44+
kunmap(page);
45+
}
46+
return bytes - left;
47+
}
48+
49+
/*
50+
* This has the same sideeffects and return value as filemap_copy_from_user().
51+
* The difference is that on a fault we need to memset the remainder of the
52+
* page (out to offset+bytes), to emulate filemap_copy_from_user()'s
53+
* single-segment behaviour.
54+
*/
55+
static inline size_t
56+
filemap_copy_from_user_iovec(struct page *page, unsigned long offset,
57+
const struct iovec *iov, size_t base, size_t bytes)
58+
{
59+
char *kaddr;
60+
size_t copied;
61+
62+
kaddr = kmap_atomic(page, KM_USER0);
63+
copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
64+
base, bytes);
65+
kunmap_atomic(kaddr, KM_USER0);
66+
if (copied != bytes) {
67+
kaddr = kmap(page);
68+
copied = __filemap_copy_from_user_iovec(kaddr + offset, iov,
69+
base, bytes);
70+
kunmap(page);
71+
}
72+
return copied;
73+
}
74+
75+
static inline void
76+
filemap_set_next_iovec(const struct iovec **iovp, size_t *basep, size_t bytes)
77+
{
78+
const struct iovec *iov = *iovp;
79+
size_t base = *basep;
80+
81+
while (bytes) {
82+
int copy = min(bytes, iov->iov_len - base);
83+
84+
bytes -= copy;
85+
base += copy;
86+
if (iov->iov_len == base) {
87+
iov++;
88+
base = 0;
89+
}
90+
}
91+
*iovp = iov;
92+
*basep = base;
93+
}
94+
#endif

0 commit comments

Comments
 (0)