From patchwork Mon Feb 27 17:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153987 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 E5531C7EE2E for ; Mon, 27 Feb 2023 17:37:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8375D280008; Mon, 27 Feb 2023 12:37:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E68F280001; Mon, 27 Feb 2023 12:37:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D53D280008; Mon, 27 Feb 2023 12:37:37 -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 5CD46280001 for ; Mon, 27 Feb 2023 12:37:37 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 09E39AAF88 for ; Mon, 27 Feb 2023 17:37:37 +0000 (UTC) X-FDA: 80513778954.09.CB88A74 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf05.hostedemail.com (Postfix) with ESMTP id F3D0210000C for ; Mon, 27 Feb 2023 17:37:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ehrse2Vd; spf=pass (imf05.hostedemail.com: domain of 3Xer8YwYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Xer8YwYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@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=1677519455; 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=qrP8wdv0q5g6TZoHkkTnkJI1bRVcCya3euyXWiQCR7k=; b=KsmtMi85L0zhCtD0dljVihiPZ6ptwGhGMh+WtQPK6fdGaJ/57fzwEbKKxm9pEWCmlamQ6z x/urUl4T5RZzbb3hRfU0tT6aUho4cHWVuV0S43TGSBpejbnvc/NSAt+r5+oISjnyulRPwW AoLoOMIvwrYGS4KXYrjczPQPG/mHZks= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ehrse2Vd; spf=pass (imf05.hostedemail.com: domain of 3Xer8YwYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3Xer8YwYKCEw685s1pu22uzs.q20zw18B-00y9oqy.25u@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519455; a=rsa-sha256; cv=none; b=FxOztobs2mG40ILq3tqgNY4/2ekI+1uWIYf2596fS3WYeAXSzliqoCXOPVe3XNwQaOvytI ZcOkVsGaUC4rd1zuxi0FBhp/+eb8lUgyS9sv5QWeFNnbE9sPhmDMcI+7LkUNFZanxTlcHM XxxbWKxVTm04FtCVK5CsQFkCn+FX98o= Received: by mail-pg1-f201.google.com with SMTP id b21-20020a63cf55000000b004393806c06eso2170651pgj.4 for ; Mon, 27 Feb 2023 09:37:34 -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=qrP8wdv0q5g6TZoHkkTnkJI1bRVcCya3euyXWiQCR7k=; b=ehrse2VdjDnpUSRaJ3cu0jOOkJfFGFsUNPVo557shDqmppFkfxAsvzUOYaJjQ0PijB EblMOtm5g5NRXaAPcMrHVwQAv8s/x+GnRlxruVHPkK5jtQN3yNt/EBweE+tKCGKaism7 U3HUjXQbto1B7qoo3unz00bS4zA1LfeWfOlzZkorv9RHy9hKyHRYaEA4i2TEzaJJuMBg IRIyIDCAlrqJadscsfwaMyXl67M96LYiFdG5WP3t9rIaF13TbFMOYIsSXYvDmmcAe7mT R89y28xjRtFN9b/E58zHscfzaCRWqNFydygKz6NtUn93MmZ0Jv953fv4FHoISujugl1t udmA== 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=qrP8wdv0q5g6TZoHkkTnkJI1bRVcCya3euyXWiQCR7k=; b=RVDIjc+iD/6ao+VwR41WbP9PHjRs0454Nb46oDtgP/VvLQrQm1PzOCQ10ZV5cu1XxS ytTRg9WaUojQc+/bFoVNkzp0JjZFrQISmERN6FtumsjVwlPNQQoO8P4+SdLchUECPskg mu0nCq9bQLaJT4eKsbOM12dlI73I/BVhGZEarUItju7zoYc4EN5jx2MZOkJSIrOoToQz Bp4IEa5c4dl/0Oli7F/wzsshTrUOFhkd/9iP1FpFKbhcVsamD4k1oWQA8Bni6CIDb8qH sBoKB9tuAotHZfr2LTw34xJgO4oT0flhJHMChh7LwH9trpFgFD5yNklC9ENBdNuxF+rS 5fiw== X-Gm-Message-State: AO0yUKWvk6Y+n0FT352NcdlnRILWSETHirDjLWheg5Te5WgfAjl47Ozn sguSNUZmkIKPd0KjYE3X4wBKJdRNO0s= X-Google-Smtp-Source: AK7set/aNutcI5JPOH6nKZSnuzXLxYVujD/4TtRCmI167JUO0duhDMkhOBXuPDJivfwxfw4Ct9inq/o370Q= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a17:902:ab58:b0:19b:e4c:2039 with SMTP id ij24-20020a170902ab5800b0019b0e4c2039mr6578302plb.4.1677519453804; Mon, 27 Feb 2023 09:37:33 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:23 -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-25-surenb@google.com> Subject: [PATCH v4 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, 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-Rspamd-Queue-Id: F3D0210000C X-Rspam-User: X-Stat-Signature: 7jijtff69ezux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TlLXNPbq8yo9VsmAH481QoL0hliZMMDt/jXXsP6FJ73W7sj8IcHZerongxVvpOdYxEsTbtzU0h14fVjaagn5N14C4hAnKJDwNtXw9Hf2jDVk9keDzy1AJ1pHP2nzKkpYGXDqYo85TzfG1/ekYDzBk0Igw3ZG6LCLZsKXpBuhHUt5slBxetDtpFxGjLg77dlVzYG5bKM4+R0EdXDH3+78uacPxA8TARW+XYgMNcQF4q5/B0es1e5eFNk+w7+kr3s+cEf4wjPPT8tEoY0X08GMDyQDq0rYZTuy5R9oR5zFOTCTfM4uJOD/Sc41saq2S7p/D4qI2WeMB7ugs2q/n6gnzFhRuRKVsWXHp0NHDcWvL1LqkTymSxIK1ini2+TcvLHLS43mHAt3nWRAkIrsp8lDm7TaTOr2ULhs2EI89eVcpO3vO7cQ9NuWVICBWAlOrLFB89oNHlEJS2ctx5Cnfs1S3dPBZitUhZnNc+Qt0aStFgTsM3xIZ7qaGDLy7nloe74XFkywKjZGgi11aSlOA9gljaE75VLZdd0xMr8Ci8HrsdZ5DV4ZuNLPO2683bPyEEq8tFA+Ot5Dkv3zyeUWSbYyZHQX2YQfuAcxqMDAyNlK8i18CrV3ls= 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 Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bda4c1a991f0..8855846a361b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5243,6 +5243,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;