@@ -205,11 +205,6 @@ static inline struct request *__ublk_check_and_get_req(struct ublk_device *ub,
205205static inline unsigned int ublk_req_build_flags (struct request * req );
206206static inline struct ublksrv_io_desc * ublk_get_iod (struct ublk_queue * ubq ,
207207 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-
213208static inline bool ublk_dev_is_zoned (const struct ublk_device * ub )
214209{
215210 return ub -> dev_info .flags & UBLK_F_ZONED ;
@@ -609,23 +604,31 @@ static void ublk_apply_params(struct ublk_device *ub)
609604 ublk_dev_param_zoned_apply (ub );
610605}
611606
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+
612612static inline bool ublk_support_user_copy (const struct ublk_queue * ubq )
613613{
614- return ubq -> flags & ( UBLK_F_USER_COPY | UBLK_F_SUPPORT_ZERO_COPY ) ;
614+ return ubq -> flags & UBLK_F_USER_COPY ;
615615}
616616
617617static inline bool ublk_need_map_io (const struct ublk_queue * ubq )
618618{
619- return !ublk_support_user_copy (ubq );
619+ return !ublk_support_user_copy (ubq ) && ! ublk_support_zero_copy ( ubq ) ;
620620}
621621
622622static inline bool ublk_need_req_ref (const struct ublk_queue * ubq )
623623{
624624 /*
625625 * read()/write() is involved in user copy, so request reference
626626 * 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
627630 */
628- return ublk_support_user_copy (ubq );
631+ return ublk_support_user_copy (ubq ) || ublk_support_zero_copy ( ubq ) ;
629632}
630633
631634static 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,
22452248 if (!ubq )
22462249 return ERR_PTR (- EINVAL );
22472250
2251+ if (!ublk_support_user_copy (ubq ))
2252+ return ERR_PTR (- EACCES );
2253+
22482254 if (tag >= ubq -> q_depth )
22492255 return ERR_PTR (- EINVAL );
22502256
@@ -2783,13 +2789,18 @@ static int ublk_ctrl_add_dev(const struct ublksrv_ctrl_cmd *header)
27832789 ub -> dev_info .flags |= UBLK_F_CMD_IOCTL_ENCODE |
27842790 UBLK_F_URING_CMD_COMP_IN_TASK ;
27852791
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 ))
27882794 ub -> dev_info .flags &= ~UBLK_F_NEED_GET_DATA ;
27892795
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+ */
27912801 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 )))) {
27932804 ret = - EINVAL ;
27942805 goto out_free_dev_number ;
27952806 }
0 commit comments