From patchwork Sat Jan 13 09:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 13518928 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF19A15C9 for ; Sat, 13 Jan 2024 09:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8AxzegmXqJlG8cEAA--.5466S3; Sat, 13 Jan 2024 17:55:50 +0800 (CST) Received: from localhost.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx+4YOXqJlpoQYAA--.930S3; Sat, 13 Jan 2024 17:55:49 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer Cc: Bibo Mao , linux-mips@vger.kernel.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen Subject: [PATCH 1/3] MIPS: adjust exception vector space revervation Date: Sat, 13 Jan 2024 17:55:07 +0800 Message-Id: <20240113095509.178697-2-huangpei@loongson.cn> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240113095509.178697-1-huangpei@loongson.cn> References: <20240113095509.178697-1-huangpei@loongson.cn> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx+4YOXqJlpoQYAA--.930S3 X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj9xXoW7JFy5CrWrur43JFWxXr13GFX_yoWktwc_Aw n2qws7Gr4Utw4Y9w1Ut3WfG3yYk393KrWUZ3ZrGa4av3y5Jr15tan0ga45ZFn3G3WkZrWr Cw1YkFZFk3W2qosvyTuYvTs0mTUanT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvT s0mT0YCTnIWjqI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUI cSsGvfJTRUUUbVAYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20x vaj40_Wr0E3s1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8 JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2 x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1D McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr4 1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_ JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU 0xZFpf9x07j5xhLUUUUU= MIPS R2+ use CP0_Ebase to setup a new exception vector space, instead of using 0x0-0x1000, so it is unnecessary to reserve 0x0-0x1000 for MIPS R2+. If this range is not within valid memoryblock.memory range, memory initialization with CONFIG_DEFERRED_STRUCT_PAGE_INIT failed on 3A1000+(3A1000+ needs other machine-specific fix ) after 61167ad5fecd ("mm: pass nid to reserve_bootmem_region()") Call reserve_exception_space(0,0x1000) only ONCE whether UP or SMP. Signed-off-by: Huang Pei --- arch/mips/kernel/cpu-probe.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c index b406d8bfb15a..3da35e20d70d 100644 --- a/arch/mips/kernel/cpu-probe.c +++ b/arch/mips/kernel/cpu-probe.c @@ -1992,12 +1992,14 @@ void cpu_probe(void) */ loongson3_cpucfg_synthesize_data(c); + if (cpu == 0) { #ifdef CONFIG_64BIT - if (cpu == 0) __ua_limit = ~((1ull << cpu_vmbits) - 1); #endif + if(!cpu_has_mips_r2_r6) + reserve_exception_space(0, 0x1000); + } - reserve_exception_space(0, 0x1000); } void cpu_report(void) From patchwork Sat Jan 13 09:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 13518929 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF1D3C8DD for ; Sat, 13 Jan 2024 09:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8DxvOgnXqJlH8cEAA--.5370S3; Sat, 13 Jan 2024 17:55:51 +0800 (CST) Received: from localhost.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx+4YOXqJlpoQYAA--.930S4; Sat, 13 Jan 2024 17:55:50 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer Cc: Bibo Mao , linux-mips@vger.kernel.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen Subject: [PATCH 2/3] MIPS: loongson64: fix booting failure Date: Sat, 13 Jan 2024 17:55:08 +0800 Message-Id: <20240113095509.178697-3-huangpei@loongson.cn> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240113095509.178697-1-huangpei@loongson.cn> References: <20240113095509.178697-1-huangpei@loongson.cn> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx+4YOXqJlpoQYAA--.930S4 X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxJFWxtrW5Cr1DGF47uF1fKrX_yoW5Wr4rpr 1fJr17Cr48Jr1UJr4UJr15Xr18Aa1jy3ZrJrW7Jr18Xr1DCF1UJr1UJr1FgryDJrWUJr17 tF1DJr4jqw1DJwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8EeHDUUUUU== Inappropriate memblock_reserve cause loongson64 booting failed with CONFIG_DEFERRED_STRUCT_PAGE_INIT like this: ---------------------------------------------------------------------- Call Trace: [] reserve_bootmem_region+0xa8/0x184 [] memblock_free_all+0x104/0x2a8 [] mem_init+0x84/0x94 [] mm_core_init+0xf8/0x308 [] start_kernel+0x43c/0x86c Code: 10400028 2402fff0 de420000 0203182b 14600022 64420070 00003025 24040003 ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Attempted to kill the idle task! ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]--- ---------------------------------------------------------------------- The root cause is no memory region "0x0-0x1fffff" paired with memory-reserved region "0x0-0x1fffff" and "0x0-0xfff", with "memblock =debug": ---------------------------------------------------------------------- memory[0x0] [0x0000000000200000-0x000000000effffff], 0x000000000ee00000 bytes on node 0 flags: 0x0 !!!!here memory[0x1] [0x0000000090000000-0x00000000fdffffff], 0x000000006e000000 bytes on node 0 flags: 0x0 memory[0x2] [0x0000000100000000-0x000000027fffffff], 0x0000000180000000 bytes on node 0 flags: 0x0 memory[0x3] [0x0000100000000000-0x000010000fffffff], 0x0000000010000000 bytes on node 1 flags: 0x0 memory[0x4] [0x0000100090000000-0x000010027fffffff], 0x00000001f0000000 bytes on node 1 flags: 0x0 reserved.cnt = 0x1f reserved[0x0] [0x0000000000000000-0x000000000190c80a], 0x000000000190c80b bytes flags: 0x0 !!!!oops 0x0-0x1fffff not in memory[0] reserved[0x1] [0x000000000190c810-0x000000000190eea3], 0x0000000000002694 bytes flags: 0x0 ---------------------------------------------------------------------- To fix this bug, we should remove unnecessary memory block reservation. Fixes: commit 61167ad5fecd("mm: pass nid to reserve_bootmem_region()) Signed-off-by: Huang Pei --- arch/mips/loongson64/numa.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/mips/loongson64/numa.c b/arch/mips/loongson64/numa.c index 8f61e93c0c5b..9b4ce40c1d40 100644 --- a/arch/mips/loongson64/numa.c +++ b/arch/mips/loongson64/numa.c @@ -129,9 +129,6 @@ static void __init node_mem_init(unsigned int node) if (node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT)) memblock_reserve((node_addrspace_offset | 0xfe000000), 32 << 20); - - /* Reserve pfn range 0~node[0]->node_start_pfn */ - memblock_reserve(0, PAGE_SIZE * start_pfn); } } From patchwork Sat Jan 13 09:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Pei X-Patchwork-Id: 13518930 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2916512E7B for ; Sat, 13 Jan 2024 09:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [111.9.175.10]) by gateway (Coremail) with SMTP id _____8AxSeooXqJlI8cEAA--.5313S3; Sat, 13 Jan 2024 17:55:52 +0800 (CST) Received: from localhost.localdomain (unknown [111.9.175.10]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx+4YOXqJlpoQYAA--.930S5; Sat, 13 Jan 2024 17:55:51 +0800 (CST) From: Huang Pei To: Thomas Bogendoerfer Cc: Bibo Mao , linux-mips@vger.kernel.org, Jiaxun Yang , Paul Burton , Li Xuefeng , Yang Tiezhu , Gao Juxin , Huacai Chen Subject: [PATCH 3/3] Revert "MIPS: Loongson64: Handle more memory types passed from firmware" Date: Sat, 13 Jan 2024 17:55:09 +0800 Message-Id: <20240113095509.178697-4-huangpei@loongson.cn> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240113095509.178697-1-huangpei@loongson.cn> References: <20240113095509.178697-1-huangpei@loongson.cn> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx+4YOXqJlpoQYAA--.930S5 X-CM-SenderInfo: xkxd0whshlqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxZr15WryDWFyDWw1kKw43CFX_yoWrtr13pr 1fAFyxKr4Yqr1xC3yxtry5WrWkZ3Z5C39rArWqvrnYqF1DCw1Iqr15tr40q34DAFWkX3ZF qrZ8ta18K3Z3K3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9jb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y 6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r4j6ryUMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU8EeHDUUUUU== This reverts commit 264927e3538169fe2973a5732f03ea01b0f9f9e8. The SMBIOS memory reserved region(0xfffe000-0xfffe7ff) is not OWNED by kenel, here OWNED means the region is within the physical memory given to kernel by firmware as SYSTEM_RAM_{LOW,HIGH}. Since commit 61167ad5fecd("mm: pass nid to reserve_bootmem_region()), loongson64 booting failed with CONFIG_DEFERRED_STRUCT_PAGE_INIT like this: ---------------------------------------------------------------------- Call Trace: [] reserve_bootmem_region+0xa8/0x184 [] memblock_free_all+0x104/0x2a8 [] mem_init+0x84/0x94 [] mm_core_init+0xf8/0x308 [] start_kernel+0x43c/0x86c Code: 10400028 2402fff0 de420000 0203182b 14600022 64420070 00003025 24040003 ---[ end trace 0000000000000000 ]--- Kernel panic - not syncing: Attempted to kill the idle task! ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]--- ---------------------------------------------------------------------- This is another case of inappropriate usage of memblock_reserve --- .../include/asm/mach-loongson64/boot_param.h | 6 +-- arch/mips/loongson64/init.c | 42 +++++++------------ 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index e007edd6b60a..c454ef734c45 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -14,11 +14,7 @@ #define ADAPTER_ROM 8 #define ACPI_TABLE 9 #define SMBIOS_TABLE 10 -#define UMA_VIDEO_RAM 11 -#define VUMA_VIDEO_RAM 12 -#define MAX_MEMORY_TYPE 13 - -#define MEM_SIZE_IS_IN_BYTES (1 << 31) +#define MAX_MEMORY_TYPE 11 #define LOONGSON3_BOOT_MEM_MAP_MAX 128 struct efi_memory_map_loongson { diff --git a/arch/mips/loongson64/init.c b/arch/mips/loongson64/init.c index f25caa6aa9d3..d62262f93069 100644 --- a/arch/mips/loongson64/init.c +++ b/arch/mips/loongson64/init.c @@ -49,7 +49,8 @@ void virtual_early_config(void) void __init szmem(unsigned int node) { u32 i, mem_type; - phys_addr_t node_id, mem_start, mem_size; + static unsigned long num_physpages; + u64 node_id, node_psize, start_pfn, end_pfn, mem_start, mem_size; /* Otherwise come from DTB */ if (loongson_sysconf.fw_interface != LOONGSON_LEFI) @@ -63,38 +64,27 @@ void __init szmem(unsigned int node) mem_type = loongson_memmap->map[i].mem_type; mem_size = loongson_memmap->map[i].mem_size; - - /* Memory size comes in MB if MEM_SIZE_IS_IN_BYTES not set */ - if (mem_size & MEM_SIZE_IS_IN_BYTES) - mem_size &= ~MEM_SIZE_IS_IN_BYTES; - else - mem_size = mem_size << 20; - - mem_start = (node_id << 44) | loongson_memmap->map[i].mem_start; + mem_start = loongson_memmap->map[i].mem_start; switch (mem_type) { case SYSTEM_RAM_LOW: case SYSTEM_RAM_HIGH: - case UMA_VIDEO_RAM: - pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes usable\n", - (u32)node_id, mem_type, &mem_start, &mem_size); - memblock_add_node(mem_start, mem_size, node, + start_pfn = ((node_id << 44) + mem_start) >> PAGE_SHIFT; + node_psize = (mem_size << 20) >> PAGE_SHIFT; + end_pfn = start_pfn + node_psize; + num_physpages += node_psize; + pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", + (u32)node_id, mem_type, mem_start, mem_size); + pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n", + start_pfn, end_pfn, num_physpages); + memblock_add_node(PFN_PHYS(start_pfn), + PFN_PHYS(node_psize), node, MEMBLOCK_NONE); break; case SYSTEM_RAM_RESERVED: - case VIDEO_ROM: - case ADAPTER_ROM: - case ACPI_TABLE: - case SMBIOS_TABLE: - pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes reserved\n", - (u32)node_id, mem_type, &mem_start, &mem_size); - memblock_reserve(mem_start, mem_size); - break; - /* We should not reserve VUMA_VIDEO_RAM as it overlaps with MMIO */ - case VUMA_VIDEO_RAM: - default: - pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes unhandled\n", - (u32)node_id, mem_type, &mem_start, &mem_size); + pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n", + (u32)node_id, mem_type, mem_start, mem_size); + memblock_reserve(((node_id << 44) + mem_start), mem_size << 20); break; } }