Read data to kernel buffer by blkdev_read_iter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux