linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* 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

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).