From patchwork Mon Aug 29 21:25:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12958446 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 27912ECAAD8 for ; Mon, 29 Aug 2022 21:26:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD3A694001A; Mon, 29 Aug 2022 17:26:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0D45940008; Mon, 29 Aug 2022 17:26:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74E9994001A; Mon, 29 Aug 2022 17:26:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 59138940008 for ; Mon, 29 Aug 2022 17:26:16 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 314EF1C2F85 for ; Mon, 29 Aug 2022 21:26:16 +0000 (UTC) X-FDA: 79853913552.13.04DC367 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf28.hostedemail.com (Postfix) with ESMTP id D703DC0026 for ; Mon, 29 Aug 2022 21:26:15 +0000 (UTC) Received: by mail-pg1-f202.google.com with SMTP id i191-20020a6387c8000000b0042b44ad723bso4563119pge.19 for ; Mon, 29 Aug 2022 14:26:15 -0700 (PDT) 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; bh=plnLK4otWaGxR+W8sd3fBxFm06LW87+WFj6YX7JmKJI=; b=O7Fq7HWZ7z8n2j/HcxIFYSMFkVCbPksq++2+VIS66vXRQwbI7dU8JTklRI8MPiby2e edzsUySG6IImo6mrh8ENCQ2+wxA6BfMFPfkVn5AwXOsZupGcnzhGGSKXttVqFe7CqMCi 1h3acQOuI10/ig3PP8xkKsm4NtzNbHGpaQpLwoGjKN2BSoc/HFLvkEbHUIkKXG5J3g9z 9q6Jpb0Ph5QlVq/4hF27NyIuM3/V2/KAkuHoouSJodEv2dWsfVfE58VeJPPY/+QOUQfz r+QwUf2vpfx2TV1s2fbWWB8eIKopRLMSEdWWEDiBiVoTpxt/dnwqSCw7tnlmHUsJj3fT 5A2Q== 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; bh=plnLK4otWaGxR+W8sd3fBxFm06LW87+WFj6YX7JmKJI=; b=0l5VyXjP07a/LhGvASyKqmJ+oN7a1mmW8ulI27Gu6SK7TuhEWc3iiNpL35Ind5VSkB qhu6suUwSP/CKyKYT6ZQEMhREzRP1O84QMxwiQiA0rRsIvpIO0W9fGVTzdciSeoxYuKp y2mjprFMRWevU87FRJMg8sJara9XkARcNvp/mZJSAZekj2EIl57woqw4Io5PVpeKPhaR g1y+IT6tBT0VMkplZrlF1vG/h095FVAqh7zkHsiRiVADBAMZ+3UxxBgsOEhzl74g3cdO vCggqOC94hXVt47tQXeqXzW3VkmVYsdHWp8FBpzN5WCqOGLwNNlGZcaiz15kiimB0wDY SAJQ== X-Gm-Message-State: ACgBeo2142MP9HqDMf01KwFsNNDLiWzzgGlwupbRVTk5gI/+OnaCJNvG ovtCZ66lZDC/gjJkaM1+lj+NxNWw064= X-Google-Smtp-Source: AA6agR6koDuvaTUSC7OU/WlAja75jS99jSayBh5syt6ErVM0PHA+biyxUvs5Ar838YXdhWnvkXm6gonES4M= X-Received: from surenb-spec.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e30]) (user=surenb job=sendgmr) by 2002:a05:6a00:14c7:b0:52e:efb7:bd05 with SMTP id w7-20020a056a0014c700b0052eefb7bd05mr17908102pfu.24.1661808374985; Mon, 29 Aug 2022 14:26:14 -0700 (PDT) Date: Mon, 29 Aug 2022 21:25:25 +0000 In-Reply-To: <20220829212531.3184856-1-surenb@google.com> Mime-Version: 1.0 References: <20220829212531.3184856-1-surenb@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220829212531.3184856-23-surenb@google.com> Subject: [RFC PATCH 22/28] 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, laurent.dufour@fr.ibm.com, paulmck@kernel.org, riel@surriel.com, 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, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, surenb@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=O7Fq7HWZ; spf=pass (imf28.hostedemail.com: domain of 39i4NYwYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=39i4NYwYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661808375; a=rsa-sha256; cv=none; b=NA+NMet9Xkj0/zWTXnD7iqljZrHtOyRjK7//cZFQ7z/9HYjVpxCXAplu9MKH/TSfL1SJ6A 1fMh2nGoErrcCvmBZGH8jffKR7/IKbxSKY27fXe5CArMo1k7WNbmFcIr/Jvt5i6Hz5xJH6 Z4g2ZcG6EcGZojT7rTJpD3FHN17Xitc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661808375; 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=plnLK4otWaGxR+W8sd3fBxFm06LW87+WFj6YX7JmKJI=; b=QV1xnQXNH1ugGFw4J0z1bWTOYVLWXcSknzWl9oJZo1ftUbeJmSdFvf03kwmsPKyb1Eelo6 /DqpLkX25QBBM1Wi9KYEfWJEkoqo/Ga/g8eT8PCb91BjvNaStVv7tA4IrFwQwbQvaC+KGX Nzb3Xym4CJuyGZ0zG85sWCjnHG6/f3Q= X-Rspamd-Queue-Id: D703DC0026 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=O7Fq7HWZ; spf=pass (imf28.hostedemail.com: domain of 39i4NYwYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=39i4NYwYKCKcZbYLUINVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Stat-Signature: n7p146edicd36mz5for8ei3io5a9ar57 X-HE-Tag: 1661808375-300463 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/mm/fault.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index fa71a5d12e87..35e74e3dc2c1 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, ... */ @@ -1323,6 +1324,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 = find_and_lock_anon_vma(mm, address); + if (!vma) + goto lock_mmap; + + if (unlikely(access_error(error_code, vma))) { + vma_read_unlock(vma); + goto lock_mmap; + } + fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); + vma_read_unlock(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 @@ -1423,6 +1456,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;