DPDK patches and discussions
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas@monjalon.net>
To: Bing Zhao <bingz@nvidia.com>
Cc: ferruh.yigit@intel.com, andrew.rybchenko@oktetlabs.ru,
	dev@dpdk.org, konstantin.ananyev@intel.com
Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: fix the race condition for fp ops reset
Date: Sat, 23 Oct 2021 10:34:49 +0200	[thread overview]
Message-ID: <3885639.MmVk1qbWW8@thomas> (raw)
In-Reply-To: <20211022211407.315068-2-bingz@nvidia.com>

22/10/2021 23:14, Bing Zhao:
> In the function "eth_dev_fp_ops_reset", a structure assignment
> operation is used to reset one queue's callback functions, etc., but
> it is not thread safe.
> 
> The structure assignment is not atomic, a lot of instructions will
> be generated. Right now, since not all the fields are needed, the
> fields in the "dummy_ops" which is not set explicitly will be 0s
> based on the specification and compiler behavior. In order to make
> "fpo" has the same content with "dummy_ops", some clearing to 0
> operation is needed.
> 
> By checking the object instructions (e.g. with GCC 4.8.5)
>    0x0000000000a58317 <+35>:	mov    %rsi,%rdi
>    0x0000000000a5831a <+38>:	mov    %rdx,%rcx
> => 0x0000000000a5831d <+41>:	rep stos %rax,%es:(%rdi)
>    0x0000000000a58320 <+44>:	mov    -0x38(%rsp),%rax
>    0x0000000000a58325 <+49>:	lea    -0xe0(%rip),%rdx
>         // # 0xa5824c <dummy_eth_rx_burst>
> 
> It shows that "rep stos" will clear the "fpo" structure before
> assigning new values.
> 
> In the other thread, if some data path Tx / Rx functions are still
> running, there is a risk to get 0 instead of the correct dummy
> content.
>   1. qd = p->rxq.data[queue_id]
>   2. (void **)&p->rxq.clbk[queue_id]
> "data" and "clbk" may be observed with NULL (0) in other threads.
> Even it is temporary, the accessing to a NULL pointer will cause a
> crash. Using "memcpy" could get rid of this.
> 
> Fixes: c87d435a4d79 ("ethdev: copy fast-path API into separate structure")
> Cc: konstantin.ananyev@intel.com
> 
> Signed-off-by: Bing Zhao <bingz@nvidia.com>
> ---
> --- a/lib/ethdev/ethdev_private.c
> +++ b/lib/ethdev/ethdev_private.c
> @@ -206,7 +206,7 @@ eth_dev_fp_ops_reset(struct rte_eth_fp_ops *fpo)
>  		.txq = {.data = dummy_data, .clbk = dummy_data,},
>  	};
>  
> -	*fpo = dummy_ops;
> +	rte_memcpy(fpo, &dummy_ops, sizeof(struct rte_eth_fp_ops));

That's not trivial.
Please add a comment to briefly explain that memcpy avoids zeroing of a simple assignment.




  reply	other threads:[~2021-10-23  8:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 21:14 [dpdk-dev] [PATCH 1/2] ethdev: fix log level of Tx and Rx dummy functions Bing Zhao
2021-10-22 21:14 ` [dpdk-dev] [PATCH 2/2] ethdev: fix the race condition for fp ops reset Bing Zhao
2021-10-23  8:34   ` Thomas Monjalon [this message]
2021-10-23 11:39     ` Ananyev, Konstantin
2021-11-10 14:34       ` Ferruh Yigit
2021-11-10 14:37         ` Ananyev, Konstantin
2021-11-10 14:57           ` Thomas Monjalon
2021-11-10 15:24             ` Bing Zhao
2021-10-23 16:13   ` [dpdk-dev] " Stephen Hemminger
2021-10-24  5:54     ` Bing Zhao
2021-10-23  8:32 ` [dpdk-dev] [PATCH 1/2] ethdev: fix log level of Tx and Rx dummy functions Thomas Monjalon
2021-10-23 11:46   ` Ananyev, Konstantin
2021-10-23 12:45     ` Bing Zhao
2021-10-24 11:48       ` Ananyev, Konstantin
2021-10-25  9:43         ` Thomas Monjalon
2021-10-25  9:51           ` David Marchand
2021-10-25 12:55             ` Ananyev, Konstantin
2021-10-25 13:27               ` Thomas Monjalon
2021-10-25 13:31                 ` David Marchand
2021-10-25 20:29                   ` Ananyev, Konstantin
2021-10-25 20:38                     ` Thomas Monjalon
2021-10-26 12:38                       ` Ananyev, Konstantin
2021-10-26 12:59                         ` Thomas Monjalon
2021-10-26  3:18                   ` Bing Zhao
2021-10-23 12:12   ` Bing Zhao

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=3885639.MmVk1qbWW8@thomas \
    --to=thomas@monjalon.net \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=bingz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=konstantin.ananyev@intel.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).