From patchwork Thu Jul 13 09:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DF3AC001E0 for ; Thu, 13 Jul 2023 09:40:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB8288D0007; Thu, 13 Jul 2023 05:40:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D68018D0001; Thu, 13 Jul 2023 05:40:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2FE18D0007; Thu, 13 Jul 2023 05:40:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B4D008D0001 for ; Thu, 13 Jul 2023 05:40:35 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 76373801A7 for ; Thu, 13 Jul 2023 09:40:35 +0000 (UTC) X-FDA: 81006093630.04.6ED33DE Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf29.hostedemail.com (Postfix) with ESMTP id 3B50F12001D for ; Thu, 13 Jul 2023 09:40:31 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689241233; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CULSRs+EGVOzWStogtsujbJIkl95CPb3awE35pF/W1s=; b=2UKrZbHKl9xedKfFAcPc2+8LnbKyuAo58Zy7+cBRLPZBNuIIi4IKoW0I60XLbLiKw6B6wg d+UZplWIFK9Whm7kCWUfWT9YN22sLBal0VkbDAFWkJ0QDJBuRWJAEssENU7e4E3w4M1LFO YIQYTP3AxevUboBW0uQruIheWWCB5pc= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689241233; a=rsa-sha256; cv=none; b=eIvzBALFw8cbtUFKSfjGGUG5NSWVDgzXzlT5ygGSVt0UhkcbrwpI0RIBKFaxwn8Uteyi83 oyB+as7RJ53TtwB/8N15Nx/G2EDQv1nncG/6dRnwP897jpeGWToTVcc6Tf+MpBV93an5dl GMu0i70x5ql+2Q5X7xLuHCgWYL2spBY= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R1qLp2H4wzVjg5; Thu, 13 Jul 2023 17:39:14 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 13 Jul 2023 17:40:27 +0800 From: Kefeng Wang To: , Andrew Morton , CC: Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , , , , , , , , Kefeng Wang Subject: [PATCH rfc -next 05/10] powerpc: mm: use try_vma_locked_page_fault() Date: Thu, 13 Jul 2023 17:53:33 +0800 Message-ID: <20230713095339.189715-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713095339.189715-1-wangkefeng.wang@huawei.com> References: <20230713095339.189715-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3B50F12001D X-Stat-Signature: shpz6hcpkz4b5oazn7ng47c84nj3tcx4 X-Rspam-User: X-HE-Tag: 1689241231-372652 X-HE-Meta: U2FsdGVkX1/oySPS0W20WEOSSCp4ZG7yLzyG4mk4DQyYUbsdtNkhcQZgYkskfYPeZ39c4ddd3QNtyKpVdwydhakv9abkCoBvB5R+6B2a+JoAOxf3P2dLv3/ehbOmXomu2/GtZipHSoc10tvVNaAEZPCgkEpmk9iuTTgRmm5Wu5Tr0QZhHiWi2+MFc5m0Bbhy7vCSGCv3L7eORn+dQtF+WEHHz+TgnVeB9KWhYuH0c5y3ysO/kXvilyUZiNP0FZ3B3wiVK6sSe+l3CLkIqqVGUV7C4T4zMzniXhvAqGhkNdxfb4FTukLdC203RUS0i4UJ2LOIvtVjLpyCw/xlKNwPCOVCLqUoWWV9iQb+cJEPTqzQcZzQAgOQbWyuSYkgBxqOMUS7wXu8gNb+/shTO6Ug3e5oo0A8Nsm52zlQKO3CGvOSGd5Hn7FZLoAoSQSusX2VQqHC/MEIpbNd8TLORsBd7s/9MUQqoBwKeWwaB3KbNxIRe8ZKeqd9mwyz8uXnjeKjN8mucJsHSg4GWBmjK7h73boPTN7OXkChYtEarpsMvIMwhf4IIYhX4T2L74cMe7QYjOGKfyNOSKlozb49+HeVwpzaT5VHF4eafMytWd/8Q/Dvev8C3/PiCPmUDj+uOBMoGeYNxdc+BKRZtZ5TqU2BZUqWJZIbzGvA/7w5a2zzqR+ToXmjr/Wqvai8NRt4wO5AdwgsbE6aDgYwZjvBuwX+kU+FcYFnV6Lsb7NnfgKO9G2psIupNPz8FLUEQmAc+Xx0lyxkf3lHojVeHhg5hnR5VyG3Y8L2z6AHl/tMX3x49M3aHf0LM2FJqtMSYQceC71vZwIujPOBBdz51HMcqAncvVKgEo4rSLm7AKapsb1OO7MtrLypMXKhnGQXpA52BeDro3/uDgzisKDwKWuedh19MYP5U1lkSZ1omQRs/6FZ5t4IRlliOX+ezqRufxnJziNGW+5b2B1K8t1CJy7/6bj lNZDsH/w VDrEZ8C1tnAT1mvXgl13OY1PnDLPTiq0afcgEwUsjhN1GW3dTtkAVUZ3KWZEfXVqmlM+iJOA/tdnRqvJxNDxKDL1HLBqngrdAFn2+SsaKbupnkxg51mht1NLuhDDv26vpe64q8huzxj/BeCWoVOwcaNfZi4h5+mKWH43AmSp8MO7DwIsbbypsFOz/bTQHPH90CQZH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use new try_vma_locked_page_fault() helper to simplify code. No functional change intended. Signed-off-by: Kefeng Wang --- arch/powerpc/mm/fault.c | 54 +++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 82954d0e6906..dd4832a3cf10 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -391,6 +391,23 @@ static int page_fault_is_bad(unsigned long err) #define page_fault_is_bad(__err) ((__err) & DSISR_BAD_FAULT_32S) #endif +#ifdef CONFIG_PER_VMA_LOCK +int arch_vma_check_access(struct vm_area_struct *vma, + struct vm_locked_fault *vmlf) +{ + int is_exec = TRAP(vmlf->regs) == INTERRUPT_INST_STORAGE; + int is_write = page_fault_is_write(vmlf->fault_code); + + if (unlikely(access_pkey_error(is_write, is_exec, + (vmlf->fault_code & DSISR_KEYFAULT), vma))) + return -EINVAL; + + if (unlikely(access_error(is_write, is_exec, vma))) + return -EINVAL; + return 0; +} +#endif + /* * For 600- and 800-family processors, the error_code parameter is DSISR * for a data fault, SRR1 for an instruction fault. @@ -413,6 +430,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, int is_write = page_fault_is_write(error_code); vm_fault_t fault, major = 0; bool kprobe_fault = kprobe_page_fault(regs, 11); + struct vm_locked_fault vmlf; if (unlikely(debugger_fault_handler(regs) || kprobe_fault)) return 0; @@ -469,41 +487,15 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, if (is_exec) flags |= FAULT_FLAG_INSTRUCTION; -#ifdef CONFIG_PER_VMA_LOCK - if (!(flags & FAULT_FLAG_USER)) - goto lock_mmap; - - vma = lock_vma_under_rcu(mm, address); - if (!vma) - goto lock_mmap; - - if (unlikely(access_pkey_error(is_write, is_exec, - (error_code & DSISR_KEYFAULT), vma))) { - vma_end_read(vma); - goto lock_mmap; - } - - if (unlikely(access_error(is_write, is_exec, vma))) { - vma_end_read(vma); - goto lock_mmap; - } - - fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); - if (!(fault & (VM_FAULT_RETRY | VM_FAULT_COMPLETED))) - vma_end_read(vma); - - if (!(fault & VM_FAULT_RETRY)) { - count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + VM_LOCKED_FAULT_INIT(vmlf, mm, address, flags, 0, regs, error_code); + if (try_vma_locked_page_fault(&vmlf, &fault)) + goto retry; + else if (!(fault | VM_FAULT_RETRY)) goto done; - } - count_vm_vma_lock_event(VMA_LOCK_RETRY); if (fault_signal_pending(fault, regs)) return user_mode(regs) ? 0 : SIGBUS; -lock_mmap: -#endif /* CONFIG_PER_VMA_LOCK */ - /* When running in the kernel we expect faults to occur only to * addresses in user space. All other faults represent errors in the * kernel and should generate an OOPS. Unfortunately, in the case of an @@ -552,9 +544,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, mmap_read_unlock(current->mm); -#ifdef CONFIG_PER_VMA_LOCK done: -#endif if (unlikely(fault & VM_FAULT_ERROR)) return mm_fault_error(regs, address, fault);