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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48E34C02194 for ; Thu, 6 Feb 2025 12:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oZxkJfVhdEYrWBRAlGbH6dm0+VsWvKeDJ0Spkyo9g8k=; b=w5RnBvnumfQpHxZabkpZmd63jQ sFTtxWFI1t7x3gxKFpFF4oYMMwoscruTCvlDnziurnG+wmGOVFJV7vat8pSjthJSWso4bLZkIarVP MQtZrHv5GNybexoo1jYyM99vmTssMoB4HJ34OwbfpNrRgYuWOAX0H8yY0PSRfq4pCsncfWJZiwxP/ lUBf00FqmpEBV+yGDcbcRTDE1fn6v/tuviLQVFfCbC4Qb3hHkNWq+HZinob/fvLxT/Cyz0F4ZY8lp FOSVhZfrjcYMPwSunO8htsCU9juQcLBW9SH1T8los9YooFAugjq03Pe5KYm1fkiSDi9uamGw7W+jN LBh+DRcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tg0ou-00000006FZW-3gAS; Thu, 06 Feb 2025 12:17:24 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tg0nV-00000006Ed1-2fZM for linux-arm-kernel@lists.infradead.org; Thu, 06 Feb 2025 12:15:58 +0000 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 1943912FC; Thu, 6 Feb 2025 04:16:18 -0800 (PST) Received: from [10.57.80.166] (unknown [10.57.80.166]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 98B683F63F; Thu, 6 Feb 2025 04:15:49 -0800 (PST) Message-ID: Date: Thu, 6 Feb 2025 12:15:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 01/16] mm: hugetlb: Add huge page size param to huge_ptep_get_and_clear() Content-Language: en-GB To: Anshuman Khandual , Catalin Marinas , Will Deacon , Muchun Song , Pasha Tatashin , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Mark Rutland , Ard Biesheuvel , Dev Jain , Alexandre Ghiti , Steve Capper , Kevin Brodsky Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huacai Chen , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Gerald Schaefer , "David S. Miller" , Andreas Larsson , stable@vger.kernel.org References: <20250205151003.88959-1-ryan.roberts@arm.com> <20250205151003.88959-2-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250206_041557_757629_5A139769 X-CRM114-Status: GOOD ( 21.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Thanks for the review! On 06/02/2025 05:03, Anshuman Khandual wrote: > > > On 2/5/25 20:39, Ryan Roberts wrote: >> In order to fix a bug, arm64 needs to be told the size of the huge page >> for which the huge_pte is being set in huge_ptep_get_and_clear(). >> Provide for this by adding an `unsigned long sz` parameter to the >> function. This follows the same pattern as huge_pte_clear() and >> set_huge_pte_at(). >> >> This commit makes the required interface modifications to the core mm as >> well as all arches that implement this function (arm64, loongarch, mips, >> parisc, powerpc, riscv, s390, sparc). The actual arm64 bug will be fixed >> in a separate commit. >> >> Cc: >> Fixes: 66b3923a1a0f ("arm64: hugetlb: add support for PTE contiguous bit") >> Signed-off-by: Ryan Roberts >> --- >> arch/arm64/include/asm/hugetlb.h | 4 ++-- >> arch/arm64/mm/hugetlbpage.c | 8 +++++--- >> arch/loongarch/include/asm/hugetlb.h | 6 ++++-- >> arch/mips/include/asm/hugetlb.h | 6 ++++-- >> arch/parisc/include/asm/hugetlb.h | 2 +- >> arch/parisc/mm/hugetlbpage.c | 2 +- >> arch/powerpc/include/asm/hugetlb.h | 6 ++++-- >> arch/riscv/include/asm/hugetlb.h | 3 ++- >> arch/riscv/mm/hugetlbpage.c | 2 +- >> arch/s390/include/asm/hugetlb.h | 12 ++++++++---- >> arch/s390/mm/hugetlbpage.c | 10 ++++++++-- >> arch/sparc/include/asm/hugetlb.h | 2 +- >> arch/sparc/mm/hugetlbpage.c | 2 +- >> include/asm-generic/hugetlb.h | 2 +- >> include/linux/hugetlb.h | 4 +++- >> mm/hugetlb.c | 4 ++-- >> 16 files changed, 48 insertions(+), 27 deletions(-) >> >> diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h >> index c6dff3e69539..03db9cb21ace 100644 >> --- a/arch/arm64/include/asm/hugetlb.h >> +++ b/arch/arm64/include/asm/hugetlb.h >> @@ -42,8 +42,8 @@ extern int huge_ptep_set_access_flags(struct vm_area_struct *vma, >> unsigned long addr, pte_t *ptep, >> pte_t pte, int dirty); >> #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR >> -extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, >> - unsigned long addr, pte_t *ptep); >> +extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, >> + pte_t *ptep, unsigned long sz); > > If VMA could be passed instead of MM, the size of the huge page can > be derived via huge_page_size(hstate_vma(vma)) and another argument > here need not be added. Also MM can be derived from VMA if required. I considered this approach; infact that's what I first implemented when fixing an equivalent bug on set_huge_pte_at() in the past. But that was problematic because there are some cases where the helper is used for kernel mappings (see vmalloc) and there is no VMA to pass in that case. See [1]. To fix this bug, usage of this helper for kernel mappings is not an issue (yet) so I guess technically it could be fixed by passing VMA. But later in this series I start using huge_ptep_get_and_clear() for the vmap (see patch 11) so it would break at that point. Another approach I considered was to allocate a spare swap-pte bit (we have a few) to indicate PTE_CONT for non-present PTEs. Then no API change is required at all. But given set_huge_pte_at() and huge_pte_clear() already pass "sz", it seemed best just to keep things simple and follow that pattern. [1] https://lore.kernel.org/all/20230922115804.2043771-1-ryan.roberts@arm.com/ Thanks, Ryan