Skip to contentSkip to conversation

hw/char/pl011: support backend hotswap

PATCH Superseded Alexander Mikhalitsyn 2 participants 3 messages Aug 11

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/char/pl011: support backend hotswap

From: Alexander Mikhalitsyn <[email protected]>

Currently, when Incus issues "chardev-change" QMP command to change chardev backend from ringbuf to socket it receives an error (with aarch64 VM):
"Chardev user does not support chardev hotswap" [1], [2]

Let's fix this by properly implementing BackendChangeHandler for pl011.

Please, note that we have to "replay" CHR_IOCTL_SERIAL_SET_BREAK, because if BRK bit was set before backend change (i.e. (s->lcr & LCR_BRK) is true), then after change we need to send break to a new backend too.

---
v2:
- fixed a typo in commit author name
[ I did git format-patch and copied this patch from my Raspberry PI
dev/test machine and it turns out that I have a stupid typo in my git config get user.name on that machine. ]
- added RWB tag from Alex Bennée
- adjusted a commit message

---
 hw/char/pl011.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
hw/char/pl011.c +15 -1
index cb12c3e224f..3622248ec0c 100644
@@ -660,12 +660,26 @@ static void pl011_init(Object *obj)
     s->id = pl011_id_arm;
 }
 
+static int pl011_be_change(void *opaque)
+{
+    PL011State *s = opaque;
+    int break_enable = s->lcr & LCR_BRK;
+
+    qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
+                             pl011_event, pl011_be_change, s, NULL, true);
+
+    qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                      &break_enable);
+
+    return 0;
+}
+
 static void pl011_realize(DeviceState *dev, Error **errp)
 {
     PL011State *s = PL011(dev);
 
     qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
-                             pl011_event, NULL, s, NULL, true);
+                             pl011_event, pl011_be_change, s, NULL, true);
 }
 
 static void pl011_reset(DeviceState *dev)
Signature · 1 line
2.47.3
#1 lore raw

Hi Alexander,

Quoted 37 lines · Alexander Mikhalitsyn

From: Alexander Mikhalitsyn <[email protected]>

Currently, when Incus issues "chardev-change" QMP command to change chardev backend from ringbuf to socket it receives an error (with aarch64 VM):
"Chardev user does not support chardev hotswap" [1], [2]

Let's fix this by properly implementing BackendChangeHandler for pl011.

Please, note that we have to "replay" CHR_IOCTL_SERIAL_SET_BREAK, because if BRK bit was set before backend change (i.e. (s->lcr & LCR_BRK) is true), then after change we need to send break to a new backend too.

---
v2:
- fixed a typo in commit author name
[ I did git format-patch and copied this patch from my Raspberry PI
dev/test machine and it turns out that I have a stupid typo in my git config get user.name on that machine. ]
- added RWB tag from Alex Bennée
- adjusted a commit message

---
  hw/char/pl011.c | 16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
hw/char/pl011.c +0 -0
index cb12c3e224f..3622248ec0c 100644
@@ -660,12 +660,26 @@ static void pl011_init(Object *obj)
      s->id = pl011_id_arm;
  }
 

hw/char/pl011.c static void pl011_init(Object *obj) · line 672

Quoted 10 lines
hw/char/pl011.c +10 -0
+static int pl011_be_change(void *opaque)
+{
+    PL011State *s = opaque;
+    int break_enable = s->lcr & LCR_BRK;
+
+    qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
+                             pl011_event, pl011_be_change, s, NULL, true);
+
+    qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                      &break_enable);

Could we factor the common code used in pl011_write() in a common helper?

Quoted 14 lines
hw/char/pl011.c +5 -1
+
+    return 0;
+}
+
  static void pl011_realize(DeviceState *dev, Error **errp)
  {
      PL011State *s = PL011(dev);
 
      qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
-                             pl011_event, NULL, s, NULL, true);
+                             pl011_event, pl011_be_change, s, NULL, true);
  }
 
  static void pl011_reset(DeviceState *dev)
#2 lore raw

Am Di., 11. Aug. 2026 um 10:30 Uhr schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 41 lines

Hi Alexander,

Quoted 37 lines · Alexander Mikhalitsyn

From: Alexander Mikhalitsyn <[email protected]>

Currently, when Incus issues "chardev-change" QMP command to change chardev backend from ringbuf to socket it receives an error (with aarch64 VM):
"Chardev user does not support chardev hotswap" [1], [2]

Let's fix this by properly implementing BackendChangeHandler for pl011.

Please, note that we have to "replay" CHR_IOCTL_SERIAL_SET_BREAK, because if BRK bit was set before backend change (i.e. (s->lcr & LCR_BRK) is true), then after change we need to send break to a new backend too.

---
v2:
- fixed a typo in commit author name
[ I did git format-patch and copied this patch from my Raspberry PI
dev/test machine and it turns out that I have a stupid typo in my git config get user.name on that machine. ]
- added RWB tag from Alex Bennée
- adjusted a commit message

---
  hw/char/pl011.c | 16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
hw/char/pl011.c +0 -0
index cb12c3e224f..3622248ec0c 100644
@@ -660,12 +660,26 @@ static void pl011_init(Object *obj)
      s->id = pl011_id_arm;
  }
 
Quoted 11 lines

hw/char/pl011.c static void pl011_init(Object *obj) · line 672

Quoted 10 lines
hw/char/pl011.c +10 -0
+static int pl011_be_change(void *opaque)
+{
+    PL011State *s = opaque;
+    int break_enable = s->lcr & LCR_BRK;
+
+    qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
+                             pl011_event, pl011_be_change, s, NULL, true);
+
+    qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+                      &break_enable);

Dear Philippe,

thank you for the review!

Quoted 2 lines

Could we factor the common code used in pl011_write() in a common helper?

yep, I think we can factor out CHR_IOCTL_SERIAL_SET_BREAK call together with break_enable variable.

Please, can you look into our thread with Alex Bennée:
https://lore.kernel.org/qemu-devel/[email protected]/

It would be great to have your opinion there.

Kind regards,
Alex

Quoted 16 lines
Quoted 15 lines
hw/char/pl011.c +5 -1
+
+    return 0;
+}
+
  static void pl011_realize(DeviceState *dev, Error **errp)
  {
      PL011State *s = PL011(dev);
 
      qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
-                             pl011_event, NULL, s, NULL, true);
+                             pl011_event, pl011_be_change, s, NULL, true);
  }
 
  static void pl011_reset(DeviceState *dev)