Skip to content

Commit 971199a

Browse files
committed
Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
Pull arm64 fixes from Will Deacon: - Preserve old 'tt_core' UAPI for Hisilicon L3C PMU driver - Ensure linear alias of kprobes instruction page is not writable - Fix kernel stack unwinding from BPF - Fix build warnings from the Fujitsu uncore PMU documentation - Fix hang with deferred 'struct page' initialisation and MTE - Consolidate KPTI page-table re-writing code * tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: arm64: mte: Do not flag the zero page as PG_mte_tagged docs: perf: Fujitsu: Fix htmldocs build warnings and errors arm64: mm: Move KPTI helpers to mmu.c tracing: Fix the bug where bpf_get_stackid returns -EFAULT on the ARM64 arm64: kprobes: call set_memory_rox() for kprobe page drivers/perf: hisi: Add tt_core_deprecated for compatibility
2 parents 2215336 + f620d66 commit 971199a

9 files changed

Lines changed: 154 additions & 118 deletions

File tree

Documentation/admin-guide/perf/fujitsu_uncore_pmu.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ The driver provides a description of its available events and configuration
1515
options in sysfs, see /sys/bus/event_sources/devices/mac_iod<iod>_mac<mac>_ch<ch>/
1616
and /sys/bus/event_sources/devices/pci_iod<iod>_pci<pci>/.
1717
This driver exports:
18+
1819
- formats, used by perf user space and other tools to configure events
1920
- events, used by perf user space and other tools to create events
20-
symbolically, e.g.:
21+
symbolically, e.g.::
22+
2123
perf stat -a -e mac_iod0_mac0_ch0/event=0x21/ ls
2224
perf stat -a -e pci_iod0_pci0/event=0x24/ ls
25+
2326
- cpumask, used by perf user space and other tools to know on which CPUs
2427
to open the events
2528

2629
This driver supports the following events for MAC:
30+
2731
- cycles
2832
This event counts MAC cycles at MAC frequency.
2933
- read-count
@@ -77,6 +81,7 @@ Examples for use with perf::
7781
perf stat -e mac_iod0_mac0_ch0/ea-mac/ ls
7882

7983
And, this driver supports the following events for PCI:
84+
8085
- pci-port0-cycles
8186
This event counts PCI cycles at PCI frequency in port0.
8287
- pci-port0-read-count

Documentation/admin-guide/perf/hisi-pmu.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ specified as a bitmap::
6666

6767
This will only count the operations from core/thread 0 and 1 in this cluster.
6868

69+
User should not use tt_core_deprecated to specify the core/thread filtering.
70+
This option is provided for backward compatiblility and only support 8bit
71+
which may not cover all the core/thread sharing L3C.
72+
6973
2. Tracetag allow the user to chose to count only read, write or atomic
7074
operations via the tt_req parameeter in perf. The default value counts all
7175
operations. tt_req is 3bits, 3'b100 represents read operations, 3'b101

arch/arm64/include/asm/ftrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs)
153153
regs->pc = afregs->pc;
154154
regs->regs[29] = afregs->fp;
155155
regs->regs[30] = afregs->lr;
156+
regs->pstate = PSR_MODE_EL1h;
156157
return regs;
157158
}
158159

arch/arm64/include/asm/mmu.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
7979
extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
8080
extern void mark_linear_text_alias_ro(void);
8181
extern int split_kernel_leaf_mapping(unsigned long start, unsigned long end);
82-
extern void init_idmap_kpti_bbml2_flag(void);
8382
extern void linear_map_maybe_split_to_ptes(void);
8483

8584
/*
@@ -107,5 +106,11 @@ static inline bool kaslr_requires_kpti(void)
107106
return true;
108107
}
109108

109+
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
110+
void kpti_install_ng_mappings(void);
111+
#else
112+
static inline void kpti_install_ng_mappings(void) {}
113+
#endif
114+
110115
#endif /* !__ASSEMBLY__ */
111116
#endif

