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.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 444D2C4CECF for ; Mon, 23 Sep 2019 18:14:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0861E20B7C for ; Mon, 23 Sep 2019 18:14:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="IesrxwT3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0861E20B7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 530286B0005; Mon, 23 Sep 2019 14:14:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 506C56B0007; Mon, 23 Sep 2019 14:14:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41D406B000A; Mon, 23 Sep 2019 14:14:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0068.hostedemail.com [216.40.44.68]) by kanga.kvack.org (Postfix) with ESMTP id 231F96B0005 for ; Mon, 23 Sep 2019 14:14:45 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id BD783181AC9C4 for ; Mon, 23 Sep 2019 18:14:44 +0000 (UTC) X-FDA: 75966986088.28.bulb24_4626f1740c93c X-HE-Tag: bulb24_4626f1740c93c X-Filterd-Recvd-Size: 6142 Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Sep 2019 18:14:41 +0000 (UTC) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 23 Sep 2019 11:14:46 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Mon, 23 Sep 2019 11:14:40 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Mon, 23 Sep 2019 11:14:40 -0700 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 23 Sep 2019 18:14:40 +0000 Received: from [10.110.48.28] (10.124.1.5) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 23 Sep 2019 18:14:39 +0000 Subject: Re: [PATCH v2 11/11] powerpc/mm/book3s64/pgtable: Uses counting method to skip serializing To: Leonardo Bras , , , Linux-MM CC: Jason Gunthorpe , Thomas Gleixner , "Arnd Bergmann" , Greg Kroah-Hartman , YueHaibing , Keith Busch , Nicholas Piggin , Mike Rapoport , Mahesh Salgaonkar , Richard Fontana , Paul Mackerras , Aneesh Kumar K.V , Ganesh Goudar , "Andrew Morton" , Ira Weiny , "Dan Williams" , Allison Randal References: <20190920195047.7703-1-leonardo@linux.ibm.com> <20190920195047.7703-12-leonardo@linux.ibm.com> <1b39eaa7-751d-40bc-d3d7-41aaa15be42a@nvidia.com> <24863d8904c6e05e5dd48cab57db4274675ae654.camel@linux.ibm.com> <4ea26ffb-ad03-bdff-7893-95332b22a5fd@nvidia.com> <18c5c378db98f223a0663034baa9fd6ce42f1ec7.camel@linux.ibm.com> X-Nvconfidentiality: public From: John Hubbard Message-ID: <8706a1f1-0c5e-d152-938b-f355b9a5aaa8@nvidia.com> Date: Mon, 23 Sep 2019 11:14:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <18c5c378db98f223a0663034baa9fd6ce42f1ec7.camel@linux.ibm.com> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To DRHQMAIL107.nvidia.com (10.27.9.16) Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1569262486; bh=hnHJJMFTAN0ei1gfv4FOxNz23ndZovcqznoxnEUvfuo=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=IesrxwT3lbKGbizW9P/9OxMi6bqhj+vZPtbe2evKesnrO1epatJQlhp5bQSpiigja wgbfAItGgBMC1lvKl+XE14e6eourA6MaNrLrhnPJO1QgBaVx2P0Ua60MRbnZ/LYN46 ts0umeTp7pxvn0/kA91s/idMaD3AT8P0rS/Juvx1cqaoV+xKr9BMdbb0BFzl5vl6d5 0Cr9oN5vDMTofAVwjHVTzaonfPZxehNoZ+99lvXMZBXqW+9zL6a27McjDZPk/Ljt2t y7z7/0vH8icTOCTJ6YwMhGy/FKoFBKd9sfSYUfNJRf/fURrmc78gyofDqNMIpD49es mNvei2JV5tprQ== 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 9/23/19 10:25 AM, Leonardo Bras wrote: > On Fri, 2019-09-20 at 17:48 -0700, John Hubbard wrote: >> > [...] >> So it seems that full memory barriers (not just compiler barriers) are required. >> If the irq enable/disable somehow provides that, then your new code just goes >> along for the ride and Just Works. (You don't have any memory barriers in >> start_lockless_pgtbl_walk() / end_lockless_pgtbl_walk(), just the compiler >> barriers provided by the atomic inc/dec.) >> >> So it's really a pre-existing question about the correctness of the gup_fast() >> irq disabling approach. > > I am not experienced in other archs, and I am still pretty new to > Power, but by what I could understand, this behavior is better > explained in serialize_against_pte_lookup. > > What happens here is that, before doing a THP split/collapse, the > function does a update of the pmd and a serialize_against_pte_lookup, > in order do avoid a invalid output on a lockless pagetable walk. > > Serialize basically runs a do_nothing in every cpu related to the > process, and wait for it to return. > > This running depends on interrupt being enabled, so disabling it before > gup_pgd_range() and re-enabling after the end, makes the THP > split/collapse wait for gup_pgd_range() completion in every cpu before > continuing. (here happens the lock) > That part is all fine, but there are no run-time memory barriers in the atomic_inc() and atomic_dec() additions, which means that this is not safe, because memory operations on CPU 1 can be reordered. It's safe as shown *if* there are memory barriers to keep the order as shown: CPU 0 CPU 1 ------ -------------- atomic_inc(val) (no run-time memory barrier!) pmd_clear(pte) if (val) run_on_all_cpus(): IPI local_irq_disable() (also not a mem barrier) READ(pte) if(pte) walk page tables local_irq_enable() (still not a barrier) atomic_dec(val) free(pte) thanks, -- John Hubbard NVIDIA > (As told before, every gup_pgd_range() that occurs after it uses a > updated pmd, so no problem.) > > I am sure other archs may have a similar mechanism using > local_irq_{disable,enable}. > > Did it answer your questions? > > Best regards, > > Leonardo Bras >