From patchwork Thu Jul 13 09:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13311663 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 E8AFBC001DC for ; Thu, 13 Jul 2023 09:40:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EC518D0009; Thu, 13 Jul 2023 05:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 726E88D0008; Thu, 13 Jul 2023 05:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 553648D0009; Thu, 13 Jul 2023 05:40:37 -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 3EE548D0008 for ; Thu, 13 Jul 2023 05:40:37 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 05793A01C4 for ; Thu, 13 Jul 2023 09:40:37 +0000 (UTC) X-FDA: 81006093714.23.555D80D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 696BFC0009 for ; Thu, 13 Jul 2023 09:40:33 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=IV4DNkdW4Hd8ZP157oL1HKEHrRYXoRV6592fFT5pGzE=; b=iS4Qt5FDByrln1PfNXkTeKiTeR3EqRCjO4S2nHvzM7madT9SNPWrDOQWU4zvyzy+DlUdZ8 +BTGCegd9MxQzukoonU+Zv/+Hqg35Q7y2uGcslmt+OC1uTXdml/X7wTnpSEY+qhFcolTUe JvPOWB3WapplV9mg3baIXeW269uurFM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=rgYTI7Mo/yXaNRDuafunMCmih3F8hjQP8BXfAueTM7hUnyoVF3jhauwkm5B4MUJS7nHj7G fePAInVUJQ0zSryqnD5zrLK0+VLjo5juV/yCQJ7dHHySCEjlaTt4PEAypOZi6VuoGblZyn BAjbfucWm1C1k9tZhIOSpVB6nE8XUn4= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4R1qMZ56yBzrRn7; Thu, 13 Jul 2023 17:39:54 +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:30 +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 07/10] ARM: mm: try VMA lock-based page fault handling first Date: Thu, 13 Jul 2023 17:53:35 +0800 Message-ID: <20230713095339.189715-8-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: 696BFC0009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: sw3duq7zbyywix6pbtout6e6p57kakgr X-HE-Tag: 1689241233-931896 X-HE-Meta: U2FsdGVkX19JPFAhele5VEyiSuY09fKshxAIeJf/MAzayo7lCgxNJecKM1TtSLs8QBQxh/kQE1t/JCKbj8isD9YthcT1EanMJG0BY7Ec/S03+7OcsQFrFLIjZfjuVPA/d4xx7zCf9Wlk8W8z3bWDQdUaaaE08+38ho4gQ4+nc0Fxz7LTvu2r71QgXlYLBLw5Xs0+Oa4q5vrF0tfUjtgIyOF5hXiKO0lSyfq9nLNT85yIJgT7MXA5ZngcppRoG0/9kpc4P2ZgD73K6g/MFcTglrQK63JeVcKPhINcj7yHDkss/A4J3IcWlnCTXr7e/NQba6ldvG2vXdSSUQmgW5nttIeEQf/GIb/+E5tNhN1AO8c6t3jmqEVicpWRKDGVJA6hzRv88VtyNAIOF2vz1fmczkfcFEYfOxIv/Q2MFBATc9daRk938aCplrx1cM5rsMuiDmqk4pbn7wh4s1bWQqak+x+YG3toMjJakNDb2gowuCMN24z06I1ctC3vxUEYVZh5a8vcVpKQrC4zzlS4qtTTZWE/urK5HehdSG2LZ/SVc3EiS9bRDD39S6BLWeMHyJzguTGmuF9GGV1mQkJCWXAsaomUE8deMk+tUIu3VjnlakzhJrkReW3hteU7ZrBKgqZ9aoJ5m3x8JwNU/voIvQ6NapJL5x+yT1KEQnIw2W7B0v87d3zJ13lBih+7DyEJwRfaEZCFYfOQD/KiElhM1UuW0nctfLiDbB8g1G3bE6H0TnQiIjk+0JNLnFgIoOIeHrFqVeuzgJZURWFyDsYg7e/K5r51/qvQ6x0/OWwGQV4K5+TZWtgzjikH/NIGvY86rdPoyPANE0AV70NLjh0wxfExyB44C631bmOBW9UUFb2c5onPgNzveobWugR5fEIj7yXwbDQFtHq0Hd9naF15XAyLOeqYUB88e61rHYVOdWH0jx9M+PeB0p0do6ZAjRFuLgnqBaY+xX4qvmpzhd+HB8D Jqowt0r1 HRb7RUJA/tSeIPPIR94w+GuJ6VoxIAMFqi/UYJ6cQcN4sHuDaIJuVBKbFjWBkabbNqyBbsa1p8spXk5LNnDYpsS+TN5zBGLnMMLm6zcvNGCJFV+omKOdBoMWJeZtOEY3AB7x6+ikHEW4tlaOs2DuSKm2TBA== 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 | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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..c44b83841e36 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -244,6 +244,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) vm_fault_t fault; unsigned int flags = FAULT_FLAG_DEFAULT; unsigned long vm_flags = VM_ACCESS_FLAGS; + struct vm_locked_fault vmlf; if (kprobe_page_fault(regs, fsr)) return 0; @@ -278,6 +279,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); + VM_LOCKED_FAULT_INIT(vmlf, mm, addr, flags, vm_flags, regs, fsr); + if (try_vma_locked_page_fault(&vmlf, &fault)) + goto retry; + else 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)) { @@ -316,7 +329,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) } mmap_read_unlock(mm); - +done: /* * Handle the "normal" case first - VM_FAULT_MAJOR */