)]}'
{
  "commit": "b51ef2ba98251fc7e36d96d274a1f26a898e4be1",
  "tree": "ad166328c04dcfb6b9b53f09b2a8679ae4881f6d",
  "parents": [
    "53bb244b9e95678c6aeae8ff05647410301cf9e0"
  ],
  "author": {
    "name": "Miaohe Lin",
    "email": "linmiaohe@huawei.com",
    "time": "Sun Apr 07 16:54:56 2024 +0800"
  },
  "committer": {
    "name": "Michael Kochera",
    "email": "kochera@google.com",
    "time": "Tue Jun 04 11:13:55 2024 +0000"
  },
  "message": "mm/memory-failure: fix deadlock when hugetlb_optimize_vmemmap is enabled\n\ncommit 1983184c22dd84a4d95a71e5c6775c2638557dc7 upstream.\n\nWhen I did hard offline test with hugetlb pages, below deadlock occurs:\n\n\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\nWARNING: possible circular locking dependency detected\n6.8.0-11409-gf6cef5f8c37f #1 Not tainted\n------------------------------------------------------\nbash/46904 is trying to acquire lock:\nffffffffabe68910 (cpu_hotplug_lock){++++}-{0:0}, at: static_key_slow_dec+0x16/0x60\n\nbut task is already holding lock:\nffffffffabf92ea8 (pcp_batch_high_lock){+.+.}-{3:3}, at: zone_pcp_disable+0x16/0x40\n\nwhich lock already depends on the new lock.\n\nthe existing dependency chain (in reverse order) is:\n\n-\u003e #1 (pcp_batch_high_lock){+.+.}-{3:3}:\n       __mutex_lock+0x6c/0x770\n       page_alloc_cpu_online+0x3c/0x70\n       cpuhp_invoke_callback+0x397/0x5f0\n       __cpuhp_invoke_callback_range+0x71/0xe0\n       _cpu_up+0xeb/0x210\n       cpu_up+0x91/0xe0\n       cpuhp_bringup_mask+0x49/0xb0\n       bringup_nonboot_cpus+0xb7/0xe0\n       smp_init+0x25/0xa0\n       kernel_init_freeable+0x15f/0x3e0\n       kernel_init+0x15/0x1b0\n       ret_from_fork+0x2f/0x50\n       ret_from_fork_asm+0x1a/0x30\n\n-\u003e #0 (cpu_hotplug_lock){++++}-{0:0}:\n       __lock_acquire+0x1298/0x1cd0\n       lock_acquire+0xc0/0x2b0\n       cpus_read_lock+0x2a/0xc0\n       static_key_slow_dec+0x16/0x60\n       __hugetlb_vmemmap_restore_folio+0x1b9/0x200\n       dissolve_free_huge_page+0x211/0x260\n       __page_handle_poison+0x45/0xc0\n       memory_failure+0x65e/0xc70\n       hard_offline_page_store+0x55/0xa0\n       kernfs_fop_write_iter+0x12c/0x1d0\n       vfs_write+0x387/0x550\n       ksys_write+0x64/0xe0\n       do_syscall_64+0xca/0x1e0\n       entry_SYSCALL_64_after_hwframe+0x6d/0x75\n\nother info that might help us debug this:\n\n Possible unsafe locking scenario:\n\n       CPU0                    CPU1\n       ----                    ----\n  lock(pcp_batch_high_lock);\n                               lock(cpu_hotplug_lock);\n                               lock(pcp_batch_high_lock);\n  rlock(cpu_hotplug_lock);\n\n *** DEADLOCK ***\n\n5 locks held by bash/46904:\n #0: ffff98f6c3bb23f0 (sb_writers#5){.+.+}-{0:0}, at: ksys_write+0x64/0xe0\n #1: ffff98f6c328e488 (\u0026of-\u003emutex){+.+.}-{3:3}, at: kernfs_fop_write_iter+0xf8/0x1d0\n #2: ffff98ef83b31890 (kn-\u003eactive#113){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x100/0x1d0\n #3: ffffffffabf9db48 (mf_mutex){+.+.}-{3:3}, at: memory_failure+0x44/0xc70\n #4: ffffffffabf92ea8 (pcp_batch_high_lock){+.+.}-{3:3}, at: zone_pcp_disable+0x16/0x40\n\nstack backtrace:\nCPU: 10 PID: 46904 Comm: bash Kdump: loaded Not tainted 6.8.0-11409-gf6cef5f8c37f #1\nHardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014\nCall Trace:\n \u003cTASK\u003e\n dump_stack_lvl+0x68/0xa0\n check_noncircular+0x129/0x140\n __lock_acquire+0x1298/0x1cd0\n lock_acquire+0xc0/0x2b0\n cpus_read_lock+0x2a/0xc0\n static_key_slow_dec+0x16/0x60\n __hugetlb_vmemmap_restore_folio+0x1b9/0x200\n dissolve_free_huge_page+0x211/0x260\n __page_handle_poison+0x45/0xc0\n memory_failure+0x65e/0xc70\n hard_offline_page_store+0x55/0xa0\n kernfs_fop_write_iter+0x12c/0x1d0\n vfs_write+0x387/0x550\n ksys_write+0x64/0xe0\n do_syscall_64+0xca/0x1e0\n entry_SYSCALL_64_after_hwframe+0x6d/0x75\nRIP: 0033:0x7fc862314887\nCode: 10 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 \u003c48\u003e 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74 24\nRSP: 002b:00007fff19311268 EFLAGS: 00000246 ORIG_RAX: 0000000000000001\nRAX: ffffffffffffffda RBX: 000000000000000c RCX: 00007fc862314887\nRDX: 000000000000000c RSI: 000056405645fe10 RDI: 0000000000000001\nRBP: 000056405645fe10 R08: 00007fc8623d1460 R09: 000000007fffffff\nR10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000c\nR13: 00007fc86241b780 R14: 00007fc862417600 R15: 00007fc862416a00\n\nIn short, below scene breaks the lock dependency chain:\n\n memory_failure\n  __page_handle_poison\n   zone_pcp_disable -- lock(pcp_batch_high_lock)\n   dissolve_free_huge_page\n    __hugetlb_vmemmap_restore_folio\n     static_key_slow_dec\n      cpus_read_lock -- rlock(cpu_hotplug_lock)\n\nFix this by calling drain_all_pages() instead.\n\nThis issue won\u0027t occur until commit a6b40850c442 (\"mm: hugetlb: replace\nhugetlb_free_vmemmap_enabled with a static_key\").  As it introduced\nrlock(cpu_hotplug_lock) in dissolve_free_huge_page() code path while\nlock(pcp_batch_high_lock) is already in the __page_handle_poison().\n\n[linmiaohe@huawei.com: extend comment per Oscar]\n[akpm@linux-foundation.org: reflow block comment]\nBUG\u003db/342562980\nTEST\u003dpresubmit\nRELEASE_NOTE\u003dFixes CVE-2024-26987 in the Linux kernel\n\ncos-patch: security-moderate\nLink: https://lkml.kernel.org/r/20240407085456.2798193-1-linmiaohe@huawei.com\nFixes: a6b40850c442 (\"mm: hugetlb: replace hugetlb_free_vmemmap_enabled with a static_key\")\nChange-Id: Ibf9ab6d3d7b71c22322fe5cba4b6ed8e4b9d5ddd\nSigned-off-by: Miaohe Lin \u003clinmiaohe@huawei.com\u003e\nAcked-by: Oscar Salvador \u003cosalvador@suse.de\u003e\nReviewed-by: Jane Chu \u003cjane.chu@oracle.com\u003e\nCc: Naoya Horiguchi \u003cnao.horiguchi@gmail.com\u003e\nCc: \u003cstable@vger.kernel.org\u003e\nSigned-off-by: Andrew Morton \u003cakpm@linux-foundation.org\u003e\nSigned-off-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\nSigned-off-by: Michael Kochera \u003ckochera@google.com\u003e\nReviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/73156\nTested-by: Cusky Presubmit Bot \u003cpresubmit@cos-infra-prod.iam.gserviceaccount.com\u003e\nReviewed-by: Oleksandr Tymoshenko \u003covt@google.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "5b846ed5dcbe91aff726b461971fe7741a998aca",
      "old_mode": 33188,
      "old_path": "mm/memory-failure.c",
      "new_id": "be58ce99925951f393917b1a2299de5656af70c5",
      "new_mode": 33188,
      "new_path": "mm/memory-failure.c"
    }
  ]
}
