From patchwork Thu Jul 13 09:53:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311660 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 84C60C0015E for ; Thu, 13 Jul 2023 09:40:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECA868D0005; Thu, 13 Jul 2023 05:40:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA0688D0001; Thu, 13 Jul 2023 05:40:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B4D8D0005; Thu, 13 Jul 2023 05:40:31 -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 BCF368D0001 for ; Thu, 13 Jul 2023 05:40:31 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8E84314015A for ; Thu, 13 Jul 2023 09:40:31 +0000 (UTC) X-FDA: 81006093462.04.ACD0F3E Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf19.hostedemail.com (Postfix) with ESMTP id EF0F21A0019 for ; Thu, 13 Jul 2023 09:40:28 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1689241229; 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=FeYFc6zSdM9ygR4Vi91p1lIFddSoVzdmv76+Wud4OVw=; b=MwOA1aa1x6F4U67ytYnLDoeINYK0tAJuFjuipQq3ShRSF4HsoDlYjj3j4f5yHhJeviGw1w IYZJy3blTdo+y5AyLq36cjLdTBRuuM0ITEEg6L7NtzxAa5tM5AnYN5pIAKbfR1NwpFMvzp DrdyRLmHGtBPS3LBTbYycy+6gvR5ZRg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689241229; a=rsa-sha256; cv=none; b=WkAasZQvjevJJBsXNTJUqcIDeYgInPQVWyguE58QTU4iIZPCwY3IZQD8q6sPT3zA1B75sx IvMP1wLDZVEQEYoN15p+6NwqZ4FP+RwCKAr0rWHwDPd8zmhtgA42VHBtGh/R7varV+crnQ W74U2fT6TIrQkh3UFfwEb+QPPegEu34= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4R1qMT1xcPz18MB1; Thu, 13 Jul 2023 17:39:49 +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:23 +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 02/10] x86: mm: use try_vma_locked_page_fault() Date: Thu, 13 Jul 2023 17:53:30 +0800 Message-ID: <20230713095339.189715-3-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: EF0F21A0019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 15b95u7ygzqcuesgx973ad8tfg1mcy4m X-HE-Tag: 1689241228-718664 X-HE-Meta: U2FsdGVkX1+qz/xGp7D4eIXd5WWL7cGc2nIsHFEuNcb+Lk43quv/viDa3cGSv6/HCG6Qk+Ro4pq7h7JOgbJZsvABQ3yopcfTYyqdradBjbV/bUBu7HFViiNbnnxoB+W6+7ZiKGtPZpHGF6Gt7wqfG9UNHXXRODJqD6aFrBNITmf8wlMddZyMtj2dKqLVHs/105sZyCG0n5gkYBl/wGY5T0w/BuE6GZWi+AYzdQzUbL5WcS/7xLs+HFNRwAnA8n5Z44rbFEleNCo1NffGmPOnfkJF85Ubgq8TsR6zeTn32Gk9jwk5r3OKScJ4C2nbvunxYogl1oo4MkDLG+fx6RGoWhdg5ifR2oVbuygOmmKyKK0jzBylFtKJMRRDhmQ46kfm8vY8Sbk6PFS2elVhQcp9+16ry0nzNEBokaPZSvRgHhiIbkA1EqFD5lktBJC/h41CYVr+bOv4jgZMzwicla/Zhz5HVymxMJJbDrCwQ9xfDff/IHBNEN7cENU05jHq811ubUdepo3Ay2Zuxg53Sm9QixBSKJoNrsl1OlHyp3BPI+r30kxJu32qJj5a94iS41COtPfTtRSYUW8h97qHCvPspoAmojE5sVDOq0cw8Uk6/j2HCVxrsk3RWxEoOuMI+GaAI+IU8WRBZ3gUMBQQdOcu1ebCvIeKfZxop3rjSKx+vPauVNkLCgQdnUtdiQq4CL9hZmyU/amObyfh7TrukbgDO5f7o0DbSpa+/A6R3tlHmKV1ARYKOZ/OInKMj7ScsuHNOihBOeuYm3tKdWbX6ffSj4BkwnrAo+Zq1ECCT0Xrk9Ye7ALPLk2jt36sbfKu5uGmbeBfkedStpAG79bSCBmKkb8NJ1rS8mECAH1fDYj3RtwZJa4oZbUBLauwfXR4HtgR/mXaoXG1HMLQLe2c9ImtsfmSCFN8gFp1Jgw/LrfaKwGxpJ7RDza+UBEohJCfUN2iGWyoCf049IMRZq6mhdA FJPtXeYz UvwqiEfV/UaUBwL2hRhiZlE17mV68FDvEvOwZmhHcA+lfcIBHm5TN17z87kYDi9u/nK7h3IGgKV8DVmiIZLfv09Q3vg7Efp48xkJBMDc7/qhgmn2jxVM+CROldkpdGL9wXwxHMNXnVmoX1zzyyX2rKTL0dGhK+QXO1YsyAMNDEwa1Yjl5LbPR0X/AYk+gOHp1/iLb 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/x86/mm/fault.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 56b4f9faf8c4..3f3b8b0a87de 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1213,6 +1213,16 @@ do_kern_addr_fault(struct pt_regs *regs, unsigned long hw_error_code, } NOKPROBE_SYMBOL(do_kern_addr_fault); +#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 + /* * Handle faults in the user portion of the address space. Nothing in here * should check X86_PF_USER without a specific justification: for almost @@ -1231,6 +1241,7 @@ void do_user_addr_fault(struct pt_regs *regs, struct mm_struct *mm; vm_fault_t fault; unsigned int flags = FAULT_FLAG_DEFAULT; + struct vm_locked_fault vmlf; tsk = current; mm = tsk->mm; @@ -1328,27 +1339,11 @@ void do_user_addr_fault(struct pt_regs *regs, } #endif -#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_error(error_code, 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); /* Quick path to respond to signals */ if (fault_signal_pending(fault, regs)) { @@ -1358,8 +1353,6 @@ void do_user_addr_fault(struct pt_regs *regs, ARCH_DEFAULT_PKEY); return; } -lock_mmap: -#endif /* CONFIG_PER_VMA_LOCK */ retry: vma = lock_mm_and_find_vma(mm, address, regs); @@ -1419,9 +1412,7 @@ void do_user_addr_fault(struct pt_regs *regs, } mmap_read_unlock(mm); -#ifdef CONFIG_PER_VMA_LOCK done: -#endif if (likely(!(fault & VM_FAULT_ERROR))) return;