]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
target/file: Fix 32-bit highmem breakage for SGL -> iovec mapping
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Wed, 5 Dec 2012 11:08:29 +0000 (12:08 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 3 Jan 2013 03:33:29 +0000 (03:33 +0000)
commit 40ff2c3b3da35dd3a00ac6722056a59b4b3f2caf upstream.

This patch changes vectored file I/O to use kmap + kunmap when mapping
incoming SGL memory -> struct iovec in order to properly support 32-bit
highmem configurations.  This is because an extra bounce buffer may be
required when processing scatterlist pages allocated with GFP_KERNEL.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
[bwh: Backported to 3.2: use task->task_sg{,_nents} for iteration]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/target/target_core_file.c

index cafa477a260121116593db5303e6b4269fa314a9..ea29eaf23789d9d20cb8846026b916c8b1ae9456 100644 (file)
@@ -300,7 +300,7 @@ static int fd_do_readv(struct se_task *task)
 
        for_each_sg(task->task_sg, sg, task->task_sg_nents, i) {
                iov[i].iov_len = sg->length;
-               iov[i].iov_base = sg_virt(sg);
+               iov[i].iov_base = kmap(sg_page(sg)) + sg->offset;
        }
 
        old_fs = get_fs();
@@ -308,6 +308,8 @@ static int fd_do_readv(struct se_task *task)
        ret = vfs_readv(fd, &iov[0], task->task_sg_nents, &pos);
        set_fs(old_fs);
 
+       for_each_sg(task->task_sg, sg, task->task_sg_nents, i)
+               kunmap(sg_page(sg));
        kfree(iov);
        /*
         * Return zeros and GOOD status even if the READ did not return
@@ -353,7 +355,7 @@ static int fd_do_writev(struct se_task *task)
 
        for_each_sg(task->task_sg, sg, task->task_sg_nents, i) {
                iov[i].iov_len = sg->length;
-               iov[i].iov_base = sg_virt(sg);
+               iov[i].iov_base = kmap(sg_page(sg)) + sg->offset;
        }
 
        old_fs = get_fs();
@@ -361,6 +363,9 @@ static int fd_do_writev(struct se_task *task)
        ret = vfs_writev(fd, &iov[0], task->task_sg_nents, &pos);
        set_fs(old_fs);
 
+       for_each_sg(task->task_sg, sg, task->task_sg_nents, i)
+               kunmap(sg_page(sg));
+
        kfree(iov);
 
        if (ret < 0 || ret != task->task_size) {