Skip to contentSkip to conversation

hw/display/vga: Do not reset 'big_endian_fb' in vga_common_reset()

PATCH In review Philippe Mathieu-Daudé 4 participants 10 messages Nov 29, 2024 – Dec 9, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover hw/display/vga: Do not reset 'big_endian_fb' in vga_common_reset()

Since v1: Split in 2 distinct patches

Philippe Mathieu-Daudé (2):
hw/display/vga: Do not reset 'big_endian_fb' in vga_common_reset() hw/display/vga: Remove pointless VGACommonState::default_endian_fb

 hw/display/vga_int.h | 1 -
 hw/display/vga.c     | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/2 hw/display/vga: Do not reset 'big_endian_fb' in vga_common_reset()

The 'pci-vga' device allow setting a 'big-endian-framebuffer' property since commit 3c2784fc864 ("vga: Expose framebuffer byteorder as a QOM property"). Similarly, the 'virtio-vga' device since commit 8be61ce2ce3 ("virtio-vga: implement big-endian-framebuffer property").

Both call vga_common_reset() in their reset handler, respectively pci_secondary_vga_reset() and virtio_vga_base_reset_hold(), which reset 'big_endian_fb', overwritting the property. This is not
correct: the hardware is expected to keep its configured endianness during resets.

Move 'big_endian_fb' assignment from vga_common_reset() to vga_common_init() which is called once when the common VGA state is initialized.

---
 hw/display/vga.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/vga.c +1 -1
index 892fedc8dce..b074b58c90d 100644
@@ -1873,7 +1873,6 @@ void vga_common_reset(VGACommonState *s)
     s->cursor_start = 0;
     s->cursor_end = 0;
     s->cursor_offset = 0;
-    s->big_endian_fb = s->default_endian_fb;
     memset(s->invalidated_y_table, '\0', sizeof(s->invalidated_y_table));
     memset(s->last_palette, '\0', sizeof(s->last_palette));
     memset(s->last_ch_attr, '\0', sizeof(s->last_ch_attr));
@@ -2266,6 +2265,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
      * all target endian dependencies from this file.
      */
     s->default_endian_fb = target_words_bigendian();
+    s->big_endian_fb = s->default_endian_fb;
 
     vga_dirty_log_start(s);
 
Signature · 1 line
2.45.2
#2 lore raw

ping?

Quoted 41 lines · Philippe Mathieu-Daudé

The 'pci-vga' device allow setting a 'big-endian-framebuffer' property since commit 3c2784fc864 ("vga: Expose framebuffer byteorder as a QOM property"). Similarly, the 'virtio-vga' device since commit 8be61ce2ce3 ("virtio-vga: implement big-endian-framebuffer property").

Both call vga_common_reset() in their reset handler, respectively pci_secondary_vga_reset() and virtio_vga_base_reset_hold(), which reset 'big_endian_fb', overwritting the property. This is not
correct: the hardware is expected to keep its configured endianness during resets.

Move 'big_endian_fb' assignment from vga_common_reset() to vga_common_init() which is called once when the common VGA state is initialized.

---
  hw/display/vga.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/vga.c +1 -1
index 892fedc8dce..b074b58c90d 100644
@@ -1873,7 +1873,6 @@ void vga_common_reset(VGACommonState *s)
      s->cursor_start = 0;
      s->cursor_end = 0;
      s->cursor_offset = 0;
-    s->big_endian_fb = s->default_endian_fb;
      memset(s->invalidated_y_table, '\0', sizeof(s->invalidated_y_table));
      memset(s->last_palette, '\0', sizeof(s->last_palette));
      memset(s->last_ch_attr, '\0', sizeof(s->last_ch_attr));
@@ -2266,6 +2265,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
       * all target endian dependencies from this file.
       */
      s->default_endian_fb = target_words_bigendian();
+    s->big_endian_fb = s->default_endian_fb;
 
      vga_dirty_log_start(s);
 
#3 lore raw

It's been a long time, I only have vague memories of this :-) But I think it should be ok.

It does definitely make sense in the virtio case and similar where the property is set once for the instance.

For bochs and ati, there's a register to configure it as well, so there *may* be an expectation that it gets reset there, I'm less certain.

