2020-06-01 16:13:39

by Mikulas Patocka

[permalink] [raw]
Subject: [PATCH 3/4] qat: use GFP_KERNEL allocations

Use GFP_KERNEL when the flag CRYPTO_TFM_REQ_MAY_SLEEP is present.
Also, use GFP_KERNEL when setting a key.

Signed-off-by: Mikulas Patocka <[email protected]>
Cc: [email protected]

Index: linux-2.6/drivers/crypto/qat/qat_common/qat_algs.c
===================================================================
--- linux-2.6.orig/drivers/crypto/qat/qat_common/qat_algs.c
+++ linux-2.6/drivers/crypto/qat/qat_common/qat_algs.c
@@ -134,6 +134,11 @@ struct qat_alg_skcipher_ctx {
struct crypto_skcipher *tfm;
};

+static int qat_gfp(u32 flags)
+{
+ return flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
+}
+
static int qat_get_inter_state_size(enum icp_qat_hw_auth_algo qat_hash_alg)
{
switch (qat_hash_alg) {
@@ -622,14 +627,14 @@ static int qat_alg_aead_newkey(struct cr
ctx->inst = inst;
ctx->enc_cd = dma_alloc_coherent(dev, sizeof(*ctx->enc_cd),
&ctx->enc_cd_paddr,
- GFP_ATOMIC);
+ GFP_KERNEL);
if (!ctx->enc_cd) {
ret = -ENOMEM;
goto out_free_inst;
}
ctx->dec_cd = dma_alloc_coherent(dev, sizeof(*ctx->dec_cd),
&ctx->dec_cd_paddr,
- GFP_ATOMIC);
+ GFP_KERNEL);
if (!ctx->dec_cd) {
ret = -ENOMEM;
goto out_free_enc;
@@ -704,7 +709,8 @@ static void qat_alg_free_bufl(struct qat
static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst,
struct scatterlist *sgl,
struct scatterlist *sglout,
- struct qat_crypto_request *qat_req)
+ struct qat_crypto_request *qat_req,
+ int gfp)
{
struct device *dev = &GET_DEV(inst->accel_dev);
int i, sg_nctr = 0;
@@ -719,7 +725,7 @@ static int qat_alg_sgl_to_bufl(struct qa
if (unlikely(!n))
return -EINVAL;

- bufl = kzalloc_node(sz, GFP_ATOMIC,
+ bufl = kzalloc_node(sz, gfp,
dev_to_node(&GET_DEV(inst->accel_dev)));
if (unlikely(!bufl))
return -ENOMEM;
@@ -753,7 +759,7 @@ static int qat_alg_sgl_to_bufl(struct qa
n = sg_nents(sglout);
sz_out = struct_size(buflout, bufers, n + 1);
sg_nctr = 0;
- buflout = kzalloc_node(sz_out, GFP_ATOMIC,
+ buflout = kzalloc_node(sz_out, gfp,
dev_to_node(&GET_DEV(inst->accel_dev)));
if (unlikely(!buflout))
goto err_in;
@@ -876,7 +882,7 @@ static int qat_alg_aead_dec(struct aead_
int digst_size = crypto_aead_authsize(aead_tfm);
int ret, backed_off;

- ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
+ ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req, qat_gfp(areq->base.flags));
if (unlikely(ret))
return ret;

@@ -919,7 +925,7 @@ static int qat_alg_aead_enc(struct aead_
uint8_t *iv = areq->iv;
int ret, backed_off;

- ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req);
+ ret = qat_alg_sgl_to_bufl(ctx->inst, areq->src, areq->dst, qat_req, qat_gfp(areq->base.flags));
if (unlikely(ret))
return ret;

@@ -980,14 +986,14 @@ static int qat_alg_skcipher_newkey(struc
ctx->inst = inst;
ctx->enc_cd = dma_alloc_coherent(dev, sizeof(*ctx->enc_cd),
&ctx->enc_cd_paddr,
- GFP_ATOMIC);
+ GFP_KERNEL);
if (!ctx->enc_cd) {
ret = -ENOMEM;
goto out_free_instance;
}
ctx->dec_cd = dma_alloc_coherent(dev, sizeof(*ctx->dec_cd),
&ctx->dec_cd_paddr,
- GFP_ATOMIC);
+ GFP_KERNEL);
if (!ctx->dec_cd) {
ret = -ENOMEM;
goto out_free_enc;
@@ -1063,11 +1069,11 @@ static int qat_alg_skcipher_encrypt(stru
return 0;

qat_req->iv = dma_alloc_coherent(dev, AES_BLOCK_SIZE,
- &qat_req->iv_paddr, GFP_ATOMIC);
+ &qat_req->iv_paddr, qat_gfp(req->base.flags));
if (!qat_req->iv)
return -ENOMEM;

- ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req);
+ ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req, qat_gfp(req->base.flags));
if (unlikely(ret)) {
dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv,
qat_req->iv_paddr);
@@ -1122,11 +1128,11 @@ static int qat_alg_skcipher_decrypt(stru
return 0;

qat_req->iv = dma_alloc_coherent(dev, AES_BLOCK_SIZE,
- &qat_req->iv_paddr, GFP_ATOMIC);
+ &qat_req->iv_paddr, qat_gfp(req->base.flags));
if (!qat_req->iv)
return -ENOMEM;

- ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req);
+ ret = qat_alg_sgl_to_bufl(ctx->inst, req->src, req->dst, qat_req, qat_gfp(req->base.flags));
if (unlikely(ret)) {
dma_free_coherent(dev, AES_BLOCK_SIZE, qat_req->iv,
qat_req->iv_paddr);


2020-06-03 13:46:22

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 3/4] qat: use GFP_KERNEL allocations

Hi Mikulas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on cryptodev/master]
[also build test WARNING on crypto/master dm/for-next v5.7 next-20200603]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Mikulas-Patocka/Intel-QAT-fixes/20200602-001343
base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
config: x86_64-randconfig-s021-20200603 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-13) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-244-g0ee050a8-dirty
# save the attached .config to linux build tree
make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)

