All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Julien Grall <julien@xen.org>
Cc: xen-devel@lists.xenproject.org, Julien Grall <jgrall@amazon.com>,
	 Stefano Stabellini <sstabellini@kernel.org>,
	 Bertrand Marquis <bertrand.marquis@arm.com>,
	 Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v3 05/19] xen/arm: mm: Add support for the contiguous bit
Date: Fri, 1 Apr 2022 16:53:02 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2204011639430.2910984@ubuntu-linux-20-04-desktop> (raw)
In-Reply-To: <20220221102218.33785-6-julien@xen.org>

On Mon, 21 Feb 2022, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
> 
> In follow-up patches, we will use xen_pt_update() (or its callers)
> to handle large mappings (e.g. frametable, xenheap). They are also
> not going to be modified once created.
> 
> The page-table entries have an hint to indicate that whether an
> entry is contiguous to another 16 entries (assuming 4KB). When the
> processor support the hint, one TLB entry will be created per
> contiguous region.
> 
> For now this is tied to _PAGE_BLOCK. We can untie it in the future
> if there are use-cases where we may want to use _PAGE_BLOCK without
> setting the contiguous (couldn't think of any yet).
> 
> Note that to avoid extra complexity, mappings with the contiguous
> bit set cannot be removed. Given the expected use, this restriction
> ought to be fine.
> 
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> 
> ---
>     Changes in v3:
>         - New patch
> ---
>  xen/arch/arm/include/asm/page.h |  4 ++
>  xen/arch/arm/mm.c               | 80 ++++++++++++++++++++++++++++++---
>  2 files changed, 77 insertions(+), 7 deletions(-)
> 
> diff --git a/xen/arch/arm/include/asm/page.h b/xen/arch/arm/include/asm/page.h
> index 07998df47bac..e7cd62190c7f 100644
> --- a/xen/arch/arm/include/asm/page.h
> +++ b/xen/arch/arm/include/asm/page.h
> @@ -70,6 +70,7 @@
>   * [5]   Page present
>   * [6]   Only populate page tables
>   * [7]   Superpage mappings is allowed
> + * [8]   Set contiguous bit (internal flag)
>   */
>  #define PAGE_AI_MASK(x) ((x) & 0x7U)
>  
> @@ -86,6 +87,9 @@
>  #define _PAGE_BLOCK_BIT     7
>  #define _PAGE_BLOCK         (1U << _PAGE_BLOCK_BIT)
>  
> +#define _PAGE_CONTIG_BIT    8
> +#define _PAGE_CONTIG        (1U << _PAGE_CONTIG_BIT)
> +
>  /*
>   * _PAGE_DEVICE and _PAGE_NORMAL are convenience defines. They are not
>   * meant to be used outside of this header.
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 3af69b396bd1..fd16c1541ce2 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -1237,6 +1237,8 @@ static int xen_pt_update_entry(mfn_t root, unsigned long virt,
>          /* Set permission */
>          pte.pt.ro = PAGE_RO_MASK(flags);
>          pte.pt.xn = PAGE_XN_MASK(flags);
> +        /* Set contiguous bit */
> +        pte.pt.contig = !!(flags & _PAGE_CONTIG);
>      }
>  
>      write_pte(entry, pte);
> @@ -1289,6 +1291,51 @@ static int xen_pt_mapping_level(unsigned long vfn, mfn_t mfn, unsigned long nr,
>       return level;
>  }
>  
> +#define XEN_PT_4K_NR_CONTIG 16
> +
> +/*
> + * Check whether the contiguous bit can be set. Return the number of
> + * contiguous entry allowed. If not allowed, return 1.
> + */
> +static unsigned int xen_pt_check_contig(unsigned long vfn, mfn_t mfn,
> +                                        unsigned int level, unsigned long left,
> +                                        unsigned int flags)
> +{
> +    unsigned long nr_contig;
> +
> +    /*
> +     * Allow the contiguous bit to set when the caller requests block
> +     * mapping.
> +     */
> +    if ( !(flags & _PAGE_BLOCK) )
> +        return 1;
> +
> +    /*
> +     * We don't allow to remove mapping with the contiguous bit set.
> +     * So shortcut the logic and directly return 1.
> +     */
> +    if ( mfn_eq(mfn, INVALID_MFN) )
> +        return 1;
> +
> +    /*
> +     * The number of contiguous entries varies depending on the page
> +     * granularity used. The logic below assumes 4KB.
> +     */
> +    BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
> +
> +    /*
> +     * In order to enable the contiguous bit, we should have enough entries
> +     * to map left and both the virtual and physical address should be
> +     * aligned to the size of 16 translation tables entries.
> +     */
> +    nr_contig = BIT(XEN_PT_LEVEL_ORDER(level), UL) * XEN_PT_4K_NR_CONTIG;
> +
> +    if ( (left < nr_contig) || ((mfn_x(mfn) | vfn) & (nr_contig - 1)) )
> +        return 1;
> +
> +    return XEN_PT_4K_NR_CONTIG;
> +}
> +
>  static DEFINE_SPINLOCK(xen_pt_lock);
>  
>  static int xen_pt_update(unsigned long virt,
> @@ -1322,6 +1369,12 @@ static int xen_pt_update(unsigned long virt,
>          return -EINVAL;
>      }
>  
> +    if ( flags & _PAGE_CONTIG )
> +    {
> +        mm_printk("_PAGE_CONTIG is an internal only flag.\n");
> +        return -EINVAL;
> +    }
> +
>      if ( !IS_ALIGNED(virt, PAGE_SIZE) )
>      {
>          mm_printk("The virtual address is not aligned to the page-size.\n");
> @@ -1333,21 +1386,34 @@ static int xen_pt_update(unsigned long virt,
>      while ( left )
>      {
>          unsigned int order, level;
> +        unsigned int nr_contig;
> +        unsigned int new_flags;
>  
>          level = xen_pt_mapping_level(vfn, mfn, left, flags);
>          order = XEN_PT_LEVEL_ORDER(level);
>  
>          ASSERT(left >= BIT(order, UL));
>  
> -        rc = xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level, flags);
> -        if ( rc )
> -            break;
> +        /*
> +         * Check if we can set the contiguous mapping and update the
> +         * flags accordingly.
> +         */
> +        nr_contig = xen_pt_check_contig(vfn, mfn, level, left, flags);
> +        new_flags = flags | ((nr_contig > 1) ? _PAGE_CONTIG : 0);

Here is an optional idea to make the code simpler. We could move the
flags changes (adding/removing _PAGE_CONTIG) to xen_pt_check_contig.
That way, we could remove the inner loop.

xen_pt_check_contig could check if _PAGE_CONTIG is already set and based
on alignment, it should be able to figure out when it needs to be
disabled.

But also this code works as far as I can tell.


> -        vfn += 1U << order;
> -        if ( !mfn_eq(mfn, INVALID_MFN) )
> -            mfn = mfn_add(mfn, 1U << order);
> +        for ( ; nr_contig > 0; nr_contig-- )
> +        {
> +            rc = xen_pt_update_entry(root, pfn_to_paddr(vfn), mfn, level,
> +                                     new_flags);
> +            if ( rc )
> +                break;
>  
> -        left -= (1U << order);
> +            vfn += 1U << order;
> +            if ( !mfn_eq(mfn, INVALID_MFN) )
> +                mfn = mfn_add(mfn, 1U << order);
> +
> +            left -= (1U << order);
> +        }
>      }
>  
>      /*
> -- 
> 2.32.0
> 


  parent reply	other threads:[~2022-04-01 23:53 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 10:21 [PATCH v3 00/19] xen/arm: mm: Remove open-coding mappings Julien Grall
2022-02-21 10:22 ` [PATCH v3 01/19] xen/arm: lpae: Rename LPAE_ENTRIES_MASK_GS to LPAE_ENTRY_MASK_GS Julien Grall
2022-02-22 13:30   ` Michal Orzel
2022-02-24 22:19     ` Julien Grall
2022-02-22 15:21   ` Bertrand Marquis
2022-02-21 10:22 ` [PATCH v3 02/19] xen/arm: lpae: Use the generic helpers to defined the Xen PT helpers Julien Grall
2022-02-22 14:26   ` Michal Orzel
2022-02-22 15:38   ` Bertrand Marquis
2022-02-24 22:24     ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 03/19] xen/arm: p2m: Replace level_{orders, masks} arrays with XEN_PT_LEVEL_{ORDER, MASK} Julien Grall
2022-02-22 15:55   ` Bertrand Marquis
2022-02-24 22:41     ` Julien Grall
2022-02-25  8:27       ` Bertrand Marquis
2022-02-25 16:41         ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 04/19] xen/arm: mm: Allow other mapping size in xen_pt_update_entry() Julien Grall
2022-04-01 23:35   ` Stefano Stabellini
2022-04-02 15:59     ` Julien Grall
2022-04-05 20:46       ` Stefano Stabellini
2022-04-10 12:17         ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 05/19] xen/arm: mm: Add support for the contiguous bit Julien Grall
2022-02-26 19:30   ` Julien Grall
2022-03-21  5:46     ` Hongda Deng
2022-04-01 23:53   ` Stefano Stabellini [this message]
2022-04-02 16:18     ` Julien Grall
2022-04-05 20:47       ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 06/19] xen/arm: mm: Avoid flushing the TLBs when mapping are inserted Julien Grall
2022-04-02  0:00   ` Stefano Stabellini
2022-04-02 16:38     ` Julien Grall
2022-04-05 20:49       ` Stefano Stabellini
2022-04-10 12:30         ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 07/19] xen/arm: mm: Don't open-code Xen PT update in remove_early_mappings() Julien Grall
2022-04-02  0:04   ` Stefano Stabellini
2022-04-02 16:47     ` Julien Grall
2022-04-05 20:51       ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 08/19] xen/arm: mm: Re-implement early_fdt_map() using map_pages_to_xen() Julien Grall
2022-03-18  7:36   ` Hongda Deng
2022-03-18 19:44     ` Julien Grall
2022-04-02  0:10   ` Stefano Stabellini
2022-04-02 17:02     ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 09/19] xen/arm32: mm: Check if the virtual address is shared before updating it Julien Grall
2022-03-18 10:44   ` Hongda Deng
2022-03-18 22:15     ` Julien Grall
2022-03-19 15:59   ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 10/19] xen/arm32: mm: Re-implement setup_xenheap_mappings() using map_pages_to_xen() Julien Grall
2022-04-02  0:11   ` Stefano Stabellini
2022-05-14  9:42   ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 11/19] xen/arm: mm: Allocate xen page tables in domheap rather than xenheap Julien Grall
2022-02-21 10:22 ` [PATCH v3 12/19] xen/arm: mm: Allow page-table allocation from the boot allocator Julien Grall
2022-04-05 20:58   ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 13/19] xen/arm: Move fixmap definitions in a separate header Julien Grall
2022-02-22 15:10   ` Jan Beulich
2022-04-05 21:12   ` Stefano Stabellini
2022-04-05 21:47     ` Julien Grall
2022-04-06  0:10       ` Stefano Stabellini
2022-04-06  8:24         ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 14/19] xen/arm: add Persistent Map (PMAP) infrastructure Julien Grall
2022-02-22 15:22   ` Jan Beulich
2022-02-28  9:55     ` Julien Grall
2022-02-28 10:10       ` Jan Beulich
2022-02-28 10:20         ` Julien Grall
2022-02-28 10:30           ` Jan Beulich
2022-02-28 10:52             ` Julien Grall
2022-04-05 21:27   ` Stefano Stabellini
2022-05-14 10:17     ` Julien Grall
2022-02-21 10:22 ` [PATCH v3 15/19] xen/arm: mm: Clean-up the includes and order them Julien Grall
2022-04-05 21:29   ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 16/19] xen/arm: mm: Use the PMAP helpers in xen_{,un}map_table() Julien Grall
2022-04-05 21:36   ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 17/19] xen/arm64: mm: Add memory to the boot allocator first Julien Grall
2022-04-05 21:50   ` Stefano Stabellini
2022-04-05 22:12     ` Julien Grall
2022-04-06  0:02       ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 18/19] xen/arm: mm: Rework setup_xenheap_mappings() Julien Grall
2022-04-05 23:57   ` Stefano Stabellini
2022-02-21 10:22 ` [PATCH v3 19/19] xen/arm: mm: Re-implement setup_frame_table_mappings() with map_pages_to_xen() Julien Grall
2022-03-16  6:10   ` Hongda Deng
2022-04-06  0:01   ` Stefano Stabellini
2022-05-14 10:02     ` Julien Grall
2022-02-27 19:25 ` [PATCH v3 00/19] xen/arm: mm: Remove open-coding mappings Julien Grall

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=alpine.DEB.2.22.394.2204011639430.2910984@ubuntu-linux-20-04-desktop \
    --to=sstabellini@kernel.org \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=jgrall@amazon.com \
    --cc=julien@xen.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.