12 Jul, 2022

1 commit

  • [ Upstream commit d1fe111fb62a1cf0446a2919f5effbb33ad0702c ]

    When the hwpoison page meets the filter conditions, it should not be
    regarded as successful memory_failure() processing for mce handler, but
    should return a distinct value, otherwise mce handler regards the error
    page has been identified and isolated, which may lead to calling
    set_mce_nospec() to change page attribute, etc.

    Here memory_failure() return -EOPNOTSUPP to indicate that the error
    event is filtered, mce handler should not take any action for this
    situation and hwpoison injector should treat as correct.

    Link: https://lkml.kernel.org/r/20220223082135.2769649-1-luofei@unicloud.com
    Signed-off-by: luofei
    Acked-by: Borislav Petkov
    Cc: Dave Hansen
    Cc: H. Peter Anvin
    Cc: Ingo Molnar
    Cc: Miaohe Lin
    Cc: Naoya Horiguchi
    Cc: Thomas Gleixner
    Cc: Tony Luck
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds
    Signed-off-by: Sasha Levin

    luofei
     

04 Sep, 2021

1 commit

  • In the current implementation of soft offline, if non-LRU page is met,
    all the slab caches will be dropped to free the page then offline. But
    if the page is not slab page all the effort is wasted in vain. Even
    though it is a slab page, it is not guaranteed the page could be freed
    at all.

    However the side effect and cost is quite high. It does not only drop
    the slab caches, but also may drop a significant amount of page caches
    which are associated with inode caches. It could make the most
    workingset gone in order to just offline a page. And the offline is not
    guaranteed to succeed at all, actually I really doubt the success rate
    for real life workload.

    Furthermore the worse consequence is the system may be locked up and
    unusable since the page cache release may incur huge amount of works
    queued for memcg release.

    Actually we ran into such unpleasant case in our production environment.
    Firstly, the workqueue of memory_failure_work_func is locked up as
    below:

    BUG: workqueue lockup - pool cpus=1 node=0 flags=0x0 nice=0 stuck for 53s!
    Showing busy workqueues and worker pools:
    workqueue events: flags=0x0
    pwq 2: cpus=1 node=0 flags=0x0 nice=0 active=14/256 refcnt=15
    in-flight: 409271:memory_failure_work_func
    pending: kfree_rcu_work, kfree_rcu_monitor, kfree_rcu_work, rht_deferred_worker, rht_deferred_worker, rht_deferred_worker, rht_deferred_worker, kfree_rcu_work, kfree_rcu_work, kfree_rcu_work, kfree_rcu_work, drain_local_stock, kfree_rcu_work
    workqueue mm_percpu_wq: flags=0x8
    pwq 2: cpus=1 node=0 flags=0x0 nice=0 active=1/256 refcnt=2
    pending: vmstat_update
    workqueue cgroup_destroy: flags=0x0
    pwq 2: cpus=1 node=0 flags=0x0 nice=0 active=1/1 refcnt=12072
    pending: css_release_work_fn

    There were over 12K css_release_work_fn queued, and this caused a few
    lockups due to the contention of worker pool lock with IRQ disabled, for
    example:

    NMI watchdog: Watchdog detected hard LOCKUP on cpu 1
    Modules linked in: amd64_edac_mod edac_mce_amd crct10dif_pclmul crc32_pclmul ghash_clmulni_intel xt_DSCP iptable_mangle kvm_amd bpfilter vfat fat acpi_ipmi i2c_piix4 usb_storage ipmi_si k10temp i2c_core ipmi_devintf ipmi_msghandler acpi_cpufreq sch_fq_codel xfs libcrc32c crc32c_intel mlx5_core mlxfw nvme xhci_pci ptp nvme_core pps_core xhci_hcd
    CPU: 1 PID: 205500 Comm: kworker/1:0 Tainted: G L 5.10.32-t1.el7.twitter.x86_64 #1
    Hardware name: TYAN F5AMT /z /S8026GM2NRE-CGN, BIOS V8.030 03/30/2021
    Workqueue: events memory_failure_work_func
    RIP: 0010:queued_spin_lock_slowpath+0x41/0x1a0
    Code: 41 f0 0f ba 2f 08 0f 92 c0 0f b6 c0 c1 e0 08 89 c2 8b 07 30 e4 09 d0 a9 00 01 ff ff 75 1b 85 c0 74 0e 8b 07 84 c0 74 08 f3 90 07 84 c0 75 f8 b8 01 00 00 00 66 89 07 c3 f6 c4 01 75 04 c6 47
    RSP: 0018:ffff9b2ac278f900 EFLAGS: 00000002
    RAX: 0000000000480101 RBX: ffff8ce98ce71800 RCX: 0000000000000084
    RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff8ce98ce6a140
    RBP: 00000000000284c8 R08: ffffd7248dcb6808 R09: 0000000000000000
    R10: 0000000000000003 R11: ffff9b2ac278f9b0 R12: 0000000000000001
    R13: ffff8cb44dab9c00 R14: ffffffffbd1ce6a0 R15: ffff8cacaa37f068
    FS: 0000000000000000(0000) GS:ffff8ce98ce40000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007fcf6e8cb000 CR3: 0000000a0c60a000 CR4: 0000000000350ee0
    Call Trace:
    __queue_work+0xd6/0x3c0
    queue_work_on+0x1c/0x30
    uncharge_batch+0x10e/0x110
    mem_cgroup_uncharge_list+0x6d/0x80
    release_pages+0x37f/0x3f0
    __pagevec_release+0x1c/0x50
    __invalidate_mapping_pages+0x348/0x380
    inode_lru_isolate+0x10a/0x160
    __list_lru_walk_one+0x7b/0x170
    list_lru_walk_one+0x4a/0x60
    prune_icache_sb+0x37/0x50
    super_cache_scan+0x123/0x1a0
    do_shrink_slab+0x10c/0x2c0
    shrink_slab+0x1f1/0x290
    drop_slab_node+0x4d/0x70
    soft_offline_page+0x1ac/0x5b0
    memory_failure_work_func+0x6a/0x90
    process_one_work+0x19e/0x340
    worker_thread+0x30/0x360
    kthread+0x116/0x130

    The lockup made the machine is quite unusable. And it also made the
    most workingset gone, the reclaimabled slab caches were reduced from 12G
    to 300MB, the page caches were decreased from 17G to 4G.

    But the most disappointing thing is all the effort doesn't make the page
    offline, it just returns:

    soft_offline: 0x1469f2: unknown non LRU page type 5ffff0000000000 ()

    It seems the aggressive behavior for non-LRU page didn't pay back, so it
    doesn't make too much sense to keep it considering the terrible side
    effect.

    Link: https://lkml.kernel.org/r/20210819054116.266126-1-shy828301@gmail.com
    Signed-off-by: Yang Shi
    Reported-by: David Mackey
    Acked-by: David Hildenbrand
    Acked-by: Naoya Horiguchi
    Cc: Oscar Salvador
    Cc: Matthew Wilcox (Oracle)
    Cc: Jonathan Corbet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yang Shi
     

