[PATCH v2 09/12] arm64: mm: Always call PTE/PMD ctor in __create_pgd_mapping()

2025-04-10 Thread Kevin Brodsky
be called). Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 43 +++ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index eca324b3a6fc..51cfc891f6a1 100644 --- a/arch/arm64/mm/mmu.c +++ b/

[PATCH v2 04/12] m68k: mm: Call ctor/dtor for kernel PTEs

2025-04-10 Thread Kevin Brodsky
The generic implementation of pte_{alloc_one,free}_kernel now calls the [cd]tor. Align the m68k/ColdFire implementation of those functions by calling the [cd]tor explicitly. Signed-off-by: Kevin Brodsky --- arch/m68k/include/asm/mcf_pgalloc.h | 6 +- 1 file changed, 5 insertions(+), 1

Re: [PATCH v2 02/12] x86: pgtable: Always use pte_free_kernel()

2025-04-09 Thread Kevin Brodsky
On 08/04/2025 19:40, Matthew Wilcox wrote: > On Tue, Apr 08, 2025 at 09:54:42AM -0700, Dave Hansen wrote: >> On 4/8/25 09:37, Matthew Wilcox wrote: >>> On Tue, Apr 08, 2025 at 08:22:47AM -0700, Dave Hansen wrote: Are there any tests for folio_test_pgtable() at free_page() time? If we had

[PATCH v2 01/12] mm: Pass mm down to pagetable_{pte,pmd}_ctor

2025-04-08 Thread Kevin Brodsky
y not be associated to any mm. For now let's pass NULL as mm; this will be refined where possible in future patches. No functional change in this patch. Signed-off-by: Kevin Brodsky --- arch/arm/mm/mmu.c| 2 +- arch/arm64/mm/mmu.c | 4

[PATCH v2 02/12] x86: pgtable: Always use pte_free_kernel()

2025-04-08 Thread Kevin Brodsky
missing dtor calls in those helpers, free the PTE pages using pte_free_kernel() instead of free_page(). While at it also use pmd_free() instead of calling pagetable_dtor() explicitly at the PMD level. Signed-off-by: Kevin Brodsky --- arch/x86/mm/pgtable.c | 7 +++ 1 file changed, 3 insertions

[PATCH v2 10/12] riscv: mm: Clarify ctor mm argument in alloc_{pte,pmd}_late

2025-04-08 Thread Kevin Brodsky
. Signed-off-by: Kevin Brodsky --- arch/riscv/mm/init.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index e5ef693fc778..59a982f88908 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -442,6 +442,11 @@ static phys_addr_t

[PATCH v2 12/12] riscv: mm: Call PUD/P4D ctor in special kernel pgtable alloc

2025-04-08 Thread Kevin Brodsky
: Kevin Brodsky --- arch/riscv/mm/init.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 59a982f88908..8d0374d7ce8e 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -590,11 +590,11 @@ static

[PATCH v2 11/12] arm64: mm: Call PUD/P4D ctor in __create_pgd_mapping()

2025-04-08 Thread Kevin Brodsky
Constructors for PUD/P4D-level pgtables were recently introduced. They should be called for all pgtables; make sure they are called for special kernel mappings created by __create_pgd_mapping() too. Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 6 +- 1 file changed, 5 insertions

[PATCH v2 07/12] mm: Skip ptlock_init() for kernel PMDs

2025-04-08 Thread Kevin Brodsky
associated to init_mm. No special-casing is needed on the dtor path, as ptlock_free() is already called unconditionally for all levels. (ptlock_free() is a no-op unless a ptlock was allocated for the given PTP.) Signed-off-by: Kevin Brodsky --- include/linux/mm.h | 2 +- 1 file changed, 1 insertion

[PATCH v2 08/12] arm64: mm: Use enum to identify pgtable level instead of *_SHIFT

2025-04-08 Thread Kevin Brodsky
this way folding becomes irrelevant. This is inspired by one of the m68k pgtable allocators (arch/m68k/include/asm/motorola_pgalloc.h). Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 54 +++-- 1 file changed, 33 insertions(+), 21 deletions(-) d

[PATCH v2 05/12] powerpc: mm: Call ctor/dtor for kernel PTEs

