From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f71.google.com (mail-lf0-f71.google.com [209.85.215.71]) by kanga.kvack.org (Postfix) with ESMTP id 0B6FD6B0005 for ; Mon, 23 May 2016 13:14:46 -0400 (EDT) Received: by mail-lf0-f71.google.com with SMTP id s130so55079620lfs.2 for ; Mon, 23 May 2016 10:14:45 -0700 (PDT) Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com. [2a00:1450:400c:c09::241]) by mx.google.com with ESMTPS id z6si45443327wjc.228.2016.05.23.10.14.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 10:14:44 -0700 (PDT) Received: by mail-wm0-x241.google.com with SMTP id 67so17065466wmg.0 for ; Mon, 23 May 2016 10:14:44 -0700 (PDT) From: Ebru Akagunduz Subject: [PATCH 2/3] mm, thp: fix possible circular locking dependency caused by sum_vm_event() Date: Mon, 23 May 2016 20:14:10 +0300 Message-Id: <1464023651-19420-3-git-send-email-ebru.akagunduz@gmail.com> In-Reply-To: <1464023651-19420-1-git-send-email-ebru.akagunduz@gmail.com> References: <1464023651-19420-1-git-send-email-ebru.akagunduz@gmail.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: hughd@google.com, riel@redhat.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, n-horiguchi@ah.jp.nec.com, aarcange@redhat.com, iamjoonsoo.kim@lge.com, gorcunov@openvz.org, linux-kernel@vger.kernel.org, mgorman@suse.de, rientjes@google.com, vbabka@suse.cz, aneesh.kumar@linux.vnet.ibm.com, hannes@cmpxchg.org, mhocko@suse.cz, boaz@plexistor.com, Ebru Akagunduz Nested circular locking dependency detected by kernel robot (udevadm). udevadm/221 is trying to acquire lock: (&mm->mmap_sem){++++++}, at: [] __might_fault+0x83/0x150 but task is already holding lock: (s_active#12){++++.+}, at: [] kernfs_fop_write+0x8e/0x250 which lock already depends on the new lock. Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(s_active); lock(cpu_hotplug.lock); lock(s_active); lock(&mm->mmap_sem); the existing dependency chain (in reverse order) is: -> #2 (s_active#12){++++.+}: [] lock_acquire+0xac/0x180 [] __kernfs_remove+0x2da/0x410 [] kernfs_remove_by_name_ns+0x40/0x90 [] sysfs_remove_file_ns+0x2b/0x70 [] device_del+0x166/0x320 [] device_destroy+0x3c/0x50 [] cpuid_class_cpu_callback+0x51/0x70 [] notifier_call_chain+0x59/0x190 [] __raw_notifier_call_chain+0x9/0x10 [] __cpu_notify+0x40/0x90 [] cpu_notify_nofail+0x10/0x30 [] notify_dead+0x27/0x1e0 [] cpuhp_down_callbacks+0x93/0x190 [] _cpu_down+0xc2/0x1e0 [] do_cpu_down+0x37/0x50 [] cpu_down+0xb/0x10 [] _debug_hotplug_cpu+0x7d/0xd0 [] debug_hotplug_cpu+0xd/0x11 [] do_one_initcall+0x138/0x1cf [] kernel_init_freeable+0x24d/0x2de [] kernel_init+0xa/0x120 [] ret_from_fork+0x22/0x50 -> #1 (cpu_hotplug.lock#2){+.+.+.}: [] lock_acquire+0xac/0x180 [] mutex_lock_nested+0x71/0x4c0 [] get_online_cpus+0x66/0x80 [] sum_vm_event+0x23/0x1b0 [] collapse_huge_page+0x118/0x10b0 [] khugepaged+0x55d/0xe80 [] kthread+0x134/0x1a0 [] ret_from_fork+0x22/0x50 -> #0 (&mm->mmap_sem){++++++}: [] __lock_acquire+0x2861/0x31f0 [] lock_acquire+0xac/0x180 [] __might_fault+0xbe/0x150 [] kernfs_fop_write+0xaf/0x250 [] __vfs_write+0x43/0x1a0 [] vfs_write+0xda/0x240 [] SyS_write+0x44/0xa0 [] entry_SYSCALL_64_fastpath+0x1f/0xbd This patch moves sum_vm_event() before taking down_write(&mm->mmap_sem) to solve dependency lock. Signed-off-by: Ebru Akagunduz --- mm/huge_memory.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 91442a9..feee44c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2451,6 +2451,9 @@ static void collapse_huge_page(struct mm_struct *mm, goto out_nolock; } + swap = get_mm_counter(mm, MM_SWAPENTS); + curr_allocstall = sum_vm_event(ALLOCSTALL); + /* * Prevent all access to pagetables with the exception of * gup_fast later hanlded by the ptep_clear_flush and the VM @@ -2483,8 +2486,6 @@ static void collapse_huge_page(struct mm_struct *mm, goto out; } - swap = get_mm_counter(mm, MM_SWAPENTS); - curr_allocstall = sum_vm_event(ALLOCSTALL); /* * Don't perform swapin readahead when the system is under pressure, * to avoid unnecessary resource consumption. -- 1.9.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org