So tentatively...

Quoted 46 lines · Philippe Mathieu-Daudé

ping?

Quoted 43 lines · Philippe Mathieu-Daudé

The 'pci-vga' device allow setting a 'big-endian-framebuffer' property since commit 3c2784fc864 ("vga: Expose framebuffer byteorder as a QOM property"). Similarly, the 'virtio-vga' device since commit 8be61ce2ce3 ("virtio-vga: implement big-endian-framebuffer property").

Both call vga_common_reset() in their reset handler, respectively pci_secondary_vga_reset() and virtio_vga_base_reset_hold(), which reset 'big_endian_fb', overwritting the property. This is not
correct: the hardware is expected to keep its configured endianness during resets.

Move 'big_endian_fb' assignment from vga_common_reset() to vga_common_init() which is called once when the common VGA state is initialized.

---
  hw/display/vga.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/vga.c +0 -1
index 892fedc8dce..b074b58c90d 100644
@@ -1873,7 +1873,6 @@ void vga_common_reset(VGACommonState *s)
       s->cursor_start = 0;
       s->cursor_end = 0;
       s->cursor_offset = 0;
-    s->big_endian_fb = s->default_endian_fb;

      memset(s->invalidated_y_table, '\0', sizeof(s-

Quoted 1 line

invalidated_y_table));

      memset(s->last_palette, '\0', sizeof(s->last_palette)); memset(s->last_ch_attr, '\0', sizeof(s->last_ch_attr));

hw/display/vga.c +1 -0
@@ -2266,6 +2265,7 @@ bool vga_common_init(VGACommonState *s,
 Object *obj, Error **errp)
        * all target endian dependencies from this file.
        */
       s->default_endian_fb = target_words_bigendian();
+    s->big_endian_fb = s->default_endian_fb;


      vga_dirty_log_start(s);

#4 lore raw

Hi,

Quoted 2 lines

For bochs and ati, there's a register to configure it as well, so there *may* be an expectation that it gets reset there, I'm less certain.

The default is there for backward compatibility reasons and it should default to machine byte order so you get something working even in case the guest does not explicitly set the byte order via register. Which should be increasingly rare these days, the register was added in (checking git log) 2014: commit b5682aa4ca79 ("vga-pci: add qext region to mmio")

The only case I'm aware of where the byte order is actually switched is booting a ppc64le guest in a pseries machine, where the opal firmware runs in bigendian mode and the linux kernel runs in little endian mode.

So here the changed reset behavior could actually make a difference, but you will only notice if the opal firmware does *not* set the byte order register.

take care,
Gerd

#5 lore raw
Quoted 12 lines · Gerd Hoffmann

Hi,

Quoted 2 lines

For bochs and ati, there's a register to configure it as well, so there *may* be an expectation that it gets reset there, I'm less certain.

The default is there for backward compatibility reasons and it should default to machine byte order so you get something working even in case the guest does not explicitly set the byte order via register. Which should be increasingly rare these days, the register was added in (checking git log) 2014: commit b5682aa4ca79 ("vga-pci: add qext region to mmio")

Quoted 7 lines

The only case I'm aware of where the byte order is actually switched is booting a ppc64le guest in a pseries machine, where the opal firmware runs in bigendian mode and the linux kernel runs in little endian mode.

So here the changed reset behavior could actually make a difference, but you will only notice if the opal firmware does *not* set the byte order register.

I'm not sure about ati-vga but I set the vga.big_endian_fb on mode switch if the guest uses big endian mode. I've added this for MacOS 9 I think which does use that. I've also put some notes on what I've found different drivers use in commit 8bb9a2b26d83a. AFAIK the ati chip starts as little endian so maybe reseting it in ati_vga_reset() if vga_common_reset() does not do that any more may be needed but I can't tell for sure that's why I did not comment on this patch so far.

Regards,
BALATON Zoltan

#6 lore raw
In reply to Gerd Hoffmann
Quoted 8 lines · Gerd Hoffmann

The only case I'm aware of where the byte order is actually switched is booting a ppc64le guest in a pseries machine, where the opal firmware runs in bigendian mode and the linux kernel runs in little endian mode.