17 Oct, 2020

1 commit

  • Another memory error injection interface debugfs:hwpoison/corrupt-pfn also
    takes bogus refcount for hwpoison_filter(). It's justified because this
    does a coarse filter, expecting that memory_failure() redoes the check for
    sure.

    Signed-off-by: Naoya Horiguchi
    Signed-off-by: Oscar Salvador
    Signed-off-by: Andrew Morton
    Cc: "Aneesh Kumar K.V"
    Cc: Aneesh Kumar K.V
    Cc: Aristeu Rozanski
    Cc: Dave Hansen
    Cc: David Hildenbrand
    Cc: Dmitry Yakunin
    Cc: Michal Hocko
    Cc: Mike Kravetz
    Cc: Oscar Salvador
    Cc: Qian Cai
    Cc: Tony Luck
    Link: https://lkml.kernel.org/r/20200922135650.1634-4-osalvador@suse.de
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     

02 Dec, 2019

1 commit


03 Jun, 2019

1 commit


21 May, 2019

1 commit

  • Add SPDX license identifiers to all files which:

    - Have no license information of any form

    - Have MODULE_LICENCE("GPL*") inside which was used in the initial
    scan/conversion to ignore the file

    These files fall under the project license, GPL v2 only. The resulting SPDX
    license identifier is:

    GPL-2.0-only

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

