@@ -79,8 +79,7 @@ int ublk_bpf_attach(struct ublk_device *ub)
if (!ublk_dev_support_bpf(ub))
return 0;
- /* todo: ublk device need to provide struct_ops prog id */
- ub->prog.prog_id = 0;
+ ub->prog.prog_id = ub->params.bpf.ops_id;
ub->prog.ops = &ublk_prog_consumer_ops;
return ublk_bpf_prog_attach(&ub->prog);
@@ -416,6 +416,19 @@ 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_BPF) {
+ const struct ublk_param_bpf *p = &ub->params.bpf;
+
+ if (!ublk_dev_support_bpf(ub))
+ return -EINVAL;
+
+ if (!(p->flags & UBLK_BPF_HAS_OPS_ID))
+ return -EINVAL;
+ } else {
+ if (ublk_dev_support_bpf(ub))
+ return -EINVAL;
+ }
+
return 0;
}
@@ -434,7 +447,7 @@ static inline bool ublk_support_user_copy(const struct ublk_queue *ubq)
static inline bool ublk_need_map_io(const struct ublk_queue *ubq)
{
- return !ublk_support_user_copy(ubq);
+ return !(ublk_support_user_copy(ubq) || ublk_support_bpf(ubq));
}
static inline bool ublk_need_req_ref(const struct ublk_queue *ubq)
@@ -24,7 +24,8 @@
| UBLK_F_CMD_IOCTL_ENCODE \
| UBLK_F_USER_COPY \
| UBLK_F_ZONED \
- | UBLK_F_USER_RECOVERY_FAIL_IO)
+ | UBLK_F_USER_RECOVERY_FAIL_IO \
+ | UBLK_F_BPF)
#define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
| UBLK_F_USER_RECOVERY_REISSUE \
@@ -33,7 +34,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_BPF)
enum {
UBLK_BPF_IO_PREP = 0,
@@ -193,12 +195,12 @@ static inline struct ublksrv_io_desc *ublk_get_iod(struct ublk_queue *ubq,
static inline bool ublk_support_bpf(const struct ublk_queue *ubq)
{
- return false;
+ return ubq->flags & UBLK_F_BPF;
}
static inline bool ublk_dev_support_bpf(const struct ublk_device *ub)
{
- return false;
+ return ub->dev_info.flags & UBLK_F_BPF;
}
struct ublk_device *ublk_get_device(struct ublk_device *ub);
@@ -207,6 +207,9 @@
*/
#define UBLK_F_USER_RECOVERY_FAIL_IO (1ULL << 9)
+/* ublk IO is handled by bpf prog */
+#define UBLK_F_BPF (1ULL << 10)
+
/* device state */
#define UBLK_S_DEV_DEAD 0
#define UBLK_S_DEV_LIVE 1
@@ -401,6 +404,13 @@ struct ublk_param_zoned {
__u8 reserved[20];
};
+struct ublk_param_bpf {
+#define UBLK_BPF_HAS_OPS_ID (1 << 0)
+ __u8 flags;
+ __u8 ops_id;
+ __u8 reserved[6];
+};
+
struct ublk_params {
/*
* Total length of parameters, userspace has to set 'len' for both
@@ -413,12 +423,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_BPF (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_zoned zoned;
+ struct ublk_param_bpf bpf;
};
#endif
Add feature flag of UBLK_F_BPF, meantime pass bpf struct_ops prog id via ublk parameter from userspace. ublk-bpf needs to copy data between ublk request pages and userspace buffer any more, so let ublk_need_map_io() return false for UBLK_F_BPF too. Signed-off-by: Ming Lei <tom.leiming@gmail.com> --- drivers/block/ublk/bpf.c | 3 +-- drivers/block/ublk/main.c | 15 ++++++++++++++- drivers/block/ublk/ublk.h | 10 ++++++---- include/uapi/linux/ublk_cmd.h | 14 +++++++++++++- 4 files changed, 34 insertions(+), 8 deletions(-)