From: Andrea Arcangeli Subject: Race condition in userspace testcase References: 46948, LTC11574 Additional Comment #103 From Andrea Arcangeli 2004-10-15 19:41 the last patch I attached is the safest I believe. I'm not sure if a lock_unlock or lock_unlock is always guaranteed to happen after the I/O, and this makes sure no race can happen anymore. --- fs/bio.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/fs/bio.c +++ b/fs/bio.c @@ -1192,6 +1192,16 @@ void bio_endio(struct bio *bio, int erro else if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) error = -EIO; + if (bio_data_dir(bio) == READ) + /* + * If the current cpu has written to the page by hand + * without dma, we must enforce ordering to be sure + * this written data will be visible before we expose + * the page contents to other cpus (for example with + * a set_pte). + */ + smp_wmb(); + if (bio->bi_end_io) bio->bi_end_io(bio, error); }