From patchwork Mon Aug 21 12:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359374 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 37529EE49B0 for ; Mon, 21 Aug 2023 12:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B70A98D0010; Mon, 21 Aug 2023 08:31:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B20AC8D0002; Mon, 21 Aug 2023 08:31:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E8FA8D0010; Mon, 21 Aug 2023 08:31:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8AE498D0002 for ; Mon, 21 Aug 2023 08:31:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 68184160B76 for ; Mon, 21 Aug 2023 12:31:28 +0000 (UTC) X-FDA: 81148047456.14.9CC3FA1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id 7DD9C40018 for ; Mon, 21 Aug 2023 12:31:25 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1692621086; 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=ylwOlASsFauhlnikf2xz20/mDXOPIgvFpCP5bYKqfYo=; b=dNm/M4kyKIMjRKKjzID4utCLQmaqtrhoOFMGN5pzOzTTtA0I2I3gBEZ2UTYvwipxt4Nev/ 7N5AVnpTLh/OeVY72fWp13sZtrnOWNW+YTrG1xr6tVcgu+bGXnWO5sMHkneXkO6ZI5ywpx +E9NzO2c2V4P8dSp96fnoXJXjLyoY5k= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1692621086; a=rsa-sha256; cv=none; b=4p2CAP0ow5Uq6zWZDMMuHDo5eJfdZh4YxqfAS6YPYSMM40BSS4FO6dOHeRPQzpX4tLrrh0 +ozvRRFFMhgSam4VmaQGWgvxcw03/NAUOOGVky9nrgEKGJFPjDIvl0pVnFq9BWsSbKG4cY 5Xm2fVSwoo7FGbeAbdw3wuG2HmnKU7w= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTsFG5XSpzNnTc; Mon, 21 Aug 2023 20:27:46 +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:19 +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 06/10] riscv: mm: use try_vma_locked_page_fault() Date: Mon, 21 Aug 2023 20:30:52 +0800 Message-ID: <20230821123056.2109942-7-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-Rspamd-Queue-Id: 7DD9C40018 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gbi7ktxmm8immnbmg5ih9mstuqwprf8t X-HE-Tag: 1692621085-75313 X-HE-Meta: U2FsdGVkX19o4K+YGGYomdFR3q2eOxWfQz3PAEId/2uK4XCDV9IDq0GKNrnYYNnkLl546UXIG2az5sr72/RkSGozrMUEkmDZd5qI9NUG68YxRgdsk2f7TUf2zFYImktjFmGbJg8+FaLkwFR20XqxcP3p/tnEyF17wuKZ4GCJG5dHONWf9fhG4ZzB6AeD7O2RpV8EftMFZtiRthiW3blI+/k1r6bDS+kmLw4BW8hRfsp/HrjbcclENxoTFFnXKJtyK26DiuV15uDKGaiCLcmcZofz1S617VzQbvecN7bnOXE0WguYPdvI5oIc6B8sH1HH4MCfl6maxCbBULTUhlocDbL2RdFc2a4IpNIHZP4NjWv6bgItnjYwRfXn243UWPELnaBY5QSoqWrp1Pn1iqsaWq31+nhkYawYGb7xjsGj8QTDWY5cNr5igsZV7i64EbodzoMCUMwHJ5Btbo+3fNJUJ5QKwxSq1W52cdzzCsHE1Y3yGHx4+UfQMNRwTP9OuZxzKjq6z61+DNrmkEDGZRYlSWgR7cep2YOXvcWwIUKnq2uPIBZYdjK5AkOiEDEvKMJs69sZ9iSaBKyAKWWozjnqUtCQsTOdG8HtgPZMLqjnwjz78EjiEpdR5NWn2WLRdtdJ99HErmtEEn3/uvJt5Qkovh3rUemUr50l3ck96R4y2WYXLwWvH7iQ6J+640hOQra6o0rs+vvBKSsmvfgWTvymjy/6cCyutffcWngU7BBBIL2B5ljmKtSX8glQBOWouWrM6dabpLUENgNtX4vfiuiNTMAxqVID0Hqh11tqy7u1jO83VPtLrDwb0akR7Eq3m4OowkBRX8bMO/cidK3HoOzk+kWOeAe3dGlyZdRRxGJHzDWdAZfsT0pv9VJOlB36fcdEBrly1JZ2CKCy/0V2QNR8w313V+hn79ZTAi4AJdj61Jkw2bxogl1R5YchJ2aKMd7xcIpVFTyXy0ssz392gjE wk2SdYmB B2yrnGXyExdN9AfzNIeqF1CY1YtQDJSAUgcyKCaTW48YEJXhFse1DmD7Uu+QwLz2rHJa7tfPkckUILKqaCx3dfvxHW/HyKR/pT6Dqm+Lk4gnztLzKNAdX+ti80GG3O3PnZG9UvDwrOddkFe2bbssco9fInwiec0xv9AL2jaCOxNvYPLeXTbCGtfvKUHqj124qUC1I 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/riscv/mm/fault.c | 58 ++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 6115d7514972..b46129b636f2 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -215,6 +215,13 @@ static inline bool access_error(unsigned long cause, struct vm_area_struct *vma) return false; } +#ifdef CONFIG_PER_VMA_LOCK +bool arch_vma_access_error(struct vm_area_struct *vma, struct vm_fault *vmf) +{ + return access_error(vmf->fault_code, vma); +} +#endif + /* * This routine handles page faults. It determines the address and the * problem, and then passes it off to one of the appropriate routines. @@ -223,17 +230,16 @@ void handle_page_fault(struct pt_regs *regs) { struct task_struct *tsk; struct vm_area_struct *vma; - struct mm_struct *mm; - unsigned long addr, cause; - unsigned int flags = FAULT_FLAG_DEFAULT; + struct mm_struct *mm = current->mm; + unsigned long addr = regs->badaddr; + unsigned long cause = regs->cause; int code = SEGV_MAPERR; vm_fault_t fault; - - cause = regs->cause; - addr = regs->badaddr; - - tsk = current; - mm = tsk->mm; + struct vm_fault vmf = { + .real_address = addr, + .fault_code = cause, + .flags = FAULT_FLAG_DEFAULT, + }; if (kprobe_page_fault(regs, cause)) return; @@ -268,7 +274,7 @@ void handle_page_fault(struct pt_regs *regs) } if (user_mode(regs)) - flags |= FAULT_FLAG_USER; + vmf.flags |= FAULT_FLAG_USER; if (!user_mode(regs) && addr < TASK_SIZE && unlikely(!(regs->status & SR_SUM))) { if (fixup_exception(regs)) @@ -280,37 +286,21 @@ void handle_page_fault(struct pt_regs *regs) perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); if (cause == EXC_STORE_PAGE_FAULT) - flags |= FAULT_FLAG_WRITE; + vmf.flags |= FAULT_FLAG_WRITE; else if (cause == EXC_INST_PAGE_FAULT) - flags |= FAULT_FLAG_INSTRUCTION; - if (!(flags & FAULT_FLAG_USER)) - goto lock_mmap; - - vma = lock_vma_under_rcu(mm, addr); - if (!vma) - goto lock_mmap; + vmf.flags |= FAULT_FLAG_INSTRUCTION; - if (unlikely(access_error(cause, vma))) { - vma_end_read(vma); - goto lock_mmap; - } - - fault = handle_mm_fault(vma, addr, 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)) { if (!user_mode(regs)) no_context(regs, addr); return; } -lock_mmap: retry: vma = lock_mm_and_find_vma(mm, addr, regs); @@ -337,7 +327,7 @@ void handle_page_fault(struct pt_regs *regs) * make sure we exit gracefully rather than endlessly redo * the fault. */ - fault = handle_mm_fault(vma, addr, flags, regs); + fault = handle_mm_fault(vma, addr, vmf.flags, regs); /* * If we need to retry but a fatal signal is pending, handle the @@ -355,7 +345,7 @@ void handle_page_fault(struct pt_regs *regs) return; if (unlikely(fault & VM_FAULT_RETRY)) { - flags |= FAULT_FLAG_TRIED; + vmf.flags |= FAULT_FLAG_TRIED; /* * No need to mmap_read_unlock(mm) as we would