linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yu Zhao <yuzhao@google.com>
To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Rientjes <rientjes@google.com>,
	 Douglas Anderson <dianders@chromium.org>,
	Frank van der Linden <fvdl@google.com>,
	 Mark Rutland <mark.rutland@arm.com>,
	Muchun Song <muchun.song@linux.dev>,
	 Nanyong Sun <sunnanyong@huawei.com>,
	Yang Shi <yang@os.amperecomputing.com>,
	 linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 3/4] arm64: pause remote CPUs to update vmemmap
Date: Mon, 5 Aug 2024 23:08:01 -0600	[thread overview]
Message-ID: <CAOUHufY-CRHoALNEenHvh6HHS=B7nX5_YyB-XZobi5zxY5nB+Q@mail.gmail.com> (raw)
In-Reply-To: <20240806022114.3320543-4-yuzhao@google.com>

On Mon, Aug 5, 2024 at 8:21 PM Yu Zhao <yuzhao@google.com> wrote:
>
> Pause remote CPUs so that the local CPU can follow the proper BBM
> sequence to safely update the vmemmap mapping `struct page` areas.
>
> While updating the vmemmap, it is guaranteed that neither the local
> CPU nor the remote ones will access the `struct page` area being
> updated, and therefore they will not trigger kernel PFs.
>
> Signed-off-by: Yu Zhao <yuzhao@google.com>
> ---
>  arch/arm64/include/asm/pgalloc.h | 55 ++++++++++++++++++++++++++++++++
>  mm/hugetlb_vmemmap.c             | 14 ++++++++
>  2 files changed, 69 insertions(+)
>
> diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
> index 8ff5f2a2579e..1af1aa34a351 100644
> --- a/arch/arm64/include/asm/pgalloc.h
> +++ b/arch/arm64/include/asm/pgalloc.h
> @@ -12,6 +12,7 @@
>  #include <asm/processor.h>
>  #include <asm/cacheflush.h>
>  #include <asm/tlbflush.h>
> +#include <asm/cpu.h>
>
>  #define __HAVE_ARCH_PGD_FREE
>  #define __HAVE_ARCH_PUD_FREE
> @@ -137,4 +138,58 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
>         __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN);
>  }
>
> +#ifdef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
> +
> +#define vmemmap_update_lock vmemmap_update_lock
> +static inline void vmemmap_update_lock(void)
> +{
> +       cpus_read_lock();
> +}
> +
> +#define vmemmap_update_unlock vmemmap_update_unlock
> +static inline void vmemmap_update_unlock(void)
> +{
> +       cpus_read_unlock();
> +}
> +
> +#define vmemmap_update_pte vmemmap_update_pte
> +static inline void vmemmap_update_pte(unsigned long addr, pte_t *ptep, pte_t pte)
> +{
> +       preempt_disable();
> +       pause_remote_cpus();
> +
> +       pte_clear(&init_mm, addr, ptep);
> +       flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
> +       set_pte_at(&init_mm, addr, ptep, pte);
> +
> +       resume_remote_cpus();
> +       preempt_enable();
> +}

Note that I kept this API from Nanyong for the sake of discussion.
What I actually plan to test in our production is:

#define vmemmap_update_pte_range_start vmemmap_update_pte_range_start
static inline void vmemmap_update_pte_range_start(pte_t *pte,
                                                  unsigned long start,
unsigned long end)
{
        preempt_disable();
        pause_remote_cpus();

        for (; start != end; start += PAGE_SIZE, pte++)
                pte_clear(&init_mm, start, pte);

        flush_tlb_kernel_range(start, end);
}

#define vmemmap_update_pte_range_end vmemmap_update_pte_range_end
static inline void vmemmap_update_pte_range_end(void)
{
        resume_remote_cpus();
        preempt_enable();
}

> +#define vmemmap_update_pmd vmemmap_update_pmd
> +static inline void vmemmap_update_pmd(unsigned long addr, pmd_t *pmdp, pte_t *ptep)
> +{
> +       preempt_disable();
> +       pause_remote_cpus();
> +
> +       pmd_clear(pmdp);
> +       flush_tlb_kernel_range(addr, addr + PMD_SIZE);
> +       pmd_populate_kernel(&init_mm, pmdp, ptep);
> +
> +       resume_remote_cpus();
> +       preempt_enable();
> +}
> +
> +#define vmemmap_flush_tlb_all vmemmap_flush_tlb_all
> +static inline void vmemmap_flush_tlb_all(void)
> +{
> +}
> +
> +#define vmemmap_flush_tlb_range vmemmap_flush_tlb_range
> +static inline void vmemmap_flush_tlb_range(unsigned long start, unsigned long end)
> +{
> +}
> +
> +#endif /* CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP */
> +
>  #endif
> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
> index 2dd92e58f304..893c73493d9c 100644
> --- a/mm/hugetlb_vmemmap.c
> +++ b/mm/hugetlb_vmemmap.c
> @@ -46,6 +46,18 @@ struct vmemmap_remap_walk {
>         unsigned long           flags;
>  };
>
> +#ifndef vmemmap_update_lock
> +static void vmemmap_update_lock(void)
> +{
> +}
> +#endif
> +
> +#ifndef vmemmap_update_unlock
> +static void vmemmap_update_unlock(void)
> +{
> +}
> +#endif
> +
>  #ifndef vmemmap_update_pmd
>  static inline void vmemmap_update_pmd(unsigned long addr,
>                                       pmd_t *pmdp, pte_t *ptep)
> @@ -194,10 +206,12 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end,
>
>         VM_BUG_ON(!PAGE_ALIGNED(start | end));
>
> +       vmemmap_update_lock();
>         mmap_read_lock(&init_mm);
>         ret = walk_page_range_novma(&init_mm, start, end, &vmemmap_remap_ops,
>                                     NULL, walk);
>         mmap_read_unlock(&init_mm);
> +       vmemmap_update_unlock();
>         if (ret)
>                 return ret;
>
> --
> 2.46.0.rc2.264.g509ed76dc8-goog
>


  reply	other threads:[~2024-08-06  5:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06  2:21 [RFC PATCH 0/4] mm/arm64: re-enable HVO Yu Zhao
2024-08-06  2:21 ` [RFC PATCH 1/4] mm: HVO: introduce helper function to update and flush pgtable Yu Zhao
2024-08-06  2:21 ` [RFC PATCH 2/4] arm64: use IPIs to pause/resume remote CPUs Yu Zhao
2024-08-06  9:12   ` David Hildenbrand
2024-08-08 16:09   ` Doug Anderson
2024-08-06  2:21 ` [RFC PATCH 3/4] arm64: pause remote CPUs to update vmemmap Yu Zhao
2024-08-06  5:08   ` Yu Zhao [this message]
2024-08-06  2:21 ` [RFC PATCH 4/4] arm64: mm: Re-enable OPTIMIZE_HUGETLB_VMEMMAP Yu Zhao

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='CAOUHufY-CRHoALNEenHvh6HHS=B7nX5_YyB-XZobi5zxY5nB+Q@mail.gmail.com' \
    --to=yuzhao@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=dianders@chromium.org \
    --cc=fvdl@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=muchun.song@linux.dev \
    --cc=rientjes@google.com \
    --cc=sunnanyong@huawei.com \
    --cc=will@kernel.org \
    --cc=yang@os.amperecomputing.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).