So here the changed reset behavior could actually make a difference, but you will only notice if the opal firmware does *not* set the byte order register.

OPAL (well skiboot) doesn't display anything anyways (or at least it didn't when I wrote it :-). It just boots Linux as a bootloader. So as long as Linux itself sets the register it should be fine.

Cheers,
Ben.

#7 lore raw
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Gerd Hoffmann

The only case I'm aware of where the byte order is actually switched is booting a ppc64le guest in a pseries machine, where the opal firmware runs in bigendian mode and the linux kernel runs in little endian mode.

Quoted 7 lines
Quoted 3 lines

So here the changed reset behavior could actually make a difference, but you will only notice if the opal firmware does *not* set the byte order register.

OPAL (well skiboot) doesn't display anything anyways (or at least it didn't when I wrote it :-). It just boots Linux as a bootloader. So as long as Linux itself sets the register it should be fine.

Oh, mixed up the firmware names, it's SLOF not OPAL.

sorry for the confusion,
Gerd

#8 lore raw
Quoted 10 lines · Gerd Hoffmann
Quoted 6 lines

OPAL (well skiboot) doesn't display anything anyways (or at least it
didn't when I wrote it :-). It just boots Linux as a bootloader. So as
long as Linux itself sets the register it should be fine.

Oh, mixed up the firmware names, it's SLOF not OPAL.

sorry for the confusion,

Looking at SLOF source, it doesn't know about the endian register at all indeed, it also doesn't put an endian propery in the device-node, and probably expects the fb to be BE on reboot. Gosh I also wrote that code... a looong time ago, I had forgotten all about it.

On SPAPR where endian *is* switched, qemu will also switch the endian of the framebuffer on an explicit mode switch via the H_SET_MODE hypercall. But afaik that does NOT include a reboot (at least from 10mn browsing the code).

So I think the patch will have the effect of breaking the framebuffer in SLOF on reboot when using SPAPR with an LE OS.

Something like this might work around it:

hw/ppc/spapr.c +3 -0
@@ -1737,6 +1737,9 @@ static void spapr_machine_reset(MachineState *machine, ResetType type)
 
     spapr_clear_pending_events(spapr);
 
+    /* Switch VGA to big endian */
+    spapr_pci_switch_vga(spapr, true);
+
     /*
      * We place the device tree just below either the top of the RMA,
      * or just below 2GB, whichever is lower, so that it can be

I can't test right now, I might later this week, ping me if you don't hear from me.

Cheers,
Ben.

#9 lore raw

PATCH v2 2/2 hw/display/vga: Remove pointless VGACommonState::default_endian_fb

In reply to Philippe Mathieu-Daudé

'default_endian_fb' value is always target_words_bigendian(), remove it as it isn't very useful.

---
 hw/display/vga_int.h | 1 -
 hw/display/vga.c     | 5 ++---
 2 files changed, 2 insertions(+), 4 deletions(-)
hw/display/vga_int.h +0 -1
index f77c1c11457..5dcdecfd422 100644
@@ -135,7 +135,6 @@ typedef struct VGACommonState {
     bool full_update_text;
     bool full_update_gfx;
     bool big_endian_fb;
-    bool default_endian_fb;
     bool global_vmstate;
     /* hardware mouse cursor support */
     uint32_t invalidated_y_table[VGA_MAX_HEIGHT / 32];
hw/display/vga.c +2 -3
index b074b58c90d..6dbbbf49073 100644
@@ -2116,7 +2116,7 @@ static bool vga_endian_state_needed(void *opaque)
      * default one, thus ensuring backward compatibility for
      * migration of the common case
      */
-    return s->default_endian_fb != s->big_endian_fb;
+    return s->big_endian_fb != target_words_bigendian();
 }
 
 static const VMStateDescription vmstate_vga_endian = {
@@ -2264,8 +2264,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, Error **errp)
      * into a device attribute set by the machine/platform to remove
      * all target endian dependencies from this file.
      */
-    s->default_endian_fb = target_words_bigendian();
-    s->big_endian_fb = s->default_endian_fb;
+    s->big_endian_fb = target_words_bigendian();
 
     vga_dirty_log_start(s);
 
Signature · 1 line
2.45.2