Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp673668ybh; Tue, 10 Mar 2020 06:15:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvEklOA2FE0UElDhLlbDKn1Vg864TEkXj95skf5SZxV+IlVpqi6H6i8g4v6dpb26oIRG7Qa X-Received: by 2002:a9d:6a82:: with SMTP id l2mr17238648otq.312.1583846135464; Tue, 10 Mar 2020 06:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583846135; cv=none; d=google.com; s=arc-20160816; b=HgF5u8/Jqz8OFqPLui0Wj7lbTFTbG0ka1GWZOhng6yoHl2ZTP8E9ZfwTADVAkZo3mh 0riUunwiOMQvrEiCNf8lkngyngyGYUOhCHSspX+6fWVwY78Gh+UV8yhIAMNXTe5ij5OA DFAuWWT5V+VYWm/IQcL0O+pG8+Nw9XAdbcKR5hxuexzX1eXavLSqiLhANig+61ODislT AtYEse/8z08+kFdn1RWhd+PUWJDXemu6UhJRB3bU+vEbo7RnOmw6ChWzZH19d0ozG56d BxgNuRNmbJRZf9y00EW4yG6trSZ5IomS+mm+VrUBcplir7aMyi6nCf97ORLYPc4Xs4q0 5V7g== 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=i95yAnyJZ8yVaHs0qsLmSj3bKzscJ5SpRYeAroteJns=; b=tUeG2M4ooblYCrS4mmmi2DXzHGb4TO7frdO0uIUmFfzvYBMBq4y1Xp/mRmZdaVgGHm T3YjnpJAqTTy2aM7uwnIfvPQGerqIR8pGarDViLVoOG5qO9b0fZLSXTH2b/DlNdOBkOm BRx9OwyMq3uzreT03E9gRiWJU9teFBddM3bTboz7yQGOL/noURrkzzQdul1HYBKdMMAg lvFQLQja4E9bJkqe0Y2Iu4DKIXWD6Dm/hHLgxO9w4DPB+Ug+EP65XHahrjhag4+/COjd 4oxgycSfhnFeAdRcUhRykNkHGPj7pkY8muOE7CHExkhB5O2OTztFZ6Q3g7btkSRh4Vll cO9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0avQhl6G; 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 w4si6740oie.124.2020.03.10.06.15.23; Tue, 10 Mar 2020 06:15:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b=0avQhl6G; 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 S1731952AbgCJNO5 (ORCPT + 99 others); Tue, 10 Mar 2020 09:14:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:39052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731938AbgCJNOx (ORCPT ); Tue, 10 Mar 2020 09:14:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 823CD2467D; Tue, 10 Mar 2020 13:14:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583846093; bh=LOH85/x3D4YpyOFgIuC3ZBsEchD+aCjhnBXoY9/o9eM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0avQhl6GkJaqRx3muiZdJfzqlT+QeRfhZDsQ6JDeg3FQNSfb+ZQv1ovDMz0BjxUvI E+uOjW7eXnNd9rHSP6MFN8zlUjtUPNluKvhfMnlJY2lXl7a5SIdt5zUjrn6zOzCrNf kmU1FG0Rh/6jE64A+mol6Y2OO7L+ih9iAJKIP+KI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heinz Mauelshagen , Mikulas Patocka , Mike Snitzer Subject: [PATCH 4.19 85/86] dm integrity: fix a deadlock due to offloading to an incorrect workqueue Date: Tue, 10 Mar 2020 13:45:49 +0100 Message-Id: <20200310124535.461145996@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124530.808338541@linuxfoundation.org> References: <20200310124530.808338541@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Mikulas Patocka commit 53770f0ec5fd417429775ba006bc4abe14002335 upstream. If we need to perform synchronous I/O in dm_integrity_map_continue(), we must make sure that we are not in the map function - in order to avoid the deadlock due to bio queuing in generic_make_request. To avoid the deadlock, we offload the request to metadata_wq. However, metadata_wq also processes metadata updates for write requests. If there are too many requests that get offloaded to metadata_wq at the beginning of dm_integrity_map_continue, the workqueue metadata_wq becomes clogged and the system is incapable of processing any metadata updates. This causes a deadlock because all the requests that need to do metadata updates wait for metadata_wq to proceed and metadata_wq waits inside wait_and_add_new_range until some existing request releases its range lock (which doesn't happen because the range lock is released after metadata update). In order to fix the deadlock, we create a new workqueue offload_wq and offload requests to it - so that processing of offload_wq is independent from processing of metadata_wq. Fixes: 7eada909bfd7 ("dm: add integrity target") Cc: stable@vger.kernel.org # v4.12+ Reported-by: Heinz Mauelshagen Tested-by: Heinz Mauelshagen Signed-off-by: Heinz Mauelshagen Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-integrity.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -198,6 +198,7 @@ struct dm_integrity_c { struct list_head wait_list; wait_queue_head_t endio_wait; struct workqueue_struct *wait_wq; + struct workqueue_struct *offload_wq; unsigned char commit_seq; commit_id_t commit_ids[N_COMMIT_IDS]; @@ -1237,7 +1238,7 @@ static void dec_in_flight(struct dm_inte dio->range.logical_sector += dio->range.n_sectors; bio_advance(bio, dio->range.n_sectors << SECTOR_SHIFT); INIT_WORK(&dio->work, integrity_bio_wait); - queue_work(ic->wait_wq, &dio->work); + queue_work(ic->offload_wq, &dio->work); return; } do_endio_flush(ic, dio); @@ -1657,7 +1658,7 @@ static void dm_integrity_map_continue(st if (need_sync_io && from_map) { INIT_WORK(&dio->work, integrity_bio_wait); - queue_work(ic->metadata_wq, &dio->work); + queue_work(ic->offload_wq, &dio->work); return; } @@ -3308,6 +3309,14 @@ static int dm_integrity_ctr(struct dm_ta goto bad; } + ic->offload_wq = alloc_workqueue("dm-integrity-offload", WQ_MEM_RECLAIM, + METADATA_WORKQUEUE_MAX_ACTIVE); + if (!ic->offload_wq) { + ti->error = "Cannot allocate workqueue"; + r = -ENOMEM; + goto bad; + } + ic->commit_wq = alloc_workqueue("dm-integrity-commit", WQ_MEM_RECLAIM, 1); if (!ic->commit_wq) { ti->error = "Cannot allocate workqueue"; @@ -3544,6 +3553,8 @@ static void dm_integrity_dtr(struct dm_t destroy_workqueue(ic->metadata_wq); if (ic->wait_wq) destroy_workqueue(ic->wait_wq); + if (ic->offload_wq) + destroy_workqueue(ic->offload_wq); if (ic->commit_wq) destroy_workqueue(ic->commit_wq); if (ic->writer_wq)