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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EE94C021BC for ; Wed, 26 Feb 2025 17:41:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1992528000B; Wed, 26 Feb 2025 12:41:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14A2B280008; Wed, 26 Feb 2025 12:41:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 010E928000B; Wed, 26 Feb 2025 12:41:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D7207280008 for ; Wed, 26 Feb 2025 12:41:39 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E54D1160252 for ; Wed, 26 Feb 2025 17:41:38 +0000 (UTC) X-FDA: 83162813076.13.95F1437 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf25.hostedemail.com (Postfix) with ESMTP id CDEB9A0016 for ; Wed, 26 Feb 2025 17:41:36 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of cmarinas@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740591697; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jvvD8VmtA028dfmpfoqe4awku57v1pGyKkk2EdLcK5A=; b=a6QUGPAtbTVzh1bvPYj5hFne4amFO5R7Ogrvdc5/+HRqurCETjYOXvMj1Ey3JDKTgW+LTV GgngoHiUT299CWChD5wxNCnL7L2GMeHo5xaJ7X3zA0Hj0CsgKcX3Bwne9+UZDNv6dxwoIJ MvwDe0ggnbWjvm+DPrJKMNdkj38vQLo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of cmarinas@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740591697; a=rsa-sha256; cv=none; b=JRlYCz+QvZdl3bMNHvJY3gCspTZBUQimTMgbGTmbMm4Ei29DckeezF4hssv476KXdY6aKA /c4M+AFrHpfhI8WehpsdC51T45TOtA4ReomVONZvLHdJd5eAE9ydivKuYG+3WbWxqYY3M/ tffSat/F5LvPLXp2j1SOm3UB03MOMIU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 22ADC6125B; Wed, 26 Feb 2025 17:41:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C9E5C4CEE2; Wed, 26 Feb 2025 17:41:29 +0000 (UTC) Date: Wed, 26 Feb 2025 17:41:27 +0000 From: Catalin Marinas To: Ryan Roberts Cc: Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Gerald Schaefer , "David S. Miller" , Andreas Larsson , Arnd Bergmann , Muchun Song , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , David Hildenbrand , "Matthew Wilcox (Oracle)" , Mark Rutland , Anshuman Khandual , Dev Jain , Kevin Brodsky , Alexandre Ghiti , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3 2/3] arm64: hugetlb: Fix huge_ptep_get_and_clear() for non-present ptes Message-ID: References: <20250226120656.2400136-1-ryan.roberts@arm.com> <20250226120656.2400136-3-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250226120656.2400136-3-ryan.roberts@arm.com> X-Rspam-User: X-Rspamd-Queue-Id: CDEB9A0016 X-Stat-Signature: p41g8agtoarpw3w613c5bkys5anzfdz1 X-Rspamd-Server: rspam03 X-HE-Tag: 1740591696-351545 X-HE-Meta: U2FsdGVkX1+TK1K884zqUZRATM1cVmhVIEMPZthd/lbhzNidBANkVx9oMsoQGOju7Fp+RHKTTaj0sJVGxdrgmRJypV5dSxk5pHLDafn4/OHuR77+nsJ5PyrMI3xxz/X0wBpDeO32OHpIE+8E2SNt0So0NtyhnbwTRB0iwRdQpIjHGG71+hIy/bUHeIuHuuLs6g4uL5M87sdSCXZ5UYmtx9xTZvDwJZdVOhq7eFqur/LT/hmv4IicGePq8sLia2IxbFBY+ALgOSFKkuKpl9oh6UYabp+blXWD4YUjKKjmePcsJYcYB6l8Y34lDh+LYjHwLF78rLq+YHPspranVGsWSNXpXCYy7G1koLWTXy/MkJpKzfcLMB3cNCjnHZ12XsqaVQ8lrJBgx2mauZ0uXEbkppBqJoXLFy+zPkkU9haXBf4si2gyClMrbkTX3fDH0cmdD8vkztwqYnuvFCxUDfMPxD3joyf5K+i+7STF4T9jCX3AqExZQKlcItplUOw8GX2m1gT1MuIpmI/gK7RHqsQygBsRtTOlK35r97CU2pqQM0TWrP6b/Sk1QjQ1Ak+SHE8kIKPoh362ImrRAul/JdMu6UFEVs28Bfl6aZ6Z+kIB2k5wrzNrCYYy9F/8VkNJm/lFYVa9myhrR5qB4FOpEHL2FE+2vhnbpl+QCT6iz0DCrlGvHFeRsRiJKPVy5fomaTVD5tp0E7Rq3kgskAdTvGa0E8qq60aSj39lJlweaDUwrO3h14TDr0RZkfaz8i2AbzWS2/5tVKcG20Kyf9k/e+CxrZyZbKJox2mmq97Jm1dCpd9ohavm3g+lvADTe5diaz7DuZK+tkhOy/zxgjD7+jHOcZu3m6G9v0F7cRv9UqnFQtzhJPtv/6Lp1fCgQhGCnL645vRFneFMMrO4IoRyGpVwDuZ5F5vmypxm3FPuoi1ATWqY9PMHeDmWCzltCUiGM9BkF16OpZfjxwr7OQlYGS5 1gA/Cp2r CsswqU9lBQv0uB8q9BQmdr8AGL6ImLLRWtiq5nGe/fVrvPH6PBGXrhgfOrbc837OH6tF5qJ8y5nioe5EzQQi0OTfx9i4fmVMhZCEfP1PLd05u5aQwj7ToTjRkP/p7i7hoJJfmkvux9TfmVQlG63n4+lIgOF/z7SngUHeTVDF9x6TNlxIvAi5HkLXOocd4bEqAiT5qX26DGRtgiTBjaUvQdKnw7l+c+GyfAhOjAEGE+qWmC8npfwkdOUVhDRdO8qpfDkv/3sqybxI8EVl0kc71jF9Z3yqZ8U+I2Cc+47n3kXq1BDCvFyTDlUaoaTyve9WYOWbeKNI4R4X5V/61FVTppuZQXgSpJwuA0OZp6qr0dniVp4S9qmdWG60OTIH+JNe5Wz/KfD9XqKf1PTZq61X4bSPImpkGHrOyFKmce8SobLWv8Zxhmq/JN+fGLxPPnhzUHxAP0QnH8GYCxpxWEnnVpOo2OQfhGbTwnZqC 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: List-Subscribe: List-Unsubscribe: On Wed, Feb 26, 2025 at 12:06:52PM +0000, Ryan Roberts wrote: > arm64 supports multiple huge_pte sizes. Some of the sizes are covered by > a single pte entry at a particular level (PMD_SIZE, PUD_SIZE), and some > are covered by multiple ptes at a particular level (CONT_PTE_SIZE, > CONT_PMD_SIZE). So the function has to figure out the size from the > huge_pte pointer. This was previously done by walking the pgtable to > determine the level and by using the PTE_CONT bit to determine the > number of ptes at the level. > > But the PTE_CONT bit is only valid when the pte is present. For > non-present pte values (e.g. markers, migration entries), the previous > implementation was therefore erroneously determining the size. There is > at least one known caller in core-mm, move_huge_pte(), which may call > huge_ptep_get_and_clear() for a non-present pte. So we must be robust to > this case. Additionally the "regular" ptep_get_and_clear() is robust to > being called for non-present ptes so it makes sense to follow the > behavior. > > Fix this by using the new sz parameter which is now provided to the > function. Additionally when clearing each pte in a contig range, don't > gather the access and dirty bits if the pte is not present. > > An alternative approach that would not require API changes would be to > store the PTE_CONT bit in a spare bit in the swap entry pte for the > non-present case. But it felt cleaner to follow other APIs' lead and > just pass in the size. > > As an aside, PTE_CONT is bit 52, which corresponds to bit 40 in the swap > entry offset field (layout of non-present pte). Since hugetlb is never > swapped to disk, this field will only be populated for markers, which > always set this bit to 0 and hwpoison swap entries, which set the offset > field to a PFN; So it would only ever be 1 for a 52-bit PVA system where > memory in that high half was poisoned (I think!). So in practice, this > bit would almost always be zero for non-present ptes and we would only > clear the first entry if it was actually a contiguous block. That's > probably a less severe symptom than if it was always interpreted as 1 > and cleared out potentially-present neighboring PTEs. > > Cc: stable@vger.kernel.org > Fixes: 66b3923a1a0f ("arm64: hugetlb: add support for PTE contiguous bit") > Reviewed-by: Catalin Marinas > Signed-off-by: Ryan Roberts > > tmp > --- Random "tmp" here, otherwise the patch looks fine (can be removed when applying). -- Catalin