FAILED: patch "[PATCH] crypto: iaa - unmap dst before software fallback on" failed to apply to 7.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 7.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-7.1.y
git checkout FETCH_HEAD
git cherry-pick -x 94a25930477113730372e0fa2985da4c5ac95c9a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026083134-rockband-cone-6be0@gregkh' --subject-prefix 'PATCH 7.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 94a25930477113730372e0fa2985da4c5ac95c9a Mon Sep 17 00:00:00 2001
From: Vinicius Costa Gomes <[email protected]>
Date: Wed, 5 Aug 2026 14:19:26 -0700
Subject: [PATCH] crypto: iaa - unmap dst before software fallback on
decompress
On a hardware analytics error, decompress retries through the software fallback, which writes req->dst with the CPU while it is still mapped DMA_FROM_DEVICE. With SWIOTLB active the later dma_unmap_sg() copies the stale bounce buffer over req->dst, corrupting the result.
Unmap before the fallback runs. The async path unmaps inline; the sync path signals the retry with -EAGAIN so iaa_comp_adecompress() runs the fallback after unmapping.
drivers/crypto/intel/iaa/iaa_crypto_main.c +18 -17
@@ -995,6 +995,11 @@ static inline int check_completion(struct device *dev,return ret; } +static bool iaa_error_should_retry (struct idxd_desc *idxd_desc) +{ +return idxd_desc->iax_completion->status ==IAA_ANALYTICS_ERROR ; +} +static void iaa_unmap_src (struct device *dev,struct acomp_req *req) {struct iaa_req_ctx *req_ctx =acomp_request_ctx (req);
@@ -1082,18 +1087,21 @@ static void iaa_desc_complete(struct idxd_desc *idxd_desc, ctx->compress, false);if (ret) {dev_dbg (dev,"%s: check_completion failed ret=%d\n" , __func__, ret); -if (!ctx->compress && - idxd_desc->iax_completion->status ==IAA_ANALYTICS_ERROR ) { +if (!ctx->compress &&iaa_error_should_retry (idxd_desc)) {pr_warn ("%s: falling back to deflate-generic decompress, " "analytics error code %x\n" , __func__, idxd_desc->iax_completion->error_code); +dma_unmap_sg (dev, ctx->req->dst,sg_nents (ctx->req->dst), +DMA_FROM_DEVICE ); +iaa_unmap_src (dev, ctx->req); + ret =deflate_generic_decompress (ctx->req);if (ret) {dev_dbg (dev,"%s: deflate-generic failed ret=%d\n" , __func__, ret); err = -EIO ; - goto err; } + goto out; }else { err = -EIO ; goto err;
@@ -1477,19 +1485,9 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, ret =check_completion (dev, idxd_desc->iax_completion, false, false);if (ret) {dev_dbg (dev,"%s: check_completion failed ret=%d\n" , __func__, ret); -if (idxd_desc->iax_completion->status ==IAA_ANALYTICS_ERROR ) { -pr_warn ("%s: falling back to deflate-generic decompress, " -"analytics error code %x\n" , __func__, - idxd_desc->iax_completion->error_code); - ret =deflate_generic_decompress (req); -if (ret) { -dev_dbg (dev,"%s: deflate-generic failed ret=%d\n" , - __func__, ret); - goto err; - } - }else { - goto err; - } +if (iaa_error_should_retry (idxd_desc)) + ret = -EAGAIN ; + goto err; }else { req->dlen = idxd_desc->iax_completion->output_size;
@@ -1722,13 +1720,16 @@ static int iaa_comp_adecompress(struct acomp_req *req)if (ret == -EINPROGRESS )return ret; -if (ret !=0 ) +if (ret !=0 && ret != -EAGAIN )dev_dbg (dev,"asynchronous decompress failed ret=%d\n" , ret);dma_unmap_sg (dev, req->dst,1 ,DMA_FROM_DEVICE );iaa_unmap_src (dev, req);iaa_wq_put (wq); +if (ret == -EAGAIN ) + ret =deflate_generic_decompress (req); +return ret; }
Sasha Levin
maintainerPATCH 1/2 crypto: iaa - fall back to software for multi-entry scatterlists
From: Giovanni Cabiddu <[email protected]>
[ Upstream commit c7fdfd2bee1cf1448e5244da1a734e680f634b02 ]
IAA cannot process source or destination scatterlists with more than one entry directly. Instead of failing these requests, route them through a separate deflate acomp transform and keep the request alive in software.
The IAA driver has never handled multi-entry scatterlists, but the limitation was latent until commit e2c3b6b21c77 ("mm: zswap: use SG list decompression APIs from zsmalloc") made zswap pass the raw zsmalloc SG list directly to crypto drivers, so objects spanning multiple pages now reach IAA as multi-entry sources and would otherwise fail decompression.
Fallback to the generic DEFLATE implementation for scatterlists with more than one entry. After the multi-entry cases fall back early, simplify the DMA mapping path to a single scatterlist entry and fall back on mapping failure as well.
Add counters to track the number of requests processed by the software implementation on the compression direction.
Stable-dep-of: 94a259304771 ("crypto: iaa - unmap dst before software fallback on decompress")
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 111 +++++++++++--------- drivers/crypto/intel/iaa/iaa_crypto_stats.c | 9 ++ drivers/crypto/intel/iaa/iaa_crypto_stats.h | 2 + 3 files changed, 71 insertions(+), 51 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +60 -51
@@ -2,6 +2,7 @@/* Copyright(c) 2021 Intel Corporation. All rights rsvd. */ #include <linux/init.h> +#include <linux/crypto.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h>
@@ -996,6 +997,19 @@ static int deflate_generic_decompress(struct acomp_req *req)return ret; } +static int deflate_generic_compress (struct acomp_req *req) +{ +ACOMP_FBREQ_ON_STACK (fbreq, req); +int ret; + + ret =crypto_acomp_compress (fbreq); + req->dlen = fbreq->dlen; + +update_total_sw_comp_calls (); + +return ret; +} +static int iaa_remap_for_verify (struct device *dev,struct iaa_wq *iaa_wq,struct acomp_req *req,dma_addr_t *src_addr,dma_addr_t *dst_addr);
@@ -1472,7 +1486,7 @@ 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; -int nr_sgs, cpu, ret =0 ; +int cpu, ret =0 ;struct iaa_wq *iaa_wq;struct idxd_wq *wq;struct device *dev;
@@ -1484,11 +1498,15 @@ static int iaa_comp_acompress(struct acomp_req *req)return -ENODEV ; } -if (!req->src || !req->slen) { -pr_debug ("invalid src, not compressing\n" ); +if (!req->src || !req->slen || !req->dst) { +pr_debug ("invalid req, not compressing\n" );return -EINVAL ; } +/* Fall back to software if src or dst has multiple sg entries */ +if (sg_nents (req->src) >1 ||sg_nents (req->dst) >1 ) +return deflate_generic_compress (req); + cpu =get_cpu (); wq =wq_table_next_wq (cpu);put_cpu ();
@@ -1507,30 +1525,25 @@ static int iaa_comp_acompress(struct acomp_req *req) 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; +if (!dma_map_sg (dev, req->src,1 ,DMA_TO_DEVICE )) { +dev_dbg (dev,"couldn't map src sg for iaa device %d, wq %d\n" , + iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id); +iaa_wq_put (wq); +return deflate_generic_compress (req); } 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, +dev_dbg (dev,"map src %llx req->src %p slen %d sg_len %d\n" , src_addr, req->src, req->slen,sg_dma_len (req->src)); - 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; +if (!dma_map_sg (dev, req->dst,1 ,DMA_FROM_DEVICE )) { +dev_dbg (dev,"couldn't map dst sg for iaa device %d, wq %d\n" , + iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id); +dma_unmap_sg (dev, req->src,1 ,DMA_TO_DEVICE ); +iaa_wq_put (wq); +return deflate_generic_compress (req); } 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, +dev_dbg (dev,"map dst %llx req->dst %p dlen %d sg_len %d\n" , dst_addr, req->dst, req->dlen,sg_dma_len (req->dst)); ret = iaa_compress(tfm, req, wq, src_addr, req->slen, dst_addr,
@@ -1550,8 +1563,8 @@ static int iaa_comp_acompress(struct acomp_req *req)if (ret)dev_dbg (dev,"asynchronous compress verification failed ret=%d\n" , ret); -dma_unmap_sg (dev, req->dst,sg_nents (req->dst),DMA_TO_DEVICE ); -dma_unmap_sg (dev, req->src,sg_nents (req->src),DMA_FROM_DEVICE ); +dma_unmap_sg (dev, req->dst,1 ,DMA_TO_DEVICE ); +dma_unmap_sg (dev, req->src,1 ,DMA_FROM_DEVICE ); goto out; }
@@ -1559,9 +1572,8 @@ static int iaa_comp_acompress(struct acomp_req *req)if (ret)dev_dbg (dev,"asynchronous compress 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 ); +dma_unmap_sg (dev, req->dst,1 ,DMA_FROM_DEVICE ); +dma_unmap_sg (dev, req->src,1 ,DMA_TO_DEVICE ); out:iaa_wq_put (wq);
@@ -1572,7 +1584,7 @@ static int iaa_comp_adecompress(struct acomp_req *req) {struct crypto_tfm *tfm = req->base.tfm;dma_addr_t src_addr, dst_addr; -int nr_sgs, cpu, ret =0 ; +int cpu, ret =0 ;struct iaa_wq *iaa_wq;struct device *dev;struct idxd_wq *wq;
@@ -1582,11 +1594,15 @@ static int iaa_comp_adecompress(struct acomp_req *req)return -ENODEV ; } -if (!req->src || !req->slen) { -pr_debug ("invalid src, not decompressing\n" ); +if (!req->src || !req->slen || !req->dst) { +pr_debug ("invalid req, not decompressing\n" );return -EINVAL ; } +/* Fall back to software if src or dst has multiple sg entries */ +if (sg_nents (req->src) >1 ||sg_nents (req->dst) >1 ) +return deflate_generic_decompress (req); + cpu =get_cpu (); wq =wq_table_next_wq (cpu);put_cpu ();
@@ -1605,30 +1621,25 @@ static int iaa_comp_adecompress(struct acomp_req *req) 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; +if (!dma_map_sg (dev, req->src,1 ,DMA_TO_DEVICE )) { +dev_dbg (dev,"couldn't map src sg for iaa device %d, wq %d\n" , + iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id); +iaa_wq_put (wq); +return deflate_generic_decompress (req); } 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, +dev_dbg (dev,"map src %llx req->src %p slen %d sg_len %d\n" , src_addr, req->src, req->slen,sg_dma_len (req->src)); - 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; +if (!dma_map_sg (dev, req->dst,1 ,DMA_FROM_DEVICE )) { +dev_dbg (dev,"couldn't map dst sg for iaa device %d, wq %d\n" , + iaa_wq->iaa_device->idxd->id, iaa_wq->wq->id); +dma_unmap_sg (dev, req->src,1 ,DMA_TO_DEVICE ); +iaa_wq_put (wq); +return deflate_generic_decompress (req); } 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, +dev_dbg (dev,"map dst %llx req->dst %p dlen %d sg_len %d\n" , dst_addr, req->dst, req->dlen,sg_dma_len (req->dst)); ret = iaa_decompress(tfm, req, wq, src_addr, req->slen,
@@ -1639,10 +1650,8 @@ static int iaa_comp_adecompress(struct acomp_req *req)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: +dma_unmap_sg (dev, req->dst,1 ,DMA_FROM_DEVICE ); +dma_unmap_sg (dev, req->src,1 ,DMA_TO_DEVICE );iaa_wq_put (wq);return ret;
drivers/crypto/intel/iaa/iaa_crypto_stats.c +9 -0
@@ -19,6 +19,7 @@static atomic64_t total_comp_calls;static atomic64_t total_decomp_calls; +static atomic64_t total_sw_comp_calls;static atomic64_t total_sw_decomp_calls;static atomic64_t total_comp_bytes_out;static atomic64_t total_decomp_bytes_in;
@@ -43,6 +44,11 @@ void update_total_decomp_calls(void)atomic64_inc (&total_decomp_calls); } +void update_total_sw_comp_calls (void ) +{ +atomic64_inc (&total_sw_comp_calls); +} +void update_total_sw_decomp_calls (void ) {atomic64_inc (&total_sw_decomp_calls);
@@ -104,6 +110,7 @@ static void reset_iaa_crypto_stats(void) {atomic64_set (&total_comp_calls,0 );atomic64_set (&total_decomp_calls,0 ); +atomic64_set (&total_sw_comp_calls,0 );atomic64_set (&total_sw_decomp_calls,0 );atomic64_set (&total_comp_bytes_out,0 );atomic64_set (&total_decomp_bytes_in,0 );
@@ -174,6 +181,8 @@ static int global_stats_show(struct seq_file *m, void *v) atomic64_read(&total_comp_calls));seq_printf (m," total_decomp_calls: %llu\n" ,atomic64_read (&total_decomp_calls)); +seq_printf (m," total_sw_comp_calls: %llu\n" , +atomic64_read (&total_sw_comp_calls));seq_printf (m," total_sw_decomp_calls: %llu\n" ,atomic64_read (&total_sw_decomp_calls)); seq_printf(m, " total_comp_bytes_out: %llu\n",
drivers/crypto/intel/iaa/iaa_crypto_stats.h +2 -0
@@ -11,6 +11,7 @@ void iaa_crypto_debugfs_cleanup(void);void update_total_comp_calls (void );void update_total_comp_bytes_out (int n);void update_total_decomp_calls (void ); +void update_total_sw_comp_calls (void );void update_total_sw_decomp_calls (void );void update_total_decomp_bytes_in (int n);void update_completion_einval_errs (void );
@@ -29,6 +30,7 @@ static inline void iaa_crypto_debugfs_cleanup(void) {}static inline void update_total_comp_calls (void ) {}static inline void update_total_comp_bytes_out (int n) {}static inline void update_total_decomp_calls (void ) {} +static inline void update_total_sw_comp_calls (void ) {}static inline void update_total_sw_decomp_calls (void ) {}static inline void update_total_decomp_bytes_in (int n) {}static inline void update_completion_einval_errs (void ) {}
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 crypto: iaa - unmap dst before software fallback on decompress
From: Vinicius Costa Gomes <[email protected]>
[ Upstream commit 94a25930477113730372e0fa2985da4c5ac95c9a ]
On a hardware analytics error, decompress retries through the software fallback, which writes req->dst with the CPU while it is still mapped DMA_FROM_DEVICE. With SWIOTLB active the later dma_unmap_sg() copies the stale bounce buffer over req->dst, corrupting the result.
Unmap before the fallback runs. The async path unmaps inline; the sync path signals the retry with -EAGAIN so iaa_comp_adecompress() runs the fallback after unmapping.
--- drivers/crypto/intel/iaa/iaa_crypto_main.c | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-)
drivers/crypto/intel/iaa/iaa_crypto_main.c +12 -15
@@ -1058,13 +1058,17 @@ static void iaa_desc_complete(struct idxd_desc *idxd_desc,pr_warn ("%s: falling back to deflate-generic decompress, " "analytics error code %x\n" , __func__, idxd_desc->iax_completion->error_code); +dma_unmap_sg (dev, ctx->req->dst,sg_nents (ctx->req->dst), +DMA_FROM_DEVICE ); +dma_unmap_sg (dev, ctx->req->src,1 ,DMA_TO_DEVICE ); + ret =deflate_generic_decompress (ctx->req);if (ret) {dev_dbg (dev,"%s: deflate-generic failed ret=%d\n" , __func__, ret); err = -EIO ; - goto err; } + goto out; }else { err = -EIO ; goto err;
@@ -1447,19 +1451,9 @@ static int iaa_decompress(struct crypto_tfm *tfm, struct acomp_req *req, ret =check_completion (dev, idxd_desc->iax_completion, false, false);if (ret) {dev_dbg (dev,"%s: check_completion failed ret=%d\n" , __func__, ret); -if (idxd_desc->iax_completion->status ==IAA_ANALYTICS_ERROR ) { -pr_warn ("%s: falling back to deflate-generic decompress, " -"analytics error code %x\n" , __func__, - idxd_desc->iax_completion->error_code); - ret =deflate_generic_decompress (req); -if (ret) { -dev_dbg (dev,"%s: deflate-generic failed ret=%d\n" , - __func__, ret); - goto err; - } - }else { - goto err; - } +if (idxd_desc->iax_completion->status ==IAA_ANALYTICS_ERROR ) + ret = -EAGAIN ; + goto err; }else { req->dlen = idxd_desc->iax_completion->output_size; }
@@ -1647,13 +1641,16 @@ static int iaa_comp_adecompress(struct acomp_req *req)if (ret == -EINPROGRESS )return ret; -if (ret !=0 ) +if (ret !=0 && ret != -EAGAIN )dev_dbg (dev,"asynchronous decompress failed ret=%d\n" , ret);dma_unmap_sg (dev, req->dst,1 ,DMA_FROM_DEVICE );dma_unmap_sg (dev, req->src,1 ,DMA_TO_DEVICE );iaa_wq_put (wq); +if (ret == -EAGAIN ) + ret =deflate_generic_decompress (req); +return ret; }
Signature · 1 line
2.53.0