From patchwork Fri Jan 27 19:41:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13119263 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 39278C38142 for ; Fri, 27 Jan 2023 19:42:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C00AE6B009C; Fri, 27 Jan 2023 14:42:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD9876B009D; Fri, 27 Jan 2023 14:42:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7A126B009E; Fri, 27 Jan 2023 14:42:14 -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 963626B009C for ; Fri, 27 Jan 2023 14:42:14 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 621921410A6 for ; Fri, 27 Jan 2023 19:42:14 +0000 (UTC) X-FDA: 80401600188.07.E934F69 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf03.hostedemail.com (Postfix) with ESMTP id A2E1520027 for ; Fri, 27 Jan 2023 19:42:12 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rcBVm8w9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3EynUYwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3EynUYwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674848532; 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=gSaEMik01Wf1+Bdt2RmdUMjgYY7lDp9hLxJUYqXXyyM=; b=oUMKD7GJRkPMmu4Nh20AIcyOPCN92Rt0U5jb5RJbABpWyz8rQqY7KsfV2ApgFnlVCUXrDI MSYhUm5/mP6s81bzezKBmhMzNwDvO9E0HxNcSSFBstR7nzodgB5lryPuW+WypJWOhCCaBO jF094/arHlQeZ0tF9e3h47iowsgf18E= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rcBVm8w9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3EynUYwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3EynUYwYKCNoOQNAJ7CKKCHA.8KIHEJQT-IIGR68G.KNC@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674848532; a=rsa-sha256; cv=none; b=0RyT0Y7670keStWZ/tsAUVZa6wRFaMqEDPdsim4SCZNi7kXjFRiFat5RIbER/ccpAv7DkS kc7pbp/DYMe1BF3zkaeviB3Lp4umiv9+LPB/kGymrWE98iFMMXwedul4Xjv/bCMbG+NMrT 5ggVXsq4Spou5YSSqs/BAYUgR12NTqQ= Received: by mail-yb1-f202.google.com with SMTP id z9-20020a25ba49000000b007d4416e3667so6420750ybj.23 for ; Fri, 27 Jan 2023 11:42:12 -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=gSaEMik01Wf1+Bdt2RmdUMjgYY7lDp9hLxJUYqXXyyM=; b=rcBVm8w95my/f0ebkBHOBSdk/g3dXIBnrvyKhE+0lfp8SBBL9UDohndGfm9prz69Nb 1VsGdk5hVjbZdd99cfs1kRzqndkhM72YtTrleRtcoKwDWYV7T956W4hi9P14DNVnfcTE 4dzd8voX/MwzX+niWcYh6zC2gtPII1RsQu2W+o1SzbH/VUzyZkZ+K0mbi6bCuvIO2r/9 q8JUw2FMeYJjbLjibdrizaV+CI77RGRlLfF03fxNpzuIRE1ymkIpYCAH7a7Vh5p4LTWM djOGRW9GCrBrxw2Z+lpBSKPiwjL/b62fESDSi0yRTpPNMfCaBkk0gvqmlpNjM1674+ZN MkCw== 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=gSaEMik01Wf1+Bdt2RmdUMjgYY7lDp9hLxJUYqXXyyM=; b=LZgSwosTaTvqmpTEt24ZDsDR/+Ki6ZRHXd28b8seS8ToBIB7PkuE4vDRRgBaNnhw8K Or/x4A5uJj3fTZj1pOt5w/GHME4G5AiPmUqo2o7z64s2hUtdkRsupUk6LpEymlU14eBV h7AwUC9RsmIBTOjYcNBOGDD+Zqup0YtahkRSglyWEGO4rDVrOjiWGej0fO8P68C3j31x zx5YCkcBhH2x1sJDBdyaurTyexFq5dZIc/8NAOX/LqsBHpRA12rv63tr4uORtPlqGnJy +ZKgfLwjlmZSwxEjbcsbkDRmzCJVP9wsvfJFSe/Oc11TlXlq7qHQL46XcRVPlHTTLQs9 X3JQ== X-Gm-Message-State: AO0yUKU/0KnsaNnlt2qOZwTtb7TmU7xEaaapsg6uH7Fnj3fpnwPfUtLo SFt1/UzxklQzfarjQXHph9vmc06b0g4= X-Google-Smtp-Source: AK7set9ZuZbDGpVLmgenU71+ffHh46VvnF49YmmPOU0QZTkBBursiC5h0isQQWJJC0fjjZLxRphOeOdStg0= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:4e19:be9:c5d0:8483]) (user=surenb job=sendgmr) by 2002:a0d:d8d5:0:b0:508:1348:3e54 with SMTP id a204-20020a0dd8d5000000b0050813483e54mr1003857ywe.440.1674848531551; Fri, 27 Jan 2023 11:42:11 -0800 (PST) Date: Fri, 27 Jan 2023 11:41:01 -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-25-surenb@google.com> Subject: [PATCH v2 24/33] mm: fall back to mmap_lock if vma->anon_vma is not yet set 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-Rspamd-Queue-Id: A2E1520027 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat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hElagDp6hyyDsmLUdnOXJdGcvZz1A6obcVveqYLZ/V69j7TYdTleIk/G1Vztj8iS0eLLSeFwf0rVvb+syc2Btf6pkZRa+FpgB7VXdTinczcWMMWK6yiPwsmDBgj9VOoYEWnD7MW8y/9uZ60rcvdhxrM0OAiFNyAt52UrjDqlHydr7jg0oPGVqu6iZaoKwp/gQYP9hjRYSVG9p0U/ZqmZTIboHRJ1ayadNgLMXbY8KKZtAfbu2vKKRSl1K2FIBPzkjbCVsa6kKx+kHFFB2FqAFclGssKTWAtizBmzuQuQxeLCTeHDiBomzN51GuVhED1Zr3/YkmjHZIfTf3JjlutN2gpE/iO/FEEgr/p2BxVuoj5ln9z7oVCZf2LKLWmySWtPWS7WXjWS5V5ajjD3945coMcJK7hBcOI3VKglk81K/qFO3/h4JLK7rzyvQM9C3Yo1+UQEG1/7BD42VUP9TjKWcjbxxzSVd38j6SxOwDmHm3SK/dWZPpTEqp9YZfCNkyTPGMcdUCN3efa2qAshl9eVeiEsY0T/Vk/pEcFZEfyyEqQezBfoI7iP0cjy9xT5CiCZ14BE9klMGLgXSDRhFQJiEP4yuZr2asxshSxHBpBF+IVDJO0BgjxnEyoFcgCQm5Nrf2BFDlrA= 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: When vma->anon_vma is not set, page fault handler will set it by either reusing anon_vma of an adjacent VMA if VMAs are compatible or by allocating a new one. find_mergeable_anon_vma() walks VMA tree to find a compatible adjacent VMA and that requires not only the faulting VMA to be stable but also the tree structure and other VMAs inside that tree. Therefore locking just the faulting VMA is not enough for this search. Fall back to taking mmap_lock when vma->anon_vma is not set. This situation happens only on the first page fault and should not affect overall performance. Signed-off-by: Suren Baghdasaryan --- mm/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 5568fcb0a46b..593548f24007 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5244,6 +5244,10 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, if (!vma_is_anonymous(vma)) goto inval; + /* find_mergeable_anon_vma uses adjacent vmas which are not locked */ + if (!vma->anon_vma) + goto inval; + if (!vma_start_read(vma)) goto inval;