LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alasdair G Kergon <agk@redhat.com>
To: Christian Kujau <lists@nerdbynature.de>, Chr <chunkeey@web.de>,
	Milan Broz <mbroz@redhat.com>, David Chinner <dgc@sgi.com>,
	LKML <linux-kernel@vger.kernel.org>,
	xfs@oss.sgi.com, dm-devel@redhat.com, dm-crypt@saout.de,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Ritesh Raj Sarraf <rrs@researchut.com>
Subject: Re: [dm-crypt] INFO: task mount:11202 blocked for more than 120 seconds
Date: Mon, 17 Mar 2008 17:36:09 +0000	[thread overview]
Message-ID: <20080317173609.GD29322@agk.fab.redhat.com> (raw)
In-Reply-To: <alpine.DEB.1.00.0803161406040.6213@sheep.housecafe.de>

Latest version for everyone to try:

From: Milan Broz <mbroz@redhat.com>

Fix regression in dm-crypt introduced in commit
3a7f6c990ad04e6f576a159876c602d14d6f7fef
(dm crypt: use async crypto).

If write requests need to be split into pieces, the code must not
process them in parallel because the crypto context cannot be shared.
So there can be parallel crypto operations on one part of the write,
but only one write bio can be processed at a time.

This is not optimal and the workqueue code need to be optimized for
parallel processing, but for now it solves problem without affecting
the performance of synchronous crypto operation (most of current
dm-crypt users).

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

---
 drivers/md/dm-crypt.c |   58 +++++++++++++++++++++++++-------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)

Index: linux-2.6.25-rc4/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.25-rc4.orig/drivers/md/dm-crypt.c	2008-03-17 11:42:16.000000000 +0000
+++ linux-2.6.25-rc4/drivers/md/dm-crypt.c	2008-03-17 11:42:28.000000000 +0000
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
  * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2006-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2006-2008 Red Hat, Inc. All rights reserved.
  *
  * This file is released under the GPL.
  */
