[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y1ZYCD1LjC5OhWsq@leoy-huanghe.lan>
Date: Mon, 24 Oct 2022 17:16:56 +0800
From: Leo Yan <leo.yan@...aro.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Greg Thelen <gthelen@...gle.com>,
Anand K Mistry <amistry@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH v1] perf record: Fix event fd races
On Sun, Oct 23, 2022 at 10:33:30PM -0700, Ian Rogers wrote:
[...]
> > > +static volatile int done_fd = -1;
> >
> > Here is a bit suspecious for adding volatile qualifier. See the
> > document: process/volatile-considered-harmful.rst.
> >
> > I know the document is mainly for kernel programming, but seems to me
> > it's also valid for C programming in userspace.
> >
> > I not sure what's the purpose for adding volatile for done_fd, if we
> > really have concern for reading any stale value for done_fd, should we
> > use WRITE_ONCE/READ_ONCE?
>
> We could just switch to C11 and stdatomic. The volatile is consistent
> with the code above and more consistent with the expectation of
> writing to a variable that is read in a signal handler.
Thanks for the info for C11 and stdatomic.h. The documentation [1] says
the safe way is for accessing shared data in signal handler is:
static volatile sig_atomic_t done_fd = -1;
It's fine if you want to use another patch to address this issue, this
patch for fixing errno is fine for me:
Reviewed-by: Leo Yan <leo.yan@...aro.org>
[1] https://wiki.sei.cmu.edu/confluence/display/c/SIG31-C.+Do+not+access+shared+objects+in+signal+handlers
Powered by blists - more mailing lists