From patchwork Mon Feb 27 17:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153993 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 556C9C7EE23 for ; Mon, 27 Feb 2023 17:37:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 130586B0098; Mon, 27 Feb 2023 12:37:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 107C128000C; Mon, 27 Feb 2023 12:37:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE894280001; Mon, 27 Feb 2023 12:37:51 -0500 (EST) 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 DF3BE6B0098 for ; Mon, 27 Feb 2023 12:37:51 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8ADC540A38 for ; Mon, 27 Feb 2023 17:37:51 +0000 (UTC) X-FDA: 80513779542.01.6AA25F5 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf05.hostedemail.com (Postfix) with ESMTP id BCD59100008 for ; Mon, 27 Feb 2023 17:37:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=axT7gIHS; spf=pass (imf05.hostedemail.com: domain of 3bOr8YwYKCFsLNK7G49HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3bOr8YwYKCFsLNK7G49HH9E7.5HFEBGNQ-FFDO35D.HK9@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=1677519469; 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=MLyuEeEynE8KONkERvpFgsKF3fJfrVlAamWKGgJMnRA=; b=CclnYsyXijp7kETvCnQGgh8geGOcQz5n10pJmYzOa5e+wG5C0HdDIW1GlVKIwHkYD1yQU4 pBSJlWY2CQU9OqYXikJ4+UXnMijGov8BJnCzBU0GV8wfm6DN4zVHk2gD0KI4HNBMoemUos yTeXRcjkGIrxPwAI83DzkV5ni22Ui8s= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=axT7gIHS; spf=pass (imf05.hostedemail.com: domain of 3bOr8YwYKCFsLNK7G49HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3bOr8YwYKCFsLNK7G49HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519469; a=rsa-sha256; cv=none; b=J7fPkqqxejzN094VU4D0WuAqaMCrGPTS3vEQ+/IG8ggr6IpDqEavjfNpxSb49PGIQOyRnS RhOekxk2P9mmBSrkqqgzmH3gh+yoGHpx95B99eIhQZif7TQrUHh16hu8CZy+byb/c/tZJ+ uvO+GYVE7cfvLka4L+SCe8LD9IlEJAE= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536b7eb9117so153613277b3.14 for ; Mon, 27 Feb 2023 09:37:49 -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=MLyuEeEynE8KONkERvpFgsKF3fJfrVlAamWKGgJMnRA=; b=axT7gIHSM9vrvAhwKVjKksPBBorC/hEiqwRtJY/ABl81gKVCntmX74iTRhXvXgAnUV Um80sGKa9BQlweiuzQTKDk//t9klBC4AuVFnP3CTk2uBlo6XhUaWjWY5Blg8c/od1wB2 kGKuk0XbNvhKWTaK071eLxFocsyNDE7thDMFx60EqbJKuNaJXP1uEzxTROegPPIy1HGi /hu0FB66yrsQ6uwQNFSWYEafLSSxfymT27BvoyNTtd8BgVaAOG8u+Vs4WjN1pPd4fScE c5yJ6zCfiGKeo2DRNILtL3E3ThjPFtXt9gJX7nMmqjJa0MWklX0CZPjvb9UiR6pRtDTU u9Vg== 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=MLyuEeEynE8KONkERvpFgsKF3fJfrVlAamWKGgJMnRA=; b=D1TdaOIQsnfq3XoLoQuRAwIs/fQqPxTBOgsObZru5FBnB5FfWlA7DHvAYHaFZRoOBM VacNznoS4e/oNcgsiRUdfzoTjRnZlWxFcV+ic2I5DdUyVhZKp9AnJhVl1PvZjxnTwzLA gehXVaLSwtVhlHhMBlf8hZtz5J5ZGCxMhraU5cV7odKpd/rSsoKKaVsyC4Fv29bNZOuX B20Sha1vmd/uKxmvFy33mJ2oH5sEccD8KUr/0J7Zg8CdNkwOY3w87Dz4LJCGBd1q/sue rQ1dEew25peJvqHRcEb1yFd2/GrpoLIf1KgepUOYJttX/LaxM2fj1MCeKfs2I33Q0HUZ Lxow== X-Gm-Message-State: AO0yUKXJUlFYoPv/h04LU2wSC/vNITanL5dD8hnc3klcKzZBN7f7jcND pVvFMMTBaWAASO2lxvQw6dKkQUqVgGI= X-Google-Smtp-Source: AK7set/sV1mOrmQyWkQwKfhY9l7Yn97smkcjzbwoSpl4Lx6r+hbm0S79lHOvGLHJAd/kE6zZDkM+t31MhHQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a05:6902:140c:b0:88a:f2f:d004 with SMTP id z12-20020a056902140c00b0088a0f2fd004mr219395ybu.5.1677519468856; Mon, 27 Feb 2023 09:37:48 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:29 -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-31-surenb@google.com> Subject: [PATCH v4 30/33] arm64/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: BCD59100008 X-Stat-Signature: iknjcuou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x LYLaAvBfSjv+l/i6iSuXtR84wHKwAUL3mNhdbA8fQcNRbb779Xq7AdbN4zhnuuV6P6p0gxOpkPrTtkQY8IGuohKSZyE7zyaQw17a9JdEyMP10UfSELKcUDxpyvzC5dbL/nBurfthilTGMxnbV5n68P2qo6dPyAZCk7dSYS5z++zoECRHx2TSZ3o97gOk1ZW98vRSxD9T6QgrXpxeVSYYiUhxX4Y20Jr2pfI8a/KI0fCOKxT6TsJ+pRDgiduTaE27xmvWxyegylTRXSV6V5kzk9cJJHWXIJeHYd9JZ8l88rLz/pV1fc/XDvwbfP8dNAK/X1rH3jsNT2iB/5z8okzUqFdTlpX9yHMMJPnW+r5r8n6zmZ5mnxOnqd3J4nrVbhbmy8WG8Z2KWsrVkJ0EFhm0luACDrELgG962avLW9/8gH/TbXf7KcG6tMjp2Q9ubaj6+7BU9tIqlmpBW0XyiCeFlucYNKngqQMKhJRhzrvJgubYZX/Hk0F0Bsx1pcfhsICS1gQOyZkzMWQsDxhLZx/5mzKX0VO6rt8OVb8ycvlt15TewEzD5OKDQdoIC7xrNe1WvtKy4Cu5eHBGJIbYhtDbO2OAO2LwqDPtqh+jtvrFcsiKK+tw8Xe2NnXIXnQ== 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/arm64/Kconfig | 1 + arch/arm64/mm/fault.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 27b2592698b0..412207d789b1 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -95,6 +95,7 @@ config ARM64 select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_SUPPORTS_PAGE_TABLE_CHECK + select ARCH_SUPPORTS_PER_VMA_LOCK select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index f4cb0f85ccf4..9e0db5c387e3 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -535,6 +535,9 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, unsigned long vm_flags; unsigned int mm_flags = FAULT_FLAG_DEFAULT; unsigned long addr = untagged_addr(far); +#ifdef CONFIG_PER_VMA_LOCK + struct vm_area_struct *vma; +#endif if (kprobe_page_fault(regs, esr)) return 0; @@ -585,6 +588,36 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); +#ifdef CONFIG_PER_VMA_LOCK + if (!(mm_flags & FAULT_FLAG_USER)) + goto lock_mmap; + + vma = lock_vma_under_rcu(mm, addr); + if (!vma) + goto lock_mmap; + + if (!(vma->vm_flags & vm_flags)) { + vma_end_read(vma); + goto lock_mmap; + } + fault = handle_mm_fault(vma, addr & PAGE_MASK, + mm_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)) + goto no_context; + return 0; + } +lock_mmap: +#endif /* CONFIG_PER_VMA_LOCK */ /* * As per x86, we may deadlock here. However, since the kernel only * validly references user space from well defined areas of the code, @@ -628,6 +661,9 @@ static int __kprobes do_page_fault(unsigned long far, unsigned long esr, } mmap_read_unlock(mm); +#ifdef CONFIG_PER_VMA_LOCK +done: +#endif /* * Handle the "normal" (no error) case first. */