All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Julien Grall <julien.grall@arm.com>
Cc: Tim Deegan <tim@xen.org>,
	sstabellini@kernel.org, Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	andre.przywara@linaro.org, xen-devel@lists.xen.org,
	Jan Beulich <jbeulich@suse.com>
Subject: Re: [RFC 16/16] xen/arm: Track page accessed between batch of Set/Way operations
Date: Mon, 5 Nov 2018 13:35:25 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1811051314590.18518@sstabellini-ThinkPad-X260> (raw)
In-Reply-To: <20181008183352.16291-17-julien.grall@arm.com>

On Mon, 8 Oct 2018, Julien Grall wrote:
> At the moment, the implementation of Set/Way operations will go through
> all the entries of the guest P2M and flush them. However, this is very
> expensive and may render unusable a guest OS using them.
> 
> For instance, Linux 32-bit will use Set/Way operations during secondary
> CPU bring-up. As the implementation is really expensive, it may be possible
> to hit the CPU bring-up timeout.
> 
> To limit the Set/Way impact, we track what pages has been of the guest
> has been accessed between batch of Set/Way operations. This is done
> using bit[0] (aka valid bit) of the P2M entry.

This is going to improve performance of ill-mannered guests at the cost
of hurting performance of well-mannered guests. Is it really a good
trade-off? Should this behavior at least be configurable with a Xen
command line?


