linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Viro <viro@math.psu.edu>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: David Woodhouse <dwmw2@infradead.org>, linux-kernel@vger.kernel.org
Subject: [PATCH] Re: kernel BUG at buffer.c:827 in test12-pre6 and 7
Date: Fri, 8 Dec 2000 13:11:54 -0500 (EST)	[thread overview]
Message-ID: <Pine.GSO.4.21.0012081301160.27010-100000@weyl.math.psu.edu> (raw)
In-Reply-To: <Pine.GSO.4.21.0012080410180.24770-100000@weyl.math.psu.edu>

Folks, see if the following patch helps. AFAICS it closes a pretty real
race - we could call block_write_full_page() for a page that has sync
IO in progress and blindly change ->b_end_io callbacks on the bh with
pending requests. With a little bit of bad luck they would complete before
we got to ll_rw_block(), thus leading to extra UnlockPage(). All it takes
is a pageout on a page that got partial write recently - if some fragments
were still unmapped we get to call get_block() on them and it can easily
block, providing a decent window for that race.

Fix: postpone changing ->b_end_io until the call of ll_rw_block(); if by
the time of ll_rw_block() some fragments will still have IO in progress -
wait on them.

Comments?
						Cheers,
							Al

--- buffer.c	Fri Dec  8 16:19:53 2000
+++ buffer.c.new	Fri Dec  8 16:26:44 2000
@@ -1577,6 +1577,26 @@
  * "Dirty" is valid only with the last case (mapped+uptodate).
  */
 
+static void write_array_async(struct page *page, struct buffer_head **p, int n)
+{
+	int i;
+	if (!n) {
+		UnlockPage(page);
+		return;
+	}
+	/*
+	 * If there are pending requests on these guys - wait before changing
+	 * ->b_end_io.
+	 */
+	for (i=0; i<n; i++) {
+		wait_on_buffer(p[i]);
+		set_bit(BH_Uptodate, &p[i]->b_state);
+		set_bit(BH_Dirty, &p[i]->b_state);
+		p[i]->b_end_io = end_buffer_io_async;
+	}
+	ll_rw_block(WRITE, n, p);
+}
+
 /*
  * block_write_full_page() is SMP-safe - currently it's still
  * being called with the kernel lock held, but the code is ready.
@@ -1616,28 +1636,17 @@
 			if (buffer_new(bh))
 				unmap_underlying_metadata(bh);
 		}
-		set_bit(BH_Uptodate, &bh->b_state);
-		set_bit(BH_Dirty, &bh->b_state);
-		bh->b_end_io = end_buffer_io_async;
 		atomic_inc(&bh->b_count);
 		arr[nr++] = bh;
 		bh = bh->b_this_page;
 		block++;
 	} while (bh != head);
 
-	if (nr) {
-		ll_rw_block(WRITE, nr, arr);
-	} else {
-		UnlockPage(page);
-	}
+	write_array_async(page, arr, nr);
 	SetPageUptodate(page);
 	return 0;
 out:
-	if (nr) {
-		ll_rw_block(WRITE, nr, arr);
-	} else {
-		UnlockPage(page);
-	}
+	write_array_async(page, arr, nr);
 	ClearPageUptodate(page);
 	return err;
 }

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

  reply	other threads:[~2000-12-08 18:42 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-07 22:42 kernel BUG at buffer.c:827 in test12-pre6 and 7 Joseph Cheek
2000-12-07 23:14 ` Keith Owens
2000-12-08  0:22 ` Linus Torvalds
2000-12-08  1:23   ` Joseph Cheek
2000-12-08  3:03     ` Keith Owens
2000-12-08  2:16   ` Joseph Cheek
2000-12-08  7:27   ` Tom Leete
2000-12-08  9:07 ` David Woodhouse
2000-12-08  9:58   ` [found?] " Alexander Viro
2000-12-08 18:11     ` Alexander Viro [this message]
2000-12-08 18:48       ` [PATCH] " Linus Torvalds
2000-12-08 19:13         ` Alexander Viro
2000-12-08 19:39           ` Linus Torvalds
2000-12-08 19:50             ` Daniel Phillips
2000-12-08 21:17               ` Linus Torvalds
2000-12-08 22:30             ` Alexander Viro
2000-12-08 22:42               ` Linus Torvalds
2000-12-09  4:59                 ` Alexander Viro
2000-12-09  8:45                   ` Linus Torvalds
2000-12-09  8:56                     ` Linus Torvalds
2000-12-09 10:40                     ` Alexander Viro
2000-12-09 12:56                       ` Andries Brouwer
2000-12-09 13:11                         ` Alexander Viro
2000-12-09 21:25                           ` Mikulas Patocka
2000-12-10  1:11                             ` Linus Torvalds
2000-12-09 17:28                       ` Linus Torvalds
2000-12-09 18:43                         ` Andi Kleen
2000-12-09 14:00                     ` David S. Miller
2000-12-09 15:37           ` David Woodhouse
2000-12-12  0:54 ` [FIXED!] " Joseph Cheek
     [not found] <90rjbg$8eso1$1@fido.engr.sgi.com>
2000-12-08 22:22 ` [PATCH] " Rajagopal Ananthanarayanan

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=Pine.GSO.4.21.0012081301160.27010-100000@weyl.math.psu.edu \
    --to=viro@math.psu.edu \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).