Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp412492rdb; Thu, 18 Jan 2024 07:16:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/wT55JwYsrXNWGehsNGowcXo1PzSPvFBodnd8WTq2neKVhsXSf5ARNtIf4Qo/BkhBN0db X-Received: by 2002:a17:906:d10d:b0:a23:62bb:2e77 with SMTP id b13-20020a170906d10d00b00a2362bb2e77mr312656ejz.61.1705590961923; Thu, 18 Jan 2024 07:16:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705590961; cv=pass; d=google.com; s=arc-20160816; b=Ylvndr9Jlg7NckDkLmhcCzzUfaSzniGLhyhyT5PFkauSww+dguJ0CTFhQp76ESnpb+ usvpXKBQByoJrVSRF5hDuE4ACFzL65jWe+FYZ0tBmLyHNoGcvxTgPtzy+u3sm5cw10e7 e09sZ+gRUgrGYueDv6vCgAx6Orn0Q4BIsSshTcFUZw6JWb3jf1MtcZ/W/ru9kDg6F0oy +cPTjKaAT80UhNLgOOwXwUBG/RWRz1T7Q01lzIOM4Tg1EDU59xpPtFTor5Qr5cpIDhmo A7jYYcuU1QBy7ZNIMiDP+eiR3/S9up1soBNqHE7jtmMhb3FY5TyBaNHJ++vQyGr1P60H C8PA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=UU3sW8YBC8V60WBn+FUKuaHKFAQ8vff+03rqS2HfW88=; fh=y3b8x3RZb75Esz5KzNOpHH8C56kWh+8W+2hqYcfmofw=; b=z3SrQsdIyTPbhJpqrQsNmCdN/27oQbd7yGyOIJ8wAlg0mVF+rjB60gsglt4+MOxiVI k48/Xr+yQvS945o1777ijF3bWlnFBDhmqvZNTbTF+lFVo59yuuHqrmn1rMOdTeKlY9HV ilp5nOYZBXa1yKInQUiCL1m8GqPRveYYTN/YjTAnYr7da8Qark6Z9eXzzkTqsoMJvmXC Bixm/vJOTfD964un3mO7/+kyjaNFypAKS/WWLI197zoS8fxkpLHY4RdkblZtzSJ4e2MM bo21wxZ79eh56EqQTxPrLdXA3v4l1X4HH+eLckFI+WeX2wuUXHoEGCwMFFC2HNFSdso6 puMw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-30245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 23-20020a170906059700b00a2b9498888esi6769904ejn.405.2024.01.18.07.16.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 07:16:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-30245-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 848651F2438A for ; Thu, 18 Jan 2024 15:16:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6BCB1E88E; Thu, 18 Jan 2024 15:15:52 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E2061E532 for ; Thu, 18 Jan 2024 15:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705590952; cv=none; b=TMEgRtvZ4L7NffPER/uQ3DEDVd912Y6uHIZZ8IYNBi3h0P6JUMx4xPps2gg9aofhghiu1KNHK1+552QneL59+dZ1Q+1HnPRJfuJSWgomXQmY9uwpa6qdSQ82yN48SI3WfLw1DkkSjE0BYI/XO3KKmYlVHxPvl7agbnSeQcCS+no= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705590952; c=relaxed/simple; bh=/hJ+jFjPcZBpWrtzOj9idrYCeyAyNSL3T466ON4vT4M=; h=Received:Received:Message-ID:Date:MIME-Version:User-Agent:Subject: Content-Language:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; b=JkYFTENi//nHBaPY5WJBwk9Ecocm02RNjjQhDO35ixZ/m3MnCzWCbKjkN5rczcVVIV/gvuyTeckVZM9ufgEmg7TZNbWHCChvacfauWsJ8GRNgtplA6E5dk7L97rAvzOwhhT29QTtWu5yuRicsROOWU2ejgI4A/UKlA/EJJ8f83w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8E4711042; Thu, 18 Jan 2024 07:16:27 -0800 (PST) Received: from [10.57.77.97] (unknown [10.57.77.97]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE12B3F73F; Thu, 18 Jan 2024 07:15:37 -0800 (PST) Message-ID: <9e60b948-0044-4826-8551-0a3888650657@arm.com> Date: Thu, 18 Jan 2024 15:15:36 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing Content-Language: en-GB To: Jason Gunthorpe , Christophe Leroy Cc: "peterx@redhat.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , "linux-riscv@lists.infradead.org" , Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Andrew Jones , "linuxppc-dev@lists.ozlabs.org" , Mike Kravetz , Muchun Song , "linux-arm-kernel@lists.infradead.org" , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox References: <20240103091423.400294-1-peterx@redhat.com> <20240103091423.400294-7-peterx@redhat.com> <20240115183748.GR734935@nvidia.com> <20240116123138.GZ734935@nvidia.com> <44e450cb-5d3f-407e-97a3-024eb936f74b@csgroup.eu> <20240117132243.GG734935@nvidia.com> From: Ryan Roberts In-Reply-To: <20240117132243.GG734935@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 17/01/2024 13:22, Jason Gunthorpe wrote: > On Tue, Jan 16, 2024 at 06:32:32PM +0000, Christophe Leroy wrote: >>>> hugepd is a page directory dedicated to huge pages, where you have huge >>>> pages listed instead of regular pages. For instance, on powerpc 32 with >>>> each PGD entries covering 4Mbytes, a regular page table has 1024 PTEs. A >>>> hugepd for 512k is a page table with 8 entries. >>>> >>>> And for 8Mbytes entries, the hugepd is a page table with only one entry. >>>> And 2 consecutive PGS entries will point to the same hugepd to cover the >>>> entire 8Mbytes. >>> >>> That still sounds alot like the ARM thing - except ARM replicates the >>> entry, you also said PPC relicates the entry like ARM to get to the >>> 8M? >> >> Is it like ARM ? Not sure. The PTE is not in the PGD it must be in a L2 >> directory, even for 8M. > > Your diagram looks almost exactly like ARM to me. > > The key thing is that the address for the L2 Table is *always* formed as: > > L2 Table Base << 12 + L2 Index << 2 + 00 > > Then the L2 Descriptor must contains bits indicating the page > size. The L2 Descriptor is replicated to every 4k entry that the page > size covers. > > The only difference I see is the 8M case which has a page size greater > than a single L1 entry. > >> Yes that's how it works on powerpc. For 8xx we used to do that for both >> 8M and 512k pages. Now for 512k pages we do kind of like ARM (which >> means replicating the entry 128 times) as that's needed to allow mixing >> different page sizes for a given PGD entry. > > Right, you want to have granular page sizes or it becomes unusable in > the general case > >> But for 8M pages that would mean replicating the entry 2048 times. >> That's a bit too much isn't it ? > > Indeed, de-duplicating the L2 Table is a neat optimization. > >>> So if you imagine a pmd_leaf(), pmd_leaf_size() and a pte_leaf_size() >>> that would return enough information for both. >> >> pmd_leaf() ? Unless I'm missing something I can't do leaf at PMD (PGD) >> level. It must be a two-level process even for pages bigger than a PMD >> entry. > > Right, this is the normal THP/hugetlb situation on x86/etc. It > wouldn't apply here since it seems the HW doesn't have a bit in the L1 > descriptor to indicate leaf. > > Instead for PPC this hugepd stuff should start to follow Ryan's > generic work for ARM contig: > > https://lore.kernel.org/all/20231218105100.172635-1-ryan.roberts@arm.com/ > > Specifically the arch implementation: > > https://lore.kernel.org/linux-mm/20231218105100.172635-15-ryan.roberts@arm.com/ > > Ie the arch should ultimately wire up the replication and variable > page size bits within its implementation of set_ptes(). set_ptes()s > gets a contiguous run of address and should install it with maximum > use of the variable page sizes. The core code will start to call > set_ptes() in more cases as Ryan gets along his project. Note that it's not just set_ptes() that you want to batch; there are other calls that can benefit too. See patches 2 and 3 in the series you linked. (although I'm working with DavidH on this and the details are going to change a little). > > For the purposes of GUP, where are are today and where we are going, > it would be much better to not have a special PPC specific "hugepd" > parser. Just process each of the 4k replicates one by one like ARM is > starting with. > > The arch would still have to return the correct page address from > pte_phys() which I think Ryan is doing by having the replicates encode > the full 4k based address in each entry. Yes; although its actually also a requirement of the arm architecture. Since the contig bit is just a hint that the HW may or may not take any notice of, the page tables have to be correct for the case where the HW just reads them in base pages. Fixing up the bottom bits should be trivial using the PTE pointer, if needed for ppc. > The HW will ignore those low > bits and pte_phys() then works properly. This would work for PPC as > well, excluding the 8M optimization. > > Going forward I'd expect to see some pte_page_size() that returns the > size bits and GUP can have logic to skip reading replicates. Yes; pte_batch_remaining() in patch 2 is an attempt at this. But as I said the details will likely change a little. > > The advantage of all this is that it stops making the feature special > and the work Ryan is doing to generically push larger folios into > set_ptes will become usable on these PPC platforms as well. And we can > kill the PPC specific hugepd. > > Jason