2025-04-08 Thread Kevin Brodsky
differentiate user from kernel pgtables. This patch aligns the powerpc implementation with the generic one by calling pagetable_pte_[cd]tor() unconditionally in those helpers. Signed-off-by: Kevin Brodsky --- arch/powerpc/mm/pgtable-frag.c | 30 +- 1 file changed, 13 insertions

[PATCH v2 06/12] sparc64: mm: Call ctor/dtor for kernel PTEs

2025-04-08 Thread Kevin Brodsky
kernel and user alloc/free functions have the same implementation, and since pgtable_t is defined as pte_t *, we can have both call a common helper. Signed-off-by: Kevin Brodsky --- arch/sparc/mm/init_64.c | 27 +-- 1 file changed, 13 insertions(+), 14 deletions(-) diff

[PATCH v2 03/12] mm: Call ctor/dtor for kernel PTEs

2025-04-08 Thread Kevin Brodsky
/ Signed-off-by: Kevin Brodsky --- arch/csky/include/asm/pgalloc.h | 2 +- arch/microblaze/mm/pgtable.c| 2 +- arch/openrisc/mm/ioremap.c | 2 +- include/asm-generic/pgalloc.h | 7 ++- include/linux/mm.h | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff

[PATCH v2 00/12] Always call constructor for kernel page tables

2025-04-08 Thread Kevin Brodsky
ernel.org Cc: linux-arm-ker...@lists.infradead.org Cc: linux-c...@vger.kernel.org Cc: linux-ker...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-openr...@vger.kernel.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparcli...@vg

Re: [PATCH 00/11] Always call constructor for kernel page tables

2025-04-05 Thread Kevin Brodsky
On 17/03/2025 16:30, Ryan Roberts wrote: > On 17/03/2025 14:16, Kevin Brodsky wrote: >> The complications in those special pgtable allocators beg the question: >> does it really make sense to treat efi_mm and init_mm differently in >> e.g. apply_to_pte_range()? Maybe what we

Re: [PATCH 02/11] mm: Call ctor/dtor for kernel PTEs

2025-03-24 Thread Kevin Brodsky
On 17/03/2025 15:16, Kevin Brodsky wrote: > diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h > index e164ca66f0f6..3c8ec3bfea44 100644 > --- a/include/asm-generic/pgalloc.h > +++ b/include/asm-generic/pgalloc.h > @@ -23,6 +23,11 @@ stat

[PATCH 04/11] powerpc: mm: Call ctor/dtor for kernel PTEs

2025-03-17 Thread Kevin Brodsky
differentiate user from kernel pgtables. This patch aligns the powerpc implementation with the generic one by calling pagetable_pte_[cd]tor() unconditionally in those helpers. Signed-off-by: Kevin Brodsky --- arch/powerpc/mm/pgtable-frag.c | 30 +- 1 file changed, 13 insertions

[PATCH 10/11] arm64: mm: Call PUD/P4D ctor in __create_pgd_mapping()

2025-03-17 Thread Kevin Brodsky
Constructors for PUD/P4D-level pgtables were recently introduced. They should be called for all pgtables; make sure they are called for special kernel mappings created by __create_pgd_mapping() too. Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 6 +- 1 file changed, 5 insertions

[PATCH 09/11] riscv: mm: Clarify ctor mm argument in alloc_{pte,pmd}_late

2025-03-17 Thread Kevin Brodsky
. Signed-off-by: Kevin Brodsky --- arch/riscv/mm/init.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 703c3648cfa9..fb18940113f2 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -409,6 +409,11 @@ static phys_addr_t

[PATCH 03/11] m68k: mm: Call ctor/dtor for kernel PTEs

2025-03-17 Thread Kevin Brodsky
The generic implementation of pte_{alloc_one,free}_kernel now calls the [cd]tor. Align the m68k/ColdFire implementation of those functions by calling the [cd]tor explicitly. Signed-off-by: Kevin Brodsky --- arch/m68k/include/asm/mcf_pgalloc.h | 6 +- 1 file changed, 5 insertions(+), 1

[PATCH 00/11] Always call constructor for kernel page tables

