Skip to contentSkip to conversation

pseries: Clean up hcall_dprintf() debugging messages

PATCH Applied David Gibson 2 participants 7 messages Mar 28, 2012 – Apr 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 pseries: Clean up hcall_dprintf() debugging messages

The pseries machine code has a number of debug messages for debugging PAPR hypercalls, dependent on DEBUG_SPAPR_HCALLS. This patch cleans these messages up a bit, by adding __func__ to the hcall_dprintf() macro and simplifying up a number of the individual messages accordingly.

Conflicts:

hw/spapr_vio.c

---
 hw/spapr.h      |    2 +-
 hw/spapr_llan.c |   12 +++++-------
 hw/spapr_vio.c  |   25 +++++++++----------------
 3 files changed, 15 insertions(+), 24 deletions(-)
hw/spapr.h +1 -1
index 11160b0..654a7a8 100644
@@ -272,7 +272,7 @@ extern sPAPREnvironment *spapr;
 
 #ifdef DEBUG_SPAPR_HCALLS
 #define hcall_dprintf(fmt, ...) \
-    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
+    do { fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); } while (0)
 #else
 #define hcall_dprintf(fmt, ...) \
     do { } while (0)
hw/spapr_llan.c +5 -7
index cfc7778..32dce17 100644
@@ -279,21 +279,19 @@ static target_ulong h_register_logical_lan(CPUPPCState *env,
 
     if (check_bd(dev, VLAN_VALID_BD(buf_list, SPAPR_VIO_TCE_PAGE_SIZE),
                  SPAPR_VIO_TCE_PAGE_SIZE) < 0) {
-        hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx " for "
-                      "H_REGISTER_LOGICAL_LAN\n", buf_list);
+        hcall_dprintf("Bad buf_list 0x" TARGET_FMT_lx "\n", buf_list);
         return H_PARAMETER;
     }
 
     filter_list_bd = VLAN_VALID_BD(filter_list, SPAPR_VIO_TCE_PAGE_SIZE);
     if (check_bd(dev, filter_list_bd, SPAPR_VIO_TCE_PAGE_SIZE) < 0) {
-        hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx " for "
-                      "H_REGISTER_LOGICAL_LAN\n", filter_list);
+        hcall_dprintf("Bad filter_list 0x" TARGET_FMT_lx "\n", filter_list);
         return H_PARAMETER;
     }
 
     if (!(rec_queue & VLAN_BD_VALID)
         || (check_bd(dev, rec_queue, VLAN_RQ_ALIGNMENT) < 0)) {
-        hcall_dprintf("Bad receive queue for H_REGISTER_LOGICAL_LAN\n");
+        hcall_dprintf("Bad receive queue\n");
         return H_PARAMETER;
     }
 
@@ -358,13 +356,13 @@ static target_ulong h_add_logical_lan_buffer(CPUPPCState *env,
             ", 0x" TARGET_FMT_lx ")\n", reg, buf);
 
     if (!sdev) {
-        hcall_dprintf("Wrong device in h_add_logical_lan_buffer\n");
+        hcall_dprintf("Bad device\n");
         return H_PARAMETER;
     }
 
     if ((check_bd(dev, buf, 4) < 0)
         || (VLAN_BD_LEN(buf) < 16)) {
-        hcall_dprintf("Bad buffer enqueued in h_add_logical_lan_buffer\n");
+        hcall_dprintf("Bad buffer enqueued\n");
         return H_PARAMETER;
     }
 
