crypto: acomp - Add virtual address and folio support
Subsystems (11)
Herbert Xu
maintainerv5 cover crypto: acomp - Add virtual address and folio support
v5 removes the incompressible warnings in ubifs, removes more dead code from qat, and replaces crypto_has_comp with crypto_has_acomp in hibernate and ipcomp.
This patch series adds virtual address and folio support to acomp. This finally brings it to feature parity with the legacy crypto_comp, which enables us to convert the existing users to acomp.
The three users are converted according to their characteristics:
ubifs uses folio+linear, hibernate uses linear only while ipcomp uses SG only.
Only ipcomp is fully asynchronous, ubifs supports asynchronous but will wait on it and hibernate is synchronous only.
Herbert Xu (14):
xfrm: ipcomp: Call pskb_may_pull in ipcomp_input
crypto: scomp - Remove support for some non-trivial SG lists
crypto: iaa - Remove dst_null support
crypto: qat - Remove dst_null support
crypto: acomp - Remove dst_free
crypto: scomp - Add chaining and virtual address support
crypto: acomp - Add ACOMP_REQUEST_ALLOC and acomp_request_alloc_extra
crypto: iaa - Use acomp stack fallback
crypto: acomp - Add async nondma fallback
crypto: acomp - Add support for folios
xfrm: ipcomp: Use crypto_acomp interface
PM: hibernate: Use crypto_acomp interface
ubifs: Use crypto_acomp interface
ubifs: Pass folios to acomp
crypto/acompress.c | 148 ++++-- crypto/scompress.c | 189 ++++--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 164 +----- drivers/crypto/intel/qat/qat_common/qat_bl.c | 159 ------ drivers/crypto/intel/qat/qat_common/qat_bl.h | 6 - .../intel/qat/qat_common/qat_comp_algs.c | 85 +--- .../intel/qat/qat_common/qat_comp_req.h | 10 - fs/ubifs/compress.c | 208 ++++++-- fs/ubifs/file.c | 74 +-- fs/ubifs/journal.c | 11 +- fs/ubifs/ubifs.h | 26 +- include/crypto/acompress.h | 184 ++++++- include/crypto/internal/acompress.h | 26 +- include/crypto/internal/scompress.h | 2 - include/linux/crypto.h | 1 + include/net/ipcomp.h | 13 +- kernel/power/hibernate.c | 5 +- kernel/power/swap.c | 58 ++- net/xfrm/xfrm_algo.c | 7 +- net/xfrm/xfrm_ipcomp.c | 478 +++++++++--------- 20 files changed, 932 insertions(+), 922 deletions(-)
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 1/14 xfrm: ipcomp: Call pskb_may_pull in ipcomp_input
If a malformed packet is received there may not be enough data to pull. This isn't a problem in practice because the caller has already done xfrm_parse_spi which in effect does the same thing.
--- net/xfrm/xfrm_ipcomp.c | 3 +++ 1 file changed, 3 insertions(+)
net/xfrm/xfrm_ipcomp.c +3 -0
@@ -97,6 +97,9 @@ int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)int err = -ENOMEM ;struct ip_comp_hdr *ipch; +if (!pskb_may_pull (skb,sizeof (*ipch))) +return -EINVAL ; +if (skb_linearize_cow (skb)) goto out;
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 2/14 crypto: scomp - Remove support for some non-trivial SG lists
In reply to Herbert XuAs the only user of acomp/scomp uses a trivial single-page SG list, remove support for everything else in preprataion for the addition of virtual address support.
However, keep support for non-trivial source SG lists as that user is currently jumping through hoops in order to linearise the source data.
Limit the source SG linearisation buffer to a single page as that user never goes over that. The only other potential user is also unlikely to exceed that (IPComp) and it can easily do its own linearisation if necessary.
Also keep the destination SG linearisation for IPComp.
--- crypto/acompress.c | 1 - crypto/scompress.c | 127 ++++++++++++++++------------ include/crypto/acompress.h | 17 +--- include/crypto/internal/scompress.h | 2 - 4 files changed, 76 insertions(+), 71 deletions(-)
crypto/acompress.c +0 -1
@@ -73,7 +73,6 @@ static int crypto_acomp_init_tfm(struct crypto_tfm *tfm) acomp->compress = alg->compress; acomp->decompress = alg->decompress; - acomp->dst_free = alg->dst_free; acomp->reqsize = alg->reqsize;if (alg->exit)
crypto/scompress.c +73 -54
194 lines not on this page · raw message
include/crypto/acompress.h +3 -14
@@ -18,8 +18,6 @@#include <linux/spinlock_types.h> #include <linux/types.h> -#define CRYPTO_ACOMP_ALLOC_OUTPUT 0x00000001 -/* Set this bit if source is virtual address instead of SG list. */ #define CRYPTO_ACOMP_REQ_SRC_VIRT 0x00000002
@@ -84,15 +82,12 @@ struct acomp_req {* * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation -* @dst_free: Frees destination buffer if allocated inside the -* algorithm * @reqsize: Context size for (de)compression requests * @base: Common crypto API algorithm data structure */ struct crypto_acomp {int (*compress)(struct acomp_req *req);int (*decompress)(struct acomp_req *req); -void (*dst_free)(struct scatterlist *dst);unsigned int reqsize;struct crypto_tfm base; };
@@ -261,9 +256,8 @@ static inline void acomp_request_set_callback(struct acomp_req *req,crypto_completion_t cmpl, void *data) { - u32 keep = CRYPTO_ACOMP_ALLOC_OUTPUT | CRYPTO_ACOMP_REQ_SRC_VIRT | -CRYPTO_ACOMP_REQ_SRC_NONDMA |CRYPTO_ACOMP_REQ_DST_VIRT | -CRYPTO_ACOMP_REQ_DST_NONDMA ; + u32 keep = CRYPTO_ACOMP_REQ_SRC_VIRT | CRYPTO_ACOMP_REQ_SRC_NONDMA | +CRYPTO_ACOMP_REQ_DST_VIRT |CRYPTO_ACOMP_REQ_DST_NONDMA ; req->base.complete = cmpl; req->base.data = data;
@@ -297,13 +291,10 @@ static inline void acomp_request_set_params(struct acomp_req *req, req->slen = slen; req->dlen = dlen; - req->base.flags &= ~(CRYPTO_ACOMP_ALLOC_OUTPUT | -CRYPTO_ACOMP_REQ_SRC_VIRT | + req->base.flags &= ~(CRYPTO_ACOMP_REQ_SRC_VIRT |CRYPTO_ACOMP_REQ_SRC_NONDMA |CRYPTO_ACOMP_REQ_DST_VIRT |CRYPTO_ACOMP_REQ_DST_NONDMA ); -if (!req->dst) - req->base.flags |=CRYPTO_ACOMP_ALLOC_OUTPUT ; }/**
@@ -403,7 +394,6 @@ static inline void acomp_request_set_dst_dma(struct acomp_req *req, req->dvirt = dst; req->dlen = dlen; - req->base.flags &= ~CRYPTO_ACOMP_ALLOC_OUTPUT ; req->base.flags &= ~CRYPTO_ACOMP_REQ_DST_NONDMA ; req->base.flags |=CRYPTO_ACOMP_REQ_DST_VIRT ; }
@@ -424,7 +414,6 @@ static inline void acomp_request_set_dst_nondma(struct acomp_req *req, req->dvirt = dst; req->dlen = dlen; - req->base.flags &= ~CRYPTO_ACOMP_ALLOC_OUTPUT ; req->base.flags |=CRYPTO_ACOMP_REQ_DST_NONDMA ; req->base.flags |=CRYPTO_ACOMP_REQ_DST_VIRT ; }
include/crypto/internal/scompress.h +0 -2
@@ -12,8 +12,6 @@#include <crypto/acompress.h> #include <crypto/algapi.h> -#define SCOMP_SCRATCH_SIZE 131072 -struct acomp_req ;struct crypto_scomp {
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 3/14 crypto: iaa - Remove dst_null support
In reply to Herbert XuRemove the unused dst_null support.
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 136 +-------------------- 1 file changed, 6 insertions(+), 130 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +6 -130
@@ -1136,8 +1136,7 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req,struct idxd_wq *wq, dma_addr_t src_addr, unsigned int slen, dma_addr_t dst_addr, unsigned int *dlen, - u32 *compression_crc, - bool disable_async) + u32 *compression_crc) { struct iaa_device_compression_mode *active_compression_mode;struct iaa_compression_ctx *ctx =crypto_tfm_ctx (tfm);
@@ -1180,7 +1179,7 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, desc->src2_size =sizeof (struct aecs_comp_table_record ); desc->completion_addr = idxd_desc->compl_dma; -if (ctx->use_irq && !disable_async) { +if (ctx->use_irq) { desc->flags |=IDXD_OP_FLAG_RCI ; idxd_desc->crypto.req = req;
@@ -1193,7 +1192,7 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req," src_addr %llx, dst_addr %llx\n" , __func__, active_compression_mode->name, src_addr, dst_addr); - }else if (ctx->async_mode && !disable_async) + }else if (ctx->async_mode) req->base.data = idxd_desc; dev_dbg(dev, "%s: compression mode %s,"
@@ -1214,7 +1213,7 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req,update_total_comp_calls ();update_wq_comp_calls (wq); -if (ctx->async_mode && !disable_async) { +if (ctx->async_mode) { ret = -EINPROGRESS ;dev_dbg (dev,"%s: returning -EINPROGRESS\n" , __func__); goto out;
@@ -1234,7 +1233,7 @@ static int iaa_compress(struct crypto_tfm *tfm, struct acomp_req *req, *compression_crc = idxd_desc->iax_completion->crc; -if (!ctx->async_mode || disable_async) +if (!ctx->async_mode)idxd_free_desc (wq, idxd_desc); out:return ret;
@@ -1500,13 +1499,11 @@ static int iaa_comp_acompress(struct acomp_req *req)struct iaa_compression_ctx *compression_ctx;struct crypto_tfm *tfm = req->base.tfm;dma_addr_t src_addr, dst_addr; -bool disable_async = false;int nr_sgs, cpu, ret =0 ;struct iaa_wq *iaa_wq;u32 compression_crc;struct idxd_wq *wq;struct device *dev; -int order =-1 ; compression_ctx =crypto_tfm_ctx (tfm);
@@ -1536,21 +1533,6 @@ static int iaa_comp_acompress(struct acomp_req *req) iaa_wq =idxd_wq_get_private (wq); -if (!req->dst) { -gfp_t flags = req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ?GFP_KERNEL :GFP_ATOMIC ; - -/* incompressible data will always be < 2 * slen */ - req->dlen =2 * req->slen; - order =order_base_2 (round_up (req->dlen,PAGE_SIZE ) /PAGE_SIZE ); - req->dst =sgl_alloc_order (req->dlen, order, false, flags,NULL ); -if (!req->dst) { - ret = -ENOMEM ; - order =-1 ; - goto out; - } - disable_async = true; - } - dev = &wq->idxd->pdev->dev; nr_sgs =dma_map_sg (dev, req->src,sg_nents (req->src),DMA_TO_DEVICE );
@@ -1580,7 +1562,7 @@ static int iaa_comp_acompress(struct acomp_req *req) req->dst, req->dlen, sg_dma_len(req->dst)); ret =iaa_compress (tfm, req, wq, src_addr, req->slen, dst_addr, - &req->dlen, &compression_crc, disable_async); + &req->dlen, &compression_crc);if (ret == -EINPROGRESS )return ret;
@@ -1611,100 +1593,6 @@ static int iaa_comp_acompress(struct acomp_req *req) out:iaa_wq_put (wq); -if (order >=0 ) -sgl_free_order (req->dst, order); - -return ret; -} - -static int iaa_comp_adecompress_alloc_dest (struct acomp_req *req) -{ -gfp_t flags = req->base.flags &CRYPTO_TFM_REQ_MAY_SLEEP ? -GFP_KERNEL :GFP_ATOMIC ; -struct crypto_tfm *tfm = req->base.tfm; -dma_addr_t src_addr, dst_addr; -int nr_sgs, cpu, ret =0 ; -struct iaa_wq *iaa_wq; -struct device *dev; -struct idxd_wq *wq; -int order =-1 ; - - cpu =get_cpu (); - wq =wq_table_next_wq (cpu); -put_cpu (); -if (!wq) { -pr_debug ("no wq configured for cpu=%d\n" , cpu); -return -ENODEV ; - } - - ret =iaa_wq_get (wq); -if (ret) { -pr_debug ("no wq available for cpu=%d\n" , cpu); -return -ENODEV ; - } - - iaa_wq =idxd_wq_get_private (wq); - - dev = &wq->idxd->pdev->dev; - - nr_sgs =dma_map_sg (dev, req->src,sg_nents (req->src),DMA_TO_DEVICE ); -if (nr_sgs <=0 || nr_sgs >1 ) { -dev_dbg (dev,"couldn't map src sg for iaa device %d," -" wq %d: ret=%d\n" , iaa_wq->iaa_device->idxd->id, - iaa_wq->wq->id, ret); - ret = -EIO ; - goto out; - } - src_addr =sg_dma_address (req->src); -dev_dbg (dev,"dma_map_sg, src_addr %llx, nr_sgs %d, req->src %p," -" req->slen %d, sg_dma_len(sg) %d\n" , src_addr, nr_sgs, - req->src, req->slen,sg_dma_len (req->src)); - - req->dlen =4 * req->slen;/* start with ~avg comp rato */ -alloc_dest: - order =order_base_2 (round_up (req->dlen,PAGE_SIZE ) /PAGE_SIZE ); - req->dst =sgl_alloc_order (req->dlen, order, false, flags,NULL ); -if (!req->dst) { - ret = -ENOMEM ; - order =-1 ; - goto out; - } - - nr_sgs =dma_map_sg (dev, req->dst,sg_nents (req->dst),DMA_FROM_DEVICE ); -if (nr_sgs <=0 || nr_sgs >1 ) { -dev_dbg (dev,"couldn't map dst sg for iaa device %d," -" wq %d: ret=%d\n" , iaa_wq->iaa_device->idxd->id, - iaa_wq->wq->id, ret); - ret = -EIO ; - goto err_map_dst; - } - - dst_addr =sg_dma_address (req->dst); -dev_dbg (dev,"dma_map_sg, dst_addr %llx, nr_sgs %d, req->dst %p," -" req->dlen %d, sg_dma_len(sg) %d\n" , dst_addr, nr_sgs, - req->dst, req->dlen,sg_dma_len (req->dst)); - ret =iaa_decompress (tfm, req, wq, src_addr, req->slen, - dst_addr, &req->dlen, true); -if (ret == -EOVERFLOW ) { -dma_unmap_sg (dev, req->dst,sg_nents (req->dst),DMA_FROM_DEVICE ); - req->dlen *=2 ; -if (req->dlen >CRYPTO_ACOMP_DST_MAX ) - goto err_map_dst; - goto alloc_dest; - } - -if (ret !=0 ) -dev_dbg (dev,"asynchronous decompress failed ret=%d\n" , ret); - -dma_unmap_sg (dev, req->dst,sg_nents (req->dst),DMA_FROM_DEVICE ); -err_map_dst: -dma_unmap_sg (dev, req->src,sg_nents (req->src),DMA_TO_DEVICE ); -out: -iaa_wq_put (wq); - -if (order >=0 ) -sgl_free_order (req->dst, order); -return ret; }
@@ -1727,9 +1615,6 @@ static int iaa_comp_adecompress(struct acomp_req *req)return -EINVAL ; } -if (!req->dst) -return iaa_comp_adecompress_alloc_dest (req); - cpu =get_cpu (); wq =wq_table_next_wq (cpu);put_cpu ();
@@ -1810,19 +1695,10 @@ static int iaa_comp_init_fixed(struct crypto_acomp *acomp_tfm)return 0 ; } -static void dst_free (struct scatterlist *sgl) -{ -/* -* Called for req->dst = NULL cases but we free elsewhere -* using sgl_free_order(). -*/ -} -static struct acomp_alg iaa_acomp_fixed_deflate = { .init = iaa_comp_init_fixed, .compress = iaa_comp_acompress, .decompress = iaa_comp_adecompress, - .dst_free = dst_free, .base = { .cra_name ="deflate" , .cra_driver_name ="deflate-iaa" ,
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 4/14 crypto: qat - Remove dst_null support
In reply to Herbert XuRemove the unused dst_null support.
--- drivers/crypto/intel/qat/qat_common/qat_bl.c | 159 ------------------ drivers/crypto/intel/qat/qat_common/qat_bl.h | 6 - .../intel/qat/qat_common/qat_comp_algs.c | 85 +--------- .../intel/qat/qat_common/qat_comp_req.h | 10 -- 4 files changed, 1 insertion(+), 259 deletions(-)
drivers/crypto/intel/qat/qat_common/qat_bl.c +0 -159
@@ -251,162 +251,3 @@ int qat_bl_sgl_to_bufl(struct adf_accel_dev *accel_dev, extra_dst_buff, sz_extra_dst_buff, sskip, dskip, flags); } - -static void qat_bl_sgl_unmap (struct adf_accel_dev *accel_dev, -struct qat_alg_buf_list *bl) -{ -struct device *dev = &GET_DEV (accel_dev); -int n = bl->num_bufs; -int i; - -for (i =0 ; i < n; i++) -if (!dma_mapping_error (dev, bl->buffers[i].addr)) -dma_unmap_single (dev, bl->buffers[i].addr, - bl->buffers[i].len,DMA_FROM_DEVICE ); -} - -static int qat_bl_sgl_map (struct adf_accel_dev *accel_dev, -struct scatterlist *sgl, -struct qat_alg_buf_list **bl) -{ -struct device *dev = &GET_DEV (accel_dev); -struct qat_alg_buf_list *bufl; -int node =dev_to_node (dev); -struct scatterlist *sg; -int n, i, sg_nctr; -size_t sz; - - n =sg_nents (sgl); - sz =struct_size (bufl, buffers, n); - bufl =kzalloc_node (sz,GFP_KERNEL , node); -if (unlikely (!bufl)) -return -ENOMEM ; - -for (i =0 ; i < n; i++) - bufl->buffers[i].addr =DMA_MAPPING_ERROR ; - - sg_nctr =0 ; -for_each_sg (sgl, sg, n, i) { -int y = sg_nctr; - -if (!sg->length) -continue ; - - bufl->buffers[y].addr =dma_map_single (dev,sg_virt (sg), - sg->length, -DMA_FROM_DEVICE ); - bufl->buffers[y].len = sg->length; -if (unlikely (dma_mapping_error (dev, bufl->buffers[y].addr))) - goto err_map; - sg_nctr++; - } - bufl->num_bufs = sg_nctr; - bufl->num_mapped_bufs = sg_nctr; - - *bl = bufl; - -return 0 ; - -err_map: -for (i =0 ; i < n; i++) -if (!dma_mapping_error (dev, bufl->buffers[i].addr)) -dma_unmap_single (dev, bufl->buffers[i].addr, - bufl->buffers[i].len, -DMA_FROM_DEVICE ); -kfree (bufl); - *bl =NULL ; - -return -ENOMEM ; -} - -static void qat_bl_sgl_free_unmap (struct adf_accel_dev *accel_dev, -struct scatterlist *sgl, -struct qat_alg_buf_list *bl, -bool free_bl) -{ -if (bl) { -qat_bl_sgl_unmap (accel_dev, bl); - -if (free_bl) -kfree (bl); - } -if (sgl) -sgl_free (sgl); -} - -static int qat_bl_sgl_alloc_map (struct adf_accel_dev *accel_dev, -struct scatterlist **sgl, -struct qat_alg_buf_list **bl, -unsigned int dlen, -gfp_t gfp) -{ -struct scatterlist *dst; -int ret; - - dst =sgl_alloc (dlen, gfp,NULL ); -if (!dst) { -dev_err (&GET_DEV (accel_dev),"sg_alloc failed\n" ); -return -ENOMEM ; - } - - ret =qat_bl_sgl_map (accel_dev, dst, bl); -if (ret) - goto err; - - *sgl = dst; - -return 0 ; - -err: -sgl_free (dst); - *sgl =NULL ; -return ret; -} - -int qat_bl_realloc_map_new_dst (struct adf_accel_dev *accel_dev, -struct scatterlist **sg, -unsigned int dlen, -struct qat_request_buffs *qat_bufs, -gfp_t gfp) -{ -struct device *dev = &GET_DEV (accel_dev); -dma_addr_t new_blp =DMA_MAPPING_ERROR ; -struct qat_alg_buf_list *new_bl; -struct scatterlist *new_sg; -size_t new_bl_size; -int ret; - - ret =qat_bl_sgl_alloc_map (accel_dev, &new_sg, &new_bl, dlen, gfp); -if (ret) -return ret; - - new_bl_size =struct_size (new_bl, buffers, new_bl->num_bufs); - -/* Map new firmware SGL descriptor */ - new_blp =dma_map_single (dev, new_bl, new_bl_size,DMA_TO_DEVICE ); -if (unlikely (dma_mapping_error (dev, new_blp))) - goto err; - -/* Unmap old firmware SGL descriptor */ -dma_unmap_single (dev, qat_bufs->bloutp, qat_bufs->sz_out,DMA_TO_DEVICE ); - -/* Free and unmap old scatterlist */ -qat_bl_sgl_free_unmap (accel_dev, *sg, qat_bufs->blout, - !qat_bufs->sgl_dst_valid); - - qat_bufs->sgl_dst_valid = false; - qat_bufs->blout = new_bl; - qat_bufs->bloutp = new_blp; - qat_bufs->sz_out = new_bl_size; - - *sg = new_sg; - -return 0 ; -err: -qat_bl_sgl_free_unmap (accel_dev, new_sg, new_bl, true); - -if (!dma_mapping_error (dev, new_blp)) -dma_unmap_single (dev, new_blp, new_bl_size,DMA_TO_DEVICE ); - -return -ENOMEM ; -}
drivers/crypto/intel/qat/qat_common/qat_bl.h +0 -6
@@ -65,10 +65,4 @@ static inline gfp_t qat_algs_alloc_flags(struct crypto_async_request *req) return req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC; } -int qat_bl_realloc_map_new_dst (struct adf_accel_dev *accel_dev, -struct scatterlist **newd, -unsigned int dlen, -struct qat_request_buffs *qat_bufs, -gfp_t gfp); -#endif
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c +1 -84
123 lines not on this page · raw message
drivers/crypto/intel/qat/qat_common/qat_comp_req.h +0 -10
@@ -25,16 +25,6 @@ static inline void qat_comp_create_req(void *ctx, void *req, u64 src, u32 slen, req_pars->out_buffer_sz = dlen; } -static inline void qat_comp_override_dst (void *req,u64 dst,u32 dlen) -{ -struct icp_qat_fw_comp_req *fw_req = req; -struct icp_qat_fw_comp_req_params *req_pars = &fw_req->comp_pars; - - fw_req->comn_mid.dest_data_addr = dst; - fw_req->comn_mid.dst_length = dlen; - req_pars->out_buffer_sz = dlen; -} - static inline void qat_comp_create_compression_req(void *ctx, void *req, u64 src, u32 slen, u64 dst, u32 dlen,
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 5/14 crypto: acomp - Remove dst_free
In reply to Herbert XuRemove the unused dst_free hook.
--- include/crypto/internal/acompress.h | 2 -- 1 file changed, 2 deletions(-)
include/crypto/internal/acompress.h +0 -2
@@ -17,7 +17,6 @@* * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation -* @dst_free: Frees destination buffer if allocated inside the algorithm * @init: Initialize the cryptographic transformation object. * This function is used to initialize the cryptographic * transformation object. This function is called only once at
@@ -38,7 +37,6 @@struct acomp_alg {int (*compress)(struct acomp_req *req);int (*decompress)(struct acomp_req *req); -void (*dst_free)(struct scatterlist *dst);int (*init)(struct crypto_acomp *tfm);void (*exit)(struct crypto_acomp *tfm);
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 6/14 crypto: scomp - Add chaining and virtual address support
In reply to Herbert XuAdd chaining and virtual address support to all scomp algorithms.
--- crypto/scompress.c | 96 +++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 31 deletions(-)
crypto/scompress.c +65 -31
@@ -178,8 +178,9 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)unsigned int dlen = req->dlen;struct page *spage, *dpage;unsigned int soff, doff; -void *src, *dst;unsigned int n; +const u8 *src; +u8 *dst;int ret;if (!req->src || !slen)
@@ -188,37 +189,47 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir)if (!req->dst || !dlen)return -EINVAL ; - soff = req->src->offset; - spage =nth_page (sg_page (req->src), soff /PAGE_SIZE ); - soff =offset_in_page (soff); - - n = slen /PAGE_SIZE ; - n += (offset_in_page (slen) + soff -1 ) /PAGE_SIZE ; -if (slen <= req->src->length && (!PageHighMem (nth_page (spage, n)) || -size_add (soff, slen) <=PAGE_SIZE )) - src =kmap_local_page (spage) + soff; -else - src = scratch->src; - - doff = req->dst->offset; - dpage =nth_page (sg_page (req->dst), doff /PAGE_SIZE ); - doff =offset_in_page (doff); - - n = dlen /PAGE_SIZE ; - n += (offset_in_page (dlen) + doff -1 ) /PAGE_SIZE ; -if (dlen <= req->dst->length && (!PageHighMem (nth_page (dpage, n)) || -size_add (doff, dlen) <=PAGE_SIZE )) - dst =kmap_local_page (dpage) + doff; +if (acomp_request_src_isvirt (req)) + src = req->svirt;else { -if (dlen >SCOMP_SCRATCH_SIZE ) - dlen =SCOMP_SCRATCH_SIZE ; - dst = scratch->dst; + soff = req->src->offset; + spage =nth_page (sg_page (req->src), soff /PAGE_SIZE ); + soff =offset_in_page (soff); + + n = slen /PAGE_SIZE ; + n += (offset_in_page (slen) + soff -1 ) /PAGE_SIZE ; +if (slen <= req->src->length && + (!PageHighMem (nth_page (spage, n)) || +size_add (soff, slen) <=PAGE_SIZE )) + src =kmap_local_page (spage) + soff; +else + src = scratch->src; + } + +if (acomp_request_dst_isvirt (req)) + dst = req->dvirt; +else { + doff = req->dst->offset; + dpage =nth_page (sg_page (req->dst), doff /PAGE_SIZE ); + doff =offset_in_page (doff); + + n = dlen /PAGE_SIZE ; + n += (offset_in_page (dlen) + doff -1 ) /PAGE_SIZE ; +if (dlen <= req->dst->length && + (!PageHighMem (nth_page (dpage, n)) || +size_add (doff, dlen) <=PAGE_SIZE )) + dst =kmap_local_page (dpage) + doff; +else { +if (dlen >SCOMP_SCRATCH_SIZE ) + dlen =SCOMP_SCRATCH_SIZE ; + dst = scratch->dst; + } }spin_lock_bh (&scratch->lock);if (src == scratch->src) -memcpy_from_sglist (src, req->src,0 , slen); +memcpy_from_sglist (scratch->src, req->src,0 , slen); stream =raw_cpu_ptr (crypto_scomp_alg (scomp)->stream);spin_lock (&stream->lock);
@@ -237,7 +248,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) req->dlen = dlen; -if (dst != scratch->dst) { +if (!acomp_request_dst_isvirt (req) && dst != scratch->dst) {kunmap_local (dst); dlen += doff;for (;;) {
@@ -248,20 +259,34 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) dpage =nth_page (dpage,1 ); } } -if (src != scratch->src) +if (!acomp_request_src_isvirt (req) && src != scratch->src)kunmap_local (src);return ret; } +static int scomp_acomp_chain (struct acomp_req *req,int dir) +{ +struct acomp_req *r2; +int err; + + err =scomp_acomp_comp_decomp (req, dir); + req->base.err = err; + +list_for_each_entry (r2, &req->base.list, base.list) + r2->base.err =scomp_acomp_comp_decomp (r2, dir); + +return err; +} +static int scomp_acomp_compress (struct acomp_req *req) { -return scomp_acomp_comp_decomp (req,1 ); +return scomp_acomp_chain (req,1 ); }static int scomp_acomp_decompress (struct acomp_req *req) { -return scomp_acomp_comp_decomp (req,0 ); +return scomp_acomp_chain (req,0 ); }static void crypto_exit_scomp_ops_async (struct crypto_tfm *tfm)
@@ -322,12 +347,21 @@ static const struct crypto_type crypto_scomp_type = { .tfmsize = offsetof(struct crypto_scomp, base), }; -int crypto_register_scomp (struct scomp_alg *alg) +static void scomp_prepare_alg (struct scomp_alg *alg) {struct crypto_alg *base = &alg->calg.base;comp_prepare_alg (&alg->calg); + base->cra_flags |=CRYPTO_ALG_REQ_CHAIN ; +} + +int crypto_register_scomp (struct scomp_alg *alg) +{ +struct crypto_alg *base = &alg->calg.base; + +scomp_prepare_alg (alg); + base->cra_type = &crypto_scomp_type; base->cra_flags |=CRYPTO_ALG_TYPE_SCOMPRESS ;
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 7/14 crypto: acomp - Add ACOMP_REQUEST_ALLOC and acomp_request_alloc_extra
In reply to Herbert XuAdd ACOMP_REQUEST_ALLOC which is a wrapper around acomp_request_alloc that falls back to a synchronous stack reqeust if the allocation fails.
Also add ACOMP_REQUEST_ON_STACK which stores the request on the stack only.
The request should be freed with acomp_request_free.
Finally add acomp_request_alloc_extra which gives the user extra memory to use in conjunction with the request.
--- crypto/acompress.c | 38 ++++++++++++-- include/crypto/acompress.h | 80 +++++++++++++++++++++++++++-- include/crypto/internal/acompress.h | 6 +++ include/linux/crypto.h | 1 + 4 files changed, 117 insertions(+), 8 deletions(-)
crypto/acompress.c +33 -5
@@ -60,28 +60,56 @@ static void crypto_acomp_exit_tfm(struct crypto_tfm *tfm)struct crypto_acomp *acomp =__crypto_acomp_tfm (tfm);struct acomp_alg *alg =crypto_acomp_alg (acomp); - alg->exit (acomp); +if (alg->exit) + alg->exit (acomp); + +if (acomp_is_async (acomp)) +crypto_free_acomp (acomp->fb); }static int crypto_acomp_init_tfm (struct crypto_tfm *tfm) {struct crypto_acomp *acomp =__crypto_acomp_tfm (tfm);struct acomp_alg *alg =crypto_acomp_alg (acomp); +struct crypto_acomp *fb =NULL ; +int err; + + acomp->fb = acomp;if (tfm->__crt_alg->cra_type != &crypto_acomp_type)return crypto_init_scomp_ops_async (tfm); +if (acomp_is_async (acomp)) { + fb =crypto_alloc_acomp (crypto_acomp_alg_name (acomp),0 , +CRYPTO_ALG_ASYNC ); +if (IS_ERR (fb)) +return PTR_ERR (fb); + + err = -EINVAL ; +if (crypto_acomp_reqsize (fb) >MAX_SYNC_COMP_REQSIZE ) + goto out_free_fb; + + acomp->fb = fb; + } + acomp->compress = alg->compress; acomp->decompress = alg->decompress; acomp->reqsize = alg->reqsize; -if (alg->exit) - acomp->base.exit = crypto_acomp_exit_tfm; + acomp->base.exit = crypto_acomp_exit_tfm; -if (alg->init) -return alg->init (acomp); +if (!alg->init) +return 0 ; + + err = alg->init (acomp); +if (err) + goto out_free_fb;return 0 ; + +out_free_fb: +crypto_free_acomp (fb); +return err; }static unsigned int crypto_acomp_extsize (struct crypto_alg *alg)
include/crypto/acompress.h +77 -3
145 lines not on this page · raw message
include/crypto/internal/acompress.h +6 -0
@@ -12,6 +12,12 @@#include <crypto/acompress.h> #include <crypto/algapi.h> +#define ACOMP_REQUEST_ON_STACK (name, tfm) \ + char __##name##_req[sizeof(struct acomp_req) + \ + MAX_SYNC_COMP_REQSIZE] CRYPTO_MINALIGN_ATTR; \ + struct acomp_req *name = acomp_request_on_stack_init( \ + __##name##_req, (tfm), 0, true) +/** * struct acomp_alg - asynchronous compression algorithm *
include/linux/crypto.h +1 -0
@@ -138,6 +138,7 @@#define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS 0x00000100#define CRYPTO_TFM_REQ_MAY_SLEEP 0x00000200#define CRYPTO_TFM_REQ_MAY_BACKLOG 0x00000400 +#define CRYPTO_TFM_REQ_ON_STACK 0x00000800/* * Miscellaneous stuff.
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 8/14 crypto: iaa - Use acomp stack fallback
In reply to Herbert XuUse ACOMP_REQUEST_ON_STACK instead of allocating legacy fallback compression transform.
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 28 +++++----------------- 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +6 -22
@@ -33,8 +33,6 @@ static unsigned int nr_cpus_per_node;/* Number of physical cpus sharing each iaa instance */ static unsigned int cpus_per_iaa; -static struct crypto_comp *deflate_generic_tfm; -/* Per-cpu lookup table for balanced wqs */ static struct wq_table_entry __percpu *wq_table;
@@ -1001,17 +999,14 @@ static inline int check_completion(struct device *dev,static int deflate_generic_decompress (struct acomp_req *req) { -void *src, *dst; +ACOMP_REQUEST_ON_STACK (fbreq,crypto_acomp_reqtfm (req));int ret; - src =kmap_local_page (sg_page (req->src)) + req->src->offset; - dst =kmap_local_page (sg_page (req->dst)) + req->dst->offset; - - ret =crypto_comp_decompress (deflate_generic_tfm, - src, req->slen, dst, &req->dlen); - -kunmap_local (src); -kunmap_local (dst); +acomp_request_set_callback (fbreq,0 ,NULL ,NULL ); +acomp_request_set_params (fbreq, req->src, req->dst, req->slen, + req->dlen); + ret =crypto_acomp_decompress (fbreq); + req->dlen = fbreq->dlen;update_total_sw_decomp_calls ();
@@ -1898,15 +1893,6 @@ static int __init iaa_crypto_init_module(void) } nr_cpus_per_node = nr_cpus / nr_nodes; -if (crypto_has_comp ("deflate-generic" ,0 ,0 )) - deflate_generic_tfm =crypto_alloc_comp ("deflate-generic" ,0 ,0 ); - -if (IS_ERR_OR_NULL (deflate_generic_tfm)) { -pr_err ("IAA could not alloc %s tfm: errcode = %ld\n" , -"deflate-generic" ,PTR_ERR (deflate_generic_tfm)); -return -ENOMEM ; - } - ret =iaa_aecs_init_fixed ();if (ret <0 ) {pr_debug ("IAA fixed compression mode init failed\n" );
@@ -1948,7 +1934,6 @@ static int __init iaa_crypto_init_module(void) err_driver_reg:iaa_aecs_cleanup_fixed (); err_aecs_init: -crypto_free_comp (deflate_generic_tfm); goto out; }
@@ -1965,7 +1950,6 @@ static void __exit iaa_crypto_cleanup_module(void) &driver_attr_verify_compress);idxd_driver_unregister (&iaa_crypto_driver);iaa_aecs_cleanup_fixed (); -crypto_free_comp (deflate_generic_tfm);pr_debug ("cleaned up\n" ); }
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 9/14 crypto: acomp - Add async nondma fallback
In reply to Herbert XuAdd support for passing non-DMA virtual addresses to async drivers by passing them along to the fallback software algorithm.
--- crypto/acompress.c | 69 +++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 28 deletions(-)
crypto/acompress.c +41 -28
@@ -152,20 +152,6 @@ struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type, }EXPORT_SYMBOL_GPL (crypto_alloc_acomp_node); -static bool acomp_request_has_nondma (struct acomp_req *req) -{ -struct acomp_req *r2; - -if (acomp_request_isnondma (req)) -return true; - -list_for_each_entry (r2, &req->base.list, base.list) -if (acomp_request_isnondma (r2)) -return true; - -return false; -} -static void acomp_save_req (struct acomp_req *req,crypto_completion_t cplt) {struct crypto_acomp *tfm =crypto_acomp_reqtfm (req);
@@ -234,6 +220,45 @@ static void acomp_virt_to_sg(struct acomp_req *req) } } +static int acomp_do_nondma (struct acomp_req_chain *state, +struct acomp_req *req) +{ +u32 keep =CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_SRC_NONDMA | +CRYPTO_ACOMP_REQ_DST_VIRT | +CRYPTO_ACOMP_REQ_DST_NONDMA ; +ACOMP_REQUEST_ON_STACK (fbreq,crypto_acomp_reqtfm (req)); +int err; + +acomp_request_set_callback (fbreq, req->base.flags,NULL ,NULL ); + fbreq->base.flags &= ~keep; + fbreq->base.flags |= req->base.flags & keep; + fbreq->src = req->src; + fbreq->dst = req->dst; + fbreq->slen = req->slen; + fbreq->dlen = req->dlen; + +if (state->op ==crypto_acomp_reqtfm (req)->compress) + err =crypto_acomp_compress (fbreq); +else + err =crypto_acomp_decompress (fbreq); + + req->dlen = fbreq->dlen; +return err; +} + +static int acomp_do_one_req (struct acomp_req_chain *state, +struct acomp_req *req) +{ + state->cur = req; + +if (acomp_request_isnondma (req)) +return acomp_do_nondma (state, req); + +acomp_virt_to_sg (req); +return state->op (req); +} +static int acomp_reqchain_finish (struct acomp_req_chain *state,int err,u32 mask) {
@@ -252,10 +277,8 @@ static int acomp_reqchain_finish(struct acomp_req_chain *state, req->base.flags &= mask; req->base.complete = acomp_reqchain_done; req->base.data = state; - state->cur = req; -acomp_virt_to_sg (req); - err = state->op (req); + err =acomp_do_one_req (state, req);if (err == -EINPROGRESS ) {if (!list_empty (&state->head))
@@ -308,27 +331,17 @@ static int acomp_do_req_chain(struct acomp_req *req, (!acomp_request_chained(req) && !acomp_request_isvirt(req)))return op (req); -/* -* There are no in-kernel users that do this. If and ever -* such users come into being then we could add a fall-back -* path. -*/ -if (acomp_request_has_nondma (req)) -return -EINVAL ; -if (acomp_is_async (tfm)) {acomp_save_req (req, acomp_reqchain_done); state = req->base.data; } state->op = op; - state->cur = req; state->src =NULL ;INIT_LIST_HEAD (&state->head);list_splice_init (&req->base.list, &state->head); -acomp_virt_to_sg (req); - err =op (req); + err =acomp_do_one_req (state, req);if (err == -EBUSY || err == -EINPROGRESS )return -EBUSY ;
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 10/14 crypto: acomp - Add support for folios
In reply to Herbert XuFor many users, it's easier to supply a folio rather than an SG list since they already have them. Add support for folios to the acomp interface.
--- crypto/acompress.c | 40 +++++++++++-- crypto/scompress.c | 68 ++++++++++++++-------- include/crypto/acompress.h | 89 +++++++++++++++++++++++++++-- include/crypto/internal/acompress.h | 18 ++++++ 4 files changed, 182 insertions(+), 33 deletions(-)
crypto/acompress.c +35 -5
@@ -12,6 +12,7 @@#include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/page-flags.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/string.h>
@@ -189,18 +190,25 @@ static void acomp_reqchain_virt(struct acomp_req_chain *state, int err) req->base.err = err; state = &req->chain; -if (state->src) +if (state->flags &CRYPTO_ACOMP_REQ_SRC_VIRT )acomp_request_set_src_dma (req, state->src, slen); -if (state->dst) +else if (state->flags &CRYPTO_ACOMP_REQ_SRC_FOLIO ) +acomp_request_set_src_folio (req, state->sfolio, state->soff, slen); +if (state->flags &CRYPTO_ACOMP_REQ_DST_VIRT )acomp_request_set_dst_dma (req, state->dst, dlen); - state->src =NULL ; - state->dst =NULL ; +else if (state->flags &CRYPTO_ACOMP_REQ_DST_FOLIO ) +acomp_request_set_dst_folio (req, state->dfolio, state->doff, dlen); }static void acomp_virt_to_sg (struct acomp_req *req) {struct acomp_req_chain *state = &req->chain; + state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_DST_VIRT | +CRYPTO_ACOMP_REQ_SRC_FOLIO | +CRYPTO_ACOMP_REQ_DST_FOLIO ); +if (acomp_request_src_isvirt (req)) {unsigned int slen = req->slen;const u8 *svirt = req->svirt;
@@ -208,6 +216,17 @@ static void acomp_virt_to_sg(struct acomp_req *req) state->src = svirt;sg_init_one (&state->ssg, svirt, slen);acomp_request_set_src_sg (req, &state->ssg, slen); + }else if (acomp_request_src_isfolio (req)) { +struct folio *folio = req->sfolio; +unsigned int slen = req->slen; +size_t off = req->soff; + + state->sfolio = folio; + state->soff = off; +sg_init_table (&state->ssg,1 ); +sg_set_page (&state->ssg,folio_page (folio, off /PAGE_SIZE ), + slen, off %PAGE_SIZE ); +acomp_request_set_src_sg (req, &state->ssg, slen); }if (acomp_request_dst_isvirt (req)) {
@@ -217,6 +236,17 @@ static void acomp_virt_to_sg(struct acomp_req *req) state->dst = dvirt;sg_init_one (&state->dsg, dvirt, dlen);acomp_request_set_dst_sg (req, &state->dsg, dlen); + }else if (acomp_request_dst_isfolio (req)) { +struct folio *folio = req->dfolio; +unsigned int dlen = req->dlen; +size_t off = req->doff; + + state->dfolio = folio; + state->doff = off; +sg_init_table (&state->dsg,1 ); +sg_set_page (&state->dsg,folio_page (folio, off /PAGE_SIZE ), + dlen, off %PAGE_SIZE ); +acomp_request_set_src_sg (req, &state->dsg, dlen); } }
@@ -328,7 +358,7 @@ static int acomp_do_req_chain(struct acomp_req *req,int err;if (crypto_acomp_req_chain (tfm) || - (!acomp_request_chained (req) && !acomp_request_isvirt (req))) + (!acomp_request_chained (req) &&acomp_request_issg (req)))return op (req);if (acomp_is_async (tfm)) {
crypto/scompress.c +44 -24
91 lines not on this page · raw message
include/crypto/acompress.h +85 -4
180 lines not on this page · raw message
include/crypto/internal/acompress.h +18 -0
@@ -103,6 +103,14 @@ static inline bool acomp_request_chained(struct acomp_req *req)return crypto_request_chained (&req->base); } +static inline bool acomp_request_issg (struct acomp_req *req) +{ +return !(req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_DST_VIRT | +CRYPTO_ACOMP_REQ_SRC_FOLIO | +CRYPTO_ACOMP_REQ_DST_FOLIO )); +} +static inline bool acomp_request_src_isvirt (struct acomp_req *req) {return req->base.flags &CRYPTO_ACOMP_REQ_SRC_VIRT ;
@@ -135,6 +143,16 @@ static inline bool acomp_request_isnondma(struct acomp_req *req) CRYPTO_ACOMP_REQ_DST_NONDMA); } +static inline bool acomp_request_src_isfolio (struct acomp_req *req) +{ +return req->base.flags &CRYPTO_ACOMP_REQ_SRC_FOLIO ; +} + +static inline bool acomp_request_dst_isfolio (struct acomp_req *req) +{ +return req->base.flags &CRYPTO_ACOMP_REQ_DST_FOLIO ; +} +static inline bool crypto_acomp_req_chain (struct crypto_acomp *tfm) {return crypto_tfm_req_chain (&tfm->base);
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 12/14 PM: hibernate: Use crypto_acomp interface
In reply to Herbert XuReplace the legacy crypto compression interface with the new acomp interface.
--- kernel/power/hibernate.c | 5 ++-- kernel/power/swap.c | 58 +++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 21 deletions(-)
kernel/power/hibernate.c +3 -2
@@ -11,6 +11,7 @@#define pr_fmt (fmt) "PM: hibernation: " fmt +#include <crypto/acompress.h> #include <linux/blkdev.h> #include <linux/export.h> #include <linux/suspend.h>
@@ -757,7 +758,7 @@ int hibernate(void)*/ if (!nocompress) {strscpy (hib_comp_algo, hibernate_compressor,sizeof (hib_comp_algo)); -if (crypto_has_comp (hib_comp_algo,0 ,0 ) !=1 ) { +if (!crypto_has_acomp (hib_comp_algo,0 ,CRYPTO_ALG_ASYNC )) {pr_err ("%s compression is not available\n" , hib_comp_algo);return -EOPNOTSUPP ; }
@@ -1008,7 +1009,7 @@ static int software_resume(void)strscpy (hib_comp_algo,COMPRESSION_ALGO_LZ4 ,sizeof (hib_comp_algo)); else strscpy(hib_comp_algo, COMPRESSION_ALGO_LZO, sizeof(hib_comp_algo)); -if (crypto_has_comp (hib_comp_algo,0 ,0 ) !=1 ) { +if (!crypto_has_acomp (hib_comp_algo,0 ,CRYPTO_ALG_ASYNC )) {pr_err ("%s compression is not available\n" , hib_comp_algo); error = -EOPNOTSUPP ; goto Unlock;
kernel/power/swap.c +39 -19
136 lines not on this page · raw message
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 13/14 ubifs: Use crypto_acomp interface
In reply to Herbert XuReplace the legacy crypto compression interface with the new acomp interface.
Remove the compression mutexes and the overallocation for memory (the offender LZO has been fixed).
Cap the output buffer length for compression to eliminate the post-compression check for UBIFS_MIN_COMPRESS_DIFF.
--- fs/ubifs/compress.c | 106 ++++++++++++++++++++++++++------------------ fs/ubifs/journal.c | 2 +- fs/ubifs/ubifs.h | 15 +------ 3 files changed, 67 insertions(+), 56 deletions(-)
fs/ubifs/compress.c +64 -42
@@ -15,7 +15,7 @@* decompression. */ -#include <linux/crypto.h> +#include <crypto/acompress.h> #include "ubifs.h" /* Fake description object for the "none" compressor */
@@ -26,11 +26,8 @@ static struct ubifs_compressor none_compr = { };#ifdef CONFIG_UBIFS_FS_LZO -static DEFINE_MUTEX (lzo_mutex); -static struct ubifs_compressor lzo_compr = { .compr_type =UBIFS_COMPR_LZO , - .comp_mutex = &lzo_mutex, .name ="lzo" , .capi_name ="lzo" , };
@@ -42,13 +39,8 @@ static struct ubifs_compressor lzo_compr = {#endif #ifdef CONFIG_UBIFS_FS_ZLIB -static DEFINE_MUTEX (deflate_mutex); -static DEFINE_MUTEX (inflate_mutex); -static struct ubifs_compressor zlib_compr = { .compr_type =UBIFS_COMPR_ZLIB , - .comp_mutex = &deflate_mutex, - .decomp_mutex = &inflate_mutex, .name ="zlib" , .capi_name ="deflate" , };
@@ -60,13 +52,8 @@ static struct ubifs_compressor zlib_compr = {#endif #ifdef CONFIG_UBIFS_FS_ZSTD -static DEFINE_MUTEX (zstd_enc_mutex); -static DEFINE_MUTEX (zstd_dec_mutex); -static struct ubifs_compressor zstd_compr = { .compr_type =UBIFS_COMPR_ZSTD , - .comp_mutex = &zstd_enc_mutex, - .decomp_mutex = &zstd_dec_mutex, .name ="zstd" , .capi_name ="zstd" , };
@@ -80,6 +67,30 @@ static struct ubifs_compressor zstd_compr = {/* All UBIFS compressors */ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT ]; +static int ubifs_compress_req (const struct ubifs_info *c, +struct acomp_req *req, +void *out_buf,int *out_len, +const char *compr_name) +{ +struct crypto_wait wait; +int in_len = req->slen; +int dlen = *out_len; +int err; + + dlen =min (dlen, in_len -UBIFS_MIN_COMPRESS_DIFF ); + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); +acomp_request_set_dst_dma (req, out_buf, dlen); + err =crypto_acomp_compress (req); + err =crypto_wait_req (err, &wait); + *out_len = req->dlen; +acomp_request_free (req); + +return err; +} +/** * ubifs_compress - compress data. * @c: UBIFS file-system description object
@@ -112,23 +123,14 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,if (in_len <UBIFS_MIN_COMPR_LEN ) goto no_compr; -if (compr->comp_mutex) -mutex_lock (compr->comp_mutex); - err =crypto_comp_compress (compr->cc, in_buf, in_len, out_buf, - (unsigned int *)out_len); -if (compr->comp_mutex) -mutex_unlock (compr->comp_mutex); -if (unlikely (err)) { -ubifs_warn (c,"cannot compress %d bytes, compressor %s, error %d, leave data uncompressed" , - in_len, compr->name, err); - goto no_compr; + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_src_nondma (req, in_buf, in_len); + err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); } -/* -* If the data compressed only slightly, it is better to leave it -* uncompressed to improve read speed. -*/ -if (in_len - *out_len <UBIFS_MIN_COMPRESS_DIFF ) +if (err) goto no_compr;return ;
@@ -139,6 +141,31 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, *compr_type =UBIFS_COMPR_NONE ; } +static int ubifs_decompress_req (const struct ubifs_info *c, +struct acomp_req *req, +const void *in_buf,int in_len,int *out_len, +const char *compr_name) +{ +struct crypto_wait wait; +int err; + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); +acomp_request_set_src_dma (req, in_buf, in_len); + err =crypto_acomp_decompress (req); + err =crypto_wait_req (err, &wait); + *out_len = req->dlen; + +if (err) +ubifs_err (c,"cannot decompress %d bytes, compressor %s, error %d" , + in_len, compr_name, err); + +acomp_request_free (req); + +return err; +} +/** * ubifs_decompress - decompress data. * @c: UBIFS file-system description object
@@ -155,7 +182,6 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,int ubifs_decompress (const struct ubifs_info *c,const void *in_buf,int in_len,void *out_buf,int *out_len,int compr_type) { -int err;struct ubifs_compressor *compr;if (unlikely (compr_type <0 || compr_type >=UBIFS_COMPR_TYPES_CNT )) {
@@ -176,17 +202,13 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,return 0 ; } -if (compr->decomp_mutex) -mutex_lock (compr->decomp_mutex); - err =crypto_comp_decompress (compr->cc, in_buf, in_len, out_buf, - (unsigned int *)out_len); -if (compr->decomp_mutex) -mutex_unlock (compr->decomp_mutex); -if (err) -ubifs_err (c,"cannot decompress %d bytes, compressor %s, error %d" , - in_len, compr->name, err); + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -return err; +acomp_request_set_dst_nondma (req, out_buf, *out_len); +return ubifs_decompress_req (c, req, in_buf, in_len, out_len, + compr->name); + } }/**
@@ -199,7 +221,7 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,static int __init compr_init (struct ubifs_compressor *compr) {if (compr->capi_name) { - compr->cc =crypto_alloc_comp (compr->capi_name,0 ,0 ); + compr->cc =crypto_alloc_acomp (compr->capi_name,0 ,0 );if (IS_ERR (compr->cc)) {pr_err ("UBIFS error (pid %d): cannot initialize compressor %s, error %ld" , current->pid, compr->name,PTR_ERR (compr->cc));
@@ -218,7 +240,7 @@ static int __init compr_init(struct ubifs_compressor *compr)static void compr_exit (struct ubifs_compressor *compr) {if (compr->capi_name) -crypto_free_comp (compr->cc); +crypto_free_acomp (compr->cc); }/**
fs/ubifs/journal.c +1 -1
@@ -1625,7 +1625,7 @@ static int truncate_data_node(const struct ubifs_info *c, const struct inode *inint err, dlen, compr_type, out_len, data_size; out_len =le32_to_cpu (dn->size); - buf =kmalloc_array (out_len,WORST_COMPR_FACTOR ,GFP_NOFS ); + buf =kmalloc (out_len,GFP_NOFS );if (!buf)return -ENOMEM ;
fs/ubifs/ubifs.h +2 -13
@@ -124,13 +124,6 @@#define OLD_ZNODE_AGE 20#define YOUNG_ZNODE_AGE 5 -/* -* Some compressors, like LZO, may end up with more data then the input buffer. -* So UBIFS always allocates larger output buffer, to be sure the compressor -* will not corrupt memory in case of worst case compression. -*/ -#define WORST_COMPR_FACTOR 2 -#ifdef CONFIG_FS_ENCRYPTION #define UBIFS_CIPHER_BLOCK_SIZE FSCRYPT_CONTENTS_ALIGNMENT#else
@@ -141,7 +134,7 @@* How much memory is needed for a buffer where we compress a data node. */ #define COMPRESSED_DATA_NODE_BUF_SZ \ - (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) + (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)/* Maximum expected tree height for use by bottom_up_buf */ #define BOTTOM_UP_HEIGHT 64
@@ -835,16 +828,12 @@ struct ubifs_node_range {* struct ubifs_compressor - UBIFS compressor description structure. * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc) * @cc: cryptoapi compressor handle -* @comp_mutex: mutex used during compression -* @decomp_mutex: mutex used during decompression * @name: compressor name * @capi_name: cryptoapi compressor name */ struct ubifs_compressor {int compr_type; -struct crypto_comp *cc; -struct mutex *comp_mutex; -struct mutex *decomp_mutex; +struct crypto_acomp *cc;const char *name;const char *capi_name; };
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 14/14 ubifs: Pass folios to acomp
In reply to Herbert XuAs the acomp interface supports folios, use that instead of mapping the data in ubifs.
--- fs/ubifs/compress.c | 106 +++++++++++++++++++++++++++++++++++++++++++- fs/ubifs/file.c | 74 +++++++++++-------------------- fs/ubifs/journal.c | 9 ++-- fs/ubifs/ubifs.h | 11 ++++- 4 files changed, 145 insertions(+), 55 deletions(-)
fs/ubifs/compress.c +104 -2
@@ -16,6 +16,7 @@*/ #include <crypto/acompress.h> +#include <linux/highmem.h> #include "ubifs.h" /* Fake description object for the "none" compressor */
@@ -126,7 +127,7 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_src_nondma (req, in_buf, in_len); +acomp_request_set_src_dma (req, in_buf, in_len); err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); }
@@ -141,6 +142,58 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, *compr_type =UBIFS_COMPR_NONE ; } +/** +* ubifs_compress_folio - compress folio. +* @c: UBIFS file-system description object +* @in_folio: data to compress +* @in_offset: offset into @in_folio +* @in_len: length of the data to compress +* @out_buf: output buffer where compressed data should be stored +* @out_len: output buffer length is returned here +* @compr_type: type of compression to use on enter, actually used compression +* type on exit +* +* This function compresses input folio @in_folio of length @in_len and +* stores the result in the output buffer @out_buf and the resulting length +* in @out_len. If the input buffer does not compress, it is just copied +* to the @out_buf. The same happens if @compr_type is %UBIFS_COMPR_NONE +* or if compression error occurred. +* +* Note, if the input buffer was not compressed, it is copied to the output +* buffer and %UBIFS_COMPR_NONE is returned in @compr_type. +*/ +void ubifs_compress_folio (const struct ubifs_info *c,struct folio *in_folio, +size_t in_offset,int in_len,void *out_buf, +int *out_len,int *compr_type) +{ +int err; +struct ubifs_compressor *compr = ubifs_compressors[*compr_type]; + +if (*compr_type ==UBIFS_COMPR_NONE ) + goto no_compr; + +/* If the input data is small, do not even try to compress it */ +if (in_len <UBIFS_MIN_COMPR_LEN ) + goto no_compr; + + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_src_folio (req, in_folio, in_offset, in_len); + err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); + } + +if (err) + goto no_compr; + +return ; + +no_compr: +memcpy_from_folio (out_buf, in_folio, in_offset, in_len); + *out_len = in_len; + *compr_type =UBIFS_COMPR_NONE ; +} + static int ubifs_decompress_req(const struct ubifs_info *c, struct acomp_req *req, const void *in_buf, int in_len, int *out_len,
@@ -205,7 +258,56 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_dst_nondma (req, out_buf, *out_len); +acomp_request_set_dst_dma (req, out_buf, *out_len); +return ubifs_decompress_req (c, req, in_buf, in_len, out_len, + compr->name); + } +} + +/** +* ubifs_decompress_folio - decompress folio. +* @c: UBIFS file-system description object +* @in_buf: data to decompress +* @in_len: length of the data to decompress +* @out_folio: output folio where decompressed data should +* @out_offset: offset into @out_folio +* @out_len: output length is returned here +* @compr_type: type of compression +* +* This function decompresses data from buffer @in_buf into folio +* @out_folio. The length of the uncompressed data is returned in +* @out_len. This functions returns %0 on success or a negative error +* code on failure. +*/ +int ubifs_decompress_folio (const struct ubifs_info *c,const void *in_buf, +int in_len,struct folio *out_folio, +size_t out_offset,int *out_len,int compr_type) +{ +struct ubifs_compressor *compr; + +if (unlikely (compr_type <0 || compr_type >=UBIFS_COMPR_TYPES_CNT )) { +ubifs_err (c,"invalid compression type %d" , compr_type); +return -EINVAL ; + } + + compr = ubifs_compressors[compr_type]; + +if (unlikely (!compr->capi_name)) { +ubifs_err (c,"%s compression is not compiled in" , compr->name); +return -EINVAL ; + } + +if (compr_type ==UBIFS_COMPR_NONE ) { +memcpy_to_folio (out_folio, out_offset, in_buf, in_len); + *out_len = in_len; +return 0 ; + } + + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_dst_folio (req, out_folio, out_offset, + *out_len);return ubifs_decompress_req (c, req, in_buf, in_len, out_len, compr->name); }
fs/ubifs/file.c +25 -49
224 lines not on this page · raw message
fs/ubifs/journal.c +6 -3
@@ -845,14 +845,16 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir,* @c: UBIFS file-system description object * @inode: inode the data node belongs to * @key: node key -* @buf: buffer to write +* @folio: buffer to write +* @offset: offset to write at * @len: data length (must not exceed %UBIFS_BLOCK_SIZE) * * This function writes a data node to the journal. Returns %0 if the data node * was successfully written, and a negative error code in case of failure. */ int ubifs_jnl_write_data (struct ubifs_info *c,const struct inode *inode, -const union ubifs_key *key,const void *buf,int len) +const union ubifs_key *key,struct folio *folio, +size_t offset,int len) {struct ubifs_data_node *data;int err, lnum, offs, compr_type, out_len, compr_len, auth_len;
@@ -896,7 +898,8 @@ int ubifs_jnl_write_data(struct ubifs_info *c, const struct inode *inode, compr_type = ui->compr_type; out_len = compr_len = dlen -UBIFS_DATA_NODE_SZ ; -ubifs_compress (c, buf, len, &data->data, &compr_len, &compr_type); +ubifs_compress_folio (c, folio, offset, len, &data->data, &compr_len, + &compr_type);ubifs_assert (c, compr_len <=UBIFS_BLOCK_SIZE );if (encrypted) {
fs/ubifs/ubifs.h +10 -1
@@ -263,6 +263,8 @@ enum { ASSACT_PANIC, }; +struct folio ; +/** * struct ubifs_old_idx - index node obsoleted since last commit start. * @rb: rb-tree node
@@ -1784,7 +1786,8 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, const struct fscrypt_name *nm, const struct inode *inode, int deletion, int xent, int in_orphan);int ubifs_jnl_write_data (struct ubifs_info *c,const struct inode *inode, -const union ubifs_key *key,const void *buf,int len); +const union ubifs_key *key,struct folio *folio, +size_t offset,int len);int ubifs_jnl_write_inode (struct ubifs_info *c,const struct inode *inode);int ubifs_jnl_delete_inode (struct ubifs_info *c,const struct inode *inode); int ubifs_jnl_xrename(struct ubifs_info *c, const struct inode *fst_dir,
@@ -2084,8 +2087,14 @@ int __init ubifs_compressors_init(void);void ubifs_compressors_exit (void );void ubifs_compress (const struct ubifs_info *c,const void *in_buf,int in_len,void *out_buf,int *out_len,int *compr_type); +void ubifs_compress_folio (const struct ubifs_info *c,struct folio *folio, +size_t offset,int in_len,void *out_buf, +int *out_len,int *compr_type);int ubifs_decompress (const struct ubifs_info *c,const void *buf,int len,void *out,int *out_len,int compr_type); +int ubifs_decompress_folio (const struct ubifs_info *c,const void *buf, +int len,struct folio *folio,size_t offset, +int *out_len,int compr_type);/* sysfs.c */ int ubifs_sysfs_init (void );
Signature · 1 line
2.39.5
Herbert Xu
maintainerPATCH v5 11/14 xfrm: ipcomp: Use crypto_acomp interface
In reply to Herbert XuReplace the legacy comperssion interface with the new acomp interface. This is the first user to make full user of the asynchronous nature of acomp by plugging into the existing xfrm resume interface.
As a result of SG support by acomp, the linear scratch buffer in ipcomp can be removed.
--- include/net/ipcomp.h | 13 +- net/xfrm/xfrm_algo.c | 7 +- net/xfrm/xfrm_ipcomp.c | 477 ++++++++++++++++++++--------------------- 3 files changed, 236 insertions(+), 261 deletions(-)
include/net/ipcomp.h +1 -12
@@ -3,20 +3,9 @@#define _NET_IPCOMP_H#include <linux/skbuff.h> -#include <linux/types.h> - -#define IPCOMP_SCRATCH_SIZE 65400 - -struct crypto_comp ; -struct ip_comp_hdr ; - -struct ipcomp_data { -u16 threshold; -struct crypto_comp *__percpu *tfms; -};struct ip_comp_hdr ; -struct sk_buff ; +struct netlink_ext_ack ;struct xfrm_state ;int ipcomp_input (struct xfrm_state *x,struct sk_buff *skb);
net/xfrm/xfrm_algo.c +3 -4
@@ -5,13 +5,13 @@* Copyright (c) 2002 James Morris <[email protected]> */ +#include <crypto/acompress.h> #include <crypto/aead.h> #include <crypto/hash.h> #include <crypto/skcipher.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/pfkeyv2.h> -#include <linux/crypto.h> #include <linux/scatterlist.h> #include <net/xfrm.h> #if IS_ENABLED (CONFIG_INET_ESP ) ||IS_ENABLED (CONFIG_INET6_ESP )
@@ -669,7 +669,7 @@ static const struct xfrm_algo_list xfrm_ealg_list = { };static const struct xfrm_algo_list xfrm_calg_list = { - .find = crypto_has_comp, + .find = crypto_has_acomp, .algs = calg_list, .entries =ARRAY_SIZE (calg_list), };
@@ -828,8 +828,7 @@ void xfrm_probe_algs(void) }for (i =0 ; i <calg_entries (); i++) { - status =crypto_has_comp (calg_list[i].name,0 , -CRYPTO_ALG_ASYNC ); + status =crypto_has_acomp (calg_list[i].name,0 ,0 );if (calg_list[i].available != status) calg_list[i].available = status; }
net/xfrm/xfrm_ipcomp.c +232 -245
574 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [v5 PATCH 13/14] ubifs: Use crypto_acomp interface
In reply to Herbert XuQuoted 9 lines · Herbert Xu
Replace the legacy crypto compression interface with the new acomp interface.
Remove the compression mutexes and the overallocation for memory (the offender LZO has been fixed).
Cap the output buffer length for compression to eliminate the post-compression check for
UBIFS_MIN_COMPRESS_DIFF.
Quoted 7 lines
Signed-off-by Herbert Xu <[email protected]>--- fs/ubifs/compress.c | 106 ++++++++++++++++++++++++++------------------ fs/ubifs/journal.c | 2 +- fs/ubifs/ubifs.h | 15 +------ 3 files changed, 67 insertions(+), 56 deletions(-)
Quoted 255 lines
fs/ubifs/compress.c +64
-42@@ -15,7 +15,7 @@* decompression. */ -#include <linux/crypto.h> +#include <crypto/acompress.h> #include "ubifs.h" /* Fake description object for the "none" compressor */ @@ -26,11 +26,8 @@ static struct ubifs_compressor none_compr = { };#ifdef CONFIG_UBIFS_FS_LZO -static DEFINE_MUTEX (lzo_mutex); -static struct ubifs_compressor lzo_compr = { .compr_type =UBIFS_COMPR_LZO , - .comp_mutex = &lzo_mutex, .name ="lzo" , .capi_name ="lzo" , };@@ -42,13 +39,8 @@ static struct ubifs_compressor lzo_compr = {#endif #ifdef CONFIG_UBIFS_FS_ZLIB -static DEFINE_MUTEX (deflate_mutex); -static DEFINE_MUTEX (inflate_mutex); -static struct ubifs_compressor zlib_compr = { .compr_type =UBIFS_COMPR_ZLIB , - .comp_mutex = &deflate_mutex, - .decomp_mutex = &inflate_mutex, .name ="zlib" , .capi_name ="deflate" , };@@ -60,13 +52,8 @@ static struct ubifs_compressor zlib_compr = {#endif #ifdef CONFIG_UBIFS_FS_ZSTD -static DEFINE_MUTEX (zstd_enc_mutex); -static DEFINE_MUTEX (zstd_dec_mutex); -static struct ubifs_compressor zstd_compr = { .compr_type =UBIFS_COMPR_ZSTD , - .comp_mutex = &zstd_enc_mutex, - .decomp_mutex = &zstd_dec_mutex, .name ="zstd" , .capi_name ="zstd" , };@@ -80,6 +67,30 @@ static struct ubifs_compressor zstd_compr = {/* All UBIFS compressors */ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT ]; +static int ubifs_compress_req (const struct ubifs_info *c, +struct acomp_req *req, +void *out_buf,int *out_len, +const char *compr_name) +{ +struct crypto_wait wait; +int in_len = req->slen; +int dlen = *out_len; +int err; + + dlen =min (dlen, in_len -UBIFS_MIN_COMPRESS_DIFF ); + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); +acomp_request_set_dst_dma (req, out_buf, dlen); + err =crypto_acomp_compress (req); + err =crypto_wait_req (err, &wait); + *out_len = req->dlen; +acomp_request_free (req); + +return err; +} +/** * ubifs_compress - compress data. * @c: UBIFS file-system description object @@ -112,23 +123,14 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,if (in_len <UBIFS_MIN_COMPR_LEN ) goto no_compr; -if (compr->comp_mutex) -mutex_lock (compr->comp_mutex); - err =crypto_comp_compress (compr->cc, in_buf, in_len, out_buf, - (unsigned int *)out_len); -if (compr->comp_mutex) -mutex_unlock (compr->comp_mutex); -if (unlikely (err)) { -ubifs_warn (c,"cannot compress %d bytes, compressor %s, error %d, leave data uncompressed" , - in_len, compr->name, err); - goto no_compr; + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_src_nondma (req, in_buf, in_len); + err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); } -/* -* If the data compressed only slightly, it is better to leave it -* uncompressed to improve read speed. -*/ -if (in_len - *out_len <UBIFS_MIN_COMPRESS_DIFF ) +if (err) goto no_compr;return ;@@ -139,6 +141,31 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, *compr_type =UBIFS_COMPR_NONE ; } +static int ubifs_decompress_req (const struct ubifs_info *c, +struct acomp_req *req, +const void *in_buf,int in_len,int *out_len, +const char *compr_name) +{ +struct crypto_wait wait; +int err; + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); +acomp_request_set_src_dma (req, in_buf, in_len); + err =crypto_acomp_decompress (req); + err =crypto_wait_req (err, &wait); + *out_len = req->dlen; + +if (err) +ubifs_err (c,"cannot decompress %d bytes, compressor %s, error %d" , + in_len, compr_name, err); + +acomp_request_free (req); + +return err; +} +/** * ubifs_decompress - decompress data. * @c: UBIFS file-system description object @@ -155,7 +182,6 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf,int ubifs_decompress (const struct ubifs_info *c,const void *in_buf,int in_len,void *out_buf,int *out_len,int compr_type) { -int err;struct ubifs_compressor *compr;if (unlikely (compr_type <0 || compr_type >=UBIFS_COMPR_TYPES_CNT )) {@@ -176,17 +202,13 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,return 0 ; } -if (compr->decomp_mutex) -mutex_lock (compr->decomp_mutex); - err =crypto_comp_decompress (compr->cc, in_buf, in_len, out_buf, - (unsigned int *)out_len); -if (compr->decomp_mutex) -mutex_unlock (compr->decomp_mutex); -if (err) -ubifs_err (c,"cannot decompress %d bytes, compressor %s, error %d" , - in_len, compr->name, err); + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -return err; +acomp_request_set_dst_nondma (req, out_buf, *out_len); +return ubifs_decompress_req (c, req, in_buf, in_len, out_len, + compr->name); + } }/** @@ -199,7 +221,7 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf,static int __init compr_init (struct ubifs_compressor *compr) {if (compr->capi_name) { - compr->cc =crypto_alloc_comp (compr->capi_name,0 ,0 ); + compr->cc =crypto_alloc_acomp (compr->capi_name,0 ,0 );if (IS_ERR (compr->cc)) {pr_err ("UBIFS error (pid %d): cannot initialize compressor %s, error %ld" , current->pid, compr->name,PTR_ERR (compr->cc));@@ -218,7 +240,7 @@ static int __init compr_init(struct ubifs_compressor *compr)static void compr_exit (struct ubifs_compressor *compr) {if (compr->capi_name) -crypto_free_comp (compr->cc); +crypto_free_acomp (compr->cc); }/** fs/ubifs/journal.c +1
-1@@ -1625,7 +1625,7 @@ static int truncate_data_node(const struct ubifs_info *c, const struct inode *inint err, dlen, compr_type, out_len, data_size; out_len =le32_to_cpu (dn->size); - buf =kmalloc_array (out_len,WORST_COMPR_FACTOR ,GFP_NOFS ); + buf =kmalloc (out_len,GFP_NOFS );if (!buf)return -ENOMEM ;fs/ubifs/ubifs.h +2
-13@@ -124,13 +124,6 @@#define OLD_ZNODE_AGE 20#define YOUNG_ZNODE_AGE 5 -/* -* Some compressors, like LZO, may end up with more data then the input buffer. -* So UBIFS always allocates larger output buffer, to be sure the compressor -* will not corrupt memory in case of worst case compression. -*/ -#define WORST_COMPR_FACTOR 2 -#ifdef CONFIG_FS_ENCRYPTION #define UBIFS_CIPHER_BLOCK_SIZE FSCRYPT_CONTENTS_ALIGNMENT#else @@ -141,7 +134,7 @@* How much memory is needed for a buffer where we compress a data node. */ #define COMPRESSED_DATA_NODE_BUF_SZ \ - (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR) + (UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE)/* Maximum expected tree height for use by bottom_up_buf */ #define BOTTOM_UP_HEIGHT 64@@ -835,16 +828,12 @@ struct ubifs_node_range {* struct ubifs_compressor - UBIFS compressor description structure. * @compr_type: compressor type (%UBIFS_COMPR_LZO, etc) * @cc: cryptoapi compressor handle -* @comp_mutex: mutex used during compression -* @decomp_mutex: mutex used during decompression * @name: compressor name * @capi_name: cryptoapi compressor name */ struct ubifs_compressor {int compr_type; -struct crypto_comp *cc; -struct mutex *comp_mutex; -struct mutex *decomp_mutex; +struct crypto_acomp *cc;const char *name;const char *capi_name; };
Re: [v5 PATCH 14/14] ubifs: Pass folios to acomp
In reply to Herbert XuQuoted 10 lines · Herbert Xu
As the acomp interface supports folios, use that instead of mapping the data in ubifs.
Signed-off-by Herbert Xu <[email protected]>--- fs/ubifs/compress.c | 106 +++++++++++++++++++++++++++++++++++++++++++- fs/ubifs/file.c | 74 +++++++++++-------------------- fs/ubifs/journal.c | 9 ++-- fs/ubifs/ubifs.h | 11 ++++- 4 files changed, 145 insertions(+), 55 deletions(-)
Quoted 14 lines
fs/ubifs/compress.c +1
-0@@ -16,6 +16,7 @@*/ #include <crypto/acompress.h> +#include <linux/highmem.h> #include "ubifs.h" /* Fake description object for the "none" compressor */
fs/ubifs/compress.c void ubifs_compress(const struct ubifs_info *c, const void *in_buf, · line 130
Quoted 5 lines
fs/ubifs/compress.c +1
-1@@ -126,7 +127,7 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_src_nondma (req, in_buf, in_len); +acomp_request_set_src_dma (req, in_buf, in_len);
Why not merging it into patch 13?
Quoted 63 lines
fs/ubifs/compress.c +52
-0err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); }@@ -141,6 +142,58 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, *compr_type =UBIFS_COMPR_NONE ; } +/** +* ubifs_compress_folio - compress folio. +* @c: UBIFS file-system description object +* @in_folio: data to compress +* @in_offset: offset into @in_folio +* @in_len: length of the data to compress +* @out_buf: output buffer where compressed data should be stored +* @out_len: output buffer length is returned here +* @compr_type: type of compression to use on enter, actually used compression +* type on exit +* +* This function compresses input folio @in_folio of length @in_len and +* stores the result in the output buffer @out_buf and the resulting length +* in @out_len. If the input buffer does not compress, it is just copied +* to the @out_buf. The same happens if @compr_type is %UBIFS_COMPR_NONE +* or if compression error occurred. +* +* Note, if the input buffer was not compressed, it is copied to the output +* buffer and %UBIFS_COMPR_NONE is returned in @compr_type. +*/ +void ubifs_compress_folio (const struct ubifs_info *c,struct folio *in_folio, +size_t in_offset,int in_len,void *out_buf, +int *out_len,int *compr_type) +{ +int err; +struct ubifs_compressor *compr = ubifs_compressors[*compr_type]; + +if (*compr_type ==UBIFS_COMPR_NONE ) + goto no_compr; + +/* If the input data is small, do not even try to compress it */ +if (in_len <UBIFS_MIN_COMPR_LEN ) + goto no_compr; + + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_src_folio (req, in_folio, in_offset, in_len); + err =ubifs_compress_req (c, req, out_buf, out_len, compr->name); + } + +if (err) + goto no_compr; + +return ; + +no_compr: +memcpy_from_folio (out_buf, in_folio, in_offset, in_len); + *out_len = in_len; + *compr_type =UBIFS_COMPR_NONE ; +} + static int ubifs_decompress_req(const struct ubifs_info *c, struct acomp_req *req, const void *in_buf, int in_len, int *out_len,
fs/ubifs/compress.c int ubifs_decompress(const struct ubifs_info *c, const void *in_buf, · line 261
Quoted 5 lines
fs/ubifs/compress.c +1
-1@@ -205,7 +258,56 @@ int ubifs_decompress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_dst_nondma (req, out_buf, *out_len); +acomp_request_set_dst_dma (req, out_buf, *out_len);
Same as the suggestion above.
Quoted 52 lines
fs/ubifs/compress.c +49
-0+return ubifs_decompress_req (c, req, in_buf, in_len, out_len, + compr->name); + } +} + +/** +* ubifs_decompress_folio - decompress folio. +* @c: UBIFS file-system description object +* @in_buf: data to decompress +* @in_len: length of the data to decompress +* @out_folio: output folio where decompressed data should +* @out_offset: offset into @out_folio +* @out_len: output length is returned here +* @compr_type: type of compression +* +* This function decompresses data from buffer @in_buf into folio +* @out_folio. The length of the uncompressed data is returned in +* @out_len. This functions returns %0 on success or a negative error +* code on failure. +*/ +int ubifs_decompress_folio (const struct ubifs_info *c,const void *in_buf, +int in_len,struct folio *out_folio, +size_t out_offset,int *out_len,int compr_type) +{ +struct ubifs_compressor *compr; + +if (unlikely (compr_type <0 || compr_type >=UBIFS_COMPR_TYPES_CNT )) { +ubifs_err (c,"invalid compression type %d" , compr_type); +return -EINVAL ; + } + + compr = ubifs_compressors[compr_type]; + +if (unlikely (!compr->capi_name)) { +ubifs_err (c,"%s compression is not compiled in" , compr->name); +return -EINVAL ; + } + +if (compr_type ==UBIFS_COMPR_NONE ) { +memcpy_to_folio (out_folio, out_offset, in_buf, in_len); + *out_len = in_len; +return 0 ; + } + + { +ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); + +acomp_request_set_dst_folio (req, out_folio, out_offset, + *out_len);return ubifs_decompress_req (c, req, in_buf, in_len, out_len, compr->name); }
Herbert Xu
maintainerRe: [v5 PATCH 14/14] ubifs: Pass folios to acomp
Quoted 2 lines · Zhihao Cheng
Thank you for testing!
Quoted 10 lines
Quoted 10 lines
fs/ubifs/compress.c +1
-0@@ -16,6 +16,7 @@*/ #include <crypto/acompress.h> +#include <linux/highmem.h> #include "ubifs.h"
Quoted 8 lines
fs/ubifs/compress.c void ubifs_compress(const struct ubifs_info *c, const void *in_buf, · line 129
Quoted 6 lines
fs/ubifs/compress.c +1
-1/* Fake description object for the "none" compressor */ @@ -126,7 +127,7 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_src_nondma (req, in_buf, in_len); +acomp_request_set_src_dma (req, in_buf, in_len);Why not merging it into patch 13?
Because it will break without this patch. If the input is a highmem folio it cannot be directly passed over to DMA (because the virtual address has been remapped by kmap_local).
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Herbert Xu
maintainerRe: [v5 PATCH 10/14] crypto: acomp - Add support for folios
In reply to Herbert XuQuoted 4 lines · Herbert Xu
crypto/scompress.c +0
-3- n = slen /PAGE_SIZE ; - n += (offset_in_page (slen) + soff -1 ) /PAGE_SIZE ; - if (slen <= req->src->length &&
crypto/scompress.c static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) · line 214
Quoted 10 lines
crypto/scompress.c +8
-2- (!PageHighMem (nth_page (spage, n)) || - size_add(soff, slen) <= PAGE_SIZE)) + spage =nth_page (spage, soff /PAGE_SIZE ); + soff =offset_in_page (soff); + + n = slen /PAGE_SIZE ; + n += (offset_in_page (slen) + soff -1 ) /PAGE_SIZE ; +if (PageHighMem (nth_page (spage, n)) && +size_add (soff, slen) <=PAGE_SIZE ) +break ;
This should of course be
size_add(soff, slen) > PAGE_SIZE
crypto/scompress.c static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) · line 241
Quoted 2 lines
crypto/scompress.c +2
-0+if (PageHighMem (dpage + n) && +size_add (doff, dlen) <=PAGE_SIZE )
Ditto.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Zhihao Cheng
reviewerRe: [v5 PATCH 14/14] ubifs: Pass folios to acomp
In reply to Herbert XuQuoted 25 lines · Herbert Xu
Quoted 2 lines · Zhihao Cheng
Thank you for testing!
Quoted 10 lines
Quoted 10 lines
fs/ubifs/compress.c +1
-0@@ -16,6 +16,7 @@*/ #include <crypto/acompress.h> +#include <linux/highmem.h> #include "ubifs.h" Quoted 8 lines
fs/ubifs/compress.c void ubifs_compress(const struct ubifs_info *c, const void *in_buf, · line 129
Quoted 6 lines
fs/ubifs/compress.c +1
-1/* Fake description object for the "none" compressor */ @@ -126,7 +127,7 @@ void ubifs_compress(const struct ubifs_info *c, const void *in_buf, {ACOMP_REQUEST_ALLOC (req, compr->cc,GFP_NOFS | __GFP_NOWARN); -acomp_request_set_src_nondma (req, in_buf, in_len); +acomp_request_set_src_dma (req, in_buf, in_len);Why not merging it into patch 13?
Quoted 3 lines
Because it will break without this patch. If the input is a highmem folio it cannot be directly passed over to DMA (because the virtual address has been remapped by
kmap_local).
Makes sense.
Quoted 3 lines
Cheers,
Herbert Xu
maintainerRe: [v5 PATCH 11/14] xfrm: ipcomp: Use crypto_acomp interface
In reply to Herbert XuQuoted 5 lines · Herbert Xu
net/xfrm/xfrm_ipcomp.c +4
-0+sg_init_table (dsg, dnfrags); + total =0 ; +for (i =0 ; i < dnfrags && total < dlen; i++) { +struct page *page;
net/xfrm/xfrm_ipcomp.c line 192
Quoted 10 lines
net/xfrm/xfrm_ipcomp.c +10
-0+ + page =alloc_page (GFP_ATOMIC ); +if (!page) +break ; +sg_set_page (dsg + i, page,PAGE_SIZE ,0 ); + total +=PAGE_SIZE ; + } +if (!i) +return ERR_PTR (-ENOMEM ); +sg_mark_end (dsg + i -1 );
This is missing a
dlen = min(dlen, total);
Review
Quoted 2 lines
(quoted diff) +2
-0+ + acomp_request_set_params(req, sg, dsg, plen, dlen);
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v5 PATCH 11/14] xfrm: ipcomp: Use crypto_acomp interface
In reply to Herbert XuHi Herbert,
Quoted 18 lines · Herbert Xu
net/xfrm/xfrm_ipcomp.c +12
-4+static int ipcomp_post_acomp (struct sk_buff *skb,int err,int hlen) +{ +struct acomp_req *req =ipcomp_cb (skb)->req; +struct ipcomp_req_extra *extra; +const int plen = skb->data_len; +struct scatterlist *dsg; +int len, dlen; - len = dlen - plen; -if (len >skb_tailroom (skb)) - len =skb_tailroom (skb); +if (unlikely (err)) + goto out_free_req; -__skb_put (skb, len); + extra =acomp_request_extra (req); + dsg = extra->sg; + dlen = req->dlen;
net/xfrm/xfrm_ipcomp.c line 67
Quoted 10 lines
net/xfrm/xfrm_ipcomp.c +5
-3- len += plen; -skb_copy_to_linear_data (skb, scratch, len); +pskb_trim_unique (skb,0 ); +__skb_put (skb, hlen); -while ((scratch += len, dlen -= len) >0 ) { +/* Only update truesize on input. */ +if (!hlen) + skb->truesize += dlen - plen;
Are you sure we need to subtract plen here? When I run fragmented traffic with ipcomp, I'm hitting the WARN from skb_try_coalesce during reassembly, ie truesize is too small:
delta = from->truesize - SKB_TRUESIZE(skb_end_offset(from));
WARN_ON_ONCE(delta < len);The splat goes away with
/* Only update truesize on input. */
if (!hlen)
- skb->truesize += dlen - plen;
+ skb->truesize += dlen;
skb->data_len = dlen;
skb->len += dlen;
pskb_trim_unique ends up calling skb_condense, which seems to adjust the truesize to account for all frags being dropped.
Does that look like the right fix to you?
Signature · 1 line
Sabrina
Herbert Xu
maintainerRe: [v5 PATCH 11/14] xfrm: ipcomp: Use crypto_acomp interface
Quoted 10 lines · Sabrina Dubroca
The splat goes away with
(quoted diff) +1
-1/* Only update truesize on input. */ if (!hlen) - skb->truesize += dlen - plen; + skb->truesize += dlen; skb->data_len = dlen; skb->len += dlen;
Quoted 4 lines
pskb_trim_uniqueends up callingskb_condense, which seems to adjust the truesize to account for all frags being dropped.Does that look like the right fix to you?
You're right. I must've missed the truesize update in skb_condense when writing this.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Re: [v5 PATCH 11/14] xfrm: ipcomp: Use crypto_acomp interface
Quoted 11 lines · Herbert Xu
Quoted 10 lines · Sabrina Dubroca
The splat goes away with
(quoted diff) +1
-1/* Only update truesize on input. */ if (!hlen) - skb->truesize += dlen - plen; + skb->truesize += dlen; skb->data_len = dlen; skb->len += dlen;
Quoted 7 lines
Quoted 4 lines
pskb_trim_uniqueends up callingskb_condense, which seems to adjust the truesize to account for all frags being dropped.Does that look like the right fix to you?
You're right. I must've missed the truesize update in
skb_condensewhen writing this.
Ok, I'll submit the patch in a bit. Thanks.
Signature · 1 line
Sabrina