arch/arm64/kernel/cpufeature.c

Lines changed: 7 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,104 +1941,6 @@ static bool has_pmuv3(const struct arm64_cpu_capabilities *entry, int scope)
19411941
}
19421942
#endif
19431943

1944-
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1945-
#define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT))
1946-
1947-
extern
1948-
void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt,
1949-
phys_addr_t size, pgprot_t prot,
1950-
phys_addr_t (*pgtable_alloc)(enum pgtable_type), int flags);
1951-
1952-
static phys_addr_t __initdata kpti_ng_temp_alloc;
1953-
1954-
static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type)
1955-
{
1956-
kpti_ng_temp_alloc -= PAGE_SIZE;
1957-
return kpti_ng_temp_alloc;
1958-
}
1959-
1960-
static int __init __kpti_install_ng_mappings(void *__unused)
1961-
{
1962-
typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long);
1963-
extern kpti_remap_fn idmap_kpti_install_ng_mappings;
1964-
kpti_remap_fn *remap_fn;
1965-
1966-
int cpu = smp_processor_id();
1967-
int levels = CONFIG_PGTABLE_LEVELS;
1968-
int order = order_base_2(levels);
1969-
u64 kpti_ng_temp_pgd_pa = 0;
1970-
pgd_t *kpti_ng_temp_pgd;
1971-
u64 alloc = 0;
1972-
1973-
if (levels == 5 && !pgtable_l5_enabled())
1974-
levels = 4;
1975-
else if (levels == 4 && !pgtable_l4_enabled())
1976-
levels = 3;
1977-
1978-
remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings);
1979-
1980-
if (!cpu) {
1981-
alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order);
1982-
kpti_ng_temp_pgd = (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE);
1983-
kpti_ng_temp_alloc = kpti_ng_temp_pgd_pa = __pa(kpti_ng_temp_pgd);
1984-
1985-
//
1986-
// Create a minimal page table hierarchy that permits us to map
1987-
// the swapper page tables temporarily as we traverse them.
1988-
//
1989-
// The physical pages are laid out as follows:
1990-
//
1991-
// +--------+-/-------+-/------ +-/------ +-\\\--------+
1992-
// : PTE[] : | PMD[] : | PUD[] : | P4D[] : ||| PGD[] :
1993-
// +--------+-\-------+-\------ +-\------ +-///--------+
1994-
// ^
1995-
// The first page is mapped into this hierarchy at a PMD_SHIFT
1996-
// aligned virtual address, so that we can manipulate the PTE
1997-
// level entries while the mapping is active. The first entry
1998-
// covers the PTE[] page itself, the remaining entries are free
1999-
// to be used as a ad-hoc fixmap.
2000-
//
2001-
create_kpti_ng_temp_pgd(kpti_ng_temp_pgd, __pa(alloc),
2002-
KPTI_NG_TEMP_VA, PAGE_SIZE, PAGE_KERNEL,
2003-
kpti_ng_pgd_alloc, 0);
2004-
}
2005-
2006-
cpu_install_idmap();
2007-
remap_fn(cpu, num_online_cpus(), kpti_ng_temp_pgd_pa, KPTI_NG_TEMP_VA);
2008-
cpu_uninstall_idmap();
2009-
2010-
if (!cpu) {
2011-
free_pages(alloc, order);
2012-
arm64_use_ng_mappings = true;
2013-
}
2014-
2015-
return 0;
2016-
}
2017-
2018-
static void __init kpti_install_ng_mappings(void)
2019-
{
2020-
/* Check whether KPTI is going to be used */
2021-
if (!arm64_kernel_unmapped_at_el0())
2022-
return;
2023-
2024-
/*
2025-
* We don't need to rewrite the page-tables if either we've done
2026-
* it already or we have KASLR enabled and therefore have not
2027-
* created any global mappings at all.
2028-
*/
2029-
if (arm64_use_ng_mappings)
2030-
return;
2031-
2032-
init_idmap_kpti_bbml2_flag();
2033-
stop_machine(__kpti_install_ng_mappings, NULL, cpu_online_mask);
2034-
}
2035-
2036-
#else
2037-
static inline void kpti_install_ng_mappings(void)
2038-
{
2039-
}
2040-
#endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */
2041-
20421944
static void cpu_enable_kpti(struct arm64_cpu_capabilities const *cap)
20431945
{
20441946
if (__this_cpu_read(this_cpu_vector) == vectors) {
@@ -2419,17 +2321,21 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused)
24192321
#ifdef CONFIG_ARM64_MTE
24202322
static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap)
24212323
{
2324+
static bool cleared_zero_page = false;
2325+
24222326
sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0);
24232327