2025-03-17 Thread Kevin Brodsky
...@lists.infradead.org Cc: linux-c...@vger.kernel.org Cc: linux-ker...@vger.kernel.org Cc: linux-m...@lists.linux-m68k.org Cc: linux-openr...@vger.kernel.org Cc: linux-ri...@lists.infradead.org Cc: linux-s...@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: sparcli...@vger.kernel.org --- Kevin Bro

[PATCH 11/11] riscv: mm: Call PUD/P4D ctor in special kernel pgtable alloc

2025-03-17 Thread Kevin Brodsky
: Kevin Brodsky --- arch/riscv/mm/init.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index fb18940113f2..dc2715f3fd00 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -557,11 +557,11 @@ static

[PATCH 08/11] arm64: mm: Always call PTE/PMD ctor in __create_pgd_mapping()

2025-03-17 Thread Kevin Brodsky
be called). Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 41 + 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index a7292ce9d7b8..accb0a33c59f 100644 --- a/arch/arm64/mm/mmu.c +++ b/

[PATCH 05/11] sparc64: mm: Call ctor/dtor for kernel PTEs

2025-03-17 Thread Kevin Brodsky
kernel and user alloc/free functions have the same implementation, and since pgtable_t is defined as pte_t *, we can have both call a common helper. Signed-off-by: Kevin Brodsky --- arch/sparc/mm/init_64.c | 27 +-- 1 file changed, 13 insertions(+), 14 deletions(-) diff

[PATCH 06/11] mm: Skip ptlock_init() for kernel PMDs

2025-03-17 Thread Kevin Brodsky
associated to init_mm. No special-casing is needed on the dtor path, as ptlock_free() is already called unconditionally for all levels. (ptlock_free() is a no-op unless a ptlock was allocated for the given PTP.) Signed-off-by: Kevin Brodsky --- include/linux/mm.h | 2 +- 1 file changed, 1 insertion

[PATCH 07/11] arm64: mm: Use enum to identify pgtable level instead of *_SHIFT

2025-03-17 Thread Kevin Brodsky
this way folding becomes irrelevant. This is inspired by one of the m68k pgtable allocators (arch/m68k/include/asm/motorola_pgalloc.h). Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 54 +++-- 1 file changed, 33 insertions(+), 21 deletions(-) d

[PATCH 02/11] mm: Call ctor/dtor for kernel PTEs

2025-03-17 Thread Kevin Brodsky
/ Signed-off-by: Kevin Brodsky --- arch/csky/include/asm/pgalloc.h | 2 +- arch/microblaze/mm/pgtable.c| 2 +- arch/openrisc/mm/ioremap.c | 2 +- include/asm-generic/pgalloc.h | 7 ++- include/linux/mm.h | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff

[PATCH 01/11] mm: Pass mm down to pagetable_{pte,pmd}_ctor

2025-03-17 Thread Kevin Brodsky
y not be associated to any mm. For now let's pass NULL as mm; this will be refined where possible in future patches. No functional change in this patch. Signed-off-by: Kevin Brodsky --- arch/arm/mm/mmu.c| 2 +- arch/arm64/mm/mmu.c | 4

Re: [PATCH v5 11/17] x86: pgtable: convert __tlb_remove_table() to use struct ptdesc

2025-01-08 Thread Kevin Brodsky
ree page table pages. > > Signed-off-by: Qi Zheng Definitely a good idea to have split patch 11 from v4. Reviewed-by: Kevin Brodsky - Kevin

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 07/01/2025 13:31, Qi Zheng wrote: > On 2025/1/7 19:58, Kevin Brodsky wrote: >> On 07/01/2025 11:51, Qi Zheng wrote: >>> [...] >>> >>> Author: Qi Zheng >>> Date:   Fri Dec 13 17:13:48 2024 +0800 >>> >>> mm: pgtable: c

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 07/01/2025 11:51, Qi Zheng wrote: > [...] > > Author: Qi Zheng > Date:   Fri Dec 13 17:13:48 2024 +0800 > >     mm: pgtable: completely move pagetable_dtor() to generic > tlb_remove_table() > >     For the generic tlb_remove_table(), it is implemented in the > following two >     forms: > >    

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 06/01/2025 04:49, Qi Zheng wrote: > [...] > >> Once this is done, we should be able to replace all those confusing >> calls to tlb_remove_page() on PTPs with tlb_remove_table() and remove >> the explicit call to pagetable_dtor(). AIUI this is essentially what >> Peter suggested on v3 [2]. > > Si

