From patchwork Fri Jan 27 19:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119298 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 4F090C54EAA for ; Fri, 27 Jan 2023 19:49:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D81826B0072; Fri, 27 Jan 2023 14:49:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D32546B0073; Fri, 27 Jan 2023 14:49:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD3156B0095; Fri, 27 Jan 2023 14:49:14 -0500 (EST) 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 AD87E6B0072 for ; Fri, 27 Jan 2023 14:49:14 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7DBB080864 for ; Fri, 27 Jan 2023 19:49:14 +0000 (UTC) X-FDA: 80401617828.30.A72F99E Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 3A7D41A0015 for ; Fri, 27 Jan 2023 19:49:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I2P3olZB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3HinUYwYKCOUZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3HinUYwYKCOUZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674848950; 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=zr26Tmb2M01sb1afZfnklHdnYeWn0/HWZzrpjXJYooI=; b=KxuP0WiqaOY/fPEgPiMSbFWovjpC8UuGaBBUm3NUHBsdUc5P+Os/41JsRof/eeZFPQIBmV D4RiOpDhSzqNJDNDj4/1nbSr0+uAmpDb+W3rXeYuVbeb8qNhfFlA7kA+KRuynbIZzq1AKD 4a4q9ijXR8AXH5rXuMTxPUGFLmqUA5k= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=I2P3olZB; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf19.hostedemail.com: domain of 3HinUYwYKCOUZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3HinUYwYKCOUZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674848950; a=rsa-sha256; cv=none; b=OS0svs+olo/uxAk/O/ilbS4NcBSnkLWIAvjgn4rNFaxtVEpEuhEr6kCuP8g2BndBu6Qep/ XmqMtwe0PD9zaDvoFh3cvkbiRHmpqM+pSfJJBOFtLfM2Quqn7181S+rMHAhCk6QYtGpvbD c34ACB3mRxvcec4X62pHdmVSN3VS4Oc= Received: by mail-yb1-f202.google.com with SMTP id t13-20020a056902018d00b0074747131938so6405669ybh.12 for ; Fri, 27 Jan 2023 11:49:09 -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=zr26Tmb2M01sb1afZfnklHdnYeWn0/HWZzrpjXJYooI=; b=I2P3olZBrDoCFDP1jHcaHXqtsXyUzxQr/ws4wX6bBu3CUipyuxA31yRpWa3MnFa/SU pcf5+CCx+WnMbozlzDdIg2ALFwq/OFj8s/q24FIJwL7Tizh8I6eeGtbBFib4zJzLB5md /zjFFlwtWXGghsSwviKTLUSRcwBRmcJaXn6b7nEXFweXpvU3ZyCKtcIxikLC8+UQ9pUQ JujyWegWeeB7qz6qsENh+jKg1foSfeMqF01FuGu+Yb/GyFYoIS6vq3ynrguPkj0pOoLx BYJ8cK1I9Z+jOMo/TqTeh+dlSH9FVfZfZ84FkijhY572Ij8GlcP0ii8VORVWe0sgl8Ck Cp6w== 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=zr26Tmb2M01sb1afZfnklHdnYeWn0/HWZzrpjXJYooI=; b=iZiOh6ybeNxyqA/x+QNUSPzkQ1mEtenG8zM8p3QrypsOzJSPyQNSPTg77J3j3z4tif dy462f4sCcVKpLVSTKOueWsXBS/UNqOJtq4gubJW+u/HeTEfkSX90jAvbg8kOOtg49Ia b94TqdiCrS/Z9OUkZCP3rkD+/eXcoZMzsiKfoh/5hIRtM2y+6r9ij20lGcIg0bdn2iBm evewzRLHJQy7J3RR/mssnOP0xe5zveYw5ObK+ogbdKMmb7oFwqMWU+PtqD33eMbLCMWc jXuH+DcJM8Yrr62+LSjxzLgzHQLACDqWA0WmPJv9o4G+aDzWtQ/krov8xqW8AJ+mG1MA rfyQ== X-Gm-Message-State: AFqh2kqhb5qA4vwBWRGiWNVQkcPE1PTnfj780yn01rZbINf12YjAlfs8 TVchhjM2zJdumxvMrzP0RuSl+s8U0xw= X-Google-Smtp-Source: AK7set8yRf6g7ktuBKP0CQzBeFyUCv/mUJgTqrv00u2WfcKZqCCOgg0GVy3Vw6WGmXU8JBT03ehy/weY7OA= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a0d:eb09:0:b0:506:391c:6d37 with SMTP id u9-20020a0deb09000000b00506391c6d37mr2021270ywe.88.1674848542935; Fri, 27 Jan 2023 11:42:22 -0800 (PST) Date: Fri, 27 Jan 2023 11:41:06 -0800 In-Reply-To: <20230127194110.533103-1-surenb@google.com> Mime-Version: 1.0 References: <20230127194110.533103-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230127194110.533103-30-surenb@google.com> Subject: [PATCH v2 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, 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, 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, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3A7D41A0015 X-Stat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RLlqk9Ehz/LhIgU0esgMF2J0mvCB9Ua9Fc0IfgKwLP8DG5zEaoUV9t6cRoJ65C2QuY0mcdQDj2ecLZj1zq/Br89SwRG4baFrpMKifjl5I5ec+gR6OtSrMbfpkZZ3df9UByPHpUG/tOyUSL/uYtzTd6Ibo9t82uTJNML4vcDh62O0+LzB+n4p0Xn2e5/HeI8f96HfXgWzwu7TCzGqwpDf1B0HReDNROXzJLn9glm/l0iISnbGv47T3/s+Biq6yqNvJA8yQ4U9a+PY8RuwmEreg2Xj4fJuMw70RgGSoCisvwbUn96m1UD5p0EBPXT5lQL0j1gG8nb8gfQ0qCax0ULkU80h1f5eT2oVtaHNDctYFhnoSxldW3goxmoeUYZadLN/q7x8Qo8wJTahmYmZAJ0rcwXo0Sc9EgY/1iWqil7xRDZxdG2+j5ZkaaLTIegIVSZCPFf2vcrthgl1gyAG2eXYWLsL3zFVaWHNYCnlLF7K7uPLM+N7wDM30D7y7u5iW1IzGECjuc6OFUd7PuEP9tmedMnP4JWRaBeCn6Irrlbqj9eQuVkFOmScIanfbrFOLTJqUSLhnyWYrhCtWXtv2A0VFzak8yT5k8UTwhhV0aFgdcJZ8CCvd3ckaDGyBUoxPuu 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 3604074a878b..3647f7bdb110 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..122c8fe4af12 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) || atomic_read(&mm->mm_users) == 1) + 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;