Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp134950lqc; Thu, 7 Mar 2024 12:32:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU4tDocCz/5sgLFuwf1DhiFXLp94fp0f/gE2fNXu3UIICwchlueXx9OuqVmz4QpFAW2TMnEePsAjrRFlssmUcihBn+VlEYU8nX+Js4FEA== X-Google-Smtp-Source: AGHT+IEUIqfv1dVuZU+8VKsvekmHON2nfYGN4MDRZhp5O3WpBlI/xo6No4F0s6LgJdgtSBZG4AVn X-Received: by 2002:a17:90a:8041:b0:299:300c:4c71 with SMTP id e1-20020a17090a804100b00299300c4c71mr15497868pjw.28.1709843574733; Thu, 07 Mar 2024 12:32:54 -0800 (PST) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m14-20020a17090a2c0e00b0029969ee2a08si2278094pjd.52.2024.03.07.12.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 12:32:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="j3UVtH/f"; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-96174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96174-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id F002EB241BC for ; Thu, 7 Mar 2024 20:17:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CDFA1386AF; Thu, 7 Mar 2024 20:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="j3UVtH/f" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (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 08A4713666E; Thu, 7 Mar 2024 20:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709842624; cv=fail; b=uPVZypbzHtxPzkc8ABeCmB7AX9fR/YRRw2Md3qdc8py1xmsnc8aFoB+suzc4sGoGB6BFojDrOCHCx56xJ1NnUeIUUU1YyGz/UcpNekohC5EMUUfU/Hxwcj6y4U7mvpy16Tj7GwtcJGLAcqYg/XQkbxowHklZDdI3ggvvn2eK6Lk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709842624; c=relaxed/simple; bh=LUjg9QL6Ky/zh7XbnbZ/8kwx/sJCmFMTArh2aK3cu7o=; h=Date:From:To:Cc:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=lrsSQmpxLAOoEg+JhbMmo3nzJyJD6aExbWBffuzHfP85Tk17E0FbJ5/BxcG4qaFctGBIjWW/b/9AL8nAYZn1U9pByVuc9yTIYABDwYsGTi4811f3YOqBqrS/2DAUj3KjFqJeq8h+slUc+zLA/wBSGjae7UuhkDxAM6XBWasoCCI= 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=j3UVtH/f; arc=fail smtp.client-ip=40.107.236.40 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=AUeOorKkZ9OFfLTlobVEbbCggrzqkdw4uZPOGMNdjEkfb+TpeXGUQtrtISKJl5+t9fIMb8xo6IyqJDKzqgMl4r8ZJ2HzNrVdcqzcmD/BVLBJpq9ur5YFwzJIYheGP5jxoCly6U9pnxvYkhngaLCEWtszr6TcnI7FzyZhGF9rK+xF31vJuHTdWY1MmxNuzGmIaJCUe0o9xCMD/VwguyBQjV+vDm+cv7qpElUm/KAtrp2KBP4YM9XZmE2WuolxlwZOnEygqTeH6xYuk0BpvU8kOgDeLe5lE19QlMeZDWdSHNPRpkw0vP5a9iAjLb2OoBPcoHMXaQ5nBydrCatpyoU4kw== 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=yjYLYsWUwR6Os+WUro8W9GHIcP7kmbFChN+9az3aDdY=; b=fLA/gr4qSFjySjO9n4Tim7MvnG3xqqnymm80GGdwvrzeGGZyDSxO061x8tOdebRvjrDzGC3UAmz6mvTZsBjOEKLzMnb2BfvEi9dyc7xgUqKssUuj6VZCBIJfZkAJB6f0z427f9bdP1ohyY5/Jw0/U9ql3iTdg2/v0NgArB91kLG1DMuAkbNrH3YwTiU3rtWHLoHu9SHoj+zVHLFT/zibxxzNK8zlstjEFqsNx0d16MYywapEKVs3g0GQTASi6bsD1fFKBgaylCqXP6A/V9OvfvvxD6o9eovQ1vG3A+kS3ci7eEyOtQM3G7bzKVD96X8cV3ntxbrVNucjl7tFJRh51Q== 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=yjYLYsWUwR6Os+WUro8W9GHIcP7kmbFChN+9az3aDdY=; b=j3UVtH/fJzzkCe8JQRPxTEeyU2ZGhp//VEnnGurdy1+9Uipsl8ykUbo9JaYTle9W8eD8VQmhHQW5QVTTdxNyFFonEqKqbOzyOTPo0CEXchzC+R4B5N+rwHcaaQgjq8Qqb2om/uj9yySTtN87yU0mHh1BB55kr0xc+u72XJsBFG2ZUac3W7ChjE+3jN5/LfUf0PP/CaNKyiCmjo7XtF1G4FEpog8pp8P/jcPew+pwRISPiZu0bNsQI2Nj11Sn5+X2r2/5eUgg1J9PYJtdRCUIHrnrAz2HaGO877JCm/CxGFd1tBOO6Xk8u0l6tznIQ63byvHpNf6y9/ivnfAjVb5Mkw== 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 MW3PR12MB4396.namprd12.prod.outlook.com (2603:10b6:303:59::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26; Thu, 7 Mar 2024 20:16:57 +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.7362.019; Thu, 7 Mar 2024 20:16:57 +0000 Date: Thu, 7 Mar 2024 16:16:55 -0400 From: Jason Gunthorpe To: peterx@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Morton , Muchun Song , Matthew Wilcox , Mike Rapoport , Christophe Leroy , x86@kernel.org, sparclinux@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Naoya Horiguchi , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen Subject: Re: [PATCH RFC 04/13] mm/x86: Change pXd_huge() behavior to exclude swap entries Message-ID: <20240307201655.GF9179@nvidia.com> References: <20240306104147.193052-1-peterx@redhat.com> <20240306104147.193052-5-peterx@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240306104147.193052-5-peterx@redhat.com> X-ClientProxiedBy: SN4PR0501CA0069.namprd05.prod.outlook.com (2603:10b6:803:41::46) 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_|MW3PR12MB4396:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f5be981-b8a3-4f7f-016a-08dc3ee38a08 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NJ8HhtV0wbDGRgbqsFpHWrL0TsNjgen6EOcqvzAwj1i+rknyc4iW+GjuROKcYGZ2InjINyjuJFn6arn9/u/outX9LkV4Kkp+h2wFho6BWXqozGFHnpomOiiLzKh0+K2OwTpJE9/l2lshCFytUlUEANeckfu2Abwhj/F9D9P+VqUYXVArGYXYbp6NuoVAfgAWWrh3hCNTrADdizHWo9ZGUR/K5ZSeef8I8/y6Z1l2fOKj4IKyaPisYNaoSOt5zB2bPIayMRpNx7MKbCDLOnoqbBTJCzambgx+XD46uLMHvY4P/3PdQmbxC0Im7XaP6XPxdPuN9ACFuVoLlZMWlbqLELqic8+19OtI7IF74/MhFSje/7Ea7E3TvwF62zjXWVNjiYcpDxVgUVMGblec1rdUZZtqK55qEL9d9htu/jZR7X+6UbSQpVTyMqZKp+51NCqR3+6CuIEzvZeTPK7deTE7fUyxcvf26NvKZzmiKYEvL7NRA9vqRU8m/M7/+b16kRuVGFySGfJlzh9mhbw4kJleM80czkHWI3rl3ne9QVA7+nEl+WZ8Y1eBEe7yQHHKelCjaLENOeSyF5XINxM3I3PpO+BPv+qBTy2oJ9bjYEAPw3mETRySDUoTJ5eyq4qFDsvOH64a+P6IrCGSj4CoeYtHTORv/pajhfEeSkblmzS8jvs= 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?U0pwSFhuZklCNENRWS9mVVNlOUFOVDBPdnFyOEJkYVV5cTJlL0VmNjVBZlpj?= =?utf-8?B?UWZDMVY3SDdWZnptNFlrYjJoajVFNC9JSVFhdDBPZm5ZNE1ITjVtNzlxaS9O?= =?utf-8?B?cVAzcU5OUFZXYis0Y1NnZm1wbFJqMHI3S1VYdktCMDhUaXhLbSthc0tiTHdD?= =?utf-8?B?RkdjUzk3MTM1SFBzekxVdVJjZ3A5WjhkS3Fxa0N6eWo0emtoT1gvMG5yMG5J?= =?utf-8?B?cWlvdnFPZXFLTytnNTAwOHYxUzFjMGlIRGxGY0RtdThTR2JsQlNqQytwMEtr?= =?utf-8?B?dWpSOGVicWxkdEdyRXpad3NaU2I5Zktvcjd5QWJnSW5PUkR1aU5RdGtNNVh5?= =?utf-8?B?elR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: 5f5be981-b8a3-4f7f-016a-08dc3ee38a08 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB3849.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 20:16:57.5340 (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: z5+PuvTjZrLgdSDdJIvRa5G12f22nrcc9yreOm+GTWyDuyBejV1Cd0ZX5bcGF6GP X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4396 On Wed, Mar 06, 2024 at 06:41:38PM +0800, peterx@redhat.com wrote: > From: Peter Xu > > This patch partly reverts below commits: > > 3a194f3f8ad0 ("mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry") > cbef8478bee5 ("mm/hugetlb: pmd_huge() returns true for non-present hugepage") > > Right now, pXd_huge() definition across kernel is unclear. We have two > groups that think differently on swap entries: > > - x86/sparc: Allow pXd_huge() to accept swap entries > - all the rest: Doesn't allow pXd_huge() to accept swap entries > > This is so confusing. Since the sparc helpers seem to be added in 2016, > which is after x86's (2015), so sparc could have followed a trend. x86 > proposed such swap handling in 2015 to resolve hugetlb swap entries hit in > GUP, but now GUP guards swap entries with !pXd_present() in all layers so > we should be safe. > > We should define this API properly, one way or another, rather than keep > them defined differently across archs. > > Gut feeling tells me that pXd_huge() shouldn't include swap entries, and it > turns out that I am not the only one thinking so, the question was raised > when the current pmd_huge() for x86 was proposed by Ville Syrjälä: > > https://lore.kernel.org/all/Y2WQ7I4LXh8iUIRd@intel.com/ > > I might also be missing something obvious, but why is it even necessary > to treat PRESENT==0+PSE==0 as a huge entry? > > It is also questioned when Jason Gunthorpe reviewed the other patchset on > swap entry handlings: > > https://lore.kernel.org/all/20240221125753.GQ13330@nvidia.com/ > > Revert its meaning back to original. It shouldn't have any functional > change as we should be ready with guards on !pXd_present() explicitly > everywhere. > > Note that I also dropped the "#if CONFIG_PGTABLE_LEVELS > 2", it was there > probably because it was breaking things when 3a194f3f8ad0 was proposed, > according to the report here: > > https://lore.kernel.org/all/Y2LYXItKQyaJTv8j@intel.com/ > > Now we shouldn't need that. > > Instead of reverting to _PAGE_PSE raw check, leverage pXd_leaf(). > > Cc: Naoya Horiguchi > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Dave Hansen > Cc: x86@kernel.org > Signed-off-by: Peter Xu > --- > arch/x86/mm/hugetlbpage.c | 18 ++++-------------- > 1 file changed, 4 insertions(+), 14 deletions(-) I think this is the right thing to do, callers should be more directly sensitive to swap entries not back into it indirectly from a helper like this. Jason