Skip to content

Commit 8e9a842

Browse files
committed
Merge tag 'riscv-for-linus-6.2-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V fixes from Palmer Dabbelt: "This is a little bigger that I'd hope for this late in the cycle, but they're all pretty concrete fixes and the only one that's bigger than a few lines is pmdp_collapse_flush() (which is almost all boilerplate/comment). It's also all bug fixes for issues that have been around for a while. So I think it's not all that scary, just bad timing. - avoid partial TLB fences for huge pages, which are disallowed by the ISA - avoid missing a frame when dumping stacks - avoid misaligned accesses (and possibly overflows) in kprobes - fix a race condition in tracking page dirtiness" * tag 'riscv-for-linus-6.2-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte riscv: kprobe: Fixup misaligned load text riscv: stacktrace: Fix missing the first frame riscv: mm: Implement pmdp_collapse_flush for THP
2 parents 3647d2d + 950b879 commit 8e9a842

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
721721
page_table_check_pmd_set(vma->vm_mm, address, pmdp, pmd);
722722
return __pmd(atomic_long_xchg((atomic_long_t *)pmdp, pmd_val(pmd)));
723723
}
724+
725+
#define pmdp_collapse_flush pmdp_collapse_flush
726+
extern pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
727+
unsigned long address, pmd_t *pmdp);
724728
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
725729

726730
/*

arch/riscv/kernel/probes/kprobes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ static bool __kprobes arch_check_kprobe(struct kprobe *p)
6565

6666
int __kprobes arch_prepare_kprobe(struct kprobe *p)
6767
{
68-
unsigned long probe_addr = (unsigned long)p->addr;
68+
u16 *insn = (u16 *)p->addr;
6969

70-
if (probe_addr & 0x1)
70+
if ((unsigned long)insn & 0x1)
7171
return -EILSEQ;
7272

7373
if (!arch_check_kprobe(p))
7474
return -EILSEQ;
7575

7676
/* copy instruction */
77-
p->opcode = *p->addr;
77+
p->opcode = (kprobe_opcode_t)(*insn++);
78+
if (GET_INSN_LENGTH(p->opcode) == 4)
79+
p->opcode |= (kprobe_opcode_t)(*insn) << 16;
7880

7981
/* decode instruction */
8082
switch (riscv_probe_decode_insn(p->addr, &p->ainsn.api)) {

arch/riscv/kernel/stacktrace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
3232
fp = (unsigned long)__builtin_frame_address(0);
3333
sp = current_stack_pointer;
3434
pc = (unsigned long)walk_stackframe;
35+
level = -1;
3536
} else {
3637
/* task blocked in __switch_to */
3738
fp = task->thread.s[0];
@@ -43,7 +44,7 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
4344
unsigned long low, high;
4445
struct stackframe *frame;
4546

46-
if (unlikely(!__kernel_text_address(pc) || (level++ >= 1 && !fn(arg, pc))))
47+
if (unlikely(!__kernel_text_address(pc) || (level++ >= 0 && !fn(arg, pc))))
4748
break;
4849

4950
/* Validate frame pointer */

arch/riscv/mm/cacheflush.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ void flush_icache_pte(pte_t pte)
9090
if (PageHuge(page))
9191
page = compound_head(page);
9292

93-
if (!test_and_set_bit(PG_dcache_clean, &page->flags))
93+
if (!test_bit(PG_dcache_clean, &page->flags)) {
9494
flush_icache_all();
95+
set_bit(PG_dcache_clean, &page->flags);
96+
}
9597
}
9698
#endif /* CONFIG_MMU */
9799

arch/riscv/mm/pgtable.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,23 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
8181
}
8282

8383
#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
84+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
85+
pmd_t pmdp_collapse_flush(struct vm_area_struct *vma,
86+
unsigned long address, pmd_t *pmdp)
87+
{
88+
pmd_t pmd = pmdp_huge_get_and_clear(vma->vm_mm, address, pmdp);
89+
90+
VM_BUG_ON(address & ~HPAGE_PMD_MASK);
91+
VM_BUG_ON(pmd_trans_huge(*pmdp));
92+
/*
93+
* When leaf PTE entries (regular pages) are collapsed into a leaf
94+
* PMD entry (huge page), a valid non-leaf PTE is converted into a
95+
* valid leaf PTE at the level 1 page table. Since the sfence.vma
96+
* forms that specify an address only apply to leaf PTEs, we need a
97+
* global flush here. collapse_huge_page() assumes these flushes are
98+
* eager, so just do the fence here.
99+
*/
100+
flush_tlb_mm(vma->vm_mm);
101+
return pmd;
102+
}
103+
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

0 commit comments

Comments
 (0)