> This patch adds a new per-arch helper is introduced to perform actions just
> before the guest is first unpaused. This will be used to invalidate the
> P2M to track access from the start of the guest.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>
>
> ---
> 
> Cc: Stefano Stabellini <sstabellini@kernel.org>
> Cc: Julien Grall <julien.grall@arm.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: George Dunlap <George.Dunlap@eu.citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Tim Deegan <tim@xen.org>
> Cc: Wei Liu <wei.liu2@citrix.com>
> ---
>  xen/arch/arm/domain.c       | 14 ++++++++++++++
>  xen/arch/arm/domain_build.c |  7 +++++++
>  xen/arch/arm/p2m.c          | 32 +++++++++++++++++++++++++++++++-
>  xen/arch/x86/domain.c       |  4 ++++
>  xen/common/domain.c         |  5 ++++-
>  xen/include/asm-arm/p2m.h   |  2 ++
>  xen/include/xen/domain.h    |  2 ++
>  7 files changed, 64 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
> index feebbf5a92..f439f4657a 100644
> --- a/xen/arch/arm/domain.c
> +++ b/xen/arch/arm/domain.c
> @@ -738,6 +738,20 @@ int arch_domain_soft_reset(struct domain *d)
>      return -ENOSYS;
>  }
>  
> +void arch_domain_creation_finished(struct domain *d)
> +{
> +    /*
> +     * To avoid flushing the whole guest RAM on the first Set/Way, we
> +     * invalidate the P2M to track what has been accessed.
> +     *
> +     * This is only turned when IOMMU is not used or the page-table are
> +     * not shared because bit[0] (e.g valid bit) unset will result
> +     * IOMMU fault that could be not fixed-up.
> +     */
> +    if ( !iommu_use_hap_pt(d) )
> +        p2m_invalidate_root(p2m_get_hostp2m(d));
> +}
> +
>  static int is_guest_pv32_psr(uint32_t psr)
>  {
>      switch (psr & PSR_MODE_MASK)
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index f552154e93..de96516faa 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -2249,6 +2249,13 @@ int __init construct_dom0(struct domain *d)
>      v->is_initialised = 1;
>      clear_bit(_VPF_down, &v->pause_flags);
>  
> +    /*
> +     * XXX: We probably want a command line option to invalidate or not
> +     * the P2M. This is because invalidating the P2M will not work with
> +     * IOMMU, however if this is not done there will be an impact.

Why can't we check on iommu_use_hap_pt(d) like in
arch_domain_creation_finished?

In any case, I agree it is a good idea to introduce a command line
parameter to toggle the p2m_invalidate_root call at domain creation
on/off. There are cases where it should be off even if an IOMMU is
present.

Aside from these two questions, the rest of the patch looks correct.


> +     */
> +    p2m_invalidate_root(p2m_get_hostp2m(d));
>
>      return 0;
>  }
>  
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index a3d4c563b1..8e0c31d7ac 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -1079,6 +1079,22 @@ static void p2m_invalidate_table(struct p2m_domain *p2m, mfn_t mfn)
>      p2m->need_flush = true;
>  }
>  
> +/*
> + * Invalidate all entries in the root page-tables. This is
> + * useful to get fault on entry and do an action.
> + */
> +void p2m_invalidate_root(struct p2m_domain *p2m)
> +{
> +    unsigned int i;
> +
> +    p2m_write_lock(p2m);
> +
> +    for ( i = 0; i < P2M_ROOT_LEVEL; i++ )
> +        p2m_invalidate_table(p2m, page_to_mfn(p2m->root + i));
> +
> +    p2m_write_unlock(p2m);
> +}
> +
>  bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn)
>  {
>      struct p2m_domain *p2m = p2m_get_hostp2m(d);
> @@ -1539,7 +1555,8 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end)
>  
>      for ( ; gfn_x(start) < gfn_x(end); start = next_gfn )
>      {
> -        mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL);
> +        bool valid;
> +        mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, &valid);
>  
>          next_gfn = gfn_next_boundary(start, order);
>  
> @@ -1547,6 +1564,13 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end)
>          if ( mfn_eq(mfn, INVALID_MFN) || !p2m_is_any_ram(t) )
>              continue;
>  
> +        /*
> +         * Page with valid bit (bit [0]) unset does not need to be
> +         * cleaned
> +         */
> +        if ( !valid )
> +            continue;
> +
>          /* XXX: Implement preemption */
>          while ( gfn_x(start) < gfn_x(next_gfn) )
>          {
> @@ -1571,6 +1595,12 @@ static void p2m_flush_vm(struct vcpu *v)
>      /* XXX: Handle preemption */
>      p2m_cache_flush_range(v->domain, p2m->lowest_mapped_gfn,
>                            p2m->max_mapped_gfn);
> +
> +    /*
> +     * Invalidate the p2m to track which page was modified by the guest
> +     * between call of p2m_flush_vm().
> +     */
> +    p2m_invalidate_root(p2m);
>  }
>  
>  /*
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index 9371efc8c7..2b6d1c01a1 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -723,6 +723,10 @@ int arch_domain_soft_reset(struct domain *d)
>      return ret;
>  }
>  
> +void arch_domain_creation_finished(struct domain *d)
> +{
> +}
> +
>  /*
>   * These are the masks of CR4 bits (subject to hardware availability) which a
>   * PV guest may not legitimiately attempt to modify.
> diff --git a/xen/common/domain.c b/xen/common/domain.c
> index 65151e2ac4..b402c635f9 100644
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -1100,8 +1100,11 @@ int domain_unpause_by_systemcontroller(struct domain *d)
>       * Creation is considered finished when the controller reference count
>       * first drops to 0.
>       */
> -    if ( new == 0 )
> +    if ( new == 0 && !d->creation_finished )
> +    {
>          d->creation_finished = true;
> +        arch_domain_creation_finished(d);
> +    }
>  
>      domain_unpause(d);
>  
> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
> index c470f062db..2a4652e7f4 100644
> --- a/xen/include/asm-arm/p2m.h
> +++ b/xen/include/asm-arm/p2m.h
> @@ -225,6 +225,8 @@ int p2m_set_entry(struct p2m_domain *p2m,
>                    p2m_type_t t,
>                    p2m_access_t a);
>  
> +void p2m_invalidate_root(struct p2m_domain *p2m);
> +
>  /*
>   * Clean & invalidate caches corresponding to a region [start,end) of guest
>   * address space.
> diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
> index 5e393fd7f2..8d95ad4bf1 100644
> --- a/xen/include/xen/domain.h
> +++ b/xen/include/xen/domain.h
> @@ -70,6 +70,8 @@ void arch_domain_unpause(struct domain *d);
>  
>  int arch_domain_soft_reset(struct domain *d);
>  
> +void arch_domain_creation_finished(struct domain *d);
> +
>  void arch_p2m_set_access_required(struct domain *d, bool access_required);
>  
>  int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u);
> -- 
> 2.11.0
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-11-05 21:35 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-08 18:33 [RFC 00/16] xen/arm: Implement Set/Way operations Julien Grall
2018-10-08 18:33 ` [RFC 01/16] xen/arm: Introduce helpers to clear/flags flags in HCR_EL2 Julien Grall
2018-10-08 18:33 ` [RFC 02/16] xen/arm: Introduce helpers to get/set an MFN from/to an LPAE entry Julien Grall
2018-10-30  0:07   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 03/16] xen/arm: Allow lpae_is_{table, mapping} helpers to work on invalid entry Julien Grall
2018-10-30  0:10   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 04/16] xen/arm: guest_walk_tables: Switch the return to bool Julien Grall
2018-10-08 18:33 ` [RFC 05/16] xen/arm: traps: Move the implementation of GUEST_BUG_ON in traps.h Julien Grall
2018-10-30  0:11   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 06/16] xen/arm: p2m: Introduce a helper to generate P2M table entry from a page Julien Grall
2018-10-30  0:14   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 07/16] xen/arm: p2m: Introduce p2m_is_valid and use it Julien Grall
2018-10-30  0:21   ` Stefano Stabellini
2018-10-30 11:02     ` Julien Grall
2018-11-02 22:45       ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 08/16] xen/arm: p2m: Handle translation fault in get_page_from_gva Julien Grall
2018-10-30  0:47   ` Stefano Stabellini
2018-10-30 11:24     ` Julien Grall
2018-10-08 18:33 ` [RFC 09/16] xen/arm: p2m: Introduce a function to resolve translation fault Julien Grall
2018-11-02 23:27   ` Stefano Stabellini
2018-11-05 11:55     ` Julien Grall
2018-11-05 17:56       ` Stefano Stabellini
2018-11-06 14:20         ` Julien Grall
2018-11-12 17:59           ` Julien Grall
2018-11-12 23:36             ` Stefano Stabellini
2018-12-04 15:35               ` Julien Grall
2018-12-04 19:13                 ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 10/16] xen/arm: vcpreg: Add wrappers to handle co-proc access trapped by HCR_EL2.TVM Julien Grall
2018-11-05 19:47   ` Stefano Stabellini
2018-11-05 23:21     ` Julien Grall
2018-11-06 17:36       ` Stefano Stabellini
2018-11-06 17:52         ` Julien Grall
2018-11-06 17:56           ` Stefano Stabellini
2018-12-04 16:24       ` Julien Grall
2018-10-08 18:33 ` [RFC 11/16] xen/arm: vsysreg: Add wrapper to handle sysreg " Julien Grall
2018-11-05 20:42   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 12/16] xen/arm: Rework p2m_cache_flush to take a range [begin, end) Julien Grall
2018-11-02 23:38   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 13/16] xen/arm: p2m: Allow to flush cache on any RAM region Julien Grall
2018-11-02 23:40   ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 14/16] xen/arm: p2m: Extend p2m_get_entry to return the value of bit[0] (valid bit) Julien Grall
2018-11-02 23:44   ` Stefano Stabellini
2018-11-05 11:56     ` Julien Grall
2018-11-05 17:31       ` Stefano Stabellini
2018-11-05 17:32         ` Julien Grall
2018-10-08 18:33 ` [RFC 15/16] xen/arm: Implement Set/Way operations Julien Grall
2018-11-05 21:10   ` Stefano Stabellini
2018-11-05 23:38     ` Julien Grall
2018-11-06 17:31       ` Stefano Stabellini
2018-11-06 17:34         ` Julien Grall
2018-11-06 17:38           ` Stefano Stabellini
2018-10-08 18:33 ` [RFC 16/16] xen/arm: Track page accessed between batch of " Julien Grall
2018-10-09  7:04   ` Jan Beulich
2018-10-09 10:16     ` Julien Grall
2018-10-09 11:43       ` Jan Beulich
2018-10-09 12:24         ` Julien Grall
2018-11-05 21:35   ` Stefano Stabellini [this message]
2018-11-05 23:28     ` Julien Grall
2018-11-06 17:43       ` Stefano Stabellini
2018-11-06 18:10         ` Julien Grall
2018-11-06 18:41           ` Stefano Stabellini
2018-11-22 14:21 ` [RFC 00/16] xen/arm: Implement " 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.10.1811051314590.18518@sstabellini-ThinkPad-X260 \
    --to=sstabellini@kernel.org \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andre.przywara@linaro.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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.