All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Wei Liu <wl@xen.org>
Cc: Xen Development List <xen-devel@lists.xenproject.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <liuwe@microsoft.com>, Jan Beulich <jbeulich@suse.com>,
	Michael Kelley <mikelley@microsoft.com>
Subject: Re: [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework
Date: Mon, 21 Oct 2019 11:56:36 +0200	[thread overview]
Message-ID: <20191021095636.GF17494@Air-de-Roger> (raw)
In-Reply-To: <20190930150044.5734-8-liuwe@microsoft.com>

On Mon, Sep 30, 2019 at 04:00:41PM +0100, Wei Liu wrote:
> Take the chance to change probe_hypervisor to hypervisor_probe.

The implementation LGTM.

> 
> Signed-off-by: Wei Liu <liuwe@microsoft.com>
> ---
>  xen/arch/x86/guest/hypervisor.c   | 31 +++++++++++++++++++++++++++++--
>  xen/arch/x86/guest/xen/pvh-boot.c |  2 +-
>  xen/arch/x86/guest/xen/xen.c      | 26 ++++++++++++++------------
>  xen/arch/x86/setup.c              |  2 +-
>  xen/include/asm-x86/guest/xen.h   |  6 ++++--
>  5 files changed, 49 insertions(+), 18 deletions(-)
> 
> diff --git a/xen/arch/x86/guest/hypervisor.c b/xen/arch/x86/guest/hypervisor.c
> index 89b9ae4de0..30453b6a7a 100644
> --- a/xen/arch/x86/guest/hypervisor.c
> +++ b/xen/arch/x86/guest/hypervisor.c
> @@ -22,7 +22,7 @@
>  #include <xen/types.h>
>  
>  #include <asm/cache.h>
> -#include <asm/guest/hypervisor.h>
> +#include <asm/guest.h>
>  
>  static struct hypervisor_ops *hops __read_mostly;
>  
> @@ -31,7 +31,34 @@ bool hypervisor_probe(void)
>      if ( hops )
>          return true;
>  
> -    return false;
> +    /* Too early to use cpu_has_hypervisor */
> +    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
> +        return false;
> +
> +#ifdef CONFIG_XEN_GUEST
> +    if ( xen_probe() )
> +        hops = &xen_hypervisor_ops;
> +#endif

I think you likely want something like:

    if ( xen_probe() )
    {
        hops = &xen_hypervisor_ops;
	return true;
    }
    if ( hyperv_probe() )
    {
        ....
	return true;
    }

    return false;

In order to return after a successful probe, or else you lose cycles
probing for hypervisors when a match has been found, and also in the
Xen case you risk detecting the HyperV support in Xen and thus using
that instead of the Xen one.

Long term if we gain more guests support I would likely want to see
hypervisor_ops turning into an array and gaining a probe function so
that this can be done in a loop instead of having this function.

> +
> +    return !!hops;
> +}
> +
> +void hypervisor_setup(void)
> +{
> +    if ( hops && hops->setup )
> +        hops->setup();
> +}
> +
> +void hypervisor_ap_setup(void)
> +{
> +    if ( hops && hops->ap_setup )
> +        hops->ap_setup();
> +}
> +
> +void hypervisor_resume(void)
> +{
> +    if ( hops && hops->resume )
> +        hops->resume();
>  }
>  
>  /*
> diff --git a/xen/arch/x86/guest/xen/pvh-boot.c b/xen/arch/x86/guest/xen/pvh-boot.c
> index ca8e156f7d..498625eae0 100644
> --- a/xen/arch/x86/guest/xen/pvh-boot.c
> +++ b/xen/arch/x86/guest/xen/pvh-boot.c
> @@ -103,7 +103,7 @@ void __init pvh_init(multiboot_info_t **mbi, module_t **mod)
>  {
>      convert_pvh_info(mbi, mod);
>  
> -    probe_hypervisor();
> +    hypervisor_probe();
>      ASSERT(xen_guest);
>  
>      get_memory_map();
> diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c
> index 9895025d02..a9d321e5eb 100644
> --- a/xen/arch/x86/guest/xen/xen.c
> +++ b/xen/arch/x86/guest/xen/xen.c
> @@ -67,24 +67,19 @@ static void __init find_xen_leaves(void)
>      }
>  }
>  
> -void __init probe_hypervisor(void)
> +bool __init xen_probe(void)
>  {
> -    if ( xen_guest )
> -        return;
> -
> -    /* Too early to use cpu_has_hypervisor */
> -    if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) )
> -        return;
> -
>      find_xen_leaves();
>  
>      if ( !xen_cpuid_base )
> -        return;
> +        return false;
>  
>      /* Fill the hypercall page. */
>      wrmsrl(cpuid_ebx(xen_cpuid_base + 2), __pa(hypercall_page));
>  
>      xen_guest = true;
> +
> +    return true;
>  }
>  
>  static void map_shared_info(void)
> @@ -249,7 +244,7 @@ static void init_evtchn(void)
>      }
>  }
>  
> -void __init hypervisor_setup(void)
> +void __init xen_setup(void)
>  {
>      init_memmap();
>  
> @@ -277,7 +272,7 @@ void __init hypervisor_setup(void)
>      init_evtchn();
>  }
>  
> -void hypervisor_ap_setup(void)
> +void xen_ap_setup(void)
>  {
>      set_vcpu_id();
>      map_vcpuinfo();
> @@ -307,7 +302,7 @@ static void ap_resume(void *unused)
>      init_evtchn();
>  }
>  
> -void hypervisor_resume(void)
> +void xen_resume(void)

