DPDK patches and discussions
 help / color / mirror / Atom feed
From: Feifei Wang <Feifei.Wang2@arm.com>
To: "Dybkowski, AdamX" <adamx.dybkowski@intel.com>,
	"Griffin, John" <john.griffin@intel.com>,
	"Trahe, Fiona" <fiona.trahe@intel.com>,
	"Jain, Deepak K" <deepak.k.jain@intel.com>,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>,
	Herbert Guan <Herbert.Guan@arm.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>,
	nd <nd@arm.com>, "stable@dpdk.org" <stable@dpdk.org>,
	Ruifeng Wang <Ruifeng.Wang@arm.com>, nd <nd@arm.com>
Subject: [dpdk-dev] 回复:  [PATCH v3] crypto/qat: fix uninitilized compiler warning
Date: Thu, 20 May 2021 05:47:17 +0000
Message-ID: <DB9PR08MB69233C07B72BBF2DC8E5EEA4C82A9@DB9PR08MB6923.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <SN6PR11MB2575E387B04CD78F50CD0314ED2B9@SN6PR11MB2575.namprd11.prod.outlook.com>

Hi, 

> -----邮件原件-----
> 发件人: Dybkowski, AdamX <adamx.dybkowski@intel.com>
> 发送时间: 2021年5月19日 21:17
> 收件人: Feifei Wang <Feifei.Wang2@arm.com>; Griffin, John
> <john.griffin@intel.com>; Trahe, Fiona <fiona.trahe@intel.com>; Jain,
> Deepak K <deepak.k.jain@intel.com>; Jerin Jacob
> <jerin.jacob@caviumnetworks.com>; Herbert Guan
> <Herbert.Guan@arm.com>
> 抄送: dev@dpdk.org; david.marchand@redhat.com; nd <nd@arm.com>;
> stable@dpdk.org; Ruifeng Wang <Ruifeng.Wang@arm.com>
> 主题: RE: [dpdk-dev] [PATCH v3] crypto/qat: fix uninitilized compiler warning
> 
> Hi.
> 
> I checked how it works on QAT hardware, and it does no harm. All unit tests
> still pass.
> Verified on two QAT-enabled machines.
Thanks very much for your testing.
> 
> The question is: should this patch be simplified to just add a call to memset
> (to zero the digest variable while still keeping it on the stack) at the function
> begin? And that will be a faster solution in run-time (using the variable on the
> stack instead of calloc that uses the heap).
> 
A good comment for this. I try to apply it and it also can solve the warning.
And actually maybe memset is more faster.
I will update this in the next version.

Best Regards
Feifei

