From patchwork Thu Jul 13 09:53:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311664 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 DBA92C0015E for ; Thu, 13 Jul 2023 09:40:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E3948D000A; Thu, 13 Jul 2023 05:40:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 293348D0008; Thu, 13 Jul 2023 05:40:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15BFF8D000A; Thu, 13 Jul 2023 05:40:38 -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 076098D0008 for ; Thu, 13 Jul 2023 05:40:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B125416016A for ; Thu, 13 Jul 2023 09:40:37 +0000 (UTC) X-FDA: 81006093714.19.45467D4 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id 0CC8F20002 for ; Thu, 13 Jul 2023 09:40:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.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=1689241235; 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=FkTnQQkkp7c5OfI+DN0NqR3ZKn27H8ODcUopLpWusuw=; b=WuoqyDoD81V8PnX8ZVBwiibz2wYB9xbd2gMbJ3KyVv6mehLsJxT6z8BwbYUF/PSyDsEmRf wUQqjl8FzzbQ6aQyo4wy4KIqGL0mn41ARhsUIqZpdLB1VhP1+UNc0FqzvWN16c0di5+73k EkbZ27Vb6kxoBkiOhWGU1ryShhnsZwI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.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=1689241235; a=rsa-sha256; cv=none; b=JV52e4aL4IhGBCOUimWHg2pjEPOhk5GokSDn2Zi+AdrhMZ0IR4lEUSiqN/SPiA8cAegVJB TE0z7YAcwu1R3aj6YoZLWAq0Bo+U4iI4dXaNNahIWvUDgdxlqEAntBfz8hL3DBGvPIMKVP a2PxQi4pK75tD7HE4l7ZefHrmFzDq+s= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R1qLq3yDQzVjXt; Thu, 13 Jul 2023 17:39:15 +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:28 +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 06/10] riscv: mm: use try_vma_locked_page_fault() Date: Thu, 13 Jul 2023 17:53:34 +0800 Message-ID: <20230713095339.189715-7-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-Queue-Id: 0CC8F20002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6t6eos8o3uh9y9i1cagn67z6bdzjyehf X-HE-Tag: 1689241234-980587 X-HE-Meta: U2FsdGVkX1/xCxgyLE+d9s27ki+RGdTUgglZ4xeBrVJlBaCFRicmeds8hLBYX0LSJGXWS4rWkaEvB+LKvPKsPrYkpNjs4aFn+W8Jgeom3ZYhn3/Tlorx5mNILxUBWImuUxgPBL8HyxAZ7819D40eV6jE2PIgtcH1kNPyaQwNWn2M+U1pze1gRIGcivxDQCNRvtWccGq/8XuQVT/r9/4vc3Exv5/n+WogzejG8IebpvcK0hbjLyytHYmOWs4/6mugWuifnD3wV0hK/Otk3tkwwHgcRyKE+Mk6tYHU9/LzKbitUZ8NBVRRA707eCmVCKLqda1hEzZCg9x/i/+3ZHWaRsU+Re2ngwPX6nX5+YUE79jcGE1iKTaS7MXqK/eNnmzpKVNPmwDVvlV3Uett0l9NNFJ0VIsKYgaXgtIx7MQknljSsF7oNH6NjHOTDzBK4JP1FhPauQHgwPGmay5vdmKldbHg8ktvNLQKv0JuoxrZkiFi5nixnYBjYP7ZvTJw/gUt2TXbfZ0Wz3Ow8+SnI/LZdSGaXARD0bDlX+mFjbrjcUXx9cl3tuPz91G5Nz2Cb2ujlKin+2akJXcieR0qg7b/4a6YQMeQhVnK5h3Ga+rQaaoXPCLQw3gvl7/kSbnOApmZ4PaSIFr0ZTv4vAR4l6UzQrmh/SIlSs4VouXc5y9ALXHT480W+unVxvKJXBhta/dQW6wQkkI5Cy0+GlINId7quLcbJYiO7M6l3kvZbCx283Rq8BjDEeuckKOcwDMQ+7qXhRdCoNK7l/ByJdY20OeZwdvSXW4y+8WR4yzj8VOLNujcDhfAhscg7zHaycLsA97dWjGo3CMdnKH0lWhs1m+SYRELwrPKiexGe5RGCPQjoQDL1akgdSu9LYGpEC5LzLQ/JLv4L6ROXBeS5Vk/EbO20ngXfADpAMj4KOnDVzMvdjS0qnIXXpt8dJVoE4rEe80wBf8IHsJNVd11DnO+RVx SKrdnl42 VurMzoWCWnrFHxixW790/89eij10aA+nJ4qDM+hHoQIirkzINgG1qFgdYA66HOqAXJ3JBcGT5vkPZZ+AczS8Zf+I+xTed9U3MscQWOJvMFIDB0dk+VR43VmZkez8Dl0JWJLpbEMZEnfgwEiZFqIqKLZ1bveYiXFDrq4RBdPsynfmj35O0wCNBJ487X48XdqyhFngX 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 | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 6ea2cce4cc17..13bc60370b5c 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -215,6 +215,16 @@ static inline bool access_error(unsigned long cause, struct vm_area_struct *vma) return false; } +#ifdef CONFIG_PER_VMA_LOCK +int arch_vma_check_access(struct vm_area_struct *vma, + struct vm_locked_fault *vmlf) +{ + if (unlikely(access_error(vmlf->fault_code, vma))) + return -EINVAL; + return 0; +} +#endif + /* * This routine handles page faults. It determines the address and the * problem, and then passes it off to one of the appropriate routines. @@ -228,6 +238,7 @@ void handle_page_fault(struct pt_regs *regs) unsigned int flags = FAULT_FLAG_DEFAULT; int code = SEGV_MAPERR; vm_fault_t fault; + struct vm_locked_fault vmlf; cause = regs->cause; addr = regs->badaddr; @@ -283,35 +294,18 @@ void handle_page_fault(struct pt_regs *regs) flags |= FAULT_FLAG_WRITE; else if (cause == EXC_INST_PAGE_FAULT) flags |= FAULT_FLAG_INSTRUCTION; -#ifdef CONFIG_PER_VMA_LOCK - if (!(flags & FAULT_FLAG_USER)) - goto lock_mmap; - vma = lock_vma_under_rcu(mm, addr); - if (!vma) - goto lock_mmap; - - 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); - vma_end_read(vma); - - if (!(fault & VM_FAULT_RETRY)) { - count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + VM_LOCKED_FAULT_INIT(vmlf, mm, addr, flags, 0, regs, cause); + 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)) { if (!user_mode(regs)) no_context(regs, addr); return; } -lock_mmap: -#endif /* CONFIG_PER_VMA_LOCK */ retry: vma = lock_mm_and_find_vma(mm, addr, regs); @@ -368,9 +362,7 @@ void handle_page_fault(struct pt_regs *regs) mmap_read_unlock(mm); -#ifdef CONFIG_PER_VMA_LOCK done: -#endif if (unlikely(fault & VM_FAULT_ERROR)) { tsk->thread.bad_cause = cause; mm_fault_error(regs, addr, fault);