[PATCH 1/4] iov_iter: Provide copy_iomem_to|from_iter()
Michal Wajdeczko
michal.wajdeczko at intel.com
Thu Nov 7 16:34:45 UTC 2024
Define simple copy helpers that work on I/O memory. This will
allow reuse of existing framework functions in new use cases.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
---
Cc: Alexander Viro <viro at zeniv.linux.org.uk>
Cc: Andrew Morton <akpm at linux-foundation.org>
Cc: Matthew Wilcox <willy at infradead.org>
Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: linux-kernel at vger.kernel.org
Cc: linux-fsdevel at vger.kernel.org
---
include/linux/uio.h | 4 ++++
lib/iov_iter.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 853f9de5aa05..6d2a24293bd1 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -178,6 +178,10 @@ size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes,
struct iov_iter *i);
size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes,
struct iov_iter *i);
+size_t copy_iomem_to_iter(const void __iomem *from, size_t offset,
+ size_t bytes, struct iov_iter *i);
+size_t copy_iomem_from_iter(void __iomem *to, size_t offset,
+ size_t bytes, struct iov_iter *i);
size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i);
size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i);
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 908e75a28d90..e8c1f1c68716 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -435,6 +435,48 @@ size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes,
}
EXPORT_SYMBOL(copy_page_from_iter);
+size_t copy_iomem_to_iter(const void __iomem *from, size_t offset,
+ size_t bytes, struct iov_iter *i)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t progress = 0, copied, len;
+
+ from += offset;
+ while (bytes) {
+ len = min(bytes, sizeof(buf));
+ memcpy_fromio(buf, from + progress, len);
+ copied = _copy_to_iter(buf, len, i);
+ if (!copied)
+ break;
+ bytes -= copied;
+ progress += copied;
+ }
+
+ return progress;
+}
+EXPORT_SYMBOL(copy_iomem_to_iter);
+
+size_t copy_iomem_from_iter(void __iomem *to, size_t offset,
+ size_t bytes, struct iov_iter *i)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t progress = 0, copied, len;
+
+ to += offset;
+ while (bytes) {
+ len = min(bytes, sizeof(buf));
+ copied = _copy_from_iter(buf, len, i);
+ if (!copied)
+ break;
+ memcpy_toio(to + progress, buf, copied);
+ bytes -= copied;
+ progress += copied;
+ }
+
+ return progress;
+}
+EXPORT_SYMBOL(copy_iomem_from_iter);
+
static __always_inline
size_t zero_to_user_iter(void __user *iter_to, size_t progress,
size_t len, void *priv, void *priv2)
--
2.43.0
More information about the Intel-xe
mailing list