Merge remote-tracking branch 'kspp/for-next/kspp'
authorStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Sep 2016 00:50:13 +0000 (10:50 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 13 Sep 2016 00:50:13 +0000 (10:50 +1000)
12 files changed:
1  2 
Documentation/kernel-parameters.txt
arch/Kconfig
arch/powerpc/kernel/Makefile
fs/namespace.c
include/linux/compiler-gcc.h
include/linux/compiler.h
include/linux/init.h
kernel/fork.c
kernel/sched/fair.c
kernel/time/timer.c
mm/page_alloc.c
net/core/dev.c

index d850308752550ff32af778fbea2548ad151557b7,9d054984370f8c0ef03fed1c830151f054d08cd0..4a04c2dad6e6659e27aa9cac8e82f7e1a490ecf2
@@@ -1688,7 -1688,7 +1688,7 @@@ bytes respectively. Such letter suffixe
  
        intel_idle.max_cstate=  [KNL,HW,ACPI,X86]
                        0       disables intel_idle and fall back on acpi_idle.
 -                      1 to 6  specify maximum depth of C-state.
 +                      1 to 9  specify maximum depth of C-state.
  
        intel_pstate=  [X86]
                       disable
                        than or equal to this physical address is ignored.
  
        maxcpus=        [SMP] Maximum number of processors that an SMP kernel
 -                      should make use of.  maxcpus=n : n >= 0 limits the
 -                      kernel to using 'n' processors.  n=0 is a special case,
 -                      it is equivalent to "nosmp", which also disables
 -                      the IO APIC.
 +                      will bring up during bootup.  maxcpus=n : n >= 0 limits
 +                      the kernel to bring up 'n' processors. Surely after
 +                      bootup you can bring up the other plugged cpu by executing
 +                      "echo 1 > /sys/devices/system/cpu/cpuX/online". So maxcpus
 +                      only takes effect during system bootup.
 +                      While n=0 is a special case, it is equivalent to "nosmp",
 +                      which also disables the IO APIC.
  
        max_loop=       [LOOP] The number of loop block devices that get
        (loop.max_loop) unconditionally pre-created at init time. The default
  
        nr_cpus=        [SMP] Maximum number of processors that an SMP kernel
                        could support.  nr_cpus=n : n >= 1 limits the kernel to
 -                      supporting 'n' processors. Later in runtime you can not
 -                      use hotplug cpu feature to put more cpu back to online.
 -                      just like you compile the kernel NR_CPUS=n
 +                      support 'n' processors. It could be larger than the
 +                      number of already plugged CPU during bootup, later in
 +                      runtime you can physically add extra cpu until it reaches
 +                      n. So during boot up some boot time memory for per-cpu
 +                      variables need be pre-allocated for later physical cpu
 +                      hot plugging.
  
        nr_uarts=       [SERIAL] maximum number of UARTs to be registered.
  
                                PAGE_SIZE is used as alignment.
                                PCI-PCI bridge can be specified, if resource
                                windows need to be expanded.
 +                              To specify the alignment for several
 +                              instances of a device, the PCI vendor,
 +                              device, subvendor, and subdevice may be
 +                              specified, e.g., 4096@pci:8086:9c22:103c:198f
                ecrc=           Enable/disable PCIe ECRC (transaction layer
                                end-to-end CRC checking).
                                bios: Use BIOS/firmware settings. This is the
        raid=           [HW,RAID]
                        See Documentation/md.txt.
  
+       ram_latent_entropy
+                       Enable a very simple form of latent entropy extraction
+                       from the first 4GB of memory as the bootmem allocator
+                       passes the memory pages to the buddy allocator.
        ramdisk_size=   [RAM] Sizes of RAM disks in kilobytes
                        See Documentation/blockdev/ramdisk.txt.
  
diff --combined arch/Kconfig
index 84244155382273920859724fe9bca32e4ca333b7,c8fbabb3ead2bd5aa744dbb0869cbb2354ab422c..47a3ab795955052c3cc553b2c25e373be58e2b72
@@@ -336,6 -336,17 +336,6 @@@ config HAVE_ARCH_SECCOMP_FILTE
            results in the system call being skipped immediately.
          - seccomp syscall wired up
  
 -        For best performance, an arch should use seccomp_phase1 and
 -        seccomp_phase2 directly.  It should call seccomp_phase1 for all
 -        syscalls if TIF_SECCOMP is set, but seccomp_phase1 does not
 -        need to be called from a ptrace-safe context.  It must then
 -        call seccomp_phase2 if seccomp_phase1 returns anything other
 -        than SECCOMP_PHASE1_OK or SECCOMP_PHASE1_SKIP.
 -
 -        As an additional optimization, an arch may provide seccomp_data
 -        directly to seccomp_phase1; this avoids multiple calls
 -        to the syscall_xyz helpers for every syscall.
 -
  config SECCOMP_FILTER
        def_bool y
        depends on HAVE_ARCH_SECCOMP_FILTER && SECCOMP && NET
@@@ -383,6 -394,24 +383,24 @@@ config GCC_PLUGIN_SANCO
          gcc-4.5 on). It is based on the commit "Add fuzzing coverage support"
          by Dmitry Vyukov <dvyukov@google.com>.
  
