Commit 7267ef7b authored by Ben Hutchings's avatar Ben Hutchings Committed by Linus Torvalds

riscv/mm: Convert to using lock_mm_and_find_vma()

Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4bce37a6
...@@ -126,6 +126,7 @@ config RISCV ...@@ -126,6 +126,7 @@ config RISCV
select IRQ_DOMAIN select IRQ_DOMAIN
select IRQ_FORCED_THREADING select IRQ_FORCED_THREADING
select KASAN_VMALLOC if KASAN select KASAN_VMALLOC if KASAN
select LOCK_MM_AND_FIND_VMA
select MODULES_USE_ELF_RELA if MODULES select MODULES_USE_ELF_RELA if MODULES
select MODULE_SECTIONS if MODULES select MODULE_SECTIONS if MODULES
select OF select OF
......
...@@ -84,13 +84,13 @@ static inline void mm_fault_error(struct pt_regs *regs, unsigned long addr, vm_f ...@@ -84,13 +84,13 @@ static inline void mm_fault_error(struct pt_regs *regs, unsigned long addr, vm_f
BUG(); BUG();
} }
static inline void bad_area(struct pt_regs *regs, struct mm_struct *mm, int code, unsigned long addr) static inline void
bad_area_nosemaphore(struct pt_regs *regs, int code, unsigned long addr)
{ {
/* /*
* Something tried to access memory that isn't in our memory map. * Something tried to access memory that isn't in our memory map.
* Fix it, but check if it's kernel or user first. * Fix it, but check if it's kernel or user first.
*/ */
mmap_read_unlock(mm);
/* User mode accesses just cause a SIGSEGV */ /* User mode accesses just cause a SIGSEGV */
if (user_mode(regs)) { if (user_mode(regs)) {
do_trap(regs, SIGSEGV, code, addr); do_trap(regs, SIGSEGV, code, addr);
...@@ -100,6 +100,15 @@ static inline void bad_area(struct pt_regs *regs, struct mm_struct *mm, int code ...@@ -100,6 +100,15 @@ static inline void bad_area(struct pt_regs *regs, struct mm_struct *mm, int code
no_context(regs, addr); no_context(regs, addr);
} }
static inline void
bad_area(struct pt_regs *regs, struct mm_struct *mm, int code,
unsigned long addr)
{
mmap_read_unlock(mm);
bad_area_nosemaphore(regs, code, addr);
}
static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long addr) static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long addr)
{ {
pgd_t *pgd, *pgd_k; pgd_t *pgd, *pgd_k;
...@@ -287,23 +296,10 @@ void handle_page_fault(struct pt_regs *regs) ...@@ -287,23 +296,10 @@ void handle_page_fault(struct pt_regs *regs)
else if (cause == EXC_INST_PAGE_FAULT) else if (cause == EXC_INST_PAGE_FAULT)
flags |= FAULT_FLAG_INSTRUCTION; flags |= FAULT_FLAG_INSTRUCTION;
retry: retry:
mmap_read_lock(mm); vma = lock_mm_and_find_vma(mm, addr, regs);
vma = find_vma(mm, addr);
if (unlikely(!vma)) { if (unlikely(!vma)) {
tsk->thread.bad_cause = cause; tsk->thread.bad_cause = cause;
bad_area(regs, mm, code, addr); bad_area_nosemaphore(regs, code, addr);
return;
}
if (likely(vma->vm_start <= addr))
goto good_area;
if (unlikely(!(vma->vm_flags & VM_GROWSDOWN))) {
tsk->thread.bad_cause = cause;
bad_area(regs, mm, code, addr);
return;
}
if (unlikely(expand_stack(vma, addr))) {
tsk->thread.bad_cause = cause;
bad_area(regs, mm, code, addr);
return; return;
} }
...@@ -311,7 +307,6 @@ void handle_page_fault(struct pt_regs *regs) ...@@ -311,7 +307,6 @@ void handle_page_fault(struct pt_regs *regs)
* Ok, we have a good vm_area for this memory access, so * Ok, we have a good vm_area for this memory access, so
* we can handle it. * we can handle it.
*/ */
good_area:
code = SEGV_ACCERR; code = SEGV_ACCERR;
if (unlikely(access_error(cause, vma))) { if (unlikely(access_error(cause, vma))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment