Skip to content

Commit add92a8

Browse files
Harsh Jainherbertx
authored andcommitted
crypto: chelsio - Fix memory corruption in DMA Mapped buffers.
Update PCI Id in "cpl_rx_phys_dsgl" header. In case pci_chan_id and tx_chan_id are not derived from same queue, H/W can send request completion indication before completing DMA Transfer. Herbert, It would be good if fix can be merge to stable tree. For 4.14 kernel, It requires some update to avoid mege conficts. Cc: <stable@vger.kernel.org> Signed-off-by: Harsh Jain <harsh@chelsio.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 13cc6f4 commit add92a8

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

drivers/crypto/chelsio/chcr_algo.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ static inline void dsgl_walk_init(struct dsgl_walk *walk,
367367
walk->to = (struct phys_sge_pairs *)(dsgl + 1);
368368
}
369369

370-
static inline void dsgl_walk_end(struct dsgl_walk *walk, unsigned short qid)
370+
static inline void dsgl_walk_end(struct dsgl_walk *walk, unsigned short qid,
371+
int pci_chan_id)
371372
{
372373
struct cpl_rx_phys_dsgl *phys_cpl;
373374

@@ -385,6 +386,7 @@ static inline void dsgl_walk_end(struct dsgl_walk *walk, unsigned short qid)
385386
phys_cpl->rss_hdr_int.opcode = CPL_RX_PHYS_ADDR;
386387
phys_cpl->rss_hdr_int.qid = htons(qid);
387388
phys_cpl->rss_hdr_int.hash_val = 0;
389+
phys_cpl->rss_hdr_int.channel = pci_chan_id;
388390
}
389391

390392
static inline void dsgl_walk_add_page(struct dsgl_walk *walk,
@@ -718,7 +720,7 @@ static inline void create_wreq(struct chcr_context *ctx,
718720
FILL_WR_RX_Q_ID(ctx->dev->rx_channel_id, qid,
719721
!!lcb, ctx->tx_qidx);
720722

721-
chcr_req->ulptx.cmd_dest = FILL_ULPTX_CMD_DEST(ctx->dev->tx_channel_id,
723+
chcr_req->ulptx.cmd_dest = FILL_ULPTX_CMD_DEST(ctx->tx_chan_id,
722724
qid);
723725
chcr_req->ulptx.len = htonl((DIV_ROUND_UP(len16, 16) -
724726
((sizeof(chcr_req->wreq)) >> 4)));
@@ -1339,16 +1341,23 @@ static int chcr_device_init(struct chcr_context *ctx)
13391341
adap->vres.ncrypto_fc);
13401342
rxq_perchan = u_ctx->lldi.nrxq / u_ctx->lldi.nchan;
13411343
txq_perchan = ntxq / u_ctx->lldi.nchan;
1342-
rxq_idx = ctx->dev->tx_channel_id * rxq_perchan;
1343-
rxq_idx += id % rxq_perchan;
1344-
txq_idx = ctx->dev->tx_channel_id * txq_perchan;
1345-
txq_idx += id % txq_perchan;
13461344
spin_lock(&ctx->dev->lock_chcr_dev);
1347-
ctx->rx_qidx = rxq_idx;
1348-
ctx->tx_qidx = txq_idx;
1345+
ctx->tx_chan_id = ctx->dev->tx_channel_id;
13491346
ctx->dev->tx_channel_id = !ctx->dev->tx_channel_id;
13501347
ctx->dev->rx_channel_id = 0;
13511348
spin_unlock(&ctx->dev->lock_chcr_dev);
1349+
rxq_idx = ctx->tx_chan_id * rxq_perchan;
1350+
rxq_idx += id % rxq_perchan;
1351+
txq_idx = ctx->tx_chan_id * txq_perchan;
1352+
txq_idx += id % txq_perchan;
1353+
ctx->rx_qidx = rxq_idx;
1354+
ctx->tx_qidx = txq_idx;
1355+
/* Channel Id used by SGE to forward packet to Host.
1356+
* Same value should be used in cpl_fw6_pld RSS_CH field
1357+
* by FW. Driver programs PCI channel ID to be used in fw
1358+
* at the time of queue allocation with value "pi->tx_chan"
1359+
*/
1360+
ctx->pci_chan_id = txq_idx / txq_perchan;
13521361
}
13531362
out:
13541363
return err;
@@ -2503,6 +2512,7 @@ void chcr_add_aead_dst_ent(struct aead_request *req,
25032512
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
25042513
struct dsgl_walk dsgl_walk;
25052514
unsigned int authsize = crypto_aead_authsize(tfm);
2515+
struct chcr_context *ctx = a_ctx(tfm);
25062516
u32 temp;
25072517

25082518
dsgl_walk_init(&dsgl_walk, phys_cpl);
@@ -2512,7 +2522,7 @@ void chcr_add_aead_dst_ent(struct aead_request *req,
25122522
dsgl_walk_add_page(&dsgl_walk, IV, &reqctx->iv_dma);
25132523
temp = req->cryptlen + (reqctx->op ? -authsize : authsize);
25142524
dsgl_walk_add_sg(&dsgl_walk, req->dst, temp, req->assoclen);
2515-
dsgl_walk_end(&dsgl_walk, qid);
2525+
dsgl_walk_end(&dsgl_walk, qid, ctx->pci_chan_id);
25162526
}
25172527

25182528
void chcr_add_cipher_src_ent(struct ablkcipher_request *req,
@@ -2544,6 +2554,8 @@ void chcr_add_cipher_dst_ent(struct ablkcipher_request *req,
25442554
unsigned short qid)
25452555
{
25462556
struct chcr_blkcipher_req_ctx *reqctx = ablkcipher_request_ctx(req);
2557+
struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(wrparam->req);
2558+
struct chcr_context *ctx = c_ctx(tfm);
25472559
struct dsgl_walk dsgl_walk;
25482560

25492561
dsgl_walk_init(&dsgl_walk, phys_cpl);
@@ -2552,7 +2564,7 @@ void chcr_add_cipher_dst_ent(struct ablkcipher_request *req,
25522564
reqctx->dstsg = dsgl_walk.last_sg;
25532565
reqctx->dst_ofst = dsgl_walk.last_sg_len;
25542566

2555-
dsgl_walk_end(&dsgl_walk, qid);
2567+
dsgl_walk_end(&dsgl_walk, qid, ctx->pci_chan_id);
25562568
}
25572569

25582570
void chcr_add_hash_src_ent(struct ahash_request *req,

drivers/crypto/chelsio/chcr_crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ struct chcr_context {
255255
struct chcr_dev *dev;
256256
unsigned char tx_qidx;
257257
unsigned char rx_qidx;
258+
unsigned char tx_chan_id;
259+
unsigned char pci_chan_id;
258260
struct __crypto_ctx crypto_ctx[0];
259261
};
260262

0 commit comments

Comments
 (0)