[PATCH v2 01/12] genirq: Use READ_ONCE for IRQ counter reads

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux