Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1177939pxk; Thu, 10 Sep 2020 08:52:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBJeJOigVByXqRDdsFVcgKkfmdLa6h26nhiiGePQrl3lal/EtaVq6fI9SMIp5qb3jSecF+ X-Received: by 2002:a17:906:1b:: with SMTP id 27mr9290380eja.169.1599753156738; Thu, 10 Sep 2020 08:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599753156; cv=none; d=google.com; s=arc-20160816; b=DZ35a7mOnHzqxlwmWBn3H6awHzaV3nQbF+jSyQCOrDHQAfwZ+xBWEo3ziecqXvGice jNXskat20U9VTAcJqPv5CwvXm1iOACcPhwHHiQbhz6HuvLdKLyjKloaE4VtPh7HSkMgj bSMx0haCAPhXI265xau9iqFqRPqFyh3DpU28xeA8Z8hc0XkNz6H3B4qCOpcQfvHdm7pR t9AUNuD9yC4Cnu8E1dT9K74ZhKp5Ac6ekc49/Fz956SFgwnUHh3QtWdyY8zVAdYXmg7i 4tVqq6o8hg0Ym15G88cuSOtgqTWqEEWqy2QRrNtY+j6rurhPbaITHyHOETRMeqY5XYBQ GCXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=IGv0f01H1HhwMLTOhjZhfHu2g8LxVsJgV1pDEfYUgDw=; b=d3UMVh+LhMubV0ch5PDmUSLwVg1jOI4mPEmRp4w+PKV4Y7/74oVUj7ITvsTLLSsZYm uG72lCHs8kfBG+FZMigdphzpkG0Bq5H45mo0xqn/wAybJlUfnIMJNDuPSKE2WjBofGkn 71eFwHHk/dU1qCIbWnDJinzC60GpynszQmROMj2VuV9c9nsIBnTK7ldPa+TLLpt0xe4p dBsjktAunjZCGChof2wbVGeZiAtyZk0XCVuvLDfds5Dt0kAwLMEzA5bvnBuZQuiBCUWU ZIiktbNCrgnK0LwJsN2LMKWGXr97asaYlloF2lca5fxBQxuK5T40DwPlciSjto4Vx0Ox oItg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=OLk8h2bg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kt6si3827181ejb.276.2020.09.10.08.52.13; Thu, 10 Sep 2020 08:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=OLk8h2bg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730940AbgIJPtu (ORCPT + 99 others); Thu, 10 Sep 2020 11:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731408AbgIJPsO (ORCPT ); Thu, 10 Sep 2020 11:48:14 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9313FC06135D for ; Thu, 10 Sep 2020 08:10:29 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id w186so6411987qkd.1 for ; Thu, 10 Sep 2020 08:10:29 -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; bh=IGv0f01H1HhwMLTOhjZhfHu2g8LxVsJgV1pDEfYUgDw=; b=OLk8h2bgkMx23a6lKAISLlfAQbxOdT1UvNWDM9Zk6DHatbSGVbAHhfj7/QkR54l1rm 7d91OLwa5I5BFDa46HUCe2u5YIKKF7iZkfQGVUZwXBkVLOtQU1rMTEuS2YOP/A4N28Nh OaR3h6vYn2g6YHgjvbU6b6KqfQkKa4ZNKWFkzx5yRTFbAouWKSLG0Y+HJuXypLnRDO1C /p+eopFDX9lOqXJ5iyilR1G0IS0msV2EgzUi/8XlGm0UwB0i+O4JYL5JY9QXWMDvYWiy JaCFeMCQ8DYNgBrrdkRhDwMsvdOgF8w7kYFilEVYxP/+fBz702MoGQCz4e65/5fZS+Qk h+2Q== 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; bh=IGv0f01H1HhwMLTOhjZhfHu2g8LxVsJgV1pDEfYUgDw=; b=WLwmLB5ileSbqsZG5mTv/fjcYXa+bIG75sXkbB9Ry3yyIctankgZZL8RY5FM3gJuyu 2dCd1CnaTe82Xug1Wv0JvSaENFrQnPWcp2hVicAYj6IFbqXYb10z7cbj+U14lYqBKPq+ ImqS4KXuz3hDdzFbk2CVdHyRoKMofDpsKzcQ0tnaHA2Q2wjXFHs8b0dZv+zgShzyJacv 8pj9iTFrAbLXQ9Ley6y+GM8UYdvGNYUwXi6KA6oV/c8Anyckg5BEOfjLA6FJ9fBv+3Nt hBtixvtvETdnfGwytlCsGivckRlkAprUhmOEC3siNCOy7wwHQykuQd2749cjvxziz/CO A8gQ== X-Gm-Message-State: AOAM533z+xEcy+YF3PN3B9j7hJGSiMS2YqPSh2AlOrrbfEnn/ZiPRxRX ZN5C68KQ2y+aO9e35oh+CHh7nA== X-Received: by 2002:a05:620a:141a:: with SMTP id d26mr7906055qkj.97.1599750628651; Thu, 10 Sep 2020 08:10:28 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id z74sm6914588qkb.11.2020.09.10.08.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 08:10:27 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kGODS-004MNk-Mg; Thu, 10 Sep 2020 12:10:26 -0300 Date: Thu, 10 Sep 2020 12:10:26 -0300 From: Jason Gunthorpe To: Gerald Schaefer , Anshuman Khandual Cc: Alexander Gordeev , Dave Hansen , John Hubbard , LKML , linux-mm , linux-arch , Andrew Morton , Linus Torvalds , Russell King , Mike Rapoport , Catalin Marinas , Will Deacon , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jeff Dike , Richard Weinberger , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Arnd Bergmann , Andrey Ryabinin , linux-x86 , linux-arm , linux-power , linux-sparc , linux-um , linux-s390 , Vasily Gorbik , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda Subject: Re: [RFC PATCH v2 1/3] mm/gup: fix gup_fast with dynamic page table folding Message-ID: <20200910151026.GL87483@ziepe.ca> References: <20200907180058.64880-1-gerald.schaefer@linux.ibm.com> <20200907180058.64880-2-gerald.schaefer@linux.ibm.com> <0dbc6ec8-45ea-0853-4856-2bc1e661a5a5@intel.com> <20200909142904.00b72921@thinkpad> <20200909192534.442f8984@thinkpad> <20200909180324.GI87483@ziepe.ca> <20200910093925.GB29166@oc3871087118.ibm.com> <20200910130233.GK87483@ziepe.ca> <20200910152803.1a930afc@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200910152803.1a930afc@thinkpad> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 10, 2020 at 03:28:03PM +0200, Gerald Schaefer wrote: > On Thu, 10 Sep 2020 10:02:33 -0300 > Jason Gunthorpe wrote: > > > On Thu, Sep 10, 2020 at 11:39:25AM +0200, Alexander Gordeev wrote: > > > > > As Gerald mentioned, it is very difficult to explain in a clear way. > > > Hopefully, one could make sense ot of it. > > > > I would say the page table API requires this invariant: > > > > pud = pud_offset(p4d, addr); > > do { > > WARN_ON(pud != pud_offset(p4d, addr); > > next = pud_addr_end(addr, end); > > } while (pud++, addr = next, addr != end); > > > > ie pud++ is supposed to be a shortcut for > > pud_offset(p4d, next) > > > > While S390 does not follow this. Fixing addr_end brings it into > > alignment by preventing pud++ from happening. > > > > The only currently known side effect is that gup_fast crashes, but it > > sure is an unexpected thing. > > It only is unexpected in a "top-level folding" world, see my other reply. > Consider it an optimization, which was possible because of how our dynamic > folding works, and e.g. because we can determine the correct pagetable > level from a pXd value in pXd_offset. No, I disagree. The page walker API the arch presents has to have well defined semantics. For instance, there is an effort to define tests and invarients for the page table accesses to bring this understanding and uniformity: mm/debug_vm_pgtable.c If we fix S390 using the pX_addr_end() change then the above should be updated with an invariant to check it. I've added Anshuman for some thoughts.. For better or worse, that invariant does exclude arches from using other folding techniques. The other solution would be to address the other side of != and adjust the pud++ eg replcae pud++ with something like: pud = pud_next_entry(p4d, pud, next) Such that: pud_next_entry(p4d, pud, next) === pud_offset(p4d, next) In which case the invarient changes to 'callers can never do pointer arithmetic on the result of pXX_offset()' which is a bit harder to enforce. Jason