1. 09 Nov, 2021 18 commits
    • Andy Shevchenko's avatar
      include/linux/llist.h: replace kernel.h with the necessary inclusions · 50b09d61
      Andy Shevchenko authored
      When kernel.h is used in the headers it adds a lot into dependency hell,
      especially when there are circular dependencies are involved.
      
      Replace kernel.h inclusion with the list of what is really being used.
      
      Link: https://lkml.kernel.org/r/20211013170417.87909-6-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Brendan Higgins <brendanhiggins@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thorsten Leemhuis <regressions@leemhuis.info>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      50b09d61
    • Andy Shevchenko's avatar
      include/linux/list.h: replace kernel.h with the necessary inclusions · cd7187e1
      Andy Shevchenko authored
      When kernel.h is used in the headers it adds a lot into dependency hell,
      especially when there are circular dependencies are involved.
      
      Replace kernel.h inclusion with the list of what is really being used.
      
      Link: https://lkml.kernel.org/r/20211013170417.87909-5-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Brendan Higgins <brendanhiggins@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thorsten Leemhuis <regressions@leemhuis.info>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      cd7187e1
    • Andy Shevchenko's avatar
      include/kunit/test.h: replace kernel.h with the necessary inclusions · ec54c289
      Andy Shevchenko authored
      When kernel.h is used in the headers it adds a lot into dependency hell,
      especially when there are circular dependencies are involved.
      
      Replace kernel.h inclusion with the list of what is really being used.
      
      Link: https://lkml.kernel.org/r/20211013170417.87909-4-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Brendan Higgins <brendanhiggins@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thorsten Leemhuis <regressions@leemhuis.info>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ec54c289
    • Andy Shevchenko's avatar
      kernel.h: split out container_of() and typeof_member() macros · d2a8ebbf
      Andy Shevchenko authored
      kernel.h is being used as a dump for all kinds of stuff for a long time.
      Here is the attempt cleaning it up by splitting out container_of() and
      typeof_member() macros.
      
      For time being include new header back to kernel.h to avoid twisted
      indirected includes for existing users.
      
      Note, there are _a lot_ of headers and modules that include kernel.h
      solely for one of these macros and this allows to unburden compiler for
      the twisted inclusion paths and to make new code cleaner in the future.
      
      Link: https://lkml.kernel.org/r/20211013170417.87909-3-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Brendan Higgins <brendanhiggins@google.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Thorsten Leemhuis <regressions@leemhuis.info>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d2a8ebbf
    • Andy Shevchenko's avatar
      kernel.h: drop unneeded <linux/kernel.h> inclusion from other headers · f5d80614
      Andy Shevchenko authored
      Patch series "kernel.h further split", v5.
      
      kernel.h is a set of something which is not related to each other and
      often used in non-crossed compilation units, especially when drivers
      need only one or two macro definitions from it.
      
      This patch (of 7):
      
      There is no evidence we need kernel.h inclusion in certain headers.
      Drop unneeded <linux/kernel.h> inclusion from other headers.
      
      [sfr@canb.auug.org.au: bottom_half.h needs kernel]
        Link: https://lkml.kernel.org/r/20211015202908.1c417ae2@canb.auug.org.au
      
      Link: https://lkml.kernel.org/r/20211013170417.87909-1-andriy.shevchenko@linux.intel.com
      Link: https://lkml.kernel.org/r/20211013170417.87909-2-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Brendan Higgins <brendanhiggins@google.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Cc: Waiman Long <longman@redhat.com>
      Cc: Boqun Feng <boqun.feng@gmail.com>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
      Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
      Cc: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
      Cc: Jonathan Cameron <jic23@kernel.org>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Thorsten Leemhuis <regressions@leemhuis.info>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      f5d80614
    • Stephen Brennan's avatar
      proc: allow pid_revalidate() during LOOKUP_RCU · da4d6b9c
      Stephen Brennan authored
      Problem Description:
      
      When running running ~128 parallel instances of
      
        TZ=/etc/localtime ps -fe >/dev/null
      
      on a 128CPU machine, the %sys utilization reaches 97%, and perf shows
      the following code path as being responsible for heavy contention on the
      d_lockref spinlock:
      
            walk_component()
              lookup_fast()
                d_revalidate()
                  pid_revalidate() // returns -ECHILD
                unlazy_child()
                  lockref_get_not_dead(&nd->path.dentry->d_lockref) <-- contention
      
      The reason is that pid_revalidate() is triggering a drop from RCU to ref
      path walk mode.  All concurrent path lookups thus try to grab a
      reference to the dentry for /proc/, before re-executing pid_revalidate()
      and then stepping into the /proc/$pid directory.  Thus there is huge
      spinlock contention.
      
      This patch allows pid_revalidate() to execute in RCU mode, meaning that
      the path lookup can successfully enter the /proc/$pid directory while
      still in RCU mode.  Later on, the path lookup may still drop into ref
      mode, but the contention will be much reduced at this point.
      
      By applying this patch, %sys utilization falls to around 85% under the
      same workload, and the number of ps processes executed per unit time
      increases by 3x-4x.  Although this particular workload is a bit
      contrived, we have seen some large collections of eager monitoring
      scripts which produced similarly high %sys time due to contention in the
      /proc directory.
      
      As a result this patch, Al noted that several procfs methods which were
      only called in ref-walk mode could now be called from RCU mode.  To
      ensure that this patch is safe, I audited all the inode get_link and
      permission() implementations, as well as dentry d_revalidate()
      implementations, in fs/proc.  The purpose here is to ensure that they
      either are safe to call in RCU (i.e.  don't sleep) or correctly bail out
      of RCU mode if they don't support it.  My analysis shows that all
      at-risk procfs methods are safe to call under RCU, and thus this patch
      is safe.
      
      Procfs RCU-walk Analysis:
      
      This analysis is up-to-date with 5.15-rc3.  When called under RCU mode,
      these functions have arguments as follows:
      
      * get_link() receives a NULL dentry pointer when called in RCU mode.
      * permission() receives MAY_NOT_BLOCK in the mode parameter when called
        from RCU.
      * d_revalidate() receives LOOKUP_RCU in flags.
      
      For the following functions, either they are trivially RCU safe, or they
      explicitly bail at the beginning of the function when they run:
      
      proc_ns_get_link       (bails out)
      proc_get_link          (RCU safe)
      proc_pid_get_link      (bails out)
      map_files_d_revalidate (bails out)
      map_misc_d_revalidate  (bails out)
      proc_net_d_revalidate  (RCU safe)
      proc_sys_revalidate    (bails out, also not under /proc/$pid)
      tid_fd_revalidate      (bails out)
      proc_sys_permission    (not under /proc/$pid)
      
      The remainder of the functions require a bit more detail:
      
      * proc_fd_permission: RCU safe. All of the body of this function is
        under rcu_read_lock(), except generic_permission() which declares
        itself RCU safe in its documentation string.
      * proc_self_get_link uses GFP_ATOMIC in the RCU case, so it is RCU aware
        and otherwise looks safe. The same is true of proc_thread_self_get_link.
      * proc_map_files_get_link: calls ns_capable, which calls capable(), and
        thus calls into the audit code (see note #1 below). The remainder is
        just a call to the trivially safe proc_pid_get_link().
      * proc_pid_permission: calls ptrace_may_access(), which appears RCU
        safe, although it does call into the "security_ptrace_access_check()"
        hook, which looks safe under smack and selinux. Just the audit code is
        of concern. Also uses get_task_struct() and put_task_struct(), see
        note #2 below.
      * proc_tid_comm_permission: Appears safe, though calls put_task_struct
        (see note #2 below).
      
      Note #1:
        Most of the concern of RCU safety has centered around the audit code.
        However, since b17ec22f ("selinux: slow_avc_audit has become
        non-blocking"), it's safe to call this code under RCU. So all of the
        above are safe by my estimation.
      
      Note #2: get_task_struct() and put_task_struct():
        The majority of get_task_struct() is under RCU read lock, and in any
        case it is a simple increment. But put_task_struct() is complex, given
        that it could at some point free the task struct, and this process has
        many steps which I couldn't manually verify. However, several other
        places call put_task_struct() under RCU, so it appears safe to use
        here too (see kernel/hung_task.c:165 or rcu/tree-stall.h:296)
      
      Patch description:
      
      pid_revalidate() drops from RCU into REF lookup mode.  When many threads
      are resolving paths within /proc in parallel, this can result in heavy
      spinlock contention on d_lockref as each thread tries to grab a
      reference to the /proc dentry (and drop it shortly thereafter).
      
      Investigation indicates that it is not necessary to drop RCU in
      pid_revalidate(), as no RCU data is modified and the function never
      sleeps.  So, remove the LOOKUP_RCU check.
      
      Link: https://lkml.kernel.org/r/20211004175629.292270-2-stephen.s.brennan@oracle.comSigned-off-by: default avatarStephen Brennan <stephen.s.brennan@oracle.com>
      Cc: Konrad Wilk <konrad.wilk@oracle.com>
      Cc: Alexander Viro <viro@zeniv.linux.org.uk>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Alexey Dobriyan <adobriyan@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      da4d6b9c
    • David Hildenbrand's avatar
      virtio-mem: kdump mode to sanitize /proc/vmcore access · ce281462
      David Hildenbrand authored
      Although virtio-mem currently supports reading unplugged memory in the
      hypervisor, this will change in the future, indicated to the device via
      a new feature flag.
      
      We similarly sanitized /proc/kcore access recently.  [1]
      
      Let's register a vmcore callback, to allow vmcore code to check if a PFN
      belonging to a virtio-mem device is either currently plugged and should
      be dumped or is currently unplugged and should not be accessed, instead
      mapping the shared zeropage or returning zeroes when reading.
      
      This is important when not capturing /proc/vmcore via tools like
      "makedumpfile" that can identify logically unplugged virtio-mem memory
      via PG_offline in the memmap, but simply by e.g., copying the file.
      
      Distributions that support virtio-mem+kdump have to make sure that the
      virtio_mem module will be part of the kdump kernel or the kdump initrd;
      dracut was recently [2] extended to include virtio-mem in the generated
      initrd.  As long as no special kdump kernels are used, this will
      automatically make sure that virtio-mem will be around in the kdump
      initrd and sanitize /proc/vmcore access -- with dracut.
      
      With this series, we'll send one virtio-mem state request for every ~2
      MiB chunk of virtio-mem memory indicated in the vmcore that we intend to
      read/map.
      
      In the future, we might want to allow building virtio-mem for kdump mode
      only, even without CONFIG_MEMORY_HOTPLUG and friends: this way, we could
      support special stripped-down kdump kernels that have many other config
      options disabled; we'll tackle that once required.  Further, we might
      want to try sensing bigger blocks (e.g., memory sections) first before
      falling back to device blocks on demand.
      
      Tested with Fedora rawhide, which contains a recent kexec-tools version
      (considering "System RAM (virtio_mem)" when creating the vmcore header)
      and a recent dracut version (including the virtio_mem module in the
      kdump initrd).
      
      Link: https://lkml.kernel.org/r/20210526093041.8800-1-david@redhat.com [1]
      Link: https://github.com/dracutdevs/dracut/pull/1157 [2]
      Link: https://lkml.kernel.org/r/20211005121430.30136-10-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ce281462
    • David Hildenbrand's avatar
      virtio-mem: factor out hotplug specifics from virtio_mem_remove() into virtio_mem_deinit_hotplug() · ffc763d0
      David Hildenbrand authored
      Let's prepare for a new virtio-mem kdump mode in which we don't actually
      hot(un)plug any memory but only observe the state of device blocks.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-9-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      ffc763d0
    • David Hildenbrand's avatar
      virtio-mem: factor out hotplug specifics from virtio_mem_probe() into virtio_mem_init_hotplug() · 84e17e68
      David Hildenbrand authored
      Let's prepare for a new virtio-mem kdump mode in which we don't actually
      hot(un)plug any memory but only observe the state of device blocks.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-8-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      84e17e68
    • David Hildenbrand's avatar
      virtio-mem: factor out hotplug specifics from virtio_mem_init() into virtio_mem_init_hotplug() · 94300fcf
      David Hildenbrand authored
      Let's prepare for a new virtio-mem kdump mode in which we don't actually
      hot(un)plug any memory but only observe the state of device blocks.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-7-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      94300fcf
    • David Hildenbrand's avatar
      proc/vmcore: convert oldmem_pfn_is_ram callback to more generic vmcore callbacks · cc5f2704
      David Hildenbrand authored
      Let's support multiple registered callbacks, making sure that
      registering vmcore callbacks cannot fail.  Make the callback return a
      bool instead of an int, handling how to deal with errors internally.
      Drop unused HAVE_OLDMEM_PFN_IS_RAM.
      
      We soon want to make use of this infrastructure from other drivers:
      virtio-mem, registering one callback for each virtio-mem device, to
      prevent reading unplugged virtio-mem memory.
      
      Handle it via a generic vmcore_cb structure, prepared for future
      extensions: for example, once we support virtio-mem on s390x where the
      vmcore is completely constructed in the second kernel, we want to detect
      and add plugged virtio-mem memory ranges to the vmcore in order for them
      to get dumped properly.
      
      Handle corner cases that are unexpected and shouldn't happen in sane
      setups: registering a callback after the vmcore has already been opened
      (warn only) and unregistering a callback after the vmcore has already been
      opened (warn and essentially read only zeroes from that point on).
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-6-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      cc5f2704
    • David Hildenbrand's avatar
      proc/vmcore: let pfn_is_ram() return a bool · 2c9feeae
      David Hildenbrand authored
      The callback should deal with errors internally, it doesn't make sense
      to expose these via pfn_is_ram().  We'll rework the callbacks next.
      Right now we consider errors as if "it's RAM"; no functional change.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-5-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      2c9feeae
    • David Hildenbrand's avatar
      x86/xen: print a warning when HVMOP_get_mem_type fails · 934fadf4
      David Hildenbrand authored
      HVMOP_get_mem_type is not expected to fail, "This call failing is
      indication of something going quite wrong and it would be good to know
      about this." [1]
      
      Let's add a pr_warn_once().
      
      Link: https://lkml.kernel.org/r/3b935aa0-6d85-0bcd-100e-15098add3c4c@oracle.com [1]
      Link: https://lkml.kernel.org/r/20211005121430.30136-4-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Suggested-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      934fadf4
    • David Hildenbrand's avatar
      x86/xen: simplify xen_oldmem_pfn_is_ram() · d452a489
      David Hildenbrand authored
      Let's simplify return handling.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-3-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      d452a489
    • David Hildenbrand's avatar
      x86/xen: update xen_oldmem_pfn_is_ram() documentation · 434b90f3
      David Hildenbrand authored
      After removing /dev/kmem, sanitizing /proc/kcore and handling /dev/mem,
      this series tackles the last sane way how a VM could accidentially
      access logically unplugged memory managed by a virtio-mem device:
      /proc/vmcore
      
      When dumping memory via "makedumpfile", PG_offline pages, used by
      virtio-mem to flag logically unplugged memory, are already properly
      excluded; however, especially when accessing/copying /proc/vmcore "the
      usual way", we can still end up reading logically unplugged memory part
      of a virtio-mem device.
      
      Patch #1-#3 are cleanups.  Patch #4 extends the existing
      oldmem_pfn_is_ram mechanism.  Patch #5-#7 are virtio-mem refactorings
      for patch #8, which implements the virtio-mem logic to query the state
      of device blocks.
      
      Patch #8:
       "Although virtio-mem currently supports reading unplugged memory in the
        hypervisor, this will change in the future, indicated to the device
        via a new feature flag. We similarly sanitized /proc/kcore access
        recently.
        [...]
        Distributions that support virtio-mem+kdump have to make sure that the
        virtio_mem module will be part of the kdump kernel or the kdump
        initrd; dracut was recently [2] extended to include virtio-mem in the
        generated initrd. As long as no special kdump kernels are used, this
        will automatically make sure that virtio-mem will be around in the
        kdump initrd and sanitize /proc/vmcore access -- with dracut"
      
      This is the last remaining bit to support
      VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE [3] in the Linux implementation of
      virtio-mem.
      
      Note: this is best-effort.  We'll never be able to control what runs
      inside the second kernel, really, but we also don't have to care: we
      only care about sane setups where we don't want our VM getting zapped
      once we touch the wrong memory location while dumping.  While we usually
      expect sane setups to use "makedumfile", nothing really speaks against
      just copying /proc/vmcore, especially in environments where HWpoisioning
      isn't typically expected.  Also, we really don't want to put all our
      trust completely on the memmap, so sanitizing also makes sense when just
      using "makedumpfile".
      
      [1] https://lkml.kernel.org/r/20210526093041.8800-1-david@redhat.com
      [2] https://github.com/dracutdevs/dracut/pull/1157
      [3] https://lists.oasis-open.org/archives/virtio-comment/202109/msg00021.html
      
      This patch (of 9):
      
      The callback is only used for the vmcore nowadays.
      
      Link: https://lkml.kernel.org/r/20211005121430.30136-1-david@redhat.com
      Link: https://lkml.kernel.org/r/20211005121430.30136-2-david@redhat.comSigned-off-by: default avatarDavid Hildenbrand <david@redhat.com>
      Reviewed-by: default avatarBoris Ostrovsky <boris.ostrvsky@oracle.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Juergen Gross <jgross@suse.com>
      Cc: Stefano Stabellini <sstabellini@kernel.org>
      Cc: "Michael S. Tsirkin" <mst@redhat.com>
      Cc: Jason Wang <jasowang@redhat.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: Oscar Salvador <osalvador@suse.de>
      Cc: Mike Rapoport <rppt@kernel.org>
      Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      434b90f3
    • Florian Weimer's avatar
      procfs: do not list TID 0 in /proc/<pid>/task · 0658a096
      Florian Weimer authored
      If a task exits concurrently, task_pid_nr_ns may return 0.
      
      [akpm@linux-foundation.org: coding style tweaks]
      [adobriyan@gmail.com: test that /proc/*/task doesn't contain "0"]
        Link: https://lkml.kernel.org/r/YV88AnVzHxPafQ9o@localhost.localdomain
      
      Link: https://lkml.kernel.org/r/8735pn5dx7.fsf@oldenburg.str.redhat.comSigned-off-by: default avatarFlorian Weimer <fweimer@redhat.com>
      Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
      Acked-by: default avatarChristian Brauner <christian.brauner@ubuntu.com>
      Reviewed-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      0658a096
    • zhangyiru's avatar
      mm,hugetlb: remove mlock ulimit for SHM_HUGETLB · 83c1fd76
      zhangyiru authored
      Commit 21a3c273 ("mm, hugetlb: add thread name and pid to
      SHM_HUGETLB mlock rlimit warning") marked this as deprecated in 2012,
      but it is not deleted yet.
      
      Mike says he still sees that message in log files on occasion, so maybe we
      should preserve this warning.
      
      Also remove hugetlbfs related user_shm_unlock in ipc/shm.c and remove the
      user_shm_unlock after out.
      
      Link: https://lkml.kernel.org/r/20211103105857.25041-1-zhangyiru3@huawei.comSigned-off-by: default avatarzhangyiru <zhangyiru3@huawei.com>
      Reviewed-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Hugh Dickins <hughd@google.com>
      Cc: Liu Zixian <liuzixian4@huawei.com>
      Cc: Michal Hocko <mhocko@suse.com>
      Cc: wuxu.wu <wuxu.wu@huawei.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      83c1fd76
    • Johannes Weiner's avatar
      vfs: keep inodes with page cache off the inode shrinker LRU · 51b8c1fe
      Johannes Weiner authored
      Historically (pre-2.5), the inode shrinker used to reclaim only empty
      inodes and skip over those that still contained page cache.  This caused
      problems on highmem hosts: struct inode could put fill lowmem zones
      before the cache was getting reclaimed in the highmem zones.
      
      To address this, the inode shrinker started to strip page cache to
      facilitate reclaiming lowmem.  However, this comes with its own set of
      problems: the shrinkers may drop actively used page cache just because
      the inodes are not currently open or dirty - think working with a large
      git tree.  It further doesn't respect cgroup memory protection settings
      and can cause priority inversions between containers.
      
      Nowadays, the page cache also holds non-resident info for evicted cache
      pages in order to detect refaults.  We've come to rely heavily on this
      data inside reclaim for protecting the cache workingset and driving swap
      behavior.  We also use it to quantify and report workload health through
      psi.  The latter in turn is used for fleet health monitoring, as well as
      driving automated memory sizing of workloads and containers, proactive
      reclaim and memory offloading schemes.
      
      The consequences of dropping page cache prematurely is that we're seeing
      subtle and not-so-subtle failures in all of the above-mentioned
      scenarios, with the workload generally entering unexpected thrashing
      states while losing the ability to reliably detect it.
      
      To fix this on non-highmem systems at least, going back to rotating
      inodes on the LRU isn't feasible.  We've tried (commit a76cf1a4
      ("mm: don't reclaim inodes with many attached pages")) and failed
      (commit 69056ee6 ("Revert "mm: don't reclaim inodes with many
      attached pages"")).
      
      The issue is mostly that shrinker pools attract pressure based on their
      size, and when objects get skipped the shrinkers remember this as
      deferred reclaim work.  This accumulates excessive pressure on the
      remaining inodes, and we can quickly eat into heavily used ones, or
      dirty ones that require IO to reclaim, when there potentially is plenty
      of cold, clean cache around still.
      
      Instead, this patch keeps populated inodes off the inode LRU in the
      first place - just like an open file or dirty state would.  An otherwise
      clean and unused inode then gets queued when the last cache entry
      disappears.  This solves the problem without reintroducing the reclaim
      issues, and generally is a bit more scalable than having to wade through
      potentially hundreds of thousands of busy inodes.
      
      Locking is a bit tricky because the locks protecting the inode state
      (i_lock) and the inode LRU (lru_list.lock) don't nest inside the
      irq-safe page cache lock (i_pages.xa_lock).  Page cache deletions are
      serialized through i_lock, taken before the i_pages lock, to make sure
      depopulated inodes are queued reliably.  Additions may race with
      deletions, but we'll check again in the shrinker.  If additions race
      with the shrinker itself, we're protected by the i_lock: if find_inode()
      or iput() win, the shrinker will bail on the elevated i_count or
      I_REFERENCED; if the shrinker wins and goes ahead with the inode, it
      will set I_FREEING and inhibit further igets(), which will cause the
      other side to create a new instance of the inode instead.
      
      Link: https://lkml.kernel.org/r/20210614211904.14420-4-hannes@cmpxchg.orgSigned-off-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
      Cc: Roman Gushchin <guro@fb.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Dave Chinner <david@fromorbit.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      51b8c1fe
  2. 06 Nov, 2021 22 commits