* [PATCH] ublk: add DMA alignment limit
@ 2025-02-27 10:37 Ming Lei
2025-02-27 14:58 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2025-02-27 10:37 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei, Keith Busch
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>
---
It is helpful to provide segment limit for avoiding extra
IO split, but that shouldn't a must for zero copy.
drivers/block/ublk_drv.c | 16 +++++++++++++++-
include/uapi/linux/ublk_cmd.h | 7 +++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 4f291b55c876..c505b14989cf 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -73,7 +73,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;
@@ -571,6 +572,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;
}
@@ -2348,6 +2359,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;
diff --git a/include/uapi/linux/ublk_cmd.h b/include/uapi/linux/ublk_cmd.h
index 74246c926b55..7255b36b5cf6 100644
--- a/include/uapi/linux/ublk_cmd.h
+++ b/include/uapi/linux/ublk_cmd.h
@@ -405,6 +405,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
@@ -417,12 +422,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
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ublk: add DMA alignment limit
2025-02-27 10:37 [PATCH] ublk: add DMA alignment limit Ming Lei
@ 2025-02-27 14:58 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-02-27 14:58 UTC (permalink / raw)
To: linux-block, Ming Lei; +Cc: Keith Busch
On Thu, 27 Feb 2025 18:37:07 +0800, Ming Lei wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] ublk: add DMA alignment limit
commit: 9fcc4add3c0d6e43788d55bf7a957c1d4de8584a
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-27 14:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 10:37 [PATCH] ublk: add DMA alignment limit Ming Lei
2025-02-27 14:58 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox