From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.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_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC1F3C4360D for ; Thu, 26 Sep 2019 03:58:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 419B9222BE for ; Thu, 26 Sep 2019 03:58:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bQOIJ9+v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 419B9222BE Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C4F66B0006; Wed, 25 Sep 2019 23:58:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 875C36B0008; Wed, 25 Sep 2019 23:58:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 765D46B000A; Wed, 25 Sep 2019 23:58:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 55DF66B0006 for ; Wed, 25 Sep 2019 23:58:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id E8B3F8790 for ; Thu, 26 Sep 2019 03:58:52 +0000 (UTC) X-FDA: 75975715704.10.waste52_3061c9c6dc61a X-HE-Tag: waste52_3061c9c6dc61a X-Filterd-Recvd-Size: 6311 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 03:58:52 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id z19so2899011ior.0 for ; Wed, 25 Sep 2019 20:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=za27vP7fGm8+9PT7f7IK3Uqx3fTObgHXvmu/wu/VnKE=; b=bQOIJ9+vstWnZjmXdBcwCGCSRzuy7zvFQTAPM566qtEfDGKnPCRhVMGN4ogtSaMOYV XPgKrngFrGhArdMrEi4JEYFHBD1wx6WFwIrSvnQd4geTHIqD8F9+YwCz+CxP9vG2Tk9d rwhpU+VLuk4Ar6Fe+Enaxf9ZmumDvXtw21O99e8HFZFax/2Li8RxNPqu1aS8e91yVagw YAg5DzWMLYoEtoYC7G5BhpytddOzrX45SdFs+NFz6ZCNu/rOfdeMmDiwjKebU0T0lZys 69mQJgNSz3icCde/nVlcDeyQE1Yzio40/M4A8yNSnEwj5lk+gUSIc87nTB5OOmKJ9rqh JudA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=za27vP7fGm8+9PT7f7IK3Uqx3fTObgHXvmu/wu/VnKE=; b=NaaaNNeEGdGFzb0/BLJcxnRp3FDJkxJgiF9u0ayjDeKUsnK15hrcWVuDahI7xt/khg 6eek71N3ZFfxRrYPm3tNVuXcyXDHCQXjkKlY8PIT2mNcSv8qskDaAPuy6YwfnTw8z7SI /fYcUkljHNYk9o9/eBrjvofRp0gKD5CtuAf910+HjnjO+RK7v0MUHuELIBCDUP4yQSRt JRYmZ50yPx8/EBOFxLGwZ94EZCrmm8Kx4H85/xaZbCrujEdk33RISqqctQPokWjKS+uC ATPBdJ0kfQCbujDlqX+5/gSliUgp6GTmSRf2sbQN3lzxgJdiaHF2gR2cU6/hFyo6s+2j ColA== X-Gm-Message-State: APjAAAWXmg47U9xGP/ftAH6OqfjbL4usjOwFZ2CY9/vIo/Nomt14s8LO /zIYqHpi9IpAvheuHiS91LIZPA== X-Google-Smtp-Source: APXvYqzbjuY36NAHvnwG6gani3YnYtPbtOfFr+IIEKelTfYxnI9Yz/t8H6n0kADFfx/fiL9VkUgoKQ== X-Received: by 2002:a5d:9a86:: with SMTP id c6mr1596276iom.118.1569470331139; Wed, 25 Sep 2019 20:58:51 -0700 (PDT) Received: from google.com ([2620:15c:183:0:9f3b:444a:4649:ca05]) by smtp.gmail.com with ESMTPSA id z10sm455431iog.41.2019.09.25.20.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2019 20:58:50 -0700 (PDT) Date: Wed, 25 Sep 2019 21:58:44 -0600 From: Yu Zhao To: "Kirill A. Shutemov" Cc: Andrew Morton , Michal Hocko , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "Kirill A . Shutemov" , Vlastimil Babka , Hugh Dickins , =?iso-8859-1?B?Suly9G1l?= Glisse , Andrea Arcangeli , "Aneesh Kumar K . V" , David Rientjes , Matthew Wilcox , Lance Roy , Ralph Campbell , Jason Gunthorpe , Dave Airlie , Thomas Hellstrom , Souptick Joarder , Mel Gorman , Jan Kara , Mike Kravetz , Huang Ying , Aaron Lu , Omar Sandoval , Thomas Gleixner , Vineeth Remanan Pillai , Daniel Jordan , Mike Rapoport , Joel Fernandes , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm: don't expose page to fast gup prematurely Message-ID: <20190926035844.GA89510@google.com> References: <20190514230751.GA70050@google.com> <20190914070518.112954-1-yuzhao@google.com> <20190924112316.324l7gqpdzhpiliq@box> <20190924220550.GA123810@google.com> <20190925121750.zxrt2zkc4g73h6cp@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190925121750.zxrt2zkc4g73h6cp@box> User-Agent: Mutt/1.10.1 (2018-07-13) 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: On Wed, Sep 25, 2019 at 03:17:50PM +0300, Kirill A. Shutemov wrote: > On Tue, Sep 24, 2019 at 04:05:50PM -0600, Yu Zhao wrote: > > On Tue, Sep 24, 2019 at 02:23:16PM +0300, Kirill A. Shutemov wrote: > > > On Sat, Sep 14, 2019 at 01:05:18AM -0600, Yu Zhao wrote: > > > > We don't want to expose page to fast gup running on a remote CPU > > > > before all local non-atomic ops on page flags are visible first. > > > > > > > > For anon page that isn't in swap cache, we need to make sure all > > > > prior non-atomic ops, especially __SetPageSwapBacked() in > > > > page_add_new_anon_rmap(), are order before set_pte_at() to prevent > > > > the following race: > > > > > > > > CPU 1 CPU1 > > > > set_pte_at() get_user_pages_fast() > > > > page_add_new_anon_rmap() gup_pte_range() > > > > __SetPageSwapBacked() SetPageReferenced() > > > > > > Is there a particular codepath that has what you listed for CPU? > > > After quick look, I only saw that we page_add_new_anon_rmap() called > > > before set_pte_at(). > > > > I think so. One in do_swap_page() and another in unuse_pte(). Both > > are on KSM paths. Am I referencing a stale copy of the source? > > I *think* it is a bug. Setting a pte before adding the page to rmap may > lead to rmap (like try_to_unmap() or something) to miss the VMA. > > Do I miss something? We have the pages locked in those two places, so for try_to_unmap() and the rest of page_vma_mapped_walk() users, they will block on the page lock: CPU 1 CPU 2 lock_page() set_pte_at() unlock_page() lock_page() try_to_unmap() page_vma_mapped_walk() pte_present() without holding ptl unlock_page() For others that don't use page_vma_mapped_walk(), they should either lock pages or grab ptl before checking pte_present(). AFAIK, the fast gup is the only one doesn't fall into the either category.