24 Jan, 2018

1 commit


04 May, 2017

1 commit

  • shake_page() is called before going into core error handling code in
    order to ensure that the error page is flushed from lru_cache lists
    where pages stay during transferring among LRU lists.

    But currently it's not fully functional because when the page is linked
    to lru_cache by calling activate_page(), its PageLRU flag is set and
    shake_page() is skipped. The result is to fail error handling with
    "still referenced by 1 users" message.

    When the page is linked to lru_cache by isolate_lru_page(), its PageLRU
    is clear, so that's fine.

    This patch makes shake_page() unconditionally called to avoild the
    failure.

    Fixes: 23a003bfd23ea9ea0b7756b920e51f64b284b468 ("mm/madvise: pass return code of memory_failure() to userspace")
    Link: http://lkml.kernel.org/r/20170417055948.GM31394@yexl-desktop
    Link: http://lkml.kernel.org/r/1493197841-23986-2-git-send-email-n-horiguchi@ah.jp.nec.com
    Signed-off-by: Naoya Horiguchi
    Reported-by: kernel test robot
    Cc: Xiaolong Ye
    Cc: Chen Gong
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     

11 Sep, 2015

1 commit

  • Hwpoison allows to filter pages by memory cgroup ino. Currently, it
    calls try_get_mem_cgroup_from_page to obtain the cgroup from a page and
    then its ino using cgroup_ino, but now we have a helper method for
    that, page_cgroup_ino, so use it instead.

    This patch also loosens the hwpoison memcg filter dependency rules - it
    makes it depend on CONFIG_MEMCG instead of CONFIG_MEMCG_SWAP, because
    hwpoison memcg filter does not require anything (nor it used to) from
    CONFIG_MEMCG_SWAP side.

    Signed-off-by: Vladimir Davydov
    Reviewed-by: Andres Lagar-Cavilla
    Cc: Minchan Kim
    Cc: Raghavendra K T
    Cc: Johannes Weiner
    Cc: Michal Hocko
    Cc: Greg Thelen
    Cc: Michel Lespinasse
    Cc: David Rientjes
    Cc: Pavel Emelyanov
    Cc: Cyrill Gorcunov
    Cc: Jonathan Corbet
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     

09 Sep, 2015

1 commit

  • Hwpoison injection takes a refcount of target page and another refcount
    of head page of THP if the target page is the tail page of a THP.
    However, current code doesn't release the refcount of head page if the
    THP is not supported to be injected wrt hwpoison filter.

    Fix it by reducing the refcount of head page if the target page is the
    tail page of a THP and it is not supported to be injected.

    Signed-off-by: Wanpeng Li
    Acked-by: Naoya Horiguchi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wanpeng Li
     

25 Jun, 2015

