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=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 29758C432C2 for ; Wed, 25 Sep 2019 12:17:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC61620640 for ; Wed, 25 Sep 2019 12:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="xjVonQsz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC61620640 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7B7556B026E; Wed, 25 Sep 2019 08:17:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 766DB6B0272; Wed, 25 Sep 2019 08:17:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67DFF6B0274; Wed, 25 Sep 2019 08:17:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 47ADB6B026E for ; Wed, 25 Sep 2019 08:17:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 95E6E824CA30 for ; Wed, 25 Sep 2019 12:17:51 +0000 (UTC) X-FDA: 75973344342.08.form35_7ebc538e4a74d X-HE-Tag: form35_7ebc538e4a74d X-Filterd-Recvd-Size: 5755 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Sep 2019 12:17:50 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id b24so4660357wmj.5 for ; Wed, 25 Sep 2019 05:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DqFYHh7P1zkKGNcj3JI+kOGE1cX5L+ByeTo5y44rHeo=; b=xjVonQsz/4QZ8/Lk18W0rcjnghr3JMgUBDvgQR3p6G0dTYAXKe8Q2JZEpVM7gWL6/8 lrp0RDCjIrsPL6F89T9yVdt+JkllEBD3Qty7ewmyojUO95yw+vVlooLLIhtqL6a2GGas IHliVfvBF1RV7LSVLdT0PaivVi67xgMc9m7lb7aP2VuPJQvfeWjjYGl4BsKXutpwMo+b bBXCEYIxViYCNhuWC9Riij8Q0c5x/JjTKhK9pZcZivSUf5D+6N52viccNNZFAR+WVcBe vBXDMVwVgylG4jPDkoyMyPm9PN3sLAlhb4aR2XbRSJGEdQUHrppH5I7OhGVv7186ybuV EIxg== 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=DqFYHh7P1zkKGNcj3JI+kOGE1cX5L+ByeTo5y44rHeo=; b=b5geXkwaI4SoF/a+uq1DXiOJD1jKjiHibqsTzoGiM5SlbZ72OaS1os5hkfVov7i1NR iv9grvarReY6vPAWLD+vwc0f56x1DnctTtRHdRd/1rhOJQsPA/TcQkgzJy2LIG8zJrUq 2Yc2pka1T/27pxZGrXoL2GY2ikGfs8R+DEnB9NpNDO7dRAH635Ndwk6vEtw3iWsgRzBg hf3iLYMbmWOXJDrwwiD7kUfmfzaFtjBMTHoCxDnF+ZpQgJ2rXvbgGHEDzM6nULnNXU9/ 8A2jp1kw+6JPG76elYGdr1eXkn+iopAMkf0GB1VNDudnAFwMLdRrX5Nz+4qOni7yFdb4 hcFQ== X-Gm-Message-State: APjAAAWY9x8Ylq7SWSZmPa+szqmdsijzySaL7CrR4IFxLYndgsWTlPhX I0Xhj1tdDM+J1QCFh4fFLFYaRQ== X-Google-Smtp-Source: APXvYqzItaZV+20Vaqxd+notYcQrDLZwBviGcDdP/Otb4i1YIx3iH1LXhQMg01OGijHUOFb2O/YtIg== X-Received: by 2002:a05:600c:389:: with SMTP id w9mr7210774wmd.139.1569413869649; Wed, 25 Sep 2019 05:17:49 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id bo6sm514411ejb.30.2019.09.25.05.17.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Sep 2019 05:17:48 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id B835B1022AB; Wed, 25 Sep 2019 15:17:50 +0300 (+03) Date: Wed, 25 Sep 2019 15:17:50 +0300 From: "Kirill A. Shutemov" To: Yu Zhao 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 , =?utf-8?B?SsOpcsO0bWU=?= 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: <20190925121750.zxrt2zkc4g73h6cp@box> References: <20190514230751.GA70050@google.com> <20190914070518.112954-1-yuzhao@google.com> <20190924112316.324l7gqpdzhpiliq@box> <20190924220550.GA123810@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190924220550.GA123810@google.com> User-Agent: NeoMutt/20180716 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 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? -- Kirill A. Shutemov