hw/spapr_vio.c +9 -16
index dbf5a90..1f67e64 100644
@@ -204,8 +204,7 @@ static target_ulong h_put_tce(CPUPPCState *env, sPAPREnvironment *spapr,
     VIOsPAPR_RTCE *rtce;
 
     if (!dev) {
-        hcall_dprintf("spapr_vio_put_tce on non-existent LIOBN "
-                      TARGET_FMT_lx "\n", liobn);
+        hcall_dprintf("LIOBN 0x" TARGET_FMT_lx " does not exist\n", liobn);
         return H_PARAMETER;
     }
 
@@ -217,8 +216,7 @@ static target_ulong h_put_tce(CPUPPCState *env, sPAPREnvironment *spapr,
 #endif
 
     if (ioba >= dev->rtce_window_size) {
-        hcall_dprintf("spapr_vio_put_tce on out-of-boards IOBA 0x"
-                      TARGET_FMT_lx "\n", ioba);
+        hcall_dprintf("Out-of-bounds IOBA 0x" TARGET_FMT_lx "\n", ioba);
         return H_PARAMETER;
     }
 
@@ -414,22 +412,20 @@ static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
 
     if (!dev) {
-        hcall_dprintf("h_reg_crq on non-existent unit 0x"
-                      TARGET_FMT_lx "\n", reg);
+        hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
         return H_PARAMETER;
     }
 
     /* We can't grok a queue size bigger than 256M for now */
     if (queue_len < 0x1000 || queue_len > 0x10000000) {
-        hcall_dprintf("h_reg_crq, queue size too small or too big (0x%llx)\n",
-                      (unsigned long long)queue_len);
+        hcall_dprintf("Queue size too small or too big (0x" TARGET_FMT_lx
+                      ")\n", queue_len);
         return H_PARAMETER;
     }
 
     /* Check queue alignment */
     if (queue_addr & 0xfff) {
-        hcall_dprintf("h_reg_crq, queue not aligned (0x%llx)\n",
-                      (unsigned long long)queue_addr);
+        hcall_dprintf("Queue not aligned (0x" TARGET_FMT_lx ")\n", queue_addr);
         return H_PARAMETER;
     }
 
@@ -460,8 +456,7 @@ static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
 
     if (!dev) {
-        hcall_dprintf("h_free_crq on non-existent unit 0x"
-                      TARGET_FMT_lx "\n", reg);
+        hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
         return H_PARAMETER;
     }
 
@@ -484,8 +479,7 @@ static target_ulong h_send_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     uint64_t crq_mangle[2];
 
     if (!dev) {
-        hcall_dprintf("h_send_crq on non-existent unit 0x"
-                      TARGET_FMT_lx "\n", reg);
+        hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
         return H_PARAMETER;
     }
     crq_mangle[0] = cpu_to_be64(msg_hi);
@@ -505,8 +499,7 @@ static target_ulong h_enable_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
 
     if (!dev) {
-        hcall_dprintf("h_enable_crq on non-existent unit 0x"
-                      TARGET_FMT_lx "\n", reg);
+        hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg);
         return H_PARAMETER;
     }
 
Signature · 1 line
1.7.9.1
#1 lore raw

PATCH 2/3 pseries: Fix bug with reset of VIO CRQs

PAPR specifies a Command Response Queue (CRQ) mechanism used for virtual IO, which we implement. However, we don't correctly clean up registered CRQs when we reset the system.

This patch adds a reset handler to fix this bug. While we're at it, add in some of the extra debug messages that were used to track the problem down.

---
 hw/spapr_vio.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)
hw/spapr_vio.c +25 -8
index 1f67e64..97d029a 100644
@@ -431,12 +431,13 @@ static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
 
     /* Check if device supports CRQs */
     if (!dev->crq.SendFunc) {
+        hcall_dprintf("h_reg_crq, device does not support CRQ\n");
         return H_NOT_FOUND;
     }
 
-
     /* Already a queue ? */
     if (dev->crq.qsize) {
+        hcall_dprintf("h_reg_crq, CRQ already registered\n");
         return H_RESOURCE;
     }
     dev->crq.qladdr = queue_addr;
