Skip to content

Commit 42d1a73

Browse files
committed
Merge branch 'aarch64/for-next/debug-virtual' into aarch64/for-next/core
Merge core DEBUG_VIRTUAL changes from Laura Abbott. Later arm and arm64 support depends on these. * aarch64/for-next/debug-virtual: drivers: firmware: psci: Use __pa_symbol for kernel symbol mm/usercopy: Switch to using lm_alias mm/kasan: Switch to using __pa_symbol and lm_alias kexec: Switch to __pa_symbol mm: Introduce lm_alias mm/cma: Cleanup highmem check lib/Kconfig.debug: Add ARCH_HAS_DEBUG_VIRTUAL
2 parents 4aa8a47 + 1a08e3d commit 42d1a73

File tree

8 files changed

+26
-22
lines changed

8 files changed

+26
-22
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ config X86
4646
select ARCH_CLOCKSOURCE_DATA
4747
select ARCH_DISCARD_MEMBLOCK
4848
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
49+
select ARCH_HAS_DEBUG_VIRTUAL
4950
select ARCH_HAS_DEVMEM_IS_ALLOWED
5051
select ARCH_HAS_ELF_RANDOMIZE
5152
select ARCH_HAS_FAST_MULTIPLIER

drivers/firmware/psci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int psci_suspend_finisher(unsigned long index)
383383
u32 *state = __this_cpu_read(psci_power_state);
384384

385385
return psci_ops.cpu_suspend(state[index - 1],
386-
virt_to_phys(cpu_resume));
386+
__pa_symbol(cpu_resume));
387387
}
388388

389389
int psci_cpu_suspend_enter(unsigned long index)

include/linux/mm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ extern int mmap_rnd_compat_bits __read_mostly;
7676
#define page_to_virt(x) __va(PFN_PHYS(page_to_pfn(x)))
7777
#endif
7878

79+
#ifndef lm_alias
80+
#define lm_alias(x) __va(__pa_symbol(x))
81+
#endif
82+
7983
/*
8084
* To prevent common memory management code establishing
8185
* a zero page mapping on a read fault.

kernel/kexec_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ void __weak arch_crash_save_vmcoreinfo(void)
13991399

14001400
phys_addr_t __weak paddr_vmcoreinfo_note(void)
14011401
{
1402-
return __pa((unsigned long)(char *)&vmcoreinfo_note);
1402+
return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
14031403
}
14041404

14051405
static int __init crash_save_vmcoreinfo_init(void)

lib/Kconfig.debug

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,12 @@ config DEBUG_VM_PGFLAGS
622622

623623
If unsure, say N.
624624

625+
config ARCH_HAS_DEBUG_VIRTUAL
626+
bool
627+
625628
config DEBUG_VIRTUAL
626629
bool "Debug VM translations"
627-
depends on DEBUG_KERNEL && X86
630+
depends on DEBUG_KERNEL && ARCH_HAS_DEBUG_VIRTUAL
628631
help
629632
Enable some costly sanity checks in virtual to page code. This can
630633
catch mistakes with virt_to_page() and friends.

mm/cma.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,13 @@ int __init cma_declare_contiguous(phys_addr_t base,
235235
phys_addr_t highmem_start;
236236
int ret = 0;
237237

238-
#ifdef CONFIG_X86
239238
/*
240-
* high_memory isn't direct mapped memory so retrieving its physical
241-
* address isn't appropriate. But it would be useful to check the
242-
* physical address of the highmem boundary so it's justifiable to get
243-
* the physical address from it. On x86 there is a validation check for
244-
* this case, so the following workaround is needed to avoid it.
239+
* We can't use __pa(high_memory) directly, since high_memory
240+
* isn't a valid direct map VA, and DEBUG_VIRTUAL will (validly)
241+
* complain. Find the boundary by adding one to the last valid
242+
* address.
245243
*/
246-
highmem_start = __pa_nodebug(high_memory);
247-
#else
248-
highmem_start = __pa(high_memory);
249-
#endif
244+
highmem_start = __pa(high_memory - 1) + 1;
250245
pr_debug("%s(size %pa, base %pa, limit %pa alignment %pa)\n",
251246
__func__, &size, &base, &limit, &alignment);
252247