1 commit

  • memory_failure() can run in 2 different mode (specified by
    MF_COUNT_INCREASED) in page refcount perspective. When
    MF_COUNT_INCREASED is set, memory_failure() assumes that the caller
    takes a refcount of the target page. And if cleared, memory_failure()
    takes it in it's own.

    In current code, however, refcounting is done differently in each caller.
    For example, madvise_hwpoison() uses get_user_pages_fast() and
    hwpoison_inject() uses get_page_unless_zero(). So this inconsistent
    refcounting causes refcount failure especially for thp tail pages.
    Typical user visible effects are like memory leak or
    VM_BUG_ON_PAGE(!page_count(page)) in isolate_lru_page().

    To fix this refcounting issue, this patch introduces get_hwpoison_page()
    to handle thp tail pages in the same manner for each caller of hwpoison
    code.

    memory_failure() might fail to split thp and in such case it returns
    without completing page isolation. This is not good because PageHWPoison
    on the thp is still set and there's no easy way to unpoison such thps. So
    this patch try to roll back any action to the thp in "non anonymous thp"
    case and "thp split failed" case, expecting an MCE(SRAR) generated by
    later access afterward will properly free such thps.

    [akpm@linux-foundation.org: fix CONFIG_HWPOISON_INJECT=m]
    Signed-off-by: Naoya Horiguchi
    Cc: Andi Kleen
    Cc: Tony Luck
    Cc: "Kirill A. Shutemov"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     

06 May, 2015

2 commits

  • Hwpoison injector checks PageLRU of the raw target page to find out
    whether the page is an appropriate target, but current code now filters
    out thp tail pages, which prevents us from testing for such cases via this
    interface. So let's check hpage instead of p.

    Signed-off-by: Naoya Horiguchi
    Acked-by: Dean Nelson
    Cc: Andi Kleen
    Cc: Andrea Arcangeli
    Cc: Hidetoshi Seto
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     
  • Hwpoison injection via debugfs:hwpoison/corrupt-pfn takes a refcount of
    the target page. But current code doesn't release it if the target page
    is not supposed to be injected, which results in memory leak. This patch
    simply adds the refcount releasing code.

    Signed-off-by: Naoya Horiguchi
    Acked-by: Dean Nelson
    Cc: Andi Kleen
    Cc: Andrea Arcangeli
    Cc: Hidetoshi Seto
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Naoya Horiguchi
     

07 Aug, 2014

1 commit


22 Jan, 2014

1 commit


01 Oct, 2013

1 commit

  • The lack of one reference count against poisoned page for hwpoison_inject
    w/o hwpoison_filter enabled result in hwpoison detect -1 users still
    referenced the page, however, the number should be 0 except the poison
    handler held one after successfully unmap. This patch fix it by hold one
    referenced count against poisoned page for hwpoison_inject w/ and w/o
    hwpoison_filter enabled.

    Before patch:

    [ 71.902112] Injecting memory failure at pfn 224706
    [ 71.902137] MCE 0x224706: dirty LRU page recovery: Failed
    [ 71.902138] MCE 0x224706: dirty LRU page still referenced by -1 users

    After patch:

    [ 94.710860] Injecting memory failure at pfn 215b68
    [ 94.710885] MCE 0x215b68: dirty LRU page recovery: Recovered

    Reviewed-by: Naoya Horiguchi
    Acked-by: Andi Kleen
    Signed-off-by: Wanpeng Li
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wanpeng Li
     

12 Sep, 2013

1 commit

  • Hwpoison injection doesn't implement read method for
    corrupt-pfn/unpoison-pfn attributes:

    # cat /sys/kernel/debug/hwpoison/corrupt-pfn
    cat: /sys/kernel/debug/hwpoison/corrupt-pfn: Permission denied
    # cat /sys/kernel/debug/hwpoison/unpoison-pfn
    cat: /sys/kernel/debug/hwpoison/unpoison-pfn: Permission denied

    This patch changes the permission of corrupt-pfn/unpoison-pfn to 0200.

    Signed-off-by: Wanpeng Li
    Reviewed-by: Naoya Horiguchi
    Cc: Andi Kleen
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wanpeng Li
     

01 Aug, 2012

