[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 3/7] rtl8139: use ldl/stl wrapper for unaligned 32-bi
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 3/7] rtl8139: use ldl/stl wrapper for unaligned 32-bit access |
Date: |
Wed, 2 Sep 2015 17:14:49 +0100 |
The tx offload feature accesses a 16-bit aligned TCP header struct. The
32-bit fields must be accessed using ldl/stl wrappers since some host
architectures fault on unaligned access.
Suggested-by: Peter Maydell <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Jason Wang <address@hidden>
Message-id: address@hidden
---
hw/net/rtl8139.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 36be22b..366d1b5 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -2118,7 +2118,11 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
DPRINTF("+++ C+ mode has IP packet\n");
- /* not aligned */
+ /* Note on memory alignment: eth_payload_data is 16-bit aligned
+ * since saved_buffer is allocated with g_malloc() and ETH_HLEN is
+ * even. 32-bit accesses must use ldl/stl wrappers to avoid
+ * unaligned accesses.
+ */
eth_payload_data = saved_buffer + ETH_HLEN;
eth_payload_len = saved_size - ETH_HLEN;
@@ -2215,7 +2219,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
}
DPRINTF("+++ C+ mode TSO TCP seqno %08x\n",
- be32_to_cpu(p_tcp_hdr->th_seq));
+ ldl_be_p(&p_tcp_hdr->th_seq));
/* add 4 TCP pseudoheader fields */
/* copy IP source and destination fields */
@@ -2271,7 +2275,8 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s)
0, (uint8_t *) dot1q_buffer);
/* add transferred count to TCP sequence number */
- p_tcp_hdr->th_seq = cpu_to_be32(chunk_size +
be32_to_cpu(p_tcp_hdr->th_seq));
+ stl_be_p(&p_tcp_hdr->th_seq,
+ chunk_size + ldl_be_p(&p_tcp_hdr->th_seq));
++send_count;
}
--
2.4.3
- [Qemu-devel] [PULL 0/7] Net patches, Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 1/7] rtl8139: remove duplicate net/eth.h definitions, Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 2/7] rtl8139: use net/eth.h macros instead of custom macros, Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 3/7] rtl8139: use ldl/stl wrapper for unaligned 32-bit access,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 4/7] rtl8139: Fix receive buffer overflow check, Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 5/7] rtl8139: Do not consume the packet during overflow in standard mode., Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 6/7] vmxnet3: Drop net_vmxnet3_info.can_receive, Stefan Hajnoczi, 2015/09/02
- [Qemu-devel] [PULL 7/7] ne2000: Drop ne2000_can_receive, Stefan Hajnoczi, 2015/09/02
- Re: [Qemu-devel] [PULL 0/7] Net patches, Peter Maydell, 2015/09/03