Re: [PATCH v4 07/15] mm: pgtable: introduce pagetable_dtor()

2025-01-07 Thread Kevin Brodsky
On 06/01/2025 14:23, Qi Zheng wrote: > On 2025/1/6 20:36, Alexander Gordeev wrote: >> On Mon, Jan 06, 2025 at 06:55:58PM +0800, Qi Zheng wrote: > +static inline void pagetable_dtor(struct ptdesc *ptdesc) > +{ > +    struct folio *folio = ptdesc_folio(ptdesc); > + > +    ptlock_f

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-03 Thread Kevin Brodsky
On 03/01/2025 10:35, Qi Zheng wrote: > On 2025/1/3 17:13, Qi Zheng wrote: >> On 2025/1/3 16:02, Kevin Brodsky wrote: >>> On 03/01/2025 04:48, Qi Zheng wrote: >>>> [...] >>>> >>>> In __tlb_batch_free_encoded_pages(), we can indeed detect PageT

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-03 Thread Kevin Brodsky
On 03/01/2025 04:48, Qi Zheng wrote: > Hi Kevin, > > On 2025/1/3 00:53, Kevin Brodsky wrote: >> On 30/12/2024 10:07, Qi Zheng wrote: >>>   static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, >>> void *pt) >>>   { >>&g

Re: [PATCH v4 04/15] mm: pgtable: add statistics for P4D level page table

2025-01-02 Thread Kevin Brodsky
On 03/01/2025 04:53, Qi Zheng wrote: > On 2025/1/3 00:53, Kevin Brodsky wrote: >> On 30/12/2024 10:07, Qi Zheng wrote: >>> diff --git a/arch/riscv/include/asm/pgalloc.h >>> b/arch/riscv/include/asm/pgalloc.h >>> index 551d614d3369c..3466fbe2e508d 100644 >&g

Re: [PATCH v4 00/15] move pagetable_*_dtor() to __tlb_remove_table()

2025-01-02 Thread Kevin Brodsky
ic pagetable_dtor_free() Aside from the nit on patch 4 and the request for clarification on patch 10, this is looking good to me, so for the whole series (aside from my own patches of course): Reviewed-by: Kevin Brodsky And happy new year! Cheers, - Kevin

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-02 Thread Kevin Brodsky
On 30/12/2024 10:07, Qi Zheng wrote: > static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) > { > - if (riscv_use_sbi_for_rfence()) > + if (riscv_use_sbi_for_rfence()) { > tlb_remove_ptdesc(tlb, pt); > - else > + } else { > + paget

Re: [PATCH v4 04/15] mm: pgtable: add statistics for P4D level page table

2025-01-02 Thread Kevin Brodsky
On 30/12/2024 10:07, Qi Zheng wrote: > diff --git a/arch/riscv/include/asm/pgalloc.h > b/arch/riscv/include/asm/pgalloc.h > index 551d614d3369c..3466fbe2e508d 100644 > --- a/arch/riscv/include/asm/pgalloc.h > +++ b/arch/riscv/include/asm/pgalloc.h > @@ -108,8 +108,12 @@ static inline void __pud_fr

Re: [PATCH v3 3/3] selftests/powerpc: Use PKEY_UNRESTRICTED macro

2024-10-28 Thread Kevin Brodsky
On 28/10/2024 10:07, Yury Khrustalev wrote: > Replace literal 0 with macro PKEY_UNRESTRICTED where pkey_*() functions > are used in mm selftests for memory protection keys for ppc target. > > Signed-off-by: Yury Khrustalev > Suggested-by: Kevin Brodsky Reviewed-by: Kevin Brodsky - Kevin

Re: [PATCH v5 19/30] arm64: add POE signal support

2024-10-17 Thread Kevin Brodsky
On 15/10/2024 17:01, Catalin Marinas wrote: >> We also still need to resolve Kevin's concern, which probably means >> keeping the thread's original POR around someplace. > If we fail to allocate context for POR_EL0 (or anything else), we'll > deliver a SIGSEGV. I think it's quite likely that the SI

Re: [PATCH v5 19/30] arm64: add POE signal support

2024-10-17 Thread Kevin Brodsky
;>>> On Wed, Oct 09, 2024 at 03:43:01PM +0100, Will Deacon wrote: >>>>> On Tue, Sep 24, 2024 at 01:27:58PM +0200, Kevin Brodsky wrote: >>>>>> On 22/08/2024 17:11, Joey Gouly wrote: >>>>>>> @@ -1178,6 +1237,9 @@ static

Re: [PATCH v5 19/30] arm64: add POE signal support

2024-09-24 Thread Kevin Brodsky
On 22/08/2024 17:11, Joey Gouly wrote: > @@ -1178,6 +1237,9 @@ static void setup_return(struct pt_regs *regs, struct > k_sigaction *ka, > sme_smstop(); > } > > + if (system_supports_poe()) > + write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0); At the point where setu

Re: [PATCH v5 06/30] arm64: context switch POR_EL0 register

2024-09-11 Thread Kevin Brodsky
On 22/08/2024 17:10, Joey Gouly wrote: > @@ -371,6 +382,9 @@ int copy_thread(struct task_struct *p, const struct > kernel_clone_args *args) > if (system_supports_tpidr2()) > p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); > > + if (system_sup

Re: [PATCH v4 06/29] arm64: context switch POR_EL0 register

2024-07-22 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > @@ -371,6 +382,9 @@ int copy_thread(struct task_struct *p, const struct > kernel_clone_args *args) > if (system_supports_tpidr2()) > p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); > > + if (system_sup

Re: [PATCH v4 17/29] arm64: implement PKEYS support

2024-07-22 Thread Kevin Brodsky
On 05/07/2024 18:59, Catalin Marinas wrote: > On Fri, May 03, 2024 at 02:01:35PM +0100, Joey Gouly wrote: >> @@ -163,7 +182,8 @@ static inline pteval_t __phys_to_pte_val(phys_addr_t >> phys) >> #define pte_access_permitted_no_overlay(pte, write) \ >> (((pte_val(pte) & (PTE_VALID | PTE_USER))

Re: [PATCH v4 28/29] kselftest/arm64: Add test case for POR_EL0 signal frame records

2024-07-09 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > +static uint64_t get_por_el0(void) > +{ > + uint64_t val; > + > + asm volatile ( > + "mrs%0, " SYS_POR_EL0 "\n" > + : "=r"(val) > + : > + : "cc"); Not sure why we would need "cc" for an MRS? __read

Re: [PATCH v4 22/29] arm64: add Permission Overlay Extension Kconfig

2024-07-09 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > Now that support for POE and Protection Keys has been implemented, add a > config to allow users to actually enable it. > > Signed-off-by: Joey Gouly > Cc: Catalin Marinas > Cc: Will Deacon > --- > arch/arm64/Kconfig | 22 ++ > 1 file

Re: [PATCH v4 18/29] arm64: add POE signal support

2024-07-09 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > @@ -1020,6 +1060,15 @@ static int setup_sigframe(struct > rt_sigframe_user_layout *user, > __put_user_error(current->thread.fault_code, &esr_ctx->esr, > err); > } > > + if (system_supports_poe() && err == 0 && user->poe_offset) {

Re: [PATCH v4 17/29] arm64: implement PKEYS support

2024-07-09 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > @@ -267,6 +294,28 @@ static inline unsigned long mm_untag_mask(struct > mm_struct *mm) > return -1UL >> 8; > } > > +/* > + * We only want to enforce protection keys on the current process > + * because we effectively have no access to POR_EL0 for o

Re: [PATCH v4 15/29] arm64: handle PKEY/POE faults

2024-07-09 Thread Kevin Brodsky
On 03/05/2024 15:01, Joey Gouly wrote: > [...] > > +static bool fault_from_pkey(unsigned long esr, struct vm_area_struct *vma, > + unsigned int mm_flags) > +{ > + unsigned long iss2 = ESR_ELx_ISS2(esr); > + > + if (!arch_pkeys_enabled()) > + return false; > +