mm/kasan/kasan_init.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/kasan.h>
1616
#include <linux/kernel.h>
1717
#include <linux/memblock.h>
18+
#include <linux/mm.h>
1819
#include <linux/pfn.h>
1920

2021
#include <asm/page.h>
@@ -49,7 +50,7 @@ static void __init zero_pte_populate(pmd_t *pmd, unsigned long addr,
4950
pte_t *pte = pte_offset_kernel(pmd, addr);
5051
pte_t zero_pte;
5152

52-
zero_pte = pfn_pte(PFN_DOWN(__pa(kasan_zero_page)), PAGE_KERNEL);
53+
zero_pte = pfn_pte(PFN_DOWN(__pa_symbol(kasan_zero_page)), PAGE_KERNEL);
5354
zero_pte = pte_wrprotect(zero_pte);
5455

5556
while (addr + PAGE_SIZE <= end) {
@@ -69,7 +70,7 @@ static void __init zero_pmd_populate(pud_t *pud, unsigned long addr,
6970
next = pmd_addr_end(addr, end);
7071

7172
if (IS_ALIGNED(addr, PMD_SIZE) && end - addr >= PMD_SIZE) {
72-
pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
73+
pmd_populate_kernel(&init_mm, pmd, lm_alias(kasan_zero_pte));
7374
continue;
7475
}
7576

@@ -92,9 +93,9 @@ static void __init zero_pud_populate(pgd_t *pgd, unsigned long addr,
9293
if (IS_ALIGNED(addr, PUD_SIZE) && end - addr >= PUD_SIZE) {
9394
pmd_t *pmd;
9495

95-
pud_populate(&init_mm, pud, kasan_zero_pmd);
96+
pud_populate(&init_mm, pud, lm_alias(kasan_zero_pmd));
9697
pmd = pmd_offset(pud, addr);
97-
pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
98+
pmd_populate_kernel(&init_mm, pmd, lm_alias(kasan_zero_pte));
9899
continue;
99100
}
100101

@@ -135,11 +136,11 @@ void __init kasan_populate_zero_shadow(const void *shadow_start,
135136
* puds,pmds, so pgd_populate(), pud_populate()
136137
* is noops.
137138
*/
138-
pgd_populate(&init_mm, pgd, kasan_zero_pud);
139+
pgd_populate(&init_mm, pgd, lm_alias(kasan_zero_pud));
139140
pud = pud_offset(pgd, addr);
140-
pud_populate(&init_mm, pud, kasan_zero_pmd);
141+
pud_populate(&init_mm, pud, lm_alias(kasan_zero_pmd));
141142
pmd = pmd_offset(pud, addr);
142-
pmd_populate_kernel(&init_mm, pmd, kasan_zero_pte);
143+
pmd_populate_kernel(&init_mm, pmd, lm_alias(kasan_zero_pte));
143144
continue;
144145
}
145146

mm/usercopy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ static inline const char *check_kernel_text_object(const void *ptr,
108108
* __pa() is not just the reverse of __va(). This can be detected
109109
* and checked:
110110
*/
111-
textlow_linear = (unsigned long)__va(__pa(textlow));
111+
textlow_linear = (unsigned long)lm_alias(textlow);
112112
/* No different mapping: we're done. */
113113
if (textlow_linear == textlow)
114114
return NULL;
115115

116116
/* Check the secondary mapping... */
117-
texthigh_linear = (unsigned long)__va(__pa(texthigh));
117+
texthigh_linear = (unsigned long)lm_alias(texthigh);
118118
if (overlaps(ptr, n, textlow_linear, texthigh_linear))
119119
return "<linear kernel text>";
120120

0 commit comments

Comments
 (0)