@@ -93,6 +93,8 @@ struct crypt_config {
 
 	struct workqueue_struct *io_queue;
 	struct workqueue_struct *crypt_queue;
+	wait_queue_head_t writeq;
+
 	/*
 	 * crypto related data
 	 */
@@ -331,14 +333,7 @@ static void crypt_convert_init(struct cr
 	ctx->idx_out = bio_out ? bio_out->bi_idx : 0;
 	ctx->sector = sector + cc->iv_offset;
 	init_completion(&ctx->restart);
-	/*
-	 * Crypto operation can be asynchronous,
-	 * ctx->pending is increased after request submission.
-	 * We need to ensure that we don't call the crypt finish
-	 * operation before pending got incremented
-	 * (dependent on crypt submission return code).
-	 */
-	atomic_set(&ctx->pending, 2);
+	atomic_set(&ctx->pending, 1);
 }
 
 static int crypt_convert_block(struct crypt_config *cc,
@@ -411,43 +406,42 @@ static void crypt_alloc_req(struct crypt
 static int crypt_convert(struct crypt_config *cc,
 			 struct convert_context *ctx)
 {
-	int r = 0;
+	int r;
 
 	while(ctx->idx_in < ctx->bio_in->bi_vcnt &&
 	      ctx->idx_out < ctx->bio_out->bi_vcnt) {
 
 		crypt_alloc_req(cc, ctx);
 
+		atomic_inc(&ctx->pending);
+
 		r = crypt_convert_block(cc, ctx, cc->req);
 
 		switch (r) {
+		/* async */
 		case -EBUSY:
 			wait_for_completion(&ctx->restart);
 			INIT_COMPLETION(ctx->restart);
 			/* fall through*/
 		case -EINPROGRESS:
-			atomic_inc(&ctx->pending);
 			cc->req = NULL;
-			r = 0;
-			/* fall through*/
+			ctx->sector++;
+			continue;
+
+		/* sync */
 		case 0:
+			atomic_dec(&ctx->pending);
 			ctx->sector++;
 			continue;
-		}
 
-		break;
+		/* error */
+		default:
+			atomic_dec(&ctx->pending);
+			return r;
+		}
 	}
 
-	/*
-	 * If there are pending crypto operation run async
-	 * code. Otherwise process return code synchronously.
-	 * The step of 2 ensures that async finish doesn't
-	 * call crypto finish too early.
-	 */
-	if (atomic_sub_return(2, &ctx->pending))
-		return -EINPROGRESS;
-
-	return r;
+	return 0;
 }
 
 static void dm_crypt_bio_destructor(struct bio *bio)
@@ -624,8 +618,10 @@ static void kcryptd_io_read(struct dm_cr
 static void kcryptd_io_write(struct dm_crypt_io *io)
 {
 	struct bio *clone = io->ctx.bio_out;
+	struct crypt_config *cc = io->target->private;
 
 	generic_make_request(clone);
+	wake_up(&cc->writeq);
 }
 
 static void kcryptd_io(struct work_struct *work)
@@ -698,7 +694,8 @@ static void kcryptd_crypt_write_convert_
 
 		r = crypt_convert(cc, &io->ctx);
 
-		if (r != -EINPROGRESS) {
+		if (atomic_dec_and_test(&io->ctx.pending)) {
+			/* processed, no running async crypto  */
 			kcryptd_crypt_write_io_submit(io, r, 0);
 			if (unlikely(r < 0))
 				return;
@@ -706,8 +703,12 @@ static void kcryptd_crypt_write_convert_
 			atomic_inc(&io->pending);
 
 		/* out of memory -> run queues */
-		if (unlikely(remaining))
+		if (unlikely(remaining)) {
+			/* wait for async crypto and reinitialize pending counter */
+			wait_event(cc->writeq, !atomic_read(&io->ctx.pending));
+			atomic_set(&io->ctx.pending, 1);
 			congestion_wait(WRITE, HZ/100);
+		}
 	}
 }
 
@@ -746,7 +747,7 @@ static void kcryptd_crypt_read_convert(s
 
 	r = crypt_convert(cc, &io->ctx);
 
-	if (r != -EINPROGRESS)
+	if (atomic_dec_and_test(&io->ctx.pending))
 		kcryptd_crypt_read_done(io, r);
 
 	crypt_dec_pending(io);
@@ -1047,6 +1048,7 @@ static int crypt_ctr(struct dm_target *t
 		goto bad_crypt_queue;
 	}
 
+	init_waitqueue_head(&cc->writeq);
 	ti->private = cc;
 	return 0;
 

  reply	other threads:[~2008-03-17 17:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-07 20:32 Christian Kujau
2008-03-07 22:40 ` David Chinner
2008-03-07 23:46   ` Christian Kujau
2008-03-08  1:54     ` Christian Kujau
2008-03-09  6:15       ` 2.6.25-rc hangs (was: INFO: task mount:11202 blocked for more than 120 seconds) Christian Kujau
2008-03-09 16:44         ` 2.6.25-rc hangs Eric Sandeen
2008-03-09 18:05           ` Christian Kujau
     [not found]             ` <47D42AD6.10500@sandeen.net>
2008-03-09 18:49               ` Christian Kujau
2008-03-12 18:06                 ` Samuel Tardieu
2008-03-12 21:02                   ` Christian Kujau
2008-03-09 21:34     ` INFO: task mount:11202 blocked for more than 120 seconds David Chinner
2008-03-10  1:46       ` Christian Kujau
2008-03-12 18:03       ` Samuel Tardieu
2008-03-12 19:53         ` Chr
2008-03-12 23:07           ` Christian Kujau
2008-03-13 13:45             ` Christian Kujau
2008-03-13 21:33               ` Chr
2008-03-13 21:54                 ` Christian Kujau
2008-03-14  0:15                   ` Chr
2008-03-14  9:27       ` Milan Broz
2008-03-14 23:58         ` Christian Kujau
2008-03-16 20:33           ` David Chinner
2008-03-15  0:08         ` Chr
2008-03-15 13:32           ` [dm-crypt] " Chr
2008-03-15 21:34             ` Chr
2008-03-16 13:08               ` Christian Kujau
2008-03-17 17:36                 ` Alasdair G Kergon [this message]
2008-03-17 18:36                   ` Chr
2008-03-18 17:46                     ` Christian Kujau
2008-03-18  0:56                   ` Herbert Xu
2008-03-18  4:07                     ` Milan Broz
2008-03-22  2:52                   ` Christian Kujau
2008-03-27  8:21                     ` Christian Kujau
2008-03-26 16:57                   ` Chr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080317173609.GD29322@agk.fab.redhat.com \
    --to=agk@redhat.com \
    --cc=chunkeey@web.de \
    --cc=dgc@sgi.com \
    --cc=dm-crypt@saout.de \
    --cc=dm-devel@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=mbroz@redhat.com \
    --cc=rrs@researchut.com \
    --cc=xfs@oss.sgi.com \
    --subject='Re: [dm-crypt] INFO: task mount:11202 blocked for more than 120 seconds' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).