From patchwork Mon Feb 27 17:36:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153992 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 251C4C64ED8 for ; Mon, 27 Feb 2023 17:37:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C04886B0093; Mon, 27 Feb 2023 12:37:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB52928000C; Mon, 27 Feb 2023 12:37:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5591280001; Mon, 27 Feb 2023 12:37:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 96B366B0093 for ; Mon, 27 Feb 2023 12:37:51 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4DAB2A0ABE for ; Mon, 27 Feb 2023 17:37:49 +0000 (UTC) X-FDA: 80513779458.22.4E6772B Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 7AF2410001E for ; Mon, 27 Feb 2023 17:37:47 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="S2z/SSZH"; spf=pass (imf14.hostedemail.com: domain of 3aur8YwYKCFkJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3aur8YwYKCFkJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677519467; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8qbswzDezEhzstnVvKcWG8k4mqqShtR5CvkIjaL/Ams=; b=cyrPF+vGgveDr4aLv2OgQ29jxs4uCyDQ6grJUgIY3YWQrJMCvzNn3ug/JZ3JbdDRW8cK1K K40shIWIuaKEt7rQtrMSSCB3y8mqIgwUtlnGYBsNCxzkfW/66JwZVPWGB67hisn3Ye/gyG 1LAsaeXvZrlRZK0FdNjtkOwxWo08l2g= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="S2z/SSZH"; spf=pass (imf14.hostedemail.com: domain of 3aur8YwYKCFkJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3aur8YwYKCFkJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519467; a=rsa-sha256; cv=none; b=Zg6lsD/ihbYjyDE2p2UrCWWMvSP3Wefu06+20dyNWk7F/T9TzNjte2oD9q6z7KoLbaoaRB kKVjYIYxqskMA300pS0fYs/zGWN42aYbPVv5KJjJahYZL0PRZClhM0gDJBWM1YspfEclE9 MbpmQYNB/PvUL6C51Y1BPGr5g3oe0U0= Received: by mail-pl1-f201.google.com with SMTP id j20-20020a170902759400b0019ace17fa33so3919324pll.7 for ; Mon, 27 Feb 2023 09:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8qbswzDezEhzstnVvKcWG8k4mqqShtR5CvkIjaL/Ams=; b=S2z/SSZHK7ga7fn7K3WxQ1Z9Tp5cfnBCSQx6U3NwmV1gsUS+bGmINQRxa2j1mxprJj TlUS9zejozFI94Me4SRmYnZJhHoCJ1T/yWkWmu9QLBmKTP9UVKEKrUis4+6aHa3Th3fJ h+Y+1Jmq5YaDOU6wdiux0RRTdqhbgVjK/U97ZWeloQvvOddB9ya0oDdfoI+0RwHp4MBY fv4OUGk3ZqItB135iDjzRMrjgTvWp+7rVjVBq1LRXg1IvF5Kyuov7vPWbX/2nDhfcOko v7S1G6CGTLyAoqFG7bUJ2+HrxmmeBgvMQ0WZGMska7TydHy4EV5ohTcRFh6YPtqaKDjC j2tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8qbswzDezEhzstnVvKcWG8k4mqqShtR5CvkIjaL/Ams=; b=lwPpvifmkOXZYAkUwBxRiEvpmbCbwx+xppw5pvfrva9rgWEwjU9npZnci4CZxhj+RS upJqTeq2nSdykWpatpgebSkWmoxN0LDtTE0W1qgLB2+bUeY8D/qxDGIfq+8EQDiQXtT0 /1Rq4noKSuRkMnK5oqItWIF+/AMZKZ45KPwR2VCb+57oBscJSr1EPI9YANDI9MgCuKIl /iCVDbAh3U6hKprdIdJwWYmvia3RJbnp+wz6eUhoqe0zhz5aS4wYFUbv95eqbtvkS57N DgtYIkT2F0WujHdMF3drTe22kMsLcnda61iAGJ7u1lpDVcxvtl0VQCLUJXGx8DTOx1qt o9jw== X-Gm-Message-State: AO0yUKW+cJ+0ouIuKwp9IpQINFu5WEts4f/2C8NA5mlmvv8MyI/UBWQD xOzs0Vq8cAwIA49lHw8FWaINXg4PCxY= X-Google-Smtp-Source: AK7set9keW13BRbYPHEfojmqkqSUJl+DCAHGSXNxIKLRjiYP92gcRxEVFUNpHyaWkuSA+coR6ukP0Mdxl38= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a63:7a56:0:b0:4fb:b88f:e98a with SMTP id j22-20020a637a56000000b004fbb88fe98amr6296782pgn.7.1677519466345; Mon, 27 Feb 2023 09:37:46 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:28 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-30-surenb@google.com> Subject: [PATCH v4 29/33] x86/mm: try VMA lock-based page fault handling first From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan X-Rspamd-Queue-Id: 7AF2410001E X-Stat-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Jd2Hyj YBLO75kt hVm9Fq5C+3zqVZzUFzCZgM4LgPxA7hoygX7cyMiAbvtpVrrMsjB16i0Wk/6taABvvkkWoZiELWIvL+0ig26m1yiTN1Pts2QhbgREQJYiyWse7Ft2Tcy4RDczmhK+JzxkSlOpCumSSLAc4FkkadvxZnBi9O8QMJc0NCF3MqT8T1IgozoRWNZWrBjYVBmn0fYaaN4tHYhOvTE8M9LEAb3ScgyRDxqB+uCElKvWqKlZNYh0sT1/FG2AgbgBSz2g+PMi4DjzC6Kd8CQGPxO1G5aZyctuALVfRqDyEWJri03Cr/NIEkpYvoVpvErnF311JRCn+VMQsUrBSfYsWZpIvt3qr3mft08GAEUgDYH0MkjRhVwudppj9XKfqEjJ7dHS7GaKVEYqMunukBJ9ZBTR0ioklNCbxthtwTwUEk6C8awc6TnmTGVMNF2CasmMgi8lRQn5civ3SV7vUVN+iUFlYkmiWzmJ1bHBfzBlhIKfmZhMKMGIrs6reTBkn5bdSnyMrwMqFsuQ0Jeuhbwlqu/bYAy6P4AA2RPDH3mOkIoBJZMZ7XbKc4gZI0jgh/JFwZOj7B6IDxunvaj0rz2GBgBsmjqyZYP4hJPtiD3C5uTeYsTBn7JXfALdgl5ruiaPTEGjEVyAWOsoJc+6ojvzcQQnYbPjXMvWOYXG3RYM6wppZ 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: Suren Baghdasaryan --- arch/x86/Kconfig | 1 + arch/x86/mm/fault.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index a825bf031f49..df21fba77db1 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -27,6 +27,7 @@ config X86_64 # Options that are inherently 64-bit kernel only: select ARCH_HAS_GIGANTIC_PAGE select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 + select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_USE_CMPXCHG_LOCKREF select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index a498ae1fbe66..e4399983c50c 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -19,6 +19,7 @@ #include /* faulthandler_disabled() */ #include /* efi_crash_gracefully_on_page_fault()*/ #include +#include /* find_and_lock_vma() */ #include /* boot_cpu_has, ... */ #include /* dotraplinkage, ... */ @@ -1333,6 +1334,38 @@ 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); + vma_end_read(vma); + + if (!(fault & VM_FAULT_RETRY)) { + count_vm_vma_lock_event(VMA_LOCK_SUCCESS); + goto done; + } + count_vm_vma_lock_event(VMA_LOCK_RETRY); + + /* Quick path to respond to signals */ + if (fault_signal_pending(fault, regs)) { + if (!user_mode(regs)) + kernelmode_fixup_or_oops(regs, error_code, address, + SIGBUS, BUS_ADRERR, + ARCH_DEFAULT_PKEY); + return; + } +lock_mmap: +#endif /* CONFIG_PER_VMA_LOCK */ + /* * Kernel-mode access to the user address space should only occur * on well-defined single instructions listed in the exception @@ -1433,6 +1466,9 @@ 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;