Skip to content

Commit 97dfbbd

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
highmem: add folio_test_partial_kmap()
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]>
1 parent 6fa0451 commit 97dfbbd

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
@@ -615,6 +615,13 @@ FOLIO_FLAG(dropbehind, FOLIO_HEAD_PAGE)
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
{

0 commit comments

Comments
 (0)