From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@meta.com>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
io-uring@vger.kernel.org, axboe@kernel.dk, hch@lst.de,
joshi.k@samsung.com, martin.petersen@oracle.com,
Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH 1/4] block: bio-integrity: add support for user buffers
Date: Thu, 19 Oct 2023 07:39:05 +0200 [thread overview]
Message-ID: <20231019053905.GC14346@lst.de> (raw)
In-Reply-To: <20231018151843.3542335-2-kbusch@meta.com>
int bio_integrity_map_user(struct bio *bio, void __user *ubuf, unsigned int len,
> + u32 seed, u32 maxvecs)
> +{
> + struct request_queue *q = bdev_get_queue(bio->bi_bdev);
> + unsigned long align = q->dma_pad_mask | queue_dma_alignment(q);
> + struct page *stack_pages[UIO_FASTIOV];
> + size_t offset = offset_in_page(ubuf);
> + unsigned long ptr = (uintptr_t)ubuf;
> + struct page **pages = stack_pages;
> + struct bio_integrity_payload *bip;
> + int npages, ret, i;
> +
> + if (bio_integrity(bio) || ptr & align || maxvecs > UIO_FASTIOV)
> + return -EINVAL;
We also need to check the length for the dma alignment/pad, not
just the start. (The undocumented iov_iter_alignment_iovec helper
obsfucateѕ this for the data path).
> + bip = bio_integrity_alloc(bio, GFP_KERNEL, maxvecs);
> + if (IS_ERR(bip))
> + return PTR_ERR(bip);
> +
> + ret = pin_user_pages_fast(ptr, UIO_FASTIOV, FOLL_WRITE, pages);
> + if (unlikely(ret < 0))
> + goto free_bip;
> +
> + npages = ret;
> + for (i = 0; i < npages; i++) {
> + u32 bytes = min_t(u32, len, PAGE_SIZE - offset);
> + ret = bio_integrity_add_page(bio, pages[i], bytes, offset);
> + if (ret != bytes) {
> + ret = -EINVAL;
> + goto release_pages;
> + }
> + len -= ret;
> + offset = 0;
> + }
Any reason to not use the bio_vec array as the buffer, similar to the
data size here?
> +EXPORT_SYMBOL(bio_integrity_map_user);
Everything that just thinly wraps get_user_pages_fast needs to be
EXPORT_SYMBOL_GPL.
next prev parent reply other threads:[~2023-10-19 5:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 15:18 [PATCH 0/4] block integrity: direclty map user space addresses Keith Busch
2023-10-18 15:18 ` [PATCH 1/4] block: bio-integrity: add support for user buffers Keith Busch
2023-10-19 5:39 ` Christoph Hellwig [this message]
2023-10-21 3:53 ` kernel test robot
2023-10-21 4:13 ` kernel test robot
2023-10-25 12:51 ` Kanchan Joshi
2023-10-25 14:42 ` Keith Busch
2023-10-18 15:18 ` [PATCH 2/4] nvme: use bio_integrity_map_user Keith Busch
2023-10-19 5:40 ` Christoph Hellwig
2023-10-25 13:26 ` Kanchan Joshi
2023-10-18 15:18 ` [PATCH 3/4] iouring: remove IORING_URING_CMD_POLLED Keith Busch
2023-10-19 5:41 ` Christoph Hellwig
2023-10-19 14:43 ` Keith Busch
2023-10-23 6:18 ` Kanchan Joshi
2023-10-18 15:18 ` [PATCH 4/4] io_uring: remove uring_cmd cookie Keith Busch
2023-10-19 5:34 ` [PATCH 0/4] block integrity: direclty map user space addresses Christoph Hellwig
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=20231019053905.GC14346@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=joshi.k@samsung.com \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=martin.petersen@oracle.com \
/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.