mirror of
https://github.com/torvalds/linux.git
synced 2026-03-14 02:06:15 +01:00
ublk: add DMA alignment limit
The in-tree ublk driver doesn't need DMA alignment limit because there is one data copy between request pages and the userspace buffer. However, ublk is going to support zero copy, then DMA alignment limit is required, because same IO buffer is forwarded to backend which may have specific buffer DMA alignment limit, so the limit has to be exposed from the frontend driver to client application. Cc: Keith Busch <kbusch@kernel.org> Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250227103707.2640014-1-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
105ca2a2c2
commit
e84025d2a9
2 changed files with 22 additions and 1 deletions
|
|
@ -70,7 +70,8 @@
|
|||
/* All UBLK_PARAM_TYPE_* should be included here */
|
||||
#define UBLK_PARAM_TYPE_ALL \
|
||||
(UBLK_PARAM_TYPE_BASIC | UBLK_PARAM_TYPE_DISCARD | \
|
||||
UBLK_PARAM_TYPE_DEVT | UBLK_PARAM_TYPE_ZONED)
|
||||
UBLK_PARAM_TYPE_DEVT | UBLK_PARAM_TYPE_ZONED | \
|
||||
UBLK_PARAM_TYPE_DMA_ALIGN)
|
||||
|
||||
struct ublk_rq_data {
|
||||
struct llist_node node;
|
||||
|
|
@ -568,6 +569,16 @@ static int ublk_validate_params(const struct ublk_device *ub)
|
|||
else if (ublk_dev_is_zoned(ub))
|
||||
return -EINVAL;
|
||||
|
||||
if (ub->params.types & UBLK_PARAM_TYPE_DMA_ALIGN) {
|
||||
const struct ublk_param_dma_align *p = &ub->params.dma;
|
||||
|
||||
if (p->alignment >= PAGE_SIZE)
|
||||
return -EINVAL;
|
||||
|
||||
if (!is_power_of_2(p->alignment + 1))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -2300,6 +2311,9 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub, struct io_uring_cmd *cmd)
|
|||
if (ub->params.basic.attrs & UBLK_ATTR_ROTATIONAL)
|
||||
lim.features |= BLK_FEAT_ROTATIONAL;
|
||||
|
||||
if (ub->params.types & UBLK_PARAM_TYPE_DMA_ALIGN)
|
||||
lim.dma_alignment = ub->params.dma.alignment;
|
||||
|
||||
if (wait_for_completion_interruptible(&ub->completion) != 0)
|
||||
return -EINTR;
|
||||
|
||||
|
|
|
|||
|
|
@ -401,6 +401,11 @@ struct ublk_param_zoned {
|
|||
__u8 reserved[20];
|
||||
};
|
||||
|
||||
struct ublk_param_dma_align {
|
||||
__u32 alignment;
|
||||
__u8 pad[4];
|
||||
};
|
||||
|
||||
struct ublk_params {
|
||||
/*
|
||||
* Total length of parameters, userspace has to set 'len' for both
|
||||
|
|
@ -413,12 +418,14 @@ struct ublk_params {
|
|||
#define UBLK_PARAM_TYPE_DISCARD (1 << 1)
|
||||
#define UBLK_PARAM_TYPE_DEVT (1 << 2)
|
||||
#define UBLK_PARAM_TYPE_ZONED (1 << 3)
|
||||
#define UBLK_PARAM_TYPE_DMA_ALIGN (1 << 4)
|
||||
__u32 types; /* types of parameter included */
|
||||
|
||||
struct ublk_param_basic basic;
|
||||
struct ublk_param_discard discard;
|
||||
struct ublk_param_devt devt;
|
||||
struct ublk_param_zoned zoned;
|
||||
struct ublk_param_dma_align dma;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue