Skip to contentSkip to conversation

hw/acpi: Fix PM control register access

PATCH In review BALATON Zoltan 4 participants 11 messages Jun 7, 2023 – Jun 20, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/acpi: Fix PM control register access

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
 hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +26 -26
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
 }
 
 /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable)
 {
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
 static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
 {
     ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;
 }
 
 static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                               unsigned width)
 {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
 }
 
 static const MemoryRegionOps acpi_pm_cnt_ops = {
Signature · 1 line
2.30.9
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · On Wed, 7 Jun 2023 22:01:25 +0200 (CEST) BALATON Zoltan <[email protected]>…

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

Quoted 79 lines
---
 hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +26 -26
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
 }
 
 /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
 void acpi_pm1_cnt_update(ACPIREGS *ar,
                          bool sci_enable, bool sci_disable)
 {
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
 static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
 {
     ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;
 }
 
 static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                               unsigned width)
 {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
 }
 
 static const MemoryRegionOps acpi_pm_cnt_ops = {
#2 lore raw
In reply to BALATON Zoltan
Quoted 49 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
 
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 11 lines
hw/acpi/core.c +5 -1
  }
 
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/ which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 13 lines
hw/acpi/core.c +13 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +7 -0
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
 
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#3 lore raw
Quoted 69 lines · Mark Cave-Ayland
Quoted 48 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Quoted 27 lines
Quoted 12 lines
hw/acpi/core.c +12 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +8 -0
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#4 lore raw
Quoted 78 lines · Michael S. Tsirkin
Quoted 69 lines · Mark Cave-Ayland
Quoted 48 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 6 lines

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Apart from the typo but -> bug I'm not sure this is related to that issue but in any case this does not trigger but works around some possible bug so maybe "This work around may be related to issue URL" or something like that maybe? I'm also not sure what comment to add where so I'd appreciate if you can handle this on merging.

Regards,
BALATON Zoltan

Quoted 29 lines
Quoted 27 lines
Quoted 12 lines
hw/acpi/core.c +12 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +8 -0
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#5 lore raw
Quoted 81 lines · BALATON Zoltan
Quoted 80 lines · Michael S. Tsirkin
Quoted 78 lines · Mark Cave-Ayland
Quoted 49 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
- 
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 573

Quoted 6 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned 
 width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 8 lines
Quoted 6 lines

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Apart from the typo but -> bug I'm not sure this is related to that issue but in any case this does not trigger but works around some possible bug so maybe "This work around may be related to issue URL" or something like that maybe? I'm also not sure what comment to add where so I'd appreciate if you can handle this on merging.

Ping? Is this queued somewhere or will it be merged? Maybe Adding Buglink tag to commit message could be sufficient or just mentioning the link in the commit message. I'm still not sure what the best way to do that so I hope you could take care of that.

Regards,
BALATON Zoltan

Quoted 32 lines
Quoted 30 lines
Quoted 28 lines
Quoted 13 lines
hw/acpi/core.c +13 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +7 -0
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+ 
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#6 lore raw
Quoted 95 lines · BALATON Zoltan
Quoted 86 lines · BALATON Zoltan
Quoted 85 lines · Michael S. Tsirkin
Quoted 71 lines · Mark Cave-Ayland
Quoted 49 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 573

Quoted 6 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr
 addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

Quoted 7 lines
Quoted 1 line

?

Apart from the typo but -> bug I'm not sure this is related to that issue but in any case this does not trigger but works around some possible bug so maybe "This work around may be related to issue URL" or something like that maybe? I'm also not sure what comment to add where so I'd appreciate if you can handle this on merging.

Quoted 7 lines

Ping? Is this queued somewhere or will it be merged? Maybe Adding Buglink tag to commit message could be sufficient or just mentioning the link in the commit message. I'm still not sure what the best way to do that so I hope you could take care of that.

Regards,
BALATON Zoltan

?

Quoted 32 lines
Quoted 32 lines
Quoted 30 lines
Quoted 28 lines
Quoted 13 lines
hw/acpi/core.c +13 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +7 -0
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#7 lore raw
Quoted 101 lines · Michael S. Tsirkin
Quoted 100 lines · BALATON Zoltan
Quoted 86 lines · BALATON Zoltan
Quoted 85 lines · Michael S. Tsirkin
Quoted 71 lines · Mark Cave-Ayland
Quoted 49 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 573

Quoted 6 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr
 addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

Quoted 7 lines
Quoted 1 line

?

Apart from the typo but -> bug I'm not sure this is related to that issue but in any case this does not trigger but works around some possible bug so maybe "This work around may be related to issue URL" or something like that maybe? I'm also not sure what comment to add where so I'd appreciate if you can handle this on merging.

Ping? Is this queued somewhere or will it be merged? Maybe Adding Buglink tag to commit message could be sufficient or just mentioning the link in the commit message. I'm still not sure what the best way to do that so I hope you could take care of that.

Quoted 6 lines
Quoted 2 lines

Regards,
BALATON Zoltan

?

Fixes means it would close the ticket but this patch does not fix that issue just may be related to it so that's why Buglink may be more appropriate but I'm not sure either. So maybe just add a sentence to the commit message saying:

"This may be related to URL.."

Regards,
BALATON Zoltan

Quoted 35 lines
Quoted 33 lines
Quoted 33 lines
Quoted 31 lines
Quoted 29 lines
Quoted 14 lines
hw/acpi/core.c +13 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +7 -0
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+
 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#8 lore raw
In reply to BALATON Zoltan
Quoted 86 lines · BALATON Zoltan
Quoted 78 lines · Michael S. Tsirkin
Quoted 69 lines · Mark Cave-Ayland
Quoted 48 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
  hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
  1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
  }
  /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
  void acpi_pm1_cnt_update(ACPIREGS *ar,
                           bool sci_enable, bool sci_disable)
  {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
  static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
  }
  static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 6 lines

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Quoted 8 lines

Apart from the typo but -> bug I'm not sure this is related to that issue but in any case this does not trigger but works around some possible bug so maybe "This work around may be related to issue URL" or something like that maybe? I'm also not sure what comment to add where so I'd appreciate if you can handle this on merging.

Regards,
BALATON Zoltan

I'll merge, just got back from travel.

Quoted 29 lines
Quoted 29 lines
Quoted 27 lines
Quoted 12 lines
hw/acpi/core.c +12 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 10 lines
hw/acpi/core.c +8 -0
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
  }
  static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#9 lore raw
