Skip to content

Commit b0e1519

Browse files
dhowellsLinus Torvalds
authored andcommitted
[PATCH] NOMMU: Make SYSV IPC SHM use ramfs facilities on NOMMU
The attached patch makes the SYSV IPC shared memory facilities use the new ramfs facilities on a no-MMU kernel. The following changes are made: (1) There are now shmem_mmap() and shmem_get_unmapped_area() functions to allow the IPC SHM facilities to commune with the tiny-shmem and shmem code. (2) ramfs files now need resizing using do_truncate() rather than by modifying the inode size directly (see shmem_file_setup()). This causes ramfs to attempt to bind a block of pages of sufficient size to the inode. (3) CONFIG_SYSVIPC is no longer contingent on CONFIG_MMU. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 642fb4d commit b0e1519

6 files changed

Lines changed: 58 additions & 8 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,18 @@ static inline struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
654654
}
655655
#endif
656656
struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags);
657+
extern int shmem_mmap(struct file *file, struct vm_area_struct *vma);
657658

658659
int shmem_zero_setup(struct vm_area_struct *);
659660

661+
#ifndef CONFIG_MMU
662+
extern unsigned long shmem_get_unmapped_area(struct file *file,
663+
unsigned long addr,
664+
unsigned long len,
665+
unsigned long pgoff,
666+
unsigned long flags);
667+
#endif
668+
660669
static inline int can_do_mlock(void)
661670
{
662671
if (capable(CAP_IPC_LOCK))

‎init/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ config SWAP
105105

106106
config SYSVIPC
107107
bool "System V IPC"
108-
depends on MMU
109108
---help---
110109
Inter Process Communication is a suite of library functions and
111110
system calls which let processes (running programs) synchronize and

‎ipc/shm.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,22 @@ static void shm_close (struct vm_area_struct *shmd)
157157

158158
static int shm_mmap(struct file * file, struct vm_area_struct * vma)
159159
{
160-
file_accessed(file);
161-
vma->vm_ops = &shm_vm_ops;
162-
shm_inc(file->f_dentry->d_inode->i_ino);
163-
return 0;
160+
int ret;
161+
162+
ret = shmem_mmap(file, vma);
163+
if (ret == 0) {
164+
vma->vm_ops = &shm_vm_ops;
165+
shm_inc(file->f_dentry->d_inode->i_ino);
166+
}
167+
168+
return ret;
164169
}
165170

166171
static struct file_operations shm_file_operations = {
167-
.mmap = shm_mmap
172+
.mmap = shm_mmap,
173+
#ifndef CONFIG_MMU
174+
.get_unmapped_area = shmem_get_unmapped_area,
175+
#endif
168176
};
169177

170178
static struct vm_operations_struct shm_vm_ops = {

‎mm/nommu.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,10 @@ int in_gate_area_no_task(unsigned long addr)
11771177
{
11781178
return 0;
11791179
}
1180+
1181+
struct page *filemap_nopage(struct vm_area_struct *area,
1182+
unsigned long address, int *type)
1183+
{
1184+
BUG();
1185+
return NULL;
1186+
}

‎mm/shmem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user)
12701270
return retval;
12711271
}
12721272

1273-
static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
1273+
int shmem_mmap(struct file *file, struct vm_area_struct *vma)
12741274
{
12751275
file_accessed(file);
12761276
vma->vm_ops = &shmem_vm_ops;

‎mm/tiny-shmem.c‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
8181
goto close_file;
8282

8383
d_instantiate(dentry, inode);
84-
inode->i_size = size;
8584
inode->i_nlink = 0; /* It is unlinked */
85+
8686
file->f_vfsmnt = mntget(shm_mnt);
8787
file->f_dentry = dentry;
8888
file->f_mapping = inode->i_mapping;
8989
file->f_op = &ramfs_file_operations;
9090
file->f_mode = FMODE_WRITE | FMODE_READ;
91+
92+
/* notify everyone as to the change of file size */
93+
error = do_truncate(dentry, size, file);
94+
if (error < 0)
95+
goto close_file;
96+
9197
return file;
9298

9399
close_file:
@@ -123,3 +129,24 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
123129
{
124130
return 0;
125131
}
132+
133+
int shmem_mmap(struct file *file, struct vm_area_struct *vma)
134+
{
135+
file_accessed(file);
136+
#ifndef CONFIG_MMU
137+
return ramfs_nommu_mmap(file, vma);
138+
#else
139+
return 0;
140+
#endif
141+
}
142+
143+
#ifndef CONFIG_MMU
144+
unsigned long shmem_get_unmapped_area(struct file *file,
145+
unsigned long addr,
146+
unsigned long len,
147+
unsigned long pgoff,
148+
unsigned long flags)
149+
{
150+
return ramfs_nommu_get_unmapped_area(file, addr, len, pgoff, flags);
151+
}
152+
#endif

0 commit comments

Comments
 (0)