Merge tag 'locking-urgent-2020-08-10' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 11 Aug 2020 02:07:44 +0000 (19:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 11 Aug 2020 02:07:44 +0000 (19:07 -0700)
Pull locking updates from Thomas Gleixner:
 "A set of locking fixes and updates:

   - Untangle the header spaghetti which causes build failures in
     various situations caused by the lockdep additions to seqcount to
     validate that the write side critical sections are non-preemptible.

   - The seqcount associated lock debug addons which were blocked by the
     above fallout.

     seqcount writers contrary to seqlock writers must be externally
     serialized, which usually happens via locking - except for strict
     per CPU seqcounts. As the lock is not part of the seqcount, lockdep
     cannot validate that the lock is held.

     This new debug mechanism adds the concept of associated locks.
     sequence count has now lock type variants and corresponding
     initializers which take a pointer to the associated lock used for
     writer serialization. If lockdep is enabled the pointer is stored
     and write_seqcount_begin() has a lockdep assertion to validate that
     the lock is held.

     Aside of the type and the initializer no other code changes are
     required at the seqcount usage sites. The rest of the seqcount API
     is unchanged and determines the type at compile time with the help
     of _Generic which is possible now that the minimal GCC version has
     been moved up.

     Adding this lockdep coverage unearthed a handful of seqcount bugs
     which have been addressed already independent of this.

     While generally useful this comes with a Trojan Horse twist: On RT
     kernels the write side critical section can become preemtible if
     the writers are serialized by an associated lock, which leads to
     the well known reader preempts writer livelock. RT prevents this by
     storing the associated lock pointer independent of lockdep in the
     seqcount and changing the reader side to block on the lock when a
     reader detects that a writer is in the write side critical section.

   - Conversion of seqcount usage sites to associated types and
     initializers"

* tag 'locking-urgent-2020-08-10' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (25 commits)
  locking/seqlock, headers: Untangle the spaghetti monster
  locking, arch/ia64: Reduce <asm/smp.h> header dependencies by moving XTP bits into the new <asm/xtp.h> header
  x86/headers: Remove APIC headers from <asm/smp.h>
  seqcount: More consistent seqprop names
  seqcount: Compress SEQCNT_LOCKNAME_ZERO()
  seqlock: Fold seqcount_LOCKNAME_init() definition
  seqlock: Fold seqcount_LOCKNAME_t definition
  seqlock: s/__SEQ_LOCKDEP/__SEQ_LOCK/g
  hrtimer: Use sequence counter with associated raw spinlock
  kvm/eventfd: Use sequence counter with associated spinlock
  userfaultfd: Use sequence counter with associated spinlock
  NFSv4: Use sequence counter with associated spinlock
  iocost: Use sequence counter with associated spinlock
  raid5: Use sequence counter with associated spinlock
  vfs: Use sequence counter with associated spinlock
  timekeeping: Use sequence counter with associated raw spinlock
  xfrm: policy: Use sequence counters with associated lock
  netfilter: nft_set_rbtree: Use sequence counter with associated rwlock
  netfilter: conntrack: Use sequence counter with associated spinlock
  sched: tasks: Use sequence counter with associated spinlock
  ...

24 files changed:
1  2 
arch/ia64/kernel/process.c
arch/ia64/kernel/smp.c
arch/x86/include/asm/tsc.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/intel.c
arch/x86/kernel/mpparse.c
arch/x86/kernel/setup.c
arch/x86/mm/init_32.c
arch/x86/xen/smp_pv.c
block/blk-iocost.c
drivers/dma-buf/dma-resv.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
drivers/iommu/intel/irq_remapping.c
drivers/md/raid5.c
drivers/md/raid5.h
fs/userfaultfd.c
include/linux/sched.h
include/net/netfilter/nf_conntrack.h
init/init_task.c
kernel/fork.c
kernel/time/timekeeping.c
net/netfilter/nf_conntrack_core.c
net/xfrm/xfrm_policy.c

Simple merge
Simple merge
@@@ -6,7 -6,11 +6,8 @@@
  #define _ASM_X86_TSC_H
  
  #include <asm/processor.h>
+ #include <asm/cpufeature.h>
  
 -#define NS_SCALE      10 /* 2^10, carefully chosen */
 -#define US_SCALE      32 /* 2^32, arbitralrily chosen */
 -
  /*
   * Standard way to access the cycle counter.
   */
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc kernel/fork.c
@@@ -2011,14 -2032,20 +2011,14 @@@ static __latent_entropy struct task_str
  #ifdef CONFIG_CPUSETS
        p->cpuset_mem_spread_rotor = NUMA_NO_NODE;
        p->cpuset_slab_spread_rotor = NUMA_NO_NODE;
-       seqcount_init(&p->mems_allowed_seq);
+       seqcount_spinlock_init(&p->mems_allowed_seq, &p->alloc_lock);
  #endif
  #ifdef CONFIG_TRACE_IRQFLAGS
 -      p->irq_events = 0;
 -      p->hardirq_enable_ip = 0;
 -      p->hardirq_enable_event = 0;
 -      p->hardirq_disable_ip = _THIS_IP_;
 -      p->hardirq_disable_event = 0;
 -      p->softirqs_enabled = 1;
 -      p->softirq_enable_ip = _THIS_IP_;
 -      p->softirq_enable_event = 0;
 -      p->softirq_disable_ip = 0;
 -      p->softirq_disable_event = 0;
 -      p->softirq_context = 0;
 +      memset(&p->irqtrace, 0, sizeof(p->irqtrace));
 +      p->irqtrace.hardirq_disable_ip  = _THIS_IP_;
 +      p->irqtrace.softirq_enable_ip   = _THIS_IP_;
 +      p->softirqs_enabled             = 1;
 +      p->softirq_context              = 0;
  #endif
  
        p->pagefault_disabled = 0;
Simple merge
Simple merge
@@@ -4157,10 -4153,10 +4157,10 @@@ void __init xfrm_init(void
  {
        register_pernet_subsys(&xfrm_net_ops);
        xfrm_dev_init();
-       seqcount_init(&xfrm_policy_hash_generation);
+       seqcount_mutex_init(&xfrm_policy_hash_generation, &hash_resize_mutex);
        xfrm_input_init();
  
 -#ifdef CONFIG_INET_ESPINTCP
 +#ifdef CONFIG_XFRM_ESPINTCP
        espintcp_init();
  #endif