From patchwork Thu Feb 16 05:17:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13142524 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 89EAEC636D7 for ; Thu, 16 Feb 2023 05:19:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 207976B00AB; Thu, 16 Feb 2023 00:19:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16A1A6B00AC; Thu, 16 Feb 2023 00:19:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F25596B00AD; Thu, 16 Feb 2023 00:19:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DF5DC6B00AB for ; Thu, 16 Feb 2023 00:19:11 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9F65440D09 for ; Thu, 16 Feb 2023 05:19:11 +0000 (UTC) X-FDA: 80472001302.15.12AA9DD Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf28.hostedemail.com (Postfix) with ESMTP id DDEF9C000E for ; Thu, 16 Feb 2023 05:19:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="VYBN/Sx6"; spf=pass (imf28.hostedemail.com: domain of 3zLztYwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zLztYwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@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=1676524749; 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=IMepWjMdRmbly/mfPnmeELsKhzAKjn/e+MmdnnCshxo=; b=ziWgRfgcoAiSYiKlqBT6p0T4ghy0OCfGGGofG3NakyAqVkwN2LeqS1tsp/2O+pHNzO/ZwH tETWvfbvADHUQKKhH+ZVrB8/XaG4VcBuWzfJ1Ea5/UBkHD+TWWvZw7mXFUr8SLJkjee8bI Q7Xmp9o7BfUeP0CKWxpYn5zRCFVxLHg= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="VYBN/Sx6"; spf=pass (imf28.hostedemail.com: domain of 3zLztYwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3zLztYwYKCCMRTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676524749; a=rsa-sha256; cv=none; b=dlrT3JVlXEZEVD+yI4TYQAOdYIBWZCbma5b3cHhpZKea0SbWOWEpB9oooOYIooY7Ohm6lW lHvVFoGijzfsT5HnXzVk31NeraUlpCGsW9vWMWvvQWjHJhgdwmKiIKX5thEY66jgE8WwWs 3f9me7IiJO/j6Wk7EVvrTLBHsJb06Lg= Received: by mail-yb1-f201.google.com with SMTP id f187-20020a251fc4000000b0087f69905709so868942ybf.10 for ; Wed, 15 Feb 2023 21:19: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=IMepWjMdRmbly/mfPnmeELsKhzAKjn/e+MmdnnCshxo=; b=VYBN/Sx6H1zkhlZQfZvD0Liynh1SzBUBQ9VOXzPL7TQljh9ke7q1U13nsJvyL8jhTT VJdOiIwIjVau+ArgVKuyZBGkikb4wPVpg6tKpQ0o6b7A2xVbgU2vETmFbJMmm/kSYK3W jjQeULRVDfrD7eqjNl25w/HYQSurUi+SuUv5YnVVfpqkT7+a9RL2gs3g5vQZ1Iey2WKK za8Zu9gxbyi43cwHcYzE3Uj7rIHDEJE8sD5soBil1CQae5YChuN7lRgwr3AT9vKkAkhX nNMop/PJ3OYQ+4sMUjA9lss931diz+voYeLd0iyVQtxE8G6e+SWaxHgo0zdZNYDoa0CR el+g== 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=IMepWjMdRmbly/mfPnmeELsKhzAKjn/e+MmdnnCshxo=; b=6Vad1CEBspTzcW0T21AHZwj69HBtl5/7IZcuk2bLi692s26OrwiLrrknPx+8vq+1un Oasar0MvOnj1vM0rdCx79coSj44qeIq6qHitHOmBkVvNbsIHutB/VG+Sb3yV5ZV/36gA 4pjm0h0fSfx3NRDJCLBb/bdELXW4p+PgwGJ3SOntiyHJqv+r1pCWMIpoeLhkEHQbk2MA 6NTt4d28RnK+0bSQU2zRx77NwSQ6j49ZFpyal+OgvPphYXopiZV4cwUUsQL3Pcn/POQk Xs4BPL5erkD8Rk+XqKhfCL0IQdIjte8PxX4NbXsXJoqYTKYy/q1OcAqKQ2DfUSoOqJun EEFA== X-Gm-Message-State: AO0yUKX6A/07LJkgbr3gGIpo1rnIKORf/+g7mbgJ6oqkuv+1v2mo6YvM xWEgwcZSWmIrGDyQzUz41BRqs6h6XjA= X-Google-Smtp-Source: AK7set9HCvy2lOclXRQNI1sLIIJkNYQ8CImwbHHTA3gwi641v9vkQcIdLDEBqeWHm5koRinED1uR5T68Tno= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f781:d5ed:1806:6ebb]) (user=surenb job=sendgmr) by 2002:a81:4516:0:b0:52e:e718:9641 with SMTP id s22-20020a814516000000b0052ee7189641mr16ywa.9.1676524748625; Wed, 15 Feb 2023 21:19:08 -0800 (PST) Date: Wed, 15 Feb 2023 21:17:46 -0800 In-Reply-To: <20230216051750.3125598-1-surenb@google.com> Mime-Version: 1.0 References: <20230216051750.3125598-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230216051750.3125598-32-surenb@google.com> Subject: [PATCH v3 31/35] 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-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dRabn Bs2u2BEHzqutV0hktTBnra0ErGzmuIiJo0/WEabim7uOiPIoZUZnWRpwNgBEa5hlkjrVJWyXKGChLq+Cx8h8rmMvIXaYJ5Eo2tT56EsxJ3/ZY4DbWRwCyoRMLjVibb5OgAjjXqNnspbQsbMhsU3ZAUSUMBBj1Z62FVxuTlzsOQrRVOR8ArHr2lcXCukC5sUnn6ueTb4LOgDKgjMWl6RzUQOy0dPJi9xDsIbjb1vpRYATMN92bHYqCh72rlrTt5Qj7NSMhjDuyZgCCFLFPyGqzme42FqYiDArKNeufme8CdzB62fKf/9RQseORdEMbfkThh4uIzdzJrzonHVbojb18aMm9REShFWqywxBJC+OIlYP8nhF6QudOnsi+JSK7XmMlfbl6EZ9k/bzbD2C8WtZp9blH7nUARKBZKGWqM0zYzIEmCAYCNRwWK8p54Rdbb1wSEUmTHVTA1qMSMP5koa7jc+wicqZWQSqgLfKthIv4cEfST3bNMpEohF39dsKfFIq6ph9JSdLqUP7JAnjLggUat4uRCTJ2mfay6joRa1B6sI5/24BDhGpumGU+AFiNsdAOOiG1 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..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;