lkml.org 
[lkml]   [2021]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v2 01/12] genirq: Use READ_ONCE for IRQ counter reads
    Date
    IRQ counters are updated by each CPU independently, access to them
    does not need to synchronized and it's okay to race: as long as the
    counter is not seen going backwards (hopefully, cache coherency
    takes care of that) and the stores and loads are not torn.

    The last part is currently sorta-kinda expected to happen because
    all the counters use "unsigned int" which is expected to fit into
    machine word and not be torn.

    Make this expectation explicit by wrapping the reads in READ_ONCE.
    Note that writes are typically perfomed via this_cpu_inc() and its
    fellows which do not do matching WRITE_ONCE().

    Signed-off-by: Alexei Lozovsky <me@ilammy.net>
    ---
    include/linux/kernel_stat.h | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)

    diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
    index 44ae1a7eb9e3..90f2e2faf999 100644
    --- a/include/linux/kernel_stat.h
    +++ b/include/linux/kernel_stat.h
    @@ -61,7 +61,7 @@ static inline void kstat_incr_softirqs_this_cpu(unsigned int irq)

    static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu)
    {
    - return kstat_cpu(cpu).softirqs[irq];
    + return READ_ONCE(kstat_cpu(cpu).softirqs[irq]);
    }

    /*
    @@ -74,7 +74,7 @@ extern unsigned int kstat_irqs_usr(unsigned int irq);
    */
    static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
    {
    - return kstat_cpu(cpu).irqs_sum;
    + return READ_ONCE(kstat_cpu(cpu).irqs_sum);
    }

    #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
    --
    2.25.1
    \
     
     \ /
      Last update: 2021-09-15 19:59    [W:4.188 / U:0.116 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site