@@ -449,6 +450,17 @@ static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
+static target_ulong free_crq(VIOsPAPRDevice *dev)
+{
+    dev->crq.qladdr = 0;
+    dev->crq.qsize = 0;
+    dev->crq.qnext = 0;
+
+    dprintf("CRQ for dev 0x%" PRIx32 " freed\n", dev->reg);
+
+    return H_SUCCESS;
+}
+
 static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
                                target_ulong opcode, target_ulong *args)
 {
@@ -460,13 +472,7 @@ static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
         return H_PARAMETER;
     }
 
-    dev->crq.qladdr = 0;
-    dev->crq.qsize = 0;
-    dev->crq.qnext = 0;
-
-    dprintf("CRQ for dev 0x" TARGET_FMT_lx " freed\n", reg);
-
-    return H_SUCCESS;
+    return free_crq(dev);
 }
 
 static target_ulong h_send_crq(CPUPPCState *env, sPAPREnvironment *spapr,
@@ -642,6 +648,15 @@ static int spapr_vio_check_reg(VIOsPAPRDevice *sdev)
     return 0;
 }
 
+static void spapr_vio_busdev_reset(void *opaque)
+{
+    VIOsPAPRDevice *dev = (VIOsPAPRDevice *)opaque;
+
+    if (dev->crq.qsize) {
+        free_crq(dev);
+    }
+}
+
 static int spapr_vio_busdev_init(DeviceState *qdev)
 {
     VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
@@ -670,6 +685,8 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
 
     rtce_init(dev);
 
+    qemu_register_reset(spapr_vio_busdev_reset, dev);
+
     return pc->init(dev);
 }
 
Signature · 1 line
1.7.9.1
#2 lore raw

Re: [Qemu-devel] [PATCH 2/3] pseries: Fix bug with reset of VIO CRQs

Am 28.03.2012 23:39, schrieb David Gibson:

Quoted 10 lines

PAPR specifies a Command Response Queue (CRQ) mechanism used for virtual IO, which we implement. However, we don't correctly clean up registered CRQs when we reset the system.

This patch adds a reset handler to fix this bug. While we're at it, add in some of the extra debug messages that were used to track the problem down.

---

As discussed on IRC, I've applied the following diff on my local branch to drop the h_reg_crq that my __func__ comment was about:

hw/spapr_vio.c +0 -0
index 0bf2c31..97d029a 100644
@@ -431,13 +431,13 @@ static target_ulong h_reg_crq(CPUPPCState *env,

sPAPREnvironment *spapr,

     /* Check if device supports CRQs */
     if (!dev->crq.SendFunc) {
-        hcall_dprintf("Device does not support CRQ\n");
+        hcall_dprintf("h_reg_crq, device does not support CRQ\n");
         return H_NOT_FOUND;
     }

     /* Already a queue ? */
     if (dev->crq.qsize) {
-        hcall_dprintf("CRQ already registered\n");
+        hcall_dprintf("h_reg_crq, CRQ already registered\n");
         return H_RESOURCE;
     }
     dev->crq.qladdr = queue_addr;

However, I'm having trouble testing reset. Whether on vanilla master or using this patch on top of ppc-next or this whole series on top of ppc-next, using ppc64-softmmu/qemu-system-ppc64 -M pseries -m 1G:

a) 0 > reset-all
results in: "reboot not available Aborted"
Do you need to update SLOF to actually use the newly added RTAS call?

b) (qemu) system_reset
results in:
exception 700
SRR0 = 0000000000000000 SRR1 = 800000008000000000080000 SPRG2 = 0000000000000000 SPRG3 = 000000003DCD1AD4

Could you please look into the two above issues? How did you test?

Thanks,
Andreas

Quoted 80 lines
 hw/spapr_vio.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)
hw/spapr_vio.c +25 -8
index 1f67e64..97d029a 100644
@@ -431,12 +431,13 @@ static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
 
     /* Check if device supports CRQs */
     if (!dev->crq.SendFunc) {
+        hcall_dprintf("h_reg_crq, device does not support CRQ\n");
         return H_NOT_FOUND;
     }
 
