From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: Takshak Chahande <ctakshak@fb.com>
Cc: <netdev@vger.kernel.org>, <ast@kernel.org>,
<daniel@iogearbox.net>, <rdna@fb.com>, <kernel-team@fb.com>,
<hechaol@fb.com>
Subject: Re: [PATCH bpf v2] libbpf : make libbpf_num_possible_cpus function thread safe
Date: Wed, 31 Jul 2019 15:31:48 -0700 [thread overview]
Message-ID: <20190731153148.2e8bc1a7@cakuba.netronome.com> (raw)
In-Reply-To: <20190731221055.1478201-1-ctakshak@fb.com>
On Wed, 31 Jul 2019 15:10:55 -0700, Takshak Chahande wrote:
> Having static variable `cpus` in libbpf_num_possible_cpus function
> without guarding it with mutex makes this function thread-unsafe.
>
> If multiple threads accessing this function, in the current form; it
> leads to incrementing the static variable value `cpus` in the multiple
> of total available CPUs.
>
> Used local stack variable to calculate the number of possible CPUs and
> then updated the static variable using WRITE_ONCE().
>
> Changes since v1:
> * added stack variable to calculate cpus
> * serialized static variable update using WRITE_ONCE()
> * fixed Fixes tag
>
> Fixes: 6446b3155521 ("bpf: add a new API libbpf_num_possible_cpus()")
> Signed-off-by: Takshak Chahande <ctakshak@fb.com>
Perhaps we would have a little less code churn if the static variable
was renamed (e.g. to saved_cpus), but functionally looks good, so:
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
(FWIW I think Andrey's comment does not apply to the networking and BPF
trees so if you respin please keep the changelog in the commit message.)
next prev parent reply other threads:[~2019-07-31 22:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 22:10 [PATCH bpf v2] libbpf : make libbpf_num_possible_cpus function thread safe Takshak Chahande
2019-07-31 22:17 ` [Potential Spoof] " Andrey Ignatov
2019-07-31 22:31 ` Jakub Kicinski [this message]
2019-08-01 3:40 ` Alexei Starovoitov
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=20190731153148.2e8bc1a7@cakuba.netronome.com \
--to=jakub.kicinski@netronome.com \
--cc=ast@kernel.org \
--cc=ctakshak@fb.com \
--cc=daniel@iogearbox.net \
--cc=hechaol@fb.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=rdna@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