linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Anshuman Khandual <anshuman.khandual@arm.com>
To: Robin Murphy <robin.murphy@arm.com>, linux-mm@kvack.org
Cc: Mark Rutland <mark.rutland@arm.com>, Yu Zhao <yuzhao@google.com>,
	David Hildenbrand <david@redhat.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Steve Capper <steve.capper@arm.com>,
	linux-kernel@vger.kernel.org, Hsin-Yi Wang <hsinyi@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Will Deacon <will@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH V2 2/2] arm64/mm: Enable vmem_altmap support for vmemmap mappings
Date: Tue, 24 Mar 2020 17:33:26 +0530	[thread overview]
Message-ID: <57af8e0a-5e47-cf3f-19dc-ce047793cd1f@arm.com> (raw)
In-Reply-To: <d428e636-0f48-6738-2296-91dba8fc6404@arm.com>


On 03/21/2020 01:05 AM, Robin Murphy wrote:
> On 2020-03-04 2:10 pm, Anshuman Khandual wrote:
>> Device memory ranges when getting hot added into ZONE_DEVICE, might require
>> their vmemmap mapping's backing memory to be allocated from their own range
>> instead of consuming system memory. This prevents large system memory usage
>> for potentially large device memory ranges. Device driver communicates this
>> request via vmem_altmap structure. Architecture needs to take this request
>> into account while creating and tearing down vemmmap mappings.
>>
>> This enables vmem_altmap support in vmemmap_populate() and vmemmap_free()
>> which includes vmemmap_populate_basepages() used for ARM64_16K_PAGES and
>> ARM64_64K_PAGES configs.
>>
>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: Steve Capper <steve.capper@arm.com>
>> Cc: David Hildenbrand <david@redhat.com>
>> Cc: Yu Zhao <yuzhao@google.com>
>> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-kernel@vger.kernel.org
>>
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>   arch/arm64/mm/mmu.c | 71 ++++++++++++++++++++++++++++++++-------------
>>   1 file changed, 51 insertions(+), 20 deletions(-)
>>
>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>> index 27cb95c471eb..0e0a0ecc812e 100644
>> --- a/arch/arm64/mm/mmu.c
>> +++ b/arch/arm64/mm/mmu.c
>> @@ -727,15 +727,30 @@ int kern_addr_valid(unsigned long addr)
>>   }
>>     #ifdef CONFIG_MEMORY_HOTPLUG
>> -static void free_hotplug_page_range(struct page *page, size_t size)
>> +static void free_hotplug_page_range(struct page *page, size_t size,
>> +                    struct vmem_altmap *altmap)
>>   {
>> -    WARN_ON(PageReserved(page));
>> -    free_pages((unsigned long)page_address(page), get_order(size));
>> +    if (altmap) {
>> +        /*
>> +         * Though unmap_hotplug_range() will tear down altmap based
>> +         * vmemmap mappings at all page table levels, these mappings
>> +         * should only have been created either at PTE or PMD level
>> +         * with vmemmap_populate_basepages() or vmemmap_populate()
>> +         * respectively. Unmapping requests at any other level will
>> +         * be problematic. Drop these warnings when vmemmap mapping
>> +         * is supported at PUD (even perhaps P4D) level.
>> +         */
>> +        WARN_ON((size != PAGE_SIZE) && (size != PMD_SIZE));
> 
> Isn't that comment equally true of the regular case? AFAICS we don't call vmemmap_alloc_block_buf() with larger than PMD_SIZE either. If the warnings are useful, shouldn't they cover both cases equally? However, given that we never warned before, and the code here appears that it would work fine anyway, *are* they really useful?

Sure, this is not something exclusively applicable for altmap based
vmemmap mappings alone. Will drop it from here.

> 
>> +        vmem_altmap_free(altmap, size >> PAGE_SHIFT);
>> +    } else {
>> +        WARN_ON(PageReserved(page));
>> +        free_pages((unsigned long)page_address(page), get_order(size));
>> +    }
>>   }
>>     static void free_hotplug_pgtable_page(struct page *page)
>>   {
>> -    free_hotplug_page_range(page, PAGE_SIZE);
>> +    free_hotplug_page_range(page, PAGE_SIZE, NULL);
>>   }
>>     static bool pgtable_range_aligned(unsigned long start, unsigned long end,
>> @@ -758,7 +773,8 @@ static bool pgtable_range_aligned(unsigned long start, unsigned long end,
>>   }
>>     static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
>> -                    unsigned long end, bool free_mapped)
>> +                    unsigned long end, bool free_mapped,
>> +                    struct vmem_altmap *altmap)
>>   {
>>       pte_t *ptep, pte;
>>   @@ -772,12 +788,14 @@ static void unmap_hotplug_pte_range(pmd_t *pmdp, unsigned long addr,
>>           pte_clear(&init_mm, addr, ptep);
>>           flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
>>           if (free_mapped)
>> -            free_hotplug_page_range(pte_page(pte), PAGE_SIZE);
>> +            free_hotplug_page_range(pte_page(pte),
>> +                        PAGE_SIZE, altmap);
>>       } while (addr += PAGE_SIZE, addr < end);
>>   }
>>     static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
>> -                    unsigned long end, bool free_mapped)
>> +                    unsigned long end, bool free_mapped,
>> +                    struct vmem_altmap *altmap)
>>   {
>>       unsigned long next;
>>       pmd_t *pmdp, pmd;
>> @@ -800,16 +818,17 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
>>               flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
>>               if (free_mapped)
>>                   free_hotplug_page_range(pmd_page(pmd),
>> -                            PMD_SIZE);
>> +                            PMD_SIZE, altmap);
>>               continue;
>>           }
>>           WARN_ON(!pmd_table(pmd));
>> -        unmap_hotplug_pte_range(pmdp, addr, next, free_mapped);
>> +        unmap_hotplug_pte_range(pmdp, addr, next, free_mapped, altmap);
>>       } while (addr = next, addr < end);
>>   }
>>     static void unmap_hotplug_pud_range(p4d_t *p4dp, unsigned long addr,
>> -                    unsigned long end, bool free_mapped)
>> +                    unsigned long end, bool free_mapped,
>> +                    struct vmem_altmap *altmap)
>>   {
>>       unsigned long next;
>>       pud_t *pudp, pud;
>> @@ -832,16 +851,17 @@ static void unmap_hotplug_pud_range(p4d_t *p4dp, unsigned long addr,
>>               flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
>>               if (free_mapped)
>>                   free_hotplug_page_range(pud_page(pud),
>> -                            PUD_SIZE);
>> +                            PUD_SIZE, altmap);
>>               continue;
>>           }
>>           WARN_ON(!pud_table(pud));
>> -        unmap_hotplug_pmd_range(pudp, addr, next, free_mapped);
>> +        unmap_hotplug_pmd_range(pudp, addr, next, free_mapped, altmap);
>>       } while (addr = next, addr < end);
>>   }
>>     static void unmap_hotplug_p4d_range(pgd_t *pgdp, unsigned long addr,
>> -                    unsigned long end, bool free_mapped)
>> +                    unsigned long end, bool free_mapped,
>> +                    struct vmem_altmap *altmap)
>>   {
>>       unsigned long next;
>>       p4d_t *p4dp, p4d;
>> @@ -854,16 +874,24 @@ static void unmap_hotplug_p4d_range(pgd_t *pgdp, unsigned long addr,
>>               continue;
>>             WARN_ON(!p4d_present(p4d));
>> -        unmap_hotplug_pud_range(p4dp, addr, next, free_mapped);
>> +        unmap_hotplug_pud_range(p4dp, addr, next, free_mapped, altmap);
>>       } while (addr = next, addr < end);
>>   }
>>     static void unmap_hotplug_range(unsigned long addr, unsigned long end,
>> -                bool free_mapped)
>> +                bool free_mapped, struct vmem_altmap *altmap)
>>   {
>>       unsigned long next;
>>       pgd_t *pgdp, pgd;
>>   +    /*
>> +     * vmem_altmap can only be used as backing memory in a given
>> +     * page table mapping. In case backing memory itself is not
>> +     * being freed, then altmap is irrelevant. Warn about this
>> +     * inconsistency when encountered.
>> +     */
>> +    WARN_ON(!free_mapped && altmap);
> 
> Personally I find that comment a bit unclear (particularly the first sentence which just seems like a confusing tautology). Is the overall point that the altmap only matters when we're unmapping and freeing vmemmap pages (such that we free them to the right allocator)? At face value it doesn't seem to warrant a warning - it's not necessary to know which allocator owns pages that we aren't freeing, but it isn't harmful either.

Probably will change the comment to something like this instead.

        /*
         * altmap can only be used as vmemmap mapping backing memory.
         * In case the backing memory itself is not being freed, then
         * altmap is just irrelevant. Warn about this inconsistency
	 * when encountered.
         */

altmap does decide which allocator, the backing pages will get freed
into. The primary purpose here is to just warn about this invalid
combination i.e (!free_mapped && altmap) which the function should
never be called with.

> 
> That said, however, after puzzling through the code I get the distinct feeling it would be more useful if all those "free_mapped" arguments were actually named "is_vmemmap" instead. A that point, the conceptual inconsistency would be a little more obvious (and arguably might not even need commenting).

'free_mapped' was a conscious decision [1] that got added during hot
remove series V9. It avoided the name to be just vmemmap specific as
the unmapping and freeing functions are very generic in nature.

[1] https://lkml.org/lkml/2019/10/8/310

> 
> All the altmap plumbing itself looks pretty mechanical and hard to disagree with :)

Okay.

> 
> Robin.


      reply	other threads:[~2020-03-24 12:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 14:10 [PATCH V2 0/2] arm64: Enable vmemmap mapping from device memory Anshuman Khandual
2020-03-04 14:10 ` [PATCH V2 1/2] mm/sparsemem: Enable vmem_altmap support in vmemmap_populate_basepages() Anshuman Khandual
2020-03-20 17:08   ` Robin Murphy
2020-03-24 12:01     ` Anshuman Khandual
2020-03-04 14:10 ` [PATCH V2 2/2] arm64/mm: Enable vmem_altmap support for vmemmap mappings Anshuman Khandual
2020-03-20 19:35   ` Robin Murphy
2020-03-24 12:03     ` Anshuman Khandual [this message]

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=57af8e0a-5e47-cf3f-19dc-ce047793cd1f@arm.com \
    --to=anshuman.khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=david@redhat.com \
    --cc=hsinyi@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=robin.murphy@arm.com \
    --cc=steve.capper@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --cc=yuzhao@google.com \
    /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 NNTP newsgroup(s).