* [PATCH v2 0/4] Add iomem helpers for use from debugfs
@ 2024-11-12 20:04 Michal Wajdeczko
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
2024-11-12 20:04 ` [PATCH v2 2/4] libfs: Provide simple_read_from|write_to_iomem() Michal Wajdeczko
0 siblings, 2 replies; 6+ messages in thread
From: Michal Wajdeczko @ 2024-11-12 20:04 UTC (permalink / raw)
To: intel-xe; +Cc: Michal Wajdeczko, linux-kernel, linux-fsdevel
This series attempts to promote helpers used by Xe [1] to libfs.
Earlier attempt [2] with similar helper was unnoticed.
[1] https://patchwork.freedesktop.org/series/140848/#rev1
[2] https://patchwork.freedesktop.org/series/133507/#rev1
v1: https://patchwork.freedesktop.org/series/141060/#rev1
v2: use iterate_and_advance to treat user_iter separately (Matthew)
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Michal Wajdeczko (4):
iov_iter: Provide copy_iomem_to|from_iter()
libfs: Provide simple_read_from|write_to_iomem()
drm/xe: Add read/write debugfs helpers for GGTT node
drm/xe/pf: Expose access to the VF GGTT PTEs over debugfs
drivers/gpu/drm/xe/xe_ggtt.c | 52 ++++++++++++++
drivers/gpu/drm/xe/xe_ggtt.h | 7 ++
drivers/gpu/drm/xe/xe_gt_sriov_pf_debugfs.c | 62 ++++++++++++++++
fs/libfs.c | 78 +++++++++++++++++++++
include/linux/fs.h | 5 ++
include/linux/uio.h | 3 +
lib/iov_iter.c | 66 +++++++++++++++++
7 files changed, 273 insertions(+)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter()
2024-11-12 20:04 [PATCH v2 0/4] Add iomem helpers for use from debugfs Michal Wajdeczko
@ 2024-11-12 20:04 ` Michal Wajdeczko
2024-11-14 1:29 ` kernel test robot
` (2 more replies)
2024-11-12 20:04 ` [PATCH v2 2/4] libfs: Provide simple_read_from|write_to_iomem() Michal Wajdeczko
1 sibling, 3 replies; 6+ messages in thread
From: Michal Wajdeczko @ 2024-11-12 20:04 UTC (permalink / raw)
To: intel-xe
Cc: Michal Wajdeczko, Matthew Wilcox, Alexander Viro, Andrew Morton,
Rodrigo Vivi, Matthew Brost, linux-kernel, linux-fsdevel
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@intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
---
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
---
v2: use iterate_and_advance to treat user_iter separately (Matthew)
---
include/linux/uio.h | 3 +++
lib/iov_iter.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 853f9de5aa05..354a6b2d1e94 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -183,6 +183,9 @@ 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);
size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i);
+size_t copy_iomem_to_iter(const void __iomem *from, size_t bytes, struct iov_iter *i);
+size_t copy_iomem_from_iter(void __iomem *to, size_t bytes, struct iov_iter *i);
+
static inline size_t copy_folio_to_iter(struct folio *folio, size_t offset,
size_t bytes, struct iov_iter *i)
{
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 908e75a28d90..80feff9c8875 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -323,6 +323,72 @@ size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
EXPORT_SYMBOL_GPL(_copy_from_iter_flushcache);
#endif
+static __always_inline
+size_t memcpy_iomem_to_iter(void *iter_to, size_t progress, size_t len,
+ void *from, void *priv2)
+{
+ memcpy_fromio(iter_to, from + progress, len);
+ return 0;
+}
+
+static __always_inline
+size_t memcpy_iomem_from_iter(void *iter_from, size_t progress, size_t len,
+ void *to, void *priv2)
+{
+ memcpy_toio(to + progress, iter_from, len);
+ return 0;
+}
+
+static __always_inline
+size_t copy_iomem_to_user_iter(void __user *iter_to, size_t progress,
+ size_t len, void *from, void *priv2)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t chunk = min(len, sizeof(buf));
+
+ memcpy_fromio(buf, from + progress, chunk);
+ chunk -= copy_to_user_iter(iter_to, progress, chunk, buf, priv2);
+ return len - chunk;
+}
+
+static __always_inline
+size_t copy_iomem_from_user_iter(void __user *iter_from, size_t progress,
+ size_t len, void *to, void *priv2)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t chunk = min(len, sizeof(buf));
+
+ chunk -= copy_from_user_iter(iter_from, progress, chunk, buf, priv2);
+ memcpy_toio(to, buf, chunk);
+ return len - chunk;
+}
+
+size_t copy_iomem_to_iter(const void __iomem *from, size_t bytes, struct iov_iter *i)
+{
+ if (WARN_ON_ONCE(i->data_source))
+ return 0;
+ if (user_backed_iter(i))
+ might_fault();
+
+ return iterate_and_advance(i, bytes, (void *)from,
+ copy_iomem_to_user_iter,
+ memcpy_iomem_to_iter);
+}
+EXPORT_SYMBOL(copy_iomem_to_iter);
+
+size_t copy_iomem_from_iter(void __iomem *to, size_t bytes, struct iov_iter *i)
+{
+ if (WARN_ON_ONCE(!i->data_source))
+ return 0;
+ if (user_backed_iter(i))
+ might_fault();
+
+ return iterate_and_advance(i, bytes, (void *)to,
+ copy_iomem_from_user_iter,
+ memcpy_iomem_from_iter);
+}
+EXPORT_SYMBOL(copy_iomem_from_iter);
+
static inline bool page_copy_sane(struct page *page, size_t offset, size_t n)
{
struct page *head;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] libfs: Provide simple_read_from|write_to_iomem()
2024-11-12 20:04 [PATCH v2 0/4] Add iomem helpers for use from debugfs Michal Wajdeczko
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
@ 2024-11-12 20:04 ` Michal Wajdeczko
1 sibling, 0 replies; 6+ messages in thread
From: Michal Wajdeczko @ 2024-11-12 20:04 UTC (permalink / raw)
To: intel-xe
Cc: Michal Wajdeczko, Alexander Viro, Christian Brauner, Jan Kara,
Rodrigo Vivi, Matthew Brost, linux-fsdevel, linux-kernel
New functions are similar to simple_read_from|write_to_buffer()
but work on the I/O memory instead. Will allow wider code reuse.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
fs/libfs.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/fs.h | 5 +++
2 files changed, 83 insertions(+)
diff --git a/fs/libfs.c b/fs/libfs.c
index 46966fd8bcf9..1c7343f1147f 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -1095,6 +1095,84 @@ void simple_release_fs(struct vfsmount **mount, int *count)
}
EXPORT_SYMBOL(simple_release_fs);
+/**
+ * simple_read_from_iomem() - copy data from the I/O memory to user space
+ * @to: the user space buffer to read to
+ * @count: the maximum number of bytes to read
+ * @ppos: the current position in the buffer
+ * @from: the I/O memory to read from
+ * @available: the size of the iomem memory
+ *
+ * The simple_read_from_iomem() function reads up to @count bytes from the
+ * I/O memory @from at offset @ppos into the user space address starting at @to.
+ *
+ * Return: On success, the number of bytes read is returned and the offset
+ * @ppos is advanced by this number, or negative value is returned on error.
+ */
+ssize_t simple_read_from_iomem(void __user *to, size_t count, loff_t *ppos,
+ const void __iomem *from, size_t available)
+{
+ struct iov_iter iter;
+ loff_t pos = *ppos;
+ size_t copied;
+
+ if (pos < 0)
+ return -EINVAL;
+ if (pos >= available || !count)
+ return 0;
+ if (count > available - pos)
+ count = available - pos;
+ if (import_ubuf(ITER_DEST, to, count, &iter))
+ return -EFAULT;
+
+ copied = copy_iomem_to_iter(from + pos, count, &iter);
+ if (!copied)
+ return -EFAULT;
+
+ *ppos = pos + copied;
+ return copied;
+}
+EXPORT_SYMBOL(simple_read_from_iomem);
+
+/**
+ * simple_write_to_iomem() - copy data from user space to the I/O memory
+ * @to: the I/O memory to write to
+ * @available: the size of the I/O memory
+ * @ppos: the current position in the buffer
+ * @from: the user space buffer to read from
+ * @count: the maximum number of bytes to read
+ *
+ * The simple_write_to_iomem() function reads up to @count bytes from the user
+ * space address starting at @from into the I/O memory @to at offset @ppos.
+ *
+ * Return: On success, the number of bytes written is returned and the offset
+ * @ppos is advanced by this number, or negative value is returned on error.
+ */
+ssize_t simple_write_to_iomem(void __iomem *to, size_t available, loff_t *ppos,
+ const void __user *from, size_t count)
+{
+ struct iov_iter iter;
+ loff_t pos = *ppos;
+ size_t copied;
+
+ if (pos < 0)
+ return -EINVAL;
+ if (pos >= available || !count)
+ return 0;
+ if (count > available - pos)
+ count = available - pos;
+ if (import_ubuf(ITER_SOURCE, (void __user *)from, count, &iter))
+ return -EFAULT;
+
+ copied = copy_iomem_from_iter(to + pos, count, &iter);
+ if (!copied)
+ return -EFAULT;
+
+ *ppos = pos + copied;
+ return copied;
+}
+EXPORT_SYMBOL(simple_write_to_iomem);
+
/**
* simple_read_from_buffer - copy data from the buffer to user space
* @to: the user space buffer to read to
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3559446279c1..2cc73c5961b0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3426,6 +3426,11 @@ extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
const void __user *from, size_t count);
+ssize_t simple_read_from_iomem(void __user *to, size_t count, loff_t *ppos,
+ const void __iomem *from, size_t available);
+ssize_t simple_write_to_iomem(void __iomem *to, size_t available, loff_t *ppos,
+ const void __user *from, size_t count);
+
struct offset_ctx {
struct maple_tree mt;
unsigned long next_offset;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter()
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
@ 2024-11-14 1:29 ` kernel test robot
2024-11-14 4:20 ` kernel test robot
2024-11-14 14:12 ` [PATCH v3 " Michal Wajdeczko
2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2024-11-14 1:29 UTC (permalink / raw)
To: Michal Wajdeczko, intel-xe
Cc: oe-kbuild-all, Michal Wajdeczko, Matthew Wilcox, Alexander Viro,
Andrew Morton, Linux Memory Management List, Rodrigo Vivi,
Matthew Brost, linux-kernel, linux-fsdevel
Hi Michal,
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-xe/drm-xe-next]
[also build test WARNING on brauner-vfs/vfs.all akpm-mm/mm-nonmm-unstable linus/master v6.12-rc7 next-20241113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Michal-Wajdeczko/iov_iter-Provide-copy_iomem_to-from_iter/20241113-080831
base: https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next
patch link: https://lore.kernel.org/r/20241112200454.2211-2-michal.wajdeczko%40intel.com
patch subject: [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter()
config: x86_64-randconfig-123-20241113 (https://download.01.org/0day-ci/archive/20241114/202411140935.iEbIWcpc-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241114/202411140935.iEbIWcpc-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411140935.iEbIWcpc-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> lib/iov_iter.c:373:47: sparse: sparse: cast removes address space '__iomem' of expression
lib/iov_iter.c:386:47: sparse: sparse: cast removes address space '__iomem' of expression
>> lib/iov_iter.c:349:33: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const volatile [noderef] __iomem * @@ got void * @@
lib/iov_iter.c:349:33: sparse: expected void const volatile [noderef] __iomem *
lib/iov_iter.c:349:33: sparse: got void *
lib/iov_iter.c:330:37: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const volatile [noderef] __iomem * @@ got void * @@
lib/iov_iter.c:330:37: sparse: expected void const volatile [noderef] __iomem *
lib/iov_iter.c:330:37: sparse: got void *
>> lib/iov_iter.c:362:21: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem * @@ got void *to @@
lib/iov_iter.c:362:21: sparse: expected void volatile [noderef] __iomem *
lib/iov_iter.c:362:21: sparse: got void *to
>> lib/iov_iter.c:338:24: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem * @@ got void * @@
lib/iov_iter.c:338:24: sparse: expected void volatile [noderef] __iomem *
lib/iov_iter.c:338:24: sparse: got void *
vim +/__iomem +373 lib/iov_iter.c
333
334 static __always_inline
335 size_t memcpy_iomem_from_iter(void *iter_from, size_t progress, size_t len,
336 void *to, void *priv2)
337 {
> 338 memcpy_toio(to + progress, iter_from, len);
339 return 0;
340 }
341
342 static __always_inline
343 size_t copy_iomem_to_user_iter(void __user *iter_to, size_t progress,
344 size_t len, void *from, void *priv2)
345 {
346 unsigned char buf[SMP_CACHE_BYTES];
347 size_t chunk = min(len, sizeof(buf));
348
> 349 memcpy_fromio(buf, from + progress, chunk);
350 chunk -= copy_to_user_iter(iter_to, progress, chunk, buf, priv2);
351 return len - chunk;
352 }
353
354 static __always_inline
355 size_t copy_iomem_from_user_iter(void __user *iter_from, size_t progress,
356 size_t len, void *to, void *priv2)
357 {
358 unsigned char buf[SMP_CACHE_BYTES];
359 size_t chunk = min(len, sizeof(buf));
360
361 chunk -= copy_from_user_iter(iter_from, progress, chunk, buf, priv2);
> 362 memcpy_toio(to, buf, chunk);
363 return len - chunk;
364 }
365
366 size_t copy_iomem_to_iter(const void __iomem *from, size_t bytes, struct iov_iter *i)
367 {
368 if (WARN_ON_ONCE(i->data_source))
369 return 0;
370 if (user_backed_iter(i))
371 might_fault();
372
> 373 return iterate_and_advance(i, bytes, (void *)from,
374 copy_iomem_to_user_iter,
375 memcpy_iomem_to_iter);
376 }
377 EXPORT_SYMBOL(copy_iomem_to_iter);
378
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter()
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
2024-11-14 1:29 ` kernel test robot
@ 2024-11-14 4:20 ` kernel test robot
2024-11-14 14:12 ` [PATCH v3 " Michal Wajdeczko
2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2024-11-14 4:20 UTC (permalink / raw)
To: Michal Wajdeczko, intel-xe
Cc: oe-kbuild-all, Michal Wajdeczko, Matthew Wilcox, Alexander Viro,
Andrew Morton, Linux Memory Management List, Rodrigo Vivi,
Matthew Brost, linux-kernel, linux-fsdevel
Hi Michal,
kernel test robot noticed the following build warnings:
[auto build test WARNING on drm-xe/drm-xe-next]
[also build test WARNING on brauner-vfs/vfs.all akpm-mm/mm-nonmm-unstable linus/master v6.12-rc7 next-20241113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Michal-Wajdeczko/iov_iter-Provide-copy_iomem_to-from_iter/20241113-080831
base: https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next
patch link: https://lore.kernel.org/r/20241112200454.2211-2-michal.wajdeczko%40intel.com
patch subject: [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter()
config: arm-randconfig-r113-20241113 (https://download.01.org/0day-ci/archive/20241114/202411141227.4kDiZIXM-lkp@intel.com/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
reproduce: (https://download.01.org/0day-ci/archive/20241114/202411141227.4kDiZIXM-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411141227.4kDiZIXM-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
lib/iov_iter.c:373:47: sparse: sparse: cast removes address space '__iomem' of expression
lib/iov_iter.c:386:47: sparse: sparse: cast removes address space '__iomem' of expression
>> lib/iov_iter.c:349:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const volatile [noderef] __iomem *from @@ got void * @@
lib/iov_iter.c:349:9: sparse: expected void const volatile [noderef] __iomem *from
lib/iov_iter.c:349:9: sparse: got void *
lib/iov_iter.c:330:9: sparse: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const volatile [noderef] __iomem *from @@ got void * @@
lib/iov_iter.c:330:9: sparse: expected void const volatile [noderef] __iomem *from
lib/iov_iter.c:330:9: sparse: got void *
>> lib/iov_iter.c:362:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem *to @@ got void *to @@
lib/iov_iter.c:362:9: sparse: expected void volatile [noderef] __iomem *to
lib/iov_iter.c:362:9: sparse: got void *to
>> lib/iov_iter.c:338:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem *to @@ got void * @@
lib/iov_iter.c:338:9: sparse: expected void volatile [noderef] __iomem *to
lib/iov_iter.c:338:9: sparse: got void *
vim +349 lib/iov_iter.c
333
334 static __always_inline
335 size_t memcpy_iomem_from_iter(void *iter_from, size_t progress, size_t len,
336 void *to, void *priv2)
337 {
> 338 memcpy_toio(to + progress, iter_from, len);
339 return 0;
340 }
341
342 static __always_inline
343 size_t copy_iomem_to_user_iter(void __user *iter_to, size_t progress,
344 size_t len, void *from, void *priv2)
345 {
346 unsigned char buf[SMP_CACHE_BYTES];
347 size_t chunk = min(len, sizeof(buf));
348
> 349 memcpy_fromio(buf, from + progress, chunk);
350 chunk -= copy_to_user_iter(iter_to, progress, chunk, buf, priv2);
351 return len - chunk;
352 }
353
354 static __always_inline
355 size_t copy_iomem_from_user_iter(void __user *iter_from, size_t progress,
356 size_t len, void *to, void *priv2)
357 {
358 unsigned char buf[SMP_CACHE_BYTES];
359 size_t chunk = min(len, sizeof(buf));
360
361 chunk -= copy_from_user_iter(iter_from, progress, chunk, buf, priv2);
> 362 memcpy_toio(to, buf, chunk);
363 return len - chunk;
364 }
365
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/4] iov_iter: Provide copy_iomem_to|from_iter()
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
2024-11-14 1:29 ` kernel test robot
2024-11-14 4:20 ` kernel test robot
@ 2024-11-14 14:12 ` Michal Wajdeczko
2 siblings, 0 replies; 6+ messages in thread
From: Michal Wajdeczko @ 2024-11-14 14:12 UTC (permalink / raw)
To: intel-xe
Cc: Michal Wajdeczko, Matthew Wilcox, Alexander Viro, Andrew Morton,
Rodrigo Vivi, Matthew Brost, linux-kernel, linux-fsdevel
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@intel.com>
Cc: Matthew Wilcox <willy@infradead.org>
---
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
---
v2: use iterate_and_advance to treat user_iter separately (Matthew)
v3: add explicit casts to make sparse happy (kernel test robot)
---
include/linux/uio.h | 3 +++
lib/iov_iter.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/include/linux/uio.h b/include/linux/uio.h
index 853f9de5aa05..354a6b2d1e94 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -183,6 +183,9 @@ 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);
size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i);
+size_t copy_iomem_to_iter(const void __iomem *from, size_t bytes, struct iov_iter *i);
+size_t copy_iomem_from_iter(void __iomem *to, size_t bytes, struct iov_iter *i);
+
static inline size_t copy_folio_to_iter(struct folio *folio, size_t offset,
size_t bytes, struct iov_iter *i)
{
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 908e75a28d90..a6eae4063366 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -323,6 +323,72 @@ size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i)
EXPORT_SYMBOL_GPL(_copy_from_iter_flushcache);
#endif
+static __always_inline
+size_t memcpy_iomem_to_iter(void *iter_to, size_t progress, size_t len,
+ void *from, void *priv2)
+{
+ memcpy_fromio(iter_to, (const void __iomem *)from + progress, len);
+ return 0;
+}
+
+static __always_inline
+size_t memcpy_iomem_from_iter(void *iter_from, size_t progress, size_t len,
+ void *to, void *priv2)
+{
+ memcpy_toio((void __iomem *)to + progress, iter_from, len);
+ return 0;
+}
+
+static __always_inline
+size_t copy_iomem_to_user_iter(void __user *iter_to, size_t progress,
+ size_t len, void *from, void *priv2)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t chunk = min(len, sizeof(buf));
+
+ memcpy_fromio(buf, (const void __iomem *)from + progress, chunk);
+ chunk -= copy_to_user_iter(iter_to, progress, chunk, buf, priv2);
+ return len - chunk;
+}
+
+static __always_inline
+size_t copy_iomem_from_user_iter(void __user *iter_from, size_t progress,
+ size_t len, void *to, void *priv2)
+{
+ unsigned char buf[SMP_CACHE_BYTES];
+ size_t chunk = min(len, sizeof(buf));
+
+ chunk -= copy_from_user_iter(iter_from, progress, chunk, buf, priv2);
+ memcpy_toio((void __iomem *)to, buf, chunk);
+ return len - chunk;
+}
+
+size_t copy_iomem_to_iter(const void __iomem *from, size_t bytes, struct iov_iter *i)
+{
+ if (WARN_ON_ONCE(i->data_source))
+ return 0;
+ if (user_backed_iter(i))
+ might_fault();
+
+ return iterate_and_advance(i, bytes, (void __force *)from,
+ copy_iomem_to_user_iter,
+ memcpy_iomem_to_iter);
+}
+EXPORT_SYMBOL(copy_iomem_to_iter);
+
+size_t copy_iomem_from_iter(void __iomem *to, size_t bytes, struct iov_iter *i)
+{
+ if (WARN_ON_ONCE(!i->data_source))
+ return 0;
+ if (user_backed_iter(i))
+ might_fault();
+
+ return iterate_and_advance(i, bytes, (void __force *)to,
+ copy_iomem_from_user_iter,
+ memcpy_iomem_from_iter);
+}
+EXPORT_SYMBOL(copy_iomem_from_iter);
+
static inline bool page_copy_sane(struct page *page, size_t offset, size_t n)
{
struct page *head;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-14 14:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 20:04 [PATCH v2 0/4] Add iomem helpers for use from debugfs Michal Wajdeczko
2024-11-12 20:04 ` [PATCH v2 1/4] iov_iter: Provide copy_iomem_to|from_iter() Michal Wajdeczko
2024-11-14 1:29 ` kernel test robot
2024-11-14 4:20 ` kernel test robot
2024-11-14 14:12 ` [PATCH v3 " Michal Wajdeczko
2024-11-12 20:04 ` [PATCH v2 2/4] libfs: Provide simple_read_from|write_to_iomem() Michal Wajdeczko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox