From patchwork Mon Feb 27 17:36:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153994 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 5BD73C64ED8 for ; Mon, 27 Feb 2023 17:37:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54EE26B0080; Mon, 27 Feb 2023 12:37:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D8AC28000C; Mon, 27 Feb 2023 12:37:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21A15280001; Mon, 27 Feb 2023 12:37:54 -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 F3A956B0080 for ; Mon, 27 Feb 2023 12:37:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CD79AA0ABE for ; Mon, 27 Feb 2023 17:37:53 +0000 (UTC) X-FDA: 80513779626.06.B7A392D Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id 0C46E180019 for ; Mon, 27 Feb 2023 17:37:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lbYIqJZd; spf=pass (imf16.hostedemail.com: domain of 3b-r8YwYKCF4OQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3b-r8YwYKCF4OQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@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=1677519472; 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=Hcfd1e1CYNsfSesf73569pOSKya0WHju+cd+LlOfzq8=; b=ISYTT7DLSjW7ECr9+97U3de4gYMpvKBFNOaeX448zC/DvBrC5Wzeh+7/bvIaVa9Vntqhrc gGSjbWsZcNmrYPV++v786VszzvZMeLdIxEnT2lIv66LAnWG3pw7W0YCemz+ecTLSddsC0I NGWQsyBqiIYeG9/rPr1vtETqHe0WNVQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lbYIqJZd; spf=pass (imf16.hostedemail.com: domain of 3b-r8YwYKCF4OQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3b-r8YwYKCF4OQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519472; a=rsa-sha256; cv=none; b=5HiHTb772c1cod6WdwyZeEWoIcsYPPGRWTzl5HATIAzvjLP2hL6Ux067WxHA5UJShKvfVx /mBa8WFUMKm4CDRs4SVD0Cdgj03N1hm5L73MOWkoiUnX96yuq2TzfpVCgbZZMNXUt0p+Gh eyL3sb5vvSRJOl0Qh0OZRmwdcD0nxxw= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536bbaa701aso152756227b3.3 for ; Mon, 27 Feb 2023 09:37:51 -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=Hcfd1e1CYNsfSesf73569pOSKya0WHju+cd+LlOfzq8=; b=lbYIqJZdRbbdDZdXc3KPyecDlcIgvcbfb+DcxfEk3pJ0tkCKREu4kmt7prlFLJ1+FQ T7SrZzz7AESmHbsebVB/dcsUJ3sSPqxUDap8J4TM2PMm/f0fKj2d5agwEF1dRo2i14i7 2Tm7gxYItOsxZ6/P6dejoIKGIeHHxYKwoxOS0Hzf8d46xNc4trKpV4bsx+tVItCky7z5 aUXOUsg8Vx6avsDKLvMNoEFIIJZIXtu9ciloUm8OADOlD0yqFEBOdNzn/R9lnJBdqTeu YgUEQUdg6StQbFTiY+Ix3uwxS+O8mpUohpFOuENl70pA6HrQlHtgGjdfJeJSJ8v+j9zf qj8Q== 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=Hcfd1e1CYNsfSesf73569pOSKya0WHju+cd+LlOfzq8=; b=gAegZDvIUiMjR8C0JxZ775Zv7mEbA4CUGe8ULJnu4UqQvnJqpRaGGYfGNXlK4s3yKA rNlQGO8KB96D1r14yMLQWFx71I1uvoywXUQpJFw9ROaVGUBe3PDE58IuKcdVoTfHUuSo XiW/U61ODRCok/8n/xuGgKQ81b6Z04YweY5JK7pXD9NlRHMxruv4qqaKXJZbo4cdHSkp oymV7PgR/h0X6edBJaRe+CYj7DPdg/FsX6gy9I/8GcSKoseM9FpCTIC/yj6guOo1as2o +0mfyaCrMXhnJhvmEBjrpGN3mXLEXOBKPN4NrlLDK1HwsLBLOacijzNOqh0Q1qld/IZc EFQA== X-Gm-Message-State: AO0yUKUUgfZ/5y3xx4iwOgJCuq3ehZUzAcdWygx7hg2rZElxmWqg9OK+ CcS1/eySPhRpMjB1gqU2idjPYB/vk+I= X-Google-Smtp-Source: AK7set/pwIZDrdxVaNh2CuYGKu4UYoRP2oxQl2zbmcloOQnN3ea3mqmxriAC+2y4Q2nBddYhpyeOIu/z0Zw= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a05:690c:31c:b0:52f:184a:da09 with SMTP id bg28-20020a05690c031c00b0052f184ada09mr265273ywb.2.1677519471088; Mon, 27 Feb 2023 09:37:51 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:30 -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-32-surenb@google.com> Subject: [PATCH v4 31/33] powerc/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-Server: rspam07 X-R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iXMuwbJR jbCzHn+uK0/t6Opq1cCvIwOx4Os8HRncYb0yS7F4iWf/LR+2YtoU7SvjzPZVmFI7ambtqp7wvUl/qfeAHSbFnxUVueIIeYbfABZf85RrjoDeg7I9sxbIJ76oJ24eQr9RTShLPdU933iqUDGq6Dr7aI7ExZiLvxQTeKKKRbvanS4hX6GioSSqPyan+b0MRzfJRETqbGd9pgENO4mPwh/rCYuDwlZZE9jJJetI67v1CjqbbrT4DQO8NLcNJi1xzHmBWQzTOvHULMq8kk4kAJA3/0oUZOAdTHhhyRBM8Asmrm8DTWmfskC0oqGUMJLkJ31b5qsg9f1nMzIthpeFAEW9ffMN4bbxRIHGxhEI5eJpBwxrKotcH/0mbOzhw1AKRVaXKzN8Q+SV+hx/X43Rvod6CGXHBLRLdlAIixakh0NE6fQJd9C9RqoxAwXSqWdTVlfRYW5jkwRYMs3VAZ2FNAdqQqXLmN8mps2UuyrgUUv8zryxvdXrf+bGM2vonTu9zcb+XIOu7AE4sT0n3tWnnL2nFm0cGZ9pk1hs9Olzghwo5ZuDyfI9oFeky5BdvAiQeXPOPE+KdxWvx18TMROLsUT3OQIFUHJoUebI0AH/TC9qNi4FaXAFyOhwcnN/eT0cP8Jm+AYSzc9OTS5cDCCk2D2FSfl1P6Q== 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: From: Laurent Dufour Attempt VMA lock-based page fault handling first, and fall back to the existing mmap_lock-based handling if that fails. Copied from "x86/mm: try VMA lock-based page fault handling first" Signed-off-by: Laurent Dufour Signed-off-by: Suren Baghdasaryan --- arch/powerpc/mm/fault.c | 41 ++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/Kconfig | 1 + arch/powerpc/platforms/pseries/Kconfig | 1 + 3 files changed, 43 insertions(+) diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c index 2bef19cc1b98..c7ae86b04b8a 100644 --- a/arch/powerpc/mm/fault.c +++ b/arch/powerpc/mm/fault.c @@ -469,6 +469,44 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, if (is_exec) flags |= FAULT_FLAG_INSTRUCTION; +#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_pkey_error(is_write, is_exec, + (error_code & DSISR_KEYFAULT), vma))) { + int rc = bad_access_pkey(regs, address, vma); + + vma_end_read(vma); + return rc; + } + + if (unlikely(access_error(is_write, is_exec, vma))) { + int rc = bad_access(regs, address); + + vma_end_read(vma); + return rc; + } + + 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); + + if (fault_signal_pending(fault, regs)) + return user_mode(regs) ? 0 : SIGBUS; + +lock_mmap: +#endif /* CONFIG_PER_VMA_LOCK */ + /* When running in the kernel we expect faults to occur only to * addresses in user space. All other faults represent errors in the * kernel and should generate an OOPS. Unfortunately, in the case of an @@ -545,6 +583,9 @@ static int ___do_page_fault(struct pt_regs *regs, unsigned long address, mmap_read_unlock(current->mm); +#ifdef CONFIG_PER_VMA_LOCK +done: +#endif if (unlikely(fault & VM_FAULT_ERROR)) return mm_fault_error(regs, address, fault); diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platforms/powernv/Kconfig index ae248a161b43..70a46acc70d6 100644 --- a/arch/powerpc/platforms/powernv/Kconfig +++ b/arch/powerpc/platforms/powernv/Kconfig @@ -16,6 +16,7 @@ config PPC_POWERNV select PPC_DOORBELL select MMU_NOTIFIER select FORCE_SMP + select ARCH_SUPPORTS_PER_VMA_LOCK default y config OPAL_PRD diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig index b481c5c8bae1..9c205fe0e619 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig @@ -21,6 +21,7 @@ config PPC_PSERIES select HOTPLUG_CPU select FORCE_SMP select SWIOTLB + select ARCH_SUPPORTS_PER_VMA_LOCK default y config PARAVIRT