24242328
mte_cpu_setup();
24252329

24262330
/*
24272331
* Clear the tags in the zero page. This needs to be done via the
2428-
* linear map which has the Tagged attribute.
2332+
* linear map which has the Tagged attribute. Since this page is
2333+
* always mapped as pte_special(), set_pte_at() will not attempt to
2334+
* clear the tags or set PG_mte_tagged.
24292335
*/
2430-
if (try_page_mte_tagging(ZERO_PAGE(0))) {
2336+
if (!cleared_zero_page) {
2337+
cleared_zero_page = true;
24312338
mte_clear_page_tags(lm_alias(empty_zero_page));
2432-
set_page_mte_tagged(ZERO_PAGE(0));
24332339
}
24342340

24352341
kasan_init_hw_tags_cpu();

arch/arm64/kernel/mte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr,
478478
if (folio_test_hugetlb(folio))
479479
WARN_ON_ONCE(!folio_test_hugetlb_mte_tagged(folio));
480480
else
481-
WARN_ON_ONCE(!page_mte_tagged(page));
481+
WARN_ON_ONCE(!page_mte_tagged(page) && !is_zero_page(page));
482482

483483
/* limit access to the end of the page */
484484
offset = offset_in_page(addr);

arch/arm64/kernel/probes/kprobes.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#define pr_fmt(fmt) "kprobes: " fmt
1212

13+
#include <linux/execmem.h>
1314
#include <linux/extable.h>
1415
#include <linux/kasan.h>
1516
#include <linux/kernel.h>
@@ -41,6 +42,17 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
4142
static void __kprobes
4243
post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
4344

45+
void *alloc_insn_page(void)
46+
{
47+
void *addr;
48+
49+
addr = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
50+
if (!addr)
51+
return NULL;
52+
set_memory_rox((unsigned long)addr, 1);
53+
return addr;
54+
}
55+
4456
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
4557
{
4658
kprobe_opcode_t *addr = p->ainsn.xol_insn;

arch/arm64/mm/mmu.c

Lines changed: 88 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,6 @@ static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
470470
mutex_unlock(&fixmap_lock);
471471
}
472472

473-
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
474-
extern __alias(__create_pgd_mapping_locked)
475-
void create_kpti_ng_temp_pgd(pgd_t *pgdir, phys_addr_t phys, unsigned long virt,
476-
phys_addr_t size, pgprot_t prot,
477-
phys_addr_t (*pgtable_alloc)(enum pgtable_type),
478-
int flags);
479-
#endif
480-
481473
#define INVALID_PHYS_ADDR (-1ULL)
482474

483475
static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp,
@@ -823,7 +815,7 @@ static bool linear_map_requires_bbml2 __initdata;
823815

824816
u32 idmap_kpti_bbml2_flag;
825817

826-
void __init init_idmap_kpti_bbml2_flag(void)
818+
static void __init init_idmap_kpti_bbml2_flag(void)
827819
{
828820
WRITE_ONCE(idmap_kpti_bbml2_flag, 1);
829821
/* Must be visible to other CPUs before stop_machine() is called. */
@@ -1135,7 +1127,93 @@ static void __init declare_vma(struct vm_struct *vma,
11351127
}
11361128

11371129
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
1138-
static pgprot_t kernel_exec_prot(void)
1130+
#define KPTI_NG_TEMP_VA (-(1UL << PMD_SHIFT))
1131+
1132+
static phys_addr_t kpti_ng_temp_alloc __initdata;
1133+
1134+
static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type)
1135+
{
1136+
kpti_ng_temp_alloc -= PAGE_SIZE;
1137+
return kpti_ng_temp_alloc;
1138+
}
1139+
1140+
static int __init __kpti_install_ng_mappings(void *__unused)
1141+
{
1142+
typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long);
1143+
extern kpti_remap_fn idmap_kpti_install_ng_mappings;
1144+
kpti_remap_fn *remap_fn;
1145+
1146+
int cpu = smp_processor_id();
1147+
int levels = CONFIG_PGTABLE_LEVELS;
1148+
int order = order_base_2(levels);
1149+
u64 kpti_ng_temp_pgd_pa = 0;
1150+
pgd_t *kpti_ng_temp_pgd;
1151+
u64 alloc = 0;
1152+
1153+
if (levels == 5 && !pgtable_l5_enabled())
1154+
levels = 4;
1155+
else if (levels == 4 && !pgtable_l4_enabled())
1156+
levels = 3;
1157+
1158+
remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings);
1159+
1160+
if (!cpu) {
1161+
alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order);
1162+
kpti_ng_temp_pgd = (pgd_t *)(alloc + (levels - 1) * PAGE_SIZE);
1163+
kpti_ng_temp_alloc = kpti_ng_temp_pgd_pa = __pa(kpti_ng_temp_pgd);
1164+
1165+
//
1166+
// Create a minimal page table hierarchy that permits us to map
1167+
// the swapper page tables temporarily as we traverse them.
1168+
//
1169+
// The physical pages are laid out as follows:
1170+
//
1171+
// +--------+-/-------+-/------ +-/------ +-\\\--------+
1172+
// : PTE[] : | PMD[] : | PUD[] : | P4D[] : ||| PGD[] :
1173+
// +--------+-\-------+-\------ +-\------ +-///--------+
1174+
// ^
1175+
// The first page is mapped into this hierarchy at a PMD_SHIFT
1176+
// aligned virtual address, so that we can manipulate the PTE
1177+
// level entries while the mapping is active. The first entry
1178+
// covers the PTE[] page itself, the remaining entries are free
1179+
// to be used as a ad-hoc fixmap.
1180+
//
1181+
__create_pgd_mapping_locked(kpti_ng_temp_pgd, __pa(alloc),
1182+
KPTI_NG_TEMP_VA, PAGE_SIZE, PAGE_KERNEL,
1183+
kpti_ng_pgd_alloc, 0);
1184+
}
1185+
1186+
cpu_install_idmap();
1187+
remap_fn(cpu, num_online_cpus(), kpti_ng_temp_pgd_pa, KPTI_NG_TEMP_VA);
1188+
cpu_uninstall_idmap();
1189+
1190+
if (!cpu) {
1191+
free_pages(alloc, order);
1192+
arm64_use_ng_mappings = true;
1193+
}
1194+
1195+
return 0;
1196+
}
1197+
1198+
void __init kpti_install_ng_mappings(void)
1199+
{
1200+
/* Check whether KPTI is going to be used */
1201+
if (!arm64_kernel_unmapped_at_el0())
1202+
return;
1203+
1204+
/*
1205+
* We don't need to rewrite the page-tables if either we've done
1206+
* it already or we have KASLR enabled and therefore have not
1207+
* created any global mappings at all.
1208+
*/
1209+
if (arm64_use_ng_mappings)
1210+
return;
1211+
1212+
init_idmap_kpti_bbml2_flag();
1213+
stop_machine(__kpti_install_ng_mappings, NULL, cpu_online_mask);
1214+
}
1215+
1216+
static pgprot_t __init kernel_exec_prot(void)
11391217
{
11401218
return rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
11411219
}

0 commit comments

Comments
 (0)