Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp340924lqt; Mon, 18 Mar 2024 09:15:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvdb9Bnsr7oEtVVEmNIur7/KxmucaMEyFKqC/lcO6pjRnXVZhTHkS9Ggqp0mp8Tu4qAw9Wo/k9dN9WIvn91EBJD8uEoKbx2q8DvWgRXQ== X-Google-Smtp-Source: AGHT+IEmkDSLvsIg8R8PzfiKgd1rh7oxQJEDE+o3SPM6lFoRj2Q8jRF9HCIxD4NpJjZgMT/A7tZR X-Received: by 2002:a05:6122:1d93:b0:4d3:34f4:7e99 with SMTP id gg19-20020a0561221d9300b004d334f47e99mr167260vkb.0.1710778533482; Mon, 18 Mar 2024 09:15:33 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id di34-20020a05612246a200b004d3395f2164si1246460vkb.182.2024.03.18.09.15.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 09:15:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106367-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=QzZuBY7h; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-106367-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106367-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 201581C21880 for ; Mon, 18 Mar 2024 16:15:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0303052F6D; Mon, 18 Mar 2024 16:15:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="QzZuBY7h" Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2088.outbound.protection.outlook.com [40.107.101.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0911381AB; Mon, 18 Mar 2024 16:15:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.88 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710778525; cv=fail; b=pcNG8sc/b0QkX3szTvzGAMDqaxeFAnrSWx1AnuAQUrR3SifXBuWo3EJ9QrcidDWxz9Lr/tYtcZSjthVvSbaVft2uSgUhDggNMjo+mxtIzwWYDJaWUI6ZRPhwFwjZJt+NxlJA8d72GwKlKM/3NFlQ0LvtNn2IG+XWaNDI6A6y9qo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710778525; c=relaxed/simple; bh=PJtS7zI0u2qOVABnmf7JxLmekBIS12Spk/QjUoD8sT0=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=uSFVzVx4ZbwtiiuvjbY2w47cJ92eoT6bPqoFgZTUE+Fnei/sD06BYXu+71GPPYqgu71QTrvLptN+g+tr6KVh4yVBRe05+R7TNBtKLi9BE1S4MCXo7lWMg3yk09ZNSnid+SPZBu22IZYhT7sPWUbUz1h5dkltslX3Zojb2ku0k+g= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=QzZuBY7h; arc=fail smtp.client-ip=40.107.101.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e+CcdGzsnTq72yJAOE+f8Me64HjGti6A26PWbOMrP9LABVfDZd5KReGe/kTpZ1XR/0AtN1nfXox3rlh3cvZtbrYpfKLKPBrgjSKAM/jb+9n/wZazTNXs9m4dpfGNRIX0TEkmVsmY6fz/dFd0n8IvSrWz9q363qOXaqq0VhOPqVG+3nRmTn9WzIe3gQPBiY/IOP7O/oCgsf7wGKzw1xvFPpGRgKCaT97ei1AIjBH3W7ktfh7pign0vjWX0xYLmWwYBT5W49GMgE74PaSNoC+4UuQJzZFKUulPc8NaryvfBTi7QHw+UmZZgNji6vjjz4XyVkh9WNahxGnju+n3uQStUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dlv9s2X6IUZXoWRPusJ/nMrZ6cYw3m45dbmZorYVX7Y=; b=dEsp+C/289gGr6movhZhmTpf5fAFa3IVXYDdL7+OGeCNrSY62JV3JmuJv7AQT33mzSikZgaDEYgX6HYzMsn9MRHhGJnqlgX4sVbaQBASZUjVUABBHA+dwKJLwCUEhrIK2jxXJl69bqoFMG5+btyksOkKCi4SR8R1SgNRUpkdFhcPEDBXyxYwfs+6K8jLwzqz5PWJh9DY+1sgeoQbfeKceUMHMrDydmUdlXEPqVu5gX5iz9NQUWAnU4p+jKJpWGXz/o2ANXNBv8DXd9S6NLpJRRTiz+qb9RXcax9RupgqaRvtzQ1mY+r85mKUfUNnJb3h8mef/S8zMAGMxrME35OuVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dlv9s2X6IUZXoWRPusJ/nMrZ6cYw3m45dbmZorYVX7Y=; b=QzZuBY7hXHCOR8706MkWbH1fDoSq2MN/Ob7GM/NjS74eXtzpITp3CC9bmX3IGr9mNw93+0Tyi8JlwgkOwCiwsDiSyMl0P5M1J4u5gAR0QAz6xdw74EFoUP13hFo7j6Fm5DEw4DtsMTIW+qTU3sQWTzzR3vDmXqzx5O1beJAkwl1GQS8Afujp1LXSzeo92aXztc8WxD0Uo3CfPZcGB6YIjVaRUSDm27pPZJRO7LJkUJCIJZY07leuZ2RiJcnpFQPZ+rAEgq81xxYP8Ksu6AGDir/sAZPBuFtCXyJoB1lZIaRruUU6ksq0rhtN8vHJ9VqO5s+iXPTHZyF9qC0QvJwIIA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) by CH3PR12MB8331.namprd12.prod.outlook.com (2603:10b6:610:12f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 16:15:21 +0000 Received: from DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::6aec:dbca:a593:a222]) by DM6PR12MB3849.namprd12.prod.outlook.com ([fe80::6aec:dbca:a593:a222%5]) with mapi id 15.20.7386.025; Mon, 18 Mar 2024 16:15:21 +0000 Date: Mon, 18 Mar 2024 13:15:19 -0300 From: Jason Gunthorpe To: Christophe Leroy Cc: Peter Xu , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-arm-kernel@lists.infradead.org" , Matthew Wilcox , "linuxppc-dev@lists.ozlabs.org" , Andrew Morton , "x86@kernel.org" , Mike Rapoport , Muchun Song , "sparclinux@vger.kernel.org" , Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K.V" , "Naveen N. Rao" Subject: Re: [PATCH 09/13] mm/powerpc: Redefine pXd_huge() with pXd_leaf() Message-ID: <20240318161519.GA5825@nvidia.com> References: <20240313214719.253873-1-peterx@redhat.com> <20240313214719.253873-10-peterx@redhat.com> <7b7d6ce1-4a3f-4392-951d-a9bd146c954c@csgroup.eu> <1f6ad500-3ff7-44d4-8223-067bd2ed9ffe@csgroup.eu> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1f6ad500-3ff7-44d4-8223-067bd2ed9ffe@csgroup.eu> X-ClientProxiedBy: SA9PR13CA0141.namprd13.prod.outlook.com (2603:10b6:806:27::26) To DM6PR12MB3849.namprd12.prod.outlook.com (2603:10b6:5:1c7::26) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB3849:EE_|CH3PR12MB8331:EE_ X-MS-Office365-Filtering-Correlation-Id: 21eacb3b-8bd6-4b62-a007-08dc47669c17 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VeKXYvAoK6iWXmAcXLaQEH4lPt94aqq5ovoSX7V3j15TdBEc7W4CWTVb4GuQrIsYtcEn2mr8Y031SJcq0lDu6/8ciSsxpyRcnYGNyPe5HuoXyea7ddZlen3EnoV+xkxHAMeLbZc+sUFV3X7YIAxpv8yNywKaXKDpucWj49i3yGvn4Rmc8QOenBXgMulnvoxda/8Q4rX+V+eliOpyIVoqKF5jeWwIev8VxDgxNPW/XPEDS9xAvC28QBdb5gImHjBjbRSm3MSq7FymDuEGdc51Hrsczy7FTDrQ8s77Tm2DUvQ5YrhEyQ7Q5LZpH1K2cM6u1XxEWmoQJRjtflJFMogrMDAiq+h43g+TovnTPRxVBpKQ7JwmUpYgRZSYeVhkBN4zHpJAmqZsqooTuupFc2zfdLi93rV+EuQUa8v2xBK0s7CuE/OdNz1eUNWYySCi3HcTOQWy8lrJut1qCU8cssJS9DfHGiSfbvnNriv6rgZr+RFKplNXdC+NaK/C+TdoLPgn/kEG1pJ4dmCRkDpd26wwyjPvbX1jihoLvtNQ7nu1pAdnRY79lgcpPsZShhzWjVoY35wbGf6xDeJTwrYYNppqvAHARxi7+r4GitMqw8oQ3d6aNDXWWCQF6uUekUvbnNzT7d7t0IzW2KOQstVWUVwyEXm/qADHXC1ekb/Uk6/oM6Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3849.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(366007)(1800799015)(7416005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bHhHUWZoQllXU0VoeTFmTE9SZkdIbU96VFpLSHdrSFJJd0s1blBzMFZ5NExp?= =?utf-8?B?dG01RGwzOEN3Y1Ztck9ScjZnaUpKYXJkSjFjcFlBdkhCUzNwc2MwTXRGcWcr?= =?utf-8?B?MmhzdWNQcUp6WFd6Wi82MWZRV3V4YjBERUJqdHdvWUlRNlpwYVJZOGcrREFL?= =?utf-8?B?Skl4U1RFUUlZbWVvYnJGSVNncWZIWjlDQmNOSXJhb0VMUWhSSHJhMVlpb2hP?= =?utf-8?B?NS80N2drWXpYQ21HVnAzS2hnTnZOblBVb1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ZTVFOQ04wbXk5enFjd2s3NDZSSndrMklKQW1CTEdkM1RIRGNuUm0yZU1V?= =?utf-8?Q?fYwU=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21eacb3b-8bd6-4b62-a007-08dc47669c17 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2024 16:15:21.2007 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ptvgPTtAQp9uxgSCr5rnubGdY/jszhNphhnpNM1hGNKovsx6qNC1ywe+pYvIhi6b X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8331 On Thu, Mar 14, 2024 at 01:11:59PM +0000, Christophe Leroy wrote: > > > Le 14/03/2024 à 13:53, Peter Xu a écrit : > > On Thu, Mar 14, 2024 at 08:45:34AM +0000, Christophe Leroy wrote: > >> > >> > >> Le 13/03/2024 à 22:47, peterx@redhat.com a écrit : > >>> From: Peter Xu > >>> > >>> PowerPC book3s 4K mostly has the same definition on both, except pXd_huge() > >>> constantly returns 0 for hash MMUs. As Michael Ellerman pointed out [1], > >>> it is safe to check _PAGE_PTE on hash MMUs, as the bit will never be set so > >>> it will keep returning false. > >>> > >>> As a reference, __p[mu]d_mkhuge() will trigger a BUG_ON trying to create > >>> such huge mappings for 4K hash MMUs. Meanwhile, the major powerpc hugetlb > >>> pgtable walker __find_linux_pte() already used pXd_leaf() to check hugetlb > >>> mappings. > >>> > >>> The goal should be that we will have one API pXd_leaf() to detect all kinds > >>> of huge mappings. AFAICT we need to use the pXd_leaf() impl (rather than > >>> pXd_huge() ones) to make sure ie. THPs on hash MMU will also return true. > >> > >> All kinds of huge mappings ? > >> > >> pXd_leaf() will detect only leaf mappings (like pXd_huge() ). There are > >> also huge mappings through hugepd. On powerpc 8xx we have 8M huge pages > >> and 512k huge pages. A PGD entry covers 4M so pgd_leaf() won't report > >> those huge pages. > > > > Ah yes, I should always mention this is in the context of leaf huge pages > > only. Are the examples you provided all fall into hugepd category? If so > > I can reword the commit message, as: > > On powerpc 8xx, only the 8M huge pages fall into the hugepd case. > > The 512k hugepages are at PTE level, they are handled more or less like > CONT_PTE on ARM. see function set_huge_pte_at() for more context. > > You can also look at pte_leaf_size() and pgd_leaf_size(). IMHO leaf should return false if the thing is pointing to a next level page table, even if that next level is fully populated with contiguous pages. This seems more aligned with the contig page direction that hugepd should be moved over to.. > By the way pgd_leaf_size() looks odd because it is called only when > pgd_leaf_size() returns true, which never happens for 8M pages. Like this, you should reach the actual final leaf that the HW will load and leaf_size() should say it is greater size than the current table level. Other levels should return 0. If necessary the core MM code should deal with this by iterating over adjacent tables. Jason