From patchwork Mon Aug 21 12:30:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359373 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 D7472EE49AA for ; Mon, 21 Aug 2023 12:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF96A8D000F; Mon, 21 Aug 2023 08:31:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CCF888D0002; Mon, 21 Aug 2023 08:31:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B48258D000F; Mon, 21 Aug 2023 08:31:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A81908D0002 for ; Mon, 21 Aug 2023 08:31:27 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3B928A0BD4 for ; Mon, 21 Aug 2023 12:31:27 +0000 (UTC) X-FDA: 81148047414.01.9328BDD Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id B3F06C0024 for ; Mon, 21 Aug 2023 12:31:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692621085; a=rsa-sha256; cv=none; b=Bs2UcbEdM7PvfTA0tDe0LcJFL8TkIs6Cs+vawIB73zukKjQvGIWHmYHnNEuQs/K07TlREd GtP4R1ihGdJs199XR1t1WmjOmVkEhaTf5wxWQ3dIdg9Ny6e3RRZ0lza6SbkgDvqDDsKvTn qKMrNl+zpXc254rIORgxvQTwF73SUEw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692621085; 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=AZ8jFv70nL0yis8cw2hxyNkLT4NIf61vqExlmfu8DlI=; b=P3evthLiShkoRxNE2vN+kxb+/OY+Z3V7S/HspCH1Sb0fYF2iT26y9VTPQqQ6JR+N3qOQ5k Z27XWxIH1wOfzTv9WD2VbNoFUCee/PwWb78avmW1JEyL98pLcvhsYjaKpuZ2oaw43jdr4f Iw61GeIbrg4RWsAqjirzoLWSQmYu1bw= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTsFF3Rj6zNnTN; Mon, 21 Aug 2023 20:27:45 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 21 Aug 2023 20:31:17 +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 , , "H . Peter Anvin" , , , , , , , Kefeng Wang Subject: [PATCH rfc v2 05/10] powerpc: mm: use try_vma_locked_page_fault() Date: Mon, 21 Aug 2023 20:30:51 +0800 Message-ID: <20230821123056.2109942-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230821123056.2109942-1-wangkefeng.wang@huawei.com> References: <20230821123056.2109942-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B3F06C0024 X-Stat-Signature: r4irqx7kpk8a7jzr9w56qjtnftq7ufh1 X-HE-Tag: 1692621084-804339 X-HE-Meta: U2FsdGVkX18VhblmrstA/kooTpkFw/auNgAWwub5WxaxIM7H6DUMgIlW/voXeiZ1dJ2+CHujIcUxdcIMo3dpR582pPjUf+RQgrD3qFMb6va4S41JhvOgIiU7muJISSJ4wCBVH0v6VX27RNmJxKbT2KogNG3a1k/gSawMpNNoHARoDMuLyr8NrwT+N9TfpaAWHnu+uoRF7DmPIUu/fZZB02IZHobgvHpF+Bhlgqb2dCNnjFwS/14YLb/fxn3JOoDIDG6Nf5Ggp6Rv/TmxyLTxSsQAANa/fS3Lkh5B6XuBv3ocmQ7Q5JccJE0Hin0t+kRAeA9TOwuymKhgI0jVz7EPRbf+1L/01hCOup6lnXcBmE18N2FMkp6CJcWHNGm3MxFt0flKNQiT5u/SuHfCqPdjQIsLArdTaoNpAQuO1QYXuOpApa+QFe2yzUbwuFK3qC1F0EVgrjsDeNoHcfOTNXRkwc8TfvyYmHuodM3+y1nOny2eb3QyvTrKtPnYv/rP5ij75j94DZn39NXzoW2WbHbuBKAUrC636f0steGZIjzhh4gi+I+9GcQnvqkHkEjWaL0Sf22nHiAPLdBhNvhzthB9smz1JV4VeOC2CHBqeX5cy4YiHTQda9y17yGR/tbcfehdgNc3IkVBga7XjtiDGq2t/0KqChJKd4mqV6Vg7XCzqGd74WPQexDccTI2vNl3pzUZLWbXu7yIYOzQxaErTl8j/T3SmQ2OWSlsw/0SwJVYKCMP8qDhMc6pL2dkTMV9gLfvTExNxL+AykbizSWUN5RbSAn3LpIlJRjntgoESLCqH6WWhG1PFaGpuPawHcRnbf9LdaHTV3png4cehPTTYxTZuZGik4BAsxstl0qhXasCP87+oSeyXH6vbNs0Bs99oeqiSDandsDQXk1Zm6H6b2QuQgkJiirh/QO35Jn9B9h+HyqZ0Z0Sf/aAbJQxUMzJGe10zDc68YmQM7CPWf0BOyQ lvMi4/wb IdX7mRcIPd16DYcNkRM4rC8e+zCdhFwRh+fyWVLva5flaFdgqE/oaQITtjb6TKRaS7cL4EQlvLZVX+FYTk9d86pqIumIy+yorrcRZN40Yb12kRe6Rp95OdOdzL/T62TcnRSxEZWcosEpZ08VU8WYofxN0Aw7maC2BTS/Mdal71wu8sgkyINmdHbsPQEzhiEMdDqIg 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 | 66 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index b1723094d464..52f9546e020e 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -391,6 +391,22 @@ 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 +bool arch_vma_access_error(struct vm_area_struct *vma, struct vm_fault *vmf) +{ + int is_exec = TRAP(vmf->regs) == INTERRUPT_INST_STORAGE; + int is_write = page_fault_is_write(vmf->fault_code); + + if (unlikely(access_pkey_error(is_write, is_exec, + (vmf->fault_code & DSISR_KEYFAULT), vma))) + return true; + + if (unlikely(access_error(is_write, is_exec, vma))) + return true; + return false; +} +#endif + /* * For 600- and 800-family processors, the error_code parameter is DSISR * for a data fault, SRR1 for an instruction fault. @@ -407,12 +423,18 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, { struct vm_area_struct * vma; struct mm_struct *mm = current->mm; - unsigned int flags = FAULT_FLAG_DEFAULT; int is_exec = TRAP(regs) == INTERRUPT_INST_STORAGE; int is_user = user_mode(regs); 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_fault vmf = { + .real_address = address, + .fault_code = error_code, + .regs = regs, + .flags = FAULT_FLAG_DEFAULT, + }; + if (unlikely(debugger_fault_handler(regs) || kprobe_fault)) return 0; @@ -463,45 +485,21 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, * mmap_lock held */ if (is_user) - flags |= FAULT_FLAG_USER; + vmf.flags |= FAULT_FLAG_USER; if (is_write) - flags |= FAULT_FLAG_WRITE; + vmf.flags |= FAULT_FLAG_WRITE; if (is_exec) - flags |= FAULT_FLAG_INSTRUCTION; + vmf.flags |= FAULT_FLAG_INSTRUCTION; - 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); + fault = try_vma_locked_page_fault(&vmf); + if (fault == VM_FAULT_NONE) + goto retry; + 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: - /* 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 @@ -528,7 +526,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, * make sure we exit gracefully rather than endlessly redo * the fault. */ - fault = handle_mm_fault(vma, address, flags, regs); + fault = handle_mm_fault(vma, address, vmf.flags, regs); major |= fault & VM_FAULT_MAJOR; @@ -544,7 +542,7 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, * case. */ if (unlikely(fault & VM_FAULT_RETRY)) { - flags |= FAULT_FLAG_TRIED; + vmf.flags |= FAULT_FLAG_TRIED; goto retry; }