-
     /* Already a queue ? */
     if (dev->crq.qsize) {
+        hcall_dprintf("h_reg_crq, CRQ already registered\n");
         return H_RESOURCE;
     }
     dev->crq.qladdr = queue_addr;
@@ -449,6 +450,17 @@ static target_ulong h_reg_crq(CPUPPCState *env, sPAPREnvironment *spapr,
     return H_SUCCESS;
 }
 
+static target_ulong free_crq(VIOsPAPRDevice *dev)
+{
+    dev->crq.qladdr = 0;
+    dev->crq.qsize = 0;
+    dev->crq.qnext = 0;
+
+    dprintf("CRQ for dev 0x%" PRIx32 " freed\n", dev->reg);
+
+    return H_SUCCESS;
+}
+
 static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
                                target_ulong opcode, target_ulong *args)
 {
@@ -460,13 +472,7 @@ static target_ulong h_free_crq(CPUPPCState *env, sPAPREnvironment *spapr,
         return H_PARAMETER;
     }
 
-    dev->crq.qladdr = 0;
-    dev->crq.qsize = 0;
-    dev->crq.qnext = 0;
-
-    dprintf("CRQ for dev 0x" TARGET_FMT_lx " freed\n", reg);
-
-    return H_SUCCESS;
+    return free_crq(dev);
 }
 
 static target_ulong h_send_crq(CPUPPCState *env, sPAPREnvironment *spapr,
@@ -642,6 +648,15 @@ static int spapr_vio_check_reg(VIOsPAPRDevice *sdev)
     return 0;
 }
 
+static void spapr_vio_busdev_reset(void *opaque)
+{
+    VIOsPAPRDevice *dev = (VIOsPAPRDevice *)opaque;
+
+    if (dev->crq.qsize) {
+        free_crq(dev);
+    }
+}
+
 static int spapr_vio_busdev_init(DeviceState *qdev)
 {
     VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
@@ -670,6 +685,8 @@ static int spapr_vio_busdev_init(DeviceState *qdev)
 
     rtce_init(dev);
 
+    qemu_register_reset(spapr_vio_busdev_reset, dev);
+
     return pc->init(dev);
 }
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/3] pseries: Fix bug with reset of VIO CRQs

Quoted 45 lines · Andreas Färber

Am 28.03.2012 23:39, schrieb David Gibson:

Quoted 10 lines

PAPR specifies a Command Response Queue (CRQ) mechanism used for virtual IO, which we implement. However, we don't correctly clean up registered CRQs when we reset the system.

This patch adds a reset handler to fix this bug. While we're at it, add in some of the extra debug messages that were used to track the problem down.

---

As discussed on IRC, I've applied the following diff on my local branch to drop the h_reg_crq that my __func__ comment was about:

hw/spapr_vio.c +2 -2
index 0bf2c31..97d029a 100644
@@ -431,13 +431,13 @@ static target_ulong h_reg_crq(CPUPPCState *env,
 sPAPREnvironment *spapr,
 
     /* Check if device supports CRQs */
     if (!dev->crq.SendFunc) {
-        hcall_dprintf("Device does not support CRQ\n");
+        hcall_dprintf("h_reg_crq, device does not support CRQ\n");
         return H_NOT_FOUND;
     }
 
     /* Already a queue ? */
     if (dev->crq.qsize) {
-        hcall_dprintf("CRQ already registered\n");
+        hcall_dprintf("h_reg_crq, CRQ already registered\n");
         return H_RESOURCE;
     }
     dev->crq.qladdr = queue_addr;

However, I'm having trouble testing reset. Whether on vanilla master or using this patch on top of ppc-next or this whole series on top of ppc-next, using ppc64-softmmu/qemu-system-ppc64 -M pseries -m 1G:

a) 0 > reset-all
results in: "reboot not available Aborted"
Do you need to update SLOF to actually use the newly added RTAS call?

Quoted 7 lines

