xen/arm: vpl011 fixes continuation
cover xen/arm: vpl011 fixes continuation
Another portion of vpl011 fixes/hardening.
Michal Orzel (3):
xen/arm: vpl011: Fix misleading comments
xen/arm: vpl011: Handle correctly TXFE when backend in Xen xen/arm: vpl011: Do not try to handle TX FIFO status when backend in
Xen
xen/arch/arm/vpl011.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 xen/arm: vpl011: Fix misleading comments
In both vpl011_read_data() and vpl011_read_data_xen(), there is a comment stating that the guest is expected to read the DR register only if the TXFE bit of FR register is not set. This is obviously logically wrong and it should be RXFE (i.e. RX FIFO empty bit set -> nothing to read).
--- xen/arch/arm/vpl011.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/vpl011.c +4 -4
@@ -143,8 +143,8 @@ static uint8_t vpl011_read_data_xen(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register -* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned. +* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned. */ if (xencons_queued (in_prod, in_cons,sizeof (intf->in)) >0 ) {
@@ -202,8 +202,8 @@ static uint8_t vpl011_read_data(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register -* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned. +* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned. */ if (xencons_queued (in_prod, in_cons,sizeof (intf->in)) >0 ) {
Signature · 1 line
2.25.1
Re: [PATCH 1/3] xen/arm: vpl011: Fix misleading comments
Quoted 4 lines · Michal Orzel
In both
vpl011_read_data()andvpl011_read_data_xen(), there is a comment stating that the guest is expected to read the DR register only if the TXFE bit of FR register is not set. This is obviously logically wrong and it should be RXFE (i.e. RX FIFO empty bit set -> nothing to read).
NIT:- I will prefer if the PL011 TRM is mentioned with the relevant section.
Quoted 2 lines
Signed-off-by Michal Orzel <[email protected]>
Quoted 30 lines
--- xen/arch/arm/vpl011.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)xen/arch/arm/vpl011.c +4
-4@@ -143,8 +143,8 @@ static uint8_t vpl011_read_data_xen(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register -* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned. +* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned. */ if (xencons_queued (in_prod, in_cons,sizeof (intf->in)) >0 ) {@@ -202,8 +202,8 @@ static uint8_t vpl011_read_data(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register -* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned. +* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned. */ if (xencons_queued (in_prod, in_cons,sizeof (intf->in)) >0 ) {
Stefano Stabellini
Reviewed-byRe: [PATCH 1/3] xen/arm: vpl011: Fix misleading comments
Quoted 9 lines · Ayan Kumar Halder
Quoted 4 lines · Michal Orzel
In both
vpl011_read_data()andvpl011_read_data_xen(), there is a comment stating that the guest is expected to read the DR register only if the TXFE bit of FR register is not set. This is obviously logically wrong and it should be RXFE (i.e. RX FIFO empty bit set -> nothing to read).NIT:- I will prefer if the PL011 TRM is mentioned with the relevant section.
Quoted 2 lines
Signed-off-by Michal Orzel <[email protected]>Reviewed-by Ayan Kumar Halder <[email protected]>
Quoted 37 lines
Quoted 36 lines
--- xen/arch/arm/vpl011.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)xen/arch/arm/vpl011.c +0
-0@@ -143,8 +143,8 @@ static uint8_t vpl011_read_data_xen(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register
xen/arch/arm/vpl011.c +0
-2-* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned.
xen/arch/arm/vpl011.c +2
-0+* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned.
*/ if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 ) {xen/arch/arm/vpl011.c +0
-0@@ -202,8 +202,8 @@ static uint8_t vpl011_read_data(struct domain *d)/* * It is expected that there will be data in the ring buffer when this * function is called since the guest is expected to read the data register
xen/arch/arm/vpl011.c +0
-2-* only if the TXFE flag is not set. -* If the guest still does read when TXFE bit is set then 0 will be returned.
xen/arch/arm/vpl011.c +2
-0+* only if the RXFE flag is not set. +* If the guest still does read when RXFE bit is set then 0 will be returned.
*/ if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) > 0 ) {
RE: [PATCH 1/3] xen/arm: vpl011: Fix misleading comments
In reply to Michal OrzelHi Michal,
Quoted 9 lines
-----Original Message-----
Subject: [PATCH 1/3] xen/arm: vpl011: Fix misleading commentsIn both
vpl011_read_data()andvpl011_read_data_xen(), there is a comment stating that the guest is expected to read the DR register only if the TXFE bit of FR register is not set. This is obviously logically wrong and it should be RXFE (i.e. RX FIFO empty bit set -> nothing to read).Signed-off-by Michal Orzel <[email protected]>
Kind regards,
Henry
PATCH 2/3 xen/arm: vpl011: Handle correctly TXFE when backend in Xen
In reply to Michal OrzelWhen backend is in Xen, the handling of data written to DR register is a bit special because we want to tell guest that we are always ready for new data to be written (i.e. no real FIFO, TXFF/BUSY never set and TXI always set). This conflicts with the current handling of TXFE bit, which we always clear and never set on a write path (we happen to set it when we receive char from serial input due to use of vpl011_data_avail() but this might never be called). This can lead to issues if a guest driver makes use of TXFE bit to check for TX transmission completion (such guest could then wait endlessly). Fix it by keeping TXFE always set to match the current emulation logic.
---
We don't have to look far for an example of a PL011/SBSA driver relying on TXFE. If a guest had a driver like we have in Xen, we would end up with no messages being printed.
--- xen/arch/arm/vpl011.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/arch/arm/vpl011.c +7 -1
@@ -112,8 +112,14 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) } } +/* +* When backend is in Xen, we tell guest we are always ready for new data +* to be written. This is fulfilled by having: +* - TXI/TXFE -> always set, +* - TXFF/BUSY -> never set. +*/ vpl011->uartris |=TXI ; - vpl011->uartfr &= ~TXFE ; + vpl011->uartfr |=TXFE ;vpl011_update_interrupt_status (d);VPL011_UNLOCK (d, flags);
Signature · 1 line
2.25.1
Re: [PATCH 2/3] xen/arm: vpl011: Handle correctly TXFE when backend in Xen
Quoted 11 lines · Michal Orzel
When backend is in Xen, the handling of data written to DR register is a bit special because we want to tell guest that we are always ready for new data to be written (i.e. no real FIFO, TXFF/BUSY never set and TXI always set). This conflicts with the current handling of TXFE bit, which we always clear and never set on a write path (we happen to set it when we receive char from serial input due to use of
vpl011_data_avail()but this might never be called). This can lead to issues if a guest driver makes use of TXFE bit to check for TX transmission completion (such guest could then wait endlessly). Fix it by keeping TXFE always set to match the current emulation logic.
Quoted 1 line
Signed-off-by Michal Orzel <[email protected]>
Quoted 31 lines
---
We don't have to look far for an example of a PL011/SBSA driver relying on TXFE. If a guest had a driver like we have in Xen, we would end up with no messages being printed.--- xen/arch/arm/vpl011.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/arch/arm/vpl011.c +7
-1@@ -112,8 +112,14 @@ static void vpl011_write_data_xen(struct domain *d, uint8_t data) } } +/* +* When backend is in Xen, we tell guest we are always ready for new data +* to be written. This is fulfilled by having: +* - TXI/TXFE -> always set, +* - TXFF/BUSY -> never set. +*/ vpl011->uartris |=TXI ; - vpl011->uartfr &= ~TXFE ; + vpl011->uartfr |=TXFE ;vpl011_update_interrupt_status (d);VPL011_UNLOCK (d, flags);Signature · 1 line
2.25.1
RE: [PATCH 2/3] xen/arm: vpl011: Handle correctly TXFE when backend in Xen
In reply to Michal OrzelHi Michal,
Quoted 15 lines
-----Original Message-----
Subject: [PATCH 2/3] xen/arm: vpl011: Handle correctly TXFE when backend in XenWhen backend is in Xen, the handling of data written to DR register is a bit special because we want to tell guest that we are always ready for new data to be written (i.e. no real FIFO, TXFF/BUSY never set and TXI always set). This conflicts with the current handling of TXFE bit, which we always clear and never set on a write path (we happen to set it when we receive char from serial input due to use of
vpl011_data_avail()but this might never be called). This can lead to issues if a guest driver makes use of TXFE bit to check for TX transmission completion (such guest could then wait endlessly). Fix it by keeping TXFE always set to match the current emulation logic.
Quoted 1 line
Signed-off-by Michal Orzel <[email protected]>
Kind regards,
Henry
PATCH 3/3 xen/arm: vpl011: Do not try to handle TX FIFO status when backend in Xen
In reply to Michal OrzelFrom vpl011_rx_char_xen(), we call vpl011_data_avail() that handles both RX and TX state. Because we are passing 0 as out_fifo_level and SBSA_UART_FIFO_SIZE as out_size, we end up calling a function vpl011_update_tx_fifo_status() which performs TXI bit handling depending on the FIFO trigger level. This does not make sense when backend is in Xen, as we maintain a single TX state where data can always be written and as such there is no TX FIFO handling. Furthermore, this function assumes that the backend is in domain by making use of struct xencons_interface unconditionally. Fix it by calling this function only when backend is in domain. Also add an assert for sanity.
--- xen/arch/arm/vpl011.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
xen/arch/arm/vpl011.c +10 -1
@@ -261,6 +261,9 @@ static void vpl011_update_tx_fifo_status(struct vpl011 *vpl011,struct xencons_interface *intf = vpl011->backend.dom.ring_buf;unsigned int fifo_threshold =sizeof (intf->out) -SBSA_UART_FIFO_LEVEL ; +/* No TX FIFO handling when backend is in Xen */ +ASSERT (vpl011->backend_in_domain); +BUILD_BUG_ON (sizeof (intf->out) <SBSA_UART_FIFO_SIZE );/*
@@ -547,7 +550,13 @@ static void vpl011_data_avail(struct domain *d,*/ vpl011->uartfr &= ~BUSY ; -vpl011_update_tx_fifo_status (vpl011, out_fifo_level); +/* +* When backend is in Xen, we are always ready for new data to be +* written (i.e. no TX FIFO handling), therefore we do not want +* to change the TX FIFO status in such case. +*/ +if ( vpl011->backend_in_domain ) +vpl011_update_tx_fifo_status (vpl011, out_fifo_level); }vpl011_update_interrupt_status (d);
Signature · 1 line
2.25.1
Re: [PATCH 3/3] xen/arm: vpl011: Do not try to handle TX FIFO status when backend in Xen
Quoted 11 lines · Michal Orzel
Quoted 1 line
From
vpl011_rx_char_xen(), we callvpl011_data_avail()that handles bothRX and TX state. Because we are passing 0 as
out_fifo_levelandSBSA_UART_FIFO_SIZEasout_size, we end up calling a functionvpl011_update_tx_fifo_status()which performs TXI bit handling depending on the FIFO trigger level. This does not make sense when backend is in Xen, as we maintain a single TX state where data can always be written and as such there is no TX FIFO handling. Furthermore, this function assumes that the backend is in domain by making use of structxencons_interfaceunconditionally. Fix it by calling this function only when backend is in domain. Also add an assert for sanity.
Quoted 1 line
Signed-off-by Michal Orzel <[email protected]>
Quoted 36 lines
--- xen/arch/arm/vpl011.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)xen/arch/arm/vpl011.c +10
-1@@ -261,6 +261,9 @@ static void vpl011_update_tx_fifo_status(struct vpl011 *vpl011,struct xencons_interface *intf = vpl011->backend.dom.ring_buf;unsigned int fifo_threshold =sizeof (intf->out) -SBSA_UART_FIFO_LEVEL ; +/* No TX FIFO handling when backend is in Xen */ +ASSERT (vpl011->backend_in_domain); +BUILD_BUG_ON (sizeof (intf->out) <SBSA_UART_FIFO_SIZE );/* @@ -547,7 +550,13 @@ static void vpl011_data_avail(struct domain *d,*/ vpl011->uartfr &= ~BUSY ; -vpl011_update_tx_fifo_status (vpl011, out_fifo_level); +/* +* When backend is in Xen, we are always ready for new data to be +* written (i.e. no TX FIFO handling), therefore we do not want +* to change the TX FIFO status in such case. +*/ +if ( vpl011->backend_in_domain ) +vpl011_update_tx_fifo_status (vpl011, out_fifo_level); }vpl011_update_interrupt_status (d);Signature · 1 line
2.25.1
RE: [PATCH 3/3] xen/arm: vpl011: Do not try to handle TX FIFO status when backend in Xen
In reply to Michal OrzelHi Michal,
Quoted 15 lines
-----Original Message-----
Subject: [PATCH 3/3] xen/arm: vpl011: Do not try to handle TX FIFO status when backend in XenFrom
vpl011_rx_char_xen(), we callvpl011_data_avail()that handles both RX and TX state. Because we are passing 0 asout_fifo_levelandSBSA_UART_FIFO_SIZEasout_size, we end up calling a functionvpl011_update_tx_fifo_status()which performs TXI bit handling depending on the FIFO trigger level. This does not make sense when backend is in Xen, as we maintain a single TX state where data can always be written and as such there is no TX FIFO handling. Furthermore, this function assumes that the backend is in domain by making use of structxencons_interfaceunconditionally. Fix it by calling this function only when backend is in domain. Also add an assert for sanity.
Quoted 1 line
Signed-off-by Michal Orzel <[email protected]>
I've tested the patch by manually running the XTP on FVP_Base, and this patch works fine. So:
Kind regards,
Henry