[PATCH] iov_iter: call kmap on each page even for lowmem if CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP is enabled
From: Barry Song
Date: Fri Mar 01 2024 - 18:09:39 EST
From: Barry Song <v-songbaohua@xxxxxxxx>
copy_page_from_iter_atomic() has the assumption lowmem will only
need one kmap to get start page_address() for all pages. This is
wrong if the debug option CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP is
enabled. This patch fixes it in the same way with skbuff.h by
always applying kmap one by one even for lowmem,
static inline bool skb_frag_must_loop(struct page *p)
{
#if defined(CONFIG_HIGHMEM)
if (IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) || PageHighMem(p))
return true;
#endif
return false;
}
Reported-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Closes: https://lore.kernel.org/all/ZeGtrvm9WGv5cxQV@xxxxxxxxxxxxxxxxxxx/
Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx>
---
-v1:
Herbert found and pointed out this problem when he reviewed my patch
in crypto/scompress.c;
99.9% of the credit for this patch goes to Herbert.
lib/iov_iter.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index e0aa6b440ca5..2e8a5b32f152 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -490,7 +490,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset,
char *p;
n = bytes - copied;
- if (PageHighMem(page)) {
+ if (IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) || PageHighMem(page)) {
page += offset / PAGE_SIZE;
offset %= PAGE_SIZE;
n = min_t(size_t, n, PAGE_SIZE - offset);
@@ -501,7 +501,8 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset,
kunmap_atomic(p);
copied += n;
offset += n;
- } while (PageHighMem(page) && copied != bytes && n > 0);
+ } while ((IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) || PageHighMem(page))
+ && copied != bytes && n > 0);
return copied;
}
--
2.34.1