[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190731153148.2e8bc1a7@cakuba.netronome.com>
Date: Wed, 31 Jul 2019 15:31:48 -0700
From: Jakub Kicinski <jakub.kicinski@...ronome.com>
To: Takshak Chahande <ctakshak@...com>
Cc: <netdev@...r.kernel.org>, <ast@...nel.org>, <daniel@...earbox.net>,
<rdna@...com>, <kernel-team@...com>, <hechaol@...com>
Subject: Re: [PATCH bpf v2] libbpf : make libbpf_num_possible_cpus function
thread safe
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@...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@...ronome.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.)
Powered by blists - more mailing lists