ARM: mm: Provide is_write_fault() 61/281561/1
authorKefeng Wang <wangkefeng.wang@huawei.com>
Mon, 15 Nov 2021 13:48:47 +0000 (21:48 +0800)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 20 Sep 2022 02:48:06 +0000 (11:48 +0900)
The function will check whether the fault is caused by a write access,
it will be called in die_kernel_fault() too in next patch, so put it
before the function of die_kernel_fault().

Acked-by: Marco Elver <elver@google.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Link: https://lore.kernel.org/linux-arm-kernel/20211115134848.171098-3-wangkefeng.wang@huawei.com/
[port for kfence feature to rpi-5.10.95]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I489b056ed9cbd8c4dbab142f3f9e26dbd727189f

arch/arm/mm/fault.c

index 17923ef..d050021 100644 (file)
@@ -100,6 +100,11 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr)
 { }
 #endif                                 /* CONFIG_MMU */
 
+static inline bool is_write_fault(unsigned int fsr)
+{
+       return (fsr & FSR_WRITE) && !(fsr & FSR_CM);
+}
+
 static void die_kernel_fault(const char *msg, struct mm_struct *mm,
                             unsigned long addr, unsigned int fsr,
                             struct pt_regs *regs)
@@ -249,7 +254,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
        if (user_mode(regs))
                flags |= FAULT_FLAG_USER;
 
-       if ((fsr & FSR_WRITE) && !(fsr & FSR_CM)) {
+       if (is_write_fault(fsr)) {
                flags |= FAULT_FLAG_WRITE;
                vm_flags = VM_WRITE;
        }