Re: [PATCH v3 0/9] s390: Improve this_cpu operations
From: David Laight
Date: Thu May 21 2026 - 18:13:51 EST
On Thu, 21 May 2026 13:46:25 -0700
Yang Shi <yang@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 5/21/26 10:55 AM, David Laight wrote:
...
> > The 'trick' here will work for reading/writing values if you don't
> > care that the value read is stale (or might have been written to
> > the memory for a different cpu).
>
> If you don't care the stale value, you can just call __this_cpu_read().
You can get an impossible value.
The generated code might be like this:
this_cpu_data = xxx;
preempt_disable_count = this_cpu_data->preempt_disable_count;
If the count was non-zero at the start you'll read the value from
the current cpu and all is fine.
But if the count is zero you can get preempted between the instructions,
the process now running on your 'old' cpu can increment the value
and you then read the new non-zero value.
That won't be good at all.
You can only use __this_cpu_read() for things that don't change.
The big problem with using per-cpu page tables is there will be absolutely
nothing stopping code taking the wrong address of a per-cpu variable and
saving it somewhere.
At the moment you have to use the helper so always get the global address.
-- David
>
> Thanks,
> Yang