Skip to content

Commit 0e91a0c

Browse files
committed
mm/highmem: Provide CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP
CONFIG_DEBUG_KMAP_LOCAL, which is selected by CONFIG_DEBUG_HIGHMEM is only providing guard pages, but does not provide a mechanism to enforce the usage of the kmap_local() infrastructure. Provide CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP which forces the temporary mapping even for lowmem pages. This needs to be a seperate config switch because this only works on architectures which do not have cache aliasing problems. Suggested-by: Linus Torvalds <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6e799cb commit 0e91a0c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Kconfig.debug

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,23 @@ config DEBUG_KMAP_LOCAL
856856
This option enables additional error checking for the kmap_local
857857
infrastructure. Disable for production use.
858858

859+
config ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
860+
bool
861+
862+
config DEBUG_KMAP_LOCAL_FORCE_MAP
863+
bool "Enforce kmap_local temporary mappings"
864+
depends on DEBUG_KERNEL && ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
865+
select KMAP_LOCAL
866+
select DEBUG_KMAP_LOCAL
867+
help
868+
This option enforces temporary mappings through the kmap_local
869+
mechanism for non-highmem pages and on non-highmem systems.
870+
Disable this for production systems!
871+
859872
config DEBUG_HIGHMEM
860873
bool "Highmem debugging"
861874
depends on DEBUG_KERNEL && HIGHMEM
875+
select DEBUG_KMAP_LOCAL_FORCE_MAP if ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP
862876
select DEBUG_KMAP_LOCAL
863877
help
864878
This option enables additional error checking for high memory

mm/highmem.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,12 @@ void *__kmap_local_page_prot(struct page *page, pgprot_t prot)
474474
{
475475
void *kmap;
476476

477-
if (!PageHighMem(page))
477+
/*
478+
* To broaden the usage of the actual kmap_local() machinery always map
479+
* pages when debugging is enabled and the architecture has no problems
480+
* with alias mappings.
481+
*/
482+
if (!IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) && !PageHighMem(page))
478483
return page_address(page);
479484

480485
/* Try kmap_high_get() if architecture has it enabled */
@@ -494,6 +499,11 @@ void kunmap_local_indexed(void *vaddr)
494499

495500
if (addr < __fix_to_virt(FIX_KMAP_END) ||
496501
addr > __fix_to_virt(FIX_KMAP_BEGIN)) {
502+
if (IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP)) {
503+
/* This _should_ never happen! See above. */
504+
WARN_ON_ONCE(1);
505+
return;
506+
}
497507
/*
498508
* Handle mappings which were obtained by kmap_high_get()
499509
* first as the virtual address of such mappings is below

0 commit comments

Comments
 (0)