@@ -205,11 +205,6 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
205
205
static inline unsigned int ublk_req_build_flags (struct request * req );
206
206
static inline struct ublksrv_io_desc * ublk_get_iod (struct ublk_queue * ubq ,
207
207
int tag );
208
- static inline bool ublk_dev_is_user_copy (const struct ublk_device * ub )
209
- {
210
- return ub -> dev_info .flags & (UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY );
211
- }
212
-
213
208
static inline bool ublk_dev_is_zoned (const struct ublk_device * ub )
214
209
{
215
210
return ub -> dev_info .flags & UBLK_F_ZONED ;
@@ -609,23 +604,31 @@ static void ublk_apply_params(struct ublk_device *ub)
609
604
ublk_dev_param_zoned_apply (ub );
610
605
}
611
606
607
+ static inline bool ublk_support_zero_copy (const struct ublk_queue * ubq )
608
+ {
609
+ return ubq -> flags & UBLK_F_SUPPORT_ZERO_COPY ;
610
+ }
611
+
612
612
static inline bool ublk_support_user_copy (const struct ublk_queue * ubq )
613
613
{
614
- return ubq -> flags & ( UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY ) ;
614
+ return ubq -> flags & UBLK_F_USER_COPY ;
615
615
}
616
616
617
617
static inline bool ublk_need_map_io (const struct ublk_queue * ubq )
618
618
{
619
- return !ublk_support_user_copy (ubq );
619
+ return !ublk_support_user_copy (ubq ) && ! ublk_support_zero_copy ( ubq ) ;
620
620
}
621
621
622
622
static inline bool ublk_need_req_ref (const struct ublk_queue * ubq )
623
623
{
624
624
/*
625
625
* read()/write() is involved in user copy, so request reference
626
626
* has to be grabbed
627
+ *
628
+ * for zero copy, request buffer need to be registered to io_uring
629
+ * buffer table, so reference is needed
627
630
*/
628
- return ublk_support_user_copy (ubq );
631
+ return ublk_support_user_copy (ubq ) || ublk_support_zero_copy ( ubq ) ;
629
632
}
630
633
631
634
static inline void ublk_init_req_ref (const struct ublk_queue * ubq ,
@@ -2245,6 +2248,9 @@ static struct request *ublk_check_and_get_req(struct kiocb *iocb,
2245
2248
if (!ubq )
2246
2249
return ERR_PTR (- EINVAL );
2247
2250
2251
+ if (!ublk_support_user_copy (ubq ))
2252
+ return ERR_PTR (- EACCES );
2253
+
2248
2254
if (tag >= ubq -> q_depth )
2249
2255
return ERR_PTR (- EINVAL );
2250
2256
@@ -2783,13 +2789,18 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
2783
2789
ub -> dev_info .flags |= UBLK_F_CMD_IOCTL_ENCODE |
2784
2790
UBLK_F_URING_CMD_COMP_IN_TASK ;
2785
2791
2786
- /* GET_DATA isn't needed any more with USER_COPY */
2787
- if (ublk_dev_is_user_copy ( ub ))
2792
+ /* GET_DATA isn't needed any more with USER_COPY or ZERO COPY */
2793
+ if (ub -> dev_info . flags & ( UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY ))
2788
2794
ub -> dev_info .flags &= ~UBLK_F_NEED_GET_DATA ;
2789
2795
2790
- /* Zoned storage support requires user copy feature */
2796
+ /*
2797
+ * Zoned storage support requires reuse `ublksrv_io_cmd->addr` for
2798
+ * returning write_append_lba, which is only allowed in case of
2799
+ * user copy or zero copy
2800
+ */
2791
2801
if (ublk_dev_is_zoned (ub ) &&
2792
- (!IS_ENABLED (CONFIG_BLK_DEV_ZONED ) || !ublk_dev_is_user_copy (ub ))) {
2802
+ (!IS_ENABLED (CONFIG_BLK_DEV_ZONED ) || !(ub -> dev_info .flags &
2803
+ (UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY )))) {
2793
2804
ret = - EINVAL ;
2794
2805
goto out_free_dev_number ;
2795
2806
}
0 commit comments