mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iov_iter: call kmap on each page even for lowmem if CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP is enabled
@ 2024-03-01 23:09 Barry Song
  2024-03-02  4:32 ` Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Barry Song @ 2024-03-01 23:09 UTC (permalink / raw)
  To: viro, akpm, linux-kernel; +Cc: herbert, Barry Song

From: Barry Song <v-songbaohua@oppo.com>

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@gondor.apana.org.au>
Closes: https://lore.kernel.org/all/ZeGtrvm9WGv5cxQV@gondor.apana.org.au/
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
---
 -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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-02  8:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01 23:09 [PATCH] iov_iter: call kmap on each page even for lowmem if CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP is enabled Barry Song
2024-03-02  4:32 ` Herbert Xu
2024-03-02  8:26   ` Barry Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®