Re: [PATCH] target-i386: Do not set MCG_SER_P by default

2015-11-20 Thread Andreas Färber
Hi,

CC'ing qemu-devel.

Am 21.11.2015 um 00:01 schrieb Borislav Petkov:
> From: Borislav Petkov 
> 
> Software Error Recovery, i.e. SER, is purely an Intel feature and it
> shouldn't be set by default. Enable it only on Intel.

Is this new in 2.5? Otherwise we would probably need compatibility code
in pc*.[ch] for incoming live migration from older versions.

> 
> Signed-off-by: Borislav Petkov 
> ---
>  target-i386/cpu.c | 7 ---
>  target-i386/cpu.h | 9 -
>  target-i386/kvm.c | 5 +
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 11e5e39a756a..8155ee94fbe1 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2803,13 +2803,6 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error 
> **errp)
>  }
>  #endif
>  
> -
> -#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
> -   (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
> -   (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
> -#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
> - (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
> - (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
>  static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
>  {
>  CPUState *cs = CPU(dev);
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index fc4a605d6a29..2605c564239a 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -283,7 +283,7 @@
>  #define MCG_CTL_P   (1ULL<<8)   /* MCG_CAP register available */
>  #define MCG_SER_P   (1ULL<<24) /* MCA recovery/new status bits */
>  
> -#define MCE_CAP_DEF (MCG_CTL_P|MCG_SER_P)
> +#define MCE_CAP_DEF MCG_CTL_P
>  #define MCE_BANKS_DEF   10
>  
>  #define MCG_STATUS_RIPV (1ULL<<0)   /* restart ip valid */
> @@ -610,6 +610,13 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
>  #define CPUID_MWAIT_IBE (1U << 1) /* Interrupts can exit capability */
>  #define CPUID_MWAIT_EMX (1U << 0) /* enumeration supported */
>  
> +#define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
> +   (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
> +   (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
> +#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
> + (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
> + (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
> +
>  #ifndef HYPERV_SPINLOCK_NEVER_RETRY
>  #define HYPERV_SPINLOCK_NEVER_RETRY 0x
>  #endif
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 2a9953b2d4b5..082d38d4838d 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -787,8 +787,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
>  if (banks > MCE_BANKS_DEF) {
>  banks = MCE_BANKS_DEF;
>  }
> +
>  mcg_cap &= MCE_CAP_DEF;
>  mcg_cap |= banks;
> +
> + if (IS_INTEL_CPU(env))
> + mcg_cap |= MCG_SER_P;

Tabs and missing braces.

> +
>  ret = kvm_vcpu_ioctl(cs, KVM_X86_SETUP_MCE, _cap);
>  if (ret < 0) {
>  fprintf(stderr, "KVM_X86_SETUP_MCE: %s", strerror(-ret));

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] qemu, pkeys: add pkeys support for qemu cpuid handling

2015-11-09 Thread Andreas Färber
Am 09.11.2015 um 13:24 schrieb Paolo Bonzini:
> On 09/11/2015 12:55, Huaitong Han wrote:
>> @@ -351,6 +362,7 @@ static const char *cpuid_6_feature_name[] = {
>>CPUID_7_0_EBX_FSGSBASE, CPUID_7_0_EBX_HLE, CPUID_7_0_EBX_AVX2,
>>CPUID_7_0_EBX_ERMS, CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM,
>>CPUID_7_0_EBX_RDSEED */
>> +#define TCG_7_0_ECX_FEATURES (CPUID_7_0_ECX_PKU | CPUID_7_0_ECX_OSPKE)
> 
> This should be zero.  Apart from this detail, the QEMU parts look good.

...except for the subjects, which should be "target-i386: add pkeys
support for cpuid handling" etc. - no need to put qemu into a QEMU
commit subject, especially not twice.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 11/12] qemu: add crash_occurred flag into CPUState

2015-07-02 Thread Andreas Färber
Hi,

This patch is clearly against QEMU, please name it cpu: Add crash_
(You may want to take a second look at the non-CPU patches, too.)

Am 02.07.2015 um 18:07 schrieb Denis V. Lunev:
 From: Andrey Smetanin asmeta...@virtuozzo.com
 
 CPUState-crash_occurred value inside CPUState marks

CPUState::crash_occurred field inside ...

 that guest crash occurred. This value added into cpu common

value is added

 migration subsection.
 
 Signed-off-by: Andrey Smetanin asmeta...@virtuozzo.com
 Signed-off-by: Denis V. Lunev d...@openvz.org
 CC: Paolo Bonzini pbonz...@redhat.com
 CC: Andreas Färber afaer...@suse.de
 ---
  exec.c| 19 +++
  include/qom/cpu.h |  1 +
  vl.c  |  3 +++
  3 files changed, 23 insertions(+)
 
 diff --git a/exec.c b/exec.c
 index f7883d2..adf49e8 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -465,6 +465,24 @@ static const VMStateDescription 
 vmstate_cpu_common_exception_index = {
  }
  };
  
 +static bool cpu_common_crash_occurred_needed(void *opaque)
 +{
 +CPUState *cpu = opaque;
 +
 +return cpu-crash_occurred != 0;
 +}
 +
 +static const VMStateDescription vmstate_cpu_common_crash_occurred = {
 +.name = cpu_common/crash_occurred,
 +.version_id = 1,
 +.minimum_version_id = 1,
 +.needed = cpu_common_crash_occurred_needed,
 +.fields = (VMStateField[]) {
 +VMSTATE_UINT32(crash_occurred, CPUState),
 +VMSTATE_END_OF_LIST()
 +}
 +};
 +
  const VMStateDescription vmstate_cpu_common = {
  .name = cpu_common,
  .version_id = 1,
 @@ -478,6 +496,7 @@ const VMStateDescription vmstate_cpu_common = {
  },
  .subsections = (const VMStateDescription*[]) {
  vmstate_cpu_common_exception_index,
 +vmstate_cpu_common_crash_occurred,
  NULL
  }
  };
 diff --git a/include/qom/cpu.h b/include/qom/cpu.h
 index 39f0f19..f559a69 100644
 --- a/include/qom/cpu.h
 +++ b/include/qom/cpu.h
 @@ -263,6 +263,7 @@ struct CPUState {
  bool created;
  bool stop;
  bool stopped;
 +uint32_t crash_occurred;
  volatile sig_atomic_t exit_request;
  uint32_t interrupt_request;
  int singlestep_enabled;

If you add this field to CPUState, you'll also need to reset it in
qom/cpu.c. Or is it intentionally persistent?

Looks good otherwise.

Regards,
Andreas

 diff --git a/vl.c b/vl.c
 index 38eee1f..9e0aee5 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -1723,6 +1723,9 @@ void qemu_system_reset(bool report)
  
  void qemu_system_guest_panicked(void)
  {
 +if (current_cpu) {
 +current_cpu-crash_occurred = 1;
 +}
  qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, error_abort);
  vm_stop(RUN_STATE_GUEST_PANICKED);
  }

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

2015-06-22 Thread Andreas Färber
Am 22.06.2015 um 18:05 schrieb Denis V. Lunev:
 From: Andrey Smetanin asmeta...@virtuozzo.com
 
 It's usually impossible to understand from Hyper-V
 crash msr's that crash happened because ctl msr
 always contains the same value HV_X64_MSR_CRASH_CTL_NOTIFY.
 To solve it add a particalar value hv_crash_occurred
 inside CPU state and migrate this value with crash msr's.
 
 Signed-off-by: Andrey Smetanin asmeta...@virtuozzo.com
 Signed-off-by: Denis V. Lunev d...@openvz.org
 CC: Paolo Bonzini pbonz...@redhat.com
 CC: Andreas Färber afaer...@suse.de
 ---
[...]
 diff --git a/target-i386/machine.c b/target-i386/machine.c
 index 15b3f31..4f72ba8 100644
 --- a/target-i386/machine.c
 +++ b/target-i386/machine.c
 @@ -679,6 +679,7 @@ static const VMStateDescription vmstate_msr_hyperv_crash 
 = {
  VMSTATE_UINT64(env.msr_hv_crash_ctl, X86CPU),
  VMSTATE_UINT64_ARRAY(env.msr_hv_crash_prm,
   X86CPU, HV_X64_MSR_CRASH_PARAMS),
 +VMSTATE_UINT8(env.hv_crash_occurred, X86CPU),
  VMSTATE_END_OF_LIST()
  }
  };

This looks like a migration format breakage. You probably need to squash
it with the preceding patch so that the cpu/msr_hyperv_crash
subsection does not change in size between commits. Just incrementing
the version is not an option for subsections, I think?

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in


Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

2015-06-22 Thread Andreas Färber
Am 22.06.2015 um 18:27 schrieb Paolo Bonzini:
 On the other hand, I wonder if current_cpu is available in
 qemu_system_guest_panicked.  If so, you could add the field to the
 generic CPUState struct and migrate it as a subsection of
 vmstate_cpu_common.

Hm, not sure whether it is.

Would that work with the two ways we use vmstate_cpu_common though?
I.e., can a nested VMState struct (VMSTATE_CPU()) have subsections?

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in


Re: [PATCH 11/11] qemu/kvm: mark in cpu state that hyper-v crash occured

2015-06-22 Thread Andreas Färber
Am 22.06.2015 um 18:36 schrieb Paolo Bonzini:
 On 22/06/2015 18:33, Andreas Färber wrote:
 On the other hand, I wonder if current_cpu is available in
 qemu_system_guest_panicked.  If so, you could add the field to the
 generic CPUState struct and migrate it as a subsection of
 vmstate_cpu_common.
 Hm, not sure whether it is.
 
 It should be...

Obviously depends on the call site. :) At some point in cpu-exec.c,
current_cpu gets set to NULL. So the function would at least deserve a
comment on when (not to) use it.

Cheers,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in


Re: [PATCH] Revert target-ppc: Create versionless CPU class per family if KVM

2015-03-04 Thread Andreas Färber
Am 03.03.2015 um 23:14 schrieb Alexey Kardashevskiy:
 On 03/04/2015 07:43 AM, Alexander Graf wrote:
 On 03.03.15 01:42, Alexey Kardashevskiy wrote:
 On 03/03/2015 12:51 AM, Alexander Graf wrote:
 On 02.03.15 14:42, Andreas Färber wrote:
 Am 02.03.2015 um 14:37 schrieb Alexander Graf:
 On 01.03.15 01:31, Andreas Färber wrote:
 This reverts commit 5b79b1cadd3e565b6d1a5ba59764bd47af58b271 to
 avoid
 double-registration of types:

 Registering `POWER5+-powerpc64-cpu' which already exists

 Taking the textual description of a CPU type as part of a new type
 name
 is plain wrong, and so is unconditionally registering a new type
 here.

 Cc: Alexey Kardashevskiy a...@ozlabs.ru
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Andreas Färber afaer...@suse.de

 Doesn't this break p8 support?

 Maybe, but p5 support was in longer and this is definitely a
 regression
 and really really wrong. If you know a way to fix it without
 handing it
 back to the IBM guys for more thought, feel free to give it a shot.

 I honestly don't fully remember what this was about. Wasn't this our
 special KVM class that we use to create a compatible cpu type on the
 fly?

 Alexey, please take a look at it.


 I sent a note yesterday :-/ Here it is again:

 With this revert, running qemu with HV KVM and -cpu POWER7 fails on real
 POWER7 machine as my machine has pvr 003f 0201 and POWER7 is an alias of
 POWER7_v2.3 (pvr 003f 0203); and this is what I tried to fix at the
 first place. QEMU looks at classes first, and if not found - at aliases,
 so this worked.

 I would rename POWER5+ to POWER5+_0.0 and make POWER5+ an alias
 for POWER5+_v2.1 (or POWER5+_0.0).

 Care to send a patch?
 
 I wonder if Andreas has a better solution to my initial problem - he
 obviously won't like the proposed patch :)

Quite predictable, am I? ;)

Could you please explain in detail what problem you are seeing on POWER8
without this patch?

From your new patch it rather sounds as if this was totally unrelated to
-cpu host and a new KVM-only feature, reinforcing my feeling that my
function is the wrong place for your code.

Also, as I pointed out, the description cannot safely be used as part of
the type name, as it may contain prohibited characters, so this still
needs fixing.

And for sure, if registering new types is indeed needed here, then a
check is needed for whether that type already exists and appropriate
error handling. I just don't understand why that is needed at all with
-cpu host taking the PVR as you say is needed here.

If you can precisely tell me what it is that you need then I'd be happy
to cook up a patch.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Revert target-ppc: Create versionless CPU class per family if KVM

2015-03-02 Thread Andreas Färber
Am 02.03.2015 um 14:37 schrieb Alexander Graf:
 On 01.03.15 01:31, Andreas Färber wrote:
 This reverts commit 5b79b1cadd3e565b6d1a5ba59764bd47af58b271 to avoid
 double-registration of types:

   Registering `POWER5+-powerpc64-cpu' which already exists

 Taking the textual description of a CPU type as part of a new type name
 is plain wrong, and so is unconditionally registering a new type here.

 Cc: Alexey Kardashevskiy a...@ozlabs.ru
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Andreas Färber afaer...@suse.de
 
 Doesn't this break p8 support?

Maybe, but p5 support was in longer and this is definitely a regression
and really really wrong. If you know a way to fix it without handing it
back to the IBM guys for more thought, feel free to give it a shot.

Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-02 Thread Andreas Färber
Am 02.03.2015 um 13:43 schrieb Michael Mueller:
 QEMU now switches into probe mode when the selected machine is none and no
 specific accelerator(s) has been requested (i.e.: -machine none).
 
 In probe mode a by ARCH_CONFIG defines predefined list of accelerators run
 their init() methods.
 
 Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com
 ---
  accel.c  | 31 +--
  include/hw/boards.h  |  1 +
  include/sysemu/kvm.h | 10 ++
  kvm-all.c|  3 +++
  4 files changed, 39 insertions(+), 6 deletions(-)

Edgar/Peter, isn't Xilinx using -machine none in TCG mode?

 @@ -78,20 +83,30 @@ static int accel_init_machine(AccelClass *acc, 
 MachineState *ms)
  
  int configure_accelerator(MachineState *ms)
  {
 -const char *p;
 +const char *p, *name;
  char buf[10];
  int ret;
  bool accel_initialised = false;
  bool init_failed = false;
  AccelClass *acc = NULL;
 +ObjectClass *oc;
 +bool probe_mode = false;
  
  p = qemu_opt_get(qemu_get_machine_opts(), accel);
  if (p == NULL) {
 -/* Use the default accelerator, tcg */
 -p = tcg;
 +oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
 +name = object_class_get_name(oc);
 +probe_mode = !strcmp(name, none TYPE_MACHINE_SUFFIX);
 +if (probe_mode) {
 +/* Use these accelerators in probe mode, tcg should be last */
 +p = probe_mode_accels;
 +} else {
 +/* Use the default accelerator, tcg */
 +p = tcg;
 +}
  }

Can't we instead use an explicit ,accel=probe or ,accel=auto?
That would then obsolete the next patch.

Regards,
Andreas

  
 -while (!accel_initialised  *p != '\0') {
 +while ((probe_mode || !accel_initialised)  *p != '\0') {
  if (*p == ':') {
  p++;
  }

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Revert target-ppc: Create versionless CPU class per family if KVM

2015-03-02 Thread Andreas Färber
Am 02.03.2015 um 14:51 schrieb Alexander Graf:
 On 02.03.15 14:42, Andreas Färber wrote:
 Am 02.03.2015 um 14:37 schrieb Alexander Graf:
 On 01.03.15 01:31, Andreas Färber wrote:
 This reverts commit 5b79b1cadd3e565b6d1a5ba59764bd47af58b271 to avoid
 double-registration of types:

   Registering `POWER5+-powerpc64-cpu' which already exists

 Taking the textual description of a CPU type as part of a new type name
 is plain wrong, and so is unconditionally registering a new type here.

 Cc: Alexey Kardashevskiy a...@ozlabs.ru
 Cc: qemu-sta...@nongnu.org
 Signed-off-by: Andreas Färber afaer...@suse.de

 Doesn't this break p8 support?

 Maybe, but p5 support was in longer and this is definitely a regression
 and really really wrong. If you know a way to fix it without handing it
 back to the IBM guys for more thought, feel free to give it a shot.
 
 I honestly don't fully remember what this was about. Wasn't this our
 special KVM class that we use to create a compatible cpu type on the fly?

No, the class I create on the fly is a few lines above:

pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
if (pvr_pcc == NULL) {
pvr_pcc = ppc_cpu_class_by_pvr_mask(host_pvr);
}
if (pvr_pcc == NULL) {
return -1;
}
type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
type_register(type_info);

So, if no matching class is returned, we never reach the offending code.

Here, a second type with the same parent was being created in the
kvm_ppc_register_host_cpu_type() function that is supposed to create
that host CPU type. Why? The host CPU type by definition should already
have the right PVR taken from the host. kvmppc_host_cpu_class_init():

/* Now fix up the class with information we can query from the host */
pcc-pvr = mfpvr();

 Alexey, please take a look at it.

Thanks,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-02 Thread Andreas Färber
Am 02.03.2015 um 17:43 schrieb Michael Mueller:
 On Mon, 02 Mar 2015 14:57:21 +0100
 Andreas Färber afaer...@suse.de wrote:
 
  int configure_accelerator(MachineState *ms)
  {
 -const char *p;
 +const char *p, *name;
  char buf[10];
  int ret;
  bool accel_initialised = false;
  bool init_failed = false;
  AccelClass *acc = NULL;
 +ObjectClass *oc;
 +bool probe_mode = false;
  
  p = qemu_opt_get(qemu_get_machine_opts(), accel);
  if (p == NULL) {
 -/* Use the default accelerator, tcg */
 -p = tcg;
 +oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
 +name = object_class_get_name(oc);
 +probe_mode = !strcmp(name, none TYPE_MACHINE_SUFFIX);
 +if (probe_mode) {
 +/* Use these accelerators in probe mode, tcg should be last */
 +p = probe_mode_accels;
 +} else {
 +/* Use the default accelerator, tcg */
 +p = tcg;
 +}
  }  

 Can't we instead use an explicit ,accel=probe or ,accel=auto?
 That would then obsolete the next patch.
 
 How would you express the following with the accel=pseudo-accel approach?
 
 -probe -machine s390-ccw,accel=kvm 
 
 Using machine none as default with tcg as last accelerator initialized 
 should not break
 anything.
 
 -M none

Let me ask differently: What does -machine none or -M none have to do
with probing? It reads as if you are introducing two probe modes. Why do
you need both? If we have -probe, isn't that independent of which
machine we specify? Who is going to call either, with which respective goal?

I think that changing the semantics of an absent ,accel=foo parameter to
mean something else than its longtime default of tcg is a bad idea.

Have you testing qtest with it? Doesn't -qtest imply accel=qtest or is
that always passed explicitly?

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Revert target-ppc: Create versionless CPU class per family if KVM

2015-02-28 Thread Andreas Färber
This reverts commit 5b79b1cadd3e565b6d1a5ba59764bd47af58b271 to avoid
double-registration of types:

  Registering `POWER5+-powerpc64-cpu' which already exists

Taking the textual description of a CPU type as part of a new type name
is plain wrong, and so is unconditionally registering a new type here.

Cc: Alexey Kardashevskiy a...@ozlabs.ru
Cc: qemu-sta...@nongnu.org
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-ppc/kvm.c | 21 -
 1 file changed, 21 deletions(-)

diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 1edf2b5..9d614ef 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -2160,18 +2160,6 @@ bool kvmppc_has_cap_fixup_hcalls(void)
 return cap_fixup_hcalls;
 }
 
-static PowerPCCPUClass *ppc_cpu_get_family_class(PowerPCCPUClass *pcc)
-{
-ObjectClass *oc = OBJECT_CLASS(pcc);
-
-while (oc  !object_class_is_abstract(oc)) {
-oc = object_class_get_parent(oc);
-}
-assert(oc);
-
-return POWERPC_CPU_CLASS(oc);
-}
-
 static int kvm_ppc_register_host_cpu_type(void)
 {
 TypeInfo type_info = {
@@ -2181,7 +2169,6 @@ static int kvm_ppc_register_host_cpu_type(void)
 };
 uint32_t host_pvr = mfpvr();
 PowerPCCPUClass *pvr_pcc;
-DeviceClass *dc;
 
 pvr_pcc = ppc_cpu_class_by_pvr(host_pvr);
 if (pvr_pcc == NULL) {
@@ -2192,14 +2179,6 @@ static int kvm_ppc_register_host_cpu_type(void)
 }
 type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
 type_register(type_info);
-
-/* Register generic family CPU class for a family */
-pvr_pcc = ppc_cpu_get_family_class(pvr_pcc);
-dc = DEVICE_CLASS(pvr_pcc);
-type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc));
-type_info.name = g_strdup_printf(%s-TYPE_POWERPC_CPU, dc-desc);
-type_register(type_info);
-
 return 0;
 }
 
-- 
2.3.0

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Andreas Färber
Am 20.02.2015 um 16:32 schrieb Michael Mueller:
 On Fri, 20 Feb 2015 15:03:30 +0100
 Alexander Graf ag...@suse.de wrote:
 

 - s390_get_proceccor_props()
 - s390_set_proceccor_props()

 They can be used to request or retrieve processor related information from 
 an accelerator.
 That information comprises the cpu identifier, the ICB value and the 
 facility lists.

 Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com  

 Hrm, I still seem to miss the point of this interface. What do you need
 it for?
 
 These functions make the internal s390 cpu model API independent from a 
 specific accelerator:  
 
 int s390_set_processor_props(S390ProcessorProps *prop)
 {
 if (kvm_enabled()) {
 return kvm_s390_set_processor_props(prop);
 }
 return -ENOSYS;
 }
 
 It's called by:
 
 s390_select_cpu_model(const char *model)
 
 which is itself called by:
 
 S390CPU *cpu_s390x_init(const char *cpu_model)
 {
 S390CPU *cpu;
 
 cpu = S390_CPU(object_new(s390_select_cpu_model(cpu_model)));
 
 object_property_set_bool(OBJECT(cpu), true, realized, NULL);
 
 return cpu;
 }
 
 So above s390_set/get_processor_props() the code is accelerator independent.

Can't you just implement the class-level name-to-ObjectClass callback
that other CPUs have grown for the above use case?

Also a general comment: cpu-model/ is not an existing directory nor one
you add, so please use target-s390x: Add foo to S390CPU or so.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Andreas Färber
Am 20.02.2015 um 17:04 schrieb Michael Mueller:
 On Fri, 20 Feb 2015 16:41:49 +0100
 Andreas Färber afaer...@suse.de wrote:
 
 Can't you just implement the class-level name-to-ObjectClass callback
 that other CPUs have grown for the above use case?
 
 If it fulfills the requirements sure. Please point me to an example,

Take a look at include/qom/cpu.h CPUClass::class_by_name and git-grep
the existing targets - most implement it already. It's a generic hook to
be used from everywhere rather than a local function specific to the
legacy init function. Apart from the error handling it should be
straight-forward.

 sounds that
 s390_select_cpu_model() is doing something similar to that, just that it 
 hooks in
 the s390_set_processor_props() call.
 
 const char *s390_select_cpu_model(const char *model)
 {
 S390ProcessorProps proc;
 const char *typename;
 S390CPUClass *cc;
 
 /* return already selected cpu typename */
 typename = s390_cpu_typename();
 if (typename) {
 goto out;
 }
 
 /* return standard cpu typename when cpu models are unavailable */
 typename = TYPE_S390_CPU;
 if (!s390_cpu_classes_initialized() || !model) {
 goto out;
 }
 cc = S390_CPU_CLASS(s390_cpu_class_by_name(model));
 if (!cc) {
 goto out;
 }
 proc.cpuid = cpuid(cc-proc);
 proc.ibc = cc-proc-ibc;
 memcpy(proc.fac_list, cc-fac_list, S390_ARCH_FAC_LIST_SIZE_BYTE);
 if (s390_set_processor_props(proc)) {
 goto out;
 }

Sorry for my ignorance, but what is proc actually needed for? For
initializing the class, there's .class_init (and cc-fac_list apparently
is initialized here). If you need to pass info to KVM, you can do so in
DeviceClass::realize when the vCPU actually goes live. A
string-to-string (or string-to-ObjectClass) translation function seems
like a weird point in time to take action with global effect.

Anyway, please implement the generic callback, then you can still call
it from your own helper functions if needed.

Regards,
Andreas

 
 /* return requested cpu typename in success case */
 typename = object_class_get_name((ObjectClass *) cc);
 out:
 selected_cpu_typename = typename;
 trace_select_cpu_model(model, typename);
 return typename;
 }

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Andreas Färber
Am 20.02.2015 um 17:12 schrieb Michael Mueller:
 On Fri, 20 Feb 2015 08:02:42 -0800
 Richard Henderson r...@twiddle.net wrote:
 
 +/**
 + * s390_test_facility - test if given facility bit is set facility list
 + *  of given cpu class
 + * @class: address of cpu class to test
 + * @nr: bit number to test
 + *
 + * Returns: true in case it is set
 + *  false in case it is not set
 + */

Please note that QEMU uses gtk-doc style, where the description goes
between arguments and Returns:, and the function name gets a ':'.
There's also fancy syntax like #CPUClass, %true, etc.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 0/6] target-i386: Make most CPU models work with enforce out of the box

2014-11-04 Thread Andreas Färber
Am 04.10.2014 um 00:16 schrieb Paolo Bonzini:
 Il 03/10/2014 21:39, Eduardo Habkost ha scritto:
 Changes v2 - v3:
  * None. This is just a rebase against latest qemu.git master (commit 
 b00a0dd)

 Changes v1 - v2:
  * Commit message and comment changes.
  * Update compat code to change pc-*-2.1, not pc-*-2.0.
  * Added patch to disable SVM by default in KVM mode.

 Most of the bits that make enforce breaks were introduced in 2010 by commit
 8560efed6a72a816c0115f41ddb9d79f7ce63f28. The intention behind that commit 
 made
 sense, the only problem is that we can't guarantee guest ABI stability across
 hosts if we simply rely on trimming of CPU features based on host 
 capabilities.

 So, this series remove CPUID bits from the CPU model definitions so they 
 become
 defaults that: 1) won't unexpectly stop working when we start using the
 enforce flag; 2) won't silently break the guest ABI when TCG or KVM start
 supporting new features.

 There's only one non-trivial case left: the qemu32/qemu64 models. The problem
 with them is that we have conflicting expectations about it, from different
 users:

 TCG users expect the default CPU model to contain most TCG-supported features
 (and it makes sense). See, for example, commit
 f1e00a9cf326acc1f2386a72525af8859852e1df.

 KVM users expect the default CPU model to be a conservative choice which will
 work on most host CPUs (and will only contain features that are supported by
 KVM).

 We could solve the qemu32/qemu64 issue by having different defaults for TCG 
 and
 KVM. But we have existing management code (libvirt) that already expects 
 qemu32
 or qemu64 to be the default, and changing the default would break that code. 
 I
 will send an RFC to address that later.

 Cc: Aurelien Jarno aurel...@aurel32.net
 Cc: Paolo Bonzini pbonz...@redhat.com
 Cc: kvm@vger.kernel.org

 Eduardo Habkost (6):
   pc: Create pc_compat_2_1() functions
   target-i386: Rename KVM auto-feature-enable compat function
   target-i386: Disable CPUID_ACPI by default on KVM mode
   target-i386: Remove unsupported bits from all CPU models
   target-i386: Don't enable nested VMX by default
   target-i386: Disable SVM by default in KVM mode

  hw/i386/pc_piix.c | 22 ++
  hw/i386/pc_q35.c  | 18 --
  target-i386/cpu.c | 42 --
  target-i386/cpu.h |  3 ++-
  4 files changed, 64 insertions(+), 21 deletions(-)

 
 Andreas, are you picking up this?

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

I do still have some comments, but let's get this in first.

Regards,
Andreas

-- 
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 21284 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 4/6] target-i386: Remove unsupported bits from all CPU models

2014-10-29 Thread Andreas Färber
Am 03.10.2014 um 21:39 schrieb Eduardo Habkost:
 The following CPU features were never supported by neither TCG or KVM,
 so they are useless on the CPU model definitions, today:
 
  * CPUID_DTS (DS)
  * CPUID_HT
  * CPUID_TM
  * CPUID_PBE
  * CPUID_EXT_DTES64
  * CPUID_EXT_DSCPL
  * CPUID_EXT_EST
  * CPUID_EXT_TM2
  * CPUID_EXT_XTPR
  * CPUID_EXT_PDCM
  * CPUID_SVM_LBRV
 
 As using enforce mode is the only way to ensure guest ABI doesn't
 change when moving to a different host, we should make enforce mode
 the default or at least encourage management software to always use it.
 
 In turn, to make enforce usable, we need CPU models that work without
 always requiring some features to be explicitly disabled. This patch
 removes the above features from all CPU model definitions.
 
 We won't need any machine-type compat code for those changes, because it
 is impossible to have existing VMs with those features enabled.
 
 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
 Cc: Aurelien Jarno aurel...@aurel32.net
 ---
 Changes v1 - v2:
 * Trivial typo fix in comment
 ---
  target-i386/cpu.c | 33 -
  1 file changed, 20 insertions(+), 13 deletions(-)
 
 diff --git a/target-i386/cpu.c b/target-i386/cpu.c
 index 4119fca..1e9fff9 100644
 --- a/target-i386/cpu.c
 +++ b/target-i386/cpu.c
 @@ -681,10 +681,11 @@ static X86CPUDefinition builtin_x86_defs[] = {
  .family = 16,
  .model = 2,
  .stepping = 3,
 +/* Missing: CPUID_HT */
  .features[FEAT_1_EDX] =
  PPRO_FEATURES |
  CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
 -CPUID_PSE36 | CPUID_VME | CPUID_HT,
 +CPUID_PSE36 | CPUID_VME,
  .features[FEAT_1_ECX] =
  CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_CX16 |
  CPUID_EXT_POPCNT,
[snip]

I'm okay with retaining these as comments. Anyone any objections?

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 5/6] target-i386: Don't enable nested VMX by default

2014-10-29 Thread Andreas Färber
Am 03.10.2014 um 21:39 schrieb Eduardo Habkost:
 TCG doesn't support VMX, and nested VMX is not enabled by default on the
 KVM kernel module.
 
 So, there's no reason to have VMX enabled by default on the core2duo and
 coreduo CPU models, today. Even the newer Intel CPU model definitions
 don't have it enabled.
 
 In this case, we need machine-type compat code, as people may be running
 the older machine-types on hosts that had VMX nesting enabled.
 
 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
 ---
  hw/i386/pc_piix.c | 2 ++
  hw/i386/pc_q35.c  | 2 ++
  target-i386/cpu.c | 8 
  3 files changed, 8 insertions(+), 4 deletions(-)
[...]
 diff --git a/target-i386/cpu.c b/target-i386/cpu.c
 index 1e9fff9..c336003 100644
 --- a/target-i386/cpu.c
 +++ b/target-i386/cpu.c
 @@ -720,10 +720,10 @@ static X86CPUDefinition builtin_x86_defs[] = {
  CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
  CPUID_PSE36 | CPUID_VME | CPUID_ACPI | CPUID_SS,
  /* Missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_EST,
 - * CPUID_EXT_TM2, CPUID_EXT_XTPR, CPUID_EXT_PDCM */
 + * CPUID_EXT_TM2, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_VMX */
  .features[FEAT_1_ECX] =
  CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 |
 -CPUID_EXT_VMX | CPUID_EXT_CX16,
 +CPUID_EXT_CX16,
  .features[FEAT_8000_0001_EDX] =
  CPUID_EXT2_LM | CPUID_EXT2_SYSCALL | CPUID_EXT2_NX,
  .features[FEAT_8000_0001_ECX] =
[snip]

Here I'm less certain what the best approach is. As you point out,
there's an inconsistency that I agree should be fixed. I wonder however
whether an approach similar to 3/6 for KVM only would be better? I.e.,
have VMX as a sometimes-KVM-supported feature be listed in the model and
filter it out for accel=kvm so that -cpu enforce works, but let
accel=tcg fail with features not implemented.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [INVITE] OVMF BoF session at the KVM Forum 2014

2014-09-18 Thread Andreas Färber
Hello Laszlo,

Am 18.09.2014 um 10:23 schrieb Laszlo Ersek:
 I've been made an offer that I couldn't refuse :) to organize a Birds
 of a Feather session concerning OVMF at the KVM Forum 2014.
 
 Interested people, please sign up:
 
   http://www.linux-kvm.org/page/KVM_Forum_2014_BOF#OVMF

Nice idea. Your summary mentions only ia32 and x86_64 - I would be
interested in an update on OVMF for AArch64 - there seemed to already be
support for ARM's Foundation Model but not yet for QEMU.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/6] target-i386: Make most CPU models work with enforce out of the box

2014-08-27 Thread Andreas Färber
Am 27.08.2014 17:42, schrieb Eduardo Habkost:
 On Wed, Aug 27, 2014 at 04:33:54PM +0200, Paolo Bonzini wrote:
 Il 27/08/2014 16:05, Eduardo Habkost ha scritto:
 On Wed, Aug 27, 2014 at 03:36:51PM +0200, Paolo Bonzini wrote:
 Il 26/08/2014 20:01, Eduardo Habkost ha scritto:
 So maybe that's good news, as things can be simpler if we make both TCG
 and KVM have similar behavior:

 * qemu64: a conservative default that should work out of the box on
   most systems, for both TCG and KVM. That's already the current status,
   we just need to document it.

 * -cpu host: for people who want every possible feature to be enabled
   (but without cross-version live-migration support). We can easily add
   support for -cpu host to TCG, too.

 This means that -cpu host has different meanings in KVM and TCG.  Is
 that an advantage or a disadvantage?

 It is the same meaning to me: enable everything that's possible,
 considering what's provided by the underlying accelerator. The host
 name is misleading, though, because on KVM it is close to the host CPU,
 but on TCG it depends solely on TCG's capabilities.

 True.  It's not very intuitive, but it is the same concept for processor
 capabilities.

 Though for some leaves that do not correspond to processor capabilities,
 -cpu host does set them to the host values.  This is not just the
 cache model, but also the family/model/stepping/vendor.

 For the TCG case, when running on a Nehalem it would be weird to see a
 Nehalem guest with SMAP or ADOX support...  I'm not sure it would even
 work to have SVM with an Intel vendor. :)
 
 In that case, the best family/model/stepping/vendor choice depends on
 TCG capabilities (defined at compile time), not on the host CPU.
 
 ...and that proves your point: if we aren't even using the host CPU
 family/model/stepping, calling it -cpu host doesn't make much sense.
 If it is so different from the host model, we can call it qemu64 (and
 do as you suggests below).

Might that be an opportunity to reconsider a -cpu best or so,
independent of its implementation, to avoid host?

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/6] target-i386: Make most CPU models work with enforce out of the box

2014-08-27 Thread Andreas Färber
Am 27.08.2014 18:08, schrieb Eduardo Habkost:
 On Wed, Aug 27, 2014 at 05:58:49PM +0200, Andreas Färber wrote:
 Am 27.08.2014 17:42, schrieb Eduardo Habkost:
 On Wed, Aug 27, 2014 at 04:33:54PM +0200, Paolo Bonzini wrote:
 Il 27/08/2014 16:05, Eduardo Habkost ha scritto:
 On Wed, Aug 27, 2014 at 03:36:51PM +0200, Paolo Bonzini wrote:
 Il 26/08/2014 20:01, Eduardo Habkost ha scritto:
 So maybe that's good news, as things can be simpler if we make both TCG
 and KVM have similar behavior:

 * qemu64: a conservative default that should work out of the box on
   most systems, for both TCG and KVM. That's already the current status,
   we just need to document it.

 * -cpu host: for people who want every possible feature to be enabled
   (but without cross-version live-migration support). We can easily add
   support for -cpu host to TCG, too.

 This means that -cpu host has different meanings in KVM and TCG.  Is
 that an advantage or a disadvantage?

 It is the same meaning to me: enable everything that's possible,
 considering what's provided by the underlying accelerator. The host
 name is misleading, though, because on KVM it is close to the host CPU,
 but on TCG it depends solely on TCG's capabilities.

 True.  It's not very intuitive, but it is the same concept for processor
 capabilities.

 Though for some leaves that do not correspond to processor capabilities,
 -cpu host does set them to the host values.  This is not just the
 cache model, but also the family/model/stepping/vendor.

 For the TCG case, when running on a Nehalem it would be weird to see a
 Nehalem guest with SMAP or ADOX support...  I'm not sure it would even
 work to have SVM with an Intel vendor. :)

 In that case, the best family/model/stepping/vendor choice depends on
 TCG capabilities (defined at compile time), not on the host CPU.

 ...and that proves your point: if we aren't even using the host CPU
 family/model/stepping, calling it -cpu host doesn't make much sense.
 If it is so different from the host model, we can call it qemu64 (and
 do as you suggests below).

 Might that be an opportunity to reconsider a -cpu best or so,
 independent of its implementation, to avoid host?
 
 It depends on what you expect -cpu best to mean. I have seen different
 meanings being proposed for it.
 
 IIRC, best was proposed to mean choose the best one from the existing
 (predefined) CPU models, not enable everything possible, not even
 looking at the CPU model table.
 
 Anyway, it makes sense to have a name for the enable everything mode
 (whatever it is), and simply make qemu64 an alias to it when in TCG
 mode.
 
 (If we didn't have existing libvirt code assuming qemu64 is always the
 default in QEMU, we could simply get rid of qemu64 and use better
 names. We may get rid of qemu64 later, but we need to provide a way
 for libvirt to stop using it, first.)

My or so referring to, e.g., -cpu optimum or -cpu maximum or whatever
we come up with that is a little more telling than qemu64 or host.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC] COLO HA Project proposal

2014-07-04 Thread Andreas Färber
Am 01.07.2014 14:12, schrieb Dr. David Alan Gilbert:
 Are there any standard APIs for the heartbeet thing we can already
 tie into?

Maybe the http://www.linux-ha.org/wiki/Heartbeat daemon?

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 16/19] target-i386: block migration and savevm if invariant tsc is exposed

2014-06-25 Thread Andreas Färber
From: Marcelo Tosatti mtosa...@redhat.com

Invariant TSC documentation mentions that invariant TSC will run at a
constant rate in all ACPI P-, C-. and T-states.

This is not the case if migration to a host with different TSC frequency
is allowed, or if savevm is performed. So block migration/savevm.

Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
Reviewed-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Eduardo Habkost ehabk...@redhat.com
Reviewed-by: Juan Quintela quint...@redhat.com
[AF+mtosatti: Updated error message]
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-i386/cpu-qom.h |  2 +-
 target-i386/kvm.c | 15 +++
 target-i386/machine.c |  2 +-
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index ff3a5de..71a1b97 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -121,7 +121,7 @@ static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
 #define ENV_OFFSET offsetof(X86CPU, env)
 
 #ifndef CONFIG_USER_ONLY
-extern const struct VMStateDescription vmstate_x86_cpu;
+extern struct VMStateDescription vmstate_x86_cpu;
 #endif
 
 /**
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 4bf0ac9..097fe11 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -35,6 +35,8 @@
 #include exec/ioport.h
 #include asm/hyperv.h
 #include hw/pci/pci.h
+#include migration/migration.h
+#include qapi/qmp/qerror.h
 
 //#define DEBUG_KVM
 
@@ -448,6 +450,8 @@ static bool hyperv_enabled(X86CPU *cpu)
 cpu-hyperv_relaxed_timing);
 }
 
+static Error *invtsc_mig_blocker;
+
 #define KVM_MAX_CPUID_ENTRIES  100
 
 int kvm_arch_init_vcpu(CPUState *cs)
@@ -705,6 +709,17 @@ int kvm_arch_init_vcpu(CPUState *cs)
   !!(c-ecx  CPUID_EXT_SMX);
 }
 
+c = cpuid_find_entry(cpuid_data.cpuid, 0x8007, 0);
+if (c  (c-edx  18)  invtsc_mig_blocker == NULL) {
+/* for migration */
+error_setg(invtsc_mig_blocker,
+   State blocked by non-migratable CPU device
+(invtsc flag));
+migrate_add_blocker(invtsc_mig_blocker);
+/* for savevm */
+vmstate_x86_cpu.unmigratable = 1;
+}
+
 cpuid_data.cpuid.padding = 0;
 r = kvm_vcpu_ioctl(cs, KVM_SET_CPUID2, cpuid_data);
 if (r) {
diff --git a/target-i386/machine.c b/target-i386/machine.c
index b8dcd2f..16d2f6a 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -603,7 +603,7 @@ static const VMStateDescription vmstate_msr_hyperv_time = {
 }
 };
 
-const VMStateDescription vmstate_x86_cpu = {
+VMStateDescription vmstate_x86_cpu = {
 .name = cpu,
 .version_id = 12,
 .minimum_version_id = 3,
-- 
1.8.4.5

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] Why I advise against using ivshmem

2014-06-18 Thread Andreas Färber
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 18.06.2014 12:48, schrieb Stefan Hajnoczi:
 On Tue, Jun 17, 2014 at 11:44:11AM +0200, Paolo Bonzini wrote:
 Il 17/06/2014 11:03, David Marchand ha scritto:
 Unless someone steps up and maintains ivshmem, I think it
 should be deprecated and dropped from QEMU.
 
 Then I can maintain ivshmem for QEMU. If this is ok, I will
 send a patch for MAINTAINERS file.
 
 Typically, adding yourself to maintainers is done only after
 having proved your ability to be a maintainer. :)
 
 So, let's stop talking and go back to code!  You can start doing
 what was suggested elsewhere in the thread: get the server and
 uio driver merged into the QEMU tree, document the protocol in
 docs/specs/ivshmem_device_spec.txt, and start fixing bugs such as
 the ones that Markus reported.
 
 One more thing to add to the list:
 
 static void ivshmem_read(void *opaque, const uint8_t * buf, int
 flags)
 
 The flags argument should be size.  Size should be checked
 before accessing buf.
 
 Please also see the bug fixes in the following unapplied patch: 
 [PATCH] ivshmem: fix potential OOB r/w access (#2) by Sebastian
 Krahmer 
 https://lists.gnu.org/archive/html/qemu-devel/2014-04/msg03538.html

Jumping
 
late onto this thread: SUSE Security team has just recently
done a thorough review of QEMU ivshmem code because a customer has
requested this be supported in SLES12. Multiple security-related
patches were submitted by Stefan Hajnoczi and Sebastian Krahmer, and I
fear they are probably still not merged for lack of active
maintainer... In such cases, after review, I expect them to be picked
up by Peter as committer or via qemu-trivial.

So -1, against dropping it.

Vincent, you will find an RFC for an ivshmem-test in the qemu-devel
list archives or possibly on my qtest branch. The blocking issue that
I haven't worked on yet is that we can't unconditionally run the qtest
because it depends on KVM enabled at configure time (as opposed to
runtime) to have the device available.
http://patchwork.ozlabs.org/patch/336367/

As others have stated before, the nahanni server seems unmaintained,
thus not getting packaged by SUSE either and making testing the
interrupt parts of ivshmem difficult - unless we sort out and fill
with actual test code my proposed qtest.

Regards,
Andreas

- -- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJToanZAAoJEPou0S0+fgE/L6YP/jtPiwvz3YoW3+H/h/YzrnE7
xVP92jj5orzmbG3HMmEnx0l7YrtzYkwymgUO56dy2SrLFe0xVMnxuzcHLzHLsnm3
bYvMVq3eAx8sdx9c/O2B/rQbNo2p8PF/luTNewN7A+w5TX0XgxdI3TpLT2pVxf0b
kMaBnfivzUf2JY/zg6NaiGnwvVrA/0kXsCGKcTBiMQxOX2EdDgNak842SjlmS332
dPbqp5PIMdxwCxI/p+gpmu0cSy1bl2H6N2gkmKQZ63Z2tA7bWn/APdQeHyOcESZE
xRAfDz2Cs3/6EL7FLirJWdwT9EMNaFcM+eRgIqDamFzviQPZVuLKdDUteO1k9x1s
FlhL3ZRa3qHair9ByEJItqzneAeYmuwZ2DkKh4p/HQfbcxLzZlL8a1EEtYz5DTy0
8+Ax6IU5U5RZmwJ4/M/Ov5eT4t/fNe0MbG3mf5A8FJ6GWoF11ut/wyj70p/EmXua
QjUblK/eFemN4YvIi0ovD4DR9ZH2+bXOb44wKL7yFahKLldaP4y9DhJTap2J0mT1
b62FfFZ6hVIGP5n30OHLlhe39QY6SyIPc4JNc9VZ3GcpXtfOHPUOAD/ykt/As1P3
cPfL+jM0QSb6VNJHNbvUsSlJ6xI26qEWzyJ5R7ww4fyEoq4XiE2RCDUWJ2t9/jQb
+Bi/esBUDhAduc1Eh3FK
=MtPH
-END PGP SIGNATURE-
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG: commit 50a2c6e breaks KVM/ARM (reset/init vcpu order)

2014-05-26 Thread Andreas Färber
Am 26.05.2014 11:57, schrieb Alexander Graf:
 
 Any reason we're so incredibly inconsistent in what we do during realize
 with reset? I would really prefer to ensure we're doing the same thing
 on all targets.
 
 
 Alex
 
 $ grep -R -A 3 -B 3 qemu_init_vcpu target-*
 target-alpha/cpu.c-CPUState *cs = CPU(dev);
 target-alpha/cpu.c-AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
 target-alpha/cpu.c-
 target-alpha/cpu.c:qemu_init_vcpu(cs);
 target-alpha/cpu.c-
 target-alpha/cpu.c-acc-parent_realize(dev, errp);
 target-alpha/cpu.c-}

Alpha is the main blocker for unifying CPU reset iirc. It does not
implement reset at all and thus is not calling it. The struct was not
designed for zero'ing things, so there's a mix of data fields and
pointers without clear separation to allow memset(), and I have neither
a working alpha test image nor the time to investigate this at the moment.

WIP here:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-alpha
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-reset

According to my commit unicore32 is another odd sock that doesn't reset
the CPU - despite implemented iirc.

Regards,
Andreas

 target-unicore32/cpu.c-{
 target-unicore32/cpu.c-UniCore32CPUClass *ucc =
 UNICORE32_CPU_GET_CLASS(dev);
 target-unicore32/cpu.c-
 target-unicore32/cpu.c:qemu_init_vcpu(CPU(dev));
 target-unicore32/cpu.c-
 target-unicore32/cpu.c-ucc-parent_realize(dev, errp);
 target-unicore32/cpu.c-}

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG: commit 50a2c6e breaks KVM/ARM (reset/init vcpu order)

2014-05-26 Thread Andreas Färber
Am 26.05.2014 12:31, schrieb Alexander Graf:
 
 On 26.05.14 12:20, Andreas Färber wrote:
 Am 26.05.2014 11:57, schrieb Alexander Graf:
 Any reason we're so incredibly inconsistent in what we do during realize
 with reset? I would really prefer to ensure we're doing the same thing
 on all targets.


 Alex

 $ grep -R -A 3 -B 3 qemu_init_vcpu target-*
 target-alpha/cpu.c-CPUState *cs = CPU(dev);
 target-alpha/cpu.c-AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
 target-alpha/cpu.c-
 target-alpha/cpu.c:qemu_init_vcpu(cs);
 target-alpha/cpu.c-
 target-alpha/cpu.c-acc-parent_realize(dev, errp);
 target-alpha/cpu.c-}
 Alpha is the main blocker for unifying CPU reset iirc. It does not
 implement reset at all and thus is not calling it. The struct was not
 designed for zero'ing things, so there's a mix of data fields and
 pointers without clear separation to allow memset(), and I have neither
 a working alpha test image nor the time to investigate this at the
 moment.

 WIP here:
 https://github.com/afaerber/qemu-cpu/commits/qom-cpu-alpha
 https://github.com/afaerber/qemu-cpu/commits/qom-cpu-reset

 According to my commit unicore32 is another odd sock that doesn't reset
 the CPU - despite implemented iirc.
 
 So if we had reset, we could call
 
   qemu_init_vcpu();
   cpu_reset()
 
 inside parent_realize(), right?

That's exactly what the single commit on qom-cpu-reset does. :)

Andreas

 Then let's prepare for that step and make at least all targets that do
 call cpu_reset call it after init_vcpu().
 
 
 Alex
 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 01/16] x86: Convert conditional compilation of debug printfs to regular ifs

2014-05-13 Thread Andreas Färber
Am 13.05.2014 09:02, schrieb Marc Marí:
 Modify debug macros to have the same format through the codebase and use 
 regular
 ifs instead of ifdef.
 
 As the debug printf is always put in code, some casting had to be added to 
 avoid
 warnings treated as errors at compile time.
 
 Signed-off-by: Marc Marí marc.mari.barc...@gmail.com
 ---
  hw/i386/kvm/pci-assign.c |9 -
  hw/i386/multiboot.c  |6 --
  target-i386/kvm.c|8 
  xen-hvm.c|   12 ++--
  xen-mapcache.c   |8 
  5 files changed, 22 insertions(+), 21 deletions(-)
 
 diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
 index e55421a..35757ae 100644
 --- a/hw/i386/kvm/pci-assign.c
 +++ b/hw/i386/kvm/pci-assign.c
 @@ -51,14 +51,13 @@
  //#define DEVICE_ASSIGNMENT_DEBUG
  
  #ifdef DEVICE_ASSIGNMENT_DEBUG
 -#define DEBUG(fmt, ...)   \
 -do {  \
 -fprintf(stderr, %s:  fmt, __func__ , __VA_ARGS__);  \
 -} while (0)
 +#define DEVICE_ASSIGNMENT_DEBUG_ENABLED 1
  #else
 -#define DEBUG(fmt, ...)
 +#define DEVICE_ASSIGNMENT_DEBUG_ENABLED 0
  #endif
  
 +#define DEBUG(fmt, ...) QEMU_DPRINTF(DEVICE_ASSIGNMENT_DEBUG_ENABLED, 
 pci_assign, fmt, ## __VA_ARGS__)

This is broken, QEMU_DPRINTF() is not defined yet. Looks like an
ordering issue with 16/16.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] KVM call agenda for 2014-05-13

2014-05-13 Thread Andreas Färber
Am 12.05.2014 13:09, schrieb Peter Maydell:
 On 12 May 2014 11:30, Peter Crosthwaite peter.crosthwa...@xilinx.com wrote:
 On Mon, May 12, 2014 at 7:44 PM, Peter Maydell peter.mayd...@linaro.org 
 wrote:
 On 12 May 2014 10:10, Juan Quintela quint...@redhat.com wrote:
 Please, send any topic that you are interested in covering.

 - QOMifying both Memory regions and GPIOs and attaching them via QOM
   links (Peter Crosthwaite)

 Is there some further useful material on-list on this subject, or
 are we just going to have a rerun of the discussions on the
 last two calls?
 
 I have any ugly work-in-progress series. TBH I was going to wait for
 discussion outcomes. Want me to RFC it?
 
 I don't think you necessarily need to post code, but maybe a writeup
 of current status/options would be useful to try to make the on-call
 discussion productive?

Here's my WIP qemu_irq conversion, so that we don't discuss IRQs for the
third time in a row without results:

https://github.com/afaerber/qemu-cpu/commits/qom-irq

make check passes, not further tested yet.
As a side effect, cleaning up the leaks turned out rather easy.

The only remaining users of qemu_free_irqs() are serial-pci.c and
ipack.c. If we can get rid of it altogether, the hacks for freeing the
memory chunk could be avoided.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 05/20] machine: Replace QEMUMachine by MachineClass in accelerator configuration

2014-05-05 Thread Andreas Färber
From: Marcel Apfelbaum marce...@redhat.com

This minimizes QEMUMachine usage, as part of machine QOM-ification.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 include/hw/boards.h |  3 +--
 include/hw/xen/xen.h|  2 +-
 include/qemu/typedefs.h |  1 +
 include/sysemu/kvm.h|  2 +-
 include/sysemu/qtest.h  |  2 +-
 kvm-all.c   |  6 +++---
 kvm-stub.c  |  2 +-
 qtest.c |  2 +-
 vl.c| 10 +-
 xen-all.c   |  2 +-
 xen-stub.c  |  2 +-
 11 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index be2e432..8f53334 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -3,12 +3,11 @@
 #ifndef HW_BOARDS_H
 #define HW_BOARDS_H
 
+#include qemu/typedefs.h
 #include sysemu/blockdev.h
 #include hw/qdev.h
 #include qom/object.h
 
-typedef struct MachineClass MachineClass;
-
 typedef struct QEMUMachineInitArgs {
 const MachineClass *machine;
 ram_addr_t ram_size;
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index 9d549fc..85fda3d 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -36,7 +36,7 @@ void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
 
-int xen_init(QEMUMachine *machine);
+int xen_init(MachineClass *mc);
 int xen_hvm_init(MemoryRegion **ram_memory);
 void xenstore_store_pv_console_info(int i, struct CharDriverState *chr);
 
diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
index bf8daac..86bab12 100644
--- a/include/qemu/typedefs.h
+++ b/include/qemu/typedefs.h
@@ -31,6 +31,7 @@ typedef struct MemoryListener MemoryListener;
 typedef struct MemoryMappingList MemoryMappingList;
 
 typedef struct QEMUMachine QEMUMachine;
+typedef struct MachineClass MachineClass;
 typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 192fe89..5ad4e0e 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -152,7 +152,7 @@ extern KVMState *kvm_state;
 
 /* external API */
 
-int kvm_init(QEMUMachine *machine);
+int kvm_init(MachineClass *mc);
 
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index 224131f..95c9ade 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -26,7 +26,7 @@ static inline bool qtest_enabled(void)
 
 bool qtest_driver(void);
 
-int qtest_init_accel(QEMUMachine *machine);
+int qtest_init_accel(MachineClass *mc);
 void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
 
 static inline int qtest_available(void)
diff --git a/kvm-all.c b/kvm-all.c
index 82a9119..5cb7f26 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1341,7 +1341,7 @@ static int kvm_max_vcpus(KVMState *s)
 return (ret) ? ret : kvm_recommended_vcpus(s);
 }
 
-int kvm_init(QEMUMachine *machine)
+int kvm_init(MachineClass *mc)
 {
 static const char upgrade_note[] =
 Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n
@@ -1433,8 +1433,8 @@ int kvm_init(QEMUMachine *machine)
 }
 
 kvm_type = qemu_opt_get(qemu_get_machine_opts(), kvm-type);
-if (machine-kvm_type) {
-type = machine-kvm_type(kvm_type);
+if (mc-kvm_type) {
+type = mc-kvm_type(kvm_type);
 } else if (kvm_type) {
 fprintf(stderr, Invalid argument kvm-type=%s\n, kvm_type);
 goto err;
diff --git a/kvm-stub.c b/kvm-stub.c
index ccdba62..8acda86 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -34,7 +34,7 @@ int kvm_init_vcpu(CPUState *cpu)
 return -ENOSYS;
 }
 
-int kvm_init(QEMUMachine *machine)
+int kvm_init(MachineClass *mc)
 {
 return -ENOSYS;
 }
diff --git a/qtest.c b/qtest.c
index 0ac9f42..2aba20d 100644
--- a/qtest.c
+++ b/qtest.c
@@ -500,7 +500,7 @@ static void qtest_event(void *opaque, int event)
 }
 }
 
-int qtest_init_accel(QEMUMachine *machine)
+int qtest_init_accel(MachineClass *mc)
 {
 configure_icount(0);
 
diff --git a/vl.c b/vl.c
index 2c2b625..f423b2e 100644
--- a/vl.c
+++ b/vl.c
@@ -2725,7 +2725,7 @@ static MachineClass *machine_parse(const char *name)
 exit(!name || !is_help_option(name));
 }
 
-static int tcg_init(QEMUMachine *machine)
+static int tcg_init(MachineClass *mc)
 {
 tcg_exec_init(tcg_tb_size * 1024 * 1024);
 return 0;
@@ -2735,7 +2735,7 @@ static struct {
 const char *opt_name;
 const char *name;
 int (*available)(void);
-int (*init)(QEMUMachine *);
+int (*init)(MachineClass *mc);
 bool *allowed;
 } accel_list[] = {
 { tcg, tcg, tcg_available, tcg_init, tcg_allowed },
@@ -2744,7 +2744,7 @@ static struct {
 { qtest, QTest, qtest_available, qtest_init_accel, qtest_allowed },
 };
 
-static int configure_accelerator(QEMUMachine *machine)
+static int configure_accelerator(MachineClass *mc

Re: [Qemu-devel] KVM call agenfda for 2014-04-01

2014-04-15 Thread Andreas Färber
Am 10.04.2014 17:52, schrieb Peter Maydell:
 On 10 April 2014 16:49, Alexander Graf ag...@suse.de wrote:
 For the next call, I would propose to revive the platform bus
 (aka: how to create non-PCI devices with -device) discussions
 to make sure we're all on the same page.
 
 I rather suspect we are not :-)  Do you have a link to
 the current proposals for prior reading?

* Igor had a proposal for hotplug of bus-less (memory) devices.
* Alistair had a proposal for command-line use of SysBus devices.

Both did not get much review from my side yet due to the release...

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] KVM call agenda for 2014-04-01

2014-03-31 Thread Andreas Färber
Hi,

Am 31.03.2014 12:40, schrieb Juan Quintela:
 
 Please, send any topic that you are interested in covering.

I would like to discuss the state of the QEMU release process, please:

* -rc1 has not been tagged.
* Who besides Anthony could upload a tarball if we tag and create it?
* make-release fix for SeaBIOS on the list. Ping, and are more affected?

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] KVM call agenda for 2014-04-01

2014-03-31 Thread Andreas Färber
Am 31.03.2014 16:32, schrieb Peter Maydell:
 On 31 March 2014 15:28, Paolo Bonzini pbonz...@redhat.com wrote:
 I think it would be a good idea to separate the committer and release
 manager roles.  Peter is providing the community with a wonderful service,
 just like you were; putting too much work on his shoulders risks getting us
 in the same situation if anything were to affect his ability to provide it.
 
 Yes, I strongly agree with this. I think we'll do much better
 if we can manage to share out responsibilities among a wider
 group of people.

May I propose Michael Roth, who is already experienced from the N-1
stable releases?

If we can enable him to upload the tarballs created from his tags that
would also streamline the stable workflow while at it.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL for-2.0-rc0 36/58] cpu: Move watchpoint fields from CPU_COMMON to CPUState

2014-03-13 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c  |  5 +++--
 exec.c  | 33 -
 gdbstub.c   |  8 
 include/exec/cpu-defs.h | 10 --
 include/qom/cpu.h   | 10 ++
 linux-user/main.c   |  5 +++--
 target-i386/cpu.h   |  2 +-
 target-i386/helper.c|  7 ---
 target-i386/kvm.c   |  8 
 target-lm32/cpu.h   |  2 +-
 target-lm32/helper.c|  7 ---
 target-xtensa/cpu.h |  2 +-
 target-xtensa/helper.c  |  8 +---
 13 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 798dc08..d7c21d3 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -200,10 +200,11 @@ void cpu_set_debug_excp_handler(CPUDebugExcpHandler 
*handler)
 
 static void cpu_handle_debug_exception(CPUArchState *env)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp;
 
-if (!env-watchpoint_hit) {
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+if (!cpu-watchpoint_hit) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 wp-flags = ~BP_WATCHPOINT_HIT;
 }
 }
diff --git a/exec.c b/exec.c
index 26ed9cc..ee5eff7 100644
--- a/exec.c
+++ b/exec.c
@@ -485,7 +485,7 @@ void cpu_exec_init(CPUArchState *env)
 cpu-cpu_index = cpu_index;
 cpu-numa_node = 0;
 QTAILQ_INIT(env-breakpoints);
-QTAILQ_INIT(env-watchpoints);
+QTAILQ_INIT(cpu-watchpoints);
 #ifndef CONFIG_USER_ONLY
 cpu-as = address_space_memory;
 cpu-thread_id = qemu_get_thread_id();
@@ -542,6 +542,7 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags, CPUWatchpoint **watchpoint)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
@@ -559,10 +560,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 wp-flags = flags;
 
 /* keep all GDB-injected watchpoints in front */
-if (flags  BP_GDB)
-QTAILQ_INSERT_HEAD(env-watchpoints, wp, entry);
-else
-QTAILQ_INSERT_TAIL(env-watchpoints, wp, entry);
+if (flags  BP_GDB) {
+QTAILQ_INSERT_HEAD(cpu-watchpoints, wp, entry);
+} else {
+QTAILQ_INSERT_TAIL(cpu-watchpoints, wp, entry);
+}
 
 tlb_flush_page(env, addr);
 
@@ -575,10 +577,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (addr == wp-vaddr  len_mask == wp-len_mask
  flags == (wp-flags  ~BP_WATCHPOINT_HIT)) {
 cpu_watchpoint_remove_by_ref(env, wp);
@@ -591,7 +594,9 @@ int cpu_watchpoint_remove(CPUArchState *env, target_ulong 
addr, target_ulong len
 /* Remove a specific watchpoint by reference.  */
 void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watchpoint)
 {
-QTAILQ_REMOVE(env-watchpoints, watchpoint, entry);
+CPUState *cpu = ENV_GET_CPU(env);
+
+QTAILQ_REMOVE(cpu-watchpoints, watchpoint, entry);
 
 tlb_flush_page(env, watchpoint-vaddr);
 
@@ -601,9 +606,10 @@ void cpu_watchpoint_remove_by_ref(CPUArchState *env, 
CPUWatchpoint *watchpoint)
 /* Remove all matching watchpoints.  */
 void cpu_watchpoint_remove_all(CPUArchState *env, int mask)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp, *next;
 
-QTAILQ_FOREACH_SAFE(wp, env-watchpoints, entry, next) {
+QTAILQ_FOREACH_SAFE(wp, cpu-watchpoints, entry, next) {
 if (wp-flags  mask)
 cpu_watchpoint_remove_by_ref(env, wp);
 }
@@ -799,6 +805,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
int prot,
target_ulong *address)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 hwaddr iotlb;
 CPUWatchpoint *wp;
 
@@ -818,7 +825,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
 
 /* Make accesses to pages with watchpoints go via the
watchpoint trap routines.  */
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (vaddr == (wp-vaddr  TARGET_PAGE_MASK)) {
 /* Avoid trapping reads of pages with a write breakpoint. */
 if ((prot  PAGE_WRITE) || (wp-flags  BP_MEM_READ)) {
@@ -1579,7 +1586,7 @@ static void check_watchpoint(int offset, int len_mask, 
int flags)
 CPUWatchpoint *wp;
 int cpu_flags;
 
-if (env-watchpoint_hit) {
+if (cpu-watchpoint_hit) {
 /* We re-entered the check after replacing the TB

Re: [Qemu-devel] [PATCH v3 6/9] target-mips: kvm: Add main KVM support for MIPS

2014-03-13 Thread Andreas Färber
Am 06.03.2014 18:09, schrieb James Hogan:
 From: Sanjay Lal sanj...@kymasys.com
 
 Implement the main KVM arch API for MIPS.
 
 Signed-off-by: Sanjay Lal sanj...@kymasys.com
 Signed-off-by: James Hogan james.ho...@imgtec.com
 Cc: Aurelien Jarno aurel...@aurel32.net
 Cc: Gleb Natapov g...@redhat.com
 Cc: Paolo Bonzini pbonz...@redhat.com
 Cc: Andreas Färber afaer...@suse.de
 Cc: Peter Maydell peter.mayd...@linaro.org
 ---
 Changes in v3:
  - s/dprintf/DPRINTF/ (Andreas Färber).
  - Use cs rather than cpu or env for CPUState variable names
(Andreas Färber).
  - Use CPUMIPSState rather than CPUArchState (Andreas Färber).
  - Pass MIPSCPU to cpu_mips_io_interrupts_pending() rather than
CPUMIPSState (Andreas Färber).
  - Remove spurious parentheses around cpu_mips_io_interrupts_pending()
call (Andreas Färber).
  - Pass MIPSCPU to kvm_mips_set_[ipi_]interrupt (Andreas Färber).
  - Make use of error_report (Andreas Färber) and clean up error messages
a little to include __func__.
  - Remove inline kvm_mips_{put,get}_one_[ul]reg() declarations from
kvm_mips.h. They're only used in target-mips/kvm.c anyway.
  - Make kvm_arch_{put,get}_registers static within target-mips/kvm.c and
remove from kvm_mips.h.
  - Set sigmask length to 16 from kvm_arch_init() since MIPS Linux has
128 signals. This is better than cluttering kvm_all.c with TARGET_*
ifdefs (Peter Maydell).
 
 Changes in v2:
  - Expand commit message
  - Checkpatch cleanups.
  - Some interrupt bug fixes from Yann Le Du l...@kymasys.com
  - Add get/set register functionality from Yann Le Du l...@kymasys.com
  - Use new 64 bit compatible ABI from Cavium from Sanjay Lal
sanj...@kymasys.com
  - Add dummy kvm_arch_init_irq_routing()
The common KVM code insists on calling kvm_arch_init_irq_routing() as
soon as it sees kernel header support for it (regardless of whether
QEMU supports it). Provide a dummy function to satisfy this.
  - Remove request_interrupt_window code (Peter Maydell)
 ---
  target-mips/kvm.c  | 472 
 +
  target-mips/kvm_mips.h |  19 ++
  2 files changed, 491 insertions(+)
  create mode 100644 target-mips/kvm.c
  create mode 100644 target-mips/kvm_mips.h
 
 diff --git a/target-mips/kvm.c b/target-mips/kvm.c
 new file mode 100644
 index 000..0ec343d
 --- /dev/null
 +++ b/target-mips/kvm.c
[...]
 +static inline int kvm_mips_put_one_reg(CPUState *cs, int reg_id, int32 *addr)

Did you mean int32_t?

 +{
 +__u64 val64 = (__u64)*addr;
 +struct kvm_one_reg cp0reg = {
 +.id = reg_id,
 +.addr = (__u64)((target_ulong)val64)
 +};
 +
 +return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, cp0reg);
 +}
 +
 +static inline int kvm_mips_put_one_ulreg(CPUState *cs, int reg_id,
 + target_ulong *addr)
 +{
 +__u64 val64 = (__u64)*addr;
 +struct kvm_one_reg cp0reg = {
 +.id = reg_id,
 +.addr = (__u64)((target_ulong)val64)
 +};
 +
 +return kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, cp0reg);
 +}
 +
 +static inline int kvm_mips_get_one_reg(CPUState *cs, int reg_id, int32 *addr)

int32_t?

 +{
 +int ret;
 +__u64 val64 = 0;
 +struct kvm_one_reg cp0reg = {
 +.id = reg_id,
 +.addr = (__u64)((target_ulong)val64)
 +};
 +
 +ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, cp0reg);
 +if (ret  0) {
 +return ret;
 +}
 +
 +*addr = (int32)val64;

int32_t?

 +return ret;
 +}
[snip]

int32 is a type used in softfloat that has weird at-least-as-wide
semantics and bit us in the past.

I'm not sure if we have a policy about __u64 etc. in KVM code. Since
it'll be Linux-only I don't see problems currently; for cross-platform
parts we prefer uint64_t. Suggest to leave as is unless told otherwise.

Otherwise looking good now, thanks for the CPU cleanups! We just had
another round of CPU refactorings go in today, but I don't spot a
conflict in this patch. Please rebase your local branch to verify.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 7/9] hw/mips: In KVM mode, inject IRQ2 (I/O) interupts via ioctls

2014-03-13 Thread Andreas Färber
Am 06.03.2014 18:09, schrieb James Hogan:
 From: Sanjay Lal sanj...@kymasys.com
 
 COP0 emulation is in-kernel for KVM, so inject IRQ2 (I/O) interrupts via
 ioctls.
 
 Signed-off-by: Sanjay Lal sanj...@kymasys.com
 Signed-off-by: James Hogan james.ho...@imgtec.com
 Reviewed-by: Aurelien Jarno aurel...@aurel32.net
 Cc: Andreas Färber afaer...@suse.de
 ---
 Changes in v3:
  - Pass MIPSCPU to kvm_mips_set_[ipi_]interrupt (Andreas Färber).

Reviewed-by: Andreas Färber afaer...@suse.de

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL for-2.0-rc0 1/6] Revert KVM: Split QEMUMachine typedef into separate header

2014-03-12 Thread Andreas Färber
This reverts commit 9c06a1f79f959fffd09bfb7efc3d76051a6cd2da.
The new header sysemu/qemumachine.h is undesired.

Suggested-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 include/hw/boards.h  |  3 ++-
 include/hw/xen/xen.h |  1 -
 include/sysemu/kvm.h |  1 -
 include/sysemu/qemumachine.h | 16 
 include/sysemu/qtest.h   |  1 -
 kvm-stub.c   |  1 -
 6 files changed, 2 insertions(+), 21 deletions(-)
 delete mode 100644 include/sysemu/qemumachine.h

diff --git a/include/hw/boards.h b/include/hw/boards.h
index c2096e6..89eb665 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -4,9 +4,10 @@
 #define HW_BOARDS_H
 
 #include sysemu/blockdev.h
-#include sysemu/qemumachine.h
 #include hw/qdev.h
 
+typedef struct QEMUMachine QEMUMachine;
+
 typedef struct QEMUMachineInitArgs {
 const QEMUMachine *machine;
 ram_addr_t ram_size;
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index e181821..9d549fc 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -10,7 +10,6 @@
 
 #include hw/irq.h
 #include qemu-common.h
-#include sysemu/qemumachine.h
 
 /* xen-machine.c */
 enum xen_mode {
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index ed01998..0bee1e8 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -18,7 +18,6 @@
 #include config-host.h
 #include qemu/queue.h
 #include qom/cpu.h
-#include sysemu/qemumachine.h
 
 #ifdef CONFIG_KVM
 #include linux/kvm.h
diff --git a/include/sysemu/qemumachine.h b/include/sysemu/qemumachine.h
deleted file mode 100644
index 4cefd56..000
--- a/include/sysemu/qemumachine.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * QEMU Machine typedef
- *
- * Copyright Alexander Graf ag...@suse.de
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#ifndef QEMUMACHINE_H
-#define QEMUMACHINE_H
-
-typedef struct QEMUMachine QEMUMachine;
-
-#endif /* !QEMUMACHINE_H */
diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index e62281d..224131f 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -16,7 +16,6 @@
 
 #include qemu-common.h
 #include qapi/error.h
-#include sysemu/qemumachine.h
 
 extern bool qtest_allowed;
 
diff --git a/kvm-stub.c b/kvm-stub.c
index 4ef084e..ccdba62 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -14,7 +14,6 @@
 #include hw/hw.h
 #include cpu.h
 #include sysemu/kvm.h
-#include sysemu/qemumachine.h
 
 #ifndef CONFIG_USER_ONLY
 #include hw/pci/msi.h
-- 
1.8.4.5

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v2 18/40] cpu: Move watchpoint fields from CPU_COMMON to CPUState

2014-03-09 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c  |  5 +++--
 exec.c  | 33 -
 gdbstub.c   |  8 
 include/exec/cpu-defs.h | 10 --
 include/qom/cpu.h   | 10 ++
 linux-user/main.c   |  5 +++--
 target-i386/cpu.h   |  2 +-
 target-i386/helper.c|  7 ---
 target-i386/kvm.c   |  8 
 target-lm32/cpu.h   |  2 +-
 target-lm32/helper.c|  7 ---
 target-xtensa/cpu.h |  2 +-
 target-xtensa/helper.c  |  8 +---
 13 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 798dc08..d7c21d3 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -200,10 +200,11 @@ void cpu_set_debug_excp_handler(CPUDebugExcpHandler 
*handler)
 
 static void cpu_handle_debug_exception(CPUArchState *env)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp;
 
-if (!env-watchpoint_hit) {
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+if (!cpu-watchpoint_hit) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 wp-flags = ~BP_WATCHPOINT_HIT;
 }
 }
diff --git a/exec.c b/exec.c
index 9b02c6a..cf4a0ef 100644
--- a/exec.c
+++ b/exec.c
@@ -485,7 +485,7 @@ void cpu_exec_init(CPUArchState *env)
 cpu-cpu_index = cpu_index;
 cpu-numa_node = 0;
 QTAILQ_INIT(env-breakpoints);
-QTAILQ_INIT(env-watchpoints);
+QTAILQ_INIT(cpu-watchpoints);
 #ifndef CONFIG_USER_ONLY
 cpu-as = address_space_memory;
 cpu-thread_id = qemu_get_thread_id();
@@ -542,6 +542,7 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags, CPUWatchpoint **watchpoint)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
@@ -559,10 +560,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 wp-flags = flags;
 
 /* keep all GDB-injected watchpoints in front */
-if (flags  BP_GDB)
-QTAILQ_INSERT_HEAD(env-watchpoints, wp, entry);
-else
-QTAILQ_INSERT_TAIL(env-watchpoints, wp, entry);
+if (flags  BP_GDB) {
+QTAILQ_INSERT_HEAD(cpu-watchpoints, wp, entry);
+} else {
+QTAILQ_INSERT_TAIL(cpu-watchpoints, wp, entry);
+}
 
 tlb_flush_page(env, addr);
 
@@ -575,10 +577,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (addr == wp-vaddr  len_mask == wp-len_mask
  flags == (wp-flags  ~BP_WATCHPOINT_HIT)) {
 cpu_watchpoint_remove_by_ref(env, wp);
@@ -591,7 +594,9 @@ int cpu_watchpoint_remove(CPUArchState *env, target_ulong 
addr, target_ulong len
 /* Remove a specific watchpoint by reference.  */
 void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watchpoint)
 {
-QTAILQ_REMOVE(env-watchpoints, watchpoint, entry);
+CPUState *cpu = ENV_GET_CPU(env);
+
+QTAILQ_REMOVE(cpu-watchpoints, watchpoint, entry);
 
 tlb_flush_page(env, watchpoint-vaddr);
 
@@ -601,9 +606,10 @@ void cpu_watchpoint_remove_by_ref(CPUArchState *env, 
CPUWatchpoint *watchpoint)
 /* Remove all matching watchpoints.  */
 void cpu_watchpoint_remove_all(CPUArchState *env, int mask)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp, *next;
 
-QTAILQ_FOREACH_SAFE(wp, env-watchpoints, entry, next) {
+QTAILQ_FOREACH_SAFE(wp, cpu-watchpoints, entry, next) {
 if (wp-flags  mask)
 cpu_watchpoint_remove_by_ref(env, wp);
 }
@@ -799,6 +805,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
int prot,
target_ulong *address)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 hwaddr iotlb;
 CPUWatchpoint *wp;
 
@@ -818,7 +825,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
 
 /* Make accesses to pages with watchpoints go via the
watchpoint trap routines.  */
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (vaddr == (wp-vaddr  TARGET_PAGE_MASK)) {
 /* Avoid trapping reads of pages with a write breakpoint. */
 if ((prot  PAGE_WRITE) || (wp-flags  BP_MEM_READ)) {
@@ -1573,7 +1580,7 @@ static void check_watchpoint(int offset, int len_mask, 
int flags)
 CPUWatchpoint *wp;
 int cpu_flags;
 
-if (env-watchpoint_hit) {
+if (cpu-watchpoint_hit) {
 /* We re-entered the check after replacing the TB

Re: [Qemu-devel] [PATCH v2 07/10] target-mips: kvm: Add main KVM support for MIPS

2014-02-10 Thread Andreas Färber
Am 16.12.2013 15:12, schrieb James Hogan:
 From: Sanjay Lal sanj...@kymasys.com
 
 Implement the main KVM arch API for MIPS.
 
 Signed-off-by: Sanjay Lal sanj...@kymasys.com
 Signed-off-by: James Hogan james.ho...@imgtec.com
 Cc: Aurelien Jarno aurel...@aurel32.net
 Cc: Gleb Natapov g...@redhat.com
 Cc: Paolo Bonzini pbonz...@redhat.com
 ---
 Changes in v2:
  - Expand commit message
  - Checkpatch cleanups.
  - Some interrupt bug fixes from Yann Le Du l...@kymasys.com
  - Add get/set register functionality from Yann Le Du l...@kymasys.com
  - Use new 64 bit compatible ABI from Cavium from Sanjay Lal
sanj...@kymasys.com
  - Add dummy kvm_arch_init_irq_routing()
The common KVM code insists on calling kvm_arch_init_irq_routing() as
soon as it sees kernel header support for it (regardless of whether
QEMU supports it). Provide a dummy function to satisfy this.
  - Remove request_interrupt_window code (Peter Maydell)
 ---
  target-mips/kvm.c  | 463 
 +
  target-mips/kvm_mips.h |  28 +++
  2 files changed, 491 insertions(+)
  create mode 100644 target-mips/kvm.c
  create mode 100644 target-mips/kvm_mips.h
 
 diff --git a/target-mips/kvm.c b/target-mips/kvm.c
 new file mode 100644
 index 000..951959b
 --- /dev/null
 +++ b/target-mips/kvm.c
 @@ -0,0 +1,463 @@
 +/*
 + * This file is subject to the terms and conditions of the GNU General Public
 + * License.  See the file COPYING in the main directory of this archive
 + * for more details.
 + *
 + * KVM/MIPS: MIPS specific KVM APIs
 + *
 + * Copyright (C) 2012-2013 Imagination Technologies Ltd.
 + * Authors: Sanjay Lal sanj...@kymasys.com
 +*/
 +
 +#include sys/types.h
 +#include sys/ioctl.h
 +#include sys/mman.h
 +
 +#include linux/kvm.h
 +
 +#include qemu-common.h
 +#include qemu/timer.h
 +#include sysemu/sysemu.h
 +#include sysemu/kvm.h
 +#include cpu.h
 +#include sysemu/cpus.h
 +#include kvm_mips.h
 +
 +#define DEBUG_KVM 0
 +
 +#define dprintf(fmt, ...) \

dprintf is the name of a stdio.h function, so DPRINTF may be a better name.

 +do { if (DEBUG_KVM) { fprintf(stderr, fmt, ## __VA_ARGS__); } } while (0)

This looks really modern, thanks. :)

 +
 +const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 +KVM_CAP_LAST_INFO
 +};
 +
 +unsigned long kvm_arch_vcpu_id(CPUState *cpu)
 +{
 +return cpu-cpu_index;
 +}
 +
 +int kvm_arch_init(KVMState *s)
 +{
 +dprintf(%s\n, __func__);
 +return 0;
 +}
 +
 +int kvm_arch_init_vcpu(CPUState *env)

Please use env only for CPUMIPSState, use cpu or cs here. The
usual convention is cs for CPUState in target-*/ so that cpu can be
used for MIPSCPU.

 +{
 +int ret = 0;
 +dprintf(%s\n, __func__);
 +return ret;
 +}
 +
 +void kvm_arch_reset_vcpu(CPUState *env)

Dito.

 +{
 +dprintf(%s\n, __func__);
 +}
 +
 +int kvm_arch_put_registers(CPUState *cs, int level)
 +{
 +MIPSCPU *cpu = MIPS_CPU(cs);
 +CPUMIPSState *env = cpu-env;
 +struct kvm_regs regs;
 +int ret;
 +int i;
 +
 +/* Set the registers based on QEMU's view of things */
 +for (i = 0; i  32; i++) {
 +regs.gpr[i] = env-active_tc.gpr[i];
 +}
 +
 +regs.hi = env-active_tc.HI[0];
 +regs.lo = env-active_tc.LO[0];
 +regs.pc = env-active_tc.PC;
 +
 +ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, regs);
 +
 +if (ret  0) {
 +return ret;
 +}
 +
 +ret = kvm_mips_te_put_cp0_registers(cs, KVM_PUT_FULL_STATE);
 +if (ret  0) {
 +return ret;
 +}
 +
 +return ret;
 +}
 +
 +int kvm_arch_get_registers(CPUState *cs)
 +{
 +MIPSCPU *cpu = MIPS_CPU(cs);
 +CPUMIPSState *env = cpu-env;
 +int ret = 0;
 +struct kvm_regs regs;
 +int i;
 +
 +/* Get the current register set as KVM seems it */
 +ret = kvm_vcpu_ioctl(cs, KVM_GET_REGS, regs);
 +
 +if (ret  0) {
 +return ret;
 +}
 +
 +for (i = 0; i  32; i++) {
 +env-active_tc.gpr[i] = regs.gpr[i];
 +}
 +
 +env-active_tc.HI[0] = regs.hi;
 +env-active_tc.LO[0] = regs.lo;
 +env-active_tc.PC = regs.pc;
 +
 +kvm_mips_te_get_cp0_registers(cs);
 +
 +return ret;
 +}
 +
 +int kvm_arch_insert_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint 
 *bp)

Dito.

 +{
 +dprintf(%s\n, __func__);
 +return 0;
 +}
 +
 +int kvm_arch_remove_sw_breakpoint(CPUState *env, struct kvm_sw_breakpoint 
 *bp)

Dito.

 +{
 +dprintf(%s\n, __func__);
 +return 0;
 +}
 +
 +static inline int cpu_mips_io_interrupts_pending(CPUArchState *env)

Please don't use CPUArchState in MIPS-specific code, use CPUMIPSState.
Although in this trivial case MIPSCPU would be more future-proof.

 +{
 +dprintf(%s: %#x\n, __func__, env-CP0_Cause  (1  (2 + CP0Ca_IP)));
 +return env-CP0_Cause  (0x1  (2 + CP0Ca_IP));
 +}
 +
 +
 +void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run)
 +{
 +MIPSCPU *cpu = MIPS_CPU(cs);
 +CPUMIPSState *env = cpu-env;
 +int r;
 +struct kvm_mips_interrupt intr;
 +
 +if 

Re: [qom-cpu PATCH 7/7 v9] target-i386: CPU model subclasses

2014-02-10 Thread Andreas Färber
Am 10.02.2014 11:21, schrieb Eduardo Habkost:
 +static const TypeInfo x86_cpu_host_type_info = {
 +.name = CPU_CLASS_NAME(host),
 +.parent = TYPE_X86_CPU,
 +.instance_size = sizeof(X86CPU),
 +.instance_init = x86_cpu_instance_init_host,
 +.abstract = false,
 +.class_size = sizeof(X86CPUClass),
 +.class_init = x86_cpu_class_init_host,
 +};

This looks broken: .class_data is not set but the loading of the cpudef
happens in the TYPE_X86_CPU initfn. My preferred solution would be to
move the cpudef-loading from TYPE_X86_CPU's instance_init to a separate
one specified for the models only, allowing non-cpudef-based models. Not
finished investigating yet.

For now I've prepended a patch implementing my generalized
CPUClass::class_by_name instead of a custom x86_cpu_class_by_name().

Other style nits that I'm working on cleaning up are declarations in the
middle of blocks, keeping _class_init naming convention (pretty sure my
patches always had the most-specific-to-least-specific naming), strictly
distinguishing between type and class, adding to my gtk-style
documentation rather than new custom comments, placing struct
documentation in the header and keeping the diff nicely readable AFAP.
I'd further like to keep some other conventions from previous CPU
subclasses, like pulling the model for loop out of the model
registration function.

My patches had always tried to turn what is now x86_cpu_load_def() into
an instance_init function rather than calling it from one - did you have
reasons not to?

Did you consider converting the host model in a first step to make the
patch smaller?

I'd rather finish my investigations and discuss my v10 patches but Paolo
is already asking whether Eduardo should send a PULL, so here's my
textual reply informing of some thoughts and WIP. ;)

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [uq/master PATCH 4/7] target-i386: Rename cpu_x86_register() to x86_cpu_load_def()

2014-02-09 Thread Andreas Färber
Am 31.01.2014 12:42, schrieb Paolo Bonzini:
 Il 30/01/2014 20:48, Eduardo Habkost ha scritto:
 There isn't any kind of registration involved in cpu_x86_register()
 anymore: it is simply looking up a CPU model name and loading the model
 definition data into the X86CPU object. Rename it to x86_cpu_load_def()
 to reflect what it does.

 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
[...]
 Reviewed-by: Paolo Bonzini pbonz...@redhat.com

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [uq/master PATCH 5/7] target-i386: Call x86_cpu_load_def() earlier

2014-02-09 Thread Andreas Färber
Am 30.01.2014 20:48, schrieb Eduardo Habkost:
 As we will initialize the X86CPU fields on instance_init eventually,
 move the code that initializes the X86CPU data based on the CPU model
 name closer to the object_new() call.
 
 Signed-off-by: Eduardo Habkost ehabk...@redhat.com

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [uq/master PATCH 6/7] target-i386: Rename x86_def_t to X86CPUDefinition

2014-02-09 Thread Andreas Färber
Am 31.01.2014 12:42, schrieb Paolo Bonzini:
 Il 30/01/2014 20:48, Eduardo Habkost ha scritto:
 As the new X86CPU subclass code is going to change lots of the code
 invoving x86_def_t, let's rename the struct to match coding style first.

 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
[...]
 Reviewed-by: Paolo Bonzini pbonz...@redhat.com

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [uq/master PATCH 7/7 v8] target-i386: CPU model subclasses

2014-02-09 Thread Andreas Färber
Am 31.01.2014 19:13, schrieb Eduardo Habkost:
 Register separate QOM classes for each x86 CPU model.
 
 This will allow management code to more easily probe what each CPU model
 provides, by simply creating objects using the appropriate class name,
 without having to restart QEMU.
 
 This also allows us to eliminate the qdev_prop_set_globals_for_type()
 hack to set CPU-model-specific global properties.
 
 Instead of creating separate class_init functions for each class, I just
 used class_data to store a pointer to the X86CPUDefinition struct for
 each CPU model. This should make the patch shorter and easier to review.
 Later we can gradually convert each X86CPUDefinition field to lists of
 per-class property defaults.
 
 Written based on the ideas from the patch [RFC v5] target-i386: Slim
 conversion to X86CPU subclasses + KVM subclasses written by Andreas
 Färber afaer...@suse.de, Igor Mammedov imamm...@redhat.com.
 
 The host CPU model is special, as the feature flags depend on KVM
 being initialized. So it has its own class_init and instance_init
 function, and feature flags are set on instance_init instead of
 class_init.
 
 Signed-off-by: Andreas Färber afaer...@suse.de
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 Signed-off-by: Eduardo Habkost ehabk...@redhat.com
 ---
 This patch is similar to the one sent by Andrea and then later
 resubmitted by Igor as [RFC v5] target-i386: Slim conversion to X86CPU
 subclasses + KVM subclasses, as it doesn't create one new class_init
 function for each subclass.
 
 Main differences v5 - v6 are:
  * Code was written from scratch (instead of using the previous patches
as base)
* I didn't mean to rewrite it entirely, but when doing additional
  simplification of the CPU init logic on other patches, I ended up
  rewriting it.
* I chose to keep the Signed-off-by lines because I built upon
  Andreas's and Igor's ideas. Is that OK?

Yes, your From and our Sobs in order is the expected way in this case.
If Igor agrees I would propose to drop the textual repetition of this.

I am ~1/3 through reviewing this and it looks pretty promising so far!
Thanks a lot for your efforts. Meanwhile one cleanup idea inline...

  * No KVM-specific subclasses, to keep things simpler.
  * No embedding of X86CPUDefinition (x86_def_t) inside the class struct,
instead keeping a pointer to the existing X86CPUDefinition struct.
  * The host class is registered on cpu.c, but the CPUID data
is filled on instance_init instead of class_init (because KVM has to
be initialized already).
* kvm_required field introduced to make sure the host class can't
  be used without KVM.
 
 Changes v6 - v7:
  * Rebase
 
 Changes v7 - v8:
  * Removed CPU listing code (will be sent as a separate patch)
  * Kept x86_cpudef_setup() (will be addressed in a separate patch)
 ---
  target-i386/cpu-qom.h |  13 
  target-i386/cpu.c | 197 
 --
  2 files changed, 138 insertions(+), 72 deletions(-)
 
 diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
 index 722f11a..60c5c32 100644
 --- a/target-i386/cpu-qom.h
 +++ b/target-i386/cpu-qom.h
 @@ -37,6 +37,9 @@
  #define X86_CPU_GET_CLASS(obj) \
  OBJECT_GET_CLASS(X86CPUClass, (obj), TYPE_X86_CPU)
  
 +
 +typedef struct X86CPUDefinition X86CPUDefinition;
 +
  /**
   * X86CPUClass:
   * @parent_realize: The parent class' realize handler.
 @@ -49,6 +52,16 @@ typedef struct X86CPUClass {
  CPUClass parent_class;
  /* public */
  
 +/* CPU model definition
 + * Should be eventually replaced by subclass-specific property defaults
 + */
 +X86CPUDefinition *cpu_def;
 +/* CPU model requires KVM to be enabled */
 +bool kvm_required;
 +/* Optional description of CPU model.
 + * If unavailable, cpu_def-model_id is used */
 +const char *model_description;

Here I wondered why you needed this? For PowerPCCPU subclasses we have
reused DeviceClass::desc.

Regards,
Andreas

 +
  DeviceRealize parent_realize;
  void (*parent_reset)(CPUState *cpu);
  } X86CPUClass;
[snip]

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [uq/master PATCH 0/7] x86 CPU subclasses, take 7

2014-01-31 Thread Andreas Färber
Am 30.01.2014 22:47, schrieb Paolo Bonzini:
 Il 30/01/2014 20:48, Eduardo Habkost ha scritto:
 Is there any hope to get this into QEMU 2.0, or it is now too late? I got
 almost no feedback on take 6 (submitted November 27).
 
 It's not too late, not for me at least.  I wanted to send the next
 uq/master pull request tomorrow or Tuesday, after I've done some more
 testing on enlightenments.  I can squeeze this in too.

Negative, not without my review. It's clearly a CPU series, and apart
from having been on vacation pretty much all of December, Eduardo and
others have objected to my subclass series the last 2 *years*, so 2
months is peanuts by comparison.

Further, I was under the impression that this series depends on Igor's
feature property series, which I haven't found time to rework and
haven't noticed anyone else do either. So if there's no prereqs (why
uq/master?) I'll happily start reviewing and queuing it.

As Eduardo points out below the commit message in the final patch, his
conversion is very similar to one of my earlier patch series, so
committing that with Eduardo as author via uq/master without crediting
me via uq/master would leave a bad taste.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 0/7 RESEND] target-i386: Simplify kvm_cpu_fill_host() and kvm_check_features_against_host()

2014-01-21 Thread Andreas Färber
Am 21.01.2014 11:03, schrieb Paolo Bonzini:
 Il 20/01/2014 21:39, Michael S. Tsirkin ha scritto:
 Resend of series submitted on 24 November 2013, that didn't get any 
 reply. Only
 change is a trivial conflict on patch 7/7.

 Question: which tree is the most appropriate to get this in? qom-cpu?
 kvm?
 Either kvm or my pc tree.
 Seems unrelated to qom.
 Paolo - want to review and take this?

 
 Yup, will include in the next uq/master pull request.

Thanks!

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH 0/7 RESEND] target-i386: Simplify kvm_cpu_fill_host() and kvm_check_features_against_host()

2014-01-20 Thread Andreas Färber
Am 20.01.2014 21:39, schrieb Michael S. Tsirkin:
 On Mon, Jan 20, 2014 at 04:36:56PM -0200, Eduardo Habkost wrote:
 On Mon, Jan 20, 2014 at 02:41:07PM -0200, Eduardo Habkost wrote:
 Resend of series submitted on 24 November 2013, that didn't get any reply. 
 Only
 change is a trivial conflict on patch 7/7.

 Question: which tree is the most appropriate to get this in? qom-cpu?
 kvm?
 
 Either kvm or my pc tree.
 Seems unrelated to qom.

Seems unrelated to PC. ;) I've been maintaining target-i386/cpu.c as
part of my QOM CPU tree according to MAINTAINERS.
I don't mind whether this goes through Paolo's or my tree, but for me to
take KVM related changes, I expect review from the KVM side.

 Paolo - want to review and take this?

Regards,
Andreas

  target-i386/cpu.c | 89 
 +--
  1 file changed, 20 insertions(+), 69 deletions(-)

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 03/10] target-i386: Move apic_state field from CPUX86State to X86CPU

2013-12-24 Thread Andreas Färber
From: Chen Fan chen.fan.f...@cn.fujitsu.com

This motion is preparing for refactoring vCPU APIC subsequently.

Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c|  2 +-
 cpus.c|  5 ++---
 hw/i386/kvmvapic.c|  8 +++-
 hw/i386/pc.c  | 17 -
 target-i386/cpu-qom.h |  4 
 target-i386/cpu.c | 22 ++
 target-i386/cpu.h |  4 
 target-i386/helper.c  | 12 ++--
 target-i386/kvm.c | 23 ++-
 target-i386/misc_helper.c |  8 
 10 files changed, 48 insertions(+), 57 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 30cfa2a..2711c58 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -320,7 +320,7 @@ int cpu_exec(CPUArchState *env)
 #if !defined(CONFIG_USER_ONLY)
 if (interrupt_request  CPU_INTERRUPT_POLL) {
 cpu-interrupt_request = ~CPU_INTERRUPT_POLL;
-apic_poll_irq(env-apic_state);
+apic_poll_irq(x86_env_get_cpu(env)-apic_state);
 }
 #endif
 if (interrupt_request  CPU_INTERRUPT_INIT) {
diff --git a/cpus.c b/cpus.c
index 01d128d..ca4c59f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1458,12 +1458,11 @@ void qmp_inject_nmi(Error **errp)
 
 CPU_FOREACH(cs) {
 X86CPU *cpu = X86_CPU(cs);
-CPUX86State *env = cpu-env;
 
-if (!env-apic_state) {
+if (!cpu-apic_state) {
 cpu_interrupt(cs, CPU_INTERRUPT_NMI);
 } else {
-apic_deliver_nmi(env-apic_state);
+apic_deliver_nmi(cpu-apic_state);
 }
 }
 #elif defined(TARGET_S390X)
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 2d87600..300a299 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -366,7 +366,7 @@ static int vapic_enable(VAPICROMState *s, X86CPU *cpu)
 (((hwaddr)cpu_number)  VAPIC_CPU_SHIFT);
 cpu_physical_memory_rw(vapic_paddr + offsetof(VAPICState, enabled),
(void *)enabled, sizeof(enabled), 1);
-apic_enable_vapic(cpu-env.apic_state, vapic_paddr);
+apic_enable_vapic(cpu-apic_state, vapic_paddr);
 
 s-state = VAPIC_ACTIVE;
 
@@ -496,12 +496,10 @@ static void vapic_enable_tpr_reporting(bool enable)
 };
 CPUState *cs;
 X86CPU *cpu;
-CPUX86State *env;
 
 CPU_FOREACH(cs) {
 cpu = X86_CPU(cs);
-env = cpu-env;
-info.apic = env-apic_state;
+info.apic = cpu-apic_state;
 run_on_cpu(cs, vapic_do_enable_tpr_reporting, info);
 }
 }
@@ -700,7 +698,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t 
data,
 default:
 case 4:
 if (!kvm_irqchip_in_kernel()) {
-apic_poll_irq(env-apic_state);
+apic_poll_irq(cpu-apic_state);
 }
 break;
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 3cd8f38..963446f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -171,14 +171,15 @@ void cpu_smm_update(CPUX86State *env)
 /* IRQ handling */
 int cpu_get_pic_interrupt(CPUX86State *env)
 {
+X86CPU *cpu = x86_env_get_cpu(env);
 int intno;
 
-intno = apic_get_interrupt(env-apic_state);
+intno = apic_get_interrupt(cpu-apic_state);
 if (intno = 0) {
 return intno;
 }
 /* read the irq from the PIC */
-if (!apic_accept_pic_intr(env-apic_state)) {
+if (!apic_accept_pic_intr(cpu-apic_state)) {
 return -1;
 }
 
@@ -190,15 +191,13 @@ static void pic_irq_request(void *opaque, int irq, int 
level)
 {
 CPUState *cs = first_cpu;
 X86CPU *cpu = X86_CPU(cs);
-CPUX86State *env = cpu-env;
 
 DPRINTF(pic_irqs: %s irq %d\n, level? raise : lower, irq);
-if (env-apic_state) {
+if (cpu-apic_state) {
 CPU_FOREACH(cs) {
 cpu = X86_CPU(cs);
-env = cpu-env;
-if (apic_accept_pic_intr(env-apic_state)) {
-apic_deliver_pic_intr(env-apic_state, level);
+if (apic_accept_pic_intr(cpu-apic_state)) {
+apic_deliver_pic_intr(cpu-apic_state, level);
 }
 }
 } else {
@@ -908,7 +907,7 @@ DeviceState *cpu_get_current_apic(void)
 {
 if (current_cpu) {
 X86CPU *cpu = X86_CPU(current_cpu);
-return cpu-env.apic_state;
+return cpu-apic_state;
 } else {
 return NULL;
 }
@@ -1002,7 +1001,7 @@ void pc_cpus_init(const char *cpu_model, DeviceState 
*icc_bridge)
 }
 
 /* map APIC MMIO area if CPU has APIC */
-if (cpu  cpu-env.apic_state) {
+if (cpu  cpu-apic_state) {
 /* XXX: what if the base changes? */
 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0,
 APIC_DEFAULT_ADDRESS, 0x1000);
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index f4fab15..dbe3e29 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386

Re: [Qemu-devel] KVM Guest keymap issue

2013-10-08 Thread Andreas Färber
Hi,

Am 08.10.2013 11:07, schrieb Matej Mailing:
 the strange thing is that all other keys and combinations work except
 those ccaron, Ccaron, scaron and Scaron, zcaron and ZCaron don't.

As mentioned on IRC, my colleague had sent a patch to add ccaron, scaron
and zcaron support for VNC:

http://patchwork.ozlabs.org/patch/270143/

Looks as if that hasn't been picked up yet, other patches in that series
have unresolved review comments. Jan?

Regards,
Andreas

P.S. Please don't top-post, that makes it harder to understand for added
people.

 In
 our language there are many words containing those chars and I really
 need to have them working.
 
 When looking at the sl keymap file, those codes, even for all other
 chars that I type with showkey --ascii, are different than the showkey
 outputs, but they work (except those mentioned above).
 
 Now I am totally confused on how could those that work, work ...
 
 Thanks for any enlightenments in advance :)
 Matej
 
 2013/9/26 Matej Mailing mail...@tam.si:
 I am still pretty lost here, also after reading your link which shed a
 light to many things.

 Every suggestion and idea is very welcome!
 Thanks,
 Matej

 2013/9/24 Markus Armbruster arm...@redhat.com:
 Not specific to KVM, adding qemu-devel.

 Matej Mailing mail...@tam.si writes:

 Dear list,

 I have a problem with a Windows XP guest that I connect to via VNC and
 is using sl keymap (option -k sl).

 The guest is Windows XP and the problematic characters are s, c and z
 with caron... when I type them via VNC, they are not printed at all in
 virtual system... I have checked the file /usr/share/kvm/keymaps/sl
 and it seems that it contains different codes than I get when doing
 showkey --ascii on the host machine (running Ubuntu 12.04). I have
 tried to change the KVM's keymap file 'sl' with the codes I get from
 showkey, but they are still not printed in virtual system to which I
 am connected via VNC...

 I am totally lost with this issue, thanks for your time and ideas.

 Required reading for anyone struggling with virtual keyboards:

 https://www.berrange.com/posts/2010/07/04/more-than-you-or-i-ever-wanted-to-know-about-virtual-keyboard-handling/
 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC qom-cpu 15/41] cpu: Move watchpoint fields from CPU_COMMON to CPUState

2013-09-04 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c  |  5 +++--
 exec.c  | 33 -
 gdbstub.c   |  8 
 include/exec/cpu-defs.h | 10 --
 include/qom/cpu.h   | 10 ++
 linux-user/main.c   |  5 +++--
 target-i386/cpu.h   |  2 +-
 target-i386/helper.c|  7 ---
 target-i386/kvm.c   |  8 
 target-xtensa/cpu.h |  2 +-
 target-xtensa/helper.c  |  8 +---
 11 files changed, 55 insertions(+), 43 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 0081eaf..209380d 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -183,10 +183,11 @@ void cpu_set_debug_excp_handler(CPUDebugExcpHandler 
*handler)
 
 static void cpu_handle_debug_exception(CPUArchState *env)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp;
 
-if (!env-watchpoint_hit) {
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+if (!cpu-watchpoint_hit) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 wp-flags = ~BP_WATCHPOINT_HIT;
 }
 }
diff --git a/exec.c b/exec.c
index 93958c3..5b70bf8 100644
--- a/exec.c
+++ b/exec.c
@@ -379,7 +379,7 @@ void cpu_exec_init(CPUArchState *env)
 cpu-cpu_index = cpu_index;
 cpu-numa_node = 0;
 QTAILQ_INIT(env-breakpoints);
-QTAILQ_INIT(env-watchpoints);
+QTAILQ_INIT(cpu-watchpoints);
 #ifndef CONFIG_USER_ONLY
 cpu-thread_id = qemu_get_thread_id();
 #endif
@@ -432,6 +432,7 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags, CPUWatchpoint **watchpoint)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
@@ -449,10 +450,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 wp-flags = flags;
 
 /* keep all GDB-injected watchpoints in front */
-if (flags  BP_GDB)
-QTAILQ_INSERT_HEAD(env-watchpoints, wp, entry);
-else
-QTAILQ_INSERT_TAIL(env-watchpoints, wp, entry);
+if (flags  BP_GDB) {
+QTAILQ_INSERT_HEAD(cpu-watchpoints, wp, entry);
+} else {
+QTAILQ_INSERT_TAIL(cpu-watchpoints, wp, entry);
+}
 
 tlb_flush_page(env, addr);
 
@@ -465,10 +467,11 @@ int cpu_watchpoint_insert(CPUArchState *env, target_ulong 
addr, target_ulong len
 int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr, target_ulong 
len,
   int flags)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 target_ulong len_mask = ~(len - 1);
 CPUWatchpoint *wp;
 
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (addr == wp-vaddr  len_mask == wp-len_mask
  flags == (wp-flags  ~BP_WATCHPOINT_HIT)) {
 cpu_watchpoint_remove_by_ref(env, wp);
@@ -481,7 +484,9 @@ int cpu_watchpoint_remove(CPUArchState *env, target_ulong 
addr, target_ulong len
 /* Remove a specific watchpoint by reference.  */
 void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watchpoint)
 {
-QTAILQ_REMOVE(env-watchpoints, watchpoint, entry);
+CPUState *cpu = ENV_GET_CPU(env);
+
+QTAILQ_REMOVE(cpu-watchpoints, watchpoint, entry);
 
 tlb_flush_page(env, watchpoint-vaddr);
 
@@ -491,9 +496,10 @@ void cpu_watchpoint_remove_by_ref(CPUArchState *env, 
CPUWatchpoint *watchpoint)
 /* Remove all matching watchpoints.  */
 void cpu_watchpoint_remove_all(CPUArchState *env, int mask)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 CPUWatchpoint *wp, *next;
 
-QTAILQ_FOREACH_SAFE(wp, env-watchpoints, entry, next) {
+QTAILQ_FOREACH_SAFE(wp, cpu-watchpoints, entry, next) {
 if (wp-flags  mask)
 cpu_watchpoint_remove_by_ref(env, wp);
 }
@@ -677,6 +683,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
int prot,
target_ulong *address)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 hwaddr iotlb;
 CPUWatchpoint *wp;
 
@@ -696,7 +703,7 @@ hwaddr memory_region_section_get_iotlb(CPUArchState *env,
 
 /* Make accesses to pages with watchpoints go via the
watchpoint trap routines.  */
-QTAILQ_FOREACH(wp, env-watchpoints, entry) {
+QTAILQ_FOREACH(wp, cpu-watchpoints, entry) {
 if (vaddr == (wp-vaddr  TARGET_PAGE_MASK)) {
 /* Avoid trapping reads of pages with a write breakpoint. */
 if ((prot  PAGE_WRITE) || (wp-flags  BP_MEM_READ)) {
@@ -1454,7 +1461,7 @@ static void check_watchpoint(int offset, int len_mask, 
int flags)
 CPUWatchpoint *wp;
 int cpu_flags;
 
-if (env-watchpoint_hit) {
+if (cpu-watchpoint_hit) {
 /* We re-entered the check after replacing the TB. Now raise
  * the debug interrupt so that is will trigger after the
  * current

[PULL 2/4] cpu: Use QTAILQ for CPU list

2013-09-03 Thread Andreas Färber
Introduce CPU_FOREACH(), CPU_FOREACH_SAFE() and CPU_NEXT() shorthand
macros.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c | 49 --
 cputlb.c   |  2 +-
 dump.c | 10 +-
 exec.c | 26 ++--
 gdbstub.c  | 14 ++---
 hw/arm/boot.c  |  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  3 +--
 hw/ppc/e500.c  |  2 +-
 hw/ppc/ppc.c   |  2 +-
 hw/ppc/spapr.c |  4 ++--
 hw/ppc/spapr_hcall.c   |  4 ++--
 include/qom/cpu.h  | 11 +--
 kvm-all.c  |  8 
 linux-user/elfload.c   |  2 +-
 linux-user/main.c  | 10 +++---
 linux-user/syscall.c   | 17 ++--
 memory_mapping.c   |  5 +++--
 monitor.c  |  2 +-
 target-i386/helper.c   |  3 +--
 target-i386/misc_helper.c  |  2 +-
 target-mips/op_helper.c| 10 --
 target-ppc/excp_helper.c   |  2 +-
 target-s390x/misc_helper.c |  8 
 translate-all.c|  4 ++--
 26 files changed, 94 insertions(+), 112 deletions(-)

diff --git a/cpus.c b/cpus.c
index d74cc11..363d392 100644
--- a/cpus.c
+++ b/cpus.c
@@ -86,7 +86,7 @@ static bool all_cpu_threads_idle(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 if (!cpu_thread_is_idle(cpu)) {
 return false;
 }
@@ -416,7 +416,7 @@ void hw_error(const char *fmt, ...)
 fprintf(stderr, qemu: hardware error: );
 vfprintf(stderr, fmt, ap);
 fprintf(stderr, \n);
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 fprintf(stderr, CPU #%d:\n, cpu-cpu_index);
 cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_FPU);
 }
@@ -428,7 +428,7 @@ void cpu_synchronize_all_states(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_state(cpu);
 }
 }
@@ -437,7 +437,7 @@ void cpu_synchronize_all_post_reset(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_post_reset(cpu);
 }
 }
@@ -446,7 +446,7 @@ void cpu_synchronize_all_post_init(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_post_init(cpu);
 }
 }
@@ -760,7 +760,7 @@ static void qemu_tcg_wait_io_event(void)
 qemu_cond_wait(qemu_io_proceeded_cond, qemu_global_mutex);
 }
 
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 qemu_wait_io_event_common(cpu);
 }
 }
@@ -872,11 +872,11 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 qemu_cond_signal(qemu_cpu_cond);
 
 /* wait for initial kick-off after machine start */
-while (first_cpu-stopped) {
+while (QTAILQ_FIRST(cpus)-stopped) {
 qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
 
 /* process any pending work */
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 qemu_wait_io_event_common(cpu);
 }
 }
@@ -991,13 +991,12 @@ void qemu_mutex_unlock_iothread(void)
 
 static int all_vcpus_paused(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
-while (cpu) {
+CPU_FOREACH(cpu) {
 if (!cpu-stopped) {
 return 0;
 }
-cpu = cpu-next_cpu;
 }
 
 return 1;
@@ -1005,23 +1004,20 @@ static int all_vcpus_paused(void)
 
 void pause_all_vcpus(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
 qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false);
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu-stop = true;
 qemu_cpu_kick(cpu);
-cpu = cpu-next_cpu;
 }
 
 if (qemu_in_vcpu_thread()) {
 cpu_stop_current();
 if (!kvm_enabled()) {
-cpu = first_cpu;
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu-stop = false;
 cpu-stopped = true;
-cpu = cpu-next_cpu;
 }
 return;
 }
@@ -1029,10 +1025,8 @@ void pause_all_vcpus(void)
 
 while (!all_vcpus_paused()) {
 qemu_cond_wait(qemu_pause_cond, qemu_global_mutex);
-cpu = first_cpu;
-while (cpu) {
+CPU_FOREACH(cpu) {
 qemu_cpu_kick(cpu);
-cpu = cpu-next_cpu;
 }
 }
 }
@@ -1046,12 +1040,11 @@ void cpu_resume(CPUState *cpu)
 
 void resume_all_vcpus(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
 qemu_clock_enable(QEMU_CLOCK_VIRTUAL, true);
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu_resume(cpu);
-cpu = cpu-next_cpu;
 }
 }
 
@@ -1215,7 +1208,7

Re: [Qemu-devel] [PATCH] i386: forward CPUID cache leaves when -cpu host is used

2013-09-02 Thread Andreas Färber
Hi,

target-i386: please.

Am 27.08.2013 22:38, schrieb Benoît Canet:
 Some users running cpu intensive tasks checking the cache CPUID leaves at
 startup and making decisions based on the result reported that the guest was
 not reflecting the host CPUID leaves when -cpu host is used.
 
 This patch fix this.
 
 Signed-off-by: Benoit Canet ben...@irqsave.net
 ---
  target-i386/cpu.c |   19 +++
  target-i386/cpu.h |1 +
  2 files changed, 20 insertions(+)
 
 diff --git a/target-i386/cpu.c b/target-i386/cpu.c
 index 42c5de0..2c8eaf7 100644
 --- a/target-i386/cpu.c
 +++ b/target-i386/cpu.c
 @@ -374,6 +374,7 @@ typedef struct x86_def_t {
  int stepping;
  FeatureWordArray features;
  char model_id[48];
 +bool fwd_cpuid_cache_leaves;
  } x86_def_t;
  
  #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
 @@ -1027,6 +1028,7 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
  assert(kvm_enabled());
  
  x86_cpu_def-name = host;
 +x86_cpu_def-fwd_cpuid_cache_leaves = true;
  host_cpuid(0x0, 0, eax, ebx, ecx, edx);
  x86_cpu_vendor_words2str(x86_cpu_def-vendor, ebx, edx, ecx);
  
 @@ -1776,6 +1778,7 @@ static void cpu_x86_register(X86CPU *cpu, const char 
 *name, Error **errp)
  env-features[FEAT_C000_0001_EDX] = def-features[FEAT_C000_0001_EDX];
  env-features[FEAT_7_0_EBX] = def-features[FEAT_7_0_EBX];
  env-cpuid_xlevel2 = def-xlevel2;
 +env-fwd_cpuid_cache_leaves = def-fwd_cpuid_cache_leaves;
  
  object_property_set_str(OBJECT(cpu), def-model_id, model-id, errp);
  }
 @@ -1949,6 +1952,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
 uint32_t count,
  }
  break;
  case 2:
 +if (env-fwd_cpuid_cache_leaves) {
 +host_cpuid(0x2, 0, eax, ebx, ecx, edx);
 +break;
 +}
  /* cache info: needed for Pentium Pro compatibility */
  *eax = 1;
  *ebx = 0;
 @@ -1956,6 +1963,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
 uint32_t count,
  *edx = 0x2c307d;
  break;
  case 4:
 +if (env-fwd_cpuid_cache_leaves) {
 +host_cpuid(0x4, count, eax, ebx, ecx, edx);
 +break;
 +}
  /* cache info: needed for Core compatibility */
  if (cs-nr_cores  1) {
  *eax = (cs-nr_cores - 1)  26;
 @@ -2102,6 +2113,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
 uint32_t count,
  break;
  case 0x8005:
  /* cache info (L1 cache) */
 +if (env-fwd_cpuid_cache_leaves) {
 +host_cpuid(0x8005, 0, eax, ebx, ecx, edx);
 +break;
 +}
  *eax = 0x01ff01ff;
  *ebx = 0x01ff01ff;
  *ecx = 0x40020140;
 @@ -2109,6 +2124,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
 uint32_t count,
  break;
  case 0x8006:
  /* cache info (L2 cache) */
 +if (env-fwd_cpuid_cache_leaves) {
 +host_cpuid(0x8006, 0, eax, ebx, ecx, edx);
 +break;
 +}
  *eax = 0;
  *ebx = 0x42004200;
  *ecx = 0x02008140;

This hunk may trivially conflict with Eduardo's cache flags cleanup.

 diff --git a/target-i386/cpu.h b/target-i386/cpu.h
 index 8a3d0fd..1ec32fa 100644
 --- a/target-i386/cpu.h
 +++ b/target-i386/cpu.h
 @@ -865,6 +865,7 @@ typedef struct CPUX86State {
  bool tsc_valid;
  int tsc_khz;
  void *kvm_xsave_buf;
 +bool fwd_cpuid_cache_leaves;
  
  /* in order to simplify APIC support, we leave this pointer to the
 user */

Please place the field in X86CPU instead and document it.

Otherwise patch looks okay to me on a brief sight; but since this is
about -cpu host I would prefer this to go through uq/master once fixed
or at least to get some acks.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC][PATCH 2/6] cpus: release allocated vcpu objects and exit vcpu thread

2013-08-28 Thread Andreas Färber
Am 29.08.2013 04:09, schrieb Chen Fan:
 After ACPI get a signal to eject a vcpu, then it will notify
 the vcpu thread of needing to exit, before the vcpu exiting,
 will release the vcpu related objects.
 
 Signed-off-by: Chen Fan chen.fan.f...@cn.fujitsu.com
 ---
  cpus.c   | 36 
  hw/acpi/piix4.c  | 16 
  include/qom/cpu.h|  9 +
  include/sysemu/kvm.h |  1 +
  kvm-all.c| 26 ++
  5 files changed, 84 insertions(+), 4 deletions(-)
 
 diff --git a/cpus.c b/cpus.c
 index 70cc617..6b793cb 100644
 --- a/cpus.c
 +++ b/cpus.c
 @@ -697,6 +697,30 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void 
 *data), void *data)
  qemu_cpu_kick(cpu);
  }
  
 +static void qemu_kvm_destroy_vcpu(CPUState *cpu)
 +{
 +CPUState *pcpu, *pcpu1;
 +
 +pcpu = first_cpu;
 +pcpu1 = NULL;
 +
 +while (pcpu) {
 +if (pcpu == cpu  pcpu1) {
 +pcpu1-next_cpu = cpu-next_cpu;
 +break;
 +}
 +pcpu1 = pcpu;
 +pcpu = pcpu-next_cpu;
 +}

No, no, no. :) I specifically posted the QOM CPUState, part 12 series
early to avoid exactly such code appearing! Give me a few minutes to
apply that to qom-cpu and then please rebase your work on
git://github.com/afaerber/qemu-cpu.git qom-cpu
using QTAILQ macro and --subject-prefix=RFC qom-cpu v2 for the next
version of the series.

Also, why is this only in the KVM code path? Isn't this needed for TCG
as well?

 +
 +if (kvm_destroy_vcpu(cpu)  0) {
 +fprintf(stderr, kvm_destroy_vcpu failed.\n);
 +exit(1);
 +}
 +
 +qdev_free(DEVICE(X86_CPU(cpu)));

DEVICE(cpu) should be sufficient.

 +}
 +
  static void flush_queued_work(CPUState *cpu)
  {
  struct qemu_work_item *wi;
 @@ -788,6 +812,11 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
  }
  }
  qemu_kvm_wait_io_event(cpu);
 +if (cpu-exit  !cpu_can_run(cpu)) {
 +qemu_kvm_destroy_vcpu(cpu);
 +qemu_mutex_unlock(qemu_global_mutex);
 +return NULL;
 +}
  }
  
  return NULL;
 @@ -1080,6 +1109,13 @@ static void qemu_dummy_start_vcpu(CPUState *cpu)
  }
  }
  
 +void qemu_down_vcpu(CPUState *cpu)
 +{
 +cpu-stop = true;
 +cpu-exit = true;
 +qemu_cpu_kick(cpu);
 +}
 +
  void qemu_init_vcpu(CPUState *cpu)
  {
  cpu-nr_cores = smp_cores;
 diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
 index 1aaa7a4..44bc809 100644
 --- a/hw/acpi/piix4.c
 +++ b/hw/acpi/piix4.c
 @@ -611,10 +611,18 @@ static const MemoryRegionOps piix4_pci_ops = {
  },
  };
  
 -static void acpi_piix_eject_vcpu(int64_t cpuid)
 +static void acpi_piix_eject_vcpu(PIIX4PMState *s, int64_t cpuid)
  {
 -/* TODO: eject a vcpu, release allocated vcpu and exit the vcpu pthread. 
  */
 -PIIX4_DPRINTF(vcpu: % PRIu64  need to be ejected.\n, cpuid);
 +CPUStatus *cpus = s-gpe_cpu;
 +CPUState *cs = NULL;
 +
 +cs = qemu_get_cpu(cpuid);

Are you sure this is correct as 0-based index? Igor?

 +if (cs == NULL) {
 +return;
 +}
 +
 +cpus-old_sts[cpuid / 8] = ~(1  (cpuid % 8));
 +qemu_down_vcpu(cs);
  }
  
  static uint64_t cpu_status_read(void *opaque, hwaddr addr, unsigned int size)
 @@ -647,7 +655,7 @@ static void cpu_status_write(void *opaque, hwaddr addr, 
 uint64_t data,
  }
  
  if (cpuid != 0) {
 -acpi_piix_eject_vcpu(cpuid);
 +acpi_piix_eject_vcpu(s, cpuid);
  }
  }
  
 diff --git a/include/qom/cpu.h b/include/qom/cpu.h
 index 3e49936..fa8ec8a 100644
 --- a/include/qom/cpu.h
 +++ b/include/qom/cpu.h
 @@ -180,6 +180,7 @@ struct CPUState {
  bool created;
  bool stop;
  bool stopped;
 +bool exit;
  volatile sig_atomic_t exit_request;
  volatile sig_atomic_t tcg_exit_req;
  uint32_t interrupt_request;
 @@ -489,6 +490,14 @@ void cpu_exit(CPUState *cpu);
  void cpu_resume(CPUState *cpu);
  
  /**
 + * qemu_down_vcpu:
 + * @cpu: The vCPU will to down.
 + *
 + * Down a vCPU.
 + */
 +void qemu_down_vcpu(CPUState *cpu);

The naming and documentation sounds wrong language-wise to me, but I am
not a native speaker either. Maybe tear down instead of down? Or
simply qemu_request_vcpu_removal() or something like that?

 +
 +/**
   * qemu_init_vcpu:
   * @cpu: The vCPU to initialize.
   *
 diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
 index de74411..fd85605 100644
 --- a/include/sysemu/kvm.h
 +++ b/include/sysemu/kvm.h
 @@ -158,6 +158,7 @@ int kvm_has_intx_set_mask(void);
  
  int kvm_init_vcpu(CPUState *cpu);
  int kvm_cpu_exec(CPUState *cpu);
 +int kvm_destroy_vcpu(CPUState *cpu);
  
  #ifdef NEED_CPU_H
  
 diff --git a/kvm-all.c b/kvm-all.c
 index 716860f..fda3601 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -225,6 +225,32 @@ static void kvm_reset_vcpu(void *opaque)
  kvm_arch_reset_vcpu(cpu);
  }
  
 +int kvm_destroy_vcpu(CPUState *cpu)
 +{
 +KVMState *s = kvm_state;
 +long 

Re: [Qemu-devel] [PATCH] kvm: sync cpu state on internal error before dump

2013-08-24 Thread Andreas Färber
Am 24.08.2013 12:37, schrieb Gleb Natapov:
 On Fri, Aug 23, 2013 at 02:41:13PM +0100, James Hogan wrote:
 On 23/08/13 13:58, Gleb Natapov wrote:
 On Fri, Aug 23, 2013 at 01:26:00PM +0100, James Hogan wrote:
 When a KVM internal error occurs QEMU dumps the CPU state, however it
 doesn't synchronise the state from KVM first so the dumped state is out
 of date. Add the synchronisation calls before the dump in both locations
 (which is used depends on whether the arch says to stop or not).

 x86_cpu_dump_state() calls cpu_synchronize_state() already.

 Ah yes, thanks. I hadn't noticed that.

 Out of the arches that support KVM only x86 and ppc call it. arm, mips
 (qemu support not upstream yet), and s390 don't. s390 never seems to
 emit that exit code, and arm only does so for unsupported exceptions
 (which should never happen).

 I'll fix in mips_cpu_dump_state() instead.

 Moving cpu_synchronize_state() up to cpu_dump_state() would be better.

Yes, please. I did not review the hooks themselves much, just avoided
global functions.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH] kvm: warn if num cpus is greater than num recommended

2013-08-22 Thread Andreas Färber
Am 22.08.2013 18:12, schrieb Eduardo Habkost:
 
 On 22/08/2013, at 12:39, Andrew Jones drjo...@redhat.com wrote:
 
 The comment in kvm_max_vcpus() states that it's using the recommended
 procedure from the kernel API documentation to get the max number
 of vcpus that kvm supports. It is, but by always returning the
 maximum number supported. The maximum number should only be used
 for development purposes. qemu should check KVM_CAP_NR_VCPUS for
 the recommended number of vcpus. This patch adds a warning if a user
 specifies a number of cpus between the recommended and max.

 Signed-off-by: Andrew Jones drjo...@redhat.com
 
 CCing libvir-list. It is probably interesting for libvirt to expose or warn 
 about the recommended VCPU limit somehow, and in this case a simple warning 
 on stderr won't be enough.
 
 ---
 kvm-all.c | 45 +++--
 1 file changed, 27 insertions(+), 18 deletions(-)

 diff --git a/kvm-all.c b/kvm-all.c
 index 716860f617455..9092e13ae60ea 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)
 return 0;
 }

 -static int kvm_max_vcpus(KVMState *s)
 +/* Find number of supported CPUs using the recommended
 + * procedure from the kernel API documentation to cope with
 + * older kernels that may be missing capabilities.
 + */
 +static int kvm_recommended_vcpus(KVMState *s)
 {
 int ret;

 -/* Find number of supported CPUs using the recommended
 - * procedure from the kernel API documentation to cope with
 - * older kernels that may be missing capabilities.
 - */
 -ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
 -if (ret) {
 -return ret;
 -}
 ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
 -if (ret) {
 -return ret;
 -}
 +return (ret) ? ret : 4;
 +}

 -return 4;
 +static int kvm_max_vcpus(KVMState *s)
 +{
 +int ret;
 +
 +ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
 +return (ret) ? ret : kvm_recommended_vcpus(s);
 }

 int kvm_init(void)
 @@ -1383,12 +1383,21 @@ int kvm_init(void)
 goto err;
 }

 -max_vcpus = kvm_max_vcpus(s);
 +max_vcpus = kvm_recommended_vcpus(s);
 if (smp_cpus  max_vcpus) {
 -ret = -EINVAL;
 -fprintf(stderr, Number of SMP cpus requested (%d) exceeds max cpus 
 
 -supported by KVM (%d)\n, smp_cpus, max_vcpus);
 -goto err;
 +fprintf(stderr,
 +Warning: Number of SMP cpus requested (%d) exceeds 
 +recommended cpus supported by KVM (%d)\n,
 +smp_cpus, max_vcpus);
 +
 +max_vcpus = kvm_max_vcpus(s);
 +if (smp_cpus  max_vcpus) {
 +ret = -EINVAL;
 +fprintf(stderr, Number of SMP cpus requested (%d) exceeds 
 +max cpus supported by KVM (%d)\n,
 +smp_cpus, max_vcpus);
 +goto err;
 +}

Should at least the fatal one use the new error_report()?

 }

 s-vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);

I notice that only checks in kvm_init() based on smp_cpus are touched
herein. Should we add similar checks to CPU hot-add code and thus
possibly move that into some per-vCPU code path?

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH qom-cpu for-next 1/2] cpu: Use QTAILQ for CPU list

2013-08-21 Thread Andreas Färber
Am 30.07.2013 18:55, schrieb Andreas Färber:
 Introduce CPU_FOREACH(), CPU_FOREACH_SAFE() and CPU_NEXT() shorthand
 macros.
 
 Signed-off-by: Andreas Färber afaer...@suse.de

Needs the following addition now:

diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
index af182da..9d0e27e 100644
--- a/hw/cpu/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
@@ -72,9 +72,15 @@ static int a15mp_priv_init(SysBusDevice *dev)
 /* Wire the outputs from each CPU's generic timer to the
  * appropriate GIC PPI inputs
  */
-for (i = 0, cpu = first_cpu; i  s-num_cpu; i++, cpu =
cpu-next_cpu) {
+i = 0;
+CPU_FOREACH(cpu) {
 DeviceState *cpudev = DEVICE(cpu);
 int ppibase = s-num_irq - 32 + i * 32;
+
+if (i  s-num_cpu) {
+break;
+}
+
 /* physical timer; we wire it up to the non-secure timer's ID,
  * since a real A15 always has TrustZone but QEMU doesn't.
  */
@@ -83,6 +89,7 @@ static int a15mp_priv_init(SysBusDevice *dev)
 /* virtual timer */
 qdev_connect_gpio_out(cpudev, 1,
   qdev_get_gpio_in(s-gic, ppibase + 27));
+i++;
 }

 /* Memory map (addresses are offsets from PERIPHBASE):


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH qom-cpu for-next 1/2] cpu: Use QTAILQ for CPU list

2013-08-21 Thread Andreas Färber
Am 21.08.2013 16:36, schrieb Peter Maydell:
 On 21 August 2013 15:12, Andreas Färber afaer...@suse.de wrote:
 
 -for (i = 0, cpu = first_cpu; i  s-num_cpu; i++, cpu =
 cpu-next_cpu) {
 +i = 0;
 +CPU_FOREACH(cpu) {
  DeviceState *cpudev = DEVICE(cpu);
  int ppibase = s-num_irq - 32 + i * 32;
 +
 +if (i  s-num_cpu) {
 +break;
 +}
 +
  /* physical timer; we wire it up to the non-secure timer's ID,
   * since a real A15 always has TrustZone but QEMU doesn't.
   */
 @@ -83,6 +89,7 @@ static int a15mp_priv_init(SysBusDevice *dev)
  /* virtual timer */
  qdev_connect_gpio_out(cpudev, 1,
qdev_get_gpio_in(s-gic, ppibase + 27));
 +i++;
  }
 
 It seems a bit ugly to have to both enumerate the CPUs
 via CPU_FOREACH and update an index i simultaneously.

Same for the original code. :)

 Isn't there any way to either say give me the CPU pointer for
 CPU i or give me the index i of this CPU ?

There is:

diff --git a/hw/cpu/a15mpcore.c b/hw/cpu/a15mpcore.c
index 9d0e27e..1263b12 100644
--- a/hw/cpu/a15mpcore.c
+++ b/hw/cpu/a15mpcore.c
@@ -50,7 +50,6 @@ static int a15mp_priv_init(SysBusDevice *dev)
 SysBusDevice *busdev;
 const char *gictype = arm_gic;
 int i;
-CPUState *cpu;

 if (kvm_irqchip_in_kernel()) {
 gictype = kvm-arm-gic;
@@ -72,15 +71,10 @@ static int a15mp_priv_init(SysBusDevice *dev)
 /* Wire the outputs from each CPU's generic timer to the
  * appropriate GIC PPI inputs
  */
-i = 0;
-CPU_FOREACH(cpu) {
-DeviceState *cpudev = DEVICE(cpu);
+for (i = 0; i  s-num_cpu; i++) {
+DeviceState *cpudev = DEVICE(qemu_get_cpu(i));
 int ppibase = s-num_irq - 32 + i * 32;

-if (i  s-num_cpu) {
-break;
-}
-
 /* physical timer; we wire it up to the non-secure timer's ID,
  * since a real A15 always has TrustZone but QEMU doesn't.
  */
@@ -89,7 +83,6 @@ static int a15mp_priv_init(SysBusDevice *dev)
 /* virtual timer */
 qdev_connect_gpio_out(cpudev, 1,
   qdev_get_gpio_in(s-gic, ppibase + 27));
-i++;
 }

 /* Memory map (addresses are offsets from PERIPHBASE):


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] Cross-Platform KVM

2013-08-21 Thread Andreas Färber
Hi,

Am 16.08.2013 09:41, schrieb Wincy Van:
 Hi,there:
 
I have implemented a version of cross-platform KVM. Now, it can
 works on Linux and Windows(kernel version 7600-9200, amd64). Is it
 useful? If so, I want make it as a branch of current KVM. Here are some
 screenshots:

Let's CC the KVM mailing list.

More telling than screenshots would be some info about your code! Is
there a public Git repository to look at? Is it based on a current
kvm.git or some older Win32 KVM fork on SourceForge? If so, how invasive
are your changes? Or is it a clean-room implementation of your own
against the header/ioctl interface? How does it work technically? etc.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH] qemu-kvm bugfix for IA32_FEATURE_CONTROL

2013-08-19 Thread Andreas Färber
Am 19.08.2013 16:31, schrieb Liu, Jinsong:
 Paolo Bonzini wrote:

 The patch looks good.  Please repost it with checkpatch.pl failures
 fixed. 

 Paolo
 
 Thanks Stefan and Paolo! Updated patch attached.
 
 Regards,
 Jinsong
 
 ===
 From a0ddf948d40e42de862543157a5668a1c12faae6 Mon Sep 17 00:00:00 2001
 From: Liu Jinsong jinsong@intel.com
 Date: Mon, 19 Aug 2013 09:33:30 +0800
 Subject: [PATCH] qemu-kvm bugfix for IA32_FEATURE_CONTROL
 
 This patch is to fix the bug https://bugs.launchpad.net/qemu-kvm/+bug/1207623
 
 IA32_FEATURE_CONTROL is pointless if not expose VMX or SMX bits to
 cpuid.1.ecx of vcpu. Current qemu-kvm will error return when kvm_put_msrs
 or kvm_get_msrs.
 
 Signed-off-by: Liu Jinsong jinsong@intel.com

Jinsong, if this is for upstream QEMU, then the commit message needs
some small improvements:

qemu-kvm is no longer maintained since 1.3 so it should not be occurring
any more.

Please use a prefix of target-i386:  (the directory name) to signal
where you are changing code, i.e. x86 only.

bugfix is not a very telling description of what a patch is doing.

(Up to Paolo and Gleb whether they'll fix it or whether they require a
resend.)

Also please use git-send-email to submit patches and use PATCH v2 etc.
for submission as top-level patch:
http://wiki.qemu.org/Contribute/SubmitAPatch

One question inline...

 ---
  target-i386/kvm.c |   17 +++--
  1 files changed, 15 insertions(+), 2 deletions(-)
 
 diff --git a/target-i386/kvm.c b/target-i386/kvm.c
 index 84ac00a..5adeb03 100644
 --- a/target-i386/kvm.c
 +++ b/target-i386/kvm.c
 @@ -65,6 +65,7 @@ static bool has_msr_star;
  static bool has_msr_hsave_pa;
  static bool has_msr_tsc_adjust;
  static bool has_msr_tsc_deadline;
 +static bool has_msr_feature_control;
  static bool has_msr_async_pf_en;
  static bool has_msr_pv_eoi_en;
  static bool has_msr_misc_enable;
 @@ -644,6 +645,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
  
  qemu_add_vm_change_state_handler(cpu_update_state, env);
  
 +c = cpuid_find_entry(cpuid_data.cpuid, 1, 0);
 +if (c) {
 +has_msr_feature_control = !!(c-ecx  CPUID_EXT_VMX) ||
 +  !!(c-ecx  CPUID_EXT_SMX);
 +}
 +
  cpuid_data.cpuid.padding = 0;
  r = kvm_vcpu_ioctl(cs, KVM_SET_CPUID2, cpuid_data);
  if (r) {
 @@ -1121,7 +1128,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
  if (hyperv_vapic_recommended()) {
  kvm_msr_entry_set(msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
  }
 -kvm_msr_entry_set(msrs[n++], MSR_IA32_FEATURE_CONTROL, 
 env-msr_ia32_feature_control);
 +if (has_msr_feature_control) {
 +kvm_msr_entry_set(msrs[n++], MSR_IA32_FEATURE_CONTROL,
 +  env-msr_ia32_feature_control);
 +}
  }
  if (env-mcg_cap) {
  int i;
 @@ -1346,7 +1356,9 @@ static int kvm_get_msrs(X86CPU *cpu)
  if (has_msr_misc_enable) {
  msrs[n++].index = MSR_IA32_MISC_ENABLE;
  }
 -msrs[n++].index = MSR_IA32_FEATURE_CONTROL;
 +if (has_msr_feature_control) {
 +msrs[n++].index = MSR_IA32_FEATURE_CONTROL;
 +}
  
  if (!env-tsc_valid) {
  msrs[n++].index = MSR_IA32_TSC;
 @@ -1447,6 +1459,7 @@ static int kvm_get_msrs(X86CPU *cpu)
  break;
  case MSR_IA32_FEATURE_CONTROL:
  env-msr_ia32_feature_control = msrs[i].data;
 +break;

Was the fallthrough previously intended? Or is this a second,
unmentioned bugfix?

Regards,
Andreas

  default:
  if (msrs[i].index = MSR_MC0_CTL 
  msrs[i].index  MSR_MC0_CTL + (env-mcg_cap  0xff) * 4) {
 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 5/6] target-i386: Move hyperv_* static globals to X86CPU

2013-08-16 Thread Andreas Färber
From: Igor Mammedov imamm...@redhat.com

- since hyperv_* helper functions are used only in target-i386/kvm.c
  move them there as static helpers

Requested-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-i386/Makefile.objs |  2 +-
 target-i386/cpu-qom.h |  4 +++
 target-i386/cpu.c | 16 
 target-i386/cpu.h |  4 +++
 target-i386/hyperv.c  | 64 ---
 target-i386/hyperv.h  | 45 -
 target-i386/kvm.c | 36 ++
 7 files changed, 46 insertions(+), 125 deletions(-)
 delete mode 100644 target-i386/hyperv.c
 delete mode 100644 target-i386/hyperv.h

diff --git a/target-i386/Makefile.objs b/target-i386/Makefile.objs
index 3b629d4d..da1fc40 100644
--- a/target-i386/Makefile.objs
+++ b/target-i386/Makefile.objs
@@ -3,7 +3,7 @@ obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o 
svm_helper.o
 obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o
-obj-$(CONFIG_KVM) += kvm.o hyperv.o
+obj-$(CONFIG_KVM) += kvm.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-$(CONFIG_LINUX_USER) += ioport-user.o
 obj-$(CONFIG_BSD_USER) += ioport-user.o
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 53b4c34..c4447c2 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -66,6 +66,10 @@ typedef struct X86CPU {
 
 CPUX86State env;
 
+bool hyperv_vapic;
+bool hyperv_relaxed_timing;
+int hyperv_spinlock_attempts;
+
 /* Features that were filtered out because of missing host capabilities */
 uint32_t filtered_features[FEATURE_WORDS];
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 2efbeca..6e38252 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -35,8 +35,6 @@
 #include qapi/visitor.h
 #include sysemu/arch_init.h
 
-#include hyperv.h
-
 #include hw/hw.h
 #if defined(CONFIG_KVM)
 #include linux/kvm_para.h
@@ -1591,12 +1589,19 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char 
*features, Error **errp)
 object_property_parse(OBJECT(cpu), num, tsc-frequency, errp);
 } else if (!strcmp(featurestr, hv-spinlocks)) {
 char *err;
+const int min = 0xFFF;
 numvalue = strtoul(val, err, 0);
 if (!*val || *err) {
 error_setg(errp, bad numerical value %s, val);
 goto out;
 }
-hyperv_set_spinlock_retries(numvalue);
+if (numvalue  min) {
+fprintf(stderr, hv-spinlocks value shall always be = 
0x%x
+, fixup will be removed in future versions\n,
+min);
+numvalue = min;
+}
+cpu-hyperv_spinlock_attempts = numvalue;
 } else {
 error_setg(errp, unrecognized feature %s, featurestr);
 goto out;
@@ -1606,9 +1611,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char 
*features, Error **errp)
 } else if (!strcmp(featurestr, enforce)) {
 check_cpuid = enforce_cpuid = 1;
 } else if (!strcmp(featurestr, hv_relaxed)) {
-hyperv_enable_relaxed_timing(true);
+cpu-hyperv_relaxed_timing = true;
 } else if (!strcmp(featurestr, hv_vapic)) {
-hyperv_enable_vapic_recommended(true);
+cpu-hyperv_vapic = true;
 } else {
 error_setg(errp, feature string `%s' not in format (+feature|
-feature|feature=xyz), featurestr);
@@ -2489,6 +2494,7 @@ static void x86_cpu_initfn(Object *obj)
 x86_cpu_get_feature_words,
 NULL, NULL, (void *)cpu-filtered_features, NULL);
 
+cpu-hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
 env-cpuid_apic_id = x86_cpu_apic_id_from_index(cs-cpu_index);
 
 /* init various static tables used in TCG mode */
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index cedefdc..8a3d0fd 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -549,6 +549,10 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
+#ifndef HYPERV_SPINLOCK_NEVER_RETRY
+#define HYPERV_SPINLOCK_NEVER_RETRY 0x
+#endif
+
 #define EXCP00_DIVZ0
 #define EXCP01_DB  1
 #define EXCP02_NMI 2
diff --git a/target-i386/hyperv.c b/target-i386/hyperv.c
deleted file mode 100644
index f284e99..000
--- a/target-i386/hyperv.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * QEMU Hyper-V support
- *
- * Copyright Red Hat, Inc. 2011
- *
- * Author: Vadim Rozenfeld vroze...@redhat.com

Re: [Qemu-devel] [PATCH uq/master] kvm: Simplify kvm_handle_io

2013-08-13 Thread Andreas Färber
Am 13.08.2013 14:43, schrieb Jan Kiszka:
 Now that cpu_in/out is just a wrapper around address_space_rw, we can
 also call the latter directly. As host endianness == guest endianness,
 there is no need for the memory access helpers st*_p/ld*_p as well.
 
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
  kvm-all.c |   28 ++--
  1 files changed, 2 insertions(+), 26 deletions(-)

Looks sensible,

Reviewed-by: Andreas Färber afaer...@suse.de

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] -cpu host (was Re: KVM call minutes for 2013-08-06)

2013-08-09 Thread Andreas Färber
Am 09.08.2013 15:12, schrieb Peter Maydell:
 possibly add support
for -cpu host,+32bitvm style syntax.

Please use only property-name=value style syntax.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] -cpu host (was Re: KVM call minutes for 2013-08-06)

2013-08-08 Thread Andreas Färber
Hi Peter,

Am 08.08.2013 14:51, schrieb Peter Maydell:
 [I missed this KVM call but the stuff about -cpu host ties into
 an issue we've been grappling with for ARM KVM, so it seems
 a reasonable jumping-off-point.]
 
 On 6 August 2013 16:15, Juan Quintela quint...@redhat.com wrote:
 2013-08-06
 --

 What libvirt needs/miss Today?
 - how to handle machine types? creating them inside qemu?
 - qemu --cpu help
   only shows cpus,  not what features qemu will use
 - qemu -cpu host
   what does this exactly means?  kvm removes same flags.
 - Important to know if migration would work.
 - Machine types sometimes disable some feature, so cpu alone is not
   enough.
 
 - kernel removes some features because it knows it can't be virtualised
 - qemu adds some others because it knows it don't need host support
 - and then lots of features in the middle
 
 So, coming at this from an ARM perspective:
 Should any target arch that supports KVM also support -cpu host?
 If so, what should it do?

I think that depends on the target and whether/what is useful.

 Is there a description somewhere of
 what the x86 and PPC semantics of -cpu host are?

I'm afraid our usual documentation will be reading the source code. ;)

x86 was first to implement -cpu host and passed through pretty much all
host features even if they would not work without additional support
code. I've seen a bunch of bugs where that leads to GMP and others
breaking badly. Lately in the case of PMU we've started to limit that.
Alex proposed -cpu best, which was never merged to date. It was similar
to how ppc's -cpu host works:

ppc matches the Processor Version Register (PVR) in kvm.c against its
known models from cpu-models.c (strictly today, mask being discussed).
The PVR can be read from userspace via mfpvr alias to mfspr (Move From
Special Purpose Register; possibly emulated for userspace by kernel?).
CPU features are all QEMU-driven AFAIU, through the CPU families in
translate_init.c. Beware, everything is highly macro'fied in ppc code.

 For ARM you can't get at feature info of the host from userspace
 (unless you want to get into parsing /proc/cpuinfo), so my current
 idea is to have KVM_ARM_VCPU_INIT support a target-cpu-type
 which means whatever host CPU is. Then when we've created the
 vcpu we can populate QEMU's idea of what the CPU features are
 by using the existing ioctls for reading the cp15 registers of
 the vcpu.

Sounds sane to me iff those cp15 registers all work with KVM and don't
need any additional KVM/QEMU/device code.

 The other unresolved thing is what -cpu host ought to mean
 for the CPU's on-chip peripherals (of which the major one is
 the interrupt controller) -- if the host is an A57 should
 this imply that you always get the A57's GICv3, or is it OK
 to provide an A57 with a GICv2? At the moment QEMU models the
 per-cpu peripherals in a somewhat more semi-detached fashion
 than is the case in silicon, treating them as more a part
 of the board model than of the cpu itself.

Feel free to submit patches changing that. Prerequisite should then be
to have those devices be pure TYPE_DEVICE rather than
TYPE_SYS_BUS_DEVICE, or otherwise you'll run into the same hot-plug trap
as we did with the x86 APIC (we had to invent a hotpluggable ICC bus as
interim solution).

 Having '-cpu host'
 not affect them might be the pragmatic choice, since it fits
 with what QEMU currently does and with kernel-side situations
 where the host CPU may only be able to show the guest VM a
 GICv2 view of the world (or only a GICv3, as the case may be).
 For this to work it does require that guests figure out what
 their per-cpu peripherals are by looking at the device tree
 rather than saying oh, this is an A57, I know all A57s
 have this, of course...

Without directly answering the question and continuing from above, my
personal view has been that we need to get away from the current CPU
model to a) how hardware is structured and b) how we want to have things
behave in virtualized environments.

Take x86 as an example: CPUState corresponds to a hyperthread today, but
we want hotplug to work like it does on a physical machine: hot-adding
on socket-level only. Beyond just building the topology with Container
objects, that means having a Xeon-X5-4242 object that has-a CPU core
has-a CPU thread and any devices the particular layers bring along.

For SoCs I have been proposing - for sh7750 and lately tegra2 - to model
the black chip on the board as a TYPE_DEVICE for encapsulation across
boards. Meaning the GIC would no longer be instantiated on the board but
as part of an object, and -smp and -cpu would as a consequence loose in
influence.

We could interpret -cpu host as instantiate the host's SoC object. But
the mainstream SoC for KVM virtualization is exynos5, and no one sat
down to model exynos5 in QEMU so far, so that would be moot. Versatile
Express is rather unlikely to match the host environment KVM is used in,
and when using Soft Macros (or what 

Re: [Qemu-devel] vm performance degradation after kvm live migration or save-restore with EPT enabled

2013-08-05 Thread Andreas Färber
Hi,

Am 05.08.2013 11:09, schrieb Zhanghaoyu (A):
 When I build the upstream, encounter a problem that I compile and install the 
 upstream(commit: e769ece3b129698d2b09811a6f6d304e4eaa8c29) on sles11sp2 
 environment via below command
 cp /boot/config-3.0.13-0.27-default ./.config
 yes  | make oldconfig
 make  make modules_install  make install
 then, I reboot the host, and select the upstream kernel, but during the 
 starting stage, below problem happened,
 Could not find /dev/disk/by-id/scsi-3600508e0864407c5b8f7ad01-part3 
 
 I'm trying to resolve it.

Possibly you need to enable loading unsupported kernel modules?
At least that's needed when testing a kmod with a SUSE kernel.

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu for-next 1/2] cpu: Use QTAILQ for CPU list

2013-07-30 Thread Andreas Färber
Introduce CPU_FOREACH(), CPU_FOREACH_SAFE() and CPU_NEXT() shorthand
macros.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c| 47 ---
 cputlb.c  |  2 +-
 dump.c| 10 +-
 exec.c| 26 ++
 gdbstub.c | 14 +++---
 hw/arm/boot.c |  2 +-
 hw/i386/kvm/clock.c   |  2 +-
 hw/i386/kvmvapic.c|  2 +-
 hw/i386/pc.c  |  3 +--
 hw/ppc/e500.c |  2 +-
 hw/ppc/ppc.c  |  2 +-
 hw/ppc/spapr.c|  4 ++--
 include/qom/cpu.h | 11 +--
 kvm-all.c |  8 
 linux-user/elfload.c  |  2 +-
 linux-user/main.c | 10 +++---
 linux-user/syscall.c  | 17 ++---
 memory_mapping.c  |  5 +++--
 monitor.c |  2 +-
 target-i386/helper.c  |  3 +--
 target-i386/misc_helper.c |  2 +-
 target-mips/op_helper.c   | 10 --
 target-ppc/excp_helper.c  |  2 +-
 translate-all.c   |  4 ++--
 24 files changed, 87 insertions(+), 105 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f65e76..1e2fd8a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -81,7 +81,7 @@ static bool all_cpu_threads_idle(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 if (!cpu_thread_is_idle(cpu)) {
 return false;
 }
@@ -394,7 +394,7 @@ void hw_error(const char *fmt, ...)
 fprintf(stderr, qemu: hardware error: );
 vfprintf(stderr, fmt, ap);
 fprintf(stderr, \n);
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 fprintf(stderr, CPU #%d:\n, cpu-cpu_index);
 cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_FPU);
 }
@@ -406,7 +406,7 @@ void cpu_synchronize_all_states(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_state(cpu);
 }
 }
@@ -415,7 +415,7 @@ void cpu_synchronize_all_post_reset(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_post_reset(cpu);
 }
 }
@@ -424,7 +424,7 @@ void cpu_synchronize_all_post_init(void)
 {
 CPUState *cpu;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 cpu_synchronize_post_init(cpu);
 }
 }
@@ -743,7 +743,7 @@ static void qemu_tcg_wait_io_event(void)
 qemu_cond_wait(qemu_io_proceeded_cond, qemu_global_mutex);
 }
 
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 qemu_wait_io_event_common(cpu);
 }
 }
@@ -855,11 +855,11 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 qemu_cond_signal(qemu_cpu_cond);
 
 /* wait for initial kick-off after machine start */
-while (first_cpu-stopped) {
+while (QTAILQ_FIRST(cpus)-stopped) {
 qemu_cond_wait(tcg_halt_cond, qemu_global_mutex);
 
 /* process any pending work */
-for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
+CPU_FOREACH(cpu) {
 qemu_wait_io_event_common(cpu);
 }
 }
@@ -969,13 +969,12 @@ void qemu_mutex_unlock_iothread(void)
 
 static int all_vcpus_paused(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
-while (cpu) {
+CPU_FOREACH(cpu) {
 if (!cpu-stopped) {
 return 0;
 }
-cpu = cpu-next_cpu;
 }
 
 return 1;
@@ -983,23 +982,20 @@ static int all_vcpus_paused(void)
 
 void pause_all_vcpus(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
 qemu_clock_enable(vm_clock, false);
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu-stop = true;
 qemu_cpu_kick(cpu);
-cpu = cpu-next_cpu;
 }
 
 if (qemu_in_vcpu_thread()) {
 cpu_stop_current();
 if (!kvm_enabled()) {
-cpu = first_cpu;
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu-stop = false;
 cpu-stopped = true;
-cpu = cpu-next_cpu;
 }
 return;
 }
@@ -1007,10 +1003,8 @@ void pause_all_vcpus(void)
 
 while (!all_vcpus_paused()) {
 qemu_cond_wait(qemu_pause_cond, qemu_global_mutex);
-cpu = first_cpu;
-while (cpu) {
+CPU_FOREACH(cpu) {
 qemu_cpu_kick(cpu);
-cpu = cpu-next_cpu;
 }
 }
 }
@@ -1024,12 +1018,11 @@ void cpu_resume(CPUState *cpu)
 
 void resume_all_vcpus(void)
 {
-CPUState *cpu = first_cpu;
+CPUState *cpu;
 
 qemu_clock_enable(vm_clock, true);
-while (cpu) {
+CPU_FOREACH(cpu) {
 cpu_resume(cpu);
-cpu = cpu-next_cpu;
 }
 }
 
@@ -1181,7 +1174,7 @@ static void tcg_exec_all(void)
 if (next_cpu == NULL) {
 next_cpu = first_cpu;
 }
-for (; next_cpu

Re: [Qemu-devel] [PATCH qom-cpu v9] target-i386: Move hyperv_* static globals to X86CPU

2013-07-28 Thread Andreas Färber
Am 08.07.2013 14:40, schrieb Igor Mammedov:
 On Mon,  8 Jul 2013 03:03:54 +0200
 Andreas Färber afaer...@suse.de wrote:
 
 From: Igor Mammedov imamm...@redhat.com

 - since hyperv_* helper functions are used only in target-i386/kvm.c
   move them there as static helpers

 Requested-by: Eduardo Habkost ehabk...@redhat.com
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 I'm not tested it yet, but it looks good to me.

Being from you originally and me having confidence in my changes on top,
I'm queuing this on qom-cpu-next:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next

Andreas

 ---
  v8 (imammedo) - v9:
  * Use X86CPU instead of CPUX86State (only used in KVM)
  * Changed helper functions to X86CPU argument
  * Moved field initialization to QOM instance_init
  * Fixed subject (not today's CPUState)

  target-i386/Makefile.objs |  2 +-
  target-i386/cpu-qom.h |  4 +++
  target-i386/cpu.c | 16 
  target-i386/cpu.h |  4 +++
  target-i386/hyperv.c  | 64 
 ---
  target-i386/hyperv.h  | 45 -
  target-i386/kvm.c | 36 ++
  7 files changed, 46 insertions(+), 125 deletions(-)
  delete mode 100644 target-i386/hyperv.c
  delete mode 100644 target-i386/hyperv.h

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 03/25] target-s390x: Fix CPUState rework fallout

2013-07-26 Thread Andreas Färber
From: Christian Borntraeger borntrae...@de.ibm.com

Commit f17ec444c3d39f76bcd8b71c2c05d5754bfe333e
exec: Change cpu_memory_rw_debug() argument to CPUState

missed to update s390x KVM code, breaking the build.

Let's fix it up.

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-s390x/kvm.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 60e94f8..85f0112 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -345,12 +345,10 @@ void *kvm_arch_ram_alloc(ram_addr_t size)
 
 int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
 {
-S390CPU *cpu = S390_CPU(cs);
-CPUS390XState *env = cpu-env;
 static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01};
 
-if (cpu_memory_rw_debug(env, bp-pc, (uint8_t *)bp-saved_insn, 4, 0) ||
-cpu_memory_rw_debug(env, bp-pc, (uint8_t *)diag_501, 4, 1)) {
+if (cpu_memory_rw_debug(cs, bp-pc, (uint8_t *)bp-saved_insn, 4, 0) ||
+cpu_memory_rw_debug(cs, bp-pc, (uint8_t *)diag_501, 4, 1)) {
 return -EINVAL;
 }
 return 0;
@@ -358,16 +356,14 @@ int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct 
kvm_sw_breakpoint *bp)
 
 int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
 {
-S390CPU *cpu = S390_CPU(cs);
-CPUS390XState *env = cpu-env;
 uint8_t t[4];
 static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01};
 
-if (cpu_memory_rw_debug(env, bp-pc, t, 4, 0)) {
+if (cpu_memory_rw_debug(cs, bp-pc, t, 4, 0)) {
 return -EINVAL;
 } else if (memcmp(t, diag_501, 4)) {
 return -EINVAL;
-} else if (cpu_memory_rw_debug(env, bp-pc, (uint8_t *)bp-saved_insn, 1, 
1)) {
+} else if (cpu_memory_rw_debug(cs, bp-pc, (uint8_t *)bp-saved_insn, 1, 
1)) {
 return -EINVAL;
 }
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 02/25] kvm: Change prototype of kvm_update_guest_debug()

2013-07-26 Thread Andreas Färber
From: Stefan Weil s...@weilnetz.de

Passing a CPUState pointer instead of a CPUArchState pointer eliminates
the last target dependent data type in sysemu/kvm.h.

It also simplifies the code.

Signed-off-by: Stefan Weil s...@weilnetz.de
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 exec.c   |  5 ++---
 include/sysemu/kvm.h |  2 +-
 kvm-all.c| 17 +
 kvm-stub.c   |  2 +-
 target-i386/kvm.c|  2 +-
 5 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/exec.c b/exec.c
index 3ba9525..c4f2894 100644
--- a/exec.c
+++ b/exec.c
@@ -590,15 +590,14 @@ void cpu_breakpoint_remove_all(CPUArchState *env, int 
mask)
 void cpu_single_step(CPUState *cpu, int enabled)
 {
 #if defined(TARGET_HAS_ICE)
-CPUArchState *env = cpu-env_ptr;
-
 if (cpu-singlestep_enabled != enabled) {
 cpu-singlestep_enabled = enabled;
 if (kvm_enabled()) {
-kvm_update_guest_debug(env, 0);
+kvm_update_guest_debug(cpu, 0);
 } else {
 /* must flush all the translated code to avoid inconsistencies */
 /* XXX: only flush what is necessary */
+CPUArchState *env = cpu-env_ptr;
 tb_flush(env);
 }
 }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index f8ac448..de74411 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -174,7 +174,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
 int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
 void kvm_remove_all_breakpoints(CPUState *cpu);
-int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
+int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap);
 #ifndef _WIN32
 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
 #endif
diff --git a/kvm-all.c b/kvm-all.c
index 4fb4ccb..716860f 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1883,9 +1883,8 @@ static void kvm_invoke_set_guest_debug(void *data)
dbg_data-dbg);
 }
 
-int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap)
+int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_set_guest_debug_data data;
 
 data.dbg.control = reinject_trap;
@@ -1935,9 +1934,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong 
addr,
 }
 
 for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
-CPUArchState *env = cpu-env_ptr;
-
-err = kvm_update_guest_debug(env, 0);
+err = kvm_update_guest_debug(cpu, 0);
 if (err) {
 return err;
 }
@@ -1977,9 +1974,7 @@ int kvm_remove_breakpoint(CPUState *cpu, target_ulong 
addr,
 }
 
 for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
-CPUArchState *env = cpu-env_ptr;
-
-err = kvm_update_guest_debug(env, 0);
+err = kvm_update_guest_debug(cpu, 0);
 if (err) {
 return err;
 }
@@ -2007,15 +2002,13 @@ void kvm_remove_all_breakpoints(CPUState *cpu)
 kvm_arch_remove_all_hw_breakpoints();
 
 for (cpu = first_cpu; cpu != NULL; cpu = cpu-next_cpu) {
-CPUArchState *env = cpu-env_ptr;
-
-kvm_update_guest_debug(env, 0);
+kvm_update_guest_debug(cpu, 0);
 }
 }
 
 #else /* !KVM_CAP_SET_GUEST_DEBUG */
 
-int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap)
+int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
 {
 return -EINVAL;
 }
diff --git a/kvm-stub.c b/kvm-stub.c
index 7b2233a..771360b 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -78,7 +78,7 @@ void kvm_setup_guest_memory(void *start, size_t size)
 {
 }
 
-int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap)
+int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
 {
 return -ENOSYS;
 }
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 3c9d10a..376fc70 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1618,7 +1618,7 @@ static int kvm_guest_debug_workarounds(X86CPU *cpu)
  */
 if (reinject_trap ||
 (!kvm_has_robust_singlestep()  cs-singlestep_enabled)) {
-ret = kvm_update_guest_debug(env, reinject_trap);
+ret = kvm_update_guest_debug(cs, reinject_trap);
 }
 return ret;
 }
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 19/24] exec: Change cpu_memory_rw_debug() argument to CPUState

2013-07-22 Thread Andreas Färber
Propagate X86CPU in kvmvapic for simplicity.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c  |  4 +--
 disas.c |  4 +--
 exec.c  |  6 ++--
 gdbstub.c   |  2 +-
 hw/i386/kvmvapic.c  | 72 +++--
 include/exec/cpu-all.h  |  3 +-
 include/exec/softmmu-semi.h | 18 +++-
 monitor.c   |  2 +-
 target-arm/arm-semi.c   |  2 +-
 target-i386/helper.c|  8 +++--
 target-i386/kvm.c   | 14 -
 target-sparc/mmu_helper.c   |  5 ++--
 target-xtensa/xtensa-semi.c | 10 +++
 13 files changed, 77 insertions(+), 73 deletions(-)

diff --git a/cpus.c b/cpus.c
index 4549b7a..ca6b886 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1285,7 +1285,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 {
 FILE *f;
 uint32_t l;
-CPUArchState *env;
 CPUState *cpu;
 uint8_t buf[1024];
 
@@ -1299,7 +1298,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
   a CPU number);
 return;
 }
-env = cpu-env_ptr;
 
 f = fopen(filename, wb);
 if (!f) {
@@ -1311,7 +1309,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 l = sizeof(buf);
 if (l  size)
 l = size;
-cpu_memory_rw_debug(env, addr, buf, l, 0);
+cpu_memory_rw_debug(cpu, addr, buf, l, 0);
 if (fwrite(buf, 1, l, f) != l) {
 error_set(errp, QERR_IO_ERROR);
 goto exit;
diff --git a/disas.c b/disas.c
index e51127e..71007fb 100644
--- a/disas.c
+++ b/disas.c
@@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr,
 {
 CPUDebug *s = container_of(info, CPUDebug, info);
 
-cpu_memory_rw_debug(s-env, memaddr, myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 return 0;
 }
 
@@ -392,7 +392,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int 
length,
 if (monitor_disas_is_physical) {
 cpu_physical_memory_read(memaddr, myaddr, length);
 } else {
-cpu_memory_rw_debug(s-env, memaddr,myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 }
 return 0;
 }
diff --git a/exec.c b/exec.c
index a491af7..7997002 100644
--- a/exec.c
+++ b/exec.c
@@ -1835,7 +1835,7 @@ MemoryRegion *get_system_io(void)
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l, flags;
@@ -2606,7 +2606,7 @@ void stq_be_phys(hwaddr addr, uint64_t val)
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l;
@@ -2615,7 +2615,7 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong 
addr,
 
 while (len  0) {
 page = addr  TARGET_PAGE_MASK;
-phys_addr = cpu_get_phys_page_debug(ENV_GET_CPU(env), page);
+phys_addr = cpu_get_phys_page_debug(cpu, page);
 /* if no physical page mapped, return an error */
 if (phys_addr == -1)
 return -1;
diff --git a/gdbstub.c b/gdbstub.c
index 848754d..6cefb17 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -46,7 +46,7 @@
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
  uint8_t *buf, int len, int is_write)
 {
-return cpu_memory_rw_debug(env, addr, buf, len, is_write);
+return cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, len, is_write);
 }
 #else
 /* target_memory_rw_debug() defined in cpu.h */
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 224601f..035d0fe 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -188,9 +188,10 @@ static bool opcode_matches(uint8_t *opcode, const 
TPRInstruction *instr)
  modrm_reg(opcode[1]) == instr-modrm_reg);
 }
 
-static int evaluate_tpr_instruction(VAPICROMState *s, CPUX86State *env,
+static int evaluate_tpr_instruction(VAPICROMState *s, X86CPU *cpu,
 target_ulong *pip, TPRAccess access)
 {
+CPUState *cs = CPU(cpu);
 const TPRInstruction *instr;
 target_ulong ip = *pip;
 uint8_t opcode[2];
@@ -211,7 +212,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
  * RSP, used by the patched instruction, is zero, so the guest gets a
  * double fault and dies.
  */
-if (env-regs[R_ESP] == 0) {
+if (cpu-env.regs[R_ESP] == 0) {
 return -1;
 }
 
@@ -226,7 +227,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
 if (instr

[PULL 14/24] kvm: Change kvm_{insert,remove}_breakpoint() argument to CPUState

2013-07-22 Thread Andreas Färber
CPUArchState is no longer directly used since converting CPU loops to
CPUState.

Prepares for changing GDBState::c_cpu to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 12 
 include/sysemu/kvm.h |  4 ++--
 kvm-all.c| 10 --
 kvm-stub.c   |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 8e23509..b5e6778 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1954,8 +1954,10 @@ static int gdb_breakpoint_insert(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_insert_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_insert_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
@@ -1991,8 +1993,10 @@ static int gdb_breakpoint_remove(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_remove_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_remove_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 1e08a85..f8ac448 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -169,9 +169,9 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
 void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
diff --git a/kvm-all.c b/kvm-all.c
index a210389..4fb4ccb 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1900,10 +1900,9 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -1946,10 +1945,9 @@ int kvm_insert_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -2022,13 +2020,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return -EINVAL;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
diff --git a/kvm-stub.c b/kvm-stub.c
index 370c837..7b2233a 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -83,13 +83,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned long 
reinject_trap)
 return -ENOSYS;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 11/24] cpu: Move singlestep_enabled field from CPU_COMMON to CPUState

2013-07-22 Thread Andreas Färber
Prepares for changing cpu_single_step() argument to CPUState.

Acked-by: Michael Walle mich...@walle.cc (for lm32)
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c|  2 +-
 cpus.c|  2 +-
 exec.c| 10 ++
 include/exec/cpu-defs.h   |  1 -
 include/qom/cpu.h |  2 ++
 kvm-all.c |  2 +-
 target-alpha/translate.c  |  3 ++-
 target-arm/translate.c|  7 ---
 target-cris/translate.c   |  7 ---
 target-i386/kvm.c |  6 --
 target-i386/translate.c   |  5 +++--
 target-lm32/translate.c   |  7 ---
 target-m68k/translate.c   |  7 ---
 target-microblaze/translate.c |  8 +---
 target-mips/translate.c   | 11 +++
 target-moxie/translate.c  |  5 +++--
 target-openrisc/translate.c   |  7 ---
 target-ppc/translate.c|  8 +---
 target-s390x/translate.c  |  5 +++--
 target-sh4/translate.c|  8 +---
 target-sparc/translate.c  |  3 ++-
 target-unicore32/translate.c  |  7 ---
 target-xtensa/translate.c |  7 ---
 23 files changed, 78 insertions(+), 52 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 3fccb86..301be28 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -297,7 +297,7 @@ int cpu_exec(CPUArchState *env)
 for(;;) {
 interrupt_request = cpu-interrupt_request;
 if (unlikely(interrupt_request)) {
-if (unlikely(env-singlestep_enabled  SSTEP_NOIRQ)) {
+if (unlikely(cpu-singlestep_enabled  SSTEP_NOIRQ)) {
 /* Mask out external interrupts for this step. */
 interrupt_request = ~CPU_INTERRUPT_SSTEP_MASK;
 }
diff --git a/cpus.c b/cpus.c
index 2509eb5..4549b7a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1186,7 +1186,7 @@ static void tcg_exec_all(void)
 CPUArchState *env = cpu-env_ptr;
 
 qemu_clock_enable(vm_clock,
-  (env-singlestep_enabled  SSTEP_NOTIMER) == 0);
+  (cpu-singlestep_enabled  SSTEP_NOTIMER) == 0);
 
 if (cpu_can_run(cpu)) {
 r = tcg_cpu_exec(env);
diff --git a/exec.c b/exec.c
index c8658c6..30b676d 100644
--- a/exec.c
+++ b/exec.c
@@ -588,11 +588,13 @@ void cpu_breakpoint_remove_all(CPUArchState *env, int 
mask)
 void cpu_single_step(CPUArchState *env, int enabled)
 {
 #if defined(TARGET_HAS_ICE)
-if (env-singlestep_enabled != enabled) {
-env-singlestep_enabled = enabled;
-if (kvm_enabled())
+CPUState *cpu = ENV_GET_CPU(env);
+
+if (cpu-singlestep_enabled != enabled) {
+cpu-singlestep_enabled = enabled;
+if (kvm_enabled()) {
 kvm_update_guest_debug(env, 0);
-else {
+} else {
 /* must flush all the translated code to avoid inconsistencies */
 /* XXX: only flush what is necessary */
 tb_flush(env);
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 39094b3..12b1ca7 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -170,7 +170,6 @@ typedef struct CPUWatchpoint {
 /* from this point: preserved by CPU reset */   \
 /* ice debug support */ \
 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;\
-int singlestep_enabled; \
 \
 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;\
 CPUWatchpoint *watchpoint_hit;  \
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 4e5ec77..94302a4 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -133,6 +133,7 @@ struct kvm_run;
  * @stopped: Indicates the CPU has been artificially stopped.
  * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
  *   CPU and return to its top level loop.
+ * @singlestep_enabled: Flags for single-stepping.
  * @env_ptr: Pointer to subclass-specific CPUArchState field.
  * @current_tb: Currently executing TB.
  * @next_cpu: Next CPU sharing TB cache.
@@ -165,6 +166,7 @@ struct CPUState {
 volatile sig_atomic_t exit_request;
 volatile sig_atomic_t tcg_exit_req;
 uint32_t interrupt_request;
+int singlestep_enabled;
 
 void *env_ptr; /* CPUArchState */
 struct TranslationBlock *current_tb;
diff --git a/kvm-all.c b/kvm-all.c
index 232c39a..a210389 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1890,7 +1890,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 
 data.dbg.control = reinject_trap;
 
-if (env-singlestep_enabled) {
+if (cpu-singlestep_enabled) {
 data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
 }
 kvm_arch_update_guest_debug(cpu

Re: [Qemu-devel] [PULL 09/43] cpu: Make first_cpu and next_cpu CPUState

2013-07-11 Thread Andreas Färber
Am 11.07.2013 11:14, schrieb TeLeMan:
 On Wed, Jul 10, 2013 at 10:33 PM, Andreas Färber afaer...@suse.de wrote:
 diff --git a/gdbstub.c b/gdbstub.c
 index f7d9f13..0ee82a9 100644
 --- a/gdbstub.c
 +++ b/gdbstub.c
[...]
 @@ -2394,7 +2401,7 @@ static int gdb_handle_packet(GDBState *s, const char 
 *line_buf)
  put_packet(s, QC1);
  break;
  } else if (strcmp(p,fThreadInfo) == 0) {
 -s-query_cpu = first_cpu;
 +s-query_cpu = first_cpu-env_ptr;
  goto report_cpuinfo;
  } else if (strcmp(p,sThreadInfo) == 0) {
  report_cpuinfo:
 @@ -2402,7 +2409,7 @@ static int gdb_handle_packet(GDBState *s, const char 
 *line_buf)
  snprintf(buf, sizeof(buf), m%x,
   cpu_index(ENV_GET_CPU(s-query_cpu)));
  put_packet(s, buf);
 -s-query_cpu = s-query_cpu-next_cpu;
 +s-query_cpu = ENV_GET_CPU(s-query_cpu)-next_cpu-env_ptr;
 next_cpu may be NULL.

True. If this is the only place where you've found that mistake then the
implicit fix is already queued next on qom-cpu:
http://patchwork.ozlabs.org/patch/255756/

Review and/or testing of the remaining gdbstub patches would be appreciated:
http://lists.nongnu.org/archive/html/qemu-devel/2013-07/msg01510.html
Mainly I'm waiting on an ack or feedback for the vaddr typedef to proceed.

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] vm performance degradation after kvm live migration or save-restore with ETP enabled

2013-07-11 Thread Andreas Färber
Hi,

Am 11.07.2013 11:36, schrieb Zhanghaoyu (A):
 I met similar problem to these, while performing live migration or 
 save-restore test on the kvm platform (qemu:1.4.0, host:suse11sp2, 
 guest:suse11sp2), running tele-communication software suite in guest,
 https://lists.gnu.org/archive/html/qemu-devel/2013-05/msg00098.html
 http://comments.gmane.org/gmane.comp.emulators.kvm.devel/102506
 http://thread.gmane.org/gmane.comp.emulators.kvm.devel/100592
 https://bugzilla.kernel.org/show_bug.cgi?id=58771
 
 After live migration or virsh restore [savefile], one process's CPU 
 utilization went up by about 30%, resulted in throughput degradation of this 
 process.
 oprofile report on this process in guest,
 pre live migration:

So far we've been unable to reproduce this with a pure qemu-kvm /
qemu-system-x86_64 command line on several EPT machines, whereas for
virsh it was reported as confirmed. Can you please share the resulting
QEMU command line from libvirt logs or process list?

Are both host and guest kernel at 3.0.80 (latest SLES updates)?

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 17/43] target-s390x: Change handle_{hypercall,diag}() argument to S390CPU

2013-07-10 Thread Andreas Färber
This allows to get rid of the last remaining ENV_GET_CPU() in
target-s390x/ by using CPU() cast directly on the argument.

Cc: Jason J. Herne jjhe...@us.ibm.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-s390x/kvm.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index af499cf..60e94f8 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -607,9 +607,10 @@ static int handle_priv(S390CPU *cpu, struct kvm_run *run,
 return r;
 }
 
-static int handle_hypercall(CPUS390XState *env, struct kvm_run *run)
+static int handle_hypercall(S390CPU *cpu, struct kvm_run *run)
 {
-CPUState *cs = ENV_GET_CPU(env);
+CPUState *cs = CPU(cpu);
+CPUS390XState *env = cpu-env;
 
 kvm_s390_get_registers_partial(cs);
 cs-kvm_vcpu_dirty = true;
@@ -618,13 +619,13 @@ static int handle_hypercall(CPUS390XState *env, struct 
kvm_run *run)
 return 0;
 }
 
-static int handle_diag(CPUS390XState *env, struct kvm_run *run, int ipb_code)
+static int handle_diag(S390CPU *cpu, struct kvm_run *run, int ipb_code)
 {
 int r = 0;
 
 switch (ipb_code) {
 case DIAG_KVM_HYPERCALL:
-r = handle_hypercall(env, run);
+r = handle_hypercall(cpu, run);
 break;
 case DIAG_KVM_BREAKPOINT:
 sleep(10);
@@ -735,7 +736,6 @@ out:
 
 static int handle_instruction(S390CPU *cpu, struct kvm_run *run)
 {
-CPUS390XState *env = cpu-env;
 unsigned int ipa0 = (run-s390_sieic.ipa  0xff00);
 uint8_t ipa1 = run-s390_sieic.ipa  0x00ff;
 int ipb_code = (run-s390_sieic.ipb  0x0fff)  16;
@@ -749,7 +749,7 @@ static int handle_instruction(S390CPU *cpu, struct kvm_run 
*run)
 r = handle_priv(cpu, run, ipa0  8, ipa1);
 break;
 case IPA0_DIAG:
-r = handle_diag(env, run, ipb_code);
+r = handle_diag(cpu, run, ipb_code);
 break;
 case IPA0_SIGP:
 r = handle_sigp(cpu, run, ipa1);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 05/43] kvm: Free current_cpu identifier

2013-07-10 Thread Andreas Färber
Since CPU loops are done as last step in kvm_{insert,remove}_breakpoint()
and kvm_remove_all_breakpoints(), we do not need to distinguish between
invoking CPU and iterated CPUs and can thereby free the identifier for
use as a global variable.

Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 include/sysemu/kvm.h | 10 +-
 kvm-all.c| 39 +--
 kvm-stub.c   |  6 +++---
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index a14cfe9..7596aca 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -169,11 +169,11 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-void kvm_remove_all_breakpoints(CPUArchState *current_env);
+void kvm_remove_all_breakpoints(CPUArchState *env);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
 #ifndef _WIN32
 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
@@ -252,9 +252,9 @@ struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState 
*cpu,
 
 int kvm_sw_breakpoints_active(CPUState *cpu);
 
-int kvm_arch_insert_sw_breakpoint(CPUState *current_cpu,
+int kvm_arch_insert_sw_breakpoint(CPUState *cpu,
   struct kvm_sw_breakpoint *bp);
-int kvm_arch_remove_sw_breakpoint(CPUState *current_cpu,
+int kvm_arch_remove_sw_breakpoint(CPUState *cpu,
   struct kvm_sw_breakpoint *bp);
 int kvm_arch_insert_hw_breakpoint(target_ulong addr,
   target_ulong len, int type);
diff --git a/kvm-all.c b/kvm-all.c
index de658de..ed13d57 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1903,16 +1903,15 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *current_cpu = ENV_GET_CPU(current_env);
+CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
-CPUArchState *env;
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_cpu, addr);
+bp = kvm_find_sw_breakpoint(cpu, addr);
 if (bp) {
 bp-use_count++;
 return 0;
@@ -1925,14 +1924,13 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 
 bp-pc = addr;
 bp-use_count = 1;
-err = kvm_arch_insert_sw_breakpoint(current_cpu, bp);
+err = kvm_arch_insert_sw_breakpoint(cpu, bp);
 if (err) {
 g_free(bp);
 return err;
 }
 
-QTAILQ_INSERT_HEAD(current_cpu-kvm_state-kvm_sw_breakpoints,
-  bp, entry);
+QTAILQ_INSERT_HEAD(cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
 } else {
 err = kvm_arch_insert_hw_breakpoint(addr, len, type);
 if (err) {
@@ -1949,16 +1947,15 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *current_cpu = ENV_GET_CPU(current_env);
+CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
-CPUArchState *env;
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_cpu, addr);
+bp = kvm_find_sw_breakpoint(cpu, addr);
 if (!bp) {
 return -ENOENT;
 }
@@ -1968,12 +1965,12 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-err = kvm_arch_remove_sw_breakpoint(current_cpu, bp);
+err = kvm_arch_remove_sw_breakpoint(cpu, bp);
 if (err) {
 return err;
 }
 
-QTAILQ_REMOVE(current_cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
+QTAILQ_REMOVE(cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
 g_free(bp);
 } else {
 err = kvm_arch_remove_hw_breakpoint(addr, len, type);
@@ -1991,16 +1988,14 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *current_env)
+void kvm_remove_all_breakpoints(CPUArchState

[PULL 07/43] kvm: Change kvm_remove_all_breakpoints() argument to CPUState

2013-07-10 Thread Andreas Färber
Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 2 +-
 include/sysemu/kvm.h | 2 +-
 kvm-all.c| 6 +++---
 kvm-stub.c   | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 9ae6576..f7d9f13 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2019,7 +2019,7 @@ static void gdb_breakpoint_remove_all(void)
 CPUArchState *env;
 
 if (kvm_enabled()) {
-kvm_remove_all_breakpoints(gdbserver_state-c_cpu);
+kvm_remove_all_breakpoints(ENV_GET_CPU(gdbserver_state-c_cpu));
 return;
 }
 
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 7596aca..1e08a85 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -173,7 +173,7 @@ int kvm_insert_breakpoint(CPUArchState *env, target_ulong 
addr,
   target_ulong len, int type);
 int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-void kvm_remove_all_breakpoints(CPUArchState *env);
+void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
 #ifndef _WIN32
 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
diff --git a/kvm-all.c b/kvm-all.c
index ed13d57..2c14ef3 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1988,11 +1988,11 @@ int kvm_remove_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp, *next;
 KVMState *s = cpu-kvm_state;
+CPUArchState *env;
 
 QTAILQ_FOREACH_SAFE(bp, s-kvm_sw_breakpoints, entry, next) {
 if (kvm_arch_remove_sw_breakpoint(cpu, bp) != 0) {
@@ -2033,7 +2033,7 @@ int kvm_remove_breakpoint(CPUArchState *env, target_ulong 
addr,
 return -EINVAL;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
 }
 #endif /* !KVM_CAP_SET_GUEST_DEBUG */
diff --git a/kvm-stub.c b/kvm-stub.c
index 583c636..370c837 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -95,7 +95,7 @@ int kvm_remove_breakpoint(CPUArchState *env, target_ulong 
addr,
 return -EINVAL;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
 }
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 16/43] target-s390x: Don't overuse ENV_GET_CPU()

2013-07-10 Thread Andreas Färber
Commit 3474b679486caa8f6448bae974e131370f360c13 (Utilize selective
runtime reg sync for hot code paths) introduced two uses of
ENV_GET_CPU() inside target-s390x/ KVM code. In one case we can use a
direct CPU() cast instead.

Cc: Jason J. Herne jjhe...@us.ibm.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-s390x/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 42f758f..af499cf 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -469,7 +469,7 @@ static int kvm_handle_css_inst(S390CPU *cpu, struct kvm_run 
*run,
 int r = 0;
 int no_cc = 0;
 CPUS390XState *env = cpu-env;
-CPUState *cs = ENV_GET_CPU(env);
+CPUState *cs = CPU(cpu);
 
 if (ipa0 != 0xb2) {
 /* Not handled for now. */
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v3 10/41] kvm: Change kvm_{insert,remove}_breakpoint() argument to CPUState

2013-07-09 Thread Andreas Färber
CPUArchState is no longer directly used since converting CPU loops to
CPUState.

Prepares for changing GDBState::c_cpu to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 12 
 include/sysemu/kvm.h |  4 ++--
 kvm-all.c| 10 --
 kvm-stub.c   |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 8e23509..b5e6778 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1954,8 +1954,10 @@ static int gdb_breakpoint_insert(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_insert_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_insert_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
@@ -1991,8 +1993,10 @@ static int gdb_breakpoint_remove(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_remove_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_remove_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 1e08a85..f8ac448 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -169,9 +169,9 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
 void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
diff --git a/kvm-all.c b/kvm-all.c
index 0c16a44..2263c48 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1903,10 +1903,9 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -1949,10 +1948,9 @@ int kvm_insert_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -2025,13 +2023,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return -EINVAL;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
diff --git a/kvm-stub.c b/kvm-stub.c
index 370c837..7b2233a 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -83,13 +83,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned long 
reinject_trap)
 return -ENOSYS;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v3 15/41] exec: Change cpu_memory_rw_debug() argument to CPUState

2013-07-09 Thread Andreas Färber
Propagate X86CPU in kvmvapic for simplicity.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c  |  4 +--
 disas.c |  4 +--
 exec.c  |  6 ++--
 gdbstub.c   |  2 +-
 hw/i386/kvmvapic.c  | 72 +++--
 include/exec/cpu-all.h  |  3 +-
 include/exec/softmmu-semi.h | 18 +++-
 monitor.c   |  2 +-
 target-arm/arm-semi.c   |  2 +-
 target-i386/helper.c|  8 +++--
 target-i386/kvm.c   | 14 -
 target-sparc/mmu_helper.c   |  5 ++--
 target-xtensa/xtensa-semi.c | 10 +++
 13 files changed, 77 insertions(+), 73 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8a4f395..1ce6816 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1247,7 +1247,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 {
 FILE *f;
 uint32_t l;
-CPUArchState *env;
 CPUState *cpu;
 uint8_t buf[1024];
 
@@ -1261,7 +1260,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
   a CPU number);
 return;
 }
-env = cpu-env_ptr;
 
 f = fopen(filename, wb);
 if (!f) {
@@ -1273,7 +1271,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 l = sizeof(buf);
 if (l  size)
 l = size;
-cpu_memory_rw_debug(env, addr, buf, l, 0);
+cpu_memory_rw_debug(cpu, addr, buf, l, 0);
 if (fwrite(buf, 1, l, f) != l) {
 error_set(errp, QERR_IO_ERROR);
 goto exit;
diff --git a/disas.c b/disas.c
index e51127e..71007fb 100644
--- a/disas.c
+++ b/disas.c
@@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr,
 {
 CPUDebug *s = container_of(info, CPUDebug, info);
 
-cpu_memory_rw_debug(s-env, memaddr, myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 return 0;
 }
 
@@ -392,7 +392,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int 
length,
 if (monitor_disas_is_physical) {
 cpu_physical_memory_read(memaddr, myaddr, length);
 } else {
-cpu_memory_rw_debug(s-env, memaddr,myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 }
 return 0;
 }
diff --git a/exec.c b/exec.c
index a768aea..f3fe6e6 100644
--- a/exec.c
+++ b/exec.c
@@ -1840,7 +1840,7 @@ MemoryRegion *get_system_io(void)
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l, flags;
@@ -2574,7 +2574,7 @@ void stq_be_phys(hwaddr addr, uint64_t val)
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l;
@@ -2583,7 +2583,7 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong 
addr,
 
 while (len  0) {
 page = addr  TARGET_PAGE_MASK;
-phys_addr = cpu_get_phys_page_debug(ENV_GET_CPU(env), page);
+phys_addr = cpu_get_phys_page_debug(cpu, page);
 /* if no physical page mapped, return an error */
 if (phys_addr == -1)
 return -1;
diff --git a/gdbstub.c b/gdbstub.c
index 848754d..6cefb17 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -46,7 +46,7 @@
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
  uint8_t *buf, int len, int is_write)
 {
-return cpu_memory_rw_debug(env, addr, buf, len, is_write);
+return cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, len, is_write);
 }
 #else
 /* target_memory_rw_debug() defined in cpu.h */
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 224601f..035d0fe 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -188,9 +188,10 @@ static bool opcode_matches(uint8_t *opcode, const 
TPRInstruction *instr)
  modrm_reg(opcode[1]) == instr-modrm_reg);
 }
 
-static int evaluate_tpr_instruction(VAPICROMState *s, CPUX86State *env,
+static int evaluate_tpr_instruction(VAPICROMState *s, X86CPU *cpu,
 target_ulong *pip, TPRAccess access)
 {
+CPUState *cs = CPU(cpu);
 const TPRInstruction *instr;
 target_ulong ip = *pip;
 uint8_t opcode[2];
@@ -211,7 +212,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
  * RSP, used by the patched instruction, is zero, so the guest gets a
  * double fault and dies.
  */
-if (env-regs[R_ESP] == 0) {
+if (cpu-env.regs[R_ESP] == 0) {
 return -1;
 }
 
@@ -226,7 +227,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
 if (instr

[PATCH qom-cpu v2 10/42] kvm: Change kvm_{insert,remove}_breakpoint() argument to CPUState

2013-07-07 Thread Andreas Färber
CPUArchState is no longer directly used since converting CPU loops to
CPUState.

Prepares for changing GDBState::c_cpu to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 12 
 include/sysemu/kvm.h |  4 ++--
 kvm-all.c| 10 --
 kvm-stub.c   |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 17da380..b77cd3e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1954,8 +1954,10 @@ static int gdb_breakpoint_insert(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_insert_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_insert_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
@@ -1991,8 +1993,10 @@ static int gdb_breakpoint_remove(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_remove_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_remove_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 1e08a85..f8ac448 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -169,9 +169,9 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
 void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
diff --git a/kvm-all.c b/kvm-all.c
index 0c16a44..2263c48 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1903,10 +1903,9 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -1949,10 +1948,9 @@ int kvm_insert_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -2025,13 +2023,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return -EINVAL;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
diff --git a/kvm-stub.c b/kvm-stub.c
index 370c837..7b2233a 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -83,13 +83,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned long 
reinject_trap)
 return -ENOSYS;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v2 16/42] exec: Change cpu_memory_rw_debug() argument to CPUState

2013-07-07 Thread Andreas Färber
Propagate X86CPU in kvmvapic for simplicity.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c  |  4 +--
 disas.c |  4 +--
 exec.c  |  6 ++--
 gdbstub.c   |  2 +-
 hw/i386/kvmvapic.c  | 72 +++--
 include/exec/cpu-all.h  |  3 +-
 include/exec/softmmu-semi.h | 18 +++-
 monitor.c   |  2 +-
 target-arm/arm-semi.c   |  2 +-
 target-i386/helper.c|  8 +++--
 target-i386/kvm.c   | 14 -
 target-sparc/mmu_helper.c   |  5 ++--
 target-xtensa/xtensa-semi.c | 10 +++
 13 files changed, 77 insertions(+), 73 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8a4f395..1ce6816 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1247,7 +1247,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 {
 FILE *f;
 uint32_t l;
-CPUArchState *env;
 CPUState *cpu;
 uint8_t buf[1024];
 
@@ -1261,7 +1260,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
   a CPU number);
 return;
 }
-env = cpu-env_ptr;
 
 f = fopen(filename, wb);
 if (!f) {
@@ -1273,7 +1271,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 l = sizeof(buf);
 if (l  size)
 l = size;
-cpu_memory_rw_debug(env, addr, buf, l, 0);
+cpu_memory_rw_debug(cpu, addr, buf, l, 0);
 if (fwrite(buf, 1, l, f) != l) {
 error_set(errp, QERR_IO_ERROR);
 goto exit;
diff --git a/disas.c b/disas.c
index e51127e..71007fb 100644
--- a/disas.c
+++ b/disas.c
@@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr,
 {
 CPUDebug *s = container_of(info, CPUDebug, info);
 
-cpu_memory_rw_debug(s-env, memaddr, myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 return 0;
 }
 
@@ -392,7 +392,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int 
length,
 if (monitor_disas_is_physical) {
 cpu_physical_memory_read(memaddr, myaddr, length);
 } else {
-cpu_memory_rw_debug(s-env, memaddr,myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 }
 return 0;
 }
diff --git a/exec.c b/exec.c
index a768aea..f3fe6e6 100644
--- a/exec.c
+++ b/exec.c
@@ -1840,7 +1840,7 @@ MemoryRegion *get_system_io(void)
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l, flags;
@@ -2574,7 +2574,7 @@ void stq_be_phys(hwaddr addr, uint64_t val)
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l;
@@ -2583,7 +2583,7 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong 
addr,
 
 while (len  0) {
 page = addr  TARGET_PAGE_MASK;
-phys_addr = cpu_get_phys_page_debug(ENV_GET_CPU(env), page);
+phys_addr = cpu_get_phys_page_debug(cpu, page);
 /* if no physical page mapped, return an error */
 if (phys_addr == -1)
 return -1;
diff --git a/gdbstub.c b/gdbstub.c
index cee9c13..43ecc0d 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -46,7 +46,7 @@
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
  uint8_t *buf, int len, int is_write)
 {
-return cpu_memory_rw_debug(env, addr, buf, len, is_write);
+return cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, len, is_write);
 }
 #else
 /* target_memory_rw_debug() defined in cpu.h */
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 224601f..035d0fe 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -188,9 +188,10 @@ static bool opcode_matches(uint8_t *opcode, const 
TPRInstruction *instr)
  modrm_reg(opcode[1]) == instr-modrm_reg);
 }
 
-static int evaluate_tpr_instruction(VAPICROMState *s, CPUX86State *env,
+static int evaluate_tpr_instruction(VAPICROMState *s, X86CPU *cpu,
 target_ulong *pip, TPRAccess access)
 {
+CPUState *cs = CPU(cpu);
 const TPRInstruction *instr;
 target_ulong ip = *pip;
 uint8_t opcode[2];
@@ -211,7 +212,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
  * RSP, used by the patched instruction, is zero, so the guest gets a
  * double fault and dies.
  */
-if (env-regs[R_ESP] == 0) {
+if (cpu-env.regs[R_ESP] == 0) {
 return -1;
 }
 
@@ -226,7 +227,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
 if (instr

[PATCH qom-cpu v2 07/42] cpu: Move singlestep_enabled field from CPU_COMMON to CPUState

2013-07-07 Thread Andreas Färber
Prepares for changing cpu_single_step() argument to CPUState.

Acked-by: Michael Walle mich...@walle.cc (for lm32)
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c|  2 +-
 cpus.c|  2 +-
 exec.c| 10 ++
 include/exec/cpu-defs.h   |  1 -
 include/qom/cpu.h |  2 ++
 kvm-all.c |  2 +-
 target-alpha/translate.c  |  3 ++-
 target-arm/translate.c|  7 ---
 target-cris/translate.c   |  7 ---
 target-i386/kvm.c |  6 --
 target-i386/translate.c   |  5 +++--
 target-lm32/translate.c   |  7 ---
 target-m68k/translate.c   |  7 ---
 target-microblaze/translate.c |  8 +---
 target-mips/translate.c   | 11 +++
 target-moxie/translate.c  |  5 +++--
 target-openrisc/translate.c   |  7 ---
 target-ppc/translate.c|  8 +---
 target-s390x/translate.c  |  5 +++--
 target-sh4/translate.c|  8 +---
 target-sparc/translate.c  |  3 ++-
 target-unicore32/translate.c  |  7 ---
 target-xtensa/translate.c |  7 ---
 23 files changed, 78 insertions(+), 52 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 3fccb86..301be28 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -297,7 +297,7 @@ int cpu_exec(CPUArchState *env)
 for(;;) {
 interrupt_request = cpu-interrupt_request;
 if (unlikely(interrupt_request)) {
-if (unlikely(env-singlestep_enabled  SSTEP_NOIRQ)) {
+if (unlikely(cpu-singlestep_enabled  SSTEP_NOIRQ)) {
 /* Mask out external interrupts for this step. */
 interrupt_request = ~CPU_INTERRUPT_SSTEP_MASK;
 }
diff --git a/cpus.c b/cpus.c
index f141428..8a4f395 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1148,7 +1148,7 @@ static void tcg_exec_all(void)
 CPUArchState *env = cpu-env_ptr;
 
 qemu_clock_enable(vm_clock,
-  (env-singlestep_enabled  SSTEP_NOTIMER) == 0);
+  (cpu-singlestep_enabled  SSTEP_NOTIMER) == 0);
 
 if (cpu_can_run(cpu)) {
 r = tcg_cpu_exec(env);
diff --git a/exec.c b/exec.c
index f01e3b6..ae6eb24 100644
--- a/exec.c
+++ b/exec.c
@@ -588,11 +588,13 @@ void cpu_breakpoint_remove_all(CPUArchState *env, int 
mask)
 void cpu_single_step(CPUArchState *env, int enabled)
 {
 #if defined(TARGET_HAS_ICE)
-if (env-singlestep_enabled != enabled) {
-env-singlestep_enabled = enabled;
-if (kvm_enabled())
+CPUState *cpu = ENV_GET_CPU(env);
+
+if (cpu-singlestep_enabled != enabled) {
+cpu-singlestep_enabled = enabled;
+if (kvm_enabled()) {
 kvm_update_guest_debug(env, 0);
-else {
+} else {
 /* must flush all the translated code to avoid inconsistencies */
 /* XXX: only flush what is necessary */
 tb_flush(env);
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 39094b3..12b1ca7 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -170,7 +170,6 @@ typedef struct CPUWatchpoint {
 /* from this point: preserved by CPU reset */   \
 /* ice debug support */ \
 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;\
-int singlestep_enabled; \
 \
 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;\
 CPUWatchpoint *watchpoint_hit;  \
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 152dad5..136482c 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -129,6 +129,7 @@ struct kvm_run;
  * @stopped: Indicates the CPU has been artificially stopped.
  * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this
  *   CPU and return to its top level loop.
+ * @singlestep_enabled: Flags for single-stepping.
  * @env_ptr: Pointer to subclass-specific CPUArchState field.
  * @current_tb: Currently executing TB.
  * @next_cpu: Next CPU sharing TB cache.
@@ -161,6 +162,7 @@ struct CPUState {
 volatile sig_atomic_t exit_request;
 volatile sig_atomic_t tcg_exit_req;
 uint32_t interrupt_request;
+int singlestep_enabled;
 
 void *env_ptr; /* CPUArchState */
 struct TranslationBlock *current_tb;
diff --git a/kvm-all.c b/kvm-all.c
index c130705..0c16a44 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1893,7 +1893,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 
 data.dbg.control = reinject_trap;
 
-if (env-singlestep_enabled) {
+if (cpu-singlestep_enabled) {
 data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
 }
 kvm_arch_update_guest_debug(cpu

Re: [Qemu-devel] KVM call agenda for 2013-07-09

2013-07-07 Thread Andreas Färber
Am 08.07.2013 01:10, schrieb Juan Quintela:
 Please, send any topic that you are interested in covering.

Static qdev vs. dynamic QOM properties and -global
(Igor's topic from two weeks ago that we couldn't cover any more)
= needed for X86CPU subclasses (hot-add, topology, NUMA, ...)

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v9] target-i386: Move hyperv_* static globals to X86CPU

2013-07-07 Thread Andreas Färber
From: Igor Mammedov imamm...@redhat.com

- since hyperv_* helper functions are used only in target-i386/kvm.c
  move them there as static helpers

Requested-by: Eduardo Habkost ehabk...@redhat.com
Signed-off-by: Igor Mammedov imamm...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 v8 (imammedo) - v9:
 * Use X86CPU instead of CPUX86State (only used in KVM)
 * Changed helper functions to X86CPU argument
 * Moved field initialization to QOM instance_init
 * Fixed subject (not today's CPUState)

 target-i386/Makefile.objs |  2 +-
 target-i386/cpu-qom.h |  4 +++
 target-i386/cpu.c | 16 
 target-i386/cpu.h |  4 +++
 target-i386/hyperv.c  | 64 ---
 target-i386/hyperv.h  | 45 -
 target-i386/kvm.c | 36 ++
 7 files changed, 46 insertions(+), 125 deletions(-)
 delete mode 100644 target-i386/hyperv.c
 delete mode 100644 target-i386/hyperv.h

diff --git a/target-i386/Makefile.objs b/target-i386/Makefile.objs
index c1d4f05..887dca7 100644
--- a/target-i386/Makefile.objs
+++ b/target-i386/Makefile.objs
@@ -2,7 +2,7 @@ obj-y += translate.o helper.o cpu.o
 obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o
 obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o
 obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o
-obj-$(CONFIG_KVM) += kvm.o hyperv.o
+obj-$(CONFIG_KVM) += kvm.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
 obj-$(CONFIG_LINUX_USER) += ioport-user.o
 obj-$(CONFIG_BSD_USER) += ioport-user.o
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 7e55e5f..18f08b8 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -66,6 +66,10 @@ typedef struct X86CPU {
 
 CPUX86State env;
 
+bool hyperv_vapic;
+bool hyperv_relaxed_timing;
+int hyperv_spinlock_attempts;
+
 /* Features that were filtered out because of missing host capabilities */
 uint32_t filtered_features[FEATURE_WORDS];
 } X86CPU;
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e3f75a8..14e9c7e 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -35,8 +35,6 @@
 #include qapi/visitor.h
 #include sysemu/arch_init.h
 
-#include hyperv.h
-
 #include hw/hw.h
 #if defined(CONFIG_KVM)
 #include linux/kvm_para.h
@@ -1587,12 +1585,19 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char 
*features, Error **errp)
 object_property_parse(OBJECT(cpu), num, tsc-frequency, errp);
 } else if (!strcmp(featurestr, hv-spinlocks)) {
 char *err;
+const int min = 0xFFF;
 numvalue = strtoul(val, err, 0);
 if (!*val || *err) {
 error_setg(errp, bad numerical value %s, val);
 goto out;
 }
-hyperv_set_spinlock_retries(numvalue);
+if (numvalue  min) {
+fprintf(stderr, hv-spinlocks value shall always be = 
0x%x
+, fixup will be removed in future versions\n,
+min);
+numvalue = min;
+}
+cpu-hyperv_spinlock_attempts = numvalue;
 } else {
 error_setg(errp, unrecognized feature %s, featurestr);
 goto out;
@@ -1602,9 +1607,9 @@ static void cpu_x86_parse_featurestr(X86CPU *cpu, char 
*features, Error **errp)
 } else if (!strcmp(featurestr, enforce)) {
 check_cpuid = enforce_cpuid = 1;
 } else if (!strcmp(featurestr, hv_relaxed)) {
-hyperv_enable_relaxed_timing(true);
+cpu-hyperv_relaxed_timing = true;
 } else if (!strcmp(featurestr, hv_vapic)) {
-hyperv_enable_vapic_recommended(true);
+cpu-hyperv_vapic = true;
 } else {
 error_setg(errp, feature string `%s' not in format (+feature|
-feature|feature=xyz), featurestr);
@@ -2479,6 +2484,7 @@ static void x86_cpu_initfn(Object *obj)
 x86_cpu_get_feature_words,
 NULL, NULL, (void *)cpu-filtered_features, NULL);
 
+cpu-hyperv_spinlock_attempts = HYPERV_SPINLOCK_NEVER_RETRY;
 env-cpuid_apic_id = x86_cpu_apic_id_from_index(cs-cpu_index);
 
 /* init various static tables used in TCG mode */
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 2d005b3..6c3eb86 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -549,6 +549,10 @@ typedef uint32_t FeatureWordArray[FEATURE_WORDS];
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
+#ifndef HYPERV_SPINLOCK_NEVER_RETRY
+#define HYPERV_SPINLOCK_NEVER_RETRY 0x
+#endif
+
 #define EXCP00_DIVZ0
 #define EXCP01_DB  1
 #define EXCP02_NMI 2
diff --git a/target-i386/hyperv.c b/target-i386

Re: [Qemu-devel] [PATCH qom-cpu v3 05/14] cpu: Make first_cpu and next_cpu CPUState

2013-07-01 Thread Andreas Färber
Am 26.06.2013 19:35, schrieb Andreas Färber:
 Move next_cpu from CPU_COMMON to CPUState.
 Move first_cpu variable to qom/cpu.h.
 
 gdbstub needs to use CPUState::env_ptr for now.
 cpu_copy() no longer needs to save and restore cpu_next.
 
 Acked-by: Paolo Bonzini pbonz...@redhat.com
 [AF: Rebased, simplified cpu_copy()]
 Signed-off-by: Andreas Färber afaer...@suse.de

Squashing the following additional conversion after rebase.

Andreas

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 38f7990..ff86154 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -500,7 +500,6 @@ static DeviceState
*ppce500_init_mpic_kvm(PPCE500Params *params,
   qemu_irq **irqs)
 {
 DeviceState *dev;
-CPUPPCState *env;
 CPUState *cs;
 int r;

@@ -512,9 +511,7 @@ static DeviceState
*ppce500_init_mpic_kvm(PPCE500Params *params,
 return NULL;
 }

-for (env = first_cpu; env != NULL; env = env-next_cpu) {
-cs = ENV_GET_CPU(env);
-
+for (cs = first_cpu; cs != NULL; cs = cs-next_cpu) {
 if (kvm_openpic_connect_vcpu(dev, cs)) {


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RFC qom-cpu 28/41] kvm: Change kvm_{insert,remove}_breakpoint() argument to CPUState

2013-06-29 Thread Andreas Färber
CPUArchState is no longer directly used since converting CPU loops to
CPUState.

Prepares for changing GDBState::c_cpu to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 12 
 include/sysemu/kvm.h |  4 ++--
 kvm-all.c| 10 --
 kvm-stub.c   |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 17da380..b77cd3e 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1954,8 +1954,10 @@ static int gdb_breakpoint_insert(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_insert_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_insert_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
@@ -1991,8 +1993,10 @@ static int gdb_breakpoint_remove(target_ulong addr, 
target_ulong len, int type)
 CPUArchState *env;
 int err = 0;
 
-if (kvm_enabled())
-return kvm_remove_breakpoint(gdbserver_state-c_cpu, addr, len, type);
+if (kvm_enabled()) {
+return kvm_remove_breakpoint(ENV_GET_CPU(gdbserver_state-c_cpu),
+ addr, len, type);
+}
 
 switch (type) {
 case GDB_BREAKPOINT_SW:
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 9460d5a..60a587e 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -159,9 +159,9 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type);
 void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
diff --git a/kvm-all.c b/kvm-all.c
index 65e93cd..9991953 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1896,10 +1896,9 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -1942,10 +1941,9 @@ int kvm_insert_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
 int err;
 
@@ -2018,13 +2016,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return -EINVAL;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
diff --git a/kvm-stub.c b/kvm-stub.c
index a6c2b01..b7f3569 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -83,13 +83,13 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned long 
reinject_trap)
 return -ENOSYS;
 }
 
-int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
 }
 
-int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
+int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
   target_ulong len, int type)
 {
 return -EINVAL;
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RFC qom-cpu 25/41] cpu: Move singlestep_enabled field from CPU_COMMON to CPUState

2013-06-29 Thread Andreas Färber
Prepares for changing cpu_single_step() argument to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpu-exec.c|  2 +-
 cpus.c|  2 +-
 exec.c| 10 ++
 include/exec/cpu-defs.h   |  1 -
 include/qom/cpu.h |  1 +
 kvm-all.c |  2 +-
 target-alpha/translate.c  | 12 
 target-arm/translate.c|  7 ---
 target-cris/translate.c   |  7 ---
 target-i386/kvm.c |  6 --
 target-i386/translate.c   |  5 +++--
 target-lm32/translate.c   |  7 ---
 target-m68k/translate.c   |  7 ---
 target-microblaze/translate.c |  8 +---
 target-mips/translate.c   | 11 +++
 target-moxie/translate.c  |  5 +++--
 target-openrisc/translate.c   |  7 ---
 target-ppc/translate.c|  8 +---
 target-s390x/translate.c  |  5 +++--
 target-sh4/translate.c|  8 +---
 target-sparc/translate.c  |  3 ++-
 target-unicore32/translate.c  |  7 ---
 target-xtensa/translate.c |  7 ---
 23 files changed, 83 insertions(+), 55 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 88f4e75..d52e581 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -297,7 +297,7 @@ int cpu_exec(CPUArchState *env)
 for(;;) {
 interrupt_request = cpu-interrupt_request;
 if (unlikely(interrupt_request)) {
-if (unlikely(env-singlestep_enabled  SSTEP_NOIRQ)) {
+if (unlikely(cpu-singlestep_enabled  SSTEP_NOIRQ)) {
 /* Mask out external interrupts for this step. */
 interrupt_request = ~CPU_INTERRUPT_SSTEP_MASK;
 }
diff --git a/cpus.c b/cpus.c
index f97983d..8b99deb 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1148,7 +1148,7 @@ static void tcg_exec_all(void)
 CPUArchState *env = cpu-env_ptr;
 
 qemu_clock_enable(vm_clock,
-  (env-singlestep_enabled  SSTEP_NOTIMER) == 0);
+  (cpu-singlestep_enabled  SSTEP_NOTIMER) == 0);
 
 if (cpu_can_run(cpu)) {
 r = tcg_cpu_exec(env);
diff --git a/exec.c b/exec.c
index 4e20143..f2d848c 100644
--- a/exec.c
+++ b/exec.c
@@ -584,11 +584,13 @@ void cpu_breakpoint_remove_all(CPUArchState *env, int 
mask)
 void cpu_single_step(CPUArchState *env, int enabled)
 {
 #if defined(TARGET_HAS_ICE)
-if (env-singlestep_enabled != enabled) {
-env-singlestep_enabled = enabled;
-if (kvm_enabled())
+CPUState *cpu = ENV_GET_CPU(env);
+
+if (cpu-singlestep_enabled != enabled) {
+cpu-singlestep_enabled = enabled;
+if (kvm_enabled()) {
 kvm_update_guest_debug(env, 0);
-else {
+} else {
 /* must flush all the translated code to avoid inconsistencies */
 /* XXX: only flush what is necessary */
 tb_flush(env);
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 39094b3..12b1ca7 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -170,7 +170,6 @@ typedef struct CPUWatchpoint {
 /* from this point: preserved by CPU reset */   \
 /* ice debug support */ \
 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;\
-int singlestep_enabled; \
 \
 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;\
 CPUWatchpoint *watchpoint_hit;  \
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index d8b77af..a02b142 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -148,6 +148,7 @@ struct CPUState {
 volatile sig_atomic_t exit_request;
 volatile sig_atomic_t tcg_exit_req;
 uint32_t interrupt_request;
+int singlestep_enabled;
 
 void *env_ptr; /* CPUArchState */
 struct TranslationBlock *current_tb;
diff --git a/kvm-all.c b/kvm-all.c
index 00ef85d..65e93cd 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1886,7 +1886,7 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 
 data.dbg.control = reinject_trap;
 
-if (env-singlestep_enabled) {
+if (cpu-singlestep_enabled) {
 data.dbg.control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_SINGLESTEP;
 }
 kvm_arch_update_guest_debug(cpu, data.dbg);
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index 147285a..0229a66 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -377,10 +377,12 @@ static ExitStatus gen_store_conditional(DisasContext 
*ctx, int ra, int rb,
 
 static int use_goto_tb(DisasContext *ctx, uint64_t dest)
 {
+CPUState *cs = CPU(ctx-cpu);
+
 /* Check for the dest on the same page as the start of the TB.  We
also want to suppress

[PATCH RFC qom-cpu 34/41] exec: Change cpu_memory_rw_debug() argument to CPUState

2013-06-29 Thread Andreas Färber
Propagate X86CPU in kvmvapic for simplicity.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c  |  4 +--
 disas.c |  4 +--
 exec.c  |  6 ++--
 gdbstub.c   |  2 +-
 hw/i386/kvmvapic.c  | 72 +++--
 include/exec/cpu-all.h  |  3 +-
 include/exec/softmmu-semi.h | 18 +++-
 monitor.c   |  2 +-
 target-arm/arm-semi.c   |  2 +-
 target-i386/helper.c|  8 +++--
 target-i386/kvm.c   | 14 -
 target-sparc/mmu_helper.c   |  5 ++--
 target-xtensa/xtensa-semi.c | 10 +++
 13 files changed, 77 insertions(+), 73 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8b99deb..9dbd5ff 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1247,7 +1247,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 {
 FILE *f;
 uint32_t l;
-CPUArchState *env;
 CPUState *cpu;
 uint8_t buf[1024];
 
@@ -1261,7 +1260,6 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
   a CPU number);
 return;
 }
-env = cpu-env_ptr;
 
 f = fopen(filename, wb);
 if (!f) {
@@ -1273,7 +1271,7 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 l = sizeof(buf);
 if (l  size)
 l = size;
-cpu_memory_rw_debug(env, addr, buf, l, 0);
+cpu_memory_rw_debug(cpu, addr, buf, l, 0);
 if (fwrite(buf, 1, l, f) != l) {
 error_set(errp, QERR_IO_ERROR);
 goto exit;
diff --git a/disas.c b/disas.c
index e51127e..71007fb 100644
--- a/disas.c
+++ b/disas.c
@@ -39,7 +39,7 @@ target_read_memory (bfd_vma memaddr,
 {
 CPUDebug *s = container_of(info, CPUDebug, info);
 
-cpu_memory_rw_debug(s-env, memaddr, myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 return 0;
 }
 
@@ -392,7 +392,7 @@ monitor_read_memory (bfd_vma memaddr, bfd_byte *myaddr, int 
length,
 if (monitor_disas_is_physical) {
 cpu_physical_memory_read(memaddr, myaddr, length);
 } else {
-cpu_memory_rw_debug(s-env, memaddr,myaddr, length, 0);
+cpu_memory_rw_debug(ENV_GET_CPU(s-env), memaddr, myaddr, length, 0);
 }
 return 0;
 }
diff --git a/exec.c b/exec.c
index 359dc64..f4906cf 100644
--- a/exec.c
+++ b/exec.c
@@ -1847,7 +1847,7 @@ MemoryRegion *get_system_io(void)
 
 /* physical memory access (slow version, mainly for debug) */
 #if defined(CONFIG_USER_ONLY)
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l, flags;
@@ -2565,7 +2565,7 @@ void stq_be_phys(hwaddr addr, uint64_t val)
 }
 
 /* virtual memory access for debug (includes writing to ROM) */
-int cpu_memory_rw_debug(CPUArchState *env, target_ulong addr,
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
 uint8_t *buf, int len, int is_write)
 {
 int l;
@@ -2574,7 +2574,7 @@ int cpu_memory_rw_debug(CPUArchState *env, target_ulong 
addr,
 
 while (len  0) {
 page = addr  TARGET_PAGE_MASK;
-phys_addr = cpu_get_phys_page_debug(ENV_GET_CPU(env), page);
+phys_addr = cpu_get_phys_page_debug(cpu, page);
 /* if no physical page mapped, return an error */
 if (phys_addr == -1)
 return -1;
diff --git a/gdbstub.c b/gdbstub.c
index cee9c13..43ecc0d 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -46,7 +46,7 @@
 static inline int target_memory_rw_debug(CPUArchState *env, target_ulong addr,
  uint8_t *buf, int len, int is_write)
 {
-return cpu_memory_rw_debug(env, addr, buf, len, is_write);
+return cpu_memory_rw_debug(ENV_GET_CPU(env), addr, buf, len, is_write);
 }
 #else
 /* target_memory_rw_debug() defined in cpu.h */
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 76fca34..860dea7 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -188,9 +188,10 @@ static bool opcode_matches(uint8_t *opcode, const 
TPRInstruction *instr)
  modrm_reg(opcode[1]) == instr-modrm_reg);
 }
 
-static int evaluate_tpr_instruction(VAPICROMState *s, CPUX86State *env,
+static int evaluate_tpr_instruction(VAPICROMState *s, X86CPU *cpu,
 target_ulong *pip, TPRAccess access)
 {
+CPUState *cs = CPU(cpu);
 const TPRInstruction *instr;
 target_ulong ip = *pip;
 uint8_t opcode[2];
@@ -211,7 +212,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
  * RSP, used by the patched instruction, is zero, so the guest gets a
  * double fault and dies.
  */
-if (env-regs[R_ESP] == 0) {
+if (cpu-env.regs[R_ESP] == 0) {
 return -1;
 }
 
@@ -226,7 +227,7 @@ static int evaluate_tpr_instruction(VAPICROMState *s, 
CPUX86State *env,
 if (instr

[PULL 16/24] kvm: Change kvm_handle_internal_error() argument to CPUState

2013-06-28 Thread Andreas Färber
It no longer uses CPUArchState.

Prepares for changing kvm_cpu_exec() argument to CPUState.

Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 kvm-all.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index bab04c9..d3e5e5e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1525,10 +1525,8 @@ static void kvm_handle_io(uint16_t port, void *data, int 
direction, int size,
 }
 }
 
-static int kvm_handle_internal_error(CPUArchState *env, struct kvm_run *run)
+static int kvm_handle_internal_error(CPUState *cpu, struct kvm_run *run)
 {
-CPUState *cpu = ENV_GET_CPU(env);
-
 fprintf(stderr, KVM internal error.);
 if (kvm_check_extension(kvm_state, KVM_CAP_INTERNAL_ERROR_DATA)) {
 int i;
@@ -1690,7 +1688,7 @@ int kvm_cpu_exec(CPUArchState *env)
 ret = -1;
 break;
 case KVM_EXIT_INTERNAL_ERROR:
-ret = kvm_handle_internal_error(env, run);
+ret = kvm_handle_internal_error(cpu, run);
 break;
 default:
 DPRINTF(kvm_arch_handle_exit\n);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 09/24] kvm: Change cpu_synchronize_state() argument to CPUState

2013-06-28 Thread Andreas Färber
Change Monitor::mon_cpu to CPUState as well.

Reviewed-by: liguang lig.f...@cn.fujitsu.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c  | 8 
 gdbstub.c   | 8 
 hw/i386/kvm/apic.c  | 2 +-
 hw/i386/kvmvapic.c  | 4 ++--
 hw/misc/vmport.c| 2 +-
 hw/ppc/ppce500_spin.c   | 2 +-
 include/sysemu/kvm.h| 4 ++--
 monitor.c   | 6 +++---
 target-i386/helper.c| 4 ++--
 target-i386/kvm.c   | 2 +-
 target-ppc/mmu-hash64.c | 2 +-
 target-ppc/translate.c  | 2 +-
 target-s390x/kvm.c  | 9 +
 13 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/cpus.c b/cpus.c
index c8bc8ad..353208c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -407,10 +407,10 @@ void hw_error(const char *fmt, ...)
 
 void cpu_synchronize_all_states(void)
 {
-CPUArchState *cpu;
+CPUArchState *env;
 
-for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
-cpu_synchronize_state(cpu);
+for (env = first_cpu; env; env = env-next_cpu) {
+cpu_synchronize_state(ENV_GET_CPU(env));
 }
 }
 
@@ -1219,7 +1219,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 CPUState *cpu = ENV_GET_CPU(env);
 CpuInfoList *info;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(cpu);
 
 info = g_malloc0(sizeof(*info));
 info-value = g_malloc0(sizeof(*info-value));
diff --git a/gdbstub.c b/gdbstub.c
index 9ffb376..663549c 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2033,7 +2033,7 @@ static void gdb_breakpoint_remove_all(void)
 
 static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
 {
-cpu_synchronize_state(s-c_cpu);
+cpu_synchronize_state(ENV_GET_CPU(s-c_cpu));
 #if defined(TARGET_I386)
 s-c_cpu-eip = pc;
 #elif defined (TARGET_PPC)
@@ -2228,7 +2228,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 }
 break;
 case 'g':
-cpu_synchronize_state(s-g_cpu);
+cpu_synchronize_state(ENV_GET_CPU(s-g_cpu));
 env = s-g_cpu;
 len = 0;
 for (addr = 0; addr  num_g_regs; addr++) {
@@ -2239,7 +2239,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 put_packet(s, buf);
 break;
 case 'G':
-cpu_synchronize_state(s-g_cpu);
+cpu_synchronize_state(ENV_GET_CPU(s-g_cpu));
 env = s-g_cpu;
 registers = mem_buf;
 len = strlen(p) / 2;
@@ -2407,7 +2407,7 @@ static int gdb_handle_packet(GDBState *s, const char 
*line_buf)
 env = find_cpu(thread);
 if (env != NULL) {
 CPUState *cpu = ENV_GET_CPU(env);
-cpu_synchronize_state(env);
+cpu_synchronize_state(cpu);
 len = snprintf((char *)mem_buf, sizeof(mem_buf),
CPU#%d [%s], cpu-cpu_index,
cpu-halted ? halted  : running);
diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c
index 8f80425..bd0bdd8 100644
--- a/hw/i386/kvm/apic.c
+++ b/hw/i386/kvm/apic.c
@@ -129,7 +129,7 @@ static void do_inject_external_nmi(void *data)
 uint32_t lvt;
 int ret;
 
-cpu_synchronize_state(s-cpu-env);
+cpu_synchronize_state(cpu);
 
 lvt = s-lvt[APIC_LVT_LINT1];
 if (!(lvt  APIC_LVT_MASKED)  ((lvt  8)  7) == APIC_DM_NMI) {
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index 655483b..f93629f 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -456,7 +456,7 @@ void vapic_report_tpr_access(DeviceState *dev, CPUState 
*cs, target_ulong ip,
 X86CPU *cpu = X86_CPU(cs);
 CPUX86State *env = cpu-env;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(cs);
 
 if (evaluate_tpr_instruction(s, env, ip, access)  0) {
 if (s-state == VAPIC_ACTIVE) {
@@ -627,7 +627,7 @@ static void vapic_write(void *opaque, hwaddr addr, uint64_t 
data,
 hwaddr rom_paddr;
 VAPICROMState *s = opaque;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(CPU(x86_env_get_cpu(env)));
 
 /*
  * The VAPIC supports two PIO-based hypercalls, both via port 0x7E.
diff --git a/hw/misc/vmport.c b/hw/misc/vmport.c
index 57b71f5..8363dfd 100644
--- a/hw/misc/vmport.c
+++ b/hw/misc/vmport.c
@@ -66,7 +66,7 @@ static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
 unsigned char command;
 uint32_t eax;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(CPU(x86_env_get_cpu(env)));
 
 eax = env-regs[R_EAX];
 if (eax != VMPORT_MAGIC)
diff --git a/hw/ppc/ppce500_spin.c b/hw/ppc/ppce500_spin.c
index 1290d37..ea65414 100644
--- a/hw/ppc/ppce500_spin.c
+++ b/hw/ppc/ppce500_spin.c
@@ -98,7 +98,7 @@ static void spin_kick(void *data)
 hwaddr map_size = 64 * 1024 * 1024;
 hwaddr map_start;
 
-cpu_synchronize_state(env);
+cpu_synchronize_state(cpu);
 stl_p(curspin-pir, env-spr[SPR_PIR]);
 env-nip = ldq_p(curspin-addr)  (map_size - 1);
 env-gpr[3

[PULL 15/24] cpu: Turn cpu_dump_{state,statistics}() into CPUState hooks

2013-06-28 Thread Andreas Färber
Make cpustats monitor command available unconditionally.

Prepares for changing kvm_handle_internal_error() and kvm_cpu_exec()
arguments to CPUState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 bsd-user/main.c   |  3 ++-
 cpus.c|  2 +-
 exec.c|  3 ++-
 include/exec/cpu-all.h| 10 --
 include/qemu/log.h|  2 +-
 include/qom/cpu.h | 42 ++
 kvm-all.c |  4 ++--
 linux-user/main.c | 38 +++---
 monitor.c | 13 ++---
 qom/cpu.c | 22 +-
 stubs/cpus.c  |  1 +
 target-alpha/cpu-qom.h|  2 ++
 target-alpha/cpu.c|  1 +
 target-alpha/helper.c |  6 --
 target-arm/arm-semi.c |  3 ++-
 target-arm/cpu-qom.h  |  3 +++
 target-arm/cpu.c  |  1 +
 target-arm/translate.c|  6 --
 target-cris/cpu-qom.h |  3 +++
 target-cris/cpu.c |  1 +
 target-cris/helper.c  |  4 +++-
 target-cris/translate.c   |  6 --
 target-i386/cpu-qom.h |  3 +++
 target-i386/cpu.c |  1 +
 target-i386/helper.c  |  7 ---
 target-lm32/cpu-qom.h |  2 ++
 target-lm32/cpu.c |  1 +
 target-lm32/translate.c   |  6 --
 target-m68k/cpu-qom.h |  2 ++
 target-m68k/cpu.c |  1 +
 target-m68k/translate.c   |  6 --
 target-microblaze/cpu-qom.h   |  2 ++
 target-microblaze/cpu.c   |  1 +
 target-microblaze/helper.c|  4 +++-
 target-microblaze/translate.c |  6 --
 target-mips/cpu-qom.h |  2 ++
 target-mips/cpu.c |  1 +
 target-mips/translate.c   |  6 --
 target-moxie/cpu.c|  3 ++-
 target-moxie/cpu.h|  2 ++
 target-moxie/helper.c |  4 +++-
 target-moxie/translate.c  |  6 --
 target-openrisc/cpu.c |  1 +
 target-openrisc/cpu.h |  2 ++
 target-openrisc/translate.c   | 12 +++-
 target-ppc/cpu-qom.h  |  4 
 target-ppc/translate.c| 15 +--
 target-ppc/translate_init.c   |  2 ++
 target-s390x/cpu-qom.h|  2 ++
 target-s390x/cpu.c|  1 +
 target-s390x/translate.c  |  6 --
 target-sh4/cpu-qom.h  |  2 ++
 target-sh4/cpu.c  |  1 +
 target-sh4/translate.c|  7 ---
 target-sparc/cpu-qom.h|  2 ++
 target-sparc/cpu.c|  7 +--
 target-unicore32/cpu-qom.h|  2 ++
 target-unicore32/cpu.c|  1 +
 target-unicore32/translate.c  |  6 --
 target-xtensa/cpu-qom.h   |  2 ++
 target-xtensa/cpu.c   |  1 +
 target-xtensa/op_helper.c |  4 +++-
 target-xtensa/translate.c |  6 --
 63 files changed, 242 insertions(+), 86 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 572f13a..75dbd7f 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -511,6 +511,7 @@ static void flush_windows(CPUSPARCState *env)
 
 void cpu_loop(CPUSPARCState *env)
 {
+CPUState *cs = CPU(sparc_env_get_cpu(env));
 int trapnr, ret, syscall_nr;
 //target_siginfo_t info;
 
@@ -659,7 +660,7 @@ void cpu_loop(CPUSPARCState *env)
 badtrap:
 #endif
 printf (Unhandled trap: 0x%x\n, trapnr);
-cpu_dump_state(env, stderr, fprintf, 0);
+cpu_dump_state(cs, stderr, fprintf, 0);
 exit (1);
 }
 process_pending_signals (env);
diff --git a/cpus.c b/cpus.c
index 40bf64c..4c7e329 100644
--- a/cpus.c
+++ b/cpus.c
@@ -397,7 +397,7 @@ void hw_error(const char *fmt, ...)
 for (env = first_cpu; env != NULL; env = env-next_cpu) {
 cpu = ENV_GET_CPU(env);
 fprintf(stderr, CPU #%d:\n, cpu-cpu_index);
-cpu_dump_state(env, stderr, fprintf, CPU_DUMP_FPU);
+cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_FPU);
 }
 va_end(ap);
 abort();
diff --git a/exec.c b/exec.c
index 2d02b11..c49806c 100644
--- a/exec.c
+++ b/exec.c
@@ -600,6 +600,7 @@ void cpu_single_step(CPUArchState *env, int enabled)
 
 void cpu_abort(CPUArchState *env, const char *fmt, ...)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 va_list ap;
 va_list ap2;
 
@@ -608,7 +609,7 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
 fprintf(stderr, qemu: fatal: );
 vfprintf(stderr, fmt, ap);
 fprintf(stderr, \n);
-cpu_dump_state(env, stderr, fprintf, CPU_DUMP_FPU | CPU_DUMP_CCOP);
+cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_FPU | CPU_DUMP_CCOP);
 if (qemu_log_enabled()) {
 qemu_log(qemu: fatal: );
 qemu_log_vprintf(fmt, ap2);
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index e1cc62e..35bdf85 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -355,16 +355,6 @@ int page_check_range(target_ulong start, target_ulong len, 
int flags);
 
 CPUArchState

[PULL 13/24] kvm: Change kvm_set_signal_mask() argument to CPUState

2013-06-28 Thread Andreas Färber
CPUArchState is no longer needed.

Prepares for changing qemu_kvm_init_cpu_signals() argument to CPUState.

Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c   | 3 ++-
 include/sysemu/kvm.h | 2 +-
 kvm-all.c| 3 +--
 kvm-stub.c   | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cpus.c b/cpus.c
index 37369ae..7d6b166 100644
--- a/cpus.c
+++ b/cpus.c
@@ -570,6 +570,7 @@ static void dummy_signal(int sig)
 
 static void qemu_kvm_init_cpu_signals(CPUArchState *env)
 {
+CPUState *cpu = ENV_GET_CPU(env);
 int r;
 sigset_t set;
 struct sigaction sigact;
@@ -581,7 +582,7 @@ static void qemu_kvm_init_cpu_signals(CPUArchState *env)
 pthread_sigmask(SIG_BLOCK, NULL, set);
 sigdelset(set, SIG_IPI);
 sigdelset(set, SIGBUS);
-r = kvm_set_signal_mask(env, set);
+r = kvm_set_signal_mask(cpu, set);
 if (r) {
 fprintf(stderr, kvm_set_signal_mask: %s\n, strerror(-r));
 exit(1);
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 06da2b3..5adb044 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -166,7 +166,7 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 void kvm_remove_all_breakpoints(CPUArchState *current_env);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
 #ifndef _WIN32
-int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset);
+int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
 #endif
 
 int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
diff --git a/kvm-all.c b/kvm-all.c
index eee294b..f1031e0 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2039,9 +2039,8 @@ void kvm_remove_all_breakpoints(CPUArchState *current_env)
 }
 #endif /* !KVM_CAP_SET_GUEST_DEBUG */
 
-int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset)
+int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_signal_mask *sigmask;
 int r;
 
diff --git a/kvm-stub.c b/kvm-stub.c
index 128faf7..50af700 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -100,7 +100,7 @@ void kvm_remove_all_breakpoints(CPUArchState *current_env)
 }
 
 #ifndef _WIN32
-int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset)
+int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset)
 {
 abort();
 }
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 08/24] kvm: Change kvm_cpu_synchronize_state() argument to CPUState

2013-06-28 Thread Andreas Färber
It no longer relies on CPUArchState since 20d695a.

Reviewed-by: liguang lig.f...@cn.fujitsu.com
Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/ppc/spapr_rtas.c  |  2 +-
 include/sysemu/kvm.h |  4 ++--
 kvm-all.c|  4 +---
 kvm-stub.c   |  2 +-
 target-i386/kvm.c| 10 +-
 5 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index f4bd3c9..42ed7dc 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -184,7 +184,7 @@ static void rtas_start_cpu(sPAPREnvironment *spapr,
 /* This will make sure qemu state is up to date with kvm, and
  * mark it dirty so our changes get flushed back before the
  * new cpu enters */
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 
 env-msr = (1ULL  MSR_SF) | (1ULL  MSR_ME);
 env-nip = start;
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 8b19322..3e1db28 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -259,14 +259,14 @@ int kvm_check_extension(KVMState *s, unsigned int 
extension);
 
 uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
   uint32_t index, int reg);
-void kvm_cpu_synchronize_state(CPUArchState *env);
+void kvm_cpu_synchronize_state(CPUState *cpu);
 
 /* generic hooks - to be moved/refactored once there are more users */
 
 static inline void cpu_synchronize_state(CPUArchState *env)
 {
 if (kvm_enabled()) {
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(ENV_GET_CPU(env));
 }
 }
 
diff --git a/kvm-all.c b/kvm-all.c
index e6b262f..eee294b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1590,10 +1590,8 @@ static void do_kvm_cpu_synchronize_state(void *arg)
 }
 }
 
-void kvm_cpu_synchronize_state(CPUArchState *env)
+void kvm_cpu_synchronize_state(CPUState *cpu)
 {
-CPUState *cpu = ENV_GET_CPU(env);
-
 if (!cpu-kvm_vcpu_dirty) {
 run_on_cpu(cpu, do_kvm_cpu_synchronize_state, cpu);
 }
diff --git a/kvm-stub.c b/kvm-stub.c
index 22eaff0..128faf7 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -42,7 +42,7 @@ void kvm_flush_coalesced_mmio_buffer(void)
 {
 }
 
-void kvm_cpu_synchronize_state(CPUArchState *env)
+void kvm_cpu_synchronize_state(CPUState *cpu)
 {
 }
 
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 9ffb6ca..0b0adfd 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1857,7 +1857,7 @@ int kvm_arch_process_async_events(CPUState *cs)
 
 cs-interrupt_request = ~CPU_INTERRUPT_MCE;
 
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 
 if (env-exception_injected == EXCP08_DBLE) {
 /* this means triple fault */
@@ -1888,16 +1888,16 @@ int kvm_arch_process_async_events(CPUState *cs)
 cs-halted = 0;
 }
 if (cs-interrupt_request  CPU_INTERRUPT_INIT) {
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 do_cpu_init(cpu);
 }
 if (cs-interrupt_request  CPU_INTERRUPT_SIPI) {
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 do_cpu_sipi(cpu);
 }
 if (cs-interrupt_request  CPU_INTERRUPT_TPR) {
 cs-interrupt_request = ~CPU_INTERRUPT_TPR;
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 apic_handle_tpr_access_report(env-apic_state, env-eip,
   env-tpr_access_type);
 }
@@ -2184,7 +2184,7 @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs)
 X86CPU *cpu = X86_CPU(cs);
 CPUX86State *env = cpu-env;
 
-kvm_cpu_synchronize_state(env);
+kvm_cpu_synchronize_state(cs);
 return !(env-cr[0]  CR0_PE_MASK) ||
((env-segs[R_CS].selector   3) != 3);
 }
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PULL 17/24] kvm: Change kvm_cpu_exec() argument to CPUState

2013-06-28 Thread Andreas Färber
It no longer uses CPUArchState.

Prepares for changing qemu_kvm_cpu_thread_fn() opaque to CPUState.

Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 cpus.c   | 2 +-
 include/sysemu/kvm.h | 2 +-
 kvm-all.c| 3 +--
 kvm-stub.c   | 4 ++--
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/cpus.c b/cpus.c
index 4c7e329..12f6f32 100644
--- a/cpus.c
+++ b/cpus.c
@@ -752,7 +752,7 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
 
 while (1) {
 if (cpu_can_run(cpu)) {
-r = kvm_cpu_exec(env);
+r = kvm_cpu_exec(cpu);
 if (r == EXCP_DEBUG) {
 cpu_handle_guest_debug(env);
 }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 5adb044..fe8bc40 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -147,9 +147,9 @@ int kvm_has_gsi_routing(void);
 int kvm_has_intx_set_mask(void);
 
 int kvm_init_vcpu(CPUState *cpu);
+int kvm_cpu_exec(CPUState *cpu);
 
 #ifdef NEED_CPU_H
-int kvm_cpu_exec(CPUArchState *env);
 
 #if !defined(CONFIG_USER_ONLY)
 void *kvm_ram_alloc(ram_addr_t size);
diff --git a/kvm-all.c b/kvm-all.c
index d3e5e5e..7a1684e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1607,9 +1607,8 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
 cpu-kvm_vcpu_dirty = false;
 }
 
-int kvm_cpu_exec(CPUArchState *env)
+int kvm_cpu_exec(CPUState *cpu)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_run *run = cpu-kvm_run;
 int ret, run_ret;
 
diff --git a/kvm-stub.c b/kvm-stub.c
index 50af700..5457fe8 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -54,9 +54,9 @@ void kvm_cpu_synchronize_post_init(CPUState *cpu)
 {
 }
 
-int kvm_cpu_exec(CPUArchState *env)
+int kvm_cpu_exec(CPUState *cpu)
 {
-abort ();
+abort();
 }
 
 int kvm_has_sync_mmu(void)
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH qom-cpu v2 20/29] kvm: Change kvm_remove_all_breakpoints() argument to CPUState

2013-06-27 Thread Andreas Färber
Am 17.06.2013 18:17, schrieb Paolo Bonzini:
 Il 16/06/2013 17:57, Andreas Färber ha scritto:
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
  gdbstub.c| 2 +-
  include/sysemu/kvm.h | 2 +-
  kvm-all.c| 5 ++---
  kvm-stub.c   | 2 +-
  4 files changed, 5 insertions(+), 6 deletions(-)

 diff --git a/gdbstub.c b/gdbstub.c
 index 3101a43..9e7f7a1 100644
 --- a/gdbstub.c
 +++ b/gdbstub.c
 @@ -2019,7 +2019,7 @@ static void gdb_breakpoint_remove_all(void)
  CPUArchState *env;
  
  if (kvm_enabled()) {
 -kvm_remove_all_breakpoints(gdbserver_state-c_cpu);
 +kvm_remove_all_breakpoints(ENV_GET_CPU(gdbserver_state-c_cpu));
 
 Planning to make gdbserver_state take a CPUState, too?

Yes, I'm still working on that: The qom-cpu-11 series is already about
as large as this one and still has only two out of three CPUArchState
fields converted. ;)

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v3 01/14] kvm: Free current_cpu identifier

2013-06-26 Thread Andreas Färber
Since CPU loops are done as last step in kvm_{insert,remove}_breakpoint()
and kvm_remove_all_breakpoints(), we do not need to distinguish between
invoking CPU and iterated CPUs and can thereby free the identifier for
use as a global variable.

Acked-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 include/sysemu/kvm.h | 10 +-
 kvm-all.c| 39 +--
 kvm-stub.c   |  6 +++---
 3 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index fe8bc40..c88aee9 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -159,11 +159,11 @@ void *kvm_arch_ram_alloc(ram_addr_t size);
 void kvm_setup_guest_memory(void *start, size_t size);
 void kvm_flush_coalesced_mmio_buffer(void);
 
-int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-void kvm_remove_all_breakpoints(CPUArchState *current_env);
+void kvm_remove_all_breakpoints(CPUArchState *env);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
 #ifndef _WIN32
 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
@@ -241,9 +241,9 @@ struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState 
*cpu,
 
 int kvm_sw_breakpoints_active(CPUState *cpu);
 
-int kvm_arch_insert_sw_breakpoint(CPUState *current_cpu,
+int kvm_arch_insert_sw_breakpoint(CPUState *cpu,
   struct kvm_sw_breakpoint *bp);
-int kvm_arch_remove_sw_breakpoint(CPUState *current_cpu,
+int kvm_arch_remove_sw_breakpoint(CPUState *cpu,
   struct kvm_sw_breakpoint *bp);
 int kvm_arch_insert_hw_breakpoint(target_ulong addr,
   target_ulong len, int type);
diff --git a/kvm-all.c b/kvm-all.c
index 7a1684e..d074597 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1896,16 +1896,15 @@ int kvm_update_guest_debug(CPUArchState *env, unsigned 
long reinject_trap)
 return data.err;
 }
 
-int kvm_insert_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_insert_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *current_cpu = ENV_GET_CPU(current_env);
+CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
-CPUArchState *env;
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_cpu, addr);
+bp = kvm_find_sw_breakpoint(cpu, addr);
 if (bp) {
 bp-use_count++;
 return 0;
@@ -1918,14 +1917,13 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 
 bp-pc = addr;
 bp-use_count = 1;
-err = kvm_arch_insert_sw_breakpoint(current_cpu, bp);
+err = kvm_arch_insert_sw_breakpoint(cpu, bp);
 if (err) {
 g_free(bp);
 return err;
 }
 
-QTAILQ_INSERT_HEAD(current_cpu-kvm_state-kvm_sw_breakpoints,
-  bp, entry);
+QTAILQ_INSERT_HEAD(cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
 } else {
 err = kvm_arch_insert_hw_breakpoint(addr, len, type);
 if (err) {
@@ -1942,16 +1940,15 @@ int kvm_insert_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-int kvm_remove_breakpoint(CPUArchState *current_env, target_ulong addr,
+int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type)
 {
-CPUState *current_cpu = ENV_GET_CPU(current_env);
+CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp;
-CPUArchState *env;
 int err;
 
 if (type == GDB_BREAKPOINT_SW) {
-bp = kvm_find_sw_breakpoint(current_cpu, addr);
+bp = kvm_find_sw_breakpoint(cpu, addr);
 if (!bp) {
 return -ENOENT;
 }
@@ -1961,12 +1958,12 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-err = kvm_arch_remove_sw_breakpoint(current_cpu, bp);
+err = kvm_arch_remove_sw_breakpoint(cpu, bp);
 if (err) {
 return err;
 }
 
-QTAILQ_REMOVE(current_cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
+QTAILQ_REMOVE(cpu-kvm_state-kvm_sw_breakpoints, bp, entry);
 g_free(bp);
 } else {
 err = kvm_arch_remove_hw_breakpoint(addr, len, type);
@@ -1984,16 +1981,14 @@ int kvm_remove_breakpoint(CPUArchState *current_env, 
target_ulong addr,
 return 0;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *current_env)
+void kvm_remove_all_breakpoints(CPUArchState

[PATCH qom-cpu v3 12/14] target-s390x: Don't overuse ENV_GET_CPU()

2013-06-26 Thread Andreas Färber
Commit 3474b679486caa8f6448bae974e131370f360c13 (Utilize selective
runtime reg sync for hot code paths) introduced two uses of
ENV_GET_CPU() inside target-s390x/ KVM code. In one case we can use a
direct CPU() cast instead.

Cc: Jason J. Herne jjhe...@us.ibm.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-s390x/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b524c35..4660074 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -469,7 +469,7 @@ static int kvm_handle_css_inst(S390CPU *cpu, struct kvm_run 
*run,
 int r = 0;
 int no_cc = 0;
 CPUS390XState *env = cpu-env;
-CPUState *cs = ENV_GET_CPU(env);
+CPUState *cs = CPU(cpu);
 
 if (ipa0 != 0xb2) {
 /* Not handled for now. */
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v3 13/14] target-s390x: Change handle_{hypercall,diag}() argument to S390CPU

2013-06-26 Thread Andreas Färber
This allows to get rid of the last remaining ENV_GET_CPU() in
target-s390x/ by using CPU() cast directly on the argument.

Cc: Jason J. Herne jjhe...@us.ibm.com
Signed-off-by: Andreas Färber afaer...@suse.de
---
 target-s390x/kvm.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 4660074..33ca7a7 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -607,9 +607,10 @@ static int handle_priv(S390CPU *cpu, struct kvm_run *run,
 return r;
 }
 
-static int handle_hypercall(CPUS390XState *env, struct kvm_run *run)
+static int handle_hypercall(S390CPU *cpu, struct kvm_run *run)
 {
-CPUState *cs = ENV_GET_CPU(env);
+CPUState *cs = CPU(cpu);
+CPUS390XState *env = cpu-env;
 
 kvm_s390_get_registers_partial(cs);
 cs-kvm_vcpu_dirty = true;
@@ -618,13 +619,13 @@ static int handle_hypercall(CPUS390XState *env, struct 
kvm_run *run)
 return 0;
 }
 
-static int handle_diag(CPUS390XState *env, struct kvm_run *run, int ipb_code)
+static int handle_diag(S390CPU *cpu, struct kvm_run *run, int ipb_code)
 {
 int r = 0;
 
 switch (ipb_code) {
 case DIAG_KVM_HYPERCALL:
-r = handle_hypercall(env, run);
+r = handle_hypercall(cpu, run);
 break;
 case DIAG_KVM_BREAKPOINT:
 sleep(10);
@@ -735,7 +736,6 @@ out:
 
 static int handle_instruction(S390CPU *cpu, struct kvm_run *run)
 {
-CPUS390XState *env = cpu-env;
 unsigned int ipa0 = (run-s390_sieic.ipa  0xff00);
 uint8_t ipa1 = run-s390_sieic.ipa  0x00ff;
 int ipb_code = (run-s390_sieic.ipb  0x0fff)  16;
@@ -749,7 +749,7 @@ static int handle_instruction(S390CPU *cpu, struct kvm_run 
*run)
 r = handle_priv(cpu, run, ipa0  8, ipa1);
 break;
 case IPA0_DIAG:
-r = handle_diag(env, run, ipb_code);
+r = handle_diag(cpu, run, ipb_code);
 break;
 case IPA0_SIGP:
 r = handle_sigp(cpu, run, ipa1);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH qom-cpu v3 03/14] kvm: Change kvm_remove_all_breakpoints() argument to CPUState

2013-06-26 Thread Andreas Färber
Acked-by: Paolo Bonzini pbonz...@redhat.com
Reviewed-by: Richard Henderson r...@twiddle.net
Signed-off-by: Andreas Färber afaer...@suse.de
---
 gdbstub.c| 2 +-
 include/sysemu/kvm.h | 2 +-
 kvm-all.c| 6 +++---
 kvm-stub.c   | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 3101a43..9e7f7a1 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2019,7 +2019,7 @@ static void gdb_breakpoint_remove_all(void)
 CPUArchState *env;
 
 if (kvm_enabled()) {
-kvm_remove_all_breakpoints(gdbserver_state-c_cpu);
+kvm_remove_all_breakpoints(ENV_GET_CPU(gdbserver_state-c_cpu));
 return;
 }
 
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index c88aee9..9460d5a 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -163,7 +163,7 @@ int kvm_insert_breakpoint(CPUArchState *env, target_ulong 
addr,
   target_ulong len, int type);
 int kvm_remove_breakpoint(CPUArchState *env, target_ulong addr,
   target_ulong len, int type);
-void kvm_remove_all_breakpoints(CPUArchState *env);
+void kvm_remove_all_breakpoints(CPUState *cpu);
 int kvm_update_guest_debug(CPUArchState *env, unsigned long reinject_trap);
 #ifndef _WIN32
 int kvm_set_signal_mask(CPUState *cpu, const sigset_t *sigset);
diff --git a/kvm-all.c b/kvm-all.c
index d074597..ee0ee02 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1981,11 +1981,11 @@ int kvm_remove_breakpoint(CPUArchState *env, 
target_ulong addr,
 return 0;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
-CPUState *cpu = ENV_GET_CPU(env);
 struct kvm_sw_breakpoint *bp, *next;
 KVMState *s = cpu-kvm_state;
+CPUArchState *env;
 
 QTAILQ_FOREACH_SAFE(bp, s-kvm_sw_breakpoints, entry, next) {
 if (kvm_arch_remove_sw_breakpoint(cpu, bp) != 0) {
@@ -2026,7 +2026,7 @@ int kvm_remove_breakpoint(CPUArchState *env, target_ulong 
addr,
 return -EINVAL;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
 }
 #endif /* !KVM_CAP_SET_GUEST_DEBUG */
diff --git a/kvm-stub.c b/kvm-stub.c
index 76da61e..a6c2b01 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -95,7 +95,7 @@ int kvm_remove_breakpoint(CPUArchState *env, target_ulong 
addr,
 return -EINVAL;
 }
 
-void kvm_remove_all_breakpoints(CPUArchState *env)
+void kvm_remove_all_breakpoints(CPUState *cpu)
 {
 }
 
-- 
1.8.1.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH qom-cpu v2 02/29] kvm: Change cpu_synchronize_state() argument to CPUState

2013-06-21 Thread Andreas Färber
Am 18.06.2013 11:39, schrieb Igor Mammedov:
 On Sun, 16 Jun 2013 17:57:22 +0200
 Andreas Färber afaer...@suse.de wrote:
 
 Change Monitor::mon_cpu to CPUState as well.
 In cpu_synchronize_all_states() use qemu_for_each_cpu() now.

 Reviewed-by: liguang lig.f...@cn.fujitsu.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
[...]
 diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
 index 655483b..f93629f 100644
 --- a/hw/i386/kvmvapic.c
 +++ b/hw/i386/kvmvapic.c
 @@ -456,7 +456,7 @@ void vapic_report_tpr_access(DeviceState *dev, CPUState 
 *cs, target_ulong ip,
  X86CPU *cpu = X86_CPU(cs);
  CPUX86State *env = cpu-env;
  
 -cpu_synchronize_state(env);
 +cpu_synchronize_state(cs);
  
  if (evaluate_tpr_instruction(s, env, ip, access)  0) {
  if (s-state == VAPIC_ACTIVE) {
 @@ -627,7 +627,7 @@ static void vapic_write(void *opaque, hwaddr addr, 
 uint64_t data,
  hwaddr rom_paddr;
  VAPICROMState *s = opaque;
  
 -cpu_synchronize_state(env);
 +cpu_synchronize_state(CPU(x86_env_get_cpu(env)));
 why not use ENV_GET_CPU() here and in several other places below to make it
 uniform?

Explained that in another reply. There's currently about four misuses in
the tree, and there had been previous patches to clean some others up;
after the series only one remains in target-ppc/mmu-hash.c.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH qom-cpu v2 01/29] kvm: Change kvm_cpu_synchronize_state() argument to CPUState

2013-06-18 Thread Andreas Färber
Am 17.06.2013 18:15, schrieb Paolo Bonzini:
 Il 16/06/2013 17:57, Andreas Färber ha scritto:
 It no longer relies on CPUArchState since 20d695a.

 Reviewed-by: liguang lig.f...@cn.fujitsu.com
 Signed-off-by: Andreas Färber afaer...@suse.de
 ---
  hw/ppc/spapr_rtas.c  |  2 +-
  include/sysemu/kvm.h |  4 ++--
  kvm-all.c|  4 +---
  kvm-stub.c   |  2 +-
  target-i386/kvm.c| 10 +-
  5 files changed, 10 insertions(+), 12 deletions(-)
[...]
 
 Acked-by: Paolo Bonzini pbonz...@redhat.com

Thanks, applied to qom-cpu:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   4   >