From d2f635d03be9896de67987c7f2f122bcb25e4ad7 Mon Sep 17 00:00:00 2001 From: Kanglong Wang Date: Thu, 18 Jun 2026 16:35:50 +0800 Subject: [PATCH 1/3] module: Optimize function definition in include/linux/module.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ANBZ: #38133 commit 32a08c17d8096f0fd2c6600bc5fe8464aaf68ea7 upstream. When the CONFIG_STRICT_MODULE_RWX is disabled in an architecture, the following error will occur, which is unreasonable. The architecture's configuration file and code should be independent of each other. ''' kernel/module/strict_rwx.c:53:6: error: redefinition of ‘module_enable_ro’ 53 | void module_enable_ro(const struct module *mod, bool after_init) | ^~~~~~~~~~~~~~~~ In file included from kernel/module/strict_rwx.c:8: ./include/linux/module.h:898:20: note: previous definition of ‘module_enable_ro’ with type ‘void(const struct module *, bool)’ {aka ‘void(const struct module *, _Bool)’} 898 | static inline void module_enable_ro(const struct module *mod, bool after_init) { } | ^~~~~~~~~~~~~~~~ make[4]: *** [scripts/Makefile.build:243: kernel/module/strict_rwx.o] Error 1 ''' The patch applies some modifications submitted upstream, removing inline function declarations from the 'include/linux/module.h', as the relevant cases were already handled in the 'kernel/module/strict_rwx.c'. Signed-off-by: Kanglong Wang Link: https://gitee.com/anolis/cloud-kernel/pulls/8312 --- include/linux/module.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/linux/module.h b/include/linux/module.h index e0223172a574..82f6ecc9360a 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -891,13 +891,8 @@ extern const struct kobj_type module_ktype; #define __MODULE_STRING(x) __stringify(x) -#ifdef CONFIG_STRICT_MODULE_RWX extern void module_enable_ro(const struct module *mod, bool after_init); extern void module_disable_ro(const struct module *mod); -#else -static inline void module_enable_ro(const struct module *mod, bool after_init) { } -static inline void module_disable_ro(const struct module *mod) { } -#endif #ifdef CONFIG_GENERIC_BUG void module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *, -- Gitee From a37d232834e5c67057874425e7478da036a8c969 Mon Sep 17 00:00:00 2001 From: Kanglong Wang Date: Thu, 18 Jun 2026 16:55:11 +0800 Subject: [PATCH 2/3] anolis: Revert "anolis: LoongArch: Enable CONFIG_STRICT_MODULE_RWX" ANBZ: #38133 This reverts commit 7022f4d17ca8635a1dc9bc35290ea562c534d869. The LoongArch currently does not support CONFIG_STRICT_MODULE_RWX feature,so it needs to be disabled. The feature will be submitted to Anolis after it is improved upstream. Signed-off-by: Kanglong Wang Link: https://gitee.com/anolis/cloud-kernel/pulls/8312 --- anolis/configs/L0-MANDATORY/loongarch/CONFIG_STRICT_MODULE_RWX | 1 + anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_SET_MEMORY | 1 + .../L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_STRICT_MODULE_RWX | 1 + arch/loongarch/Kconfig | 1 - 4 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 anolis/configs/L0-MANDATORY/loongarch/CONFIG_STRICT_MODULE_RWX create mode 100644 anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_SET_MEMORY create mode 100644 anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_STRICT_MODULE_RWX diff --git a/anolis/configs/L0-MANDATORY/loongarch/CONFIG_STRICT_MODULE_RWX b/anolis/configs/L0-MANDATORY/loongarch/CONFIG_STRICT_MODULE_RWX new file mode 100644 index 000000000000..09b399c09b34 --- /dev/null +++ b/anolis/configs/L0-MANDATORY/loongarch/CONFIG_STRICT_MODULE_RWX @@ -0,0 +1 @@ +# CONFIG_STRICT_MODULE_RWX is not set diff --git a/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_SET_MEMORY b/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_SET_MEMORY new file mode 100644 index 000000000000..a88c501d32aa --- /dev/null +++ b/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_SET_MEMORY @@ -0,0 +1 @@ +# CONFIG_ARCH_HAS_SET_MEMORY is not set diff --git a/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_STRICT_MODULE_RWX b/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_STRICT_MODULE_RWX new file mode 100644 index 000000000000..e75a110cf4a3 --- /dev/null +++ b/anolis/configs/L2-OPTIONAL/loongarch/CONFIG_ARCH_HAS_STRICT_MODULE_RWX @@ -0,0 +1 @@ +# CONFIG_ARCH_HAS_STRICT_MODULE_RWX is not set diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 76aee0ed3b5b..0813262ea616 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -20,7 +20,6 @@ config LOONGARCH select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_SET_MEMORY - select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_INLINE_READ_LOCK if !PREEMPTION select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION -- Gitee From 44427d4404cacce38c0862991fe9e37639096516 Mon Sep 17 00:00:00 2001 From: Kanglong Wang Date: Thu, 18 Jun 2026 20:58:57 +0800 Subject: [PATCH 3/3] anolis: Revert "LoongArch: Add ARCH_HAS_SET_MEMORY support" ANBZ: #38133 This reverts commit e2cdd34d00310aa3a4e5011bec1296c55c640cce. Signed-off-by: Kanglong Wang Link: https://gitee.com/anolis/cloud-kernel/pulls/8312 --- arch/loongarch/Kconfig | 1 - arch/loongarch/include/asm/set_memory.h | 17 --- arch/loongarch/mm/Makefile | 3 +- arch/loongarch/mm/pageattr.c | 158 ------------------------ 4 files changed, 1 insertion(+), 178 deletions(-) delete mode 100644 arch/loongarch/include/asm/set_memory.h delete mode 100644 arch/loongarch/mm/pageattr.c diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 0813262ea616..f5fdaed5f833 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -19,7 +19,6 @@ config LOONGARCH select ARCH_HAS_NMI_SAFE_THIS_CPU_OPS select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PTE_SPECIAL - select ARCH_HAS_SET_MEMORY select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_INLINE_READ_LOCK if !PREEMPTION select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION diff --git a/arch/loongarch/include/asm/set_memory.h b/arch/loongarch/include/asm/set_memory.h deleted file mode 100644 index 64c7f942e8ec..000000000000 --- a/arch/loongarch/include/asm/set_memory.h +++ /dev/null @@ -1,17 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2024 Loongson Technology Corporation Limited - */ - -#ifndef _ASM_LOONGARCH_SET_MEMORY_H -#define _ASM_LOONGARCH_SET_MEMORY_H - -/* - * Functions to change memory attributes. - */ -int set_memory_x(unsigned long addr, int numpages); -int set_memory_nx(unsigned long addr, int numpages); -int set_memory_ro(unsigned long addr, int numpages); -int set_memory_rw(unsigned long addr, int numpages); - -#endif /* _ASM_LOONGARCH_SET_MEMORY_H */ diff --git a/arch/loongarch/mm/Makefile b/arch/loongarch/mm/Makefile index 278be2c8fc36..e4d1e581dbae 100644 --- a/arch/loongarch/mm/Makefile +++ b/arch/loongarch/mm/Makefile @@ -4,8 +4,7 @@ # obj-y += init.o cache.o tlb.o tlbex.o extable.o \ - fault.o ioremap.o maccess.o mmap.o pgtable.o \ - page.o pageattr.o + fault.o ioremap.o maccess.o mmap.o pgtable.o page.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_KASAN) += kasan_init.o diff --git a/arch/loongarch/mm/pageattr.c b/arch/loongarch/mm/pageattr.c deleted file mode 100644 index e3db1c38b5fe..000000000000 --- a/arch/loongarch/mm/pageattr.c +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2024 Loongson Technology Corporation Limited - */ - -#include -#include -#include -#include - -struct pageattr_masks { - pgprot_t set_mask; - pgprot_t clear_mask; -}; - -static unsigned long set_pageattr_masks(unsigned long val, struct mm_walk *walk) -{ - unsigned long new_val = val; - struct pageattr_masks *masks = walk->private; - - new_val &= ~(pgprot_val(masks->clear_mask)); - new_val |= (pgprot_val(masks->set_mask)); - - return new_val; -} - -static int pageattr_pgd_entry(pgd_t *pgd, unsigned long addr, - unsigned long next, struct mm_walk *walk) -{ - pgd_t val = pgdp_get(pgd); - - if (pgd_leaf(val)) { - val = __pgd(set_pageattr_masks(pgd_val(val), walk)); - set_pgd(pgd, val); - } - - return 0; -} - -static int pageattr_p4d_entry(p4d_t *p4d, unsigned long addr, - unsigned long next, struct mm_walk *walk) -{ - p4d_t val = p4dp_get(p4d); - - if (p4d_leaf(val)) { - val = __p4d(set_pageattr_masks(p4d_val(val), walk)); - set_p4d(p4d, val); - } - - return 0; -} - -static int pageattr_pud_entry(pud_t *pud, unsigned long addr, - unsigned long next, struct mm_walk *walk) -{ - pud_t val = pudp_get(pud); - - if (pud_leaf(val)) { - val = __pud(set_pageattr_masks(pud_val(val), walk)); - set_pud(pud, val); - } - - return 0; -} - -static int pageattr_pmd_entry(pmd_t *pmd, unsigned long addr, - unsigned long next, struct mm_walk *walk) -{ - pmd_t val = pmdp_get(pmd); - - if (pmd_leaf(val)) { - val = __pmd(set_pageattr_masks(pmd_val(val), walk)); - set_pmd(pmd, val); - } - - return 0; -} - -static int pageattr_pte_entry(pte_t *pte, unsigned long addr, - unsigned long next, struct mm_walk *walk) -{ - pte_t val = ptep_get(pte); - - val = __pte(set_pageattr_masks(pte_val(val), walk)); - set_pte(pte, val); - - return 0; -} - -static int pageattr_pte_hole(unsigned long addr, unsigned long next, - int depth, struct mm_walk *walk) -{ - return 0; -} - -static const struct mm_walk_ops pageattr_ops = { - .pgd_entry = pageattr_pgd_entry, - .p4d_entry = pageattr_p4d_entry, - .pud_entry = pageattr_pud_entry, - .pmd_entry = pageattr_pmd_entry, - .pte_entry = pageattr_pte_entry, - .pte_hole = pageattr_pte_hole, - .walk_lock = PGWALK_RDLOCK, -}; - -static int __set_memory(unsigned long addr, int numpages, pgprot_t set_mask, pgprot_t clear_mask) -{ - int ret; - unsigned long start = addr; - unsigned long end = start + PAGE_SIZE * numpages; - struct pageattr_masks masks = { - .set_mask = set_mask, - .clear_mask = clear_mask - }; - - if (!numpages) - return 0; - - mmap_write_lock(&init_mm); - ret = walk_page_range_novma(&init_mm, start, end, &pageattr_ops, NULL, &masks); - mmap_write_unlock(&init_mm); - - flush_tlb_kernel_range(start, end); - - return ret; -} - -int set_memory_x(unsigned long addr, int numpages) -{ - if (addr < vm_map_base) - return 0; - - return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_NO_EXEC)); -} - -int set_memory_nx(unsigned long addr, int numpages) -{ - if (addr < vm_map_base) - return 0; - - return __set_memory(addr, numpages, __pgprot(_PAGE_NO_EXEC), __pgprot(0)); -} - -int set_memory_ro(unsigned long addr, int numpages) -{ - if (addr < vm_map_base) - return 0; - - return __set_memory(addr, numpages, __pgprot(0), __pgprot(_PAGE_WRITE | _PAGE_DIRTY)); -} - -int set_memory_rw(unsigned long addr, int numpages) -{ - if (addr < vm_map_base) - return 0; - - return __set_memory(addr, numpages, __pgprot(_PAGE_WRITE | _PAGE_DIRTY), __pgprot(0)); -} -- Gitee