From: Alexandre Ghiti <alex@ghiti.fr>
To: Jisheng Zhang <jszhang@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>, Will Deacon <will@kernel.org>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Nick Piggin <npiggin@gmail.com>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 1/4] riscv: tlb: fix __p*d_free_tlb()
Date: Wed, 7 Feb 2024 08:28:01 +0100 [thread overview]
Message-ID: <6d03704c-e0b3-40e8-a0b1-6ad357a775d1@ghiti.fr> (raw)
In-Reply-To: <08f55d3e-d68e-406a-9bc9-d62f3c86e949@ghiti.fr>
Hi Jisheng,
On 31/12/2023 07:21, Alexandre Ghiti wrote:
> Hi Jisheng,
>
> On 19/12/2023 18:50, Jisheng Zhang wrote:
>> If non-leaf PTEs I.E pmd, pud or p4d is modified, a sfence.vma is
>> a must for safe, imagine if an implementation caches the non-leaf
>> translation in TLB, although I didn't meet this HW so far, but it's
>> possible in theory.
>>
>> Signed-off-by: Jisheng Zhang<jszhang@kernel.org>
>> ---
>> arch/riscv/include/asm/pgalloc.h | 20 +++++++++++++++++---
>> 1 file changed, 17 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/riscv/include/asm/pgalloc.h
>> b/arch/riscv/include/asm/pgalloc.h
>> index d169a4f41a2e..a12fb83fa1f5 100644
>> --- a/arch/riscv/include/asm/pgalloc.h
>> +++ b/arch/riscv/include/asm/pgalloc.h
>> @@ -95,7 +95,13 @@ static inline void pud_free(struct mm_struct *mm,
>> pud_t *pud)
>> __pud_free(mm, pud);
>> }
>> -#define __pud_free_tlb(tlb, pud, addr) pud_free((tlb)->mm, pud)
>> +#define __pud_free_tlb(tlb, pud, addr) \
>> +do { \
>> + if (pgtable_l4_enabled) { \
>> + pagetable_pud_dtor(virt_to_ptdesc(pud)); \
>> + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pud)); \
>
>
> The specification indeed states that an sfence.vma must be emitted
> after a page directory modification. Your change is not enough though
> since eventually tlb_flush() is called and in this function we should
> add:
>
> if (tlb->freed_tables)
> tlb_flush_mm();
I sent a patch for that here
https://lore.kernel.org/linux-riscv/20240128120405.25876-1-alexghiti@rivosinc.com/
You can add:
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Thanks,
Alex
>
> otherwise we are not guaranteed that a "global" sfence.vma is called.
>
> Would you be able to benchmark this change and see the performance
> impact?
>
> Thanks,
>
> Alex
>
>
>> + } \
>> +} while (0)
>> #define p4d_alloc_one p4d_alloc_one
>> static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned
>> long addr)
>> @@ -124,7 +130,11 @@ static inline void p4d_free(struct mm_struct
>> *mm, p4d_t *p4d)
>> __p4d_free(mm, p4d);
>> }
>> -#define __p4d_free_tlb(tlb, p4d, addr) p4d_free((tlb)->mm, p4d)
>> +#define __p4d_free_tlb(tlb, p4d, addr) \
>> +do { \
>> + if (pgtable_l5_enabled) \
>> + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(p4d)); \
>> +} while (0)
>> #endif /* __PAGETABLE_PMD_FOLDED */
>> static inline void sync_kernel_mappings(pgd_t *pgd)
>> @@ -149,7 +159,11 @@ static inline pgd_t *pgd_alloc(struct mm_struct
>> *mm)
>> #ifndef __PAGETABLE_PMD_FOLDED
>> -#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
>> +#define __pmd_free_tlb(tlb, pmd, addr) \
>> +do { \
>> + pagetable_pmd_dtor(virt_to_ptdesc(pmd)); \
>> + tlb_remove_page_ptdesc((tlb), virt_to_ptdesc(pmd)); \
>> +} while (0)
>> #endif /* __PAGETABLE_PMD_FOLDED */
>
next prev parent reply other threads:[~2024-02-07 7:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-19 17:50 [PATCH 0/4] riscv: support fast gup Jisheng Zhang
2023-12-19 17:50 ` [PATCH 1/4] riscv: tlb: fix __p*d_free_tlb() Jisheng Zhang
2023-12-31 6:21 ` Alexandre Ghiti
2024-02-07 7:28 ` Alexandre Ghiti [this message]
2024-01-04 10:55 ` Alexandre Ghiti
2024-01-10 14:52 ` Palmer Dabbelt
2023-12-19 17:50 ` [PATCH 2/4] riscv: tlb: convert __p*d_free_tlb() to inline functions Jisheng Zhang
2023-12-20 2:59 ` [External] " yunhui cui
2023-12-20 12:57 ` Jisheng Zhang
2023-12-31 6:24 ` Alexandre Ghiti
2023-12-19 17:50 ` [PATCH 3/4] riscv: enable MMU_GATHER_RCU_TABLE_FREE for SMP && MMU Jisheng Zhang
2023-12-31 6:32 ` Alexandre Ghiti
2024-01-02 3:23 ` Jisheng Zhang
2024-01-04 10:45 ` Alexandre Ghiti
2023-12-19 17:50 ` [PATCH 4/4] riscv: enable HAVE_FAST_GUP if MMU Jisheng Zhang
2023-12-31 6:37 ` Alexandre Ghiti
2024-01-02 3:25 ` Jisheng Zhang
2024-01-04 10:46 ` Alexandre Ghiti
2024-01-25 21:30 ` [PATCH 0/4] riscv: support fast gup patchwork-bot+linux-riscv
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6d03704c-e0b3-40e8-a0b1-6ad357a775d1@ghiti.fr \
--to=alex@ghiti.fr \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=aou@eecs.berkeley.edu \
--cc=jszhang@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).