qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, "Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host"
Date: Wed, 2 Jan 2013 20:00:26 +0100	[thread overview]
Message-ID: <20130102200026.3ab5eee4@thinkpad.mammed.net> (raw)
In-Reply-To: <1356726846-10637-8-git-send-email-ehabkost@redhat.com>

On Fri, 28 Dec 2012 18:34:04 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Note that we are initializing the CPU features inside instance_init (and
> not storing any CPU feature information inside the class struct) because
> kvm_cpu_fill_host() needs KVM to be initialized, and we can't guarantee
> that KVM will be initialized when class_init is called.
initializing defaults in initfn will be broken after we convert features into
static properties due to all initfn()s are called before static properties
defaults are set.

Is it possible to initialize kvm first before calling class_init().

> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  target-i386/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 42 insertions(+), 3 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index c824c08..2b6cc3b 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -330,6 +330,14 @@ typedef struct x86_def_t {
>  #define TCG_SVM_FEATURES 0
>  #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP)
>  
> +
> +/* CPU class name definitions: */
> +
> +#define CPU_CLASS_NAME(name) (name "-" TYPE_X86_CPU)
> +
> +#define TYPE_X86_HOST_CPU CPU_CLASS_NAME("host")
> +
> +
>  /* maintains list of cpu model definitions
>   */
>  static x86_def_t *x86_defs = {NULL};
> @@ -1221,9 +1229,7 @@ static X86CPU *x86_cpu_create_from_name(const char *name, Error **errp)
>  
>      if (kvm_enabled() && name && strcmp(name, "host") == 0) {
>  #ifdef CONFIG_KVM
> -        cpu = X86_CPU(object_new(TYPE_X86_CPU));
> -        kvm_cpu_fill_host(x86_cpu_def);
> -        cpudef_2_x86_cpu(cpu, x86_cpu_def, &error);
> +        cpu = X86_CPU(object_new(TYPE_X86_HOST_CPU));
>  #endif
>      } else {
>          x86_def_t *def;
> @@ -2168,9 +2174,42 @@ static const TypeInfo x86_cpu_type_info = {
>      .class_init = x86_cpu_common_class_init,
>  };
>  
> +#ifdef CONFIG_KVM
> +
> +static void x86_host_cpu_initfn(Object *obj)
> +{
> +    X86CPU *cpu = X86_CPU(obj);
> +    Error *err = NULL;
> +    x86_def_t cpudef;
> +
> +    memset(&cpudef, 0, sizeof(cpudef));
> +    kvm_cpu_fill_host(&cpudef);
> +    cpudef_2_x86_cpu(cpu, &cpudef, &err);
> +
> +    if (err) {
> +        error_report("unexpected cpu init error: %s", error_get_pretty(err));
> +        exit(1);
> +    }
> +}
> +
> +static const TypeInfo x86_host_cpu_type_info = {
> +    .name = TYPE_X86_HOST_CPU,
> +    .parent = TYPE_X86_CPU,
> +    .instance_size = sizeof(X86CPU),
> +    .instance_init = x86_host_cpu_initfn,
> +    .abstract = false,
> +    .class_size = sizeof(X86CPUClass),
> +};
> +
> +#endif /* CONFIG_KVM */
> +
> +
>  static void x86_cpu_register_types(void)
>  {
>      type_register_static(&x86_cpu_type_info);
> +#ifdef CONFIG_KVM
> +    type_register_static(&x86_host_cpu_type_info);
> +#endif
>  }
>  
>  type_init(x86_cpu_register_types)
> -- 
> 1.7.11.7
> 


-- 
Regards,
  Igor

  reply	other threads:[~2013-01-02 19:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 20:33 [Qemu-devel] [PATCH 0/9] x86 CPU subclasses Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 1/9] target-i386: Move CPU object creation to cpu.c Eduardo Habkost
2012-12-28 20:33 ` [Qemu-devel] [PATCH 2/9] target-i386: Make cpu_x86_create() get Error argument Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [PATCH 3/9] target-i386: Simplify cpu_x86_find_by_name() logic Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 4/9] target-i386: Set feature string parsing results directly on CPU object Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 5/9] target-i386: Move kvm_features/hypervisor initialization to cpu_x86_find_by_name() Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 6/9] target-i386: Move CPU creation code to model name lookup function Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 7/9] target-i386: CPU subclass for -cpu "host" Eduardo Habkost
2013-01-02 19:00   ` Igor Mammedov [this message]
2013-01-02 20:07     ` Igor Mammedov
2013-01-02 20:20       ` Eduardo Habkost
2013-01-02 20:16     ` Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 8/9] target-i386: CPU subclasses for predefined CPU models Eduardo Habkost
2012-12-28 20:34 ` [Qemu-devel] [RFC 9/9] target-i386: Unify CPU object creation on x86_cpu_create_from_name() Eduardo Habkost

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=20130102200026.3ab5eee4@thinkpad.mammed.net \
    --to=imammedo@redhat.com \
    --cc=afaerber@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.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 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).