All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: axboe@suse.de, bzolnier@gmail.com, rmk@arm.linux.org.uk,
	james.steward@dynamicratings.com, jgarzik@pobox.com,
	James.Bottomley@SteelEye.com, linux-kernel@vger.kernel.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 2/8] block: implement blk kmap helpers
Date: Sat, 14 Jan 2006 00:24:16 +0900	[thread overview]
Message-ID: <11371658561196-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11371658562541-git-send-email-htejun@gmail.com>

When block requests are handled via DMA dma mapping functions take
care of cache coherency.  Unfortunately, cache coherencly was left
unhandled until now for block PIOs, resulting in data corruption
issues on architectures with aliasing caches.

All block PIO operations use kmap/unmap to access target memory area
and the mapping/unmapping points are the perfect places for cache
flushing.  kmap/unmap are to PIO'ing cpus what dma_map/unmap are to
DMAing devices.

This patch implements blk kmap helpers which additionally take
@direction argument and deal with cache coherency.

Signed-off-by: Tejun Heo <htejun@gmail.com>

---

 include/linux/blkdev.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

fdaeda6742b70451ddbb860b440d2533c6591fda
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 02a585f..1040029 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -17,6 +17,10 @@
 
 #include <asm/scatterlist.h>
 
+/* for PIO kmap helpers */
+#include <linux/highmem.h>
+#include <linux/dma-mapping.h>
+
 struct request_queue;
 typedef struct request_queue request_queue_t;
 struct elevator_queue;
@@ -812,6 +816,40 @@ static inline void put_dev_sector(Sector
 	page_cache_release(p.v);
 }
 
+/*
+ * PIO kmap helpers.
+ *
+ * Block PIO requires cache flushes on architectures with aliasing
+ * caches.  If a driver wants to perform PIO on a user-mappable page
+ * (page cache page), it MUST use one of the following kmap/unmap
+ * helpers unless it handles cache coherency itself.
+ */
+static inline void * blk_kmap_atomic(struct page *page, enum km_type type,
+				     enum dma_data_direction dir)
+{
+	return kmap_atomic(page, type);
+}
+
+static inline void blk_kunmap_atomic(void *addr, enum km_type type,
+				     enum dma_data_direction dir)
+{
+	if (dir == DMA_BIDIRECTIONAL || dir == DMA_FROM_DEVICE)
+		flush_dcache_page(kmap_atomic_to_page(addr));
+	kunmap_atomic(addr, type);
+}
+
+static inline void * blk_kmap(struct page *page, enum dma_data_direction dir)
+{
+	return kmap(page);
+}
+
+static inline void blk_kunmap(struct page *page, enum dma_data_direction dir)
+{
+	if (dir == DMA_BIDIRECTIONAL || dir == DMA_FROM_DEVICE)
+		flush_dcache_page(page);
+	kunmap(page);
+}
+
 struct work_struct;
 int kblockd_schedule_work(struct work_struct *work);
 void kblockd_flush(void);
-- 
1.0.6



  parent reply	other threads:[~2006-01-13 15:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-13 15:24 [PATCHSET] block: fix PIO cache coherency bug Tejun Heo
2006-01-13 15:24 ` [PATCH 3/8] block: convert bio kmap helpers to use blk_kmap helpers Tejun Heo
2006-01-13 15:24 ` Tejun Heo [this message]
2006-01-13 15:24 ` [PATCH 4/8] block: convert IDE " Tejun Heo
2006-02-14 19:07   ` Matt Reimer
2006-02-15  2:05     ` Tejun Heo
2006-02-16 18:01       ` Russell King
2006-02-16 18:10         ` Linus Torvalds
2006-02-16 19:02           ` Russell King
2006-01-13 15:24 ` [PATCH 5/8] block: convert libata " Tejun Heo
2006-01-13 15:24 ` [PATCH 1/8] highmem: include asm/kmap_types.h in linux/highmem.h Tejun Heo
2006-01-13 15:24 ` [PATCH 6/8] block: convert scsi to use blk_kmap helpers Tejun Heo
2006-01-13 15:24 ` [PATCH 7/8] block: convert block/rd.c " Tejun Heo
2006-01-13 15:24 ` [PATCH 8/8] block: convert md " Tejun Heo
2006-01-13 15:37 ` [PATCHSET] block: fix PIO cache coherency bug Jens Axboe
2006-01-13 15:47 ` Bartlomiej Zolnierkiewicz
2006-01-13 15:50 ` James Bottomley
2006-01-13 18:20   ` Russell King
2006-01-13 18:35     ` James Bottomley
2006-01-13 19:06       ` Russell King
2006-02-22  8:27         ` Tejun Heo
2006-03-02 18:46           ` James Bottomley
2006-03-02 20:30             ` Russell King
2006-03-02 20:43               ` James Bottomley
2006-03-02 20:57                 ` Russell King
2006-03-02 20:44               ` Jens Axboe
2006-05-29 19:17                 ` Nicolas Pitre
2006-05-30 11:19                   ` Tejun Heo
2006-05-30 21:07                     ` Guennadi Liakhovetski
2006-05-30 21:32                       ` Nicolas Pitre
2006-05-31  0:57                       ` David S. Miller
2006-03-02 20:40           ` Jens Axboe
2006-03-20 16:12           ` James Bottomley
2006-03-20 16:26             ` Tejun Heo
2006-03-20 16:33               ` James Bottomley
2006-03-20 16:40                 ` Tejun Heo
2006-03-20 16:48                   ` James Bottomley
2006-03-23 14:23               ` James Bottomley
2006-03-20 16:50             ` Randy.Dunlap
2006-03-20 16:52               ` James Bottomley
2006-01-13 22:02 ` Russell King
2006-01-13 22:38   ` James Bottomley
2006-01-13 22:43     ` David S. Miller
2006-01-14  4:58       ` James Bottomley
2006-01-17 15:00 ` Jeff Garzik

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=11371658561196-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=James.Bottomley@SteelEye.com \
    --cc=axboe@suse.de \
    --cc=bzolnier@gmail.com \
    --cc=james.steward@dynamicratings.com \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk@arm.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.