1 commit

  • Sanity:

    CONFIG_CGROUP_MEM_RES_CTLR -> CONFIG_MEMCG
    CONFIG_CGROUP_MEM_RES_CTLR_SWAP -> CONFIG_MEMCG_SWAP
    CONFIG_CGROUP_MEM_RES_CTLR_SWAP_ENABLED -> CONFIG_MEMCG_SWAP_ENABLED
    CONFIG_CGROUP_MEM_RES_CTLR_KMEM -> CONFIG_MEMCG_KMEM

    [mhocko@suse.cz: fix missed bits]
    Cc: Glauber Costa
    Acked-by: Michal Hocko
    Cc: Johannes Weiner
    Cc: KAMEZAWA Hiroyuki
    Cc: Hugh Dickins
    Cc: Tejun Heo
    Cc: Aneesh Kumar K.V
    Cc: David Rientjes
    Cc: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     

04 Jan, 2012

1 commit

  • There is only one caller of memory_failure(), all other users call
    __memory_failure() and pass in the flags argument explicitly. The
    lone user of memory_failure() will soon need to pass flags too.

    Add flags argument to the callsite in mce.c. Delete the old memory_failure()
    function, and then rename __memory_failure() without the leading "__".

    Provide clearer message when action optional memory errors are ignored.

    Acked-by: Borislav Petkov
    Signed-off-by: Tony Luck

    Tony Luck
     

31 Mar, 2011

1 commit


11 Aug, 2010

1 commit

  • This patch enables hwpoison injection through debug/hwpoison interfaces,
    with which we can test memory error handling for free or reserved
    hugepages (which cannot be tested by madvise() injector).

    [AK: Export PageHuge too for the injection module]
    Signed-off-by: Naoya Horiguchi
    Cc: Andrew Morton
    Acked-by: Fengguang Wu
    Signed-off-by: Andi Kleen

    Naoya Horiguchi
     

16 Dec, 2009

