From: gaosong <gaosong@loongson.cn>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org,
Tianrui Zhao <zhaotianrui@loongson.cn>
Subject: Re: [PULL 3/5] hw/loongarch: Add numa support
Date: Tue, 7 May 2024 09:29:48 +0800 [thread overview]
Message-ID: <489aec57-4c01-ac41-8133-765bbf55e782@loongson.cn> (raw)
In-Reply-To: <CAFEAcA_iu05EA+XZ4ENW_5QZ4uxLNzmY5FV9W_Ev1KFaZaJ+hw@mail.gmail.com>
在 2024/5/3 下午8:50, Peter Maydell 写道:
> On Fri, 16 Jun 2023 at 11:03, Song Gao <gaosong@loongson.cn> wrote:
>> From: Tianrui Zhao <zhaotianrui@loongson.cn>
>>
>> 1. Implement some functions for LoongArch numa support;
>> 2. Implement fdt_add_memory_node() for fdt;
>> 3. build_srat() fills node_id and adds build numa memory.
>>
>> Reviewed-by: Song Gao <gaosong@loongson.cn>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Message-Id: <20230613122613.2471743-1-zhaotianrui@loongson.cn>
> Hi; Coverity has pointed out a memory leak in this commit
> (CID 1544773):
>
>> @@ -799,17 +823,43 @@ static void loongarch_init(MachineState *machine)
>> machine->possible_cpus->cpus[i].cpu = OBJECT(cpu);
>> }
>> fdt_add_cpu_nodes(lams);
>> - /* Add memory region */
>> - memory_region_init_alias(&lams->lowmem, NULL, "loongarch.lowram",
>> - machine->ram, 0, 256 * MiB);
>> - memory_region_add_subregion(address_space_mem, offset, &lams->lowmem);
>> - offset += 256 * MiB;
>> - memmap_add_entry(0, 256 * MiB, 1);
>> - highram_size = ram_size - 256 * MiB;
>> - memory_region_init_alias(&lams->highmem, NULL, "loongarch.highmem",
>> - machine->ram, offset, highram_size);
>> - memory_region_add_subregion(address_space_mem, 0x90000000, &lams->highmem);
>> - memmap_add_entry(0x90000000, highram_size, 1);
>> +
>> + /* Node0 memory */
>> + memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1);
>> + fdt_add_memory_node(machine, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 0);
>> + memory_region_init_alias(&lams->lowmem, NULL, "loongarch.node0.lowram",
>> + machine->ram, offset, VIRT_LOWMEM_SIZE);
>> + memory_region_add_subregion(address_space_mem, phyAddr, &lams->lowmem);
>> +
>> + offset += VIRT_LOWMEM_SIZE;
>> + if (nb_numa_nodes > 0) {
>> + assert(numa_info[0].node_mem > VIRT_LOWMEM_SIZE);
>> + highram_size = numa_info[0].node_mem - VIRT_LOWMEM_SIZE;
>> + } else {
>> + highram_size = ram_size - VIRT_LOWMEM_SIZE;
>> + }
>> + phyAddr = VIRT_HIGHMEM_BASE;
>> + memmap_add_entry(phyAddr, highram_size, 1);
>> + fdt_add_memory_node(machine, phyAddr, highram_size, 0);
>> + memory_region_init_alias(&lams->highmem, NULL, "loongarch.node0.highram",
>> + machine->ram, offset, highram_size);
>> + memory_region_add_subregion(address_space_mem, phyAddr, &lams->highmem);
>> +
>> + /* Node1 - Nodemax memory */
>> + offset += highram_size;
>> + phyAddr += highram_size;
>> +
>> + for (i = 1; i < nb_numa_nodes; i++) {
>> + MemoryRegion *nodemem = g_new(MemoryRegion, 1);
>> + ramName = g_strdup_printf("loongarch.node%d.ram", i);
>> + memory_region_init_alias(nodemem, NULL, ramName, machine->ram,
>> + offset, numa_info[i].node_mem);
>> + memory_region_add_subregion(address_space_mem, phyAddr, nodemem);
>> + memmap_add_entry(phyAddr, numa_info[i].node_mem, 1);
>> + fdt_add_memory_node(machine, phyAddr, numa_info[i].node_mem, i);
>> + offset += numa_info[i].node_mem;
>> + phyAddr += numa_info[i].node_mem;
> In this loop, we allocate memory via g_strdup_printf(),
> but never free it. The nicest fix for this is to use the
> g_autofree mechanism so that the memory is automatically
> freed when execution reaches the end of the block:
> g_autofree ramName = g_strdup_printf("....", ...);
Thank you. I will fix it.
Thanks
Song Gao
> thanks
> -- PMM
next prev parent reply other threads:[~2024-05-07 1:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 10:01 [PULL 0/5] loongarch-to-apply queue Song Gao
2023-06-16 10:01 ` [PULL 1/5] hw/loongarch/virt: Add cpu arch_id support Song Gao
2023-06-16 10:01 ` [PULL 2/5] hw/intc: Set physical cpuid route for LoongArch ipi device Song Gao
2023-06-16 10:01 ` [PULL 3/5] hw/loongarch: Add numa support Song Gao
2024-05-03 12:50 ` Peter Maydell
2024-05-07 1:29 ` gaosong [this message]
2023-06-16 10:01 ` [PULL 4/5] hw/loongarch: Supplement cpu topology arguments Song Gao
2023-06-16 10:01 ` [PULL 5/5] target/loongarch: Fix CSR.DMW0-3.VSEG check Song Gao
2023-06-17 8:02 ` [PULL 0/5] loongarch-to-apply queue Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=489aec57-4c01-ac41-8133-765bbf55e782@loongson.cn \
--to=gaosong@loongson.cn \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zhaotianrui@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).