Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/mm/filemap_xip.c |
| 3 | * |
| 4 | * Copyright (C) 2005 IBM Corporation |
| 5 | * Author: Carsten Otte <cotte@de.ibm.com> |
| 6 | * |
| 7 | * derived from linux/mm/filemap.c - Copyright (C) Linus Torvalds |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/fs.h> |
Christoph Hellwig | de1414a | 2015-01-14 10:42:36 +0100 | [diff] [blame] | 12 | #include <linux/backing-dev.h> |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 13 | #include <linux/pagemap.h> |
Paul Gortmaker | b95f1b31 | 2011-10-16 02:01:52 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 15 | #include <linux/uio.h> |
| 16 | #include <linux/rmap.h> |
Andrea Arcangeli | cddb8a5 | 2008-07-28 15:46:29 -0700 | [diff] [blame] | 17 | #include <linux/mmu_notifier.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 18 | #include <linux/sched.h> |
Nick Piggin | 538f8ea6 | 2008-08-20 14:09:20 -0700 | [diff] [blame] | 19 | #include <linux/seqlock.h> |
| 20 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/gfp.h> |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 22 | #include <asm/tlbflush.h> |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 26 | * truncate a page used for execute in place |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 27 | * functionality is analog to block_truncate_page but does use get_xip_mem |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 28 | * to get the page instead of page cache |
| 29 | */ |
| 30 | int |
| 31 | xip_truncate_page(struct address_space *mapping, loff_t from) |
| 32 | { |
| 33 | pgoff_t index = from >> PAGE_CACHE_SHIFT; |
| 34 | unsigned offset = from & (PAGE_CACHE_SIZE-1); |
| 35 | unsigned blocksize; |
| 36 | unsigned length; |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 37 | void *xip_mem; |
| 38 | unsigned long xip_pfn; |
| 39 | int err; |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 40 | |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 41 | BUG_ON(!mapping->a_ops->get_xip_mem); |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 42 | |
| 43 | blocksize = 1 << mapping->host->i_blkbits; |
| 44 | length = offset & (blocksize - 1); |
| 45 | |
| 46 | /* Block boundary? Nothing to do */ |
| 47 | if (!length) |
| 48 | return 0; |
| 49 | |
| 50 | length = blocksize - length; |
| 51 | |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 52 | err = mapping->a_ops->get_xip_mem(mapping, index, 0, |
| 53 | &xip_mem, &xip_pfn); |
| 54 | if (unlikely(err)) { |
| 55 | if (err == -ENODATA) |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 56 | /* Hole? No need to truncate */ |
| 57 | return 0; |
Carsten Otte | eb6fe0c | 2005-06-23 22:05:28 -0700 | [diff] [blame] | 58 | else |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 59 | return err; |
Carsten Otte | afa597b | 2005-07-15 03:56:30 -0700 | [diff] [blame] | 60 | } |
Nick Piggin | 70688e4 | 2008-04-28 02:13:02 -0700 | [diff] [blame] | 61 | memset(xip_mem + offset, 0, length); |
Carsten Otte | eb6fe0c | 2005-06-23 22:05:28 -0700 | [diff] [blame] | 62 | return 0; |
Carsten Otte | ceffc07 | 2005-06-23 22:05:25 -0700 | [diff] [blame] | 63 | } |
| 64 | EXPORT_SYMBOL_GPL(xip_truncate_page); |