+ config GCC_PLUGIN_LATENT_ENTROPY
+       bool "Generate some entropy during boot and runtime"
+       depends on GCC_PLUGINS
+       help
+         By saying Y here the kernel will instrument some kernel code to
+         extract some entropy from both original and artificially created
+         program state.  This will help especially embedded systems where
+         there is little 'natural' source of entropy normally.  The cost
+         is some slowdown of the boot process (about 0.5%) and fork and
+         irq processing.
+         Note that entropy extracted this way is not cryptographically
+         secure!
+         This plugin was ported from grsecurity/PaX. More information at:
+          * https://grsecurity.net/
+          * https://pax.grsecurity.net/
  config HAVE_CC_STACKPROTECTOR
        bool
        help
@@@ -459,25 -488,6 +477,25 @@@ config HAVE_ARCH_WITHIN_STACK_FRAME
          and similar) by implementing an inline arch_within_stack_frames(),
          which is used by CONFIG_HARDENED_USERCOPY.
  
 +config THIN_ARCHIVES
 +      bool
 +      help
 +        Select this if the architecture wants to use thin archives
 +        instead of ld -r to create the built-in.o files.
 +
 +config LD_DEAD_CODE_DATA_ELIMINATION
 +      bool
 +      help
 +        Select this if the architecture wants to do dead code and
 +        data elimination with the linker by compiling with
 +        -ffunction-sections -fdata-sections and linking with
 +        --gc-sections.
 +
 +        This requires that the arch annotates or otherwise protects
 +        its external entry points from being discarded. Linker scripts
 +        must also merge .text.*, .data.*, and .bss.* correctly into
 +        output sections.
 +
  config HAVE_CONTEXT_TRACKING
        bool
        help
index fe4c075bcf50eda75905e7c53b4830914cef5b00,eac76ca873fcc83571362227e70aa8e43892b777..62df36c3f138c6bb9f6ac16adcc5e341414ff052
@@@ -14,6 -14,11 +14,11 @@@ CFLAGS_prom_init.o      += -fPI
  CFLAGS_btext.o                += -fPIC
  endif
  
+ CFLAGS_cputable.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
+ CFLAGS_init.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
+ CFLAGS_btext.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
+ CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
  ifdef CONFIG_FUNCTION_TRACER
  # Do not trace early boot code
  CFLAGS_REMOVE_cputable.o = -mno-sched-epilog $(CC_FLAGS_FTRACE)
@@@ -41,7 -46,7 +46,7 @@@ obj-$(CONFIG_VDSO32)          += vdso32
  obj-$(CONFIG_HAVE_HW_BREAKPOINT)      += hw_breakpoint.o
  obj-$(CONFIG_PPC_BOOK3S_64)   += cpu_setup_ppc970.o cpu_setup_pa6t.o
  obj-$(CONFIG_PPC_BOOK3S_64)   += cpu_setup_power.o
 -obj-$(CONFIG_PPC_BOOK3S_64)   += mce.o mce_power.o hmi.o
 +obj-$(CONFIG_PPC_BOOK3S_64)   += mce.o mce_power.o
  obj-$(CONFIG_PPC_BOOK3E_64)   += exceptions-64e.o idle_book3e.o
  obj-$(CONFIG_PPC64)           += vdso64/
  obj-$(CONFIG_ALTIVEC)         += vecemu.o
diff --combined fs/namespace.c
index dcd9afe21e62810f92ee9073dcd2cf7744814ea3,4a9568b81138f7bd16cfd8b8987c3d8638cdcae7..c9f84a2420960e1abee9646bdd58fa2b0ea7d249
@@@ -2700,7 -2700,7 +2700,7 @@@ long do_mount(const char *dev_name, con
  
        flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
                   MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
 -                 MS_STRICTATIME);
 +                 MS_STRICTATIME | MS_NOREMOTELOCK);
  
        if (flags & MS_REMOUNT)
                retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
@@@ -2759,6 -2759,7 +2759,7 @@@ static struct mnt_namespace *alloc_mnt_
        return new_ns;
  }
  
+ __latent_entropy
  struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
                struct user_namespace *user_ns, struct fs_struct *new_fs)
  {
index 573c5a18908fd53970fefea291805c500fd1d7f9,0ef8329f95c283642611fbee17b82292f5f197e3..432f5c97e18f4f75fd68b1c1101cf828fb3d4fa0
  #define __compiler_offsetof(a, b)                                     \
        __builtin_offsetof(a, b)
  
 -#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
 +#if GCC_VERSION >= 40100
  # define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
  #endif
  
  #endif /* GCC_VERSION >= 40300 */
  
  #if GCC_VERSION >= 40500
+ #ifndef __CHECKER__
+ #ifdef LATENT_ENTROPY_PLUGIN
+ #define __latent_entropy __attribute__((latent_entropy))
+ #endif
+ #endif
  /*
   * Mark a position in code as unreachable.  This can be used to
   * suppress control flow warnings after asm blocks that transfer
   */
  #define asm_volatile_goto(x...)       do { asm goto(x); asm (""); } while (0)
  
 -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
 +/*
 + * sparse (__CHECKER__) pretends to be gcc, but can't do constant
 + * folding in __builtin_bswap*() (yet), so don't set these for it.
 + */
 +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__)
  #if GCC_VERSION >= 40400
  #define __HAVE_BUILTIN_BSWAP32__
  #define __HAVE_BUILTIN_BSWAP64__
  #if GCC_VERSION >= 40800
  #define __HAVE_BUILTIN_BSWAP16__
  #endif
 -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
 +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */
  
  #if GCC_VERSION >= 50000
  #define KASAN_ABI_VERSION 4