In reply to Michael S. Tsirkin
Quoted 78 lines · Michael S. Tsirkin
Quoted 69 lines · Mark Cave-Ayland
Quoted 48 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
   hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
   1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
   }
   /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
   void acpi_pm1_cnt_update(ACPIREGS *ar,
                            bool sci_enable, bool sci_disable)
   {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
   static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
   {
       ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
   }
   static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                 unsigned width)
   {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 6 lines

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Well it was just an observation based on its similarity to my patch, but it would need a quick check with the debugger to step back up from the access to confirm if it were caused by the same issue (see the above issue #360 for detail).

As per my previous message no objection to the patch, but if it does have the same underlying cause then it could explain why this has been a tricky problem to solve (as in general the memory API "just works") and also provide another test case for a potential fix.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
hw/acpi/core.c +14 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
Quoted 8 lines
Quoted 8 lines

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 8 lines
hw/acpi/core.c +6 -0
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
   }
   static const MemoryRegionOps acpi_pm_cnt_ops = {

ATB,

Mark.

#10 lore raw
Quoted 121 lines · Mark Cave-Ayland
Quoted 78 lines · Michael S. Tsirkin
Quoted 69 lines · Mark Cave-Ayland
Quoted 48 lines · BALATON Zoltan

On pegasos2 which has ACPI as part of VT8231 south bridge the board firmware writes PM control register by accessing the second byte so addr will be 1. This wasn't handled correctly and the write went to addr 0 instead. Remove the acpi_pm1_cnt_write() function which is used only once and does not take addr into account and handle non-zero address in acpi_pm_cnt_{read|write}. This fixes ACPI shutdown with pegasos2 firmware.

---
   hw/acpi/core.c | 52 +++++++++++++++++++++++++-------------------------
   1 file changed, 26 insertions(+), 26 deletions(-)
hw/acpi/core.c +0 -24
index 6da275c599..00b1e79a30 100644
@@ -551,30 +551,6 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
   }
   /* ACPI PM1aCNT */
-static void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
-{
-    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-
-    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-        /* change suspend type */
-        uint16_t sus_typ = (val >> 10) & 7;
-        switch (sus_typ) {
-        case 0: /* soft power off */
-            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            break;
-        case 1:
-            qemu_system_suspend_request();
-            break;
-        default:
-            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
-                qapi_event_send_suspend_disk();
-                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
-            }
-            break;
-        }
-    }
-}
-
   void acpi_pm1_cnt_update(ACPIREGS *ar,
                            bool sci_enable, bool sci_disable)
   {

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 572

Quoted 5 lines
hw/acpi/core.c +1 -1
@@ -593,13 +569,37 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
   static uint64_t acpi_pm_cnt_read(void *opaque, hwaddr addr, unsigned width)
   {
       ACPIREGS *ar = opaque;
-    return ar->pm1.cnt.cnt;
+    return ar->pm1.cnt.cnt >> addr * 8;

This shift here...

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 582

Quoted 10 lines
hw/acpi/core.c +5 -1
   }
   static void acpi_pm_cnt_write(void *opaque, hwaddr addr, uint64_t val,
                                 unsigned width)
   {
-    acpi_pm1_cnt_write(opaque, val);
+    ACPIREGS *ar = opaque;
+
+    if (addr == 1) {
+        val = val << 8 | (ar->pm1.cnt.cnt & 0xff);
+    }
Quoted 7 lines

and this shift here look similar to my workaround in https://patchew.org/QEMU/[email protected]/[email protected]/
which is a symptom of https://gitlab.com/qemu-project/qemu/-/issues/360.

Whilst there is no imminent fix for the above issue, it may be worth a few mins to determine if this is the same issue and if so document it with comments accordingly as I did so that the workaround can be removed at a later date.

Quoted 6 lines

So I will add
this triggers a but in memory core,
(see
https://gitlab.com/qemu-project/qemu/-/issues/360 for more detail)

?

Well it was just an observation based on its similarity to my patch, but it would need a quick check with the debugger to step back up from the access to confirm if it were caused by the same issue (see the above issue #360 for detail).

As per my previous message no objection to the patch, but if it does have the same underlying cause then it could explain why this has been a tricky problem to solve (as in general the memory API "just works") and also provide another test case for a potential fix.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
hw/acpi/core.c +14 -0
+    ar->pm1.cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch (sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            break;
+        case 1:
+            qemu_system_suspend_request();
+            break;
+        default:
+            if (sus_typ == ar->pm1.cnt.s4_val) { /* S4 request */
Quoted 8 lines
Quoted 8 lines

hw/acpi/core.c void acpi_pm1_cnt_update(ACPIREGS *ar, · line 605

Quoted 8 lines
hw/acpi/core.c +6 -0
+                qapi_event_send_suspend_disk();
+                qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
+            }
+            break;
+        }
+    }
   }
   static const MemoryRegionOps acpi_pm_cnt_ops = {
Quoted 3 lines

ATB,

Mark.

Yea look at e.g. discussion around
https://lore.kernel.org/all/20211108130934.59B48748F52%40zero.eik.bme.hu/t.mbox.gz

Signature · 1 line
MST