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 A7DA1C25B79 for ; Tue, 28 May 2024 08:07:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 178E86B008C; Tue, 28 May 2024 04:07:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 129BB6B0092; Tue, 28 May 2024 04:07:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F337D6B0096; Tue, 28 May 2024 04:07:28 -0400 (EDT) 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 D5E3E6B008C for ; Tue, 28 May 2024 04:07:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7722B81668 for ; Tue, 28 May 2024 08:07:28 +0000 (UTC) X-FDA: 82167074976.17.51BB7B9 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by imf04.hostedemail.com (Postfix) with ESMTP id 7220E4000D for ; Tue, 28 May 2024 08:07:26 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of alex@ghiti.fr designates 217.70.183.197 as permitted sender) smtp.mailfrom=alex@ghiti.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716883646; 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=FSMWHOdEX12Zul1R/8Z449CEKQ9A5rONrW066n3Lp8s=; b=To59r1C4oF6ptkBGB4+iFvCpr+CD8w6fnsG4DClMiCBrqZ12jvfG2f0PMtbO+AjLaH7pNU XNp+Yw0PHIS4kDUPc4VCc+i210k6BY28t8NKrfetKZSzGhGVnfU39i7tDyzyB4VJQaSq/M Hnlm/r3eryToGY/vlbRsZRloUG4ZIP8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of alex@ghiti.fr designates 217.70.183.197 as permitted sender) smtp.mailfrom=alex@ghiti.fr ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716883646; a=rsa-sha256; cv=none; b=X/wmhEuY2AiYx0AmXhkxRP5ONErCE42cHTeJ1YIISBu0I3UfFjPbeLH7BlsCuYjDwOK/hR n5MrgcT14zUeRIE2qEfTb9sSkdh4GqT8+mlXEd52j8/aK9K3exbgmOPIF7li5Xcc6HVxfe 4En5eZtprksLwoNbeWRJAZpycOLf7a4= Received: by mail.gandi.net (Postfix) with ESMTPSA id D8D001C0002; Tue, 28 May 2024 08:07:21 +0000 (UTC) Message-ID: <863092ed-2b04-46bb-8d99-5796346cef3a@ghiti.fr> Date: Tue, 28 May 2024 10:07:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RESEND v2 0/9] Merge arm64/riscv hugetlbfs contpte support Content-Language: en-US To: Alexandre Ghiti , Ryan Roberts Cc: Catalin Marinas , Will Deacon , Mark Rutland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mm@kvack.org References: <20240508113419.18620-1-alexghiti@rivosinc.com> <6d37f914-d139-48ea-be63-c428ac767cc1@arm.com> From: Alexandre Ghiti In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-Sasl: alex@ghiti.fr X-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YPQ5yRf9VneF7MFHaHpyb xQ+VLbmo 0aOaLEmTBTIV6c4p2EJAYYW1twhFUMHwsrVw8Oc7M0T99Z8lwM/Lw31/I3/kAII3abxlU8oTQ4S/jNfnJ1wvSyKMllVLcLTzdGCjkkh69MycJSk0/W8JKjH6bbbM0sQrldZFmVoCa2ALxYNBtdAKlzdqot94ZA0aByCQDZW1Zy6y8YEkz4eqKchc7RRcC042rMwnbJtm0CddWEPafGOBl5qA9auqLvLEOtPKpm6/doHyVMwlMaZ3/btSSL6o75lRDiTisyUivIby0e4qgFNPy1MxOCj6IGg3B75Ub 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: Hi Ryan, On 12/05/2024 19:25, Alexandre Ghiti wrote: > Hi Ryan, > > On Fri, May 10, 2024 at 3:49 PM Ryan Roberts wrote: >> On 08/05/2024 12:34, Alexandre Ghiti wrote: >>> This patchset intends to merge the contiguous ptes hugetlbfs implementation >>> of arm64 and riscv. >>> >>> Both arm64 and riscv support the use of contiguous ptes to map pages that >>> are larger than the default page table size, respectively called contpte >>> and svnapot. >>> >>> The riscv implementation differs from the arm64's in that the LSBs of the >>> pfn of a svnapot pte are used to store the size of the mapping, allowing >>> for future sizes to be added (for now only 64KB is supported). That's an >>> issue for the core mm code which expects to find the *real* pfn a pte points >>> to. Patch 1 fixes that by always returning svnapot ptes with the real pfn >>> and restores the size of the mapping when it is written to a page table. >>> >>> The following patches are just merges of the 2 different implementations >>> that currently exist in arm64 and riscv which are very similar. It paves >>> the way to the reuse of the recent contpte THP work by Ryan [1] to avoid >>> reimplementing the same in riscv. >> Hi Alexandre, >> >> I've skimmed through this series and the one that moves contpte. I can see there >> is definitely value in sharing the implementation, and the rough shape of things >> seems appropriate. I had some minor concerns about making it harder to implement >> potential future arm64 errata workarounds but on reflection, most of the >> now-shared code is really just wrapping the primitives that are still arch-specific. >> >> I'm going to need to spend proper time reviewing it to give detailed feedback, >> but I'll be out on paternity leave for 3 weeks from end of Monday at the latest. > Too bad, I expected to discuss that with you at LSF/MM...But congrats! > Hope your wife is fine :) > >> So realistically I won't be able to do the detailed review until at least the >> first week of June. >> >> Some high level thoughts: >> >> - huge_ptep_* functions could be working on different sized huge ptes - arm64 >> supports contpte, pmd, contpmd and pud. Is keeping them in contpte.c >> appropriate? > Hmm indeed, I'll see what I can do. So I took a look at that. It amounts to doing the same as what we do for THP contptes, ie having both contpte-aware and "normal" APIs. Let's take for example huge_ptep_get(), below is what I get. To me it's not that bad, so I'll implement this unless there is strong opposition. diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index f8efbc128446..869a9aae6c68 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1715,6 +1715,16 @@ static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,                 contpte_clear_young_dirty_ptes(vma, addr, ptep, nr, flags);  } +static inline pte_t huge_ptep_get(pte_t *ptep) +{ +        pte_t orig_pte = __ptep_get(ptep); + +        if (!pte_present(orig_pte) || !pte_cont(orig_pte)) +                return orig_pte; + +        return contpte_huge_ptep_get(ptep); +} +  #else /* CONFIG_ARM64_CONTPTE */  #define ptep_get                               __ptep_get @@ -1736,6 +1746,8 @@ static inline void clear_young_dirty_ptes(struct vm_area_struct *vma,  #define ptep_set_access_flags __ptep_set_access_flags  #define clear_young_dirty_ptes __clear_young_dirty_ptes +#define huge_ptep_get                          __ptep_get +  #endif /* CONFIG_ARM64_CONTPTE */  #endif /* !__ASSEMBLY__ */ diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c index 3f09ac73cce3..aa0ee3f02226 100644 --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -127,28 +127,6 @@ static inline int num_contig_ptes(unsigned long size, size_t *pgsize)         return contig_ptes;  } -pte_t huge_ptep_get(pte_t *ptep) -{ -       int ncontig, i; -       size_t pgsize; -       pte_t orig_pte = __ptep_get(ptep); - -       if (!pte_present(orig_pte) || !pte_cont(orig_pte)) -               return orig_pte; - -       ncontig = num_contig_ptes(page_size(pte_page(orig_pte)), &pgsize); -       for (i = 0; i < ncontig; i++, ptep++) { -               pte_t pte = __ptep_get(ptep); - -               if (pte_dirty(pte)) -                       orig_pte = pte_mkdirty(orig_pte); - -               if (pte_young(pte)) -                       orig_pte = pte_mkyoung(orig_pte); -       } -       return orig_pte; -} -  /*   * Changing some bits of contiguous entries requires us to follow a   * Break-Before-Make approach, breaking the whole contiguous set diff --git a/mm/contpte.c b/mm/contpte.c new file mode 100644 index 000000000000..4e742cf00b6f --- /dev/null +++ b/mm/contpte.c @@ -0,0 +1,17 @@ +pte_t contpte_huge_ptep_get(pte_t *ptep) +{ +        int ncontig, i; +        size_t pgsize; + +        ncontig = num_contig_ptes(page_size(pte_page(orig_pte)), &pgsize); +        for (i = 0; i < ncontig; i++, ptep++) { +                pte_t pte = __ptep_get(ptep); + +                if (pte_dirty(pte)) +                        orig_pte = pte_mkdirty(orig_pte); + +                if (pte_young(pte)) +                        orig_pte = pte_mkyoung(orig_pte); +        } +        return orig_pte; +} > >> Perhaps it's better to keep huge_pte and contpte separate? Also, it >> only works on arm64 because we can get away with calling the lower-level pte >> functions even when the huge_pte is actually a contpmd/pmd/pud, because the >> format is the same. That might present challenges to other arches if the format >> is different? > Yes, but I think that if that happens, we could get away with it by > choosing the right function depending on the size of the mapping? > >> - It might be easier to review if the arm64 stuff is first moved (without >> changes) then modified to make it suitable for riscv, then for riscv to be >> hooked up. At the moment I'm trying to follow all 3 parts per-function. > Ok, let me give it a try during your paternity leave! > >> Thanks, >> Ryan > Thanks, > > Alex > >> >>> This patchset was tested by running the libhugetlbfs testsuite with 64KB >>> and 2MB pages on both architectures (on a 4KB base page size arm64 kernel). >>> >>> [1] https://lore.kernel.org/linux-arm-kernel/20240215103205.2607016-1-ryan.roberts@arm.com/ >>> >>> Changes in v2: >>> - Rebase on top of 6.9-rc3 >>> >>> Alexandre Ghiti (9): >>> riscv: Restore the pfn in a NAPOT pte when manipulated by core mm code >>> riscv: Safely remove huge_pte_offset() when manipulating NAPOT ptes >>> mm: Use common huge_ptep_get() function for riscv/arm64 >>> mm: Use common set_huge_pte_at() function for riscv/arm64 >>> mm: Use common huge_pte_clear() function for riscv/arm64 >>> mm: Use common huge_ptep_get_and_clear() function for riscv/arm64 >>> mm: Use common huge_ptep_set_access_flags() function for riscv/arm64 >>> mm: Use common huge_ptep_set_wrprotect() function for riscv/arm64 >>> mm: Use common huge_ptep_clear_flush() function for riscv/arm64 >>> >>> arch/arm64/Kconfig | 1 + >>> arch/arm64/include/asm/pgtable.h | 56 +++++- >>> arch/arm64/mm/hugetlbpage.c | 291 +--------------------------- >>> arch/riscv/Kconfig | 1 + >>> arch/riscv/include/asm/hugetlb.h | 2 +- >>> arch/riscv/include/asm/pgtable-64.h | 11 ++ >>> arch/riscv/include/asm/pgtable.h | 153 +++++++++++++-- >>> arch/riscv/mm/hugetlbpage.c | 227 ---------------------- >>> arch/riscv/mm/pgtable.c | 6 +- >>> mm/Kconfig | 3 + >>> mm/Makefile | 1 + >>> mm/contpte.c | 272 ++++++++++++++++++++++++++ >>> 12 files changed, 480 insertions(+), 544 deletions(-) >>> create mode 100644 mm/contpte.c >>> > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv