History

highmem: add folio_test_partial_kmap()

In commit c749d9b7ebbc ("iov_iter: fix copy_page_from_iter_atomic() if KMAP_LOCAL_FORCE_MAP"), Hugh correctly noted that if KMAP_LOCAL_FORCE_MAP is enabled, we must limit ourselves to PAGE_SIZE bytes per call to kmap_local(). The same problem exists in memcpy_from_folio(), memcpy_to_folio(), folio_zero_tail(), folio_fill_tail() and memcpy_from_file_folio(), so add folio_test_partial_kmap() to do this more succinctly.

Matthew Wilcox (Oracle) committed 1 year ago

Commit 97dfbbd1 parent 6fa04512 files · +12 −5Browse files

Showing the changes to include (2 of 2 files). Show all

Unified · Split

2 files
  1. include/linux/highmem.h +5 −5
  2. include/linux/page-flags.h +7 −0
include/linux/highmem.h+5−5
@@ -461,7 +461,7 @@ static inline void memcpy_from_folio(char *to, struct folio *folio, · 460 unmodified lines
461461 const char *from = kmap_local_folio(folio, offset);
462462 size_t chunk = len;
463463
464− if (folio_test_highmem(folio) &&
464+ if (folio_test_partial_kmap(folio) &&
465465 chunk > PAGE_SIZE - offset_in_page(offset))
466466 chunk = PAGE_SIZE - offset_in_page(offset);
467467 memcpy(to, from, chunk);
@@ -489,7 +489,7 @@ static inline void memcpy_to_folio(struct folio *folio, size_t offset, · 21 unmodified lines
489489 char *to = kmap_local_folio(folio, offset);
490490 size_t chunk = len;
491491
492− if (folio_test_highmem(folio) &&
492+ if (folio_test_partial_kmap(folio) &&
493493 chunk > PAGE_SIZE - offset_in_page(offset))
494494 chunk = PAGE_SIZE - offset_in_page(offset);
495495 memcpy(to, from, chunk);
@@ -522,7 +522,7 @@ static inline __must_check void *folio_zero_tail(struct folio *folio, · 26 unmodified lines
522522 {
523523 size_t len = folio_size(folio) - offset;
524524
525− if (folio_test_highmem(folio)) {
525+ if (folio_test_partial_kmap(folio)) {
526526 size_t max = PAGE_SIZE - offset_in_page(offset);
527527
528528 while (len > max) {
@@ -560,7 +560,7 @@ static inline void folio_fill_tail(struct folio *folio, size_t offset, · 31 unmodified lines
560560
561561 VM_BUG_ON(offset + len > folio_size(folio));
562562
563− if (folio_test_highmem(folio)) {
563+ if (folio_test_partial_kmap(folio)) {
564564 size_t max = PAGE_SIZE - offset_in_page(offset);
565565
566566 while (len > max) {
@@ -597,7 +597,7 @@ static inline size_t memcpy_from_file_folio(char *to, struct folio *folio, · 30 unmodified lines
597597 size_t offset = offset_in_folio(folio, pos);
598598 char *from = kmap_local_folio(folio, offset);
599599
600− if (folio_test_highmem(folio)) {
600+ if (folio_test_partial_kmap(folio)) {
601601 offset = offset_in_page(offset);
602602 len = min_t(size_t, len, PAGE_SIZE - offset);
603603 } else
include/linux/page-flags.h+7−0
@@ -615,6 +615,13 @@ FOLIO_FLAG(dropbehind, FOLIO_HEAD_PAGE) · 614 unmodified lines
615615 PAGEFLAG_FALSE(HighMem, highmem)
616616 #endif
617617
618+/* Does kmap_local_folio() only allow access to one page of the folio? */
619+#ifdef CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP
620+#define folio_test_partial_kmap(f) true
621+#else
622+#define folio_test_partial_kmap(f) folio_test_highmem(f)
623+#endif
624+
618625 #ifdef CONFIG_SWAP
619626 static __always_inline bool folio_test_swapcache(const struct folio *folio)
620627 {