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 8B80FC021B3 for ; Fri, 21 Feb 2025 10:27:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E22A928000B; Fri, 21 Feb 2025 05:27:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2BC6B009E; Fri, 21 Feb 2025 05:27:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4B4728000B; Fri, 21 Feb 2025 05:27:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A64126B0089 for ; Fri, 21 Feb 2025 05:27:07 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 242EC120140 for ; Fri, 21 Feb 2025 10:27:07 +0000 (UTC) X-FDA: 83143574094.13.3607433 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf08.hostedemail.com (Postfix) with ESMTP id 02A4F16000A for ; Fri, 21 Feb 2025 10:27:04 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740133625; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZ2VWlpKeEiLEf/5Ln29C1rdKHqi8QQc5Jr1aEMZJdM=; b=Uuw45egN3nlrjKcwiykiOHPif6o1heVPN1KSYqaSz1YEKjO8yBCRlp6h/9cBQgvDNo6sfG IVaS3a7RQio5aKY/rphkewlxfdCCRiloDvoA7I0yR+9k8Iyd+2rc8DexE65JlKVeAXtfaw 2IZqOwQUXwlxZZn74xDxfzdUsLFw/lY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740133625; a=rsa-sha256; cv=none; b=rUAk+H799sWTwGrX0E1D4piXpZlHvuRp3DPV7hiJagTBPUSiyN/3VbvjR4esDxJIrDSysy cAzxheFXQ/VhqYhE0XKccuGe8IH6TposQcnDh33UX9bdOtqhGTOJoDnym2M3RqRu7bfMGv AqJL1+y9ip+jIYlqlkTnTRrsn9ckygs= 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 D36C6169C; Fri, 21 Feb 2025 02:27:21 -0800 (PST) Received: from [10.57.85.120] (unknown [10.57.85.120]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 320623F5A1; Fri, 21 Feb 2025 02:26:59 -0800 (PST) Message-ID: <1ac64c39-419b-4fac-8820-bbfb4e6afec4@arm.com> Date: Fri, 21 Feb 2025 10:26:57 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/4] arm64: hugetlb: Fix huge_ptep_get_and_clear() for non-present ptes Content-Language: en-GB To: Catalin Marinas , Anshuman Khandual 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 , 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 References: <20250217140419.1702389-1-ryan.roberts@arm.com> <20250217140419.1702389-3-ryan.roberts@arm.com> <5477d161-12e7-4475-a6e9-ff3921989673@arm.com> <50f48574-241d-42d8-b811-3e422c41e21a@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 02A4F16000A X-Stat-Signature: tq6qak9uam7pjiotaozka5kade9f9zct X-Rspamd-Server: rspam03 X-HE-Tag: 1740133624-373782 X-HE-Meta: U2FsdGVkX1+J9kO8UmR2exXNJOfLjpG0TXUmV7RS0qyVg67E7RKsJYCu3b7VHxyFFe0fYmSJHo6N/kGTvZF6BdxjaGrkw7Cd8nqu3xdGBj1mFgQdAdJCxWFqo2EShrlYYhFor8ZUjnTSLf3Qi0R54d1O1TQ5n3izYf/V4HYMnbbWfkDwhUF4Od+wrBokRhhsJ6yNXwLn2DjhVSYcm2G4kKoR3g+49xXh0u1yfHWRUmXPl5Uvem7p3MsODKzAAg79xFv90FblDblpHRWm3RyBpA9Is8/yjTCxwKHdxdvoKzb/JPWqmmTqDUoIe8VXmrIfqJ/3dGpcuv7jExxkCQsHavKuO404f6mKg7sFfpogIrfxqdiMyYgxLRrYNI5On6b+Ubbh3C/vApXJnwbMXcsTjnBJMS7jQK2A8zJebnWdwmgFfFazpqh98XIwtJGvtXDS6NXpk8dfttE0LsktaB1UXfLE+zF/MBS5PGwKhYtAIzNo6qEv1BPdBP0GcJG2rdzy441mTqtRk367SSxECRiLOJ1az0DmwPZ5jur3D0r4iAkaoVHagabglbKJz23vOdItJFMkaa9GCXhExHIS4TuK3GDslqjEYlUAepHONIA8SdTjabpaufcjCAs/BRXyu++/qCQLGPTSu0273ka6EODOZ0n0l8E0IfXdTHyd1Mv35ZoR6blmDcLk9OdPAIfR69DZmrJ4+/GbBlWDK329oWkzqhzgIXZX433+UoRHkO/+kjF6wYma85lqhCpaMjd9ADmNOGoGALEimrPnq/UolT9V/2dFy1+rIjOa5Yjkkl8gpNz3LupFZYRNCiZ4J8aP4ojP0Jj1CCEt/VHEIH+714FllPXaJo55WRVrSgQl5cacxDXR2epIDrRpR2pjy/I9zilEBvevQ+Wq+mQk1rL8saNrynBG/ncwVag+iPdDztJe7mLs6cFHa28gYE7l43yo74a9bC1eUWij++bG9Fwn9Ga WI6Akbh8 NAke4J8LzanFnMv0tY140jpK+ZDOaeIBptQflPJ2nhQgC2Htj3W0EFanib9UYq0yQ2xGEbifpUyAlR7g8D97RbPdMoZHqp2ExY8syjGy223Bw/q/MH3j2nWULOJd2IgLZQ6aXJE2lVIcJCTKZcqDv1EWGZOGXNykg671+1X4TQbWPi2xjekEZoJop8Zy9vISZ8abD 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 21/02/2025 09:55, Catalin Marinas wrote: > On Thu, Feb 20, 2025 at 12:07:35PM +0530, Anshuman Khandual wrote: >> On 2/19/25 14:28, Ryan Roberts wrote: >>> On 19/02/2025 08:45, Anshuman Khandual wrote: >>>> On 2/17/25 19:34, Ryan Roberts wrote: >>>>> + while (--ncontig) { >>>> >>>> Should this be converted into a for loop instead just to be in sync with other >>>> similar iterators in this file. >>>> >>>> for (i = 1; i < ncontig; i++, addr += pgsize, ptep++) >>>> { >>>> tmp_pte = __ptep_get_and_clear(mm, addr, ptep); >>>> if (present) { >>>> if (pte_dirty(tmp_pte)) >>>> pte = pte_mkdirty(pte); >>>> if (pte_young(tmp_pte)) >>>> pte = pte_mkyoung(pte); >>>> } >>>> } >>> >>> I think the way you have written this it's incorrect. Let's say we have 16 ptes >>> in the block. We want to iterate over the last 15 of them (we have already read >>> pte 0). But you're iterating over the first 15 because you don't increment addr >>> and ptep until after you've been around the loop the first time. So we would >>> need to explicitly increment those 2 before entering the loop. But that is only >>> neccessary if ncontig > 1. Personally I think my approach is neater... >> >> Thinking about this again. Just wondering should not a pte_present() >> check on each entries being cleared along with (ncontig > 1) in this >> existing loop before transferring over the dirty and accessed bits - >> also work as intended with less code churn ? > > Shouldn't all the ptes in a contig block be either all present or all > not-present? Is there any point in checking each individually? I agree, that's why I was just testing it once outside the loop. I'm confident my code and Anshuman's alternative are both correct. So it's just a stylistic choice really. I'd prefer to leave it as is, but will change if there is consensus. I'm not sure I'm hearing that though. Catalin, do you want me to respin the series to fix up the typos that Anshuman highlighted, or will you handle that? Thanks, Ryan