netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: He Fengqing <hefengqing@huawei.com>,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	kafai@fb.com
Cc: songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: RE: [bpf-next] bpf: Fix possible race in inc_misses_counter
Date: Tue, 25 Jan 2022 11:55:16 -0800	[thread overview]
Message-ID: <61f055a4b6451_2e4c520871@john.notmuch> (raw)
In-Reply-To: <20220122102936.1219518-1-hefengqing@huawei.com>

He Fengqing wrote:
> It seems inc_misses_counter() suffers from same issue fixed in
> the commit d979617aa84d ("bpf: Fixes possible race in update_prog_stats()
> for 32bit arches"):
> As it can run while interrupts are enabled, it could
> be re-entered and the u64_stats syncp could be mangled.
> 
> Fixes: 9ed9e9ba2337 ("bpf: Count the number of times recursion was prevented")
> Signed-off-by: He Fengqing <hefengqing@huawei.com>
> ---
>  kernel/bpf/trampoline.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Appears possible through sleepable progs.

Acked-by: John Fastabend <john.fastabend@gmail.com>

> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 4b6974a195c1..5e7edf913060 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -550,11 +550,12 @@ static __always_inline u64 notrace bpf_prog_start_time(void)
>  static void notrace inc_misses_counter(struct bpf_prog *prog)
>  {
>  	struct bpf_prog_stats *stats;
> +	unsigned int flags;
>  
>  	stats = this_cpu_ptr(prog->stats);
> -	u64_stats_update_begin(&stats->syncp);
> +	flags = u64_stats_update_begin_irqsave(&stats->syncp);
>  	u64_stats_inc(&stats->misses);
> -	u64_stats_update_end(&stats->syncp);
> +	u64_stats_update_end_irqrestore(&stats->syncp, flags);
>  }
>  
>  /* The logic is similar to bpf_prog_run(), but with an explicit
> -- 
> 2.25.1
> 



      reply	other threads:[~2022-01-25 19:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-22 10:29 [bpf-next] bpf: Fix possible race in inc_misses_counter He Fengqing
2022-01-25 19:55 ` John Fastabend [this message]

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=61f055a4b6451_2e4c520871@john.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hefengqing@huawei.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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).