Skip to content

Commit 9b8263c

Browse files
Matthew Wilcox (Oracle)gregkh
authored andcommitted
highmem: add folio_test_partial_kmap()
commit 97dfbbd upstream. In commit c749d9b ("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. Link: https://lkml.kernel.org/r/[email protected] Fixes: 00cdf76 ("mm: add memcpy_from_file_folio()") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Al Viro <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cb9a101 commit 9b8263c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

include/linux/highmem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static inline void memcpy_from_folio(char *to, struct folio *folio,
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,
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,
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,
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,
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ FOLIO_FLAG(readahead, FOLIO_HEAD_PAGE)
573573
PAGEFLAG_FALSE(HighMem, highmem)
574574
#endif
575575

576+
/* Does kmap_local_folio() only allow access to one page of the folio? */
577+
#ifdef CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP
578+
#define folio_test_partial_kmap(f) true
579+
#else
580+
#define folio_test_partial_kmap(f) folio_test_highmem(f)
581+
#endif
582+
576583
#ifdef CONFIG_SWAP
577584
static __always_inline bool folio_test_swapcache(const struct folio *folio)
578585
{

0 commit comments

Comments
 (0)