I think xen_{setup/ap_setup/resume} can be made static now?

Thanks, Roger.

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

  reply	other threads:[~2019-10-21  9:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 15:00 [Xen-devel] [PATCH for-next v2 0/9] Port Xen to Hyper-V Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 1/9] x86: introduce CONFIG_GUEST and move code Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 2/9] x86: include asm_defns.h directly in hypercall.h Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 3/9] x86: drop hypervisor_cpuid_base Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 4/9] x86: include xen/lib.h in guest/hypercall.h Wei Liu
2019-10-21  9:02   ` Roger Pau Monné
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 5/9] x86: introduce hypervisor framework Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 6/9] x86: rename hypervisor_{alloc, free}_unused_page Wei Liu
2019-10-21  9:11   ` Roger Pau Monné
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 7/9] x86: switch xen implementation to use hypervisor framework Wei Liu
2019-10-21  9:56   ` Roger Pau Monné [this message]
2019-10-21 14:35     ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 8/9] x86: be more verbose when running on a hypervisor Wei Liu
2019-10-21 10:00   ` Roger Pau Monné
2019-10-21 14:35     ` Wei Liu
2019-10-23 13:22     ` Jan Beulich
2019-11-05 11:17       ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next v2 9/9] x86: introduce CONFIG_HYPERV and detection code Wei Liu
2019-09-30 15:04   ` Wei Liu
2019-10-21 10:22   ` Roger Pau Monné
2019-10-21 10:26     ` Roger Pau Monné
2019-10-21 15:02       ` Andrew Cooper
2019-10-21 15:26         ` Wei Liu
2019-10-21 14:56     ` Wei Liu
2019-10-21 15:11       ` Roger Pau Monné
2019-10-21 15:20         ` Wei Liu
2019-09-30 15:00 ` [Xen-devel] [PATCH for-next RFC 0/8] Port Xen to Hyper-V Wei Liu
2019-10-21  8:58 ` [Xen-devel] [PATCH for-next v2 0/9] " Wei Liu

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=20191021095636.GF17494@Air-de-Roger \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=liuwe@microsoft.com \
    --cc=mikelley@microsoft.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.