From: "Björn Töpel" <bjorn@kernel.org>
To: David Hildenbrand <david@redhat.com>,
Alexandre Ghiti <alexghiti@rivosinc.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
linux-riscv@lists.infradead.org
Cc: "Björn Töpel" <bjorn@rivosinc.com>,
"Andrew Bresticker" <abrestic@rivosinc.com>,
"Chethan Seshadri" <Chethan.Seshadri@catalinasystems.io>,
"Lorenzo Stoakes" <lstoakes@gmail.com>,
"Oscar Salvador" <osalvador@suse.de>,
"Santosh Mamila" <santosh.mamila@catalinasystems.io>,
"Sivakumar Munnangi" <siva.munnangi@catalinasystems.io>,
"Sunil V L" <sunilvl@ventanamicro.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v2 4/8] riscv: mm: Add memory hotplugging support
Date: Tue, 14 May 2024 18:34:46 +0200 [thread overview]
Message-ID: <87r0e4tkrd.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <267be75e-ed4a-45d0-883f-51c7324c30f1@redhat.com>
David Hildenbrand <david@redhat.com> writes:
> On 14.05.24 16:04, Björn Töpel wrote:
>> From: Björn Töpel <bjorn@rivosinc.com>
>>
>> For an architecture to support memory hotplugging, a couple of
>> callbacks needs to be implemented:
>>
>> arch_add_memory()
>> This callback is responsible for adding the physical memory into the
>> direct map, and call into the memory hotplugging generic code via
>> __add_pages() that adds the corresponding struct page entries, and
>> updates the vmemmap mapping.
>>
>> arch_remove_memory()
>> This is the inverse of the callback above.
>>
>> vmemmap_free()
>> This function tears down the vmemmap mappings (if
>> CONFIG_SPARSEMEM_VMEMMAP is enabled), and also deallocates the
>> backing vmemmap pages. Note that for persistent memory, an
>> alternative allocator for the backing pages can be used; The
>> vmem_altmap. This means that when the backing pages are cleared,
>> extra care is needed so that the correct deallocation method is
>> used.
>>
>> arch_get_mappable_range()
>> This functions returns the PA range that the direct map can map.
>> Used by the MHP internals for sanity checks.
>>
>> The page table unmap/teardown functions are heavily based on code from
>> the x86 tree. The same remove_pgd_mapping() function is used in both
>> vmemmap_free() and arch_remove_memory(), but in the latter function
>> the backing pages are not removed.
>>
>> Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
>> ---
>> arch/riscv/mm/init.c | 242 +++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 242 insertions(+)
>>
>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> index 6f72b0b2b854..7f0b921a3d3a 100644
>> --- a/arch/riscv/mm/init.c
>> +++ b/arch/riscv/mm/init.c
>> @@ -1493,3 +1493,245 @@ void __init pgtable_cache_init(void)
>> }
>> }
>> #endif
>> +
>> +#ifdef CONFIG_MEMORY_HOTPLUG
>> +static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)
>> +{
>> + pte_t *pte;
>> + int i;
>> +
>> + for (i = 0; i < PTRS_PER_PTE; i++) {
>> + pte = pte_start + i;
>> + if (!pte_none(*pte))
>> + return;
>> + }
>> +
>> + free_pages((unsigned long)page_address(pmd_page(*pmd)), 0);
>> + pmd_clear(pmd);
>> +}
>> +
>> +static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud)
>> +{
>> + pmd_t *pmd;
>> + int i;
>> +
>> + for (i = 0; i < PTRS_PER_PMD; i++) {
>> + pmd = pmd_start + i;
>> + if (!pmd_none(*pmd))
>> + return;
>> + }
>> +
>> + free_pages((unsigned long)page_address(pud_page(*pud)), 0);
>> + pud_clear(pud);
>> +}
>> +
>> +static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d)
>> +{
>> + pud_t *pud;
>> + int i;
>> +
>> + for (i = 0; i < PTRS_PER_PUD; i++) {
>> + pud = pud_start + i;
>> + if (!pud_none(*pud))
>> + return;
>> + }
>> +
>> + free_pages((unsigned long)page_address(p4d_page(*p4d)), 0);
>> + p4d_clear(p4d);
>> +}
>> +
>> +static void __meminit free_vmemmap_storage(struct page *page, size_t size,
>> + struct vmem_altmap *altmap)
>> +{
>> + if (altmap)
>> + vmem_altmap_free(altmap, size >> PAGE_SHIFT);
>> + else
>> + free_pages((unsigned long)page_address(page), get_order(size));
>
> If you unplug a DIMM that was added during boot (can happen on x86-64,
> can it happen on riscv?), free_pages() would not be sufficient. You'd be
> freeing a PG_reserved page that has to be freed differently.
I'd say if it can happen on x86-64, it probably can on RISC-V. I'll look
into this for the next spin!
Thanks for spending time on the series!
Cheers,
Björn
next prev parent reply other threads:[~2024-05-14 16:34 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 14:04 [PATCH v2 0/8] riscv: Memory Hot(Un)Plug support Björn Töpel
2024-05-14 14:04 ` [PATCH v2 1/8] riscv: mm: Pre-allocate vmemmap/direct map PGD entries Björn Töpel
2024-05-14 15:57 ` Alexandre Ghiti
2024-05-14 16:33 ` Björn Töpel
2024-05-14 14:04 ` [PATCH v2 2/8] riscv: mm: Change attribute from __init to __meminit for page functions Björn Töpel
2024-05-14 15:59 ` David Hildenbrand
2024-05-14 17:17 ` Alexandre Ghiti
2024-05-14 17:45 ` Björn Töpel
2024-05-14 20:32 ` Oscar Salvador
2024-05-15 5:39 ` Björn Töpel
2024-05-14 14:04 ` [PATCH v2 3/8] riscv: mm: Refactor create_linear_mapping_range() for memory hot add Björn Töpel
2024-05-14 16:00 ` David Hildenbrand
2024-05-14 17:24 ` Alexandre Ghiti
2024-05-14 20:37 ` Oscar Salvador
2024-05-14 14:04 ` [PATCH v2 4/8] riscv: mm: Add memory hotplugging support Björn Töpel
2024-05-14 16:04 ` David Hildenbrand
2024-05-14 16:34 ` Björn Töpel [this message]
2024-05-14 17:49 ` Alexandre Ghiti
2024-05-14 19:31 ` Björn Töpel
2024-05-14 20:49 ` Oscar Salvador
2024-05-15 5:41 ` Björn Töpel
2024-05-14 14:04 ` [PATCH v2 5/8] riscv: mm: Take memory hotplug read-lock during kernel page table dump Björn Töpel
2024-05-14 20:39 ` David Hildenbrand
2024-05-14 21:03 ` Oscar Salvador
2024-05-14 14:04 ` [PATCH v2 6/8] riscv: Enable memory hotplugging for RISC-V Björn Töpel
2024-05-14 18:00 ` Alexandre Ghiti
2024-05-14 18:17 ` Björn Töpel
2024-05-14 18:41 ` Alexandre Ghiti
2024-05-14 20:40 ` David Hildenbrand
2024-05-14 21:06 ` Oscar Salvador
2024-05-14 14:04 ` [PATCH v2 7/8] virtio-mem: Enable virtio-mem " Björn Töpel
2024-05-14 15:58 ` David Hildenbrand
2024-05-14 14:04 ` [PATCH v2 8/8] riscv: mm: Add support for ZONE_DEVICE Björn Töpel
2024-05-15 7:03 ` Björn Töpel
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=87r0e4tkrd.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=Chethan.Seshadri@catalinasystems.io \
--cc=abrestic@rivosinc.com \
--cc=alexghiti@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=lstoakes@gmail.com \
--cc=osalvador@suse.de \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=santosh.mamila@catalinasystems.io \
--cc=siva.munnangi@catalinasystems.io \
--cc=sunilvl@ventanamicro.com \
--cc=virtualization@lists.linux-foundation.org \
/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