* Read data to kernel buffer by blkdev_read_iter
@ 2019-03-22 13:06 Ivan Safonov
2019-03-22 13:42 ` Bart Van Assche
0 siblings, 1 reply; 5+ messages in thread
From: Ivan Safonov @ 2019-03-22 13:06 UTC (permalink / raw)
To: linux-block
Hi,
I want to read data by kernel module from a block device like this:
static int module_init(void)
{
const size_t len = 0x1000;
struct file *file;
char *buf;
struct iovec iovec;
struct kiocb kiocb;
struct iov_iter iov_iter;
ssize_t rcount;
buf = vmalloc(len);
file = filp_open("/dev/sda", 0, 0);
iovec.iov_base = buf;
iovec.iov_len = len;
kiocb.ki_filp = file;
kiocb.ki_pos = 0x200000000;
kiocb.ki_complete = NULL;
kiocb.ki_flags = IOCB_DIRECT;
kiocb.ki_hint = 0;
iov_iter_init(&iov_iter, READ, &iovec, 1, len);
rcount = blkdev_read_iter(&kiocb, &iov_iter);
filp_close(file, current);
vfree(buf);
return rcount < 0 ? rcount : 0;
}
but blkdev_read_iter always return -EFAULT. I tried to localize the error:
blkdev_read_iter
generic_file_read_iter
blkdev_direct_IO
__blkdev_direct_IO_simple
bio_iov_iter_get_pages
__bio_iov_iter_get_pages
iov_iter_get_pages
get_user_pages_fast
...
find_vma
find_vma return NULL for vmalloc'ed block.
Kernel version is 4.19.16.
Is this behavior valid for iov_iter with type ITER_KVEC?
--
Ivan Safonov.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Read data to kernel buffer by blkdev_read_iter
2019-03-22 13:06 Read data to kernel buffer by blkdev_read_iter Ivan Safonov
@ 2019-03-22 13:42 ` Bart Van Assche
2019-03-22 14:57 ` Ivan Safonov
0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2019-03-22 13:42 UTC (permalink / raw)
To: Ivan Safonov, linux-block
On 3/22/19 6:06 AM, Ivan Safonov wrote:
> Kernel version is 4.19.16.
>
> Is this behavior valid for iov_iter with type ITER_KVEC?
Are you familiar with the ITER_KVEC flag?
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Read data to kernel buffer by blkdev_read_iter
2019-03-22 13:42 ` Bart Van Assche
@ 2019-03-22 14:57 ` Ivan Safonov
2019-03-22 15:36 ` Bart Van Assche
0 siblings, 1 reply; 5+ messages in thread
From: Ivan Safonov @ 2019-03-22 14:57 UTC (permalink / raw)
To: Bart Van Assche, linux-block
On 3/22/19 4:42 PM, Bart Van Assche wrote:
> On 3/22/19 6:06 AM, Ivan Safonov wrote:
>> Kernel version is 4.19.16.
>>
>> Is this behavior valid for iov_iter with type ITER_KVEC?
>
> Are you familiar with the ITER_KVEC flag?
No, I did not find a clear description of this flag.
In the previous message I misled you: iov_iter has ITER_KVEC type only
if set_fs(get_ds()) present before iov_iter_init(). In this case
_without_ IOCB_DIRECT blkdev_read_iter() work fine. With IOCB_DIRECT
blkdev_read_iter() return -EFAULT.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Read data to kernel buffer by blkdev_read_iter
2019-03-22 14:57 ` Ivan Safonov
@ 2019-03-22 15:36 ` Bart Van Assche
2019-03-22 16:24 ` Ivan Safonov
0 siblings, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2019-03-22 15:36 UTC (permalink / raw)
To: Ivan Safonov, linux-block
On Fri, 2019-03-22 at 17:57 +0300, Ivan Safonov wrote:
> In the previous message I misled you: iov_iter has ITER_KVEC type only
> if set_fs(get_ds()) present before iov_iter_init(). In this case
> _without_ IOCB_DIRECT blkdev_read_iter() work fine. With IOCB_DIRECT
> blkdev_read_iter() return -EFAULT.
Have you tried to store a physical address in iov_base instead of a virtual
address?
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Read data to kernel buffer by blkdev_read_iter
2019-03-22 15:36 ` Bart Van Assche
@ 2019-03-22 16:24 ` Ivan Safonov
0 siblings, 0 replies; 5+ messages in thread
From: Ivan Safonov @ 2019-03-22 16:24 UTC (permalink / raw)
To: Bart Van Assche, linux-block
On 3/22/19 6:36 PM, Bart Van Assche wrote:
> On Fri, 2019-03-22 at 17:57 +0300, Ivan Safonov wrote:
>> In the previous message I misled you: iov_iter has ITER_KVEC type only
>> if set_fs(get_ds()) present before iov_iter_init(). In this case
>> _without_ IOCB_DIRECT blkdev_read_iter() work fine. With IOCB_DIRECT
>> blkdev_read_iter() return -EFAULT.
>
> Have you tried to store a physical address in iov_base instead of a virtual
> address?
I tried: already -EFAULT.
vm_area_struct description says: ranges consist of virtual addresses:
/*
* This struct defines a memory VMM memory area. There is one of these
* per VM-area/task. A VM area is any part of the process virtual memory
* space that has a special rule for the page-fault handlers (ie a shared
* library, the executable area etc).
*/
So, the physical addresses could not solve this problem.
I think there should be no memory checks for the kernel allocated
memory, or the blkdev_read_iter() is not available to work with
vmalloc'ed memory at all.
--
Ivan Safonov.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-22 16:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22 13:06 Read data to kernel buffer by blkdev_read_iter Ivan Safonov
2019-03-22 13:42 ` Bart Van Assche
2019-03-22 14:57 ` Ivan Safonov
2019-03-22 15:36 ` Bart Van Assche
2019-03-22 16:24 ` Ivan Safonov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).