From patchwork Mon Aug 21 12:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359378 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 B3F29EE4996 for ; Mon, 21 Aug 2023 12:31:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE6D38D0014; Mon, 21 Aug 2023 08:31:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBE788D0002; Mon, 21 Aug 2023 08:31:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A865C8D0014; Mon, 21 Aug 2023 08:31:34 -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 9684F8D0002 for ; Mon, 21 Aug 2023 08:31:34 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6F968B2191 for ; Mon, 21 Aug 2023 12:31:34 +0000 (UTC) X-FDA: 81148047708.24.E9C717C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id DEBE818002F for ; Mon, 21 Aug 2023 12:31:31 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.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=1692621092; 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=zcPOcBoFA8WcmdCmuHl5Kjr7MCHnERomL1MjeiooAb8=; b=PPgUW2gVSx9IVe9SNYGmr5cqMYKaCKeBdLR18YiGH1RabdtaNTzkY5Nq+mobNP0vC9nGjV i4pNBG9SaqZQNKsQgK1YQcwQk3nJdLLWpctXAKtMLsz2UHrsz963Qab5+RXPmaH/sCK6SZ g6lFUpj/QWvfWXuqEf1BNXNQkTTSMAY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.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=1692621092; a=rsa-sha256; cv=none; b=AeCew9JnpehWOmVVL2w5OvKTs5InloGSXRxqPcvc4dREeKjKfUx/xrwyGWi7fDSJdhBCEM CCJsDTHxGoHtlshxh4IJYd+XpIIa9DMVtAhhngo2YkXHW4Ba0vKDczrcWSMpqjKxRHIToL CjNHZrMg+RMHTGCTGjhANKxFYah4wWs= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RTsFC3r4rztShZ; Mon, 21 Aug 2023 20:27:43 +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:24 +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 10/10] loongarch: mm: try VMA lock-based page fault handling first Date: Mon, 21 Aug 2023 20:30:56 +0800 Message-ID: <20230821123056.2109942-11-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DEBE818002F X-Stat-Signature: dpoeyywjypuf73brnpoa1uoug1da479x X-HE-Tag: 1692621091-324148 X-HE-Meta: U2FsdGVkX19Utf837N1V3dkdUquDiSH8VKAvjH0XCMjISztoh7VDoL10kdQsrfGsOrALKehqZsOFfTQFpO8PxdQ+Xr6HJ4REsqGUnXuDzq9Asc/WGikqk2GbUuuIvzbwhGYYRdhg1ti1EsrX9TL9VU210vYC4DEBTArVshSctsDC9uaOOs4kzHQHUcAV8j8lv/Nw6gAEUerkCYbeHUosJLXBCWpWSn0SM0Qt9PEmQtKlL/4+zK63/Gbvu4ZNKIt2t3wszP9K+KiZOtwbKn5P9p9zO4ay/N3whD9gHuiiLlQ2dg9kKS1dJh+4UspGhE6rqVjOtIc7JmMtFFUIjR1TAzf2QJNQf0G8aIViN0hplSz87KajMVXhcGn9A5Df+4ewhYKCd2mjDeCCEOupFnK62MlsifknIOmXa59TDtB3uI7EIiFl8EPVr4VT3n8t90skgX73jMigY2nYVfjoUuxRTMZt4wchtdcjYT7mrE63sc7VlC4oCZAXPQrCzsOfZACWlBW8z6LezkpsEI62WfkE5Gd+WYWzxLH9jAPwqdz0z4nmGxRfiNsdGz8xwyvcoU0XiK6s96TaqqYnruzzIFPVva3FYnGLUWrw5VEi6ma/CaoYu7BppsXNsj6TQ1bWtJf3pvToNcV79KMfhYRDGV9K8RF+m9fuLMLD/OCK7SEGlY5IRzkZy7qyM8P5dNp4wTidJewR3sVU1LI3CNXW2XcdSjJ7g3K526X39sd1Y0DKFEflO6fKtaTfrgaU/1e249BeCdAIH1gNQSPt7kBdoI2jAOCvdcq4EH+n4p/QtQWHsVgcyCDwWueekioU9Aor14AdqvQ60Blttpg0SKL/Bw2pXW7aZI6oQ+dyuBgGPISMjdZapVFIRAROb0yN+0EUukqm7hiy2jh67xhhsYnzFw8x8bIFSMEh9nyDKI/chG7/fs6p6cqA9uc5MsOnXPwHKscFXDD7SQp+PvqJIRg8Wic rst0tWaz 2RdvU+xQ3I78F6COo2txm0QTDuGbCAQ+X1JJ8SJkor7d+MCEW3WUwEoUruH3KGcV+9bOCE+Hi9skF12J/8Uuvbj5UQwgH5rVC1oJy9/Xn2mGmOG5KqBiRYMgcumn4GqkGCaDOGYdjhUcpKNIe0eyznkPB3A== 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/loongarch/Kconfig | 1 + arch/loongarch/mm/fault.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 2b27b18a63af..6b821f621920 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -56,6 +56,7 @@ config LOONGARCH select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_SUPPORTS_NUMA_BALANCING + select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_QUEUED_RWLOCKS diff --git a/arch/loongarch/mm/fault.c b/arch/loongarch/mm/fault.c index 2a45e9f3a485..f7ac3a14bb06 100644 --- a/arch/loongarch/mm/fault.c +++ b/arch/loongarch/mm/fault.c @@ -142,6 +142,13 @@ static inline bool access_error(unsigned int flags, struct pt_regs *regs, 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->flags, vmf->regs, vmf->real_address, vma); +} +#endif + /* * This routine handles page faults. It determines the address, * and the problem, and then passes it off to one of the appropriate @@ -151,11 +158,15 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, unsigned long write, unsigned long address) { int si_code = SEGV_MAPERR; - unsigned int flags = FAULT_FLAG_DEFAULT; struct task_struct *tsk = current; struct mm_struct *mm = tsk->mm; struct vm_area_struct *vma = NULL; vm_fault_t fault; + struct vm_fault vmf = { + .real_address = address, + .regs = regs, + .flags = FAULT_FLAG_DEFAULT, + }; if (kprobe_page_fault(regs, current->thread.trap_nr)) return; @@ -184,11 +195,24 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, goto bad_area_nosemaphore; if (user_mode(regs)) - flags |= FAULT_FLAG_USER; + vmf.flags |= FAULT_FLAG_USER; if (write) - flags |= FAULT_FLAG_WRITE; + vmf.flags |= FAULT_FLAG_WRITE; perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); + + 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)) + no_context(regs, write, address); + return; + } + retry: vma = lock_mm_and_find_vma(mm, address, regs); if (unlikely(!vma)) @@ -196,7 +220,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, si_code = SEGV_ACCERR; - if (access_error(flags, regs, vma)) + if (access_error(vmf.flags, regs, address, vma)) goto bad_area; /* @@ -204,7 +228,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, * make sure we exit gracefully rather than endlessly redo * the fault. */ - fault = handle_mm_fault(vma, address, flags, regs); + fault = handle_mm_fault(vma, address, vmf.flags, regs); if (fault_signal_pending(fault, regs)) { if (!user_mode(regs)) @@ -217,7 +241,7 @@ static void __kprobes __do_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 @@ -229,6 +253,7 @@ static void __kprobes __do_page_fault(struct pt_regs *regs, mmap_read_unlock(mm); +done: if (unlikely(fault & VM_FAULT_ERROR)) { if (fault & VM_FAULT_OOM) do_out_of_memory(regs, write, address);