Re: [PATCH v3 06/13] epoll: introduce helpers for adding/removing events to uring

Roman Penyaev
2019-05-31T14:28:39Z

On 2019-05-31 14:53, Peter Zijlstra wrote:
> On Fri, May 31, 2019 at 01:15:21PM +0200, Roman Penyaev wrote:
>> On 2019-05-31 11:56, Peter Zijlstra wrote:
>> > On Thu, May 16, 2019 at 10:58:03AM +0200, Roman Penyaev wrote:
>
>> > > + i = __atomic_fetch_add(&ep->user_header->tail, 1,
>> > > + __ATOMIC_ACQUIRE);
>> >
>> > afaict __atomic_fetch_add() does not exist.
>>
>> That is gcc extension. I did not find any API just to increment
>> the variable atomically without using/casting to atomic. What
>> is a proper way to achieve that?
>
> That's C11 atomics, and those shall not be used in the kernel. For one
> they're not available in the minimally required GCC version (4.6).
>
> The proper and only way is to use atomic_t, but also you cannot share
> atomic_t with userspace.

Yes, that what I tried to avoid choosing c11 extension.

>
> The normal way of doing something like this is to have a kernel private
> atomic_t and copy the value out to userspace using smp_store_release().

Since this path is lockless unfortunately that won't work. So seems
the only way is to do one more cmpxchg (sigh) or give up and take a
look (sad sigh).

--
Roman