>> drivers/crypto/qat/qat_common/qat_algs.c:139:49: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted gfp_t @@
>> drivers/crypto/qat/qat_common/qat_algs.c:139:49: sparse: expected int
>> drivers/crypto/qat/qat_common/qat_algs.c:139:49: sparse: got restricted gfp_t
>> drivers/crypto/qat/qat_common/qat_algs.c:728:33: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted gfp_t [usertype] flags @@ got int gfp @@
>> drivers/crypto/qat/qat_common/qat_algs.c:728:33: sparse: expected restricted gfp_t [usertype] flags
>> drivers/crypto/qat/qat_common/qat_algs.c:728:33: sparse: got int gfp
drivers/crypto/qat/qat_common/qat_algs.c:762:48: sparse: sparse: incorrect type in argument 2 (different base types) @@ expected restricted gfp_t [usertype] flags @@ got int gfp @@
drivers/crypto/qat/qat_common/qat_algs.c:762:48: sparse: expected restricted gfp_t [usertype] flags
drivers/crypto/qat/qat_common/qat_algs.c:762:48: sparse: got int gfp
>> drivers/crypto/qat/qat_common/qat_algs.c:1072:69: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected restricted gfp_t [usertype] gfp @@ got int @@
>> drivers/crypto/qat/qat_common/qat_algs.c:1072:69: sparse: expected restricted gfp_t [usertype] gfp
>> drivers/crypto/qat/qat_common/qat_algs.c:1072:69: sparse: got int
drivers/crypto/qat/qat_common/qat_algs.c:1131:69: sparse: sparse: incorrect type in argument 4 (different base types) @@ expected restricted gfp_t [usertype] gfp @@ got int @@
drivers/crypto/qat/qat_common/qat_algs.c:1131:69: sparse: expected restricted gfp_t [usertype] gfp
drivers/crypto/qat/qat_common/qat_algs.c:1131:69: sparse: got int

vim +139 drivers/crypto/qat/qat_common/qat_algs.c

136
137 static int qat_gfp(u32 flags)
138 {
> 139 return flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC;
140 }
141

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (3.21 kB)
.config.gz (37.18 kB)
Download all attachments