All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Safonov <insafonov@gmail.com>
To: linux-block@vger.kernel.org
Subject: Read data to kernel buffer by blkdev_read_iter
Date: Fri, 22 Mar 2019 16:06:04 +0300	[thread overview]
Message-ID: <b6d54ac9-ee29-edcf-907d-1e12fce321ac@gmail.com> (raw)

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.

             reply	other threads:[~2019-03-22 13:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 13:06 Ivan Safonov [this message]
2019-03-22 13:42 ` Read data to kernel buffer by blkdev_read_iter 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b6d54ac9-ee29-edcf-907d-1e12fce321ac@gmail.com \
    --to=insafonov@gmail.com \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.