Skip to contentSkip to conversation

spapr: compute interrupt vector address from LPCR

PATCH Superseded Cédric Le Goater 3 participants 4 messages Mar 24, 2016 – Mar 29, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr: compute interrupt vector address from LPCR

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.

---
 hw/ppc/spapr.c         |   21 +++++++++++++++++++++
 hw/ppc/spapr_hcall.c   |   13 ++-----------
 include/hw/ppc/spapr.h |   14 ++++++++++++++
 3 files changed, 37 insertions(+), 11 deletions(-)
hw/ppc/spapr.c +21 -0
Index: 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;
 }
 
include/hw/ppc/spapr.h +14 -0
Index: 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,
hw/ppc/spapr_hcall.c +2 -11
Index: 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;
     }
 
#1 lore raw

Hi Cedric,

Quoted 19 lines · On Thu, 24 Mar 2016 16:28:53 +0100 Cédric Le Goater <[email protected]> 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.

---
 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
===================================================================

hw/ppc/spapr.c static bool spapr_vga_init(PCIBus *pci_b · line 1252

Quoted 9 lines
hw/ppc/spapr.c +6 -0
@@ -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

Quoted 76 lines
hw/ppc/spapr.c +15 -0
+        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
===================================================================

include/hw/ppc/spapr.h +14 -0
@@ -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
===================================================================

hw/ppc/spapr_hcall.c +2 -11
@@ -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;
     }
 
#2 lore raw
Quoted 36 lines · Greg Kurz

Hi Cedric,

Quoted 19 lines · On Thu, 24 Mar 2016 16:28:53 +0100 Cédric Le Goater <[email protected]> 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.

---
 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
===================================================================

hw/ppc/spapr.c static bool spapr_vga_init(PCIBus *pci_b · line 1252

Quoted 9 lines
hw/ppc/spapr.c +6 -0
@@ -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 ?

Quoted 6 lines

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.

Quoted 82 lines

Cheers.

--
Greg

Quoted 76 lines
hw/ppc/spapr.c +15 -0
+        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
===================================================================

include/hw/ppc/spapr.h +14 -0
@@ -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
===================================================================

hw/ppc/spapr_hcall.c +2 -11
@@ -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;
     }
 
#3 lore raw
In reply to Cédric Le Goater
Quoted 44 lines · Cédric Le Goater

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.

---
 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
===================================================================

hw/ppc/spapr.c +18 -0
@@ -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;

hw/ppc/spapr.c static int spapr_post_load(void *opaque, · line 1282

Quoted 8 lines
hw/ppc/spapr.c +3 -0
@@ -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().

Quoted 11 lines

Index: qemu-dgibson-for-2.6.git/include/hw/ppc/spapr.h
===================================================================

include/hw/ppc/spapr.h +3 -0
@@ -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) {

include/hw/ppc/spapr.h struct sPAPREventLogEntry { · line 576

Quoted 10 lines
include/hw/ppc/spapr.h +10 -0
+    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.

Quoted 28 lines
include/hw/ppc/spapr.h +0 -0
 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
===================================================================

hw/ppc/spapr_hcall.c +2 -11
@@ -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;
     }
 
Signature · 4 lines
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