linux side: replace vfs_read by kernel_read

vfs_read has been unexported in bd8df82be66 ("fs: unexport vfs_read and vfs_write")
in kernel 4.14.
kernel_read has always™ existed and is actually more appropriate: we can
remove the set_fs calls that are done in kernel_read.

The downside is that the function prototype also changed in 4.14 with
bdd1d2d3d251 ("fs: fix kernel_read prototype")...
(same with kernel_write e13ec939e96b ("fs: fix kernel_write prototype"))

Change-Id: I6f76a6387ae02b4d33bd62952d995a90b1952fc9
This commit is contained in:
Dominique Martinet
2018-08-17 10:14:54 +09:00
committed by Dominique Martinet
parent 61a942acdc
commit ea35954613
2 changed files with 23 additions and 28 deletions

View File

@ -1453,7 +1453,6 @@ static int pager_req_read(ihk_os_t os, uintptr_t handle, off_t off, size_t size,
uintptr_t phys = -1; uintptr_t phys = -1;
ihk_device_t dev = ihk_os_to_dev(os); ihk_device_t dev = ihk_os_to_dev(os);
void *buf = NULL; void *buf = NULL;
mm_segment_t fs;
loff_t pos; loff_t pos;
dprintk("pager_req_read(%lx,%lx,%lx,%lx)\n", handle, off, size, rpa); dprintk("pager_req_read(%lx,%lx,%lx,%lx)\n", handle, off, size, rpa);
@ -1490,8 +1489,6 @@ static int pager_req_read(ihk_os_t os, uintptr_t handle, off_t off, size_t size,
goto out; goto out;
} }
fs = get_fs();
set_fs(KERNEL_DS);
pos = off; pos = off;
n = 0; n = 0;
while (n < size) { while (n < size) {
@ -1500,7 +1497,12 @@ static int pager_req_read(ihk_os_t os, uintptr_t handle, off_t off, size_t size,
__func__, pos, off+n); __func__, pos, off+n);
pos = off + n; pos = off + n;
} }
ss = vfs_read(file, buf + n, size - n, &pos); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
ss = kernel_read(file, buf + n, size - n, &pos);
#else
ss = kernel_read(file, pos, buf + n, size - n);
pos += ss;
#endif
if (ss < 0) { if (ss < 0) {
break; break;
} }
@ -1511,7 +1513,6 @@ static int pager_req_read(ihk_os_t os, uintptr_t handle, off_t off, size_t size,
} }
n += ss; n += ss;
} }
set_fs(fs);
if (ss < 0) { if (ss < 0) {
pr_warn("%s(%lx,%lx,%lx,%lx):pread failed. %ld\n", pr_warn("%s(%lx,%lx,%lx,%lx):pread failed. %ld\n",
__func__, handle, off, size, rpa, ss); __func__, handle, off, size, rpa, ss);
@ -1541,7 +1542,6 @@ static int pager_req_write(ihk_os_t os, uintptr_t handle, off_t off, size_t size
uintptr_t phys = -1; uintptr_t phys = -1;
ihk_device_t dev = ihk_os_to_dev(os); ihk_device_t dev = ihk_os_to_dev(os);
void *buf = NULL; void *buf = NULL;
mm_segment_t fs;
loff_t pos; loff_t pos;
loff_t fsize; loff_t fsize;
size_t len; size_t len;
@ -1573,7 +1573,7 @@ static int pager_req_write(ihk_os_t os, uintptr_t handle, off_t off, size_t size
/* /*
* XXX: Find a way to avoid changing the file size * XXX: Find a way to avoid changing the file size
* by using a function in the same abstraction level as vfs_write(). * by using a function in the same abstraction level as kernel_write().
*/ */
fsize = i_size_read(file->f_mapping->host); fsize = i_size_read(file->f_mapping->host);
if (off >= fsize) { if (off >= fsize) {
@ -1590,15 +1590,16 @@ static int pager_req_write(ihk_os_t os, uintptr_t handle, off_t off, size_t size
goto out; goto out;
} }
fs = get_fs();
set_fs(KERNEL_DS);
pos = off; pos = off;
len = size; len = size;
if ((off + size) > fsize) { if ((off + size) > fsize) {
len = fsize - off; len = fsize - off;
} }
ss = vfs_write(file, buf, len, &pos); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
set_fs(fs); ss = kernel_write(file, buf, len, &pos);
#else
ss = kernel_write(file, buf, len, pos);
#endif
if (ss < 0) { if (ss < 0) {
printk("pager_req_write(%lx,%lx,%lx,%lx):pwrite failed. %ld\n", handle, off, size, rpa, ss); printk("pager_req_write(%lx,%lx,%lx,%lx):pwrite failed. %ld\n", handle, off, size, rpa, ss);
goto out; goto out;
@ -2150,7 +2151,6 @@ static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
#else /* POSTK_DEBUG_TEMP_FIX_61 */ #else /* POSTK_DEBUG_TEMP_FIX_61 */
int ret, i, tablesize, size, error = 0; int ret, i, tablesize, size, error = 0;
#endif /* POSTK_DEBUG_TEMP_FIX_61 */ #endif /* POSTK_DEBUG_TEMP_FIX_61 */
mm_segment_t oldfs = get_fs();
unsigned long phys, tablephys, rphys; unsigned long phys, tablephys, rphys;
ihk_device_t dev = ihk_os_to_dev(os); ihk_device_t dev = ihk_os_to_dev(os);
char *pt; char *pt;
@ -2163,8 +2163,6 @@ static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
goto fail; goto fail;
} }
set_fs(KERNEL_DS);
/* Every Linux documentation insists we should not /* Every Linux documentation insists we should not
* open a file in the kernel module, but our karma * open a file in the kernel module, but our karma
* leads us here. Precisely, Here we emulate the core * leads us here. Precisely, Here we emulate the core
@ -2210,15 +2208,13 @@ static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
#endif /*POSTK_DEBUG_TEMP_FIX_38*/ #endif /*POSTK_DEBUG_TEMP_FIX_38*/
dprintk("virtual %p\n", pt); dprintk("virtual %p\n", pt);
if (pt != NULL) { if (pt != NULL) {
#ifdef POSTK_DEBUG_ARCH_DEP_41 /* use writehandler version switch add */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,18,0) ret = kernel_write(file, pt, size,
ret = __kernel_write(file, pt, size, &file->f_pos); &file->f_pos);
#else #else
ret = file->f_op->write(file, pt, size, &file->f_pos); ret = kernel_write(file, pt, size, file->f_pos);
file->f_pos += ret;
#endif #endif
#else /* POSTK_DEBUG_ARCH_DEP_41 */
ret = file->f_op->write(file, pt, size, &file->f_pos);
#endif /* POSTK_DEBUG_ARCH_DEP_41 */
} else { } else {
dprintk("cannot map physical memory(%lx) to virtual memory.\n", dprintk("cannot map physical memory(%lx) to virtual memory.\n",
phys); phys);
@ -2261,7 +2257,6 @@ static int writecore(ihk_os_t os, unsigned long rcoretable, int chunks) {
ihk_device_unmap_memory(dev, tablephys, tablesize); ihk_device_unmap_memory(dev, tablephys, tablesize);
filp_close(file, NULL); filp_close(file, NULL);
fail: fail:
set_fs(oldfs);
if (error == -ENOSYS) { if (error == -ENOSYS) {
/* make sure we do not travel to user land */ /* make sure we do not travel to user land */
error = -EINVAL; error = -EINVAL;

View File

@ -798,7 +798,6 @@ static int read_file(void *buf, size_t size, char *fmt, va_list ap)
int n; int n;
struct file *fp = NULL; struct file *fp = NULL;
loff_t off; loff_t off;
mm_segment_t ofs;
ssize_t ss; ssize_t ss;
dprintk("read_file(%p,%ld,%s,%p)\n", buf, size, fmt, ap); dprintk("read_file(%p,%ld,%s,%p)\n", buf, size, fmt, ap);
@ -824,13 +823,14 @@ static int read_file(void *buf, size_t size, char *fmt, va_list ap)
} }
off = 0; off = 0;
ofs = get_fs(); #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
set_fs(KERNEL_DS); ss = kernel_read(fp, buf, size, &off);
ss = vfs_read(fp, buf, size, &off); #else
set_fs(ofs); ss = kernel_read(fp, off, buf, size);
#endif
if (ss < 0) { if (ss < 0) {
error = ss; error = ss;
eprintk("mcctrl:read_file:vfs_read failed. %d\n", error); eprintk("mcctrl:read_file:kernel_read failed. %d\n", error);
goto out; goto out;
} }
if (ss >= size) { if (ss >= size) {