From patchwork Mon Aug 21 12:30:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359376 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 064CCEE49B0 for ; Mon, 21 Aug 2023 12:31:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CC938D0012; Mon, 21 Aug 2023 08:31:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52DCC8D0002; Mon, 21 Aug 2023 08:31:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F5138D0012; Mon, 21 Aug 2023 08:31:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 23DA98D0002 for ; Mon, 21 Aug 2023 08:31:30 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E043A40C2E for ; Mon, 21 Aug 2023 12:31:29 +0000 (UTC) X-FDA: 81148047498.24.F95D613 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf21.hostedemail.com (Postfix) with ESMTP id 27B361C0031 for ; Mon, 21 Aug 2023 12:31:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.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=1692621087; 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=l4jSuPrbGHI4pMXaRA4r+395y9GbHYpFkl5xNMupVfQ=; b=nRLSD9jBvXtd4gFGbEt+uZriRWml93eXFTB6QYzmPZoOi90145zgNY+vV6zvvrpVINHRPZ 8KQ/pg7BNg45pWOZn2ZplmE3+zr7xX6ihXC39TvRbEBgoYDc9pR27O5/O3y9Vy7kwPQl3e 22FJJ1q9zJ6uabmi2BzdFmDgyCnx878= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.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=1692621087; a=rsa-sha256; cv=none; b=D+90gw9jpH1cQQsdp5LKU2zVS0sPg9tOmT/4Pku0ldeq/8pi5ksrwZEsCWMrROMhCH0Q7r 4FwXiA5xk0SLPTTP7S0PZtgMWHDOVXD0BBai/Nd8sxNfwoyR4/94tSh2G3SUB3Azv4r6t0 RkNeazvsETURg7PgASWw9HnAEjTNEB0= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTsGr51ZwzVks7; Mon, 21 Aug 2023 20:29:08 +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:20 +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 07/10] ARM: mm: try VMA lock-based page fault handling first Date: Mon, 21 Aug 2023 20:30:53 +0800 Message-ID: <20230821123056.2109942-8-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: 27B361C0031 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fcmiw3zpuifp4fmdarug3s8n6top6pbo X-HE-Tag: 1692621086-323273 X-HE-Meta: U2FsdGVkX1/1/KfjygVNpRqA1Itd8ngfot6qEtge9c2I/Tlbb2G4bsMZWzzDrVusORZNKVqLvRorn07RReI5aH71qqfSXY3qGCDEFP3OLSX6zbDWGq18WE7So+CzvJ1AR3Rr1FxQctfdnmB5ewYCHeGVrm3CkP4mK9PWPwlBE80V9y4PN+KjvgN0Wz7UwlZtEtnZWKBQD+1BzMagUQX1dLOfchIyl4XjdxfYV09glAA40xs/p94K5HhGFwFQEbEdA28hp51qe/v22ewmNDAKWd4CDCYyrdTTcYmLMaIzQcaEjm97NicCnG+oBFA14b2PrfLZBVKYq/6NsEXOE5u3WlZwx0HCQ64zMCYZMPz2/jNfhRsuzhSENaoPe41r/p7BIEnxdPzWkPqgMzmSlIvE+aRdg4hgSNYUSvhqPpyRCAGfEtbmhdMZgPrE9Kj692DBKD96WPK64FxvkSrupCCpfQl5/RF/2e6c+anaCos08oW9XvpKtC89cuiHiRa082H2qeV0MihhhwuyakJ2fqHO2xGuIGrGDlcKb7BnGnh5U5wW4H0EIp8dOsanfi37wuTngf8QgWg1rYXvEtTmUbEMs664L3+rfMcJpw715FixtRjqlnQbBdYqXl22kqt7oVMwzs4N8pRyTglPQ8q+zUKqSYAoZSmpCRMdUo4HpLN3x8m9tWZGDQwBEXOVbuIlQ86lQvjeFykk5Nf33EXwVbYKDOdDkh3VsAPHgcMZDcGftVMIW7YKVJX0LXnw0nmlLK7NwYYRPnJOQHsW9+RybzDdgIPLO/qZOVBcRwzEdtI0CKMI/L0zSG169XKswb0qLU5ZRZmDxCusb3fWlW3TGO8iJH400wt5oFEIZlRBXrsGENyYZCuq/fvXchiHKwDgKOv6bgjvkLwiwg4thCWLNZoDF+Dho9Npu3INqaeKTEijTqcQSg8LiNEWR4tiL28zSwR4/a+nG22AZXxmd44DQ9h IeFPZHXt voGj3ecPSHWGV29gYsls7byWC9zQwQCkCx4f2HEbP+34CvTDIq1arvhPwyjiFYHcieVbI2maT7b648zFZLnssfNFW1DQo364AIwf+P2wkmNEcZ+02zMDIu5vmO261tC8Ag9WGJrznjnLnX8HKJcsJIC9AXw== 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: Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Signed-off-by: Kefeng Wang --- arch/arm/Kconfig | 1 + arch/arm/mm/fault.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 1a6a6eb48a15..8b6d4507ccee 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -34,6 +34,7 @@ config ARM select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_HUGETLBFS if ARM_LPAE + select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_MEMTEST diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index fef62e4a9edd..d53bb028899a 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -242,8 +242,11 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) struct vm_area_struct *vma; int sig, code; vm_fault_t fault; - unsigned int flags = FAULT_FLAG_DEFAULT; - unsigned long vm_flags = VM_ACCESS_FLAGS; + struct vm_fault vmf = { + .real_address = addr, + .flags = FAULT_FLAG_DEFAULT, + .vm_flags = VM_ACCESS_FLAGS, + }; if (kprobe_page_fault(regs, fsr)) return 0; @@ -261,15 +264,15 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) goto no_context; if (user_mode(regs)) - flags |= FAULT_FLAG_USER; + vmf.flags |= FAULT_FLAG_USER; if (is_write_fault(fsr)) { - flags |= FAULT_FLAG_WRITE; - vm_flags = VM_WRITE; + vmf.flags |= FAULT_FLAG_WRITE; + vmf.vm_flags = VM_WRITE; } if (fsr & FSR_LNX_PF) { - vm_flags = VM_EXEC; + vmf.vm_flags = VM_EXEC; if (is_permission_fault(fsr) && !user_mode(regs)) die_kernel_fault("execution of memory", @@ -278,6 +281,18 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); + fault = try_vma_locked_page_fault(&vmf); + if (fault == VM_FAULT_NONE) + goto retry; + if (!(fault & VM_FAULT_RETRY)) + goto done; + + if (fault_signal_pending(fault, regs)) { + if (!user_mode(regs)) + goto no_context; + return 0; + } + retry: vma = lock_mm_and_find_vma(mm, addr, regs); if (unlikely(!vma)) { @@ -289,10 +304,10 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) * ok, we have a good vm_area for this memory access, check the * permissions on the VMA allow for the fault which occurred. */ - if (!(vma->vm_flags & vm_flags)) + if (!(vma->vm_flags & vmf.vm_flags)) fault = VM_FAULT_BADACCESS; else - fault = handle_mm_fault(vma, addr & PAGE_MASK, flags, regs); + fault = handle_mm_fault(vma, addr & PAGE_MASK, vmf.flags, regs); /* If we need to retry but a fatal signal is pending, handle the * signal first. We do not need to release the mmap_lock because @@ -310,13 +325,13 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) if (!(fault & VM_FAULT_ERROR)) { if (fault & VM_FAULT_RETRY) { - flags |= FAULT_FLAG_TRIED; + vmf.flags |= FAULT_FLAG_TRIED; goto retry; } } mmap_read_unlock(mm); - +done: /* * Handle the "normal" case first - VM_FAULT_MAJOR */