> Adam
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of Feifei Wang
> > Sent: Monday, 17 May, 2021 11:07
> > To: Griffin, John <john.griffin@intel.com>; Trahe, Fiona
> > <fiona.trahe@intel.com>; Jain, Deepak K <deepak.k.jain@intel.com>;
> > Jerin Jacob <jerin.jacob@caviumnetworks.com>; Herbert Guan
> > <herbert.guan@arm.com>
> > Cc: dev@dpdk.org; david.marchand@redhat.com; nd@arm.com; Feifei
> Wang
> > <feifei.wang2@arm.com>; stable@dpdk.org; Ruifeng Wang
> > <ruifeng.wang@arm.com>
> > Subject: [dpdk-dev] [PATCH v3] crypto/qat: fix uninitilized compiler
> > warning
> >
> > In Arm platform, when "RTE_ARCH_ARM64_MEMCPY" is set as true,
> compiler
> > will report variable uninitilized warning:
> >
> > ../drivers/crypto/qat/qat_sym_session.c:
> > In function ‘partial_hash_compute’:
> > ../lib/eal/include/generic/rte_byteorder.h:241:24: warning:
> > ‘<U35a0>’ may be used uninitialized in this function
> > 	[-Wmaybe-uninitialized]
> > 	241 | #define rte_bswap32(x) __builtin_bswap32(x)
> > 	...
> >
> > This is because "digest" will be initialized by "rte_memcpy" function
> > rather than "memcpy" if "RTE_ARCH_ARM64_MEMCPY" is set as true.
> > However, compiler cannot know it is initialized by the function.
> >
> > To fix this, use "calloc" to initialize "digest".
> >
> > Fixes: cd7fc8a84b48 ("eal/arm64: optimize memcpy")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
> > Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> > ---
> > v2: add check and free for memory dynamic allocation (David Marchand)
> > v3: fix compiler error
> >
> >  drivers/crypto/qat/qat_sym_session.c | 27 ++++++++++++++++++---------
> >  1 file changed, 18 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/crypto/qat/qat_sym_session.c
> > b/drivers/crypto/qat/qat_sym_session.c
> > index 231b1640da..105a10957a 100644
> > --- a/drivers/crypto/qat/qat_sym_session.c
> > +++ b/drivers/crypto/qat/qat_sym_session.c
> > @@ -1190,8 +1190,7 @@ static int partial_hash_compute(enum
> > icp_qat_hw_auth_algo hash_alg,
> >  			uint8_t *data_out)
> >  {
> >  	int digest_size;
> > -	uint8_t digest[qat_hash_get_digest_size(
> > -			ICP_QAT_HW_AUTH_ALGO_DELIMITER)];
> > +	uint8_t *digest;
> >  	uint32_t *hash_state_out_be32;
> >  	uint64_t *hash_state_out_be64;
> >  	int i;
> > @@ -1200,55 +1199,65 @@ static int partial_hash_compute(enum
> > icp_qat_hw_auth_algo hash_alg,
> >  	if (digest_size <= 0)
> >  		return -EFAULT;
> >
> > +	digest = calloc(qat_hash_get_digest_size(
> > +				ICP_QAT_HW_AUTH_ALGO_DELIMITER),
> > sizeof(uint8_t));
> > +	if (!digest)
> > +		return -ENOMEM;
> > +
> >  	hash_state_out_be32 = (uint32_t *)data_out;
> >  	hash_state_out_be64 = (uint64_t *)data_out;
> >
> >  	switch (hash_alg) {
> >  	case ICP_QAT_HW_AUTH_ALGO_SHA1:
> >  		if (partial_hash_sha1(data_in, digest))
> > -			return -EFAULT;
> > +			goto fail;
> >  		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
> >  			*hash_state_out_be32 =
> >  				rte_bswap32(*(((uint32_t *)digest)+i));
> >  		break;
> >  	case ICP_QAT_HW_AUTH_ALGO_SHA224:
> >  		if (partial_hash_sha224(data_in, digest))
> > -			return -EFAULT;
> > +			goto fail;
> >  		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
> >  			*hash_state_out_be32 =
> >  				rte_bswap32(*(((uint32_t *)digest)+i));
> >  		break;
> >  	case ICP_QAT_HW_AUTH_ALGO_SHA256:
> >  		if (partial_hash_sha256(data_in, digest))
> > -			return -EFAULT;
> > +			goto fail;
> >  		for (i = 0; i < digest_size >> 2; i++, hash_state_out_be32++)
> >  			*hash_state_out_be32 =
> >  				rte_bswap32(*(((uint32_t *)digest)+i));
> >  		break;
> >  	case ICP_QAT_HW_AUTH_ALGO_SHA384:
> >  		if (partial_hash_sha384(data_in, digest))
> > -			return -EFAULT;
> > +			goto fail;
> >  		for (i = 0; i < digest_size >> 3; i++, hash_state_out_be64++)
> >  			*hash_state_out_be64 =
> >  				rte_bswap64(*(((uint64_t *)digest)+i));
> >  		break;
> >  	case ICP_QAT_HW_AUTH_ALGO_SHA512:
> >  		if (partial_hash_sha512(data_in, digest))
> > -			return -EFAULT;
> > +			goto fail;
> >  		for (i = 0; i < digest_size >> 3; i++, hash_state_out_be64++)
> >  			*hash_state_out_be64 =
> >  				rte_bswap64(*(((uint64_t *)digest)+i));
> >  		break;
> >  	case ICP_QAT_HW_AUTH_ALGO_MD5:
> >  		if (partial_hash_md5(data_in, data_out))
> > -			return -EFAULT;
> > +			goto fail;
> >  		break;
> >  	default:
> >  		QAT_LOG(ERR, "invalid hash alg %u", hash_alg);
> > -		return -EFAULT;
> > +		goto fail;
> >  	}
> >
> > +	free(digest);
> >  	return 0;
> > +
> > +fail:
> > +	free(digest);
> > +	return -EFAULT;
> >  }
> >  #define HMAC_IPAD_VALUE	0x36
> >  #define HMAC_OPAD_VALUE	0x5c
> > --
> > 2.25.1


  reply	other threads:[~2021-05-20  5:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14  7:41 [dpdk-dev] [PATCH] " Feifei Wang
2021-05-14  7:49 ` [dpdk-dev] [dpdk-stable] " David Marchand
2021-05-14  8:01   ` [dpdk-dev] 回复: " Feifei Wang
2021-05-14  8:13     ` [dpdk-dev] " David Marchand
2021-05-14  8:30       ` [dpdk-dev] 回复: " Feifei Wang
2021-05-17  9:07 ` [dpdk-dev] [PATCH v3] " Feifei Wang
2021-05-19  7:56   ` [dpdk-dev] [dpdk-stable] " Thomas Monjalon
2021-05-19  8:11   ` Ferruh Yigit
2021-05-20  5:44     ` [dpdk-dev] 回复: " Feifei Wang
2021-05-20  8:08       ` Ferruh Yigit
2021-05-19 13:13   ` [dpdk-dev] " Dybkowski, AdamX
2021-05-19 13:16   ` Dybkowski, AdamX
2021-05-20  5:47     ` Feifei Wang [this message]
2021-05-20  8:43 ` [dpdk-dev] [PATCH v4] crypto/qat: fix uninitilized gcc " Feifei Wang
2021-05-20  9:06   ` Dybkowski, AdamX
2021-05-21  2:00 ` [dpdk-dev] [PATCH v5] crypto/qat: fix uninitialized " Feifei Wang
2021-06-29 20:04   ` [dpdk-dev] [EXT] " Akhil Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB9PR08MB69233C07B72BBF2DC8E5EEA4C82A9@DB9PR08MB6923.eurprd08.prod.outlook.com \
    --to=feifei.wang2@arm.com \
    --cc=Herbert.Guan@arm.com \
    --cc=Ruifeng.Wang@arm.com \
    --cc=adamx.dybkowski@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=deepak.k.jain@intel.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@intel.com \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=john.griffin@intel.com \
    --cc=nd@arm.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git