diff --combined include/linux/compiler.h
index bc776717ffe248f204c6c9fd86a55d414f2d8171,d7a0b579442c9064a933ce6e7219031562ad9807..0e0faff63bd2d7e98c5a0eead16f2aa445d9afd3
@@@ -182,29 -182,6 +182,29 @@@ void ftrace_likely_update(struct ftrace
  # define unreachable() do { } while (1)
  #endif
  
 +/*
 + * KENTRY - kernel entry point
 + * This can be used to annotate symbols (functions or data) that are used
 + * without their linker symbol being referenced explicitly. For example,
 + * interrupt vector handlers, or functions in the kernel image that are found
 + * programatically.
 + *
 + * Not required for symbols exported with EXPORT_SYMBOL, or initcalls. Those
 + * are handled in their own way (with KEEP() in linker scripts).
 + *
 + * KENTRY can be avoided if the symbols in question are marked as KEEP() in the
 + * linker script. For example an architecture could KEEP() its entire
 + * boot/exception vector code rather than annotate each function and data.
 + */
 +#ifndef KENTRY
 +# define KENTRY(sym)                                          \
 +      extern typeof(sym) sym;                                 \
 +      static const unsigned long __kentry_##sym               \
 +      __used                                                  \
 +      __attribute__((section("___kentry" "+" #sym ), used))   \
 +      = (unsigned long)&sym;
 +#endif
 +
  #ifndef RELOC_HIDE
  # define RELOC_HIDE(ptr, off)                                 \
    ({ unsigned long __ptr;                                     \
@@@ -429,6 -406,10 +429,10 @@@ static __always_inline void __write_onc
  # define __attribute_const__  /* unimplemented */
  #endif
  
+ #ifndef __latent_entropy
+ # define __latent_entropy
+ #endif
  /*
   * Tell gcc if a function is cold. The compiler will assume any path
   * directly leading to the call is unlikely.
   * object's lifetime is managed by something other than RCU.  That
   * "something other" might be reference counting or simple immortality.
   *
 - * The seemingly unused void * variable is to validate @p is indeed a pointer
 - * type. All pointer types silently cast to void *.
 + * The seemingly unused size_t variable is to validate @p is indeed a pointer
 + * type by making sure it can be dereferenced.
   */
  #define lockless_dereference(p) \
  ({ \
        typeof(p) _________p1 = READ_ONCE(p); \
 -      __maybe_unused const void * const _________p2 = _________p1; \
 +      size_t __maybe_unused __size_of_ptr = sizeof(*(p)); \
        smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
        (_________p1); \
  })
diff --combined include/linux/init.h
index e571fec4bb284460499b13597e41d3c9ad3b17ec,1e5c131d5c9a12c513b33b021be26ac21fee8df8..62d6843326634fa05887b33272a0e20e9e539789
@@@ -39,7 -39,7 +39,7 @@@
  
  /* These are for everybody (although not all archs will actually
     discard it in modules) */
- #define __init                __section(.init.text) __cold notrace
+ #define __init                __section(.init.text) __cold notrace __latent_entropy
  #define __initdata    __section(.init.data)
  #define __initconst   __constsection(.init.rodata)
  #define __exitdata    __section(.exit.data)
@@@ -86,7 -86,8 +86,8 @@@
  #define __exit          __section(.exit.text) __exitused __cold notrace
  
  /* Used for MEMORY_HOTPLUG */
- #define __meminit        __section(.meminit.text) __cold notrace
+ #define __meminit        __section(.meminit.text) __cold notrace \
+                                                 __latent_entropy
  #define __meminitdata    __section(.meminit.data)
  #define __meminitconst   __constsection(.meminit.rodata)
  #define __memexit        __section(.memexit.text) __exitused __cold notrace
@@@ -150,8 -151,24 +151,8 @@@ extern bool initcall_debug
  
  #ifndef __ASSEMBLY__
  
 -#ifdef CONFIG_LTO
 -/* Work around a LTO gcc problem: when there is no reference to a variable
 - * in a module it will be moved to the end of the program. This causes
 - * reordering of initcalls which the kernel does not like.
 - * Add a dummy reference function to avoid this. The function is
 - * deleted by the linker.
 - */
 -#define LTO_REFERENCE_INITCALL(x) \
 -      ; /* yes this is needed */                      \
 -      static __used __exit void *reference_##x(void)  \
 -      {                                               \
 -              return &x;                              \
 -      }
 -#else
 -#define LTO_REFERENCE_INITCALL(x)
 -#endif
 -
 -/* initcalls are now grouped by functionality into separate 
 +/*
 + * initcalls are now grouped by functionality into separate
   * subsections. Ordering inside the subsections is determined
   * by link order. 
   * For backwards compatibility, initcall() puts the call in 
   *
   * The `id' arg to __define_initcall() is needed so that multiple initcalls
   * can point at the same handler without causing duplicate-symbol build errors.
 + *
 + * Initcalls are run by placing pointers in initcall sections that the
 + * kernel iterates at runtime. The linker can do dead code / data elimination
 + * and remove that completely, so the initcall sections have to be marked
 + * as KEEP() in the linker script.
   */
  
  #define __define_initcall(fn, id) \
        static initcall_t __initcall_##fn##id __used \
 -      __attribute__((__section__(".initcall" #id ".init"))) = fn; \
 -      LTO_REFERENCE_INITCALL(__initcall_##fn##id)
 +      __attribute__((__section__(".initcall" #id ".init"))) = fn;
  
  /*
   * Early initcalls run before initializing SMP.
  
  #define __initcall(fn) device_initcall(fn)
  
 -#define __exitcall(fn) \
 +#define __exitcall(fn)                                                \
        static exitcall_t __exitcall_##fn __exit_call = fn
  
 -#define console_initcall(fn) \
 -      static initcall_t __initcall_##fn \
 +#define console_initcall(fn)                                  \
 +      static initcall_t __initcall_##fn                       \
        __used __section(.con_initcall.init) = fn
  
 -#define security_initcall(fn) \
 -      static initcall_t __initcall_##fn \
 +#define security_initcall(fn)                                 \
 +      static initcall_t __initcall_##fn                       \
        __used __section(.security_initcall.init) = fn
  
  struct obs_kernel_param {
diff --combined kernel/fork.c
index beb31725f7e2746fb17cdd305c4193ab2c70e551,5baf957f1bcdbd7c20c28de2379d60855d20b56e..05393881ef399ac365b6fa522864875a1e55b6f7
@@@ -404,7 -404,8 +404,8 @@@ free_tsk
  }
  
  #ifdef CONFIG_MMU
- static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
+ static __latent_entropy int dup_mmap(struct mm_struct *mm,
+                                       struct mm_struct *oldmm)
  {
        struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
        struct rb_node **rb_link, *rb_parent;
@@@ -798,29 -799,6 +799,29 @@@ struct file *get_mm_exe_file(struct mm_
  }
  EXPORT_SYMBOL(get_mm_exe_file);
  
 +/**
 + * get_task_exe_file - acquire a reference to the task's executable file
 + *
 + * Returns %NULL if task's mm (if any) has no associated executable file or
 + * this is a kernel thread with borrowed mm (see the comment above get_task_mm).
 + * User must release file via fput().
 + */
 +struct file *get_task_exe_file(struct task_struct *task)
 +{
 +      struct file *exe_file = NULL;
 +      struct mm_struct *mm;
 +
 +      task_lock(task);
 +      mm = task->mm;
 +      if (mm) {
 +              if (!(task->flags & PF_KTHREAD))
 +                      exe_file = get_mm_exe_file(mm);
 +      }
 +      task_unlock(task);
 +      return exe_file;
 +}
 +EXPORT_SYMBOL(get_task_exe_file);
 +
  /**
   * get_task_mm - acquire a reference to the task's mm
   *
@@@ -936,12 -914,14 +937,12 @@@ void mm_release(struct task_struct *tsk
        deactivate_mm(tsk, mm);
  
        /*
 -       * If we're exiting normally, clear a user-space tid field if
 -       * requested.  We leave this alone when dying by signal, to leave
 -       * the value intact in a core dump, and to save the unnecessary
 -       * trouble, say, a killed vfork parent shouldn't touch this mm.
 -       * Userland only wants this done for a sys_exit.
 +       * Signal userspace if we're not exiting with a core dump
 +       * because we want to leave the value intact for debugging
 +       * purposes.
         */
        if (tsk->clear_child_tid) {
 -              if (!(tsk->flags & PF_SIGNALED) &&
 +              if (!(tsk->signal->flags & SIGNAL_GROUP_COREDUMP) &&
                    atomic_read(&mm->mm_users) > 1) {
                        /*
                         * We don't check the error code - if userspace has
@@@ -1296,7 -1276,8 +1297,8 @@@ init_task_pid(struct task_struct *task
   * parts of the process environment (as per the clone
   * flags). The actual kick-off is left to the caller.
   */
- static struct task_struct *copy_process(unsigned long clone_flags,
+ static __latent_entropy struct task_struct *copy_process(
+                                       unsigned long clone_flags,
                                        unsigned long stack_start,
                                        unsigned long stack_size,
                                        int __user *child_tidptr,
        p->real_start_time = ktime_get_boot_ns();
        p->io_context = NULL;
        p->audit_context = NULL;
 -      threadgroup_change_begin(current);
        cgroup_fork(p);
  #ifdef CONFIG_NUMA
        p->mempolicy = mpol_dup(p->mempolicy);
        INIT_LIST_HEAD(&p->thread_group);
        p->task_works = NULL;
  
 +      threadgroup_change_begin(current);
        /*
         * Ensure that the cgroup subsystem policies allow the new process to be
         * forked. It should be noted the the new process's css_set can be changed
  bad_fork_cancel_cgroup:
        cgroup_cancel_fork(p);
  bad_fork_free_pid:
 +      threadgroup_change_end(current);
        if (pid != &init_struct_pid)
                free_pid(pid);
  bad_fork_cleanup_thread:
@@@ -1710,6 -1690,7 +1712,6 @@@ bad_fork_cleanup_policy
        mpol_put(p->mempolicy);
  bad_fork_cleanup_threadgroup_lock:
  #endif
 -      threadgroup_change_end(current);
        delayacct_tsk_free(p);
  bad_fork_cleanup_count:
        atomic_dec(&p->cred->user->processes);
@@@ -1780,6 -1761,7 +1782,7 @@@ long _do_fork(unsigned long clone_flags
  
        p = copy_process(clone_flags, stack_start, stack_size,
                         child_tidptr, NULL, trace, tls, NUMA_NO_NODE);
+       add_latent_entropy();
        /*
         * Do this prior waking up the new thread - the thread pointer
         * might get invalid after that point, if the thread exits quickly.
diff --combined kernel/sched/fair.c
index 5d558cc91f08eb3538265e0426536ba289b669b1,24d9602c8a8556a1503e1baeadf87bad814ea929..e6a9dee0d34f9fb9a61f3e33c80e057a25ef1bcc
@@@ -2875,7 -2875,12 +2875,7 @@@ static inline void update_tg_load_avg(s
  
  static inline void cfs_rq_util_change(struct cfs_rq *cfs_rq)
  {
 -      struct rq *rq = rq_of(cfs_rq);
 -      int cpu = cpu_of(rq);
 -
 -      if (cpu == smp_processor_id() && &rq->cfs == cfs_rq) {
 -              unsigned long max = rq->cpu_capacity_orig;
 -
 +      if (&this_rq()->cfs == cfs_rq) {
                /*
                 * There are a few boundary cases this might miss but it should
                 * get called often enough that that should (hopefully) not be
                 *
                 * See cpu_util().
                 */
 -              cpufreq_update_util(rq_clock(rq),
 -                                  min(cfs_rq->avg.util_avg, max), max);
 +              cpufreq_update_util(rq_of(cfs_rq), 0);
        }
  }
  
@@@ -3153,7 -3159,10 +3153,7 @@@ update_cfs_rq_load_avg(u64 now, struct 
  
  static inline void update_load_avg(struct sched_entity *se, int not_used)
  {
 -      struct cfs_rq *cfs_rq = cfs_rq_of(se);
 -      struct rq *rq = rq_of(cfs_rq);
 -
 -      cpufreq_trigger_update(rq_clock(rq));
 +      cpufreq_update_util(rq_of(cfs_rq_of(se)), 0);
  }
  
  static inline void
@@@ -4260,7 -4269,7 +4260,7 @@@ static void sync_throttle(struct task_g
        pcfs_rq = tg->parent->cfs_rq[cpu];
  
        cfs_rq->throttle_count = pcfs_rq->throttle_count;
 -      pcfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu));
 +      cfs_rq->throttled_clock_task = rq_clock_task(cpu_rq(cpu));
  }
  
  /* conditionally throttle active cfs_rq's from put_prev_entity() */
@@@ -8274,7 -8283,7 +8274,7 @@@ static void nohz_idle_balance(struct r
   * run_rebalance_domains is triggered when needed from the scheduler tick.
   * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
   */
- static void run_rebalance_domains(struct softirq_action *h)
+ static __latent_entropy void run_rebalance_domains(struct softirq_action *h)
  {
        struct rq *this_rq = this_rq();
        enum cpu_idle_type idle = this_rq->idle_balance ?
diff --combined kernel/time/timer.c
index 32bf6f75a8fec255c6d5fbf38e9fecd9e1e848fa,5f58fd2c220e723058d2c19d762013e2a5022287..2d47980a1bc423df44e8e1324537f4e185b338ae
@@@ -1496,7 -1496,6 +1496,7 @@@ u64 get_next_timer_interrupt(unsigned l
        struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
        u64 expires = KTIME_MAX;
        unsigned long nextevt;
 +      bool is_max_delta;
  
        /*
         * Pretend that there is no timer pending if the cpu is offline.
  
        spin_lock(&base->lock);
        nextevt = __next_timer_interrupt(base);
 +      is_max_delta = (nextevt == base->clk + NEXT_TIMER_MAX_DELTA);
        base->next_expiry = nextevt;
        /*
         * We have a fresh next event. Check whether we can forward the base:
                expires = basem;
                base->is_idle = false;
        } else {
 -              expires = basem + (nextevt - basej) * TICK_NSEC;
 +              if (!is_max_delta)
 +                      expires = basem + (nextevt - basej) * TICK_NSEC;
                /*
                 * If we expect to sleep more than a tick, mark the base idle:
                 */
@@@ -1633,7 -1630,7 +1633,7 @@@ static inline void __run_timers(struct 
  /*
   * This function runs timers and the timer-tq in bottom half context.
   */
- static void run_timer_softirq(struct softirq_action *h)
+ static __latent_entropy void run_timer_softirq(struct softirq_action *h)
  {
        struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]);
  
diff --combined mm/page_alloc.c
index a2214c64ed3cd04dceaed7a579f593852e458df1,194ba70faaeff877ddc9c3bf138812c2d305596e..41940f6e3c1c07eec3467f41de4e5337e5d4b654
@@@ -64,6 -64,7 +64,7 @@@
  #include <linux/page_owner.h>
  #include <linux/kthread.h>
  #include <linux/memcontrol.h>
+ #include <linux/random.h>
  
  #include <asm/sections.h>
  #include <asm/tlbflush.h>
@@@ -91,6 -92,11 +92,11 @@@ EXPORT_PER_CPU_SYMBOL(_numa_mem_)
  int _node_numa_mem_[MAX_NUMNODES];
  #endif
  
+ #ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
+ volatile u64 latent_entropy __latent_entropy;
+ EXPORT_SYMBOL(latent_entropy);
+ #endif
  /*
   * Array of node states.
   */
@@@ -1008,8 -1014,10 +1014,8 @@@ static __always_inline bool free_pages_
        }
        if (PageMappingFlags(page))
                page->mapping = NULL;
 -      if (memcg_kmem_enabled() && PageKmemcg(page)) {
 +      if (memcg_kmem_enabled() && PageKmemcg(page))
                memcg_kmem_uncharge(page, order);
 -              __ClearPageKmemcg(page);
 -      }
        if (check_free)
                bad += free_pages_check(page);
        if (bad)
@@@ -1234,6 -1242,15 +1240,15 @@@ static void __free_pages_ok(struct pag
        local_irq_restore(flags);
  }
  
+ bool __meminitdata ram_latent_entropy;
+ static int __init setup_ram_latent_entropy(char *str)
+ {
+       ram_latent_entropy = true;
+       return 0;
+ }
+ early_param("ram_latent_entropy", setup_ram_latent_entropy);
  static void __init __free_pages_boot_core(struct page *page, unsigned int order)
  {
        unsigned int nr_pages = 1 << order;
        __ClearPageReserved(p);
        set_page_count(p, 0);
  
+       if (ram_latent_entropy && !PageHighMem(page) &&
+               page_to_pfn(page) < 0x100000) {
+               u64 hash = 0;
+               size_t index, end = PAGE_SIZE * nr_pages / sizeof(hash);
+               const u64 *data = lowmem_page_address(page);
+               for (index = 0; index < end; index++)
+                       hash ^= hash + data[index];
+               add_device_randomness((const void *)&hash, sizeof(hash));
+       }
        page_zone(page)->managed_pages += nr_pages;
        set_page_refcounted(page);
        __free_pages(page, order);
@@@ -3137,6 -3165,54 +3163,6 @@@ __alloc_pages_direct_compact(gfp_t gfp_
        return NULL;
  }
  
 -static inline bool
 -should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
 -                   enum compact_result compact_result,
 -                   enum compact_priority *compact_priority,
 -                   int compaction_retries)
 -{
 -      int max_retries = MAX_COMPACT_RETRIES;
 -
 -      if (!order)
 -              return false;
 -
 -      /*
 -       * compaction considers all the zone as desperately out of memory
 -       * so it doesn't really make much sense to retry except when the
 -       * failure could be caused by insufficient priority
 -       */
 -      if (compaction_failed(compact_result)) {
 -              if (*compact_priority > MIN_COMPACT_PRIORITY) {
 -                      (*compact_priority)--;
 -                      return true;
 -              }
 -              return false;
 -      }
 -
 -      /*
 -       * make sure the compaction wasn't deferred or didn't bail out early
 -       * due to locks contention before we declare that we should give up.
 -       * But do not retry if the given zonelist is not suitable for
 -       * compaction.
 -       */
 -      if (compaction_withdrawn(compact_result))
 -              return compaction_zonelist_suitable(ac, order, alloc_flags);
 -
 -      /*
 -       * !costly requests are much more important than __GFP_REPEAT
 -       * costly ones because they are de facto nofail and invoke OOM
 -       * killer to move on while costly can fail and users are ready
 -       * to cope with that. 1/4 retries is rather arbitrary but we
 -       * would need much more detailed feedback from compaction to
 -       * make a better decision.
 -       */
 -      if (order > PAGE_ALLOC_COSTLY_ORDER)
 -              max_retries /= 4;
 -      if (compaction_retries <= max_retries)
 -              return true;
 -
 -      return false;
 -}
  #else
  static inline struct page *
  __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
        return NULL;
  }
  
 +#endif /* CONFIG_COMPACTION */
 +
  static inline bool
  should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
                     enum compact_result compact_result,
        }
        return false;
  }
 -#endif /* CONFIG_COMPACTION */
  
  /* Perform direct synchronous page reclaim */
  static int
@@@ -3707,10 -3782,12 +3733,10 @@@ no_zone
        }
  
  out:
 -      if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page) {
 -              if (unlikely(memcg_kmem_charge(page, gfp_mask, order))) {
 -                      __free_pages(page, order);
 -                      page = NULL;
 -              } else
 -                      __SetPageKmemcg(page);
 +      if (memcg_kmem_enabled() && (gfp_mask & __GFP_ACCOUNT) && page &&
 +          unlikely(memcg_kmem_charge(page, gfp_mask, order) != 0)) {
 +              __free_pages(page, order);
 +              page = NULL;
        }
  
        if (kmemcheck_enabled && page)
@@@ -4013,7 -4090,7 +4039,7 @@@ long si_mem_available(void
        int lru;
  
        for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
 -              pages[lru] = global_page_state(NR_LRU_BASE + lru);
 +              pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
  
        for_each_zone(zone)
                wmark_low += zone->watermark[WMARK_LOW];
@@@ -4360,7 -4437,7 +4386,7 @@@ static int build_zonelists_node(pg_data
        do {
                zone_type--;
                zone = pgdat->node_zones + zone_type;
 -              if (populated_zone(zone)) {
 +              if (managed_zone(zone)) {
                        zoneref_set_zone(zone,
                                &zonelist->_zonerefs[nr_zones++]);
                        check_highest_zone(zone_type);
@@@ -4598,7 -4675,7 +4624,7 @@@ static void build_zonelists_in_zone_ord
                for (j = 0; j < nr_nodes; j++) {
                        node = node_order[j];
                        z = &NODE_DATA(node)->node_zones[zone_type];
 -                      if (populated_zone(z)) {
 +                      if (managed_zone(z)) {
                                zoneref_set_zone(z,
                                        &zonelist->_zonerefs[pos++]);
                                check_highest_zone(zone_type);
@@@ -4710,8 -4787,6 +4736,8 @@@ int local_memory_node(int node
  }
  #endif
  
 +static void setup_min_unmapped_ratio(void);
 +static void setup_min_slab_ratio(void);
  #else /* CONFIG_NUMA */
  
  static void set_zonelist_order(void)
@@@ -5833,6 -5908,9 +5859,6 @@@ static void __paginginit free_area_init
                zone->managed_pages = is_highmem_idx(j) ? realsize : freesize;
  #ifdef CONFIG_NUMA
                zone->node = nid;
 -              pgdat->min_unmapped_pages += (freesize*sysctl_min_unmapped_ratio)
 -                                              / 100;
 -              pgdat->min_slab_pages += (freesize * sysctl_min_slab_ratio) / 100;
  #endif
                zone->name = zone_names[j];
                zone->zone_pgdat = pgdat;
@@@ -6753,12 -6831,6 +6779,12 @@@ int __meminit init_per_zone_wmark_min(v
        setup_per_zone_wmarks();
        refresh_zone_stat_thresholds();
        setup_per_zone_lowmem_reserve();
 +
 +#ifdef CONFIG_NUMA
 +      setup_min_unmapped_ratio();
 +      setup_min_slab_ratio();
 +#endif
 +
        return 0;
  }
  core_initcall(init_per_zone_wmark_min)
@@@ -6800,58 -6872,43 +6826,58 @@@ int watermark_scale_factor_sysctl_handl
  }
  
  #ifdef CONFIG_NUMA
 +static void setup_min_unmapped_ratio(void)
 +{
 +      pg_data_t *pgdat;
 +      struct zone *zone;
 +
 +      for_each_online_pgdat(pgdat)
 +              pgdat->min_unmapped_pages = 0;
 +
 +      for_each_zone(zone)
 +              zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages *
 +                              sysctl_min_unmapped_ratio) / 100;
 +}
 +
 +
  int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *table, int write,
        void __user *buffer, size_t *length, loff_t *ppos)
  {
 -      struct pglist_data *pgdat;
 -      struct zone *zone;
        int rc;
  
        rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
        if (rc)
                return rc;
  
 +      setup_min_unmapped_ratio();
 +
 +      return 0;
 +}
 +
 +static void setup_min_slab_ratio(void)
 +{
 +      pg_data_t *pgdat;
 +      struct zone *zone;
 +
        for_each_online_pgdat(pgdat)
                pgdat->min_slab_pages = 0;
  
        for_each_zone(zone)
 -              zone->zone_pgdat->min_unmapped_pages += (zone->managed_pages *
 -                              sysctl_min_unmapped_ratio) / 100;
 -      return 0;
 +              zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
 +                              sysctl_min_slab_ratio) / 100;
  }
  
  int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *table, int write,
        void __user *buffer, size_t *length, loff_t *ppos)
  {
 -      struct pglist_data *pgdat;
 -      struct zone *zone;
        int rc;
  
        rc = proc_dointvec_minmax(table, write, buffer, length, ppos);
        if (rc)
                return rc;
  
 -      for_each_online_pgdat(pgdat)
 -              pgdat->min_slab_pages = 0;
 +      setup_min_slab_ratio();
  
 -      for_each_zone(zone)
 -              zone->zone_pgdat->min_slab_pages += (zone->managed_pages *
 -                              sysctl_min_slab_ratio) / 100;
        return 0;
  }
  #endif
diff --combined net/core/dev.c
index 9dbece2f1296b65b4c66f8d9d9c3172b59ee1819,a38319b0c19794a937792124c61ac1c651542d5c..9e76d4df6ca0773720d6285985ef551161b0f74a
@@@ -3355,6 -3355,16 +3355,6 @@@ static int __dev_queue_xmit(struct sk_b
        else
                skb_dst_force(skb);
  
 -#ifdef CONFIG_NET_SWITCHDEV
 -      /* Don't forward if offload device already forwarded */
 -      if (skb->offload_fwd_mark &&
 -          skb->offload_fwd_mark == dev->offload_fwd_mark) {
 -              consume_skb(skb);
 -              rc = NET_XMIT_SUCCESS;
 -              goto out;
 -      }
 -#endif
 -
        txq = netdev_pick_tx(dev, skb, accel_priv);
        q = rcu_dereference_bh(txq->qdisc);
  
@@@ -3845,7 -3855,7 +3845,7 @@@ int netif_rx_ni(struct sk_buff *skb
  }
  EXPORT_SYMBOL(netif_rx_ni);
  
- static void net_tx_action(struct softirq_action *h)
+ static __latent_entropy void net_tx_action(struct softirq_action *h)
  {
        struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  
        }
  }
  
 -#if (defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)) && \
 -    (defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE))
 +#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_ATM_LANE)
  /* This hook is defined here for ATM LANE */
  int (*br_fdb_test_addr_hook)(struct net_device *dev,
                             unsigned char *addr) __read_mostly;
@@@ -3963,22 -3974,6 +3963,22 @@@ sch_handle_ingress(struct sk_buff *skb
        return skb;
  }
  
 +/**
 + *    netdev_is_rx_handler_busy - check if receive handler is registered
 + *    @dev: device to check
 + *
 + *    Check if a receive handler is already registered for a given device.
 + *    Return true if there one.
 + *
 + *    The caller must hold the rtnl_mutex.
 + */
 +bool netdev_is_rx_handler_busy(struct net_device *dev)
 +{
 +      ASSERT_RTNL();
 +      return dev && rtnl_dereference(dev->rx_handler);
 +}
 +EXPORT_SYMBOL_GPL(netdev_is_rx_handler_busy);
 +
  /**
   *    netdev_rx_handler_register - register receive handler
   *    @dev: device to register a handler for
@@@ -4297,53 -4292,32 +4297,53 @@@ int netif_receive_skb(struct sk_buff *s
  }
  EXPORT_SYMBOL(netif_receive_skb);
  
 -/* Network device is going away, flush any packets still pending
 - * Called with irqs disabled.
 - */
 -static void flush_backlog(void *arg)
 +DEFINE_PER_CPU(struct work_struct, flush_works);
 +
 +/* Network device is going away, flush any packets still pending */
 +static void flush_backlog(struct work_struct *work)
  {
 -      struct net_device *dev = arg;
 -      struct softnet_data *sd = this_cpu_ptr(&softnet_data);
        struct sk_buff *skb, *tmp;
 +      struct softnet_data *sd;
 +
 +      local_bh_disable();
 +      sd = this_cpu_ptr(&softnet_data);
  
 +      local_irq_disable();
        rps_lock(sd);
        skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
 -              if (skb->dev == dev) {
 +              if (skb->dev->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->input_pkt_queue);
                        kfree_skb(skb);
                        input_queue_head_incr(sd);
                }
        }
        rps_unlock(sd);
 +      local_irq_enable();
  
        skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
 -              if (skb->dev == dev) {
 +              if (skb->dev->reg_state == NETREG_UNREGISTERING) {
                        __skb_unlink(skb, &sd->process_queue);
                        kfree_skb(skb);
                        input_queue_head_incr(sd);
                }
        }
 +      local_bh_enable();
 +}
 +
 +static void flush_all_backlogs(void)
 +{
 +      unsigned int cpu;
 +
 +      get_online_cpus();
 +
 +      for_each_online_cpu(cpu)
 +              queue_work_on(cpu, system_highpri_wq,
 +                            per_cpu_ptr(&flush_works, cpu));
 +
 +      for_each_online_cpu(cpu)
 +              flush_work(per_cpu_ptr(&flush_works, cpu));
 +
 +      put_online_cpus();
  }
  
  static int napi_gro_complete(struct sk_buff *skb)
@@@ -4831,9 -4805,8 +4831,9 @@@ static bool sd_has_rps_ipi_waiting(stru
  
  static int process_backlog(struct napi_struct *napi, int quota)
  {
 -      int work = 0;
        struct softnet_data *sd = container_of(napi, struct softnet_data, backlog);
 +      bool again = true;
 +      int work = 0;
  
        /* Check if we have pending ipi, its better to send them now,
         * not waiting net_rx_action() end.
        }
  
        napi->weight = weight_p;
 -      local_irq_disable();
 -      while (1) {
 +      while (again) {
                struct sk_buff *skb;
  
                while ((skb = __skb_dequeue(&sd->process_queue))) {
                        rcu_read_lock();
 -                      local_irq_enable();
                        __netif_receive_skb(skb);
                        rcu_read_unlock();
 -                      local_irq_disable();
                        input_queue_head_incr(sd);
 -                      if (++work >= quota) {
 -                              local_irq_enable();
 +                      if (++work >= quota)
                                return work;
 -                      }
 +
                }
  
 +              local_irq_disable();
                rps_lock(sd);
                if (skb_queue_empty(&sd->input_pkt_queue)) {
                        /*
                         * and we dont need an smp_mb() memory barrier.
                         */
                        napi->state = 0;
 -                      rps_unlock(sd);
 -
 -                      break;
 +                      again = false;
 +              } else {
 +                      skb_queue_splice_tail_init(&sd->input_pkt_queue,
 +                                                 &sd->process_queue);
                }
 -
 -              skb_queue_splice_tail_init(&sd->input_pkt_queue,
 -                                         &sd->process_queue);
                rps_unlock(sd);
 +              local_irq_enable();
        }
 -      local_irq_enable();
  
        return work;
  }
@@@ -5193,7 -5171,7 +5193,7 @@@ out_unlock
        return work;
  }
  
- static void net_rx_action(struct softirq_action *h)
+ static __latent_entropy void net_rx_action(struct softirq_action *h)
  {
        struct softnet_data *sd = this_cpu_ptr(&softnet_data);
        unsigned long time_limit = jiffies + 2;
@@@ -6067,7 -6045,8 +6067,7 @@@ void *netdev_lower_dev_get_private(stru
  EXPORT_SYMBOL(netdev_lower_dev_get_private);
  
  
 -int dev_get_nest_level(struct net_device *dev,
 -                     bool (*type_check)(const struct net_device *dev))
 +int dev_get_nest_level(struct net_device *dev)
  {
        struct net_device *lower = NULL;
        struct list_head *iter;
        ASSERT_RTNL();
  
        netdev_for_each_lower_dev(dev, lower, iter) {
 -              nest = dev_get_nest_level(lower, type_check);
 +              nest = dev_get_nest_level(lower);
                if (max_nest < nest)
                        max_nest = nest;
        }
  
 -      if (type_check(dev))
 -              max_nest++;
 -
 -      return max_nest;
 +      return max_nest + 1;
  }
  EXPORT_SYMBOL(dev_get_nest_level);
  
@@@ -6729,8 -6711,8 +6729,8 @@@ static void rollback_registered_many(st
                unlist_netdevice(dev);
  
                dev->reg_state = NETREG_UNREGISTERING;
 -              on_each_cpu(flush_backlog, dev, 1);
        }
 +      flush_all_backlogs();
  
        synchronize_net();
  
@@@ -7647,9 -7629,6 +7647,9 @@@ struct net_device *alloc_netdev_mqs(in
        INIT_LIST_HEAD(&dev->all_adj_list.lower);
        INIT_LIST_HEAD(&dev->ptype_all);
        INIT_LIST_HEAD(&dev->ptype_specific);
 +#ifdef CONFIG_NET_SCHED
 +      hash_init(dev->qdisc_hash);
 +#endif
        dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
        setup(dev);
  
@@@ -8295,11 -8274,8 +8295,11 @@@ static int __init net_dev_init(void
         */
  
        for_each_possible_cpu(i) {
 +              struct work_struct *flush = per_cpu_ptr(&flush_works, i);
                struct softnet_data *sd = &per_cpu(softnet_data, i);
  
 +              INIT_WORK(flush, flush_backlog);
 +
                skb_queue_head_init(&sd->input_pkt_queue);
                skb_queue_head_init(&sd->process_queue);
                INIT_LIST_HEAD(&sd->poll_list);
This page took 0.050319 seconds and 5 git commands to generate.