hide __pte2cachemode_tbl and __cachemode2pte_tbl
Hi all,
this series avoids pointlessly exposing the cachemode to pte bit translation tables to modules.
PATCH 1/4 x86/mm: Add a x86_has_pat_wp helper
Abstract the ioremap code away from the caching mode internals.
--- arch/x86/include/asm/memtype.h | 2 ++ arch/x86/mm/init.c | 6 ++++++ arch/x86/mm/ioremap.c | 8 ++------ 3 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/memtype.h +2 -0
@@ -24,4 +24,6 @@ extern void memtype_free_io(resource_size_t start, resource_size_t end);extern bool pat_pfn_immune_to_uc_mtrr (unsigned long pfn); +bool x86_has_pat_wp (void ); +#endif /* _ASM_X86_MEMTYPE_H */
arch/x86/mm/init.c +6 -0
@@ -71,6 +71,12 @@ uint8_t __pte2cachemode_tbl[8] = { };EXPORT_SYMBOL (__pte2cachemode_tbl); +/* Check that the write-protect PAT entry is set for write-protect */ +bool x86_has_pat_wp (void ) +{ +return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP; +} +static unsigned long __initdata pgt_buf_start;static unsigned long __initdata pgt_buf_end;static unsigned long __initdata pgt_buf_top;
arch/x86/mm/ioremap.c +2 -6
@@ -778,10 +778,8 @@ void __init *early_memremap_encrypted(resource_size_t phys_addr,void __init *early_memremap_encrypted_wp (resource_size_t phys_addr,unsigned long size) { -/* Be sure the write-protect PAT entry is set for write-protect */ -if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP) +if (!x86_has_pat_wp ())return NULL ; -return early_memremap_prot (phys_addr, size, __PAGE_KERNEL_ENC_WP); }
@@ -799,10 +797,8 @@ void __init *early_memremap_decrypted(resource_size_t phys_addr,void __init *early_memremap_decrypted_wp (resource_size_t phys_addr,unsigned long size) { -/* Be sure the write-protect PAT entry is set for write-protect */ -if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP) +if (!x86_has_pat_wp ())return NULL ; -return early_memremap_prot (phys_addr, size, __PAGE_KERNEL_NOENC_WP); }#endif /* CONFIG_AMD_MEM_ENCRYPT */
Signature · 1 line
2.25.1
[tip: x86/mm] x86/mm: Add a x86_has_pat_wp() helper
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 1f6f655e01adebf5bd5e6c3da2e843c104ded051 Gitweb: https://git.kernel.org/tip/1f6f655e01adebf5bd5e6c3da2e843c104ded051 Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:42 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Apr 2020 12:39:11 +02:00
x86/mm: Add a x86_has_pat_wp() helper
Abstract the ioremap code away from the caching mode internals.
--- arch/x86/include/asm/memtype.h | 2 ++ arch/x86/mm/init.c | 6 ++++++ arch/x86/mm/ioremap.c | 8 ++------ 3 files changed, 10 insertions(+), 6 deletions(-)
arch/x86/include/asm/memtype.h +2 -0
@@ -24,4 +24,6 @@ extern void memtype_free_io(resource_size_t start, resource_size_t end);extern bool pat_pfn_immune_to_uc_mtrr (unsigned long pfn); +bool x86_has_pat_wp (void ); +#endif /* _ASM_X86_MEMTYPE_H */
arch/x86/mm/init.c +6 -0
@@ -71,6 +71,12 @@ uint8_t __pte2cachemode_tbl[8] = { };EXPORT_SYMBOL (__pte2cachemode_tbl); +/* Check that the write-protect PAT entry is set for write-protect */ +bool x86_has_pat_wp (void ) +{ +return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP; +} +static unsigned long __initdata pgt_buf_start;static unsigned long __initdata pgt_buf_end;static unsigned long __initdata pgt_buf_top;
arch/x86/mm/ioremap.c +2 -6
@@ -778,10 +778,8 @@ void __init *early_memremap_encrypted(resource_size_t phys_addr,void __init *early_memremap_encrypted_wp (resource_size_t phys_addr,unsigned long size) { -/* Be sure the write-protect PAT entry is set for write-protect */ -if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP) +if (!x86_has_pat_wp ())return NULL ; -return early_memremap_prot (phys_addr, size, __PAGE_KERNEL_ENC_WP); }
@@ -799,10 +797,8 @@ void __init *early_memremap_decrypted(resource_size_t phys_addr,void __init *early_memremap_decrypted_wp (resource_size_t phys_addr,unsigned long size) { -/* Be sure the write-protect PAT entry is set for write-protect */ -if (__pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] != _PAGE_CACHE_MODE_WP) +if (!x86_has_pat_wp ())return NULL ; -return early_memremap_prot (phys_addr, size, __PAGE_KERNEL_NOENC_WP); }#endif /* CONFIG_AMD_MEM_ENCRYPT */
PATCH 2/4 x86/mm: Move pgprot2cachemode out of line
In reply to Christoph HellwigThis helper is only used by x86 low-level MM code. Also remove the entirely pointless __pte2cachemode_tbl export as that symbol can be marked static now.
--- arch/x86/include/asm/memtype.h | 1 + arch/x86/include/asm/pgtable_types.h | 10 ---------- arch/x86/mm/init.c | 13 +++++++++++-- 3 files changed, 12 insertions(+), 12 deletions(-)
arch/x86/include/asm/memtype.h +1 -0
@@ -25,5 +25,6 @@ extern void memtype_free_io(resource_size_t start, resource_size_t end);extern bool pat_pfn_immune_to_uc_mtrr (unsigned long pfn);bool x86_has_pat_wp (void ); +enum page_cache_mode pgprot2cachemode (pgprot_t pgprot);#endif /* _ASM_X86_MEMTYPE_H */
arch/x86/include/asm/pgtable_types.h +0 -10
@@ -468,7 +468,6 @@ static inline pteval_t pte_flags(pte_t pte) }extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; -extern uint8_t __pte2cachemode_tbl[8 ];#define __pte2cm_idx (cb) \ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \
@@ -489,15 +488,6 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm) {return __pgprot (cachemode2protval (pcm)); } -static inline enum page_cache_mode pgprot2cachemode (pgprot_t pgprot) -{ -unsigned long masked; - - masked =pgprot_val (pgprot) & _PAGE_CACHE_MASK; -if (likely (masked ==0 )) -return 0 ; -return __pte2cachemode_tbl[__pte2cm_idx (masked)]; -}static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) {pgprotval_t val =pgprot_val (pgprot);
arch/x86/mm/init.c +11 -2
@@ -59,7 +59,7 @@ uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { };EXPORT_SYMBOL (__cachemode2pte_tbl); -uint8_t __pte2cachemode_tbl[8 ] = { +static uint8_t __pte2cachemode_tbl[8 ] = { [__pte2cm_idx (0 |0 |0 )] = _PAGE_CACHE_MODE_WB, [__pte2cm_idx (_PAGE_PWT |0 |0 )] = _PAGE_CACHE_MODE_UC_MINUS, [__pte2cm_idx (0 | _PAGE_PCD |0 )] = _PAGE_CACHE_MODE_UC_MINUS,
@@ -69,7 +69,6 @@ uint8_t __pte2cachemode_tbl[8] = { [__pte2cm_idx(0 | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC_MINUS, [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC, }; -EXPORT_SYMBOL (__pte2cachemode_tbl);/* Check that the write-protect PAT entry is set for write-protect */ bool x86_has_pat_wp (void )
@@ -77,6 +76,16 @@ bool x86_has_pat_wp(void)return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP; } +enum page_cache_mode pgprot2cachemode (pgprot_t pgprot) +{ +unsigned long masked; + + masked =pgprot_val (pgprot) & _PAGE_CACHE_MASK; +if (likely (masked ==0 )) +return 0 ; +return __pte2cachemode_tbl[__pte2cm_idx (masked)]; +} +static unsigned long __initdata pgt_buf_start;static unsigned long __initdata pgt_buf_end;static unsigned long __initdata pgt_buf_top;
Signature · 1 line
2.25.1
[tip: x86/mm] x86/mm: Move pgprot2cachemode out of line
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 7fa3e10f0f3646108a1018004d0f571c3222dc9f Gitweb: https://git.kernel.org/tip/7fa3e10f0f3646108a1018004d0f571c3222dc9f Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:43 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Apr 2020 12:39:17 +02:00
x86/mm: Move pgprot2cachemode out of line
This helper is only used by x86 low-level MM code. Also remove the entirely pointless __pte2cachemode_tbl export as that symbol can be marked static now.
--- arch/x86/include/asm/memtype.h | 1 + arch/x86/include/asm/pgtable_types.h | 10 ---------- arch/x86/mm/init.c | 13 +++++++++++-- 3 files changed, 12 insertions(+), 12 deletions(-)
arch/x86/include/asm/memtype.h +1 -0
@@ -25,5 +25,6 @@ extern void memtype_free_io(resource_size_t start, resource_size_t end);extern bool pat_pfn_immune_to_uc_mtrr (unsigned long pfn);bool x86_has_pat_wp (void ); +enum page_cache_mode pgprot2cachemode (pgprot_t pgprot);#endif /* _ASM_X86_MEMTYPE_H */
arch/x86/include/asm/pgtable_types.h +0 -10
@@ -468,7 +468,6 @@ static inline pteval_t pte_flags(pte_t pte) }extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; -extern uint8_t __pte2cachemode_tbl[8 ];#define __pte2cm_idx (cb) \ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \
@@ -489,15 +488,6 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm) {return __pgprot (cachemode2protval (pcm)); } -static inline enum page_cache_mode pgprot2cachemode (pgprot_t pgprot) -{ -unsigned long masked; - - masked =pgprot_val (pgprot) & _PAGE_CACHE_MASK; -if (likely (masked ==0 )) -return 0 ; -return __pte2cachemode_tbl[__pte2cm_idx (masked)]; -}static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) {pgprotval_t val =pgprot_val (pgprot);
arch/x86/mm/init.c +11 -2
@@ -59,7 +59,7 @@ uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { };EXPORT_SYMBOL (__cachemode2pte_tbl); -uint8_t __pte2cachemode_tbl[8 ] = { +static uint8_t __pte2cachemode_tbl[8 ] = { [__pte2cm_idx (0 |0 |0 )] = _PAGE_CACHE_MODE_WB, [__pte2cm_idx (_PAGE_PWT |0 |0 )] = _PAGE_CACHE_MODE_UC_MINUS, [__pte2cm_idx (0 | _PAGE_PCD |0 )] = _PAGE_CACHE_MODE_UC_MINUS,
@@ -69,7 +69,6 @@ uint8_t __pte2cachemode_tbl[8] = { [__pte2cm_idx(0 | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC_MINUS, [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC, }; -EXPORT_SYMBOL (__pte2cachemode_tbl);/* Check that the write-protect PAT entry is set for write-protect */ bool x86_has_pat_wp (void )
@@ -77,6 +76,16 @@ bool x86_has_pat_wp(void)return __pte2cachemode_tbl[_PAGE_CACHE_MODE_WP] == _PAGE_CACHE_MODE_WP; } +enum page_cache_mode pgprot2cachemode (pgprot_t pgprot) +{ +unsigned long masked; + + masked =pgprot_val (pgprot) & _PAGE_CACHE_MASK; +if (likely (masked ==0 )) +return 0 ; +return __pte2cachemode_tbl[__pte2cm_idx (masked)]; +} +static unsigned long __initdata pgt_buf_start;static unsigned long __initdata pgt_buf_end;static unsigned long __initdata pgt_buf_top;
PATCH 3/4 x86/mm: Cleanup pgprot_4k_2_large and pgprot_large_2_4k
In reply to Christoph HellwigMake use of lower level helpers that operate on the raw protection values to make the code a little easier to understand, and to also avoid extra conversions in a few callers.
--- arch/x86/include/asm/pgtable_types.h | 26 +++++++++++++------------- arch/x86/mm/init_64.c | 2 +- arch/x86/mm/pgtable.c | 8 ++------ 3 files changed, 16 insertions(+), 20 deletions(-)
arch/x86/include/asm/pgtable_types.h +13 -13
@@ -488,24 +488,24 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm) {return __pgprot (cachemode2protval (pcm)); } -static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +static inline unsigned long protval_4k_2_large (unsigned long val) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | ((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +} +static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +{ +return __pgprot (protval_4k_2_large (pgprot_val (pgprot))); +} +static inline unsigned long protval_large_2_4k (unsigned long val) +{ +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | + ((val & _PAGE_PAT_LARGE) >> + (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); }static inline pgprot_t pgprot_large_2_4k (pgprot_t pgprot) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | - ((val & _PAGE_PAT_LARGE) >> - (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +return __pgprot (protval_large_2_4k (pgprot_val (pgprot))); }
arch/x86/mm/init_64.c +1 -1
@@ -367,7 +367,7 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,pgprot_t prot;pgprot_val (prot) =pgprot_val (PAGE_KERNEL_LARGE ) | -pgprot_val (pgprot_4k_2_large (cachemode2pgprot (cache))); +protval_4k_2_large (cachemode2protval (cache));BUG_ON ((phys & ~PMD_MASK ) || (size & ~PMD_MASK ));for (; size; phys +=PMD_SIZE , size -=PMD_SIZE ) { pgd =pgd_offset_k ((unsigned long )__va (phys));
arch/x86/mm/pgtable.c +2 -6
@@ -706,11 +706,9 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)if (pud_present (*pud) && !pud_huge (*pud))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pud,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot) | _PAGE_PSE))));return 1 ; }
@@ -738,11 +736,9 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)if (pmd_present (*pmd) && !pmd_huge (*pmd))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pmd,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot)) | _PAGE_PSE)));return 1 ; }
Signature · 1 line
2.25.1
[tip: x86/mm] x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 9e294786c89ae0904932c06d79e5e1c044864f65 Gitweb: https://git.kernel.org/tip/9e294786c89ae0904932c06d79e5e1c044864f65 Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:44 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Apr 2020 12:39:22 +02:00
x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()
Make use of lower level helpers that operate on the raw protection values to make the code a little easier to understand, and to also avoid extra conversions in a few callers.
--- arch/x86/include/asm/pgtable_types.h | 26 +++++++++++++------------- arch/x86/mm/init_64.c | 2 +- arch/x86/mm/pgtable.c | 8 ++------ 3 files changed, 16 insertions(+), 20 deletions(-)
arch/x86/include/asm/pgtable_types.h +13 -13
@@ -488,24 +488,24 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm) {return __pgprot (cachemode2protval (pcm)); } -static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +static inline unsigned long protval_4k_2_large (unsigned long val) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | ((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +} +static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +{ +return __pgprot (protval_4k_2_large (pgprot_val (pgprot))); +} +static inline unsigned long protval_large_2_4k (unsigned long val) +{ +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | + ((val & _PAGE_PAT_LARGE) >> + (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); }static inline pgprot_t pgprot_large_2_4k (pgprot_t pgprot) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | - ((val & _PAGE_PAT_LARGE) >> - (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +return __pgprot (protval_large_2_4k (pgprot_val (pgprot))); }
arch/x86/mm/init_64.c +1 -1
@@ -367,7 +367,7 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,pgprot_t prot;pgprot_val (prot) =pgprot_val (PAGE_KERNEL_LARGE ) | -pgprot_val (pgprot_4k_2_large (cachemode2pgprot (cache))); +protval_4k_2_large (cachemode2protval (cache));BUG_ON ((phys & ~PMD_MASK ) || (size & ~PMD_MASK ));for (; size; phys +=PMD_SIZE , size -=PMD_SIZE ) { pgd =pgd_offset_k ((unsigned long )__va (phys));
arch/x86/mm/pgtable.c +2 -6
@@ -706,11 +706,9 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)if (pud_present (*pud) && !pud_huge (*pud))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pud,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot) | _PAGE_PSE))));return 1 ; }
@@ -738,11 +736,9 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)if (pmd_present (*pmd) && !pmd_huge (*pmd))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pmd,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot)) | _PAGE_PSE)));return 1 ; }
[tip: x86/mm] x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()
In reply to Christoph HellwigThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: d073569363d9f076a568ce8c31250d332ccf33ce Gitweb: https://git.kernel.org/tip/d073569363d9f076a568ce8c31250d332ccf33ce Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:44 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 23 Apr 2020 11:31:52 +02:00
x86/mm: Cleanup pgprot_4k_2_large() and pgprot_large_2_4k()
Make use of lower level helpers that operate on the raw protection values to make the code a little easier to understand, and to also avoid extra conversions in a few callers.
[ Qian: Fix a wrongly placed bracket in the original submission.
Reported and fixed by Qian Cai <[email protected]>. Details in second
Link: below. ]
--- arch/x86/include/asm/pgtable_types.h | 26 +++++++++++++------------- arch/x86/mm/init_64.c | 2 +- arch/x86/mm/pgtable.c | 8 ++------ 3 files changed, 16 insertions(+), 20 deletions(-)
arch/x86/include/asm/pgtable_types.h +13 -13
@@ -488,24 +488,24 @@ static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm) {return __pgprot (cachemode2protval (pcm)); } -static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +static inline unsigned long protval_4k_2_large (unsigned long val) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | ((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +} +static inline pgprot_t pgprot_4k_2_large (pgprot_t pgprot) +{ +return __pgprot (protval_4k_2_large (pgprot_val (pgprot))); +} +static inline unsigned long protval_large_2_4k (unsigned long val) +{ +return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | + ((val & _PAGE_PAT_LARGE) >> + (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); }static inline pgprot_t pgprot_large_2_4k (pgprot_t pgprot) { -pgprotval_t val =pgprot_val (pgprot); -pgprot_t new; - -pgprot_val (new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) | - ((val & _PAGE_PAT_LARGE) >> - (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT)); -return new; +return __pgprot (protval_large_2_4k (pgprot_val (pgprot))); }
arch/x86/mm/init_64.c +1 -1
@@ -367,7 +367,7 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,pgprot_t prot;pgprot_val (prot) =pgprot_val (PAGE_KERNEL_LARGE ) | -pgprot_val (pgprot_4k_2_large (cachemode2pgprot (cache))); +protval_4k_2_large (cachemode2protval (cache));BUG_ON ((phys & ~PMD_MASK ) || (size & ~PMD_MASK ));for (; size; phys +=PMD_SIZE , size -=PMD_SIZE ) { pgd =pgd_offset_k ((unsigned long )__va (phys));
arch/x86/mm/pgtable.c +2 -6
@@ -706,11 +706,9 @@ int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)if (pud_present (*pud) && !pud_huge (*pud))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pud,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot)) | _PAGE_PSE)));return 1 ; }
@@ -738,11 +736,9 @@ int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot)if (pmd_present (*pmd) && !pmd_huge (*pmd))return 0 ; - prot =pgprot_4k_2_large (prot); -set_pte ((pte_t *)pmd,pfn_pte ( (u64 )addr >>PAGE_SHIFT , -__pgprot (pgprot_val (prot) | _PAGE_PSE))); +__pgprot (protval_4k_2_large (pgprot_val (prot)) | _PAGE_PSE)));return 1 ; }
PATCH 4/4 x86/mm: Unexport __cachemode2pte_tbl
In reply to Christoph HellwigExporting the raw data for a table is generally a bad idea. Move cachemode2protval out of line given that it isn't really used in the fast path, and then mark __cachemode2pte_tbl static.
--- arch/x86/include/asm/pgtable_types.h | 14 ++------------ arch/x86/mm/init.c | 11 +++++++++-- arch/x86/mm/pat/set_memory.c | 5 +++++ 3 files changed, 16 insertions(+), 14 deletions(-)
arch/x86/include/asm/pgtable_types.h +2 -12
@@ -467,8 +467,6 @@ static inline pteval_t pte_flags(pte_t pte)return native_pte_val (pte) &PTE_FLAGS_MASK ; } -extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; -#define __pte2cm_idx (cb) \ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \ (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) | \
@@ -478,16 +476,8 @@ extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; (((i) & 2) << (_PAGE_BIT_PCD - 1)) | \ (((i) & 1) << _PAGE_BIT_PWT)) -static inline unsigned long cachemode2protval (enum page_cache_mode pcm) -{ -if (likely (pcm ==0 )) -return 0 ; -return __cachemode2pte_tbl[pcm]; -} -static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) -{ -return __pgprot (cachemode2protval (pcm)); -} +unsigned long cachemode2protval (enum page_cache_mode pcm); +static inline unsigned long protval_4k_2_large (unsigned long val) { return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
arch/x86/mm/init.c +9 -2
@@ -49,7 +49,7 @@* Index into __pte2cachemode_tbl[] are the caching attribute bits of the pte * (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2. */ -uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { +static uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WB ] =0 |0 , [_PAGE_CACHE_MODE_WC ] =0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC_MINUS] =0 | _PAGE_PCD,
@@ -57,7 +57,14 @@ uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD, }; -EXPORT_SYMBOL (__cachemode2pte_tbl ); + +unsigned long cachemode2protval (enum page_cache_mode pcm) +{ +if (likely (pcm ==0 )) +return 0 ; +return __cachemode2pte_tbl[pcm]; +} +EXPORT_SYMBOL (cachemode2protval);static uint8_t __pte2cachemode_tbl[8 ] = { [__pte2cm_idx (0 |0 |0 )] = _PAGE_CACHE_MODE_WB,
arch/x86/mm/pat/set_memory.c +5 -0
@@ -68,6 +68,11 @@ static DEFINE_SPINLOCK(cpa_lock);#define CPA_PAGES_ARRAY 4#define CPA_NO_CHECK_ALIAS 8/* Do not search for aliases */ +static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) +{ +return __pgprot (cachemode2protval (pcm)); +} +#ifdef CONFIG_PROC_FS static unsigned long direct_pages_count[PG_LEVEL_NUM ];
Signature · 1 line
2.25.1
[tip: x86/mm] x86/mm: Unexport __cachemode2pte_tbl
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: a85573f7e74191e5f5500c45fb4ec79cdfe13a08 Gitweb: https://git.kernel.org/tip/a85573f7e74191e5f5500c45fb4ec79cdfe13a08 Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:45 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 20 Apr 2020 12:39:31 +02:00
x86/mm: Unexport __cachemode2pte_tbl
Exporting the raw data for a table is generally a bad idea. Move cachemode2protval() out of line given that it isn't really used in the fast path, and then mark __cachemode2pte_tbl static.
--- arch/x86/include/asm/pgtable_types.h | 14 ++------------ arch/x86/mm/init.c | 11 +++++++++-- arch/x86/mm/pat/set_memory.c | 5 +++++ 3 files changed, 16 insertions(+), 14 deletions(-)
arch/x86/include/asm/pgtable_types.h +2 -12
@@ -467,8 +467,6 @@ static inline pteval_t pte_flags(pte_t pte)return native_pte_val (pte) &PTE_FLAGS_MASK ; } -extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; -#define __pte2cm_idx (cb) \ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \ (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) | \
@@ -478,16 +476,8 @@ extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; (((i) & 2) << (_PAGE_BIT_PCD - 1)) | \ (((i) & 1) << _PAGE_BIT_PWT)) -static inline unsigned long cachemode2protval (enum page_cache_mode pcm) -{ -if (likely (pcm ==0 )) -return 0 ; -return __cachemode2pte_tbl[pcm]; -} -static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) -{ -return __pgprot (cachemode2protval (pcm)); -} +unsigned long cachemode2protval (enum page_cache_mode pcm); +static inline unsigned long protval_4k_2_large (unsigned long val) { return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
arch/x86/mm/init.c +9 -2
@@ -49,7 +49,7 @@* Index into __pte2cachemode_tbl[] are the caching attribute bits of the pte * (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2. */ -uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { +static uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WB ] =0 |0 , [_PAGE_CACHE_MODE_WC ] =0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC_MINUS] =0 | _PAGE_PCD,
@@ -57,7 +57,14 @@ uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD, }; -EXPORT_SYMBOL (__cachemode2pte_tbl ); + +unsigned long cachemode2protval (enum page_cache_mode pcm) +{ +if (likely (pcm ==0 )) +return 0 ; +return __cachemode2pte_tbl[pcm]; +} +EXPORT_SYMBOL (cachemode2protval);static uint8_t __pte2cachemode_tbl[8 ] = { [__pte2cm_idx (0 |0 |0 )] = _PAGE_CACHE_MODE_WB,
arch/x86/mm/pat/set_memory.c +5 -0
@@ -68,6 +68,11 @@ static DEFINE_SPINLOCK(cpa_lock);#define CPA_PAGES_ARRAY 4#define CPA_NO_CHECK_ALIAS 8/* Do not search for aliases */ +static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) +{ +return __pgprot (cachemode2protval (pcm)); +} +#ifdef CONFIG_PROC_FS static unsigned long direct_pages_count[PG_LEVEL_NUM ];
[tip: x86/mm] x86/mm: Unexport __cachemode2pte_tbl
In reply to Christoph HellwigThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: de17a37896e1ad9e17ebd5274a50c33e18c9cb90 Gitweb: https://git.kernel.org/tip/de17a37896e1ad9e17ebd5274a50c33e18c9cb90 Author: Christoph Hellwig <[email protected]> AuthorDate: Wed, 08 Apr 2020 17:27:45 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 23 Apr 2020 11:34:31 +02:00
x86/mm: Unexport __cachemode2pte_tbl
Exporting the raw data for a table is generally a bad idea. Move cachemode2protval() out of line given that it isn't really used in the fast path, and then mark __cachemode2pte_tbl static.
--- arch/x86/include/asm/pgtable_types.h | 14 ++------------ arch/x86/mm/init.c | 11 +++++++++-- arch/x86/mm/pat/set_memory.c | 5 +++++ 3 files changed, 16 insertions(+), 14 deletions(-)
arch/x86/include/asm/pgtable_types.h +2 -12
@@ -467,8 +467,6 @@ static inline pteval_t pte_flags(pte_t pte)return native_pte_val (pte) &PTE_FLAGS_MASK ; } -extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; -#define __pte2cm_idx (cb) \ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \ (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) | \
@@ -478,16 +476,8 @@ extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM]; (((i) & 2) << (_PAGE_BIT_PCD - 1)) | \ (((i) & 1) << _PAGE_BIT_PWT)) -static inline unsigned long cachemode2protval (enum page_cache_mode pcm) -{ -if (likely (pcm ==0 )) -return 0 ; -return __cachemode2pte_tbl[pcm]; -} -static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) -{ -return __pgprot (cachemode2protval (pcm)); -} +unsigned long cachemode2protval (enum page_cache_mode pcm); +static inline unsigned long protval_4k_2_large (unsigned long val) { return (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
arch/x86/mm/init.c +9 -2
@@ -49,7 +49,7 @@* Index into __pte2cachemode_tbl[] are the caching attribute bits of the pte * (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2. */ -uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { +static uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WB ] =0 |0 , [_PAGE_CACHE_MODE_WC ] =0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC_MINUS] =0 | _PAGE_PCD,
@@ -57,7 +57,14 @@ uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = { [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD, }; -EXPORT_SYMBOL (__cachemode2pte_tbl ); + +unsigned long cachemode2protval (enum page_cache_mode pcm) +{ +if (likely (pcm ==0 )) +return 0 ; +return __cachemode2pte_tbl[pcm]; +} +EXPORT_SYMBOL (cachemode2protval);static uint8_t __pte2cachemode_tbl[8 ] = { [__pte2cm_idx (0 |0 |0 )] = _PAGE_CACHE_MODE_WB,
arch/x86/mm/pat/set_memory.c +5 -0
@@ -68,6 +68,11 @@ static DEFINE_SPINLOCK(cpa_lock);#define CPA_PAGES_ARRAY 4#define CPA_NO_CHECK_ALIAS 8/* Do not search for aliases */ +static inline pgprot_t cachemode2pgprot (enum page_cache_mode pcm) +{ +return __pgprot (cachemode2protval (pcm)); +} +#ifdef CONFIG_PROC_FS static unsigned long direct_pages_count[PG_LEVEL_NUM ];
Quoted 4 lines · Christoph Hellwig
Hi all,
this series avoids pointlessly exposing the cachemode to pte bit translation tables to modules.
Any comments?
Quoted 4 lines · Christoph Hellwig
Hi all,
this series avoids pointlessly exposing the cachemode to pte bit translation tables to modules.
Nice!