blob: 59fb387b223870bfc082809afab1cb5fb2039661 [file] [log] [blame]
Carsten Otteceffc072005-06-23 22:05:25 -07001/*
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 Hellwigde1414a2015-01-14 10:42:36 +010012#include <linux/backing-dev.h>
Carsten Otteceffc072005-06-23 22:05:25 -070013#include <linux/pagemap.h>
Paul Gortmakerb95f1b312011-10-16 02:01:52 -040014#include <linux/export.h>
Carsten Otteceffc072005-06-23 22:05:25 -070015#include <linux/uio.h>
16#include <linux/rmap.h>
Andrea Arcangelicddb8a52008-07-28 15:46:29 -070017#include <linux/mmu_notifier.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040018#include <linux/sched.h>
Nick Piggin538f8ea62008-08-20 14:09:20 -070019#include <linux/seqlock.h>
20#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/gfp.h>
Carsten Otteceffc072005-06-23 22:05:25 -070022#include <asm/tlbflush.h>
Nick Piggin70688e42008-04-28 02:13:02 -070023#include <asm/io.h>
Carsten Otteceffc072005-06-23 22:05:25 -070024
25/*
Carsten Otteceffc072005-06-23 22:05:25 -070026 * truncate a page used for execute in place
Nick Piggin70688e42008-04-28 02:13:02 -070027 * functionality is analog to block_truncate_page but does use get_xip_mem
Carsten Otteceffc072005-06-23 22:05:25 -070028 * to get the page instead of page cache
29 */
30int
31xip_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 Piggin70688e42008-04-28 02:13:02 -070037 void *xip_mem;
38 unsigned long xip_pfn;
39 int err;
Carsten Otteceffc072005-06-23 22:05:25 -070040
Nick Piggin70688e42008-04-28 02:13:02 -070041 BUG_ON(!mapping->a_ops->get_xip_mem);
Carsten Otteceffc072005-06-23 22:05:25 -070042
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 Piggin70688e42008-04-28 02:13:02 -070052 err = mapping->a_ops->get_xip_mem(mapping, index, 0,
53 &xip_mem, &xip_pfn);
54 if (unlikely(err)) {
55 if (err == -ENODATA)
Carsten Otteceffc072005-06-23 22:05:25 -070056 /* Hole? No need to truncate */
57 return 0;
Carsten Otteeb6fe0c2005-06-23 22:05:28 -070058 else
Nick Piggin70688e42008-04-28 02:13:02 -070059 return err;
Carsten Otteafa597b2005-07-15 03:56:30 -070060 }
Nick Piggin70688e42008-04-28 02:13:02 -070061 memset(xip_mem + offset, 0, length);
Carsten Otteeb6fe0c2005-06-23 22:05:28 -070062 return 0;
Carsten Otteceffc072005-06-23 22:05:25 -070063}
64EXPORT_SYMBOL_GPL(xip_truncate_page);