From: Ma Wupeng mawupeng1@huawei.com
Enhanced maintenance and test capability for pbha. Enable ARM64_PBHA by default.
Changelog since v1: - let {pte,pmd}_pbha return false if pbha is not enabled
Ma Wupeng (7): proc: introduce proc_hide_ents to hide proc files arm64: mm: Cleanup in pbha_bit0_pte_range mm: cpufeature: Make update_pbha_perf_only_bit static arm64: mm: Do not show info during startup if pbha is not enabled arm64: mm: Hide pbha_bit0 in procfs if pbha is not enabled arm64: mm: pagemap: Export pbha bit0 info config: Enable ARM64_PBHA by default
Documentation/admin-guide/mm/pagemap.rst | 4 +++- arch/arm64/configs/openeuler_defconfig | 2 +- arch/arm64/kernel/cpufeature.c | 2 +- drivers/soc/hisilicon/pbha.c | 11 +++++------ fs/proc/base.c | 25 ++++++++++++++++++++++-- fs/proc/task_mmu.c | 15 ++++++++++++++ include/linux/pbha.h | 24 +++++++++++++++++++++++ 7 files changed, 72 insertions(+), 11 deletions(-)
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Introduce proc_hide_ents to hide proc files.
Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- fs/proc/base.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c index 88842619f830..4f30cef0b573 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -2847,6 +2847,11 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry, return d_splice_alias(inode, dentry); }
+static bool proc_hide_pidents(const struct pid_entry *p) +{ + return false; +} + static struct dentry *proc_pident_lookup(struct inode *dir, struct dentry *dentry, const struct pid_entry *p, @@ -2865,6 +2870,8 @@ static struct dentry *proc_pident_lookup(struct inode *dir, for (; p < end; p++) { if (p->len != dentry->d_name.len) continue; + if (proc_hide_pidents(p)) + continue; if (!memcmp(dentry->d_name.name, p->name, p->len)) { res = proc_pident_instantiate(dentry, task, p); break; @@ -2891,8 +2898,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx, goto out;
for (p = ents + (ctx->pos - 2); p < ents + nents; p++) { - if (!proc_fill_cache(file, ctx, p->name, p->len, - proc_pident_instantiate, task, p)) + if (!proc_hide_pidents(p) && + !proc_fill_cache(file, ctx, p->name, p->len, + proc_pident_instantiate, task, p)) break; ctx->pos++; }
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Remove unused variable.
Reported-by: kernel test robot lkp@intel.com Closes: https://lore.kernel.org/oe-kbuild-all/202403141207.Ix7wfVox-lkp@intel.com/ Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- drivers/soc/hisilicon/pbha.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/soc/hisilicon/pbha.c b/drivers/soc/hisilicon/pbha.c index 30d5057d8f95..79173154bf9c 100644 --- a/drivers/soc/hisilicon/pbha.c +++ b/drivers/soc/hisilicon/pbha.c @@ -99,7 +99,7 @@ static int pbha_bit0_pte_range(pmd_t *pmd, unsigned long addr, { int *op = (int *)walk->private; struct vm_area_struct *vma = walk->vma; - pte_t *pte, ptent; + pte_t *pte; spinlock_t *ptl; bool set = (*op == SET_PBHA_BIT0_FLAG);
@@ -115,11 +115,8 @@ static int pbha_bit0_pte_range(pmd_t *pmd, unsigned long addr, return 0;
pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); - for (; addr != end; pte++, addr += PAGE_SIZE) { - ptent = *pte; - + for (; addr != end; pte++, addr += PAGE_SIZE) pbha_bit0_update_pte_bits(vma, addr, pte, set); - } pte_unmap_unlock(pte - 1, ptl); cond_resched(); return 0;
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Since update_pbha_perf_only_bit is used by current file, make it static.
Reported-by: kernel test robot lkp@intel.com Closes: https://lore.kernel.org/oe-kbuild-all/202403131533.AIOfBKrb-lkp@intel.com/ Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- arch/arm64/kernel/cpufeature.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 5aabbbc74f28..9a4193991be5 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1687,7 +1687,7 @@ static void stage2_test_pbha_value(u8 val) arm64_pbha_stage2_safe_bits |= val; }
-void update_pbha_perf_only_bit(const u8 *bits, int cnt) +static void update_pbha_perf_only_bit(const u8 *bits, int cnt) { u8 val; int i;
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Do not show pbha related info during startup if pbha is not properly enabled. Param pbha is checked during efi-stub and kernel startup, however any param starts with "pbha" can lead to pbha related log info while pbha is not enabled since only "enable" or "user" is accepted by kernel. To solve this problem, only show this info if accepted args is passed to kernel.
Fixes: 3bef1e33a5dd ("arm64: mm: Introduce kernel param pbha") Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- drivers/soc/hisilicon/pbha.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/soc/hisilicon/pbha.c b/drivers/soc/hisilicon/pbha.c index 79173154bf9c..57daa5c338b5 100644 --- a/drivers/soc/hisilicon/pbha.c +++ b/drivers/soc/hisilicon/pbha.c @@ -197,7 +197,9 @@ static int __init setup_pbha(char *str) pbha_bit0_enabled = true; }
- pr_info("pbha bit_0 enabled, kernel: %d\n", pbha_bit0_kernel_enabled); + if (pbha_bit0_enabled) + pr_info("pbha bit_0 enabled, kernel: %d\n", + pbha_bit0_kernel_enabled);
return 0; }
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Hide pbha_bit0 in procfs if pbha is not enabled
Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- fs/proc/base.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/fs/proc/base.c b/fs/proc/base.c index 4f30cef0b573..4e0054a37c4c 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1450,6 +1450,16 @@ static const struct file_operations proc_pbha_bit0_ops = { .write = pbha_bit0_write, .llseek = generic_file_llseek, }; + +bool pbha_bit0_hide_file(const char *name) +{ + if (!system_support_pbha_bit0() && !strncmp("pbha_bit0", name, 9)) + return true; + + return false; +} +#else +static bool pbha_bit0_hide_file(const char *name) { return false; } #endif
#ifdef CONFIG_AUDIT @@ -2849,6 +2859,9 @@ static struct dentry *proc_pident_instantiate(struct dentry *dentry,
static bool proc_hide_pidents(const struct pid_entry *p) { + if (pbha_bit0_hide_file(p->name)) + return true; + return false; }
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
Bit 57 is used Commit fb8e37f35a2f ("mm/pagemap: export uffd-wp protection information"). Use bit 59 to improve future compatibility for pbha.
Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- Documentation/admin-guide/mm/pagemap.rst | 4 +++- fs/proc/task_mmu.c | 15 +++++++++++++++ include/linux/pbha.h | 24 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst index 2f472dd3ee9f..bfaa9a2aeb67 100644 --- a/Documentation/admin-guide/mm/pagemap.rst +++ b/Documentation/admin-guide/mm/pagemap.rst @@ -21,7 +21,9 @@ There are four components to pagemap: * Bit 55 pte is soft-dirty (see :ref:`Documentation/admin-guide/mm/soft-dirty.rst <soft_dirty>`) * Bit 56 page exclusively mapped (since 4.2) - * Bits 57-60 zero + * Bits 57-58 zero + * Bit 59 PBHA bit0, used only CONFIG_ARM64_PBHA is enabled + * Bits 60 zero * Bit 61 page is file-page or shared-anon (since 3.5) * Bit 62 page swapped * Bit 63 page present diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index d54e0e3474cc..e20e97fa9d1e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -20,6 +20,7 @@ #include <linux/uaccess.h> #include <linux/pkeys.h> #include <linux/module.h> +#include <linux/pbha.h>
#include <asm/elf.h> #include <asm/tlb.h> @@ -1327,6 +1328,11 @@ struct pagemapread { #define PM_PFRAME_MASK GENMASK_ULL(PM_PFRAME_BITS - 1, 0) #define PM_SOFT_DIRTY BIT_ULL(55) #define PM_MMAP_EXCLUSIVE BIT_ULL(56) +#ifdef CONFIG_ARM64_PBHA +#define PM_PBHA_BIT0 BIT_ULL(59) +#else +#define PM_PBHA_BIT0 BIT_ULL(0) +#endif #define PM_FILE BIT_ULL(61) #define PM_SWAP BIT_ULL(62) #define PM_PRESENT BIT_ULL(63) @@ -1419,6 +1425,9 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm, page = device_private_entry_to_page(entry); }
+ if (pte_pbha(pte)) + flags |= PM_PBHA_BIT0; + if (page && !PageAnon(page)) flags |= PM_FILE; if (page && !migration && page_mapcount(page) == 1) @@ -1479,6 +1488,9 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, } #endif
+ if (pmd_pbha(pmd)) + flags |= PM_PBHA_BIT0; + if (page && !migration && page_mapcount(page) == 1) flags |= PM_MMAP_EXCLUSIVE;
@@ -1711,6 +1723,9 @@ static int get_pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long pmd_t pmd = *pmdp; struct page *page = NULL;
+ if (pmd_pbha(pmd)) + flags |= PM_PBHA_BIT0; + if (pmd_present(pmd)) { page = pmd_page(pmd); flags |= PM_PRESENT; diff --git a/include/linux/pbha.h b/include/linux/pbha.h index 25cb88aa3d1c..45a4b07778bf 100644 --- a/include/linux/pbha.h +++ b/include/linux/pbha.h @@ -54,6 +54,22 @@ static inline pte_t maybe_mk_pbha_bit0(pte_t pte, struct vm_area_struct *vma)
return pte; } + +static inline bool pte_pbha(pte_t pte) +{ + if (!system_support_pbha_bit0()) + return false; + + return !!(pte_val(pte) & (PBHA_VAL_BIT0 << PBHA_BITS_SHIFT)); +} + +static inline bool pmd_pbha(pmd_t pmd) +{ + if (!system_support_pbha_bit0()) + return false; + + return !!(pmd_val(pmd) & (PBHA_VAL_BIT0 << PBHA_BITS_SHIFT)); +} #else static inline bool system_support_pbha_bit0(void) { return false; } static inline pgprot_t pgprot_pbha_bit0(pgprot_t prot) { return prot; } @@ -61,6 +77,14 @@ static inline pte_t maybe_mk_pbha_bit0(pte_t pte, struct vm_area_struct *vma) { return pte; } +static inline bool pte_pbha(pte_t pte) +{ + return false; +} +static inline bool pmd_pbha(pmd_t pte) +{ + return false; +} #endif
#endif
From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I96IZH
--------------------------------
ENABLE CONFIG_ARM64_PBHA for arm64 by default.
Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- arch/arm64/configs/openeuler_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/configs/openeuler_defconfig b/arch/arm64/configs/openeuler_defconfig index eafaeb54f808..5ad5e4378f2f 100644 --- a/arch/arm64/configs/openeuler_defconfig +++ b/arch/arm64/configs/openeuler_defconfig @@ -497,7 +497,7 @@ CONFIG_ARM64_VHE=y CONFIG_ARM64_PMEM=y CONFIG_ARM64_RAS_EXTN=y CONFIG_ARM64_CNP=y -# CONFIG_ARM64_PBHA is not set +CONFIG_ARM64_PBHA=y # end of ARMv8.2 architectural features
#
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/5375 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/K...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/5375 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/K...