Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3653730rdh; Thu, 28 Sep 2023 20:16:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBWE3FYokhJ7Y3m0rGD1Bky4l4m2M+K8/NogIWlUkHLwXrnI6LOJ/WhlWLtx/AeFqJ/TuS X-Received: by 2002:a05:6358:885:b0:143:7d73:6e66 with SMTP id m5-20020a056358088500b001437d736e66mr3395631rwj.1.1695957418625; Thu, 28 Sep 2023 20:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695957418; cv=none; d=google.com; s=arc-20160816; b=hFegkyMC8AXD+nqAHeWFFbcGiAMbtim8nJSbwZeGbGUrKgP5uX89YsGDASqb/ukcLv xLqMFXzaLWE/BG45fXvsEqjZObWUqQa30pRBHzcAgFWiU02KUFrL3SYC59MW6mHbcFMc ub/3pqdnS7B8uyhp1zV+JRUiKkbzUfEU2ZAx9PZiH2LYhfRkf1yCnUu+mZH7tNSV9jvE G1/oCfvK56X0fuy0wSAVwceOdowddOa6cODA0jduV5kXJI730cKXAyO9sbzFQGxpPr9t g00WsyZd97rOEQr/11HxNFXcxXMwzkrG8iWUqnxPgWl9iOsl+8lLtXAWpcu02nX7r6jY qU/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xsHLGxGeDn14ekxmLTtpNWlyKujIB9kYU0PV2IMFY58=; fh=4OSpxeiBwsuIzSsgUf+PjxsJgx9x8GY3HkIgnmcCqx8=; b=06YwRCqGcVgCK2njVLlu4KUwdat26SQLHsk6EkS38jEx+dfEdZaswHiKxHA34YMVBl 2UAdMgjk5tKh/g96deA9zzRtiwQF+sCUMiE/We5uCcBCPTFgp10xjvhk8GkTK8YRNlzz ONDaigyqt6cmHFvEAmrq9Rcs1pGfg0JxTgLcHgG0P8OU0eWtU166nZGngEOdeMEfYHtS aZwJLH5hiy3e2/xYkDA3grDHiaslC6i0R6SeqN8Wn0uFJ5rgWOVUuuNAM2u6Cr3KFGgq Q5TDnqjTB+3NnnorWrF6gyZ9wdsFvBiSAFj7FljHgc4PAgf0kheNvNUDWPPXBIYAOjzg 2j1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vf6iMiuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id n10-20020a17090a9f0a00b0027756e1f0c2si641221pjp.7.2023.09.28.20.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:16:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vf6iMiuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 66752837433E; Thu, 28 Sep 2023 13:04:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbjI1UD5 (ORCPT + 99 others); Thu, 28 Sep 2023 16:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbjI1UD4 (ORCPT ); Thu, 28 Sep 2023 16:03:56 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31729193 for ; Thu, 28 Sep 2023 13:03:54 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5a1d0fee86aso95028497b3.2 for ; Thu, 28 Sep 2023 13:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695931433; x=1696536233; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xsHLGxGeDn14ekxmLTtpNWlyKujIB9kYU0PV2IMFY58=; b=vf6iMiuE+fHZpEy28IjSRzP/TfvLZVhU7z3LQIjZuNsmbbmlUaJvrTk2vIN14ySUT5 gC8skrwWSoEp7oVaMXQbYrxNkpUkwfzkVK9o2OB9Mirr0IuuQ9lXMcVuCv75x2DYlk23 MTKQywDHjRdWN6XBA1AHq2NnfLD1mBMeOuAEXWXrPO0W5CyU7RF7bq+Ll2lfOnXVIoC8 CuaC7j5RdQ0dZgdqOQIvUZ5Bbu24OZkXWgp5lnZpQ2eg76nhEh3ECrqYtt14n1KlnLqF rRW3Illf8V2VQBVCkllQ/071P50WUnoc9v4KyQbptSe6ai/7S2lvyMkx+YMkGwmlmkAg 6MKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695931433; x=1696536233; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xsHLGxGeDn14ekxmLTtpNWlyKujIB9kYU0PV2IMFY58=; b=LVafY6iciHPfncPoyg3zQPRWEjKRhTSHF2h6ukgNCB5+LohH6gqOsZ5a/IaA05S6ZS 42TLug6pDH24XyTjUqh8rjw8hBjxs/PlAHSgAo/ZBj9vh1a88wCHdX66oNXGLUlArVEE bmqWOgWjTtzmG6x6ZXj0RU7xWk7vKkvi9DO+rFC0qgvWTJNcmzl9klyJ3jmV3sbT16PS jL6Jlj0yfWbynC9Uba2ILBh051c2A2VOk3qcNiZH6eXyTpRBIDohpalPqZCRJqEl/Uqv swuUIR5KFV2Ja1wDe5NPdqWgdg1I1Zz948vuRVFJwVz+ss7MYKO1iKa1UKA/T6sGFZ6c gpSQ== X-Gm-Message-State: AOJu0YwyASDsp5NLupK9aMZ9uVDTXPo6INY/jpsa1c6YtTzoVKB8eoRW JKPVn1UXAZ3ttZI98fZaRdWEBgJTh2tdLj/8ojBY3g== X-Received: by 2002:a81:49c8:0:b0:59f:8026:4260 with SMTP id w191-20020a8149c8000000b0059f80264260mr2399284ywa.24.1695931433221; Thu, 28 Sep 2023 13:03:53 -0700 (PDT) MIME-Version: 1.0 References: <20230923013148.1390521-1-surenb@google.com> <20230923013148.1390521-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 28 Sep 2023 13:03:42 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] userfaultfd: UFFDIO_REMAP: rmap preparation To: Peter Xu Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, lokeshgidra@google.com, david@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 28 Sep 2023 13:04:13 -0700 (PDT) On Thu, Sep 28, 2023 at 9:23=E2=80=AFAM Peter Xu wrote: > > Suren, > > Sorry to review so late. > > On Fri, Sep 22, 2023 at 06:31:44PM -0700, Suren Baghdasaryan wrote: > > diff --git a/mm/rmap.c b/mm/rmap.c > > index ec7f8e6c9e48..c1ebbd23fa61 100644 > > --- a/mm/rmap.c > > +++ b/mm/rmap.c > > @@ -542,6 +542,7 @@ struct anon_vma *folio_lock_anon_vma_read(struct fo= lio *folio, > > struct anon_vma *root_anon_vma; > > unsigned long anon_mapping; > > > > +repeat: > > rcu_read_lock(); > > anon_mapping =3D (unsigned long)READ_ONCE(folio->mapping); > > if ((anon_mapping & PAGE_MAPPING_FLAGS) !=3D PAGE_MAPPING_ANON) > > @@ -586,6 +587,18 @@ struct anon_vma *folio_lock_anon_vma_read(struct f= olio *folio, > > rcu_read_unlock(); > > anon_vma_lock_read(anon_vma); > > > > + /* > > + * Check if UFFDIO_REMAP changed the anon_vma. This is needed > > + * because we don't assume the folio was locked. > > + */ > > + if (unlikely((unsigned long) READ_ONCE(folio->mapping) !=3D > > + anon_mapping)) { > > + anon_vma_unlock_read(anon_vma); > > + put_anon_vma(anon_vma); > > + anon_vma =3D NULL; > > + goto repeat; > > + } > > We have an open-coded fast path above this: > > if (down_read_trylock(&root_anon_vma->rwsem)) { > /* > * If the folio is still mapped, then this anon_vma is st= ill > * its anon_vma, and holding the mutex ensures that it wi= ll > * not go away, see anon_vma_free(). > */ > if (!folio_mapped(folio)) { > up_read(&root_anon_vma->rwsem); > anon_vma =3D NULL; > } > goto out; > } > > Would that also need such check? Yes, I think they should be handled the same way. Will fix. Thanks! > > > + > > if (atomic_dec_and_test(&anon_vma->refcount)) { > > /* > > * Oops, we held the last refcount, release the lock > > -- > > 2.42.0.515.g380fc7ccd1-goog > > > > -- > Peter Xu >