From: Zongyu Wu <wuzongyu1@huawei.com> Add error warning when CRC errors occur;When using the same ctx, the context data of the previous service flow that has ended needs to be cleared;An error message is added to report related information to zip module;The minimum output length of the lz77_zstd_price algorithm should be 4096+16+800+insize. Signed-off-by: Zongyu Wu <wuzongyu1@huawei.com> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> --- drv/hisi_comp.c | 20 ++++++++++++-------- v1/drv/hisi_zip_udrv.c | 5 +++++ v1/wd_comp.c | 6 +++++- wd_util.c | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/drv/hisi_comp.c b/drv/hisi_comp.c index cad21fa..36f3e3e 100644 --- a/drv/hisi_comp.c +++ b/drv/hisi_comp.c @@ -859,9 +859,11 @@ static int lz77_zstd_buf_check(struct wd_comp_msg *msg) } if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 && - seq_avail_out <= PRICE_MIN_OUT_SIZE)) { + seq_avail_out <= PRICE_MIN_OUT_SIZE + ZSTD_FREQ_DATA_SIZE + + ZSTD_LIT_RESV_SIZE)) { WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n", - out_size, PRICE_MIN_OUT_SIZE + lits_size); + out_size, PRICE_MIN_OUT_SIZE + ZSTD_FREQ_DATA_SIZE + + ZSTD_LIT_RESV_SIZE + lits_size); return -WD_EINVAL; } @@ -885,8 +887,8 @@ static int lz77_only_buf_check(struct wd_comp_msg *msg) __u32 lits_size = in_size + ZSTD_LIT_RESV_SIZE; __u32 seq_avail_out = out_size - lits_size; - /* lits_size need to be less than 8M when use pbuffer */ - if (unlikely(lits_size > HZ_MAX_SIZE)) { + /* in_size need to be less than 8M minus the literal calculation reserved space */ + if (unlikely(in_size > HZ_MAX_SIZE - ZSTD_LIT_RESV_SIZE)) { WD_ERR("invalid: in_len(%u) of lz77_only is out of range!\n", in_size); return -WD_EINVAL; } @@ -1030,9 +1032,11 @@ static int lz77_zstd_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size) } if (unlikely(msg->stream_mode == WD_COMP_STATEFUL && msg->comp_lv == WD_COMP_L9 && - seq_avail_out <= PRICE_MIN_OUT_SIZE)) { + seq_avail_out <= PRICE_MIN_OUT_SIZE + ZSTD_FREQ_DATA_SIZE + + ZSTD_LIT_RESV_SIZE)) { WD_ERR("invalid: out_len(%u) not enough, %u bytes are minimum in price mode!\n", - out_size, PRICE_MIN_OUT_SIZE + lits_size); + out_size, PRICE_MIN_OUT_SIZE + ZSTD_FREQ_DATA_SIZE + + ZSTD_LIT_RESV_SIZE + lits_size); return -WD_EINVAL; } @@ -1050,7 +1054,7 @@ static int lz77_only_buf_check_sgl(struct wd_comp_msg *msg, __u32 lits_size) * the dfx information. The literals and sequences data need to be written * to an independent sgl splited from list_dst. */ - if (unlikely(lits_size < in_size + ZSTD_LIT_RESV_SIZE)) { + if (unlikely(lits_size < (__u64)in_size + ZSTD_LIT_RESV_SIZE)) { WD_ERR("invalid: output is not enough for literals, at least %u bytes!\n", ZSTD_LIT_RESV_SIZE + lits_size); return -WD_EINVAL; @@ -1652,7 +1656,7 @@ static int parse_zip_sqe(struct hisi_qp *qp, struct hisi_zip_sqe *sqe, recv_msg->req.status = 0; if (unlikely(status != 0 && status != HZ_NEGACOMPRESS && - status != HZ_CRC_ERR && status != HZ_DECOMP_END)) { + status != HZ_DECOMP_END)) { if (status == ERR_DSTLEN_OUT) WD_DEBUG("bad request(ctx_st=0x%x, status=0x%x, algorithm type=%u)!\n", ctx_st, status, type); diff --git a/v1/drv/hisi_zip_udrv.c b/v1/drv/hisi_zip_udrv.c index 44e1545..903df1c 100644 --- a/v1/drv/hisi_zip_udrv.c +++ b/v1/drv/hisi_zip_udrv.c @@ -494,6 +494,11 @@ static int fill_zip_buffer_size_deflate(void *ssqe, struct wcrypto_comp_msg *msg return -WD_EINVAL; } + if (unlikely(!msg->avail_out)) { + WD_ERR("The avai_out is error (%u)!\n", msg->avail_out); + return -WD_EINVAL; + } + if (unlikely(msg->data_fmt != WD_SGL_BUF && msg->avail_out > MAX_BUFFER_SIZE)) { WD_ERR("warning: avail_out is out of range (%u), will set 8MB size max!\n", diff --git a/v1/wd_comp.c b/v1/wd_comp.c index 169f1b4..bcdab09 100644 --- a/v1/wd_comp.c +++ b/v1/wd_comp.c @@ -54,6 +54,10 @@ static void fill_comp_msg(struct wcrypto_comp_ctx *ctx, msg->checksum = opdata->checksum; msg->tag = ctx->ctx_id; msg->status = 0; + + if (msg->stream_mode == WCRYPTO_COMP_STATEFUL && + opdata->stream_pos == WCRYPTO_COMP_STREAM_NEW && ctx->ctx_buf) + memset(ctx->ctx_buf, 0, MAX_CTX_RSV_SIZE); } static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *setup) @@ -94,7 +98,7 @@ static int ctx_params_check(struct wd_queue *q, struct wcrypto_comp_ctx_setup *s return -WD_EINVAL; } - if (setup->stream_mode > WCRYPTO_FINISH) { + if (setup->stream_mode > WCRYPTO_COMP_STATEFUL) { WD_ERR("err: stream_mode is invalid!\n"); return -WD_EINVAL; } diff --git a/wd_util.c b/wd_util.c index 67a46a6..375984f 100644 --- a/wd_util.c +++ b/wd_util.c @@ -2373,7 +2373,7 @@ static void create_lib_to_list(const char *lib_path, struct drv_lib_list **head) static struct drv_lib_list *load_libraries_from_config(const char *config_path, const char *lib_dir_path) { - char *path_buf, *lib_path, *line; + char *lib_path, *line; struct drv_lib_list *head = NULL; FILE *config_file; int ret; -- 2.33.0