qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] spapr: compute interrupt vector address from LPCR
@ 2016-03-24 15:28 Cédric Le Goater
  2016-03-25 11:45 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
  2016-03-29  4:35 ` [Qemu-devel] " David Gibson
  0 siblings, 2 replies; 4+ messages in thread
From: Cédric Le Goater @ 2016-03-24 15:28 UTC (permalink / raw)
  To: David Gibson
  Cc: Thomas Huth, Cédric Le Goater, qemu-ppc, qemu-devel,
	Greg Kurz

This address is changed by the linux kernel using the H_SET_MODE hcall
and needs to be migrated in order to restart a spapr VM running in
TCG. This can be done using the AIL bits from the LPCR register.

The patch introduces a spapr_h_set_mode_resource_addr() helper to
share some code with the H_SET_MODE hcall.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
 hw/ppc/spapr.c         |   21 +++++++++++++++++++++
 hw/ppc/spapr_hcall.c   |   13 ++-----------
 include/hw/ppc/spapr.h |   14 ++++++++++++++
 3 files changed, 37 insertions(+), 11 deletions(-)

Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
===================================================================
--- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr.c
+++ qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
@@ -1244,6 +1244,24 @@ static bool spapr_vga_init(PCIBus *pci_b
     }
 }
 
+static int load_excp_prefix(void)
+{
+    CPUState *cs;
+
+    CPU_FOREACH(cs) {
+        CPUPPCState *env = &POWERPC_CPU(cs)->env;
+        int ail = (env->spr[SPR_LPCR] & LPCR_AIL) >> LPCR_AIL_SHIFT;
+
+        env->excp_prefix = spapr_h_set_mode_resource_addr(ail);
+        if (env->excp_prefix == H_UNSUPPORTED_FLAG) {
+            error_report("LPCR has an invalid AIL value");
+            return -EINVAL;
+        }
+    }
+
+    return 0;
+}
+
 static int spapr_post_load(void *opaque, int version_id)
 {
     sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
@@ -1257,6 +1275,9 @@ static int spapr_post_load(void *opaque,
         err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
     }
 
+    if (!err) {
+        err = load_excp_prefix();
+    }
     return err;
 }
 
Index: qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
===================================================================
--- qemu-dgibson-for-2.6.git.orig/include/hw/ppc/spapr.h
+++ qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
@@ -561,6 +561,20 @@ struct sPAPREventLogEntry {
     QTAILQ_ENTRY(sPAPREventLogEntry) next;
 };
 
+static inline target_ulong spapr_h_set_mode_resource_addr(target_ulong mflags)
+{
+    switch (mflags) {
+    case H_SET_MODE_ADDR_TRANS_NONE:
+        return 0;
+    case H_SET_MODE_ADDR_TRANS_0001_8000:
+        return 0x18000;
+    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
+        return 0xC000000000004000ULL;
+    default:
+        return H_UNSUPPORTED_FLAG;
+    }
+}
+
 void spapr_events_init(sPAPRMachineState *sm);
 void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
 int spapr_h_cas_compose_response(sPAPRMachineState *sm,
Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
===================================================================
--- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr_hcall.c
+++ qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
@@ -835,17 +835,8 @@ static target_ulong h_set_mode_resource_
         return H_P4;
     }
 
-    switch (mflags) {
-    case H_SET_MODE_ADDR_TRANS_NONE:
-        prefix = 0;
-        break;
-    case H_SET_MODE_ADDR_TRANS_0001_8000:
-        prefix = 0x18000;
-        break;
-    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
-        prefix = 0xC000000000004000ULL;
-        break;
-    default:
+    prefix = spapr_h_set_mode_resource_addr(mflags);
+    if (prefix == H_UNSUPPORTED_FLAG) {
         return H_UNSUPPORTED_FLAG;
     }
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: compute interrupt vector address from LPCR
  2016-03-24 15:28 [Qemu-devel] [PATCH] spapr: compute interrupt vector address from LPCR Cédric Le Goater
@ 2016-03-25 11:45 ` Greg Kurz
  2016-03-29  7:13   ` Cédric Le Goater
  2016-03-29  4:35 ` [Qemu-devel] " David Gibson
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Kurz @ 2016-03-25 11:45 UTC (permalink / raw)
  To: Cédric Le Goater; +Cc: Thomas Huth, qemu-ppc, qemu-devel, David Gibson

Hi Cedric,

On Thu, 24 Mar 2016 16:28:53 +0100
Cédric Le Goater <clg@fr.ibm.com> wrote:

> This address is changed by the linux kernel using the H_SET_MODE hcall
> and needs to be migrated in order to restart a spapr VM running in
> TCG. This can be done using the AIL bits from the LPCR register.
> 
> The patch introduces a spapr_h_set_mode_resource_addr() helper to
> share some code with the H_SET_MODE hcall.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>  hw/ppc/spapr.c         |   21 +++++++++++++++++++++
>  hw/ppc/spapr_hcall.c   |   13 ++-----------
>  include/hw/ppc/spapr.h |   14 ++++++++++++++
>  3 files changed, 37 insertions(+), 11 deletions(-)
> 
> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr.c
> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
> @@ -1244,6 +1244,24 @@ static bool spapr_vga_init(PCIBus *pci_b
>      }
>  }
> 
> +static int load_excp_prefix(void)
> +{
> +    CPUState *cs;
> +
> +    CPU_FOREACH(cs) {
> +        CPUPPCState *env = &POWERPC_CPU(cs)->env;

And how are we sure env contains the migrated register values ?

Actually, this "works" because vmstate_ppc_cpu is registered before vmstate_spapr,
and the same ordering happens to be used when sending state over the wire, but it
looks wrong.

The excp_prefix should be restored in cpu_post_load(), unless I'm missing
something.

Cheers.

--
Greg

> +        int ail = (env->spr[SPR_LPCR] & LPCR_AIL) >> LPCR_AIL_SHIFT;
> +
> +        env->excp_prefix = spapr_h_set_mode_resource_addr(ail);
> +        if (env->excp_prefix == H_UNSUPPORTED_FLAG) {
> +            error_report("LPCR has an invalid AIL value");
> +            return -EINVAL;
> +        }
> +    }
> +
> +    return 0;
> +}
> +
>  static int spapr_post_load(void *opaque, int version_id)
>  {
>      sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
> @@ -1257,6 +1275,9 @@ static int spapr_post_load(void *opaque,
>          err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
>      }
> 
> +    if (!err) {
> +        err = load_excp_prefix();
> +    }
>      return err;
>  }
> 
> Index: qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/include/hw/ppc/spapr.h
> +++ qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
> @@ -561,6 +561,20 @@ struct sPAPREventLogEntry {
>      QTAILQ_ENTRY(sPAPREventLogEntry) next;
>  };
> 
> +static inline target_ulong spapr_h_set_mode_resource_addr(target_ulong mflags)
> +{
> +    switch (mflags) {
> +    case H_SET_MODE_ADDR_TRANS_NONE:
> +        return 0;
> +    case H_SET_MODE_ADDR_TRANS_0001_8000:
> +        return 0x18000;
> +    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
> +        return 0xC000000000004000ULL;
> +    default:
> +        return H_UNSUPPORTED_FLAG;
> +    }
> +}
> +
>  void spapr_events_init(sPAPRMachineState *sm);
>  void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
>  int spapr_h_cas_compose_response(sPAPRMachineState *sm,
> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr_hcall.c
> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
> @@ -835,17 +835,8 @@ static target_ulong h_set_mode_resource_
>          return H_P4;
>      }
> 
> -    switch (mflags) {
> -    case H_SET_MODE_ADDR_TRANS_NONE:
> -        prefix = 0;
> -        break;
> -    case H_SET_MODE_ADDR_TRANS_0001_8000:
> -        prefix = 0x18000;
> -        break;
> -    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
> -        prefix = 0xC000000000004000ULL;
> -        break;
> -    default:
> +    prefix = spapr_h_set_mode_resource_addr(mflags);
> +    if (prefix == H_UNSUPPORTED_FLAG) {
>          return H_UNSUPPORTED_FLAG;
>      }
> 
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] spapr: compute interrupt vector address from LPCR
  2016-03-24 15:28 [Qemu-devel] [PATCH] spapr: compute interrupt vector address from LPCR Cédric Le Goater
  2016-03-25 11:45 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2016-03-29  4:35 ` David Gibson
  1 sibling, 0 replies; 4+ messages in thread
From: David Gibson @ 2016-03-29  4:35 UTC (permalink / raw)
  To: Cédric Le Goater; +Cc: Thomas Huth, qemu-ppc, qemu-devel, Greg Kurz

[-- Attachment #1: Type: text/plain, Size: 4135 bytes --]

On Thu, Mar 24, 2016 at 04:28:53PM +0100, Cédric Le Goater wrote:
> This address is changed by the linux kernel using the H_SET_MODE hcall
> and needs to be migrated in order to restart a spapr VM running in
> TCG. This can be done using the AIL bits from the LPCR register.
> 
> The patch introduces a spapr_h_set_mode_resource_addr() helper to
> share some code with the H_SET_MODE hcall.
> 
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>  hw/ppc/spapr.c         |   21 +++++++++++++++++++++
>  hw/ppc/spapr_hcall.c   |   13 ++-----------
>  include/hw/ppc/spapr.h |   14 ++++++++++++++
>  3 files changed, 37 insertions(+), 11 deletions(-)
> 
> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr.c
> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
> @@ -1244,6 +1244,24 @@ static bool spapr_vga_init(PCIBus *pci_b
>      }
>  }
>  
> +static int load_excp_prefix(void)
> +{
> +    CPUState *cs;
> +
> +    CPU_FOREACH(cs) {
> +        CPUPPCState *env = &POWERPC_CPU(cs)->env;
> +        int ail = (env->spr[SPR_LPCR] & LPCR_AIL) >> LPCR_AIL_SHIFT;
> +
> +        env->excp_prefix = spapr_h_set_mode_resource_addr(ail);
> +        if (env->excp_prefix == H_UNSUPPORTED_FLAG) {
> +            error_report("LPCR has an invalid AIL value");
> +            return -EINVAL;
> +        }
> +    }
> +
> +    return 0;
> +}
> +
>  static int spapr_post_load(void *opaque, int version_id)
>  {
>      sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
> @@ -1257,6 +1275,9 @@ static int spapr_post_load(void *opaque,
>          err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
>      }
>  
> +    if (!err) {
> +        err = load_excp_prefix();
> +    }
>      return err;
>  }

As Greg says, it seems like this would make more sense in
cpu_post_load().


> Index: qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/include/hw/ppc/spapr.h
> +++ qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
> @@ -561,6 +561,20 @@ struct sPAPREventLogEntry {
>      QTAILQ_ENTRY(sPAPREventLogEntry) next;
>  };
>  
> +static inline target_ulong spapr_h_set_mode_resource_addr(target_ulong mflags)
> +{
> +    switch (mflags) {
> +    case H_SET_MODE_ADDR_TRANS_NONE:
> +        return 0;
> +    case H_SET_MODE_ADDR_TRANS_0001_8000:
> +        return 0x18000;
> +    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
> +        return 0xC000000000004000ULL;
> +    default:
> +        return H_UNSUPPORTED_FLAG;
> +    }
> +}

I'd like to see a different name for this function, and to move it
into target-ppc, since I imagine we'll want to re-use it for mtlpcr
(and/or mtmsr) once we do the powernv machine type.

>  void spapr_events_init(sPAPRMachineState *sm);
>  void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
>  int spapr_h_cas_compose_response(sPAPRMachineState *sm,
> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
> ===================================================================
> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr_hcall.c
> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
> @@ -835,17 +835,8 @@ static target_ulong h_set_mode_resource_
>          return H_P4;
>      }
>  
> -    switch (mflags) {
> -    case H_SET_MODE_ADDR_TRANS_NONE:
> -        prefix = 0;
> -        break;
> -    case H_SET_MODE_ADDR_TRANS_0001_8000:
> -        prefix = 0x18000;
> -        break;
> -    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
> -        prefix = 0xC000000000004000ULL;
> -        break;
> -    default:
> +    prefix = spapr_h_set_mode_resource_addr(mflags);
> +    if (prefix == H_UNSUPPORTED_FLAG) {
>          return H_UNSUPPORTED_FLAG;
>      }
>  
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [Qemu-ppc] [PATCH] spapr: compute interrupt vector address from LPCR
  2016-03-25 11:45 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
@ 2016-03-29  7:13   ` Cédric Le Goater
  0 siblings, 0 replies; 4+ messages in thread
From: Cédric Le Goater @ 2016-03-29  7:13 UTC (permalink / raw)
  To: Greg Kurz; +Cc: Thomas Huth, qemu-ppc, qemu-devel, David Gibson

On 03/25/2016 12:45 PM, Greg Kurz wrote:
> Hi Cedric,
> 
> On Thu, 24 Mar 2016 16:28:53 +0100
> Cédric Le Goater <clg@fr.ibm.com> wrote:
> 
>> This address is changed by the linux kernel using the H_SET_MODE hcall
>> and needs to be migrated in order to restart a spapr VM running in
>> TCG. This can be done using the AIL bits from the LPCR register.
>>
>> The patch introduces a spapr_h_set_mode_resource_addr() helper to
>> share some code with the H_SET_MODE hcall.
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>>  hw/ppc/spapr.c         |   21 +++++++++++++++++++++
>>  hw/ppc/spapr_hcall.c   |   13 ++-----------
>>  include/hw/ppc/spapr.h |   14 ++++++++++++++
>>  3 files changed, 37 insertions(+), 11 deletions(-)
>>
>> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
>> ===================================================================
>> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr.c
>> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr.c
>> @@ -1244,6 +1244,24 @@ static bool spapr_vga_init(PCIBus *pci_b
>>      }
>>  }
>>
>> +static int load_excp_prefix(void)
>> +{
>> +    CPUState *cs;
>> +
>> +    CPU_FOREACH(cs) {
>> +        CPUPPCState *env = &POWERPC_CPU(cs)->env;
> 
> And how are we sure env contains the migrated register values ?
> 
> Actually, this "works" because vmstate_ppc_cpu is registered before vmstate_spapr,
> and the same ordering happens to be used when sending state over the wire, but it
> looks wrong.
> 
> The excp_prefix should be restored in cpu_post_load(), unless I'm missing
> something.

ah yes. You're right. It was there initially but as this is specific spar, 
I moved the code out. Bad choice.

Thanks,

C. 

> Cheers.
> 
> --
> Greg
> 
>> +        int ail = (env->spr[SPR_LPCR] & LPCR_AIL) >> LPCR_AIL_SHIFT;
>> +
>> +        env->excp_prefix = spapr_h_set_mode_resource_addr(ail);
>> +        if (env->excp_prefix == H_UNSUPPORTED_FLAG) {
>> +            error_report("LPCR has an invalid AIL value");
>> +            return -EINVAL;
>> +        }
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>>  static int spapr_post_load(void *opaque, int version_id)
>>  {
>>      sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
>> @@ -1257,6 +1275,9 @@ static int spapr_post_load(void *opaque,
>>          err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
>>      }
>>
>> +    if (!err) {
>> +        err = load_excp_prefix();
>> +    }
>>      return err;
>>  }
>>
>> Index: qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
>> ===================================================================
>> --- qemu-dgibson-for-2.6.git.orig/include/hw/ppc/spapr.h
>> +++ qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
>> @@ -561,6 +561,20 @@ struct sPAPREventLogEntry {
>>      QTAILQ_ENTRY(sPAPREventLogEntry) next;
>>  };
>>
>> +static inline target_ulong spapr_h_set_mode_resource_addr(target_ulong mflags)
>> +{
>> +    switch (mflags) {
>> +    case H_SET_MODE_ADDR_TRANS_NONE:
>> +        return 0;
>> +    case H_SET_MODE_ADDR_TRANS_0001_8000:
>> +        return 0x18000;
>> +    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
>> +        return 0xC000000000004000ULL;
>> +    default:
>> +        return H_UNSUPPORTED_FLAG;
>> +    }
>> +}
>> +
>>  void spapr_events_init(sPAPRMachineState *sm);
>>  void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
>>  int spapr_h_cas_compose_response(sPAPRMachineState *sm,
>> Index: qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
>> ===================================================================
>> --- qemu-dgibson-for-2.6.git.orig/hw/ppc/spapr_hcall.c
>> +++ qemu-dgibson-for-2.6.git/hw/ppc/spapr_hcall.c
>> @@ -835,17 +835,8 @@ static target_ulong h_set_mode_resource_
>>          return H_P4;
>>      }
>>
>> -    switch (mflags) {
>> -    case H_SET_MODE_ADDR_TRANS_NONE:
>> -        prefix = 0;
>> -        break;
>> -    case H_SET_MODE_ADDR_TRANS_0001_8000:
>> -        prefix = 0x18000;
>> -        break;
>> -    case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000:
>> -        prefix = 0xC000000000004000ULL;
>> -        break;
>> -    default:
>> +    prefix = spapr_h_set_mode_resource_addr(mflags);
>> +    if (prefix == H_UNSUPPORTED_FLAG) {
>>          return H_UNSUPPORTED_FLAG;
>>      }
>>
>>
>>
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-29  7:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-24 15:28 [Qemu-devel] [PATCH] spapr: compute interrupt vector address from LPCR Cédric Le Goater
2016-03-25 11:45 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-03-29  7:13   ` Cédric Le Goater
2016-03-29  4:35 ` [Qemu-devel] " David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).