hw/net/tulip: Fix LP#1874539
cover hw/net/tulip: Fix LP#1874539
Attempt to fix the launchpad bug filled by Helge:
In a qemu-system-hppa system, qemu release v5.0.0-rc, the tulip nic driver is broken. The tulip nic is detected, even getting DHCP info does work. But when trying to download bigger files via network, the tulip driver gets stuck.
Philippe Mathieu-Daudé (3):
hw/net/tulip: Fix 'Descriptor Error' definition hw/net/tulip: Log descriptor overflows
hw/net/tulip: Set descriptor error bit when lenght is incorrect
hw/net/tulip.h | 2 +- hw/net/tulip.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.1
RFC PATCH 1/3 hw/net/tulip: Fix 'Descriptor Error' definition
Bit #14 is "DE" for 'Descriptor Error':
When set, indicates a frame truncation caused by a frame that does not fit within the current descriptor buffers, and that the 21143 does not own the next descriptor.
[Table 4-1. RDES0 Bit Fields Description]
--- hw/net/tulip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/tulip.h +1 -1
@@ -211,7 +211,7 @@#define RDES0_RF BIT(11)#define RDES0_DT_SHIFT 12#define RDES0_DT_MASK 3 -#define RDES0_LE BIT(14) +#define RDES0_DE BIT(14)#define RDES0_ES BIT(15)#define RDES0_FL_SHIFT 16#define RDES0_FL_MASK 0x3fff
Signature · 1 line
2.21.1
RFC PATCH 2/3 hw/net/tulip: Log descriptor overflows
In reply to Philippe Mathieu-DaudéLog with GUEST_ERROR what the guest is doing wrong.
--- hw/net/tulip.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/net/tulip.c +16 -0
@@ -172,6 +172,11 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) }if (s->rx_frame_len + len >sizeof (s->rx_frame)) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: descriptor overflow " +"(ofs: %u, len:%d, size:%zu)\n" , + __func__, s->rx_frame_len, len, +sizeof (s->rx_frame));return ; } pci_dma_write(&s->dev, desc->buf_addr1, s->rx_frame +
@@ -187,6 +192,11 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) }if (s->rx_frame_len + len >sizeof (s->rx_frame)) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: descriptor overflow " +"(ofs: %u, len:%d, size:%zu)\n" , + __func__, s->rx_frame_len, len, +sizeof (s->rx_frame));return ; } pci_dma_write(&s->dev, desc->buf_addr2, s->rx_frame +
@@ -584,6 +594,9 @@ static int tulip_copy_tx_buffers(TULIPState *s, struct tulip_descriptor *desc)int len2 = (desc->control >>TDES1_BUF2_SIZE_SHIFT ) &TDES1_BUF2_SIZE_MASK ;if (s->tx_frame_len + len1 >sizeof (s->tx_frame)) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: descriptor overflow (ofs: %u, len:%d, size:%zu)\n" , + __func__, s->tx_frame_len, len1,sizeof (s->tx_frame));return -1 ; }if (len1) {
@@ -593,6 +606,9 @@ static int tulip_copy_tx_buffers(TULIPState *s, struct tulip_descriptor *desc) }if (s->tx_frame_len + len2 >sizeof (s->tx_frame)) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: descriptor overflow (ofs: %u, len:%d, size:%zu)\n" , + __func__, s->tx_frame_len, len2,sizeof (s->tx_frame));return -1 ; }if (len2) {
Signature · 1 line
2.21.1
RFC PATCH 3/3 hw/net/tulip: Set descriptor error bit when lenght is incorrect
In reply to Philippe Mathieu-DaudéWhen a frame lenght is incorrect, set the RDES0 'Error Summary' and 'Frame too long' bits. Then stop the receive process and trigger an abnormal interrupt. See [4.3.5 Receive Process].
--- hw/net/tulip.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
hw/net/tulip.c +12 -4
@@ -158,7 +158,7 @@ static void tulip_next_rx_descriptor(TULIPState *s, s->current_rx_desc &= ~3ULL ; } -static void tulip_copy_rx_bytes (TULIPState *s,struct tulip_descriptor *desc) +static int tulip_copy_rx_bytes (TULIPState *s,struct tulip_descriptor *desc) {int len1 = (desc->control >>RDES1_BUF1_SIZE_SHIFT ) &RDES1_BUF1_SIZE_MASK ;int len2 = (desc->control >>RDES1_BUF2_SIZE_SHIFT ) &RDES1_BUF2_SIZE_MASK ;
@@ -177,7 +177,8 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)"(ofs: %u, len:%d, size:%zu)\n" , __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); -return ; + s->rx_frame_len =0 ; +return -1 ; }pci_dma_write (&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len);
@@ -197,12 +198,15 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)"(ofs: %u, len:%d, size:%zu)\n" , __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); -return ; + s->rx_frame_len =0 ; +return -1 ; }pci_dma_write (&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len; } + +return 0 ; }static bool tulip_filter_address (TULIPState *s,const uint8_t *addr)
@@ -274,7 +278,11 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size) s->rx_frame_len = s->rx_frame_size; } -tulip_copy_rx_bytes (s, &desc); +if (tulip_copy_rx_bytes (s, &desc)) { + desc.status |=RDES0_ES |RDES0_TL ;/* Error: frame too long */ + s->csr[5 ] |=CSR5_RPS ;/* Receive process stopped */ +tulip_update_int (s); + }if (!s->rx_frame_len) { desc.status |= s->rx_status;
Signature · 1 line
2.21.1
Re: [RFC PATCH 3/3] hw/net/tulip: Set descriptor error bit when lenght is incorrect
Quoted 4 lines · Philippe Mathieu-Daudé
When a frame lenght is incorrect, set the RDES0 'Error Summary' and 'Frame too long' bits. Then stop the receive process and trigger an abnormal interrupt. See [4.3.5 Receive Process].
Quoted 9 lines
Cc Li Qiang <[email protected]>Cc Li Qiang <[email protected]>Cc Ziming Zhang <[email protected]>Cc Jason Wang <[email protected]>Cc Prasad J Pandit <[email protected]>Fixes 8ffb7265af ("check frame size and r/w data length")Reported-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Hi Philippe:
It's still unclear to me that how this fixes the stuck. Did you mean guest trigger the error condition and then recvoer by abnormal interrupt?
If yes, this sounds still like a bug somewhere in the code.
Thanks
Quoted 57 lines
--- hw/net/tulip.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)hw/net/tulip.c +12
-4@@ -158,7 +158,7 @@ static void tulip_next_rx_descriptor(TULIPState *s, s->current_rx_desc &= ~3ULL ; } -static void tulip_copy_rx_bytes (TULIPState *s,struct tulip_descriptor *desc) +static int tulip_copy_rx_bytes (TULIPState *s,struct tulip_descriptor *desc) {int len1 = (desc->control >>RDES1_BUF1_SIZE_SHIFT ) &RDES1_BUF1_SIZE_MASK ;int len2 = (desc->control >>RDES1_BUF2_SIZE_SHIFT ) &RDES1_BUF2_SIZE_MASK ;@@ -177,7 +177,8 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)"(ofs: %u, len:%d, size:%zu)\n" , __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); -return ; + s->rx_frame_len =0 ; +return -1 ; }pci_dma_write (&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len);@@ -197,12 +198,15 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc)"(ofs: %u, len:%d, size:%zu)\n" , __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); -return ; + s->rx_frame_len =0 ; +return -1 ; }pci_dma_write (&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len; } + +return 0 ; }static bool tulip_filter_address (TULIPState *s,const uint8_t *addr)@@ -274,7 +278,11 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size) s->rx_frame_len = s->rx_frame_size; } -tulip_copy_rx_bytes (s, &desc); +if (tulip_copy_rx_bytes (s, &desc)) { + desc.status |=RDES0_ES |RDES0_TL ;/* Error: frame too long */ + s->csr[5 ] |=CSR5_RPS ;/* Receive process stopped */ +tulip_update_int (s); + }if (!s->rx_frame_len) { desc.status |= s->rx_status;
Re: [RFC PATCH 3/3] hw/net/tulip: Set descriptor error bit when lenght is incorrect
Quoted 17 lines · Jason Wang
Quoted 4 lines · Philippe Mathieu-Daudé
When a frame lenght is incorrect, set the RDES0 'Error Summary' and 'Frame too long' bits. Then stop the receive process and trigger an abnormal interrupt. See [4.3.5 Receive Process].
Quoted 9 lines
Cc Li Qiang <[email protected]>Cc Li Qiang <[email protected]>Cc Ziming Zhang <[email protected]>Cc Jason Wang <[email protected]>Cc Prasad J Pandit <[email protected]>Fixes 8ffb7265af ("check frame size and r/w data length")Reported-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 5 lines
Hi Philippe:
It's still unclear to me that how this fixes the stuck. Did you mean guest trigger the error condition and then recvoer by abnormal interrupt?
If yes, this sounds still like a bug somewhere in the code.
Sadly the patches do not fix the bug.
Helge
Quoted 55 lines
Quoted 54 lines
---
hw/net/tulip.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)hw/net/tulip.c +3
-1@@ -158,7 +158,7 @@ static void tulip_next_rx_descriptor(TULIPState *s, s->current_rx_desc &= ~3ULL; } -static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) +static int tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) { int len1 = (desc->control >> RDES1_BUF1_SIZE_SHIFT) & RDES1_BUF1_SIZE_MASK; int len2 = (desc->control >> RDES1_BUF2_SIZE_SHIFT) & RDES1_BUF2_SIZE_MASK;@@ -177,7 +177,8 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) "(ofs: %u, len:%d, size:%zu)\n", __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); - return; + s->rx_frame_len = 0; + return -1; }
pci_dma_write(&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len);hw/net/tulip.c +2
-1@@ -197,12 +198,15 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) "(ofs: %u, len:%d, size:%zu)\n", __func__, s->rx_frame_len, len, sizeof(s->rx_frame)); - return; + s->rx_frame_len = 0; + return -1; }
pci_dma_write(&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len);s->rx_frame_len-= len;
}
+
+ return 0;
}
static booltulip_filter_address(TULIPState *s, const uint8_t *addr)hw/net/tulip.c +5
-0@@ -274,7 +278,11 @@ static ssize_t tulip_receive(TULIPState *s, const uint8_t *buf, size_t size) s->rx_frame_len = s->rx_frame_size; } - tulip_copy_rx_bytes(s, &desc); + if (tulip_copy_rx_bytes(s, &desc)) { + desc.status |= RDES0_ES | RDES0_TL; /* Error: frame too long */ + s->csr[5] |= CSR5_RPS; /* Receive process stopped */ + tulip_update_int(s); + } if (!s->rx_frame_len) { desc.status |= s->rx_status;
Re: [RFC PATCH 3/3] hw/net/tulip: Set descriptor error bit when lenght is incorrect
In reply to Philippe Mathieu-DaudéQuoted 1 line · Philippe Mathieu-Daudé
When a frame lenght is incorrect, set the RDES0 'Error Summary'
length (here, and in the subject)
Quoted 3 lines
and 'Frame too long' bits. Then stop the receive process and trigger an abnormal interrupt. See [4.3.5 Receive Process].
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
* Philippe Mathieu-Daudé <[email protected]>:
Quoted 8 lines
Attempt to fix the launchpad bug filled by Helge:
In a qemu-system-hppa system, qemu release v5.0.0-rc, the tulip nic driver is broken. The tulip nic is detected, even getting DHCP info does work. But when trying to download bigger files via network, the tulip driver gets stuck.
Quoted 8 lines
Philippe Mathieu-Daudé (3):
hw/net/tulip: Fix 'Descriptor Error' definition hw/net/tulip: Log descriptor overflows
hw/net/tulip: Set descriptor error bit when lenght is incorrecthw/net/tulip.h | 2 +- hw/net/tulip.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-)
Philippe, thanks for your efforts. Sadly your patch did not fixed the bug itself, but it had some nice cleanups which should be included at some point.
Regarding the tulip hang reported by me, the patch below does fix the issue.
[PATCH] Fix tulip rx hang
Commit 8ffb7265af ("check frame size and r/w data length") introduced checks to prevent accesses outside of the rx/tx buffers. But the new checks were plain wrong. rx_frame_len does count backwards, and the surrounding code ensures that rx_frame_len will not be bigger than rx_frame_size. Remove those checks again.
hw/net/tulip.c +0 -6
@@ -171,9 +171,6 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) len = s->rx_frame_len; } -if (s->rx_frame_len + len >sizeof (s->rx_frame)) { -return ; - }pci_dma_write (&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len;
@@ -186,9 +183,6 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) len = s->rx_frame_len; } -if (s->rx_frame_len + len >sizeof (s->rx_frame)) { -return ; - }pci_dma_write (&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len;
Quoted 52 lines · Helge Deller
* Philippe Mathieu-Daudé <[email protected]>:
Quoted 8 lines
Attempt to fix the launchpad bug filled by Helge:
In a qemu-system-hppa system, qemu release v5.0.0-rc, the tulip nic driver is broken. The tulip nic is detected, even getting DHCP info does work. But when trying to download bigger files via network, the tulip driver gets stuck.
Quoted 8 lines
Philippe Mathieu-Daudé (3):
hw/net/tulip: Fix 'Descriptor Error' definition hw/net/tulip: Log descriptor overflows
hw/net/tulip: Set descriptor error bit when lenght is incorrecthw/net/tulip.h | 2 +- hw/net/tulip.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-)Philippe, thanks for your efforts. Sadly your patch did not fixed the bug itself, but it had some nice cleanups which should be included at some point.
Regarding the tulip hang reported by me, the patch below does fix the issue.
[PATCH] Fix tulip rx hang
Cc Prasad J Pandit <[email protected]>Fixes 8ffb7265af ("check frame size and r/w data length")Signed-off-by Helge Deller <[email protected]>Commit
8ffb7265af("check frame size and r/w data length") introduced checks to prevent accesses outside of the rx/tx buffers. But the new checks were plain wrong.rx_frame_lendoes count backwards, and the surrounding code ensures thatrx_frame_lenwill not be bigger thanrx_frame_size. Remove those checks again.hw/net/tulip.c +0
-3@@ -171,9 +171,6 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) len = s->rx_frame_len; } -if (s->rx_frame_len + len >sizeof (s->rx_frame)) { -return ; - }pci_dma_write (&s->dev, desc->buf_addr1, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len;
hw/net/tulip.c static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) · line 188
Quoted 9 lines
hw/net/tulip.c +0
-3@@ -186,9 +183,6 @@ static void tulip_copy_rx_bytes(TULIPState *s, struct tulip_descriptor *desc) len = s->rx_frame_len; } -if (s->rx_frame_len + len >sizeof (s->rx_frame)) { -return ; - }pci_dma_write (&s->dev, desc->buf_addr2, s->rx_frame + (s->rx_frame_size - s->rx_frame_len), len); s->rx_frame_len -= len;
Looks good to me.
Would you please send a formal patch and cc Peter.
Consider we are about to release 5.0, it's better for him to apply the patch directly.
Thanks
Quoted 6 lines · Jason Wang
Looks good to me.
Would you please send a formal patch and cc Peter.
Consider we are about to release 5.0, it's better for him to apply the patch directly.
I am not applying any further patches for 5.0 unless they come with an attached rock-solid justification for why we should delay the release again for them.
thanks
-- PMM
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Jason Wang
Looks good to me.
Would you please send a formal patch and cc Peter.
Quoted 8 lines
Quoted 2 lines
Consider we are about to release 5.0, it's better for him to apply the patch directly.
I am not applying any further patches for 5.0 unless they come with an attached rock-solid justification for why we should delay the release again for them.
thanks
-- PMM
Ok.
I will queue that patch for 5.1.
Thanks
Quoted 1 line
Hi Jason,
Quoted 13 lines · Jason Wang
Quoted 12 lines · Peter Maydell
Quoted 6 lines · Jason Wang
Looks good to me.
Would you please send a formal patch and cc Peter.
Consider we are about to release 5.0, it's better for him to apply the patch directly.
I am not applying any further patches for 5.0 unless they come with an attached rock-solid justification for why we should delay the release again for them.
Quoted 7 lines
Quoted 2 lines
thanks
-- PMMOk.
I will queue that patch for 5.1.
Can you queue patches #1 and #2?
Quoted 7 lines
Thanks
Quoted 1 line
Quoted 20 lines · Philippe Mathieu-Daudé
Hi Jason,
Quoted 17 lines · Jason Wang
Quoted 14 lines · Peter Maydell
Quoted 6 lines · Jason Wang
Looks good to me.
Would you please send a formal patch and cc Peter.
Consider we are about to release 5.0, it's better for him to apply the patch directly.
I am not applying any further patches for 5.0 unless they come with an attached rock-solid justification for why we should delay the release again for them.
thanks
-- PMM
Quoted 5 lines
Quoted 3 lines
Ok.
I will queue that patch for 5.1.
Can you queue patches #1 and #2?
Queued.
Thanks
Quoted 9 lines
Quoted 8 lines
Thanks
Quoted 1 line