b) (qemu) system_reset
results in:
exception 700
SRR0 = 0000000000000000 SRR1 = 800000008000000000080000 SPRG2 = 0000000000000000 SPRG3 = 000000003DCD1AD4

Could you please look into the two above issues? How did you test?

Ah. I used "reboot" from within the guest Linux. I'll look at the others, the first could just be a slof bug.

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
#4 lore raw

Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/3] pseries: Fix bug with reset of VIO CRQs

In reply to Andreas Färber
Quoted 1 line · Andreas Färber

Am 28.03.2012 23:39, schrieb David Gibson:

[snip]

Quoted 7 lines

However, I'm having trouble testing reset. Whether on vanilla master or using this patch on top of ppc-next or this whole series on top of ppc-next, using ppc64-softmmu/qemu-system-ppc64 -M pseries -m 1G:

a) 0 > reset-all
results in: "reboot not available Aborted"
Do you need to update SLOF to actually use the newly added RTAS call?

Maybe, I'll have to check that.

Quoted 7 lines

b) (qemu) system_reset
results in:
exception 700
SRR0 = 0000000000000000 SRR1 = 800000008000000000080000 SPRG2 = 0000000000000000 SPRG3 = 000000003DCD1AD4

Could you please look into the two above issues? How did you test?

Hrm. I don't get that, at least with a fully booted kernel, although it does fail to boot completely after the reset, which I'll debug.

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
#5 lore raw

PATCH 3/3 pseries: Implement RTAS system-reboot call

In reply to David Gibson

This patch adds the PAPR defined RTAS system-reboot call to the pseries machine emulation, providing the guest with a way to trigger a reboot. This exposes a bug in the pseries VIO code which means CRQs are not properly reset on a system reset. This patch also fixes that bug by adding a suitable reset handler.

---
 hw/spapr_rtas.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
hw/spapr_rtas.c +14 -0
index 0946585..480a4ae 100644
@@ -112,6 +112,19 @@ static void rtas_power_off(sPAPREnvironment *spapr,
     rtas_st(rets, 0, 0);
 }
 
+static void rtas_system_reboot(sPAPREnvironment *spapr,
+                               uint32_t token, uint32_t nargs,
+                               target_ulong args,
+                               uint32_t nret, target_ulong rets)
+{
+    if (nargs != 0 || nret != 1) {
+        rtas_st(rets, 0, -3);
+        return;
+    }
+    qemu_system_reset_request();
+    rtas_st(rets, 0, 0);
+}
+
 static void rtas_query_cpu_stopped_state(sPAPREnvironment *spapr,
                                          uint32_t token, uint32_t nargs,
                                          target_ulong args,
@@ -294,6 +307,7 @@ static void core_rtas_register_types(void)
     spapr_rtas_register("get-time-of-day", rtas_get_time_of_day);
     spapr_rtas_register("set-time-of-day", rtas_set_time_of_day);
     spapr_rtas_register("power-off", rtas_power_off);
+    spapr_rtas_register("system-reboot", rtas_system_reboot);
     spapr_rtas_register("query-cpu-stopped-state",
                         rtas_query_cpu_stopped_state);
     spapr_rtas_register("start-cpu", rtas_start_cpu);
Signature · 1 line
1.7.9.1
#6 lore raw
In reply to David Gibson

Am 28.03.2012 23:39, schrieb David Gibson:

Quoted 11 lines

The pseries machine code has a number of debug messages for debugging PAPR hypercalls, dependent on DEBUG_SPAPR_HCALLS. This patch cleans these messages up a bit, by adding __func__ to the hcall_dprintf() macro and simplifying up a number of the individual messages accordingly.

Conflicts:

hw/spapr_vio.c
---

Thanks, that cleanup went beyond what I expected for what-is-now-2/3.

Applied to ppc-next:
http://repo.or.cz/w/qemu/agraf.git/shortlog/refs/heads/ppc-next

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg