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=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 ECBADC10DCE for ; Fri, 13 Mar 2020 19:55:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A52F4206E2 for ; Fri, 13 Mar 2020 19:55:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="IaI1o/nb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A52F4206E2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 56D786B0007; Fri, 13 Mar 2020 15:55:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F7766B000A; Fri, 13 Mar 2020 15:55:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E7246B000C; Fri, 13 Mar 2020 15:55:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 263D16B0007 for ; Fri, 13 Mar 2020 15:55:53 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C41814DCD for ; Fri, 13 Mar 2020 19:55:52 +0000 (UTC) X-FDA: 76591394544.18.humor89_334b8135db413 X-HE-Tag: humor89_334b8135db413 X-Filterd-Recvd-Size: 6600 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Mar 2020 19:55:52 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id f28so14680625qkk.13 for ; Fri, 13 Mar 2020 12:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=87KqPlDMHgw97GV/6GeuCjBWLsGckmaqH6kpwHETsV8=; b=IaI1o/nbI8tdis4U2kskwqLiVp3tR4CtvbFz8sA47teWHxd/T5+6rm/6ewRIdNlMNG 0qFcrsbYYRy46EZiPu9dOqWn8g1MSPdUt//XwpJkDstfCSFBcR9s8GzeyhpVhLMYMyqH e4J1IH2AgHUzFxDhv7qBaZ4eRP7VcZETgHSXyB/aFNpU28/xvYi6117lRd4gGfXTSfYo s5QHfQoIftvXr7dFPX5eXiIDE8mmykF2AKp9287JbXYoL88FgrIID9xBRWJWL181yTTJ iqrEkJUsIYkdTXlCVOM5TzemwgbQPUTBbIrd2sufHfgiJFUvSVxFfZTE2Tjfhkqr3HOs RR8w== 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=87KqPlDMHgw97GV/6GeuCjBWLsGckmaqH6kpwHETsV8=; b=S4b4Tb9YC3JGppjHd7WZRs5NQTq4wZnV8oyKFVlAlNOQCKVoBDzC/tPvmOzmk2p6it Ez1I51YZJn0UO4KavPmIUC32UHVH/7TExJNp9Io7tXPhKIdF2Ndga9nB4fF92Y/mGw9C kL6X+t8HSHuNq3QXQgTU22GP+2NXiC7AiyIbC1RBDOmfo0T7ehzPKkcU9ZJoZ7yFbKq9 N9Anxm2M7S3GFN/+pU4CIqPCz59SOGaU0cMSEsN7JG1LOTyZa3sHHlfjQtMGq0ztR+GV sdS/dOnWL+nbPxn4Q7hVlFZjdY8s0/OtTEEoCEHyZ7M2l8f/Iw+ChaxScjLB+Tjwpo9O vcmA== X-Gm-Message-State: ANhLgQ0E3GjzDNGSkbOnHVduvzgfjOupzAr+dw4AxoJOel2HgRRSmMRo nDZnK4UsPoY6BJPQq4jz2pxAKQ== X-Google-Smtp-Source: ADFU+vszdQfTs7KFiVac4pruumYRzYTRQbmBVhPe56+YVviAN87wfdAZizQ3CSLbD8AmBkwABUoNLA== X-Received: by 2002:a37:591:: with SMTP id 139mr12437176qkf.281.1584129351908; Fri, 13 Mar 2020 12:55:51 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id m92sm4067512qtd.94.2020.03.13.12.55.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Mar 2020 12:55:51 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jCqPO-0004gC-St; Fri, 13 Mar 2020 16:55:50 -0300 Date: Fri, 13 Mar 2020 16:55:50 -0300 From: Jason Gunthorpe To: Steven Price , Matthew Wilcox Cc: Jerome Glisse , Ralph Campbell , "Felix.Kuehling@amd.com" , Philip Yang , John Hubbard , "amd-gfx@lists.freedesktop.org" , "linux-mm@kvack.org" , "dri-devel@lists.freedesktop.org" , Christoph Hellwig Subject: Re: [PATCH] mm/hmm: Simplify hmm_vma_walk_pud slightly Message-ID: <20200313195550.GH31668@ziepe.ca> References: <5bd778fa-51e5-3e0c-d9bb-b38539b03c8d@arm.com> <20200312102813.56699-1-steven.price@arm.com> <20200312142749.GM31668@ziepe.ca> <58e296a6-d32b-bb37-28ce-ade0f784454d@arm.com> <20200312151113.GO31668@ziepe.ca> <689d3c56-3d19-4655-21f5-f9aeab3089df@arm.com> <20200312163734.GR31668@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) 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 Thu, Mar 12, 2020 at 05:02:18PM +0000, Steven Price wrote: > On 12/03/2020 16:37, Jason Gunthorpe wrote: > > On Thu, Mar 12, 2020 at 04:16:33PM +0000, Steven Price wrote: > > > > Actually, while you are looking at this, do you think we should be > > > > adding at least READ_ONCE in the pagewalk.c walk_* functions? The > > > > multiple references of pmd, pud, etc without locking seems sketchy to > > > > me. > > > > > > I agree it seems worrying. I'm not entirely sure whether the holding of > > > mmap_sem is sufficient, > > > > I looked at this question, and at least for PMD, mmap_sem is not > > sufficient. I didn't easilly figure it out for the other ones > > > > I'm guessing if PMD is not safe then none of them are. > > > > > this isn't something that I changed so I've just > > > been hoping that it's sufficient since it seems to have been working > > > (whether that's by chance because the compiler didn't generate multiple > > > reads I've no idea). For walking the kernel's page tables the lack of > > > READ_ONCE is also not great, but at least for PTDUMP we don't care too much > > > about accuracy and it should be crash proof because there's no RCU grace > > > period. And again the code I was replacing didn't have any special > > > protection. > > > > > > I can't see any harm in updating the code to include READ_ONCE and I'm happy > > > to review a patch. > > > > The reason I ask is because hmm's walkers often have this pattern > > where they get the pointer and then de-ref it (again) then > > immediately have to recheck the 'again' conditions of the walker > > itself because the re-read may have given a different value. > > > > Having the walker deref the pointer and pass the value it into the ops > > for use rather than repeatedly de-refing an unlocked value seems like > > a much safer design to me. > > Yeah that sounds like a good idea. I'm looking at this now.. The PUD is also changing under the read mmap_sem - and I was able to think up some race conditiony bugs related to this. Have some patches now.. However, I haven't been able to understand why walk_page_range() doesn't check pud_present() or pmd_present() before calling pmd_offset_map() or pte_offset_map(). As far as I can see a non-present entry has a swap entry encoded in it, and thus it seems like it is a bad idea to pass a non-present entry to the two map functions. I think those should only be called when the entry points to the next level in the page table (so there is something to map?) I see you added !present tests for the !vma case, but why only there? Is this a bug? Do you know how it works? Is it something that was missed when people added non-present PUD and PMD's? Thanks, Jason