Received: by 10.213.65.68 with SMTP id h4csp264512imn; Fri, 23 Mar 2018 04:15:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELtNp3OLNxCwW3x75SGHqXP/vk4DGiikyT2tt60PHlpRbkBzTpWCewWLEpgS17/Gf4u1tHwI X-Received: by 10.98.236.220 with SMTP id e89mr17879058pfm.173.1521803720604; Fri, 23 Mar 2018 04:15:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521803720; cv=none; d=google.com; s=arc-20160816; b=GprilP8TKVLSiinoWABTzV0WMBLzTXdTbQazEPtMuLzP3nLxSB6FW542GFhszNsiBk s9HaOR8TuD+rVQuLViY9CMEaNsgTrU4RV3YVJYCdzaXWed47YBbdUx7lhMARkOT4+5kN S8UHAQZchpbF0oWOypUGu24FYNIo3/ShR237xAOf4zLewD/Wb5Gd3cgbM/NxiVZLuY4J Y73W18krnSBUtC70ofQMNwoqSNfI2OhdKjqdTjyawS/YEH9o1+vtfuq9ip9gvPdtvA+p JXVdK8zP16aI7qLUSsGHZP3qsG5lOx2mj+7R5EBPlK2oLM5IqRilqA6CtO1LmsSoZTOg QRaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=XQ8fvapTleJwgdy9GEW+1vct8EBU2Wjcmq7a7vVru/8=; b=S+NOS6ZDCG+YOCPnJKvjxJ3/clDL8BJh2Z+Fg+mMZyBuG4qfxAa4f4AsDVJYl99lQL kEl+cBkl273AoLIo62j4bOv0ZbFf1fjxU3w5wEnnrtlHNrY3hYzvGMQ6w5ppdaDM06bH Yc3Dqw4YJlIuitwPeCB6zEXGLHxFFdNH/t8zFDwgOzfNCe9a1QBdZpilfynadh7GcJlY 2WZej0BgFao3G07fgah7yrddGBvpjqjnZzQc9lEhh5QBDvELQePwwh0d17JRV9Aq4NWA R+ufISa2t8tmaS7mqGBTzjS/85VQtGXqDQsZWGv/1YCq7EzJb9iso79pfnLBArtYwyCF h4Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k3si6457424pff.82.2018.03.23.04.15.06; Fri, 23 Mar 2018 04:15:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932696AbeCWKK0 (ORCPT + 99 others); Fri, 23 Mar 2018 06:10:26 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42484 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932681AbeCWKKT (ORCPT ); Fri, 23 Mar 2018 06:10:19 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C92FF1047; Fri, 23 Mar 2018 10:10:18 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , "Peter Zijlstra (Intel)" , Jens Axboe , Sasha Levin Subject: [PATCH 4.9 133/177] block/mq: Cure cpu hotplug lock inversion Date: Fri, 23 Mar 2018 10:54:21 +0100 Message-Id: <20180323094211.086193872@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra [ Upstream commit eabe06595d62cfa9278e2cd012df614bc68a7042 ] By poking at /debug/sched_features I triggered the following splat: [] ====================================================== [] WARNING: possible circular locking dependency detected [] 4.11.0-00873-g964c8b7-dirty #694 Not tainted [] ------------------------------------------------------ [] bash/2109 is trying to acquire lock: [] (cpu_hotplug_lock.rw_sem){++++++}, at: [] static_key_slow_dec+0x1b/0x50 [] [] but task is already holding lock: [] (&sb->s_type->i_mutex_key#4){+++++.}, at: [] sched_feat_write+0x86/0x170 [] [] which lock already depends on the new lock. [] [] [] the existing dependency chain (in reverse order) is: [] [] -> #2 (&sb->s_type->i_mutex_key#4){+++++.}: [] lock_acquire+0x100/0x210 [] down_write+0x28/0x60 [] start_creating+0x5e/0xf0 [] debugfs_create_dir+0x13/0x110 [] blk_mq_debugfs_register+0x21/0x70 [] blk_mq_register_dev+0x64/0xd0 [] blk_register_queue+0x6a/0x170 [] device_add_disk+0x22d/0x440 [] loop_add+0x1f3/0x280 [] loop_init+0x104/0x142 [] do_one_initcall+0x43/0x180 [] kernel_init_freeable+0x1de/0x266 [] kernel_init+0xe/0x100 [] ret_from_fork+0x31/0x40 [] [] -> #1 (all_q_mutex){+.+.+.}: [] lock_acquire+0x100/0x210 [] __mutex_lock+0x6c/0x960 [] mutex_lock_nested+0x1b/0x20 [] blk_mq_init_allocated_queue+0x37c/0x4e0 [] blk_mq_init_queue+0x3a/0x60 [] loop_add+0xe5/0x280 [] loop_init+0x104/0x142 [] do_one_initcall+0x43/0x180 [] kernel_init_freeable+0x1de/0x266 [] kernel_init+0xe/0x100 [] ret_from_fork+0x31/0x40 [] *** DEADLOCK *** [] [] 3 locks held by bash/2109: [] #0: (sb_writers#11){.+.+.+}, at: [] vfs_write+0x17d/0x1a0 [] #1: (debugfs_srcu){......}, at: [] full_proxy_write+0x5d/0xd0 [] #2: (&sb->s_type->i_mutex_key#4){+++++.}, at: [] sched_feat_write+0x86/0x170 [] [] stack backtrace: [] CPU: 9 PID: 2109 Comm: bash Not tainted 4.11.0-00873-g964c8b7-dirty #694 [] Hardware name: Intel Corporation S2600GZ/S2600GZ, BIOS SE5C600.86B.02.02.0002.122320131210 12/23/2013 [] Call Trace: [] lock_acquire+0x100/0x210 [] get_online_cpus+0x2a/0x90 [] static_key_slow_dec+0x1b/0x50 [] static_key_disable+0x20/0x30 [] sched_feat_write+0x131/0x170 [] full_proxy_write+0x97/0xd0 [] __vfs_write+0x28/0x120 [] vfs_write+0xb5/0x1a0 [] SyS_write+0x49/0xa0 [] entry_SYSCALL_64_fastpath+0x23/0xc2 This is because of the cpu hotplug lock rework. Break the chain at #1 by reversing the lock acquisition order. This way i_mutex_key#4 no longer depends on cpu_hotplug_lock and things are good. Cc: Jens Axboe Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- block/blk-mq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2014,15 +2014,15 @@ struct request_queue *blk_mq_init_alloca blk_mq_init_cpu_queues(q, set->nr_hw_queues); - get_online_cpus(); mutex_lock(&all_q_mutex); + get_online_cpus(); list_add_tail(&q->all_q_node, &all_q_list); blk_mq_add_queue_tag_set(set, q); blk_mq_map_swqueue(q, cpu_online_mask); - mutex_unlock(&all_q_mutex); put_online_cpus(); + mutex_unlock(&all_q_mutex); return q;