Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2482113imj; Mon, 18 Feb 2019 06:47:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IY9jQJjz3oMwGIflqcFDShsaqAiiyIOloqZ2bv2grOPA/PI6pI4CrmPJK14X8nt3hfiUuhe X-Received: by 2002:a17:902:8c81:: with SMTP id t1mr26073275plo.107.1550501243233; Mon, 18 Feb 2019 06:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550501243; cv=none; d=google.com; s=arc-20160816; b=e1/7HTmO+EZIxLKcetlPEp+Fdic/OaneiwTGXsNGAtbo4J3cPNyspJk88Tlt/ryETz Ygiqnm4HHx6cQSRqV7XmGy2dmFu2NliSNJ0jvqkA4QJXdnRM52ewVBa6ss/qk88FFrqk HY9ad0dDdFjAQSZlZHLdJKp5t7iIuEZ/dnkXomnHygD8bhpuRyFGonMidIjTAn01cVAz 6I2RU/leq4EV/fSdg+m63YkTY2NXUEMMUJor55VqujhptRadr4IVhoKmiFB1ClG/I/k8 lm3zP0XHDGDN7jlWMemtoNlJ2wDQ4kE10mNJajM+PlWZkDlvbRUpWepWdutQtyuG0dqu FZ1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gk51qKkj28Ta4G4unjuXQxr5SOLI6OXZWtTr67VG9To=; b=0WRlNqnDZee12V8ui/EKqgdhuDbdnLLROXsPEzMe2MuBiGYjLAJnujaAU2ql3AVJbc Ny4AJu+x1AcXdsMpfgShwzlmkhnqL2K6W+2ts3dfZOhihN8KaqOA29kNzdSVuzAt1iMq B7CXQLsujCK1dwCMYaYGMNZBwuQvd/SyHcwd72Qo0d8ghGeo5TzyrhimHOkXcCSk1MmI QL+XYgH7AkXbMhgnj5kR4I9lGYCLzfao4Y4uiueDPvN9skTZUjW2fVWCBipuIP6fk2wp xO5/GLfG9mYRkLWA8hyicq6XLmzU/G/sgiH+fVV6rLq+0CmsgYXi2xNbUS9MPgj+7SdE 2FpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R8BNbBOG; 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 a13si12867318pgq.404.2019.02.18.06.47.07; Mon, 18 Feb 2019 06:47:23 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=R8BNbBOG; 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 S1732105AbfBROpI (ORCPT + 99 others); Mon, 18 Feb 2019 09:45:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:54592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731831AbfBRNry (ORCPT ); Mon, 18 Feb 2019 08:47:54 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E38A0217F5; Mon, 18 Feb 2019 13:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550497673; bh=UWJpD+Oyh6bJ59rPXyzNqLW4Sj/FuoifDrNC8lvwP3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R8BNbBOGXiimu7hDN4A9oyly9N4YkscJl0a4TyxgRedkrZQXh++Lt4lVIfs2znlY6 kum2w72B4zhVLYBkQgt54uwmgAW4FKeVgkgTqqLoCFz+cWYN5HXlMPiKA/OLGvCni8 KzGkNqvs2YI6XTVsHdQFFEduLA6hTNpgUEbq0M/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zachary Hays , Ulf Hansson Subject: [PATCH 4.20 66/92] mmc: block: handle complete_work on separate workqueue Date: Mon, 18 Feb 2019 14:43:09 +0100 Message-Id: <20190218133501.078263427@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133454.668268457@linuxfoundation.org> References: <20190218133454.668268457@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zachary Hays commit dcf6e2e38a1c7ccbc535de5e1d9b14998847499d upstream. The kblockd workqueue is created with the WQ_MEM_RECLAIM flag set. This generates a rescuer thread for that queue that will trigger when the CPU is under heavy load and collect the uncompleted work. In the case of mmc, this creates the possibility of a deadlock when there are multiple partitions on the device as other blk-mq work is also run on the same queue. For example: - worker 0 claims the mmc host to work on partition 1 - worker 1 attempts to claim the host for partition 2 but has to wait for worker 0 to finish - worker 0 schedules complete_work to release the host - rescuer thread is triggered after time-out and collects the dangling work - rescuer thread attempts to complete the work in order starting with claim host - the task to release host is now blocked by a task to claim it and will never be called The above results in multiple hung tasks that lead to failures to mount partitions. Handling complete_work on a separate workqueue avoids this by keeping the work completion tasks separate from the other blk-mq work. This allows the host to be released without getting blocked by other tasks attempting to claim the host. Signed-off-by: Zachary Hays Fixes: 81196976ed94 ("mmc: block: Add blk-mq support") Cc: Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/block.c | 10 +++++++++- include/linux/mmc/card.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2114,7 +2114,7 @@ static void mmc_blk_mq_req_done(struct m if (waiting) wake_up(&mq->wait); else - kblockd_schedule_work(&mq->complete_work); + queue_work(mq->card->complete_wq, &mq->complete_work); return; } @@ -2928,6 +2928,13 @@ static int mmc_blk_probe(struct mmc_card mmc_fixup_device(card, mmc_blk_fixups); + card->complete_wq = alloc_workqueue("mmc_complete", + WQ_MEM_RECLAIM | WQ_HIGHPRI, 0); + if (unlikely(!card->complete_wq)) { + pr_err("Failed to create mmc completion workqueue"); + return -ENOMEM; + } + md = mmc_blk_alloc(card); if (IS_ERR(md)) return PTR_ERR(md); @@ -2991,6 +2998,7 @@ static void mmc_blk_remove(struct mmc_ca pm_runtime_put_noidle(&card->dev); mmc_blk_remove_req(md); dev_set_drvdata(&card->dev, NULL); + destroy_workqueue(card->complete_wq); } static int _mmc_blk_suspend(struct mmc_card *card) --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -308,6 +308,7 @@ struct mmc_card { unsigned int nr_parts; unsigned int bouncesz; /* Bounce buffer size */ + struct workqueue_struct *complete_wq; /* Private workqueue */ }; static inline bool mmc_large_sector(struct mmc_card *card)