Commit 30afcb4b authored by Jared Hulbert's avatar Jared Hulbert Committed by Linus Torvalds

return pfn from direct_access, for XIP

Alter the block device ->direct_access() API to work with the new
get_xip_mem() API (that requires both kaddr and pfn are returned).

Some architectures will not do the right thing in their virt_to_page() for use
by XIP (to translate from the kernel virtual address returned by
direct_access(), to a user mappable pfn in XIP's page fault handler.

However, we can't switch it to just return the pfn and not the kaddr, because
we have no good way to get a kva from a pfn, and XIP requires the kva for its
read(2) and write(2) handlers.  So we have to return both.
Signed-off-by: default avatarJared Hulbert <jaredeh@gmail.com>
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Cc: Carsten Otte <cotte@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux-mm@kvack.org
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 423bad60
...@@ -143,7 +143,7 @@ axon_ram_make_request(struct request_queue *queue, struct bio *bio) ...@@ -143,7 +143,7 @@ axon_ram_make_request(struct request_queue *queue, struct bio *bio)
*/ */
static int static int
axon_ram_direct_access(struct block_device *device, sector_t sector, axon_ram_direct_access(struct block_device *device, sector_t sector,
unsigned long *data) void **kaddr, unsigned long *pfn)
{ {
struct axon_ram_bank *bank = device->bd_disk->private_data; struct axon_ram_bank *bank = device->bd_disk->private_data;
loff_t offset; loff_t offset;
...@@ -154,7 +154,8 @@ axon_ram_direct_access(struct block_device *device, sector_t sector, ...@@ -154,7 +154,8 @@ axon_ram_direct_access(struct block_device *device, sector_t sector,
return -ERANGE; return -ERANGE;
} }
*data = bank->ph_addr + offset; *kaddr = (void *)(bank->ph_addr + offset);
*pfn = virt_to_phys(kaddr) >> PAGE_SHIFT;
return 0; return 0;
} }
......
...@@ -319,7 +319,7 @@ static int brd_make_request(struct request_queue *q, struct bio *bio) ...@@ -319,7 +319,7 @@ static int brd_make_request(struct request_queue *q, struct bio *bio)
#ifdef CONFIG_BLK_DEV_XIP #ifdef CONFIG_BLK_DEV_XIP
static int brd_direct_access (struct block_device *bdev, sector_t sector, static int brd_direct_access (struct block_device *bdev, sector_t sector,
unsigned long *data) void **kaddr, unsigned long *pfn)
{ {
struct brd_device *brd = bdev->bd_disk->private_data; struct brd_device *brd = bdev->bd_disk->private_data;
struct page *page; struct page *page;
...@@ -333,7 +333,8 @@ static int brd_direct_access (struct block_device *bdev, sector_t sector, ...@@ -333,7 +333,8 @@ static int brd_direct_access (struct block_device *bdev, sector_t sector,
page = brd_insert_page(brd, sector); page = brd_insert_page(brd, sector);
if (!page) if (!page)
return -ENOMEM; return -ENOMEM;
*data = (unsigned long)page_address(page); *kaddr = page_address(page);
*pfn = page_to_pfn(page);
return 0; return 0;
} }
......
...@@ -36,7 +36,7 @@ static int dcssblk_open(struct inode *inode, struct file *filp); ...@@ -36,7 +36,7 @@ static int dcssblk_open(struct inode *inode, struct file *filp);
static int dcssblk_release(struct inode *inode, struct file *filp); static int dcssblk_release(struct inode *inode, struct file *filp);
static int dcssblk_make_request(struct request_queue *q, struct bio *bio); static int dcssblk_make_request(struct request_queue *q, struct bio *bio);
static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum, static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum,
unsigned long *data); void **kaddr, unsigned long *pfn);
static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0"; static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0";
...@@ -636,7 +636,7 @@ dcssblk_make_request(struct request_queue *q, struct bio *bio) ...@@ -636,7 +636,7 @@ dcssblk_make_request(struct request_queue *q, struct bio *bio)
static int static int
dcssblk_direct_access (struct block_device *bdev, sector_t secnum, dcssblk_direct_access (struct block_device *bdev, sector_t secnum,
unsigned long *data) void **kaddr, unsigned long *pfn)
{ {
struct dcssblk_dev_info *dev_info; struct dcssblk_dev_info *dev_info;
unsigned long pgoff; unsigned long pgoff;
...@@ -649,7 +649,9 @@ dcssblk_direct_access (struct block_device *bdev, sector_t secnum, ...@@ -649,7 +649,9 @@ dcssblk_direct_access (struct block_device *bdev, sector_t secnum,
pgoff = secnum / (PAGE_SIZE / 512); pgoff = secnum / (PAGE_SIZE / 512);
if ((pgoff+1)*PAGE_SIZE-1 > dev_info->end - dev_info->start) if ((pgoff+1)*PAGE_SIZE-1 > dev_info->end - dev_info->start)
return -ERANGE; return -ERANGE;
*data = (unsigned long) (dev_info->start+pgoff*PAGE_SIZE); *kaddr = (void *) (dev_info->start+pgoff*PAGE_SIZE);
*pfn = virt_to_phys(*kaddr) >> PAGE_SHIFT;
return 0; return 0;
} }
......
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
static inline int static inline int
__inode_direct_access(struct inode *inode, sector_t sector, __inode_direct_access(struct inode *inode, sector_t sector,
unsigned long *data) void **kaddr, unsigned long *pfn)
{ {
BUG_ON(!inode->i_sb->s_bdev->bd_disk->fops->direct_access); struct block_device *bdev = inode->i_sb->s_bdev;
return inode->i_sb->s_bdev->bd_disk->fops struct block_device_operations *ops = bdev->bd_disk->fops;
->direct_access(inode->i_sb->s_bdev,sector,data);
BUG_ON(!ops->direct_access);
return ops->direct_access(bdev, sector, kaddr, pfn);
} }
static inline int static inline int
...@@ -48,12 +50,13 @@ int ...@@ -48,12 +50,13 @@ int
ext2_clear_xip_target(struct inode *inode, int block) ext2_clear_xip_target(struct inode *inode, int block)
{ {
sector_t sector = block * (PAGE_SIZE/512); sector_t sector = block * (PAGE_SIZE/512);
unsigned long data; void *kaddr;
unsigned long pfn;
int rc; int rc;
rc = __inode_direct_access(inode, sector, &data); rc = __inode_direct_access(inode, sector, &kaddr, &pfn);
if (!rc) if (!rc)
clear_page((void*)data); clear_page(kaddr);
return rc; return rc;
} }
...@@ -74,7 +77,8 @@ ext2_get_xip_page(struct address_space *mapping, sector_t offset, ...@@ -74,7 +77,8 @@ ext2_get_xip_page(struct address_space *mapping, sector_t offset,
int create) int create)
{ {
int rc; int rc;
unsigned long data; void *kaddr;
unsigned long pfn;
sector_t sector; sector_t sector;
/* first, retrieve the sector number */ /* first, retrieve the sector number */
...@@ -84,9 +88,9 @@ ext2_get_xip_page(struct address_space *mapping, sector_t offset, ...@@ -84,9 +88,9 @@ ext2_get_xip_page(struct address_space *mapping, sector_t offset,
/* retrieve address of the target data */ /* retrieve address of the target data */
rc = __inode_direct_access rc = __inode_direct_access
(mapping->host, sector * (PAGE_SIZE/512), &data); (mapping->host, sector * (PAGE_SIZE/512), &kaddr, &pfn);
if (!rc) if (!rc)
return virt_to_page(data); return pfn_to_page(pfn);
error: error:
return ERR_PTR(rc); return ERR_PTR(rc);
......
...@@ -1178,7 +1178,8 @@ struct block_device_operations { ...@@ -1178,7 +1178,8 @@ struct block_device_operations {
int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
long (*compat_ioctl) (struct file *, unsigned, unsigned long); long (*compat_ioctl) (struct file *, unsigned, unsigned long);
int (*direct_access) (struct block_device *, sector_t, unsigned long *); int (*direct_access) (struct block_device *, sector_t,
void **, unsigned long *);
int (*media_changed) (struct gendisk *); int (*media_changed) (struct gendisk *);
int (*revalidate_disk) (struct gendisk *); int (*revalidate_disk) (struct gendisk *);
int (*getgeo)(struct block_device *, struct hd_geometry *); int (*getgeo)(struct block_device *, struct hd_geometry *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment