Re: KCSAN: data-race in __alloc_file / __alloc_file

From: Eric Dumazet
Date: Tue Nov 12 2019 - 18:18:00 EST


On Tue, Nov 12, 2019 at 2:44 PM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Tue, Nov 12, 2019 at 02:07:03PM -0800, Eric Dumazet wrote:
> >
> > I would prefer some kind of explicit marking, instead of a comment.
> >
> > Even if we prefer having a sane compiler, having these clearly
> > annotated can help
> > code readability quite a lot.
>
> Annotating every line where tsk->min_flt is used with a comment
> or explicit macro seems like a lot of churn.
> How about adding an attribute to a field ?
> Or an attribute to a type?
>
> clang attributes can be easily exteneded. We add bpf specific attributes
> that are known to clang only when 'clang -target bpf' is used.
> There could be x86 or generic attributes.
> Then one can do:
> typedef unsigned long __attribute__((ignore_data_race)) racy_u64;
> struct task_struct {
> racy_u64 min_flt;
> };
>
> Hopefully less churn and clear signal to clang.

Hmm we have the ' volatile' attribute on jiffies, and it causes
confusion already :p

arch/x86/kernel/apic/apic.c:904: jif_start = READ_ONCE(jiffies);
arch/x86/kernel/apic/apic.c:927:
unsigned long jif_now = READ_ONCE(jiffies);
kernel/sched/wait_bit.c:218: unsigned long now = READ_ONCE(jiffies);
kernel/sched/wait_bit.c:232: unsigned long now = READ_ONCE(jiffies);
kernel/time/timer.c:891: jnow = READ_ONCE(jiffies);
kernel/time/timer.c:1681: unsigned long now = READ_ONCE(jiffies);
net/rxrpc/conn_client.c:1111: now = READ_ONCE(jiffies);