diff options
author | Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | 2009-06-18 04:19:12 -0400 |
---|---|---|
committer | Pierre Ossman <pierre@ossman.eu> | 2009-07-31 06:28:45 -0400 |
commit | 6de7e356faf54aa75de5b624bbce28a5b776dfa8 (patch) | |
tree | 09b341b7c1371448a5ae8a9cd4009a4f81f4a3dd | |
parent | b592972493c38665efd7d429a01b23fcb21e331a (diff) |
lib/scatterlist: add a flags to signalize mapping direction
sg_miter_start() is currently unaware of the direction of the copy
process (to or from the scatter list). It is important to know the
direction because the page has to be flushed in case the data written
is seen on a different mapping in user land on cache incoherent
architectures.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Acked-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Pierre Ossman <pierre@ossman.eu>
-rw-r--r-- | include/linux/scatterlist.h | 2 | ||||
-rw-r--r-- | lib/scatterlist.c | 16 |
2 files changed, 14 insertions, 4 deletions
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h index e5996984ddd0..9aaf5bfdad1a 100644 --- a/include/linux/scatterlist.h +++ b/include/linux/scatterlist.h | |||
@@ -242,6 +242,8 @@ size_t sg_copy_to_buffer(struct scatterlist *sgl, unsigned int nents, | |||
242 | */ | 242 | */ |
243 | 243 | ||
244 | #define SG_MITER_ATOMIC (1 << 0) /* use kmap_atomic */ | 244 | #define SG_MITER_ATOMIC (1 << 0) /* use kmap_atomic */ |
245 | #define SG_MITER_TO_SG (1 << 1) /* flush back to phys on unmap */ | ||
246 | #define SG_MITER_FROM_SG (1 << 2) /* nop */ | ||
245 | 247 | ||
246 | struct sg_mapping_iter { | 248 | struct sg_mapping_iter { |
247 | /* the following three fields can be accessed directly */ | 249 | /* the following three fields can be accessed directly */ |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index a295e404e908..0d475d8167bf 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
@@ -314,6 +314,7 @@ void sg_miter_start(struct sg_mapping_iter *miter, struct scatterlist *sgl, | |||
314 | miter->__sg = sgl; | 314 | miter->__sg = sgl; |
315 | miter->__nents = nents; | 315 | miter->__nents = nents; |
316 | miter->__offset = 0; | 316 | miter->__offset = 0; |
317 | WARN_ON(!(flags & (SG_MITER_TO_SG | SG_MITER_FROM_SG))); | ||
317 | miter->__flags = flags; | 318 | miter->__flags = flags; |
318 | } | 319 | } |
319 | EXPORT_SYMBOL(sg_miter_start); | 320 | EXPORT_SYMBOL(sg_miter_start); |
@@ -394,6 +395,9 @@ void sg_miter_stop(struct sg_mapping_iter *miter) | |||
394 | if (miter->addr) { | 395 | if (miter->addr) { |
395 | miter->__offset += miter->consumed; | 396 | miter->__offset += miter->consumed; |
396 | 397 | ||
398 | if (miter->__flags & SG_MITER_TO_SG) | ||
399 | flush_kernel_dcache_page(miter->page); | ||
400 | |||
397 | if (miter->__flags & SG_MITER_ATOMIC) { | 401 | if (miter->__flags & SG_MITER_ATOMIC) { |
398 | WARN_ON(!irqs_disabled()); | 402 | WARN_ON(!irqs_disabled()); |
399 | kunmap_atomic(miter->addr, KM_BIO_SRC_IRQ); | 403 | kunmap_atomic(miter->addr, KM_BIO_SRC_IRQ); |
@@ -426,8 +430,14 @@ static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, | |||
426 | unsigned int offset = 0; | 430 | unsigned int offset = 0; |
427 | struct sg_mapping_iter miter; | 431 | struct sg_mapping_iter miter; |
428 | unsigned long flags; | 432 | unsigned long flags; |
433 | unsigned int sg_flags = SG_MITER_ATOMIC; | ||
434 | |||
435 | if (to_buffer) | ||
436 | sg_flags |= SG_MITER_FROM_SG; | ||
437 | else | ||
438 | sg_flags |= SG_MITER_TO_SG; | ||
429 | 439 | ||
430 | sg_miter_start(&miter, sgl, nents, SG_MITER_ATOMIC); | 440 | sg_miter_start(&miter, sgl, nents, sg_flags); |
431 | 441 | ||
432 | local_irq_save(flags); | 442 | local_irq_save(flags); |
433 | 443 | ||
@@ -438,10 +448,8 @@ static size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, | |||
438 | 448 | ||
439 | if (to_buffer) | 449 | if (to_buffer) |
440 | memcpy(buf + offset, miter.addr, len); | 450 | memcpy(buf + offset, miter.addr, len); |
441 | else { | 451 | else |
442 | memcpy(miter.addr, buf + offset, len); | 452 | memcpy(miter.addr, buf + offset, len); |
443 | flush_kernel_dcache_page(miter.page); | ||
444 | } | ||
445 | 453 | ||
446 | offset += len; | 454 | offset += len; |
447 | } | 455 | } |