All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Hongyan Xia <hx242@xen.org>
Cc: xen-devel@lists.xenproject.org,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	julien@xen.org, "Wei Liu" <wl@xen.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>
Subject: Re: [PATCH v6 08/15] x86_64/mm: switch to new APIs in setup_m2p_table
Date: Wed, 20 May 2020 11:54:21 +0200	[thread overview]
Message-ID: <ac76fddd-06f8-9e60-24b7-bd942265b3c6@suse.com> (raw)
In-Reply-To: <a5e7c92fdc538c23f0173bec8e3b026dcf665c11.1587735799.git.hongyxia@amazon.com>

On 24.04.2020 16:08, Hongyan Xia wrote:
> --- a/xen/arch/x86/x86_64/mm.c
> +++ b/xen/arch/x86/x86_64/mm.c
> @@ -379,13 +379,13 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
>  {
>      unsigned long i, va, smap, emap;
>      unsigned int n;
> -    l2_pgentry_t *l2_ro_mpt = NULL;
>      l3_pgentry_t *l3_ro_mpt = NULL;
>      int ret = 0;
>  
>      ASSERT(l4e_get_flags(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)])
>              & _PAGE_PRESENT);
> -    l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]);
> +    l3_ro_mpt = map_l3t_from_l4e(
> +                    idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]);
>  
>      smap = (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 3)) -1)));
>      emap = ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) &
> @@ -424,6 +424,7 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
>                  break;
>          if ( n < CNT )
>          {
> +            l2_pgentry_t *l2_ro_mpt;
>              mfn_t mfn = alloc_hotadd_mfn(info);
>  
>              ret = map_pages_to_xen(
> @@ -440,30 +441,30 @@ static int setup_m2p_table(struct mem_hotadd_info *info)
>                    _PAGE_PSE));
>              if ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) &
>                _PAGE_PRESENT )
> -                l2_ro_mpt = l3e_to_l2e(l3_ro_mpt[l3_table_offset(va)]) +
> -                  l2_table_offset(va);
> +                l2_ro_mpt = map_l2t_from_l3e(l3_ro_mpt[l3_table_offset(va)]);
>              else
>              {
> -                l2_ro_mpt = alloc_xen_pagetable();
> -                if ( !l2_ro_mpt )
> +                mfn_t l2_ro_mpt_mfn = alloc_xen_pagetable_new();
> +
> +                if ( mfn_eq(l2_ro_mpt_mfn, INVALID_MFN) )
>                  {
>                      ret = -ENOMEM;
>                      goto error;
>                  }
>  
> +                l2_ro_mpt = map_domain_page(l2_ro_mpt_mfn);
>                  clear_page(l2_ro_mpt);
>                  l3e_write(&l3_ro_mpt[l3_table_offset(va)],
> -                          l3e_from_paddr(__pa(l2_ro_mpt),
> -                                         __PAGE_HYPERVISOR_RO | _PAGE_USER));
> -                l2_ro_mpt += l2_table_offset(va);
> +                          l3e_from_mfn(l2_ro_mpt_mfn,
> +                                       __PAGE_HYPERVISOR_RO | _PAGE_USER));
>              }
> +            l2_ro_mpt += l2_table_offset(va);
>  
>              /* NB. Cannot be GLOBAL: guest user mode should not see it. */
>              l2e_write(l2_ro_mpt, l2e_from_mfn(mfn,
>                     /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT));
> +            unmap_domain_page(l2_ro_mpt);
>          }
> -        if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )
> -            l2_ro_mpt = NULL;

I think you want to consider retaining these two lines and the wider
scope of l2_ro_mpt, to leverage it to avoid mapping and unmapping
the same L2 page over and over on each loop iteration.

Jan


  reply	other threads:[~2020-05-20  9:54 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24 14:08 [PATCH v6 00/15] switch to domheap for Xen page tables Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 01/15] x86/mm: map_pages_to_xen would better have one exit path Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 02/15] x86/mm: make sure there is one exit path for modify_xen_mappings Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 03/15] x86/mm: rewrite virt_to_xen_l*e Hongyan Xia
2020-05-20  9:27   ` Jan Beulich
2020-04-24 14:08 ` [PATCH v6 04/15] x86/mm: switch to new APIs in map_pages_to_xen Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 05/15] x86/mm: switch to new APIs in modify_xen_mappings Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 06/15] x86_64/mm: introduce pl2e in paging_init Hongyan Xia
2020-05-20  9:35   ` Jan Beulich
2020-04-24 14:08 ` [PATCH v6 07/15] x86_64/mm: switch to new APIs " Hongyan Xia
2020-05-20  9:46   ` Jan Beulich
2020-05-27 15:01     ` Hongyan Xia
2020-04-24 14:08 ` [PATCH v6 08/15] x86_64/mm: switch to new APIs in setup_m2p_table Hongyan Xia
2020-05-20  9:54   ` Jan Beulich [this message]
2020-04-24 14:09 ` [PATCH v6 09/15] efi: use new page table APIs in copy_mapping Hongyan Xia
2020-04-30 12:42   ` Jan Beulich
2020-04-24 14:09 ` [PATCH v6 10/15] efi: switch to new APIs in EFI code Hongyan Xia
2020-04-30 12:55   ` Jan Beulich
2020-04-24 14:09 ` [PATCH v6 11/15] x86/smpboot: clone_mapping should have one exit path Hongyan Xia
2020-04-30 14:59   ` Jan Beulich
2020-04-24 14:09 ` [PATCH v6 12/15] x86/smpboot: switch pl*e to use new APIs in clone_mapping Hongyan Xia
2020-04-30 15:15   ` Jan Beulich
2020-05-11 10:55     ` Hongyan Xia
2020-04-24 14:09 ` [PATCH v6 13/15] x86/mm: drop old page table APIs Hongyan Xia
2020-05-20 10:09   ` Jan Beulich
2020-05-27 15:19     ` Hongyan Xia
2020-04-24 14:09 ` [PATCH v6 14/15] x86: switch to use domheap page for page tables Hongyan Xia
2020-04-24 14:09 ` [PATCH v6 15/15] x86/mm: drop _new suffix for page table APIs Hongyan Xia
2020-05-20  9:56   ` Jan Beulich

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=ac76fddd-06f8-9e60-24b7-bd942265b3c6@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=hx242@xen.org \
    --cc=julien@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=wl@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.