Skip to content

Commit 10e3edd

Browse files
pm215Michael Tokarev
authored andcommitted
hw/char/pl011: Use correct masks for IBRD and FBRD
In commit b88cfee we defined masks for the IBRD and FBRD integer and fractional baud rate divider registers, to prevent the guest from writing invalid values which could cause division-by-zero. Unfortunately we got the mask values the wrong way around: the FBRD register is six bits and the IBRD register is 16 bits, not vice-versa. You would only run into this bug if you programmed the UART to a baud rate of less than 9600, because for 9600 baud and above the IBRD value will fit into 6 bits, as per the table in https://developer.arm.com/documentation/ddi0183/g/programmers-model/register-descriptions/fractional-baud-rate-register--uartfbrd The only visible effects would be that the value read back from the register by the guest would be truncated, and we would print an incorrect baud rate in the debug logs. Cc: [email protected] Fixes: b88cfee ("hw/char/pl011: Avoid division-by-zero in pl011_get_baudrate()") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2610 Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Message-id: [email protected] (cherry picked from commit cd247ea) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 460ddd6 commit 10e3edd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

hw/char/pl011.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ DeviceState *pl011_create(hwaddr addr, qemu_irq irq, Chardev *chr)
8888
#define CR_LBE (1 << 7)
8989

9090
/* Integer Baud Rate Divider, UARTIBRD */
91-
#define IBRD_MASK 0x3f
91+
#define IBRD_MASK 0xffff
9292

9393
/* Fractional Baud Rate Divider, UARTFBRD */
94-
#define FBRD_MASK 0xffff
94+
#define FBRD_MASK 0x3f
9595

9696
static const unsigned char pl011_id_arm[8] =
9797
{ 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };

0 commit comments

Comments
 (0)