Re: [PATCH] mips: kdump: Crash kernel should be able to see old memories
Hi, Jiaxun On 04/20/2021 09:11 AM, Jiaxun Yang wrote: 在 2021/4/19 18:56, Youling Tang 写道: From: Huacai Chen kexec-tools use mem=X@Y to pass usable memories to crash kernel, but in commit a94e4f24ec836c8984f83959 ("MIPS: init: Drop boot_mem_map") all BIOS passed memories are removed by early_parse_mem(). I think this is reasonable for a normal kernel but not for a crash kernel, because a crash kernel should be able to see all old memories, even though it is not supposed to use them. Fixes: a94e4f24ec836c8984f83959 ("MIPS: init: Drop boot_mem_map") Signed-off-by: Huacai Chen Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index b86e241..ac90d3b 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -351,8 +351,10 @@ static int __init early_parse_mem(char *p) */ if (usermem == 0) { usermem = 1; +#ifndef CONFIG_CRASH_DUMP Why depend on a config instead of a runtime variable? If not depend on config, we can determine whether the command line contains the "elfcorehdr=" parameter, because the "mem=" and "elfcorhdr=" parameters are automatically added in kexec-tools. So if there is an "elfcorehdr=" parameter in the command line, it means that the currently running kernel is a capture kernel, and the memblock_remove() operation is not called. The revised patch is as follows: if (usermem == 0) { usermem = 1; - memblock_remove(memblock_start_of_DRAM(), - memblock_end_of_DRAM() - memblock_start_of_DRAM()); + if (!strstr(boot_command_line, "elfcorehdr")) { + memblock_remove(memblock_start_of_DRAM(), + memblock_end_of_DRAM() - memblock_start_of_DRAM()); + } Do you think it is feasible? Btw as you are fixing my commit please keep me CCed. Sorry, I will add your CCed. Thanks, Youling Thanks. - Jiaxun
Re: [PATCH] MIPS: Fix cmdline "mem=" parameter parsing
Hi, Jiaxun On 04/20/2021 09:05 AM, Jiaxun Yang wrote: 在 2021/4/19 18:50, Youling Tang 写道: This problem may only occur on NUMA platforms. When machine start with the "mem=" parameter on Loongson64, it cannot boot. When parsing the "mem=" parameter, first remove all RAM, and then add memory through memblock_add(), which causes the newly added memory to be located on MAX_NUMNODES. The solution is to add the current "mem=" parameter range to the memory area of the corresponding node, instead of adding all of it to the MAX_NUMNODES node area. Get the node number corresponding to the "mem=" parameter range through pa_to_nid(), and then add it to the corresponding node through memblock_add_node(). Signed-off-by: Jinyang He Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 279be01..b86e241 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -359,7 +359,7 @@ static int __init early_parse_mem(char *p) if (*p == '@') start = memparse(p + 1, ); -memblock_add(start, size); +memblock_add_node(start, size, pa_to_nid(start)); pa_to_nid is not available for all platforms. Thanks for your correction. pa_to_nid() only has actual definitions in mach-ip27 and mach-loongson64 (only for NUMA platform). In arch/mips/include/asm/mmzone.h: #ifndef pa_to_nid #define pa_to_nid(addr) 0 #endif So only need #include to solve the "error: implicit declaration of function'pa_to_nid'" compilation error. Thanks, Youling Thanks. - Jiaxun return 0; }
[PATCH] mips: kdump: Crash kernel should be able to see old memories
From: Huacai Chen kexec-tools use mem=X@Y to pass usable memories to crash kernel, but in commit a94e4f24ec836c8984f83959 ("MIPS: init: Drop boot_mem_map") all BIOS passed memories are removed by early_parse_mem(). I think this is reasonable for a normal kernel but not for a crash kernel, because a crash kernel should be able to see all old memories, even though it is not supposed to use them. Fixes: a94e4f24ec836c8984f83959 ("MIPS: init: Drop boot_mem_map") Signed-off-by: Huacai Chen Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index b86e241..ac90d3b 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -351,8 +351,10 @@ static int __init early_parse_mem(char *p) */ if (usermem == 0) { usermem = 1; +#ifndef CONFIG_CRASH_DUMP memblock_remove(memblock_start_of_DRAM(), memblock_end_of_DRAM() - memblock_start_of_DRAM()); +#endif } start = 0; size = memparse(p, ); -- 2.1.0
[PATCH] MIPS: Fix cmdline "mem=" parameter parsing
This problem may only occur on NUMA platforms. When machine start with the "mem=" parameter on Loongson64, it cannot boot. When parsing the "mem=" parameter, first remove all RAM, and then add memory through memblock_add(), which causes the newly added memory to be located on MAX_NUMNODES. The solution is to add the current "mem=" parameter range to the memory area of the corresponding node, instead of adding all of it to the MAX_NUMNODES node area. Get the node number corresponding to the "mem=" parameter range through pa_to_nid(), and then add it to the corresponding node through memblock_add_node(). Signed-off-by: Jinyang He Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 279be01..b86e241 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -359,7 +359,7 @@ static int __init early_parse_mem(char *p) if (*p == '@') start = memparse(p + 1, ); - memblock_add(start, size); + memblock_add_node(start, size, pa_to_nid(start)); return 0; } -- 2.1.0
[PATCH 2/2] MIPS: kdump: Provide arch_kexec_protect(unprotect)_crashkres()
Commit 9b492cf58077 ("kexec: introduce a protection mechanism for the crashkernel reserved memory") , provides a mechanism to protect the memory reserved by the crashed kernel. 1) After each crash kexec loading, it simply marks the reserved memory regions readonly since we no longer access it after that. When someone stamps the region, the first kernel will panic and trigger the kdump. This arch_kexec_protect_crashkres() will actually protect the reserved memory. 2) To allow multiple loading, once 1) was done we also need to remark the reserved memory to readwrite each time a system call related to kdump is made. This arch_kexec_unprotect_crashkres() will undo the protection of the reserved memory. Signed-off-by: Youling Tang --- arch/mips/kernel/machine_kexec.c | 40 1 file changed, 40 insertions(+) diff --git a/arch/mips/kernel/machine_kexec.c b/arch/mips/kernel/machine_kexec.c index 432bfd3..379c2c3 100644 --- a/arch/mips/kernel/machine_kexec.c +++ b/arch/mips/kernel/machine_kexec.c @@ -11,6 +11,7 @@ #include #include +#include extern const unsigned char relocate_new_kernel[]; extern const size_t relocate_new_kernel_size; @@ -205,6 +206,45 @@ void kexec_reboot(void) do_kexec(); } +static int +kexec_mark_range(unsigned long start, unsigned long end, bool protect) +{ + struct page *page; + unsigned int nr_pages; + + /* +* For physical range: [start, end]. We must skip the unassigned +* crashk resource with zero-valued "end" member. +*/ + if (!end || start > end) + return 0; + + page = pfn_to_page(start >> PAGE_SHIFT); + nr_pages = (end >> PAGE_SHIFT) - (start >> PAGE_SHIFT) + 1; + if (protect) + return set_pages_ro(page, nr_pages); + else + return set_pages_rw(page, nr_pages); +} + +static void +kexec_mark_crashkres(bool protect) +{ + kexec_mark_range(crashk_res.start, crashk_res.end, protect); +} + +void +arch_kexec_protect_crashkres(void) +{ + kexec_mark_crashkres(true); +} + +void +arch_kexec_unprotect_crashkres(void) +{ + kexec_mark_crashkres(false); +} + void machine_kexec(struct kimage *image) { -- 2.1.0
[PATCH 1/2] MIPS: mm: Add ARCH_HAS_SET_MEMORY support
Add set_memory_ro/rw/x/nx/rw_nx architecture hooks. These set_memory_* and set_pages_* APIs can make it easier to change the attributes of memory or pages. Similar to the implementation of riscv. The declaration of set_memory_* functions uses the general set_memory.h (i.e. include/asm-generic/set_memory.h). Signed-off-by: Youling Tang --- arch/mips/Kconfig | 1 + arch/mips/include/asm/set_memory.h | 19 + arch/mips/mm/Makefile | 1 + arch/mips/mm/pageattr.c| 157 + 4 files changed, 178 insertions(+) create mode 100644 arch/mips/include/asm/set_memory.h create mode 100644 arch/mips/mm/pageattr.c diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index e9893cd..ddeefd4 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -12,6 +12,7 @@ config MIPS select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_GCOV_PROFILE_ALL + select ARCH_HAS_SET_MEMORY select ARCH_KEEP_MEMBLOCK if DEBUG_KERNEL select ARCH_SUPPORTS_UPROBES select ARCH_USE_BUILTIN_BSWAP diff --git a/arch/mips/include/asm/set_memory.h b/arch/mips/include/asm/set_memory.h new file mode 100644 index 000..42217eb --- /dev/null +++ b/arch/mips/include/asm/set_memory.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_MIPS_SET_MEMORY_H +#define _ASM_MIPS_SET_MEMORY_H + +#include + +struct pageattr_masks { + pgprot_t set_mask; + pgprot_t clear_mask; +}; + +/* + * Functions to change pages attributes. + */ +int set_pages_ro(struct page *page, int numpages); +int set_pages_rw(struct page *page, int numpages); + +#endif /* _ASM_MIPS_SET_MEMORY_H */ diff --git a/arch/mips/mm/Makefile b/arch/mips/mm/Makefile index 4acc4f3..2022940 100644 --- a/arch/mips/mm/Makefile +++ b/arch/mips/mm/Makefile @@ -12,6 +12,7 @@ obj-y += mmap.o obj-y += page.o obj-y += page-funcs.o obj-y += pgtable.o +obj-y += pageattr.o obj-y += tlbex.o obj-y += tlbex-fault.o obj-y += tlb-funcs.o diff --git a/arch/mips/mm/pageattr.c b/arch/mips/mm/pageattr.c new file mode 100644 index 000..59db16e --- /dev/null +++ b/arch/mips/mm/pageattr.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include + +static unsigned long set_pageattr_masks(unsigned long val, struct mm_walk *walk) +{ + struct pageattr_masks *masks = walk->private; + unsigned long new_val = val; + + 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 = READ_ONCE(*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 = READ_ONCE(*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 = READ_ONCE(*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 = READ_ONCE(*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 = READ_ONCE(*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) +{ + /* Nothing to do here */ + 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, +
[PATCH] MIPS: pgtable: Add swp pte related macros definition and check
Add definitions for the bit masks/shifts/sizes, and implement MAX_SWAPFILES_CHECK() such that we fail to build if we are unable to properly encode the swp type field. Signed-off-by: Youling Tang --- arch/mips/include/asm/pgtable-32.h | 32 arch/mips/include/asm/pgtable-64.h | 18 +++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/arch/mips/include/asm/pgtable-32.h b/arch/mips/include/asm/pgtable-32.h index 6c0532d..3ec12ce 100644 --- a/arch/mips/include/asm/pgtable-32.h +++ b/arch/mips/include/asm/pgtable-32.h @@ -201,9 +201,8 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) #if defined(CONFIG_CPU_R3K_TLB) /* Swap entries must have VALID bit cleared. */ -#define __swp_type(x) (((x).val >> 10) & 0x1f) -#define __swp_offset(x)((x).val >> 15) -#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 10) | ((offset) << 15) }) +#define __SWP_TYPE_SHIFT 10 + #define __pte_to_swp_entry(pte)((swp_entry_t) { pte_val(pte) }) #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) @@ -212,18 +211,16 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) #if defined(CONFIG_XPA) /* Swap entries must have VALID and GLOBAL bits cleared. */ -#define __swp_type(x) (((x).val >> 4) & 0x1f) -#define __swp_offset(x) ((x).val >> 9) -#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 4) | ((offset) << 9) }) +#define __SWP_TYPE_SHIFT 4 + #define __pte_to_swp_entry(pte)((swp_entry_t) { (pte).pte_high }) #define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val }) #elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) /* Swap entries must have VALID and GLOBAL bits cleared. */ -#define __swp_type(x) (((x).val >> 2) & 0x1f) -#define __swp_offset(x) ((x).val >> 7) -#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 2) | ((offset) << 7) }) +#define __SWP_TYPE_SHIFT 2 + #define __pte_to_swp_entry(pte)((swp_entry_t) { (pte).pte_high }) #define __swp_entry_to_pte(x) ((pte_t) { 0, (x).val }) @@ -235,9 +232,8 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) * _PAGE_GLOBAL at bit 6 * _PAGE_VALID at bit 7 */ -#define __swp_type(x) (((x).val >> 8) & 0x1f) -#define __swp_offset(x) ((x).val >> 13) -#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << 8) | ((offset) << 13) }) +#define __SWP_TYPE_SHIFT 8 + #define __pte_to_swp_entry(pte)((swp_entry_t) { pte_val(pte) }) #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) @@ -245,4 +241,16 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot) #endif /* defined(CONFIG_CPU_R3K_TLB) */ +#define __SWP_TYPE_BITS5 +#define __SWP_TYPE_MASK((1UL << __SWP_TYPE_BITS) - 1) +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) + +#define MAX_SWAPFILES_CHECK() \ + BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS) + +#define __swp_type(x) (((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK) +#define __swp_offset(x)((x).val >> __SWP_OFFSET_SHIFT) +#define __swp_entry(type,offset) ((swp_entry_t) { ((type) << __SWP_TYPE_SHIFT) | \ + ((offset) << __SWP_OFFSET_SHIFT) }) + #endif /* _ASM_PGTABLE_32_H */ diff --git a/arch/mips/include/asm/pgtable-64.h b/arch/mips/include/asm/pgtable-64.h index 1e7d6ce..d06 100644 --- a/arch/mips/include/asm/pgtable-64.h +++ b/arch/mips/include/asm/pgtable-64.h @@ -330,15 +330,27 @@ extern void pgd_init(unsigned long page); extern void pud_init(unsigned long page, unsigned long pagetable); extern void pmd_init(unsigned long page, unsigned long pagetable); +#define __SWP_TYPE_SHIFT 16 +#define __SWP_TYPE_BITS8 +#define __SWP_TYPE_MASK((1UL << __SWP_TYPE_BITS) - 1) +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT) + +#define MAX_SWAPFILES_CHECK() \ + BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS) + /* * Non-present pages: high 40 bits are offset, next 8 bits type, * low 16 bits zero. */ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) -{ pte_t pte; pte_val(pte) = (type << 16) | (offset << 24); return pte; } +{ + pte_t pte; + pte_val(pte) = (type << __SWP_TYPE_SHIFT) | (offset << __SWP_OFFSET_SHIFT); + return pte; +} -#define __swp_type(x) (((x).val >> 16) & 0xff) -#define
[PATCH v4] MIPS: Loongson64: Add kexec/kdump support
From: Huacai Chen Add kexec/kdump support for Loongson64 by: 1, Provide Loongson-specific kexec functions: loongson_kexec_prepare(), loongson_kexec_shutdown() and loongson_crash_shutdown(); 2, Provide Loongson-specific assembly code in kexec_smp_wait(); To start Loongson64, The boot CPU needs 3 parameters: fw_arg0: the number of arguments in cmdline (i.e., argc). fw_arg1: structure holds cmdline such as "root=/dev/sda1 console=tty" (i.e., argv). fw_arg2: environment (i.e., envp, additional boot parameters from LEFI). Non-boot CPUs do not need one parameter as the IPI mailbox base address. They query their own IPI mailbox to get PC, SP and GP in a loopi, until the boot CPU brings them up. loongson_kexec_prepare(): Setup cmdline for kexec/kdump. The kexec/kdump cmdline comes from kexec's "append" option string. This structure will be parsed in fw_init_cmdline() of arch/mips/fw/lib/cmdline.c. Both image ->control_code_page and the cmdline need to be in a safe memory region (memory allocated by the old kernel may be corrupted by the new kernel). In order to maintain compatibility for the old firmware, the low 2MB is reserverd and safe for Loongson. So let KEXEC_CTRL_CODE and KEXEC_ARGV_ ADDR be here. LEFI parameters may be corrupted at runtime, so backup it at mips_reboot_setup(), and then restore it at loongson_kexec_shutdown() /loongson_crash_shutdown(). loongson_kexec_shutdown(): Wake up all present CPUs and let them go to reboot_code_buffer. Pass the kexec parameters to kexec_args. loongson_crash_shutdown(): Pass the kdump parameters to kexec_args. The assembly part in kexec_smp_wait provide a routine as BIOS does, in order to keep secondary CPUs in a querying loop. The layout of low 2MB memory in our design: 0x8000, the first MB, the first 64K, Exception vectors 0x8001, the first MB, the second 64K, STR (suspend) data 0x8002, the first MB, the third and fourth 64K, UEFI HOB 0x8004, the first MB, the fifth 64K, RT-Thread for SMC 0x8010, the second MB, the first 64K, KEXEC code 0x80108000, the second MB, the second 64K, KEXEC data Cc: Eric Biederman Tested-by: Jinyang He Signed-off-by: Huacai Chen Signed-off-by: Jinyang He Signed-off-by: Youling Tang --- v3 -> v4: - Use the macro kexec_smp_wait_final and move the platform-specific code into the kernel-entry-init.h file. This suggestion comes from Thomas. .../asm/mach-cavium-octeon/kernel-entry-init.h | 8 ++ .../asm/mach-loongson64/kernel-entry-init.h| 27 + arch/mips/kernel/relocate_kernel.S | 9 +- arch/mips/loongson64/reset.c | 113 + 4 files changed, 152 insertions(+), 5 deletions(-) diff --git a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h index c38b38c..b071a73 100644 --- a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h +++ b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h @@ -157,4 +157,12 @@ .macro smp_slave_setup .endm +#define USE_KEXEC_SMP_WAIT_FINAL + .macro kexec_smp_wait_final + .set push + .set noreorder + synci 0($0) + .set pop + .endm + #endif /* __ASM_MACH_CAVIUM_OCTEON_KERNEL_ENTRY_H */ diff --git a/arch/mips/include/asm/mach-loongson64/kernel-entry-init.h b/arch/mips/include/asm/mach-loongson64/kernel-entry-init.h index e4d77f4..13373c5 100644 --- a/arch/mips/include/asm/mach-loongson64/kernel-entry-init.h +++ b/arch/mips/include/asm/mach-loongson64/kernel-entry-init.h @@ -75,4 +75,31 @@ .setpop .endm +#define USE_KEXEC_SMP_WAIT_FINAL + .macro kexec_smp_wait_final + /* s0:prid s1:initfn */ + /* a0:base t1:cpuid t2:node t9:count */ + mfc0t1, CP0_EBASE + andit1, MIPS_EBASE_CPUNUM + dinsa0, t1, 8, 2 /* insert core id*/ + dextt2, t1, 2, 2 + dinsa0, t2, 44, 2 /* insert node id */ + mfc0s0, CP0_PRID + andis0, s0, (PRID_IMP_MASK | PRID_REV_MASK) + beq s0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3B_R1), 1f + beq s0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3B_R2), 1f + b 2f /* Loongson-3A1000/3A2000/3A3000/3A4000 */ +1: dinsa0, t2, 14, 2 /* Loongson-3B1000/3B1500 need bit 15~14 */ +2: li t9, 0x100 /* wait for init loop */ +3: addiu t9, -1 /* limit mailbox access */ + bnezt9, 3b + lw s1, 0x20(a0) /* check PC as an indicator */ + beqzs1, 2b + ld s1, 0x20(a0) /* get PC via mailbox reg0 */ + ld sp, 0x28(a0) /* get SP via mailbox reg1 */ + ld gp, 0x30(a0)
Re: [PATCH] staging: fix ignoring return value warning
Hi, Dan On 02/09/2021 03:02 AM, Dan Carpenter wrote: On Mon, Feb 08, 2021 at 04:06:18PM +0100, Sascha Hauer wrote: Hi Dan, On Mon, Feb 08, 2021 at 04:45:17PM +0300, Dan Carpenter wrote: On Sun, Feb 07, 2021 at 05:23:28PM +0800, Youling Tang wrote: Fix the below ignoring return value warning for device_reset. drivers/staging/mt7621-dma/mtk-hsdma.c:685:2: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] device_reset(>dev); ^~~~ ~~ drivers/staging/ralink-gdma/ralink-gdma.c:836:2: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] device_reset(>dev); ^~~~ ~~ We can't really do this sort of fix without the hardware to test it. This could be the correct fix or perhaps switching to device_reset_optional() is the correct fix. We can't know unless we have the hardware to test. When device_reset() is the wrong function then adding a return value check will turn this into a runtime error for those who have the hardware which will hopefully trigger them to tell us why reset_device is wrong for them. At least for a staging driver I find this procedure opportune. That seems like sort of a jerk move... What's the rush? Someone will eventually be able to test this if we just wait around for a bit. Otherwise if no one has the hardware then eventually the driver will be deleted. regards, dan carpenter We do not have the relevant hardware to test, this is just to solve a compile-time warning. Thanks, Youling.
[PATCH] staging: fix ignoring return value warning
Fix the below ignoring return value warning for device_reset. drivers/staging/mt7621-dma/mtk-hsdma.c:685:2: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] device_reset(>dev); ^~~~ ~~ drivers/staging/ralink-gdma/ralink-gdma.c:836:2: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result] device_reset(>dev); ^~~~ ~~ Signed-off-by: Youling Tang --- drivers/staging/mt7621-dma/mtk-hsdma.c| 6 +- drivers/staging/ralink-gdma/ralink-gdma.c | 6 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/staging/mt7621-dma/mtk-hsdma.c b/drivers/staging/mt7621-dma/mtk-hsdma.c index bc4bb43..d4ffa52 100644 --- a/drivers/staging/mt7621-dma/mtk-hsdma.c +++ b/drivers/staging/mt7621-dma/mtk-hsdma.c @@ -682,7 +682,11 @@ static int mtk_hsdma_probe(struct platform_device *pdev) return ret; } - device_reset(>dev); + ret = device_reset(>dev); + if (ret) { + dev_err(>dev, "failed to reset device\n"); + return ret; + } dd = >ddev; dma_cap_set(DMA_MEMCPY, dd->cap_mask); diff --git a/drivers/staging/ralink-gdma/ralink-gdma.c b/drivers/staging/ralink-gdma/ralink-gdma.c index 655df31..df99c47 100644 --- a/drivers/staging/ralink-gdma/ralink-gdma.c +++ b/drivers/staging/ralink-gdma/ralink-gdma.c @@ -833,7 +833,11 @@ static int gdma_dma_probe(struct platform_device *pdev) return ret; } - device_reset(>dev); + ret = device_reset(>dev); + if (ret) { + dev_err(>dev, "failed to reset device\n"); + return ret; + } dd = _dev->ddev; dma_cap_set(DMA_MEMCPY, dd->cap_mask); -- 2.1.0
[PATCH v2] MIPS: crash_dump.c: Simplify copy_oldmem_page()
Replace kmap_atomic_pfn() with kmap_local_pfn() which is preemptible and can take page faults. Remove the indirection of the dump page and the related cruft which is not longer required. Remove unused or redundant header files. Reported-by: kernel test robot Signed-off-by: Youling Tang --- v2: - Keep the crash_dump.h header file included to avoid the "no previous prototype for function" warning. arch/mips/kernel/crash_dump.c | 41 ++--- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/arch/mips/kernel/crash_dump.c b/arch/mips/kernel/crash_dump.c index 01b2bd9..2e50f551 100644 --- a/arch/mips/kernel/crash_dump.c +++ b/arch/mips/kernel/crash_dump.c @@ -1,11 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include #include -#include -#include - -static void *kdump_buf_page; /** * copy_oldmem_page - copy one page from "oldmem" @@ -19,10 +14,6 @@ static void *kdump_buf_page; * * Copy a page from "oldmem". For this page, there is no pte mapped * in the current kernel. - * - * Calling copy_to_user() in atomic context is not desirable. Hence first - * copying the data to a pre-allocated kernel page and then copying to user - * space in non-atomic context. */ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, unsigned long offset, int userbuf) @@ -32,36 +23,16 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!csize) return 0; - vaddr = kmap_atomic_pfn(pfn); + vaddr = kmap_local_pfn(pfn); if (!userbuf) { - memcpy(buf, (vaddr + offset), csize); - kunmap_atomic(vaddr); + memcpy(buf, vaddr + offset, csize); } else { - if (!kdump_buf_page) { - pr_warn("Kdump: Kdump buffer page not allocated\n"); - - return -EFAULT; - } - copy_page(kdump_buf_page, vaddr); - kunmap_atomic(vaddr); - if (copy_to_user(buf, (kdump_buf_page + offset), csize)) - return -EFAULT; + if (copy_to_user(buf, vaddr + offset, csize)) + csize = -EFAULT; } - return csize; -} - -static int __init kdump_buf_page_init(void) -{ - int ret = 0; + kunmap_local(vaddr); - kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL); - if (!kdump_buf_page) { - pr_warn("Kdump: Failed to allocate kdump buffer page\n"); - ret = -ENOMEM; - } - - return ret; + return csize; } -arch_initcall(kdump_buf_page_init); -- 2.1.0
[PATCH] MIPS: crash_dump.c: Simplify copy_oldmem_page()
Replace kmap_atomic_pfn() with kmap_local_pfn() which is preemptible and can take page faults. Remove the indirection of the dump page and the related cruft which is not longer required. Remove unused or redundant header files. Signed-off-by: Youling Tang --- arch/mips/kernel/crash_dump.c | 42 ++ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/arch/mips/kernel/crash_dump.c b/arch/mips/kernel/crash_dump.c index 01b2bd9..f2eb91c 100644 --- a/arch/mips/kernel/crash_dump.c +++ b/arch/mips/kernel/crash_dump.c @@ -1,11 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include -#include -#include -#include - -static void *kdump_buf_page; /** * copy_oldmem_page - copy one page from "oldmem" @@ -19,10 +13,6 @@ static void *kdump_buf_page; * * Copy a page from "oldmem". For this page, there is no pte mapped * in the current kernel. - * - * Calling copy_to_user() in atomic context is not desirable. Hence first - * copying the data to a pre-allocated kernel page and then copying to user - * space in non-atomic context. */ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, unsigned long offset, int userbuf) @@ -32,36 +22,16 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!csize) return 0; - vaddr = kmap_atomic_pfn(pfn); + vaddr = kmap_local_pfn(pfn); if (!userbuf) { - memcpy(buf, (vaddr + offset), csize); - kunmap_atomic(vaddr); + memcpy(buf, vaddr + offset, csize); } else { - if (!kdump_buf_page) { - pr_warn("Kdump: Kdump buffer page not allocated\n"); - - return -EFAULT; - } - copy_page(kdump_buf_page, vaddr); - kunmap_atomic(vaddr); - if (copy_to_user(buf, (kdump_buf_page + offset), csize)) - return -EFAULT; + if (copy_to_user(buf, vaddr + offset, csize)) + csize = -EFAULT; } - return csize; -} - -static int __init kdump_buf_page_init(void) -{ - int ret = 0; + kunmap_local(vaddr); - kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL); - if (!kdump_buf_page) { - pr_warn("Kdump: Failed to allocate kdump buffer page\n"); - ret = -ENOMEM; - } - - return ret; + return csize; } -arch_initcall(kdump_buf_page_init); -- 2.1.0
[PATCH v3] i2c: ismt: Use dma_set_mask_and_coherent
'pci_set_dma_mask()' + 'pci_set_consistent_dma_mask()' can be replaced by an equivalent 'dma_set_mask_and_coherent()' which is much less verbose. Reported-by: kernel test robot Signed-off-by: Youling Tang --- v3: Fix build errors of incompatible pointer types. drivers/i2c/busses/i2c-ismt.c | 10 +++--- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index a35a27c..88f6039 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c @@ -903,16 +903,12 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -ENODEV; } - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || - (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || - (pci_set_consistent_dma_mask(pdev, -DMA_BIT_MASK(32)) != 0)) { - dev_err(>dev, "pci_set_dma_mask fail %p\n", + if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(64)) != 0) + if (dma_set_mask_and_coherent(>dev, DMA_BIT_MASK(32)) != 0) { + dev_err(>dev, "dma_set_mask_and_coherent fail %p\n", pdev); return -ENODEV; } - } err = ismt_dev_init(priv); if (err) -- 2.1.0
[PATCH v2] i2c: ismt: Use dma_set_mask_and_coherent
'pci_set_dma_mask()' + 'pci_set_consistent_dma_mask()' can be replaced by an equivalent 'dma_set_mask_and_coherent()' which is much less verbose. Signed-off-by: Youling Tang --- drivers/i2c/busses/i2c-ismt.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index a35a27c..5f49830 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c @@ -903,16 +903,12 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -ENODEV; } - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || - (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || - (pci_set_consistent_dma_mask(pdev, -DMA_BIT_MASK(32)) != 0)) { + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(64)) != 0) + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(32)) != 0) { dev_err(>dev, "pci_set_dma_mask fail %p\n", pdev); return -ENODEV; } - } err = ismt_dev_init(priv); if (err) -- 2.1.0
Re: [PATCH] i2c: busses: Use dma_set_mask_and_coherent
Hi, Wolfram On 12/03/2020 12:01 AM, Wolfram Sang wrote: On Tue, Nov 24, 2020 at 09:08:35PM +0800, Youling Tang wrote: 'pci_set_dma_mask()' + 'pci_set_consistent_dma_mask()' can be replaced by an equivalent 'dma_set_mask_and_coherent()' which is much less verbose. Signed-off-by: Youling Tang Please use "i2c: ismt:", so driver maintainers know that the patch is relevant to them. Thank you for your suggestion, I'll send v2 later. Thanks. Youling. --- drivers/i2c/busses/i2c-ismt.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index a35a27c..5f49830 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c @@ -903,16 +903,12 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -ENODEV; } - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || - (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || - (pci_set_consistent_dma_mask(pdev, -DMA_BIT_MASK(32)) != 0)) { + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(64)) != 0) + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(32)) != 0) { dev_err(>dev, "pci_set_dma_mask fail %p\n", pdev); return -ENODEV; } - } err = ismt_dev_init(priv); if (err) -- 2.1.0
[PATCH] powerpc: Use common STABS_DEBUG and DWARF_DEBUG and ELF_DETAILS macro
Use the common STABS_DEBUG and DWARF_DEBUG and ELF_DETAILS macro rule for the linker script in an effort. Signed-off-by: Youling Tang --- arch/powerpc/kernel/vdso32/vdso32.lds.S | 42 - arch/powerpc/kernel/vdso64/vdso64.lds.S | 42 - 2 files changed, 8 insertions(+), 76 deletions(-) diff --git a/arch/powerpc/kernel/vdso32/vdso32.lds.S b/arch/powerpc/kernel/vdso32/vdso32.lds.S index 7eadac7..8b5c7eb 100644 --- a/arch/powerpc/kernel/vdso32/vdso32.lds.S +++ b/arch/powerpc/kernel/vdso32/vdso32.lds.S @@ -4,6 +4,7 @@ * library */ #include +#include #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf32-powerpcle", "elf32-powerpcle", "elf32-powerpcle") @@ -68,44 +69,9 @@ SECTIONS __end = .; PROVIDE(end = .); - /* -* Stabs debugging sections are here too. -*/ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index 0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - - /* -* DWARF debug sections. -* Symbols in the DWARF debugging sections are relative to the beginning -* of the section so we begin them at 0. -*/ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } + STABS_DEBUG + DWARF_DEBUG + ELF_DETAILS /DISCARD/ : { *(.note.GNU-stack) diff --git a/arch/powerpc/kernel/vdso64/vdso64.lds.S b/arch/powerpc/kernel/vdso64/vdso64.lds.S index 256fb97..0002f4e 100644 --- a/arch/powerpc/kernel/vdso64/vdso64.lds.S +++ b/arch/powerpc/kernel/vdso64/vdso64.lds.S @@ -4,6 +4,7 @@ * library */ #include +#include #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle") @@ -67,44 +68,9 @@ SECTIONS _end = .; PROVIDE(end = .); - /* -* Stabs debugging sections are here too. -*/ - .stab 0 : { *(.stab) } - .stabstr 0 : { *(.stabstr) } - .stab.excl 0 : { *(.stab.excl) } - .stab.exclstr 0 : { *(.stab.exclstr) } - .stab.index0 : { *(.stab.index) } - .stab.indexstr 0 : { *(.stab.indexstr) } - .comment 0 : { *(.comment) } - - /* -* DWARF debug sections. -* Symbols in the DWARF debugging sections are relative to the beginning -* of the section so we begin them at 0. -*/ - /* DWARF 1 */ - .debug 0 : { *(.debug) } - .line 0 : { *(.line) } - /* GNU DWARF 1 extensions */ - .debug_srcinfo 0 : { *(.debug_srcinfo) } - .debug_sfnames 0 : { *(.debug_sfnames) } - /* DWARF 1.1 and DWARF 2 */ - .debug_aranges 0 : { *(.debug_aranges) } - .debug_pubnames 0 : { *(.debug_pubnames) } - /* DWARF 2 */ - .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } - .debug_abbrev 0 : { *(.debug_abbrev) } - .debug_line 0 : { *(.debug_line) } - .debug_frame0 : { *(.debug_frame) } - .debug_str 0 : { *(.debug_str) } - .debug_loc 0 : { *(.debug_loc) } - .debug_macinfo 0 : { *(.debug_macinfo) } - /* SGI/MIPS DWARF 2 extensions */ - .debug_weaknames 0 : { *(.debug_weaknames) } - .debug_funcnames 0 : { *(.debug_funcnames) } - .debug_typenames 0 : { *(.debug_typenames) } - .debug_varnames 0 : { *(.debug_varnames) } + STABS_DEBUG + DWARF_DEBUG + ELF_DETAILS /DISCARD/ : { *(.note.GNU-stack) -- 2.1.0
Re: [PATCH v2] acpi: Fix use-after-free in acpi_ipmi.c
Hi, On 11/26/2020 10:22 PM, Rafael J. Wysocki wrote: On Thu, Nov 26, 2020 at 2:26 AM Youling Tang wrote: kfree() has been called inside put_device so anther kfree would cause a use-after-free bug. Signed-off-by: Youling Tang --- drivers/acpi/acpi_ipmi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c index 9d6c0fc..18edf8b 100644 --- a/drivers/acpi/acpi_ipmi.c +++ b/drivers/acpi/acpi_ipmi.c @@ -142,7 +142,6 @@ static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device) { ipmi_destroy_user(ipmi_device->user_interface); put_device(ipmi_device->dev); Does putting ipmi_device->dev (which is a different object than ipmi_device itself) really cause ipmi_device to be freed automatically? If not, the change below will introduce a memory leak. ipmi_device will be free so that there is no memory leak. Similar to the following: https://lore.kernel.org/patchwork/patch/1342136/ Thanks, Youling. - kfree(ipmi_device); } static void ipmi_dev_release_kref(struct kref *kref) --
[PATCH] tools: selftests: Add missing munmap() in check_error_paths()
Add the missing munmap(addr_ro, PAGE_SIZE) before return. Signed-off-by: Youling Tang --- tools/testing/selftests/ptrace/peeksiginfo.c | 12 +++- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/ptrace/peeksiginfo.c b/tools/testing/selftests/ptrace/peeksiginfo.c index 5490065..3d64be4 100644 --- a/tools/testing/selftests/ptrace/peeksiginfo.c +++ b/tools/testing/selftests/ptrace/peeksiginfo.c @@ -62,7 +62,7 @@ static int check_error_paths(pid_t child) MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0); if (addr_ro == MAP_FAILED) { err("mmap() failed: %m\n"); - goto out; + goto out_rw; } arg.nr = SIGNR; @@ -75,7 +75,7 @@ static int check_error_paths(pid_t child) err("sys_ptrace() returns %d (expected -1)," " errno %d (expected %d): %m\n", ret, errno, EINVAL); - goto out; + goto out_ro; } arg.flags = 0; @@ -84,7 +84,7 @@ static int check_error_paths(pid_t child) addr_ro - sizeof(siginfo_t) * 2); if (ret != 2) { err("sys_ptrace() returns %d (expected 2): %m\n", ret); - goto out; + goto out_ro; } /* Read-only buffer */ @@ -93,11 +93,13 @@ static int check_error_paths(pid_t child) err("sys_ptrace() returns %d (expected -1)," " errno %d (expected %d): %m\n", ret, errno, EFAULT); - goto out; + goto out_ro; } exit_code = 0; -out: +out_ro: + munmap(addr_ro, PAGE_SIZE); +out_rw: munmap(addr_rw, 2 * PAGE_SIZE); return exit_code; } -- 2.1.0
[PATCH] sparc: Removes code duplication between arch_ptrace and compat_arch_ptrace
The patch removes code duplication between arch_ptrace and compat_arch_ptrace, in large part by having the former call into the later for all requests that don't need any special "compat" treatment. Signed-off-by: Youling Tang --- arch/sparc/kernel/ptrace_64.c | 71 +++ 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c index 2b92155d..4fd8c33 100644 --- a/arch/sparc/kernel/ptrace_64.c +++ b/arch/sparc/kernel/ptrace_64.c @@ -929,78 +929,51 @@ struct compat_fps { long compat_arch_ptrace(struct task_struct *child, compat_long_t request, compat_ulong_t caddr, compat_ulong_t cdata) { - compat_ulong_t caddr2 = task_pt_regs(current)->u_regs[UREG_I4]; struct pt_regs32 __user *pregs; struct compat_fps __user *fps; - unsigned long addr2 = caddr2; unsigned long addr = caddr; unsigned long data = cdata; - int ret; pregs = (struct pt_regs32 __user *) addr; fps = (struct compat_fps __user *) addr; switch (request) { - case PTRACE_PEEKUSR: - ret = (addr != 0) ? -EIO : 0; - break; - case PTRACE_GETREGS: - ret = copy_regset_to_user(child, _view, + return copy_regset_to_user(child, _view, REGSET_GENERAL, 0, 19 * sizeof(u32), pregs); - break; case PTRACE_SETREGS: - ret = copy_regset_from_user(child, _view, + return copy_regset_from_user(child, _view, REGSET_GENERAL, 0, 19 * sizeof(u32), pregs); - break; case PTRACE_GETFPREGS: - ret = copy_regset_to_user(child, _view, + return copy_regset_to_user(child, _view, REGSET_FP, 0, 68 * sizeof(u32), fps); - break; case PTRACE_SETFPREGS: - ret = copy_regset_from_user(child, _view, + return copy_regset_from_user(child, _view, REGSET_FP, 0, 33 * sizeof(u32), fps); - break; + case PTRACE_PEEKUSR: case PTRACE_READTEXT: case PTRACE_READDATA: - ret = ptrace_readdata(child, addr, - (char __user *)addr2, data); - if (ret == data) - ret = 0; - else if (ret >= 0) - ret = -EIO; - break; - case PTRACE_WRITETEXT: case PTRACE_WRITEDATA: - ret = ptrace_writedata(child, (char __user *) addr2, - addr, data); - if (ret == data) - ret = 0; - else if (ret >= 0) - ret = -EIO; - break; + return arch_ptrace(child, request, addr, data); default: if (request == PTRACE_SPARC_DETACH) request = PTRACE_DETACH; - ret = compat_ptrace_request(child, request, addr, data); - break; + return compat_ptrace_request(child, request, addr, data); } - - return ret; } #endif /* CONFIG_COMPAT */ @@ -1025,63 +998,53 @@ long arch_ptrace(struct task_struct *child, long request, switch (request) { case PTRACE_PEEKUSR: - ret = (addr != 0) ? -EIO : 0; - break; + return ((addr != 0) ? -EIO : 0); case PTRACE_GETREGS64: - ret = copy_regset_to_user(child, _view, + return copy_regset_to_user(child, _view, REGSET_GENERAL, 0, 19 * sizeof(u64), pregs); - break; case PTRACE_SETREGS64: - ret = copy_regset_from_user(child, _view, + return copy_regset_from_user(child, _view, REGSET_GENERAL, 0, 19 * sizeof(u64), pregs); - break; case PTRACE_GETFPREGS64: - ret = copy_regset_to_user(child, view, REGSET_FP, + return copy_regset_to_user(child, view, REGSET_FP, 0 * sizeof(u64), 33 * sizeof(u64),
[PATCH] alpha: ptrace generic requests
This removes duplicated code by calling the generic ptrace_request function for the things they already handle. Signed-off-by: Youling Tang --- arch/alpha/kernel/ptrace.c | 6 -- 1 file changed, 6 deletions(-) diff --git a/arch/alpha/kernel/ptrace.c b/arch/alpha/kernel/ptrace.c index 8c43212..eb4d566 100644 --- a/arch/alpha/kernel/ptrace.c +++ b/arch/alpha/kernel/ptrace.c @@ -301,12 +301,6 @@ long arch_ptrace(struct task_struct *child, long request, DBG(DBG_MEM, ("peek $%lu->%#lx\n", addr, ret)); break; - /* When I and D space are separate, this will have to be fixed. */ - case PTRACE_POKETEXT: /* write the word at location addr. */ - case PTRACE_POKEDATA: - ret = generic_ptrace_pokedata(child, addr, data); - break; - case PTRACE_POKEUSR: /* write the specified register */ DBG(DBG_MEM, ("poke $%lu<-%#lx\n", addr, data)); ret = put_reg(child, addr, data); -- 2.1.0
[PATCH v2] acpi: Fix use-after-free in acpi_ipmi.c
kfree() has been called inside put_device so anther kfree would cause a use-after-free bug. Signed-off-by: Youling Tang --- drivers/acpi/acpi_ipmi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c index 9d6c0fc..18edf8b 100644 --- a/drivers/acpi/acpi_ipmi.c +++ b/drivers/acpi/acpi_ipmi.c @@ -142,7 +142,6 @@ static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device) { ipmi_destroy_user(ipmi_device->user_interface); put_device(ipmi_device->dev); - kfree(ipmi_device); } static void ipmi_dev_release_kref(struct kref *kref) -- 2.1.0
Re: [PATCH] acpi: Fix use-after-free in acpi_ipmi.c
Hi, On 11/25/2020 11:53 PM, Rafael J. Wysocki wrote: On Tue, Nov 24, 2020 at 1:51 PM Youling Tang wrote: kfree() has been called inside put_device so anther kfree would cause a use-after-free bug. Signed-off-by: Youling Tang --- drivers/acpi/acpi_ipmi.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c index 9d6c0fc..72902b6 100644 --- a/drivers/acpi/acpi_ipmi.c +++ b/drivers/acpi/acpi_ipmi.c @@ -130,7 +130,6 @@ ipmi_dev_alloc(int iface, struct device *dev, acpi_handle handle) ipmi_device, ); if (err) { put_device(dev); - kfree(ipmi_device); dev doesn't point to the same object in memory as ipmi_device, though, if I'm not mistaken. Please double check that and resend the patch if you are sure that it is correct. You're right, dev really doesn't point to the same memory object as ipmi_device. I'll send v2 later. Thanks, Youling. return NULL; } ipmi_device->user_interface = user; @@ -142,7 +141,6 @@ static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device) { ipmi_destroy_user(ipmi_device->user_interface); put_device(ipmi_device->dev); - kfree(ipmi_device); } static void ipmi_dev_release_kref(struct kref *kref) -- 2.1.0
[PATCH] i2c: busses: Use dma_set_mask_and_coherent
'pci_set_dma_mask()' + 'pci_set_consistent_dma_mask()' can be replaced by an equivalent 'dma_set_mask_and_coherent()' which is much less verbose. Signed-off-by: Youling Tang --- drivers/i2c/busses/i2c-ismt.c | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index a35a27c..5f49830 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c @@ -903,16 +903,12 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id) return -ENODEV; } - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) || - (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)) { - if ((pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) || - (pci_set_consistent_dma_mask(pdev, -DMA_BIT_MASK(32)) != 0)) { + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(64)) != 0) + if (dma_set_mask_and_coherent(pdev, DMA_BIT_MASK(32)) != 0) { dev_err(>dev, "pci_set_dma_mask fail %p\n", pdev); return -ENODEV; } - } err = ismt_dev_init(priv); if (err) -- 2.1.0
[PATCH] acpi: Fix use-after-free in acpi_ipmi.c
kfree() has been called inside put_device so anther kfree would cause a use-after-free bug. Signed-off-by: Youling Tang --- drivers/acpi/acpi_ipmi.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c index 9d6c0fc..72902b6 100644 --- a/drivers/acpi/acpi_ipmi.c +++ b/drivers/acpi/acpi_ipmi.c @@ -130,7 +130,6 @@ ipmi_dev_alloc(int iface, struct device *dev, acpi_handle handle) ipmi_device, ); if (err) { put_device(dev); - kfree(ipmi_device); return NULL; } ipmi_device->user_interface = user; @@ -142,7 +141,6 @@ static void ipmi_dev_release(struct acpi_ipmi_device *ipmi_device) { ipmi_destroy_user(ipmi_device->user_interface); put_device(ipmi_device->dev); - kfree(ipmi_device); } static void ipmi_dev_release_kref(struct kref *kref) -- 2.1.0
Re: [PATCH] microblaze: Use the common INIT_DATA_SECTION macro in vmlinux.lds.S
Hi, Michal On 11/20/2020 09:31 PM, Michal Simek wrote: Hi, On 19. 11. 20 2:40, Youling Tang wrote: Use the common INIT_DATA_SECTION rule for the linker script in an effort to regularize the linker script. Signed-off-by: Youling Tang --- arch/microblaze/kernel/vmlinux.lds.S | 24 +--- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/arch/microblaze/kernel/vmlinux.lds.S b/arch/microblaze/kernel/vmlinux.lds.S index df07b3d..527ebfc 100644 --- a/arch/microblaze/kernel/vmlinux.lds.S +++ b/arch/microblaze/kernel/vmlinux.lds.S @@ -96,10 +96,7 @@ SECTIONS { __init_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) - - .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { - INIT_DATA - } + INIT_DATA_SECTION(0) . = ALIGN(4); .init.ivt : AT(ADDR(.init.ivt) - LOAD_OFFSET) { @@ -107,25 +104,6 @@ SECTIONS { *(.init.ivt) __ivt_end = .; } - - .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { - INIT_SETUP(0) - } - - .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET ) { - INIT_CALLS - } - - .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { - CON_INITCALL - } - - __init_end_before_initramfs = .; - - .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { - INIT_RAM_FS - } - __init_end = .; .bss ALIGN (PAGE_SIZE) : AT(ADDR(.bss) - LOAD_OFFSET) { Thanks for the patch but I can't accept it because recently we found that there needs to be some resorting in linker to be able to boot. The issue is that INIT_RAMFS_FS section is text/data/init and bss. But because microblaze in early code is using two TLBs (16M) each for early mapping and you have big initramfs bss section is unreachable. That's why these sections needs to be swapped. Maybe bss section can be moved up before INIT_DATA_SECTION maybe even before INIT_TEXT_SECTION and we should be fine. Thank you for your reply. Do you mean it should be changed as follows: ... .bss ALIGN (PAGE_SIZE) : AT(ADDR(.bss) - LOAD_OFFSET) { /* page aligned when MMU used */ __bss_start = . ; *(.bss*) *(COMMON) . = ALIGN (4) ; __bss_stop = . ; } INIT_TEXT_SECTION(PAGE_SIZE) INIT_DATA_SECTION(0) ... Thanks, Youling Thanks, Michal
[PATCH 2/2] m68k: Add a missing ELF_DETAILS in link script
Commit c604abc3f6e3 ("vmlinux.lds.h: Split ELF_DETAILS from STABS_DEBUG") after should add a missing ELF_DETAILS, at the same time, the .comment section has been included in the ELF_DETAILS. Signed-off-by: Youling Tang --- arch/m68k/kernel/vmlinux-nommu.lds | 2 +- arch/m68k/kernel/vmlinux-std.lds | 2 +- arch/m68k/kernel/vmlinux-sun3.lds | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/m68k/kernel/vmlinux-nommu.lds b/arch/m68k/kernel/vmlinux-nommu.lds index 247e19f..396e126 100644 --- a/arch/m68k/kernel/vmlinux-nommu.lds +++ b/arch/m68k/kernel/vmlinux-nommu.lds @@ -86,7 +86,7 @@ SECTIONS { _end = .; STABS_DEBUG - .comment 0 : { *(.comment) } + ELF_DETAILS /* Sections to be discarded */ DISCARDS diff --git a/arch/m68k/kernel/vmlinux-std.lds b/arch/m68k/kernel/vmlinux-std.lds index 1511346..ed1d9ed 100644 --- a/arch/m68k/kernel/vmlinux-std.lds +++ b/arch/m68k/kernel/vmlinux-std.lds @@ -59,7 +59,7 @@ SECTIONS _end = . ; STABS_DEBUG - .comment 0 : { *(.comment) } + ELF_DETAILS /* Sections to be discarded */ DISCARDS diff --git a/arch/m68k/kernel/vmlinux-sun3.lds b/arch/m68k/kernel/vmlinux-sun3.lds index 90ff8e5..4a52f44 100644 --- a/arch/m68k/kernel/vmlinux-sun3.lds +++ b/arch/m68k/kernel/vmlinux-sun3.lds @@ -52,6 +52,7 @@ __init_begin = .; _end = . ; STABS_DEBUG + ELF_DETAILS /* Sections to be discarded */ DISCARDS -- 2.1.0
[PATCH 1/2] m68k: Drop redundant NOTES in link script
Commit eaf937075c9a ("vmlinux.lds.h: Move NOTES into RO_DATA") after should remove redundant NOTES. Signed-off-by: Youling Tang --- arch/m68k/kernel/vmlinux-nommu.lds | 1 - arch/m68k/kernel/vmlinux-std.lds | 1 - arch/m68k/kernel/vmlinux-sun3.lds | 1 - 3 files changed, 3 deletions(-) diff --git a/arch/m68k/kernel/vmlinux-nommu.lds b/arch/m68k/kernel/vmlinux-nommu.lds index 7b97542..247e19f 100644 --- a/arch/m68k/kernel/vmlinux-nommu.lds +++ b/arch/m68k/kernel/vmlinux-nommu.lds @@ -65,7 +65,6 @@ SECTIONS { _edata = .; EXCEPTION_TABLE(16) - NOTES . = ALIGN(PAGE_SIZE); __init_begin = .; diff --git a/arch/m68k/kernel/vmlinux-std.lds b/arch/m68k/kernel/vmlinux-std.lds index 4d33da4..1511346 100644 --- a/arch/m68k/kernel/vmlinux-std.lds +++ b/arch/m68k/kernel/vmlinux-std.lds @@ -49,7 +49,6 @@ SECTIONS *(.m68k_fixup) __stop_fixup = .; } - NOTES .init_end : { /* This ALIGN be in a section so that _end is at the end of the load segment. */ diff --git a/arch/m68k/kernel/vmlinux-sun3.lds b/arch/m68k/kernel/vmlinux-sun3.lds index 87d9f4d0..90ff8e5 100644 --- a/arch/m68k/kernel/vmlinux-sun3.lds +++ b/arch/m68k/kernel/vmlinux-sun3.lds @@ -33,7 +33,6 @@ SECTIONS RW_DATA(16, PAGE_SIZE, THREAD_SIZE) :data /* End of data goes *here* so that freeing init code works properly. */ _edata = .; - NOTES /* will be freed after init */ . = ALIGN(PAGE_SIZE);/* Init code and data */ -- 2.1.0
[PATCH] c6x: Use common DISCARDS in vmlinux.lds.S
Use the common DISCARDS rule for the linker script in an effort to regularize the linker script. Signed-off-by: Youling Tang --- arch/c6x/kernel/vmlinux.lds.S | 8 ++-- 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/c6x/kernel/vmlinux.lds.S b/arch/c6x/kernel/vmlinux.lds.S index ac99ba0..188a334 100644 --- a/arch/c6x/kernel/vmlinux.lds.S +++ b/arch/c6x/kernel/vmlinux.lds.S @@ -139,13 +139,9 @@ SECTIONS DWARF_DEBUG + DISCARDS /DISCARD/ : { - EXIT_TEXT - EXIT_DATA - EXIT_CALL - *(.discard) - *(.discard.*) - *(.interp) + *(.interp) } } -- 2.1.0
Re: [PATCH] arm64: vmlinux.lds.S: Drop redundant *.init.rodata.*
Hi, Ard On 11/19/2020 03:18 PM, Ard Biesheuvel wrote: On Thu, 19 Nov 2020 at 02:45, Youling Tang wrote: We currently try to emit *.init.rodata.* twice, once in INIT_DATA, and once in the line immediately following it. As the two section definitions are identical, the latter is redundant and can be dropped. This patch drops the redundant *.init.rodata.* section definition. Signed-off-by: Youling Tang .init.rodata.* was added to INIT_DATA in 266ff2a8f51f02b429a987d87634697eb0d01d6a, so removing it here seems reasonable. However, it does conflict with the for-next/lto branch in the arm64 tree. The possible causes of the conflict are e35123d83ee submit. master branch code as follows: ... INIT_RAM_FS *(.init.rodata.* .init.bss) /* from the EFI stub */ for-next/lto branch code as follows: ... INIT_RAM_FS *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ Thanks, Youling --- arch/arm64/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604..7dba3c4 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -201,7 +201,7 @@ SECTIONS INIT_CALLS CON_INITCALL INIT_RAM_FS - *(.init.rodata.* .init.bss) /* from the EFI stub */ + *(.init.bss)/* from the EFI stub */ } .exit.data : { EXIT_DATA -- 2.1.0
[PATCH] arm64: vmlinux.lds.S: Drop redundant *.init.rodata.*
We currently try to emit *.init.rodata.* twice, once in INIT_DATA, and once in the line immediately following it. As the two section definitions are identical, the latter is redundant and can be dropped. This patch drops the redundant *.init.rodata.* section definition. Signed-off-by: Youling Tang --- arch/arm64/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604..7dba3c4 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -201,7 +201,7 @@ SECTIONS INIT_CALLS CON_INITCALL INIT_RAM_FS - *(.init.rodata.* .init.bss) /* from the EFI stub */ + *(.init.bss)/* from the EFI stub */ } .exit.data : { EXIT_DATA -- 2.1.0
[PATCH] microblaze: Use the common INIT_DATA_SECTION macro in vmlinux.lds.S
Use the common INIT_DATA_SECTION rule for the linker script in an effort to regularize the linker script. Signed-off-by: Youling Tang --- arch/microblaze/kernel/vmlinux.lds.S | 24 +--- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/arch/microblaze/kernel/vmlinux.lds.S b/arch/microblaze/kernel/vmlinux.lds.S index df07b3d..527ebfc 100644 --- a/arch/microblaze/kernel/vmlinux.lds.S +++ b/arch/microblaze/kernel/vmlinux.lds.S @@ -96,10 +96,7 @@ SECTIONS { __init_begin = .; INIT_TEXT_SECTION(PAGE_SIZE) - - .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { - INIT_DATA - } + INIT_DATA_SECTION(0) . = ALIGN(4); .init.ivt : AT(ADDR(.init.ivt) - LOAD_OFFSET) { @@ -107,25 +104,6 @@ SECTIONS { *(.init.ivt) __ivt_end = .; } - - .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { - INIT_SETUP(0) - } - - .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET ) { - INIT_CALLS - } - - .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { - CON_INITCALL - } - - __init_end_before_initramfs = .; - - .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { - INIT_RAM_FS - } - __init_end = .; .bss ALIGN (PAGE_SIZE) : AT(ADDR(.bss) - LOAD_OFFSET) { -- 2.1.0
[PATCH] rtc: Fix memleak in sun6i_rtc_clk_init
When rtc->base or rtc->int_osc or rtc->losc or rtc->ext_losc is NULL, we should free clk_data and rtc before the function returns to prevent memleak. Signed-off-by: Youling Tang --- drivers/rtc/rtc-sun6i.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c index e2b8b15..84ff1e6 100644 --- a/drivers/rtc/rtc-sun6i.c +++ b/drivers/rtc/rtc-sun6i.c @@ -272,7 +272,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, 3); if (IS_ERR(rtc->int_osc)) { pr_crit("Couldn't register the internal oscillator\n"); - return; + goto err; } parents[0] = clk_hw_get_name(rtc->int_osc); @@ -290,7 +290,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, rtc->losc = clk_register(NULL, >hw); if (IS_ERR(rtc->losc)) { pr_crit("Couldn't register the LOSC clock\n"); - return; + goto err; } of_property_read_string_index(node, "clock-output-names", 1, @@ -301,7 +301,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, >lock); if (IS_ERR(rtc->ext_losc)) { pr_crit("Couldn't register the LOSC external gate\n"); - return; + goto err; } clk_data->num = 2; @@ -316,6 +316,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, err: kfree(clk_data); + kfree(rtc); } static const struct sun6i_rtc_clk_data sun6i_a31_rtc_data = { -- 2.1.0
[PATCH 2/2] arm: Fix kfree NULL pointer in omap2xxx_clkt_vps_init
The returns pointer is NULL when kzalloc fails to apply for space, so fix kfree NULL pointer. Signed-off-by: Youling Tang --- arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c index 70892b3..edf046b 100644 --- a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c +++ b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c @@ -235,7 +235,7 @@ void omap2xxx_clkt_vps_init(void) hw = kzalloc(sizeof(*hw), GFP_KERNEL); if (!hw) - goto cleanup; + return; init.name = "virt_prcm_set"; init.ops = _prcm_set_ops; init.parent_names = _name; @@ -251,8 +251,5 @@ void omap2xxx_clkt_vps_init(void) } clkdev_create(clk, "cpufreq_ck", NULL); - return; -cleanup: - kfree(hw); } #endif -- 2.1.0
[PATCH 1/2] arm: Fix memleak in omap2xxx_clkt_vps_init
If the clk_register fails, we should free hw before function returns to prevent memleak. Signed-off-by: Youling Tang --- arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c index 2a3e722..70892b3 100644 --- a/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c +++ b/arch/arm/mach-omap2/clkt2xxx_virt_prcm_set.c @@ -244,6 +244,12 @@ void omap2xxx_clkt_vps_init(void) hw->hw.init = clk = clk_register(NULL, >hw); + if (IS_ERR(clk)) { + printk(KERN_ERR "Failed to register clock\n"); + kfree(hw); + return; + } + clkdev_create(clk, "cpufreq_ck", NULL); return; cleanup: -- 2.1.0
[PATCH] mips: loongson64: Remove unnecessary external declaration
prom_init_memory() unused in loongson64, only used in loongson2ef, and has been declared in arch/mips/include/asm/mach-loongson2ef/loongson.h, so remove the external declaration in loongson64. Signed-off-by: Youling Tang --- arch/mips/include/asm/mach-loongson64/loongson.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/mips/include/asm/mach-loongson64/loongson.h b/arch/mips/include/asm/mach-loongson64/loongson.h index fde1b75..8433501 100644 --- a/arch/mips/include/asm/mach-loongson64/loongson.h +++ b/arch/mips/include/asm/mach-loongson64/loongson.h @@ -23,7 +23,6 @@ extern u32 memsize, highmemsize; extern const struct plat_smp_ops loongson3_smp_ops; /* loongson-specific command line, env and memory initialization */ -extern void __init prom_init_memory(void); extern void __init prom_init_env(void); extern void *loongson_fdt_blob; -- 2.1.0
[PATCH] mips: Use the common RW_DATA macro in vmlinux.lds.S
Use the common RW_DATA rule for the linker script in an effort to regularize the linker script. Signed-off-by: Youling Tang --- arch/mips/kernel/vmlinux.lds.S | 15 +++ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 5e97e9d..e2fa07e 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -84,18 +84,9 @@ SECTIONS _sdata = .; /* Start of data section */ RO_DATA(4096) - /* writeable */ - .data : { /* Data */ - . = . + DATAOFFSET; /* for CONFIG_MAPPED_KERNEL */ - - INIT_TASK_DATA(THREAD_SIZE) - NOSAVE_DATA - CACHELINE_ALIGNED_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT) - READ_MOSTLY_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT) - DATA_DATA - CONSTRUCTORS - } - BUG_TABLE + . = . + DATAOFFSET; /* for CONFIG_MAPPED_KERNEL */ + RW_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT, PAGE_SIZE, THREAD_SIZE) + _gp = . + 0x8000; .lit8 : { *(.lit8) -- 2.1.0
[PATCH] powerpc: Use the common INIT_DATA_SECTION macro in vmlinux.lds.S
Use the common INIT_DATA_SECTION rule for the linker script in an effort to regularize the linker script. Signed-off-by: Youling Tang --- arch/powerpc/kernel/vmlinux.lds.S | 19 +-- 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S index e0548b4..5dc05f3 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -186,21 +186,7 @@ SECTIONS EXIT_TEXT } - .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { - INIT_DATA - } - - .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { - INIT_SETUP(16) - } - - .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) { - INIT_CALLS - } - - .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) { - CON_INITCALL - } + INIT_DATA_SECTION(16) . = ALIGN(8); __ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) { @@ -228,9 +214,6 @@ SECTIONS __stop___fw_ftr_fixup = .; } #endif - .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) { - INIT_RAM_FS - } PERCPU_SECTION(L1_CACHE_BYTES) -- 2.1.0
[PATCH] mips: Modify the FLAGS attribute value of text segment in PHDRS
The attribute of the text segment should be read-only and executable, FLAGS(7) should be changed to FLAGS(5), like x86, s390 architecture. Signed-off-by: Youling Tang --- arch/mips/boot/compressed/ld.script | 2 +- arch/mips/kernel/vmlinux.lds.S | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/boot/compressed/ld.script b/arch/mips/boot/compressed/ld.script index 2ed08fb..35b0315 100644 --- a/arch/mips/boot/compressed/ld.script +++ b/arch/mips/boot/compressed/ld.script @@ -9,7 +9,7 @@ OUTPUT_ARCH(mips) ENTRY(start) PHDRS { - text PT_LOAD FLAGS(7); /* RWX */ + text PT_LOAD FLAGS(5); /* R_X */ } SECTIONS { diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S index 5e97e9d..545c4a9 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -22,7 +22,7 @@ OUTPUT_ARCH(mips) ENTRY(kernel_entry) PHDRS { - text PT_LOAD FLAGS(7); /* RWX */ + text PT_LOAD FLAGS(5); /* R_X */ #ifndef CONFIG_CAVIUM_OCTEON_SOC note PT_NOTE FLAGS(4); /* R__ */ #endif /* CAVIUM_OCTEON_SOC */ -- 2.1.0
[PATCH] arm64: Change the location of DISCARDS
In the include/asm-generic/vmlinux.lds.h file, the "must be the last" comment indicates that DISCARDS should be placed in the last position of SECTIONS, like x86, mips, riscv, etc. Signed-off-by: Youling Tang --- arch/arm64/kernel/vmlinux.lds.S | 13 +++-- 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index 1bda604..bf31074 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -109,12 +109,6 @@ SECTIONS * matching the same input section name. There is no documented * order of matching. */ - DISCARDS - /DISCARD/ : { - *(.interp .dynamic) - *(.dynsym .dynstr .hash .gnu.hash) - } - . = KIMAGE_VADDR; .head.text : { @@ -284,6 +278,13 @@ SECTIONS .data.rel.ro : { *(.data.rel.ro) } ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") + + /* Sections to be discarded */ + DISCARDS + /DISCARD/ : { + *(.interp .dynamic) + *(.dynsym .dynstr .hash .gnu.hash) + } } #include "image-vars.h" -- 2.1.0
Re: [PATCH] MIPS: kexec: Add crashkernel=YM handling
On 09/19/2020 03:02 PM, Jiaxun Yang wrote: 于 2020年9月19日 GMT+08:00 上午9:55:46, Youling Tang 写到: When the kernel crashkernel parameter is specified with just a size, we are supposed to allocate a region from RAM to store the crashkernel. However, MIPS merely reserves physical address zero with no checking that there is even RAM there. Fix this by lifting similar code from x86, importing it to MIPS with the MIPS specific parameters added. In the absence of any platform specific information, we allocate the crashkernel region from the first 512MB of physical memory (limited to CKSEG0 or KSEG0 address range). When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM). E.g. without this patch: The environment as follows: [0.00] MIPS: machine is loongson,loongson64c-4core-ls7a ... [0.00] Kernel command line: root=/dev/sda2 crashkernel=96M ... The warning as follows: [0.00] Invalid memory region reserved for crash kernel And the iomem as follows: 0020-0eff : System RAM 0020-00b47f87 : Kernel code 00b47f88-00df : Kernel data 00e6-01f73c7f : Kernel bss 1a00-1bff : pci@1a00 ... With this patch: After increasing crash_base <= 0 handling. And the iomem as follows: 0020-0eff : System RAM 0020-00b47f87 : Kernel code 00b47f88-00df : Kernel data 00e6-01f73c7f : Kernel bss 0400-09ff : Crash kernel 1a00-1bff : pci@1a00 ... Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 24 +--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index bf5f5ac..59a88ea 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr); #endif #ifdef CONFIG_KEXEC + +/* 64M alignment for crash kernel regions */ +#define CRASH_ALIGNSZ_64M +#define CRASH_ADDR_MAX SZ_512M Hi Youling How do you determine the alignment requirement? Can we relax it? Thanks. - Jiaxun Hi Jiaxun Only when XM is not specified, 64M alignment is specified. After the capture kernel is configured with CRASH_DUMP, PHYSICAL_START defaults to 0x0x8400 (64M). The kexec -p operation will succeed only when the reserved Crash kernel start address is consistent with PHYSICAL_START. The description of PHYSICAL_START in arch/mips/Kconfig:2996 is as follows: This gives the CKSEG0 or KSEG0 address where the kernel is loaded.If you plan to use kernel for capturing the crash dump change this value to start of the reserved region (the "X" value as specified in the "crashkernel=YM@XM" command line boot parameter passed to the panic-ed kernel). Thanks, - Youling + static void __init mips_parse_crashkernel(void) { unsigned long long total_mem; @@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void) if (ret != 0 || crash_size <= 0) return; - if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) { - pr_warn("Invalid memory region reserved for crash kernel\n"); - return; + if (crash_base <= 0) { + crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX, + crash_size, CRASH_ALIGN); + if (!crash_base) { + pr_warn("crashkernel reservation failed - No suitable area found.\n"); + return; + } + } else { + unsigned long long start; + + start = memblock_find_in_range(crash_base, crash_base + crash_size, + crash_size, 1); + if (start != crash_base) { + pr_warn("Invalid memory region reserved for crash kernel\n"); + return; + } } crashk_res.start = crash_base;
[PATCH] MIPS: kexec: Add crashkernel=YM handling
When the kernel crashkernel parameter is specified with just a size, we are supposed to allocate a region from RAM to store the crashkernel. However, MIPS merely reserves physical address zero with no checking that there is even RAM there. Fix this by lifting similar code from x86, importing it to MIPS with the MIPS specific parameters added. In the absence of any platform specific information, we allocate the crashkernel region from the first 512MB of physical memory (limited to CKSEG0 or KSEG0 address range). When X is not specified, crash_base defaults to 0 (crashkernel=YM@XM). E.g. without this patch: The environment as follows: [0.00] MIPS: machine is loongson,loongson64c-4core-ls7a ... [0.00] Kernel command line: root=/dev/sda2 crashkernel=96M ... The warning as follows: [0.00] Invalid memory region reserved for crash kernel And the iomem as follows: 0020-0eff : System RAM 0020-00b47f87 : Kernel code 00b47f88-00df : Kernel data 00e6-01f73c7f : Kernel bss 1a00-1bff : pci@1a00 ... With this patch: After increasing crash_base <= 0 handling. And the iomem as follows: 0020-0eff : System RAM 0020-00b47f87 : Kernel code 00b47f88-00df : Kernel data 00e6-01f73c7f : Kernel bss 0400-09ff : Crash kernel 1a00-1bff : pci@1a00 ... Signed-off-by: Youling Tang --- arch/mips/kernel/setup.c | 24 +--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index bf5f5ac..59a88ea 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -477,6 +477,11 @@ early_param("elfcorehdr", early_parse_elfcorehdr); #endif #ifdef CONFIG_KEXEC + +/* 64M alignment for crash kernel regions */ +#define CRASH_ALIGNSZ_64M +#define CRASH_ADDR_MAX SZ_512M + static void __init mips_parse_crashkernel(void) { unsigned long long total_mem; @@ -489,9 +494,22 @@ static void __init mips_parse_crashkernel(void) if (ret != 0 || crash_size <= 0) return; - if (!memblock_find_in_range(crash_base, crash_base + crash_size, crash_size, 1)) { - pr_warn("Invalid memory region reserved for crash kernel\n"); - return; + if (crash_base <= 0) { + crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX, + crash_size, CRASH_ALIGN); + if (!crash_base) { + pr_warn("crashkernel reservation failed - No suitable area found.\n"); + return; + } + } else { + unsigned long long start; + + start = memblock_find_in_range(crash_base, crash_base + crash_size, + crash_size, 1); + if (start != crash_base) { + pr_warn("Invalid memory region reserved for crash kernel\n"); + return; + } } crashk_res.start = crash_base; -- 2.1.0
Re: [PATCH] MIPS: Remove unused BOOT_MEM_INIT_RAM
On 09/14/2020 12:32 PM, Jiaxun Yang wrote: 在 2020/9/12 9:59, Youling Tang 写道: Commit a94e4f24ec83 ("MIPS: init: Drop boot_mem_map") left the BOOT_MEM_INIT_RAM unused, remove it. Signed-off-by: Youling Tang --- arch/mips/include/asm/bootinfo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h index 147c932..39196ae 100644 --- a/arch/mips/include/asm/bootinfo.h +++ b/arch/mips/include/asm/bootinfo.h @@ -91,7 +91,6 @@ extern unsigned long mips_machtype; #define BOOT_MEM_RAM1 #define BOOT_MEM_ROM_DATA2 #define BOOT_MEM_RESERVED3 -#define BOOT_MEM_INIT_RAM4 If you're willing to remove that you'd better turn the memtype struct into a enum. Hi Jiaxun, Do you mean to modify it as follows? enum boot_memtype { BOOT_MEM_RAM, BOOT_MEM_ROM_DATA, BOOT_MEM_RESERVED, BOOT_MEM_NOMAP, }; Thanks. - Youling Btw: It seems you've done a lot of minor clean-up works recently, if you'd like to I think you can try to turn all the platforms into memblock and remove all these gules between memblock and legacy code. Thanks. - Jiaxun #define BOOT_MEM_NOMAP5 extern void add_memory_region(phys_addr_t start, phys_addr_t size, long type);
[PATCH] MIPS: Remove unused BOOT_MEM_INIT_RAM
Commit a94e4f24ec83 ("MIPS: init: Drop boot_mem_map") left the BOOT_MEM_INIT_RAM unused, remove it. Signed-off-by: Youling Tang --- arch/mips/include/asm/bootinfo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h index 147c932..39196ae 100644 --- a/arch/mips/include/asm/bootinfo.h +++ b/arch/mips/include/asm/bootinfo.h @@ -91,7 +91,6 @@ extern unsigned long mips_machtype; #define BOOT_MEM_RAM 1 #define BOOT_MEM_ROM_DATA 2 #define BOOT_MEM_RESERVED 3 -#define BOOT_MEM_INIT_RAM 4 #define BOOT_MEM_NOMAP 5 extern void add_memory_region(phys_addr_t start, phys_addr_t size, long type); -- 2.1.0
[PATCH] MIPS: netlogic: Remove unused code
Remove some unused code. Signed-off-by: Youling Tang --- arch/mips/include/asm/netlogic/psb-bootinfo.h | 15 --- 1 file changed, 15 deletions(-) diff --git a/arch/mips/include/asm/netlogic/psb-bootinfo.h b/arch/mips/include/asm/netlogic/psb-bootinfo.h index 6878307..272544b 100644 --- a/arch/mips/include/asm/netlogic/psb-bootinfo.h +++ b/arch/mips/include/asm/netlogic/psb-bootinfo.h @@ -77,21 +77,6 @@ struct psb_info { uint64_t avail_mem_map; }; -enum { - NETLOGIC_IO_SPACE = 0x10, - PCIX_IO_SPACE, - PCIX_CFG_SPACE, - PCIX_MEMORY_SPACE, - HT_IO_SPACE, - HT_CFG_SPACE, - HT_MEMORY_SPACE, - SRAM_SPACE, - FLASH_CONTROLLER_SPACE -}; - -#define NLM_MAX_ARGS 64 -#define NLM_MAX_ENVS 32 - /* This is what netlboot passes and linux boot_mem_map is subtly different */ #define NLM_BOOT_MEM_MAP_MAX 32 struct nlm_boot_mem_map { -- 2.1.0
[PATCH] gpu: amd: Remove duplicate semicolons at the end of line
Remove duplicate semicolons at the end of line. Signed-off-by: Youling Tang --- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 2 +- drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c index e99bef6..8603a26 100644 --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c @@ -1108,7 +1108,7 @@ static int vcn_v2_5_mmsch_start(struct amdgpu_device *adev, { uint32_t data = 0, loop = 0, size = 0; uint64_t addr = table->gpu_addr; - struct mmsch_v1_1_init_header *header = NULL;; + struct mmsch_v1_1_init_header *header = NULL; header = (struct mmsch_v1_1_init_header *)table->cpu_addr; size = header->total_size; diff --git a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c index afdd4f0..b320931 100644 --- a/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c +++ b/drivers/gpu/drm/amd/display/dc/dml/display_mode_vba.c @@ -467,7 +467,7 @@ static void fetch_pipe_params(struct display_mode_lib *mode_lib) mode_lib->vba.AudioSampleLayout[mode_lib->vba.NumberOfActivePlanes] = 1; mode_lib->vba.DRAMClockChangeLatencyOverride = 0.0; - mode_lib->vba.DSCEnabled[mode_lib->vba.NumberOfActivePlanes] = dout->dsc_enable;; + mode_lib->vba.DSCEnabled[mode_lib->vba.NumberOfActivePlanes] = dout->dsc_enable; mode_lib->vba.DSCEnable[mode_lib->vba.NumberOfActivePlanes] = dout->dsc_enable; mode_lib->vba.NumberOfDSCSlices[mode_lib->vba.NumberOfActivePlanes] = dout->dsc_slices; -- 2.1.0
[PATCH] MIPS: Loongson64: Fix build error about redeclaration of enumerator 'VIRTUAL' and "CONFIG_DM_THIN_PROVISIONING"
After commit 39c1485c8baa (MIPS: KVM: Add kvm guestsupport for Loongson-3) Fix the following build error: drivers/md/dm-thin.c:116:2: error: redeclaration of enumerator ‘VIRTUAL’ VIRTUAL, ^ In file included from ./arch/mips/include/asm/mach-loongson64/mmzone.h:12:0, from ./arch/mips/include/asm/mmzone.h:12, from ./include/linux/mmzone.h:962, from ./include/linux/gfp.h:6, from ./include/linux/slab.h:15, from ./include/linux/genhd.h:16, from ./include/linux/blkdev.h:8, from drivers/md/persistent-data/dm-block-manager.h:11, from drivers/md/dm-thin-metadata.h:10, from drivers/md/dm-thin.c:7: ./arch/mips/include/asm/mach-loongson64/boot_param.h:198:2: note: previous definition of ‘VIRTUAL’ was here VIRTUAL = 3 ^ scripts/Makefile.build:283: recipe for target 'drivers/md/dm-thin.o' failed make[2]: *** [drivers/md/dm-thin.o] Error 1 Signed-off-by: Youling Tang --- arch/mips/include/asm/mach-loongson64/boot_param.h | 2 +- arch/mips/loongson64/env.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index afc92b7..a4ef4ac 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -195,7 +195,7 @@ struct boot_params { enum loongson_bridge_type { LS7A = 1, RS780E = 2, - VIRTUAL = 3 + VIRT = 3 }; struct loongson_system_configuration { diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c index 134cb8e..623b3f1 100644 --- a/arch/mips/loongson64/env.c +++ b/arch/mips/loongson64/env.c @@ -180,8 +180,8 @@ void __init prom_init_env(void) loongson_sysconf.early_config = rs780e_early_config; break; default: - pr_info("The bridge chip is VIRTUAL\n"); - loongson_sysconf.bridgetype = VIRTUAL; + pr_info("The bridge chip is VIRT\n"); + loongson_sysconf.bridgetype = VIRT; loongson_sysconf.early_config = virtual_early_config; loongson_fdt_blob = __dtb_loongson64v_4core_virtio_begin; break; -- 2.1.0
Re: [PATCH] kexec: Delete an unnecessary comparison
On 08/14/2020 02:07 PM, Joe Perches wrote: On Thu, 2020-08-13 at 20:45 +0800, Youling Tang wrote: Regardless of whether the ret value is zero or non-zero, the trajectory of the program execution is the same, so there is no need to compare. Signed-off-by: Youling Tang --- kernel/kexec_file.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 78c0837..3ad0ae2 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image) ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest", digest, SHA256_DIGEST_SIZE, 0); - if (ret) - goto out_free_digest; } out_free_digest: If you really want to change the function, then you could change a couple of breaks to gotos, remove multiple unnecessary tests, and unindent a block of code too. --- kernel/kexec_file.c | 30 -- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index ca40bef75a61..34a025e85887 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -763,7 +763,7 @@ static int kexec_calculate_store_digests(struct kimage *image) ret = crypto_shash_update(desc, ksegment->kbuf, ksegment->bufsz); if (ret) - break; + goto out_free_digest; /* * Assume rest of the buffer is filled with zero and @@ -777,32 +777,26 @@ static int kexec_calculate_store_digests(struct kimage *image) bytes = zero_buf_sz; ret = crypto_shash_update(desc, zero_buf, bytes); if (ret) - break; + goto out_free_digest; nullsz -= bytes; } - if (ret) - break; - sha_regions[j].start = ksegment->mem; sha_regions[j].len = ksegment->memsz; j++; } - if (!ret) { - ret = crypto_shash_final(desc, digest); - if (ret) - goto out_free_digest; - ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions", -sha_regions, sha_region_sz, 0); - if (ret) - goto out_free_digest; + ret = crypto_shash_final(desc, digest); + if (ret) + goto out_free_digest; - ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest", -digest, SHA256_DIGEST_SIZE, 0); - if (ret) - goto out_free_digest; - } + ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha_regions", +sha_regions, sha_region_sz, 0); + if (ret) + goto out_free_digest; + + ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest", +digest, SHA256_DIGEST_SIZE, 0); out_free_digest: kfree(digest); OK, looks good to me, I will send v2. Thanks, Youling
[PATCH] kexec: Delete an unnecessary comparison
Regardless of whether the ret value is zero or non-zero, the trajectory of the program execution is the same, so there is no need to compare. Signed-off-by: Youling Tang --- kernel/kexec_file.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 78c0837..3ad0ae2 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -800,8 +800,6 @@ static int kexec_calculate_store_digests(struct kimage *image) ret = kexec_purgatory_get_set_symbol(image, "purgatory_sha256_digest", digest, SHA256_DIGEST_SIZE, 0); - if (ret) - goto out_free_digest; } out_free_digest: -- 2.1.0
[PATCH] sound/soc/intel: Fix spelling mistake "cant" --> "can't"
There is some spelling mistakes in a dev_err message. Fix it. Signed-off-by: Youling Tang --- sound/soc/intel/common/sst-firmware.c | 4 ++-- sound/soc/intel/haswell/sst-haswell-ipc.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/intel/common/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c index 0594f89..1189ec3 100644 --- a/sound/soc/intel/common/sst-firmware.c +++ b/sound/soc/intel/common/sst-firmware.c @@ -130,7 +130,7 @@ static void block_list_remove(struct sst_dsp *dsp, err = block->ops->disable(block); if (err < 0) dev_err(dsp->dev, - "error: cant disable block %d:%d\n", + "error: can't disable block %d:%d\n", block->type, block->index); } } @@ -158,7 +158,7 @@ static int block_list_prepare(struct sst_dsp *dsp, ret = block->ops->enable(block); if (ret < 0) { dev_err(dsp->dev, - "error: cant disable block %d:%d\n", + "error: can't disable block %d:%d\n", block->type, block->index); goto err; } diff --git a/sound/soc/intel/haswell/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c index 0ff89ea..773688b 100644 --- a/sound/soc/intel/haswell/sst-haswell-ipc.c +++ b/sound/soc/intel/haswell/sst-haswell-ipc.c @@ -1507,7 +1507,7 @@ static int sst_hsw_dx_state_dump(struct sst_hsw *hsw) ret = sst_dsp_dma_get_channel(sst, 0); if (ret < 0) { - dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret); + dev_err(hsw->dev, "error: can't allocate dma channel %d\n", ret); return ret; } @@ -1587,7 +1587,7 @@ int sst_hsw_dsp_load(struct sst_hsw *hsw) ret = sst_dsp_dma_get_channel(dsp, 0); if (ret < 0) { - dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret); + dev_err(hsw->dev, "error: can't allocate dma channel %d\n", ret); return ret; } @@ -1616,7 +1616,7 @@ static int sst_hsw_dsp_restore(struct sst_hsw *hsw) ret = sst_dsp_dma_get_channel(dsp, 0); if (ret < 0) { - dev_err(hsw->dev, "error: cant allocate dma channel %d\n", ret); + dev_err(hsw->dev, "error: can't allocate dma channel %d\n", ret); return ret; } -- 2.1.0
[PATCH v3] tools/objtool: Fix unnecessary jumps
Previously cleanup() function was called under the out label for both fatal errors (ret < 0) and warnings. Now that cleanup() function is removed, the out label is no longer required. Remove it and return immediately for the fatal errors with ret as return code and 0 for warnings. Signed-off-by: Youling Tang Reviewed-by: Kamalesh Babulal --- tools/objtool/check.c | 30 ++ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e034a8f..b9bfcb5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2799,19 +2799,19 @@ int check(const char *_objname, bool orc) ret = decode_sections(); if (ret < 0) - goto out; + return ret; warnings += ret; if (list_empty(_list)) - goto out; + return ret; if (vmlinux && !validate_dup) { ret = validate_vmlinux_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; - goto out; + return 0; } if (retpoline) { @@ -2823,45 +2823,35 @@ int check(const char *_objname, bool orc) ret = validate_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; ret = validate_unwind_hints(, NULL); if (ret < 0) - goto out; + return ret; warnings += ret; if (!warnings) { ret = validate_reachable_instructions(); if (ret < 0) - goto out; + return ret; warnings += ret; } if (orc) { ret = create_orc(); if (ret < 0) - goto out; + return ret; ret = create_orc_sections(); if (ret < 0) - goto out; + return ret; } if (file.elf->changed) { ret = elf_write(file.elf); if (ret < 0) - goto out; - } - -out: - if (ret < 0) { - /* -* Fatal error. The binary is corrupt or otherwise broken in -* some way, or objtool itself is broken. Fail the kernel -* build. -*/ - return ret; + return ret; } return 0; -- 2.1.0
[PATCH] [v2] tools/objtool: Fix unnecessary jumps
There is no need to jump to the "out" tag when "ret < 0", just return directly to "ret". Signed-off-by: Youling Tang --- tools/objtool/check.c | 30 ++ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e034a8f..b9bfcb5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2799,19 +2799,19 @@ int check(const char *_objname, bool orc) ret = decode_sections(); if (ret < 0) - goto out; + return ret; warnings += ret; if (list_empty(_list)) - goto out; + return ret; if (vmlinux && !validate_dup) { ret = validate_vmlinux_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; - goto out; + return 0; } if (retpoline) { @@ -2823,45 +2823,35 @@ int check(const char *_objname, bool orc) ret = validate_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; ret = validate_unwind_hints(, NULL); if (ret < 0) - goto out; + return ret; warnings += ret; if (!warnings) { ret = validate_reachable_instructions(); if (ret < 0) - goto out; + return ret; warnings += ret; } if (orc) { ret = create_orc(); if (ret < 0) - goto out; + return ret; ret = create_orc_sections(); if (ret < 0) - goto out; + return ret; } if (file.elf->changed) { ret = elf_write(file.elf); if (ret < 0) - goto out; - } - -out: - if (ret < 0) { - /* -* Fatal error. The binary is corrupt or otherwise broken in -* some way, or objtool itself is broken. Fail the kernel -* build. -*/ - return ret; + return ret; } return 0; -- 2.1.0
Re: [PATCH] tools/objtool: Fix unnecessary jumps
Thank you for your reply and suggestions, I will remove the "out" label code. Thanks, Youling On 08/10/2020 08:57 PM, Kamalesh Babulal wrote: On 10/08/20 9:36 am, Youling Tang wrote: There is no need to jump to the "out" tag when "ret < 0", just return directly to "ret". Signed-off-by: Youling Tang --- tools/objtool/check.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e034a8f..94b166d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c [snip] if (file.elf->changed) { ret = elf_write(file.elf); if (ret < 0) - goto out; + return ret; } out: the out label code is no more required with this change, so remove it and return 0 for warnings for now. Previously cleanup() function was called under the out label for both fatal errors (ret < 0) and warnings. Now that cleanup() function is removed, the out label is no longer required.
[PATCH] tools/objtool: Fix unnecessary jumps
There is no need to jump to the "out" tag when "ret < 0", just return directly to "ret". Signed-off-by: Youling Tang --- tools/objtool/check.c | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e034a8f..94b166d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2799,7 +2799,7 @@ int check(const char *_objname, bool orc) ret = decode_sections(); if (ret < 0) - goto out; + return ret; warnings += ret; if (list_empty(_list)) @@ -2808,7 +2808,7 @@ int check(const char *_objname, bool orc) if (vmlinux && !validate_dup) { ret = validate_vmlinux_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; goto out; @@ -2823,35 +2823,35 @@ int check(const char *_objname, bool orc) ret = validate_functions(); if (ret < 0) - goto out; + return ret; warnings += ret; ret = validate_unwind_hints(, NULL); if (ret < 0) - goto out; + return ret; warnings += ret; if (!warnings) { ret = validate_reachable_instructions(); if (ret < 0) - goto out; + return ret; warnings += ret; } if (orc) { ret = create_orc(); if (ret < 0) - goto out; + return ret; ret = create_orc_sections(); if (ret < 0) - goto out; + return ret; } if (file.elf->changed) { ret = elf_write(file.elf); if (ret < 0) - goto out; + return ret; } out: -- 2.1.0
[PATCH] kernel/debug: Fix spelling mistake in debug_core.c
Fix typo: "notifiter" --> "notifier" "overriden" --> "overridden" Signed-off-by: Youling Tang --- kernel/debug/debug_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index b16dbc1..30a 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -80,7 +80,7 @@ static intexception_level; struct kgdb_io *dbg_io_ops; static DEFINE_SPINLOCK(kgdb_registration_lock); -/* Action for the reboot notifiter, a global allow kdb to change it */ +/* Action for the reboot notifier, a global allow kdb to change it */ static int kgdbreboot; /* kgdb console driver is loaded */ static int kgdb_con_registered; @@ -163,7 +163,7 @@ early_param("nokgdbroundup", opt_nokgdbroundup); /* * Weak aliases for breakpoint management, - * can be overriden by architectures when needed: + * can be overridden by architectures when needed: */ int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) { -- 2.1.0
[PATCH] scsi/aic7xxx/aicasm: Add missing fclose() call
Add missing fclose() call to close "regdiagfile" in the function stop(). Signed-off-by: Youling Tang --- drivers/scsi/aic7xxx/aicasm/aicasm.c | 9 + 1 file changed, 9 insertions(+) diff --git a/drivers/scsi/aic7xxx/aicasm/aicasm.c b/drivers/scsi/aic7xxx/aicasm/aicasm.c index 5f474e4..a504058 100644 --- a/drivers/scsi/aic7xxx/aicasm/aicasm.c +++ b/drivers/scsi/aic7xxx/aicasm/aicasm.c @@ -722,6 +722,15 @@ stop(const char *string, int err_code) } } + if (regdiagfile != NULL) { + fclose(regdiagfile); + if (err_code != 0) { + fprintf(stderr, "%s: Removing %s due to error\n", + appname, regdiagfilename); + unlink(regdiagfilename); + } + } + symlist_free(_functions); symtable_close(); -- 2.1.0