sparc32: srmmu: improve type safety of __nocache_fix()
v2 cover sparc32: srmmu: improve type safety of __nocache_fix()
From: Mike Rapoport <[email protected]>
Hi,
As discussed at [1] the __nocache_fix() macro in sparc's SRMMU can be made type safe and so the compiler will yell anout misuse of pXd pointers for which the __nocache_fix() is primarily used.
The first patch is an fix of such misuse that I've discovered after adding type cast to __nocache_fix(), but to avoid breaking bisection I've made it the first commit.
v2: rebased on v5.8-rc2+
--
Sincerely yours,
Mike.
[1] https://lkml.kernel.org/r/CAHk-=wisORTa7QVPnFqNw9pFs62UiwgsD4C4d=MtYy1o4JPyGQ@mail.gmail.com
Mike Rapoport (2):
sparc32: use PUD rather than PGD to get PMD in srmmu_inherit_prom_mappings()
sparc32: srmmu: improve type safety of __nocache_fix()
arch/sparc/include/asm/pgtsrmmu.h | 2 +- arch/sparc/mm/srmmu.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-)
base-commit: 1590a2e1c681b0991bd42c992cabfd380e0338f2
Signature · 1 line
2.26.2
PATCH v2 1/2 sparc32: use PUD rather than PGD to get PMD in srmmu_inherit_prom_mappings()
From: Mike Rapoport <[email protected]>
This is a misprint in the page table traversal in srmmu_inherit_prom_mappings`() function which accessed a PMD entry using PGD rather than PUD.
Since sparc32 has only 3 page table levels, the PGD and PUD are essentially the same and usage of __nocache_fix() removed the type checking.
Use PUD for the consistency and to avoid breakage because of upcoming addition of type checking into __nocache_fix().
--- arch/sparc/mm/srmmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/srmmu.c +1 -1
@@ -822,7 +822,7 @@ static void __init srmmu_inherit_prom_mappings(unsigned long start,memset (__nocache_fix (pmdp),0 ,SRMMU_PMD_TABLE_SIZE );pud_set (__nocache_fix (pudp), pmdp); } - pmdp =pmd_offset (__nocache_fix (pgdp), start); + pmdp =pmd_offset (__nocache_fix (pudp), start);if (what =1 ) { *(pmd_t *)__nocache_fix (pmdp) =__pmd (probed); start +=PMD_SIZE ;
Signature · 1 line
2.26.2
PATCH v2 2/2 sparc32: srmmu: improve type safety of __nocache_fix()
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
The __nocache_fix(VADDR) macro is used to add an offset for pointers and its "return type" is 'void *'.
We can do better and keep the type information with simply by casting the return value to (__typeof__(VADDR)).
This will ".. show when those pgd/p4d/pud pointers get mis-used because they don't end up dropping the type info.."
The addition of the casting to __nocache_fix() also allows to remove explicit casts at its call sites.
--- arch/sparc/include/asm/pgtsrmmu.h | 2 +- arch/sparc/mm/srmmu.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-)
arch/sparc/include/asm/pgtsrmmu.h +1 -1
@@ -113,7 +113,7 @@ extern unsigned long last_valid_pfn;extern void *srmmu_nocache_pool;#define __nocache_pa (VADDR ) (((unsigned long)VADDR) - SRMMU_NOCACHE_VADDR + __pa((unsigned long)srmmu_nocache_pool))#define __nocache_va (PADDR ) (__va((unsigned long)PADDR) - (unsigned long)srmmu_nocache_pool + SRMMU_NOCACHE_VADDR) -#define __nocache_fix (VADDR ) __va(__nocache_pa(VADDR)) +#define __nocache_fix (VADDR ) ((__typeof__(VADDR))__va(__nocache_pa(VADDR)))/* Accessing the MMU control register. */ unsigned int srmmu_get_mmureg (void );
arch/sparc/mm/srmmu.c +8 -8
@@ -689,7 +689,7 @@ static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start, pgdp =pgd_offset_k (start); p4dp =p4d_offset (pgdp, start); pudp =pud_offset (p4dp, start); -if (pud_none (*(pud_t *)__nocache_fix (pudp))) { +if (pud_none (*__nocache_fix (pudp))) { pmdp =__srmmu_get_nocache (SRMMU_PMD_TABLE_SIZE ,SRMMU_PMD_TABLE_SIZE );if (pmdp =NULL )
@@ -698,7 +698,7 @@ static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start,pud_set (__nocache_fix (pudp), pmdp); } pmdp =pmd_offset (__nocache_fix (pudp), start); -if (srmmu_pmd_none (*(pmd_t *)__nocache_fix (pmdp))) { +if (srmmu_pmd_none (*__nocache_fix (pmdp))) { ptep =__srmmu_get_nocache (PTE_SIZE ,PTE_SIZE );if (ptep =NULL )early_pgtable_allocfail ("pte" );
@@ -810,11 +810,11 @@ static void __init srmmu_inherit_prom_mappings(unsigned long start, p4dp =p4d_offset (pgdp, start); pudp =pud_offset (p4dp, start);if (what =2 ) { - *(pgd_t *)__nocache_fix (pgdp) =__pgd (probed); + *__nocache_fix (pgdp) =__pgd (probed); start +=PGDIR_SIZE ;continue ; } -if (pud_none (*(pud_t *)__nocache_fix (pudp))) { +if (pud_none (*__nocache_fix (pudp))) { pmdp =__srmmu_get_nocache (SRMMU_PMD_TABLE_SIZE ,SRMMU_PMD_TABLE_SIZE );if (pmdp =NULL )
@@ -828,7 +828,7 @@ static void __init srmmu_inherit_prom_mappings(unsigned long start, start +=PMD_SIZE ;continue ; } -if (srmmu_pmd_none (*(pmd_t *)__nocache_fix (pmdp))) { +if (srmmu_pmd_none (*__nocache_fix (pmdp))) { ptep =__srmmu_get_nocache (PTE_SIZE ,PTE_SIZE );if (ptep =NULL )early_pgtable_allocfail ("pte" );
@@ -836,7 +836,7 @@ static void __init srmmu_inherit_prom_mappings(unsigned long start,pmd_set (__nocache_fix (pmdp), ptep); } ptep =pte_offset_kernel (__nocache_fix (pmdp), start); - *(pte_t *)__nocache_fix (ptep) =__pte (probed); + *__nocache_fix (ptep) =__pte (probed); start +=PAGE_SIZE ; } }
@@ -850,7 +850,7 @@ static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_baseunsigned long big_pte; big_pte =KERNEL_PTE (phys_base >>4 ); - *(pgd_t *)__nocache_fix (pgdp) =__pgd (big_pte); + *__nocache_fix (pgdp) =__pgd (big_pte); }/* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
@@ -940,7 +940,7 @@ void __init srmmu_paging_init(void) srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa (srmmu_context_table);for (i =0 ; i < num_contexts; i++) -srmmu_ctxd_set ((ctxd_t *)__nocache_fix (&srmmu_context_table[i]), srmmu_swapper_pg_dir); +srmmu_ctxd_set (__nocache_fix (&srmmu_context_table[i]), srmmu_swapper_pg_dir);flush_cache_all ();srmmu_set_ctable_ptr ((unsigned long )srmmu_ctx_table_phys);
Signature · 1 line
2.26.2
Gentle ping.
Quoted 32 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
Hi,
As discussed at [1] the
__nocache_fix()macro in sparc's SRMMU can be made type safe and so the compiler will yell anout misuse of pXd pointers for which the__nocache_fix()is primarily used.The first patch is an fix of such misuse that I've discovered after adding type cast to
__nocache_fix(), but to avoid breaking bisection I've made it the first commit.v2: rebased on v5.8-rc2+
--
Sincerely yours,
Mike.[1] https://lkml.kernel.org/r/CAHk-=wisORTa7QVPnFqNw9pFs62UiwgsD4C4d=MtYy1o4JPyGQ@mail.gmail.com
Mike Rapoport (2):
sparc32: use PUD rather than PGD to get PMD insrmmu_inherit_prom_mappings()
sparc32: srmmu: improve type safety of__nocache_fix()arch/sparc/include/asm/pgtsrmmu.h | 2 +- arch/sparc/mm/srmmu.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-)base-commit:
1590a2e1c681b0991bd42c992cabfd380e0338f2Signature · 1 line
2.26.2
Signature · 2 lines
Sincerely yours, Mike.
David Miller
maintainerFrom: Mike Rapoport <[email protected]>
Date: Sat, 27 Jun 2020 11:16:51 +0300
Quoted 8 lines
From: Mike Rapoport <[email protected]>
Hi,
As discussed at [1] the
__nocache_fix()macro in sparc's SRMMU can be made type safe and so the compiler will yell anout misuse of pXd pointers for which the__nocache_fix()is primarily used.
Quoted 5 lines
The first patch is an fix of such misuse that I've discovered after adding type cast to
__nocache_fix(), but to avoid breaking bisection I've made it the first commit.v2: rebased on v5.8-rc2+
Series applied, thanks Mike.