From patchwork Mon Jan 9 20:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13094295 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 53D8AC61DB3 for ; Mon, 9 Jan 2023 20:54:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E52B28E0006; Mon, 9 Jan 2023 15:54:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2A0C8E0001; Mon, 9 Jan 2023 15:54:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7CA38E0006; Mon, 9 Jan 2023 15:54:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B69A78E0001 for ; Mon, 9 Jan 2023 15:54:56 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 867D2160F3D for ; Mon, 9 Jan 2023 20:54:56 +0000 (UTC) X-FDA: 80336464992.26.7E0A0DA Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf08.hostedemail.com (Postfix) with ESMTP id E4B8D160008 for ; Mon, 9 Jan 2023 20:54:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GjzlXD65; spf=pass (imf08.hostedemail.com: domain of 3Hn-8YwYKCDMhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Hn-8YwYKCDMhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673297694; a=rsa-sha256; cv=none; b=Pc/JCzebbo+rvmZwJvJCFNEZ6uv615S7ZpFienUJk4eKjTv0BBmwzcb+FvxCoCz8V9zjz7 qeLMVfcNPmLsL6TGBYE4M3E2iR/k2Lt86rSzzMm3CMK6L5dj+Af6LLo8Z/i2fxHzUUGBuy ZdtsBbJd41KxLPsE/LBWVFSs9ZC0S6U= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GjzlXD65; spf=pass (imf08.hostedemail.com: domain of 3Hn-8YwYKCDMhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Hn-8YwYKCDMhjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@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=1673297694; 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=Bx36nWIWIaMqsyKC4DFh9Dy6zgkZnlvdwV69ikS09tQ=; b=AJM2cV5qxtsHKHZ5Yo1hiKCAocTstdnrWRlcg6Cumen9qrDJR1CSurBiUsQsdqTvhUpoAT Y3rqEZw7xO8fFOjkT28yE7n9gjYc6YYWvhFOoIAa7q6OCTy4GRCx/etv5XPWvrPpE0F2lW JqAdkEZ3K0Vq6TKl0lhcDijspTQyNMc= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-4ad7a1bd6f4so105783277b3.21 for ; Mon, 09 Jan 2023 12:54:54 -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=Bx36nWIWIaMqsyKC4DFh9Dy6zgkZnlvdwV69ikS09tQ=; b=GjzlXD654bxHD8qHg+BCMZfuuyb19mHGKgBfyrdYtuHPZI3RXY2mylK8MrrZ6vi/KV XpBGPAViKdrJ111khQK0LarqUyqdysojbfZLW54fo2JQeFn5ElZgOwEGNBdof4Exx32h oce1agjXuGHjstOPH9icNCzJQUnGWQYtYgBGU792WEzYIKYlpSXiCOhWF2Ne+MX/DqXf xrifjQ0boHWSv5tXEGAlsRbW4dbyfRz7jLqAVJ0lSkujXDjZ2O7m0HOdnuYL7/iH8Jk5 Up4mHJat+wejXPO4fCLDWlYHvfZ/+JBFjf5EhWbTUQtFaZy2JybPs/XeOQ27EyoIyzsK wpvQ== 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=Bx36nWIWIaMqsyKC4DFh9Dy6zgkZnlvdwV69ikS09tQ=; b=2iKXRT/m4ezNLhnqJ5ByLP+c0RKGAoANSESMZ5zQxbBS3fu5LgIwaPTQcfkRoJkRwV VlrXMfo3kRbLWsUh39Onw/AeKw8JbVHpQNbM0wVegXahx7JPEgXVfa0nBVGKvaXAGPyt NCzXMjDtULCUYLQ0f52CK7HGPa9RVuosi2qiCailx+Ylv5AwaawZZatQ10oXbB7J1LnF 9qyKa4MtcUpzv5gDeK48fiz5usOHmgvVF7PCq25mYbjLSSsnA2DPpnJ5PsjBMCSLP+3V X/LpRNSjXhL7TmP3diDadvX/jYPJxu1CsKyGAoJxzMmSAhpQttDgUc2G6XSgni8lR5Zx xZ8Q== X-Gm-Message-State: AFqh2kp77klHqELyFv4hJcfiqSgs/5OyakwKSsjygvDn41jhVUzNRuIp LhslSCtjLMLhCh3Nhmmr5D5Uj/Gx/7Q= X-Google-Smtp-Source: AMrXdXsUnoeDnhtdWoii8DMH8rCFUM9XgPs0a9yaOqp3Qv/VXJUnVpuxBD4Is/HyplWdMowbocjku3a0aLg= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:9393:6f7a:d410:55ca]) (user=surenb job=sendgmr) by 2002:a25:3c83:0:b0:700:604:2e1b with SMTP id j125-20020a253c83000000b0070006042e1bmr7014317yba.246.1673297694067; Mon, 09 Jan 2023 12:54:54 -0800 (PST) Date: Mon, 9 Jan 2023 12:53:24 -0800 In-Reply-To: <20230109205336.3665937-1-surenb@google.com> Mime-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230109205336.3665937-30-surenb@google.com> Subject: [PATCH 29/41] 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, laurent.dufour@fr.ibm.com, paulmck@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, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@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-Rspam-User: X-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97byvk MEGjPP4G x1s+WNY6QHGkrr3+Qt8RNZmtC2G6ObqBuV7gqfaBKNr5RM/Z79hM+eF4vlKhGSE8gWj6x+sNXiGM5fx/i3IFSJhvJ/NrYLvisHPyyKC+lPqkqIFp68VfAhwWePYrVikI3mi2UedVn1mLMF45xusxJ1ej+Z4N9aJfefY9HsUvNPzaVPWdD6sS8oA3E4gF2IGw3OTneFyhecLXXisJCZ3m0DupJly2XlERt+uiINPTsiTuzesQ/Cux+cZ2Cj3P8GZMlwo/wsQN9QiIwHplb3j9c0wgHLy9FamD50X5rqJk015CI4lQjNbq+K3DmR+N59+SEHfMMoieTkRSF1Pas1UXfQQmaYLwgb2AnBjunoUsM2EuOwE1oa0PGzWeDQNANf65wuEm59Jn/gxz/zLmcq11FTPc7EhhFwNoRR2g3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, 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, pagefault 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 a658e26d965d..2560524ad7f4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5264,6 +5264,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_read_trylock(vma)) goto inval;