[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230713095339.189715-10-wangkefeng.wang@huawei.com>
Date: Thu, 13 Jul 2023 17:53:37 +0800
From: Kefeng Wang <wangkefeng.wang@...wei.com>
To: <linux-mm@...ck.org>, Andrew Morton <akpm@...ux-foundation.org>,
<surenb@...gle.com>
CC: Russell King <linux@...linux.org.uk>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Huacai Chen <chenhuacai@...nel.org>,
WANG Xuerui <kernel@...0n.name>,
Michael Ellerman <mpe@...erman.id.au>,
Nicholas Piggin <npiggin@...il.com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
<x86@...nel.org>, <linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>, <loongarch@...ts.linux.dev>,
<linuxppc-dev@...ts.ozlabs.org>, <linux-riscv@...ts.infradead.org>,
<linux-s390@...r.kernel.org>,
Kefeng Wang <wangkefeng.wang@...wei.com>
Subject: [PATCH rfc -next 09/10] loongarch: mm: add access_error() helper
Add access_error() to check whether vma could be accessible or not,
which will be used __do_page_fault() and later vma locked based page
fault.
Signed-off-by: Kefeng Wang <wangkefeng.wang@...wei.com>
---
arch/loongarch/mm/fault.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c
index 03d06ee184da..cde2ea0119fa 100644
--- a/arch/loongarch/mm/fault.c
+++ b/arch/loongarch/mm/fault.c
@@ -120,6 +120,22 @@ static void __kprobes do_sigsegv(struct pt_regs *regs,
force_sig_fault(SIGSEGV, si_code, (void __user *)address);
}
+static inline bool access_error(unsigned int flags, struct pt_regs *regs,
+ unsigned long addr, struct vm_area_struct *vma)
+{
+ if (flags & FAULT_FLAG_WRITE) {
+ if (!(vma->vm_flags & VM_WRITE))
+ return true;
+ } else {
+ if (!(vma->vm_flags & VM_READ) && addr != exception_era(regs))
+ return true;
+ if (!(vma->vm_flags & VM_EXEC) && addr == exception_era(regs))
+ return true;
+ }
+
+ return false;
+}
+
/*
* This routine handles page faults. It determines the address,
* and the problem, and then passes it off to one of the appropriate
@@ -163,6 +179,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
if (user_mode(regs))
flags |= FAULT_FLAG_USER;
+ if (write)
+ flags |= FAULT_FLAG_WRITE;
perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
retry:
@@ -172,16 +190,8 @@ static void __kprobes __do_page_fault(struct pt_regs *regs,
si_code = SEGV_ACCERR;
- if (write) {
- flags |= FAULT_FLAG_WRITE;
- if (!(vma->vm_flags & VM_WRITE))
- goto bad_area;
- } else {
- if (!(vma->vm_flags & VM_READ) && address != exception_era(regs))
- goto bad_area;
- if (!(vma->vm_flags & VM_EXEC) && address == exception_era(regs))
- goto bad_area;
- }
+ if (access_error(flags, regs, vma))
+ goto bad_area;
/*
* If for any reason at all we couldn't handle the fault,
--
2.27.0
Powered by blists - more mailing lists