8 commits

  • Signed-off-by: Andi Kleen

    Andi Kleen
     
  • This is a simpler, gentler variant of memory_failure() for soft page
    offlining controlled from user space. It doesn't kill anything, just
    tries to invalidate and if that doesn't work migrate the
    page away.

    This is useful for predictive failure analysis, where a page has
    a high rate of corrected errors, but hasn't gone bad yet. Instead
    it can be offlined early and avoided.

    The offlining is controlled from sysfs, including a new generic
    entry point for hard page offlining for symmetry too.

    We use the page isolate facility to prevent re-allocation
    race. Normally this is only used by memory hotplug. To avoid
    races with memory allocation I am using lock_system_sleep().
    This avoids the situation where memory hotplug is about
    to isolate a page range and then hwpoison undoes that work.
    This is a big hammer currently, but the simplest solution
    currently.

    When the page is not free or LRU we try to free pages
    from slab and other caches. The slab freeing is currently
    quite dumb and does not try to focus on the specific slab
    cache which might own the page. This could be potentially
    improved later.

    Thanks to Fengguang Wu and Haicheng Li for some fixes.

    [Added fix from Andrew Morton to adapt to new migrate_pages prototype]
    Signed-off-by: Andi Kleen

    Andi Kleen
     
  • In some use cases, user doesn't need extra filtering. E.g. user program
    can inject errors through madvise syscall to its own pages, however it
    might not know what the page state exactly is or which inode the page
    belongs to.

    So introduce an one-off interface "corrupt-filter-enable".

    Echo 0 to switch off page filters, and echo 1 to switch on the filters.
    [AK: changed default to 0]

    Signed-off-by: Haicheng Li
    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Haicheng Li
     
  • The hwpoison test suite need to inject hwpoison to a collection of
    selected task pages, and must not touch pages not owned by them and
    thus kill important system processes such as init. (But it's OK to
    mis-hwpoison free/unowned pages as well as shared clean pages.
    Mis-hwpoison of shared dirty pages will kill all tasks, so the test
    suite will target all or non of such tasks in the first place.)

    The memory cgroup serves this purpose well. We can put the target
    processes under the control of a memory cgroup, and tell the hwpoison
    injection code to only kill pages associated with some active memory
    cgroup.

    The prerequisite for doing hwpoison stress tests with mem_cgroup is,
    the mem_cgroup code tracks task pages _accurately_ (unless page is
    locked). Which we believe is/should be true.

    The benefits are simplification of hwpoison injector code. Also the
    mem_cgroup code will automatically be tested by hwpoison test cases.

    The alternative interfaces pin-pfn/unpin-pfn can also delegate the
    (process and page flags) filtering functions reliably to user space.
    However prototype implementation shows that this scheme adds more
    complexity than we wanted.

    Example test case:

    mkdir /cgroup/hwpoison

    usemem -m 100 -s 1000 &
    echo `jobs -p` > /cgroup/hwpoison/tasks

    memcg_ino=$(ls -id /cgroup/hwpoison | cut -f1 -d' ')
    echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg

    page-types -p `pidof init` --hwpoison # shall do nothing
    page-types -p `pidof usemem` --hwpoison # poison its pages

    [AK: Fix documentation]
    [Add fix for problem noticed by Li Zefan ;
    dentry in the css could be NULL]

    CC: KOSAKI Motohiro
    CC: Hugh Dickins
    CC: Daisuke Nishimura
    CC: Balbir Singh
    CC: KAMEZAWA Hiroyuki
    CC: Li Zefan
    CC: Paul Menage
    CC: Nick Piggin
    CC: Andi Kleen
    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Andi Kleen
     
  • When specified, only poison pages if ((page_flags & mask) == value).

    - corrupt-filter-flags-mask
    - corrupt-filter-flags-value

    This allows stress testing of many kinds of pages.

    Strictly speaking, the buddy pages requires taking zone lock, to avoid
    setting PG_hwpoison on a "was buddy but now allocated to someone" page.
    However we can just do nothing because we set PG_locked in the beginning,
    this prevents the page allocator from allocating it to someone. (It will
    BUG() on the unexpected PG_locked, which is fine for hwpoison testing.)

    [AK: Add select PROC_PAGE_MONITOR to satisfy dependency]

    CC: Nick Piggin
    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Wu Fengguang
     
  • __memory_failure()'s workflow is

    set PG_hwpoison
    //...
    unset PG_hwpoison if didn't pass hwpoison filter

    That could kill unrelated process if it happens to page fault on the
    page with the (temporary) PG_hwpoison. The race should be big enough to
    appear in stress tests.

    Fix it by grabbing the page and checking filter at inject time. This
    also avoids the very noisy "Injecting memory failure..." messages.

    - we don't touch madvise() based injection, because the filters are
    generally not necessary for it.
    - if we want to apply the filters to h/w aided injection, we'd better to
    rearrange the logic in __memory_failure() instead of this patch.

    AK: fix documentation, use drain all, cleanups

    CC: Haicheng Li
    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Wu Fengguang
     
  • Filesystem data/metadata present the most tricky-to-isolate pages.
    It requires careful code review and stress testing to get them right.

    The fs/device filter helps to target the stress tests to some specific
    filesystem pages. The filter condition is block device's major/minor
    numbers:
    - corrupt-filter-dev-major
    - corrupt-filter-dev-minor
    When specified (non -1), only page cache pages that belong to that
    device will be poisoned.

    The filters are checked reliably on the locked and refcounted page.

    Haicheng: clear PG_hwpoison and drop bad page count if filter not OK
    AK: Add documentation

    CC: Haicheng Li
    CC: Nick Piggin
    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Wu Fengguang
     
  • The unpoisoning interface is useful for stress testing tools to
    reclaim poisoned pages (to prevent OOM)

    There is no hardware level unpoisioning, so this
    cannot be used for real memory errors, only for software injected errors.

    Note that it may leak pages silently - those who have been removed from
    LRU cache, but not isolated from page cache/swap cache at hwpoison time.
    Especially the stress test of dirty swap cache pages shall reboot system
    before exhausting memory.

    AK: Fix comments, add documentation, add printks, rename symbol

    Signed-off-by: Wu Fengguang
    Signed-off-by: Andi Kleen

    Wu Fengguang
     

16 Sep, 2009

1 commit