use QEMU_PACKED and QEMU_ALIGNED macros
cover use QEMU_PACKED and QEMU_ALIGNED macros
Still trying to reduce clang -Waddress-of-packed-member warnings.
Philippe Mathieu-Daudé (7):
net: struct MACAddr can use the QEMU_PACKED macro net/eth: use the QEMU_PACKED macro net/rocker: use QEMU_PACKED and QEMU_ALIGNED() macros net/rocker: move struct rocker_desc to C file net/eepro100: use QEMU_ALIGNED() macro net/eepro100: reduce alignment to DWORD (32bit) i386/pc: use the QEMU_ALIGNED() macro
hw/net/rocker/rocker_hw.h | 15 +-------------- include/net/eth.h | 26 +++++++++++++------------- include/net/net.h | 2 +- hw/i386/pc.c | 4 ++-- hw/net/eepro100.c | 2 +- hw/net/rocker/rocker_desc.c | 13 +++++++++++++ 6 files changed, 31 insertions(+), 31 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/7 net: struct MACAddr can use the QEMU_PACKED macro
--- include/net/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/net.h +1 -1
@@ -23,7 +23,7 @@struct MACAddr {uint8_t a[6 ]; -}; +}QEMU_PACKED ;/* qdev nic properties */
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 1/7] net: struct MACAddr can use the QEMU_PACKED macro
Quoted 10 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/net/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/net/net.h +0
-0
include/net/net.h line 26
Quoted 5 lines
include/net/net.h +1
-1@@ -23,7 +23,7 @@struct MACAddr {uint8_t a[6 ]; -}; +}QEMU_PACKED ;
I suppose the arm32 abi does pad structs to a multiple of 4. Does this actually affect anything else?
r~
PATCH 2/7 net/eth: use the QEMU_PACKED macro
In reply to Philippe Mathieu-Daudé--- include/net/eth.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
include/net/eth.h +13 -13
@@ -36,12 +36,12 @@ struct eth_header {uint8_t h_dest[ETH_ALEN ];/* destination eth addr */ uint8_t h_source[ETH_ALEN ];/* source ether addr */ uint16_t h_proto;/* packet type ID field */ -}; +}QEMU_PACKED ;struct vlan_header {uint16_t h_tci;/* priority and VLAN ID */ uint16_t h_proto;/* encapsulated protocol */ -}; +}QEMU_PACKED ;struct ip_header {uint8_t ip_ver_len;/* version and header length */
@@ -53,9 +53,9 @@ struct ip_header {uint8_t ip_p;/* protocol */ uint16_t ip_sum;/* checksum */ uint32_t ip_src, ip_dst;/* source and destination address */ -}; +}QEMU_PACKED ; -typedef struct tcp_header { +typedef struct QEMU_PACKED tcp_header {uint16_t th_sport;/* source port */ uint16_t th_dport;/* destination port */ uint32_t th_seq;/* sequence number */
@@ -77,14 +77,14 @@ typedef struct tcp_header {#define TCP_HEADER_DATA_OFFSET (tcp) \ (((be16_to_cpu((tcp)->th_offset_flags) >> 12) & 0xf) << 2) -typedef struct udp_header { +typedef struct QEMU_PACKED udp_header {uint16_t uh_sport;/* source port */ uint16_t uh_dport;/* destination port */ uint16_t uh_ulen;/* udp length */ uint16_t uh_sum;/* udp checksum */ } udp_header; -typedef struct ip_pseudo_header { +typedef struct QEMU_PACKED ip_pseudo_header {uint32_t ip_src;uint32_t ip_dst;uint8_t zeros;
@@ -116,9 +116,9 @@ struct ip6_header { } ip6_ctlun;struct in6_address ip6_src;/* source address */ struct in6_address ip6_dst;/* destination address */ -}; +}QEMU_PACKED ; -typedef struct ip6_pseudo_header { +typedef struct QEMU_PACKED ip6_pseudo_header {struct in6_address ip6_src;struct in6_address ip6_dst;uint32_t len;
@@ -129,7 +129,7 @@ typedef struct ip6_pseudo_header {struct ip6_ext_hdr {uint8_t ip6r_nxt;/* next header */ uint8_t ip6r_len;/* length in units of 8 octets */ -}; +}QEMU_PACKED ;struct ip6_ext_hdr_routing {uint8_t nxt;
@@ -137,21 +137,21 @@ struct ip6_ext_hdr_routing {uint8_t rtype;uint8_t segleft;uint8_t rsvd[4 ]; -}; +}QEMU_PACKED ;struct ip6_option_hdr {#define IP6_OPT_PAD1 (0x00)#define IP6_OPT_HOME (0xC9)uint8_t type;uint8_t len; -}; +}QEMU_PACKED ;struct udp_hdr {uint16_t uh_sport;/* source port */ uint16_t uh_dport;/* destination port */ uint16_t uh_ulen;/* udp length */ uint16_t uh_sum;/* udp checksum */ -}; +}QEMU_PACKED ;struct tcp_hdr {u_short th_sport;/* source port */
@@ -180,7 +180,7 @@ struct tcp_hdr {u_short th_win;/* window */ u_short th_sum;/* checksum */ u_short th_urp;/* urgent pointer */ -}; +}QEMU_PACKED ;#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt#define ip6_ecn_acc ip6_ctlun.ip6_un3.ip6_un3_ecn
Signature · 1 line
2.15.1
PATCH 3/7 net/rocker: use QEMU_PACKED and QEMU_ALIGNED() macros
In reply to Philippe Mathieu-Daudé--- hw/net/rocker/rocker_hw.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/net/rocker/rocker_hw.h +2 -2
@@ -130,7 +130,7 @@ typedef struct rocker_desc {__le16 tlv_size;__le16 rsvd[5 ];/* pad to 32 bytes */ __le16 comp_err; -} __attribute__((packed, aligned(8))) RockerDesc; +} QEMU_PACKED QEMU_ALIGNED(8) RockerDesc;/* * Rocker TLV type fields
@@ -140,7 +140,7 @@ typedef struct rocker_tlv {__le32 type;__le16 len;__le16 rsvd; -} __attribute__((packed, aligned(8))) RockerTlv; +} QEMU_PACKED QEMU_ALIGNED(8) RockerTlv;/* cmd msg */ enum {
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 3/7] net/rocker: use QEMU_PACKED and QEMU_ALIGNED() macros
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/rocker/rocker_hw.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 4/7 net/rocker: move struct rocker_desc to C file
In reply to Philippe Mathieu-Daudéthis is the only user.
--- hw/net/rocker/rocker_hw.h | 13 ------------- hw/net/rocker/rocker_desc.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-)
hw/net/rocker/rocker_hw.h +0 -13
@@ -119,19 +119,6 @@ enum {*/ #define ROCKER_RING_INDEX (reg) ((reg >> 5) & 0x7F) -/* -* Rocker DMA Descriptor -*/ - -typedef struct rocker_desc { -__le64 buf_addr; -uint64_t cookie; -__le16 buf_size; -__le16 tlv_size; -__le16 rsvd[5 ];/* pad to 32 bytes */ -__le16 comp_err; -} QEMU_PACKED QEMU_ALIGNED(8) RockerDesc; -/* * Rocker TLV type fields */
hw/net/rocker/rocker_desc.c +13 -0
@@ -23,6 +23,19 @@#include "rocker_hw.h" #include "rocker_desc.h" +/* +* Rocker DMA Descriptor +*/ + +typedef struct rocker_desc { +__le64 buf_addr; +uint64_t cookie; +__le16 buf_size; +__le16 tlv_size; +__le16 rsvd[5 ];/* pad to 32 bytes */ +__le16 comp_err; +} QEMU_PACKED QEMU_ALIGNED(8) RockerDesc; +struct desc_ring {hwaddr base_addr;uint32_t size;
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 4/7] net/rocker: move struct rocker_desc to C file
Quoted 7 lines · Philippe Mathieu-Daudé
this is the only user.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/rocker/rocker_hw.h | 13 ------------- hw/net/rocker/rocker_desc.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-)
r~
PATCH 5/7 net/eepro100: use QEMU_ALIGNED() macro
In reply to Philippe Mathieu-Daudé--- hw/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/eepro100.c +1 -1
@@ -266,7 +266,7 @@ typedef struct {/* Data in mem is always in the byte order of the controller (le). * It must be dword aligned to allow direct access to 32 bit values. */ - uint8_t mem[PCI_MEM_SIZE] __attribute__((aligned(8))); + uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(8);/* Configuration bytes. */ uint8_t configuration[22 ];
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 5/7] net/eepro100: use QEMU_ALIGNED() macro
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
RFC PATCH 6/7 net/eepro100: reduce alignment to DWORD (32bit)
In reply to Philippe Mathieu-Daudéas suggested in the comment.
--- hw/net/eepro100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/eepro100.c +1 -1
@@ -266,7 +266,7 @@ typedef struct {/* Data in mem is always in the byte order of the controller (le). * It must be dword aligned to allow direct access to 32 bit values. */ - uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(8); + uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(4);/* Configuration bytes. */ uint8_t configuration[22 ];
Signature · 1 line
2.15.1
Re: [Qemu-devel] [RFC PATCH 6/7] net/eepro100: reduce alignment to DWORD (32bit)
hw/net/eepro100.c typedef struct { · line 269
Quoted 4 lines · Philippe Mathieu-Daudé
/* Data in mem is always in the byte order of the controller (le).
* It must be dword aligned to allow direct access to 32 bit values. */hw/net/eepro100.c +1
-1- uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(8); + uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(4);
It's actually not needed at all, since accesses go through ld*_le_p and st*_le_p (commit 4d9be25, "hw/net/eepro100.c: Don't use cpu_to_*w() and *_to_cpup()", 2016-06-16).
Paolo
Re: [Qemu-devel] [RFC PATCH 6/7] net/eepro100: reduce alignment to DWORD (32bit)
Quoted 9 lines · Paolo Bonzini
hw/net/eepro100.c typedef struct { · line 269
Quoted 4 lines · Philippe Mathieu-Daudé
/* Data in mem is always in the byte order of the controller (le).
* It must be dword aligned to allow direct access to 32 bit values. */hw/net/eepro100.c +1
-1- uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(8); + uint8_t mem[PCI_MEM_SIZE] QEMU_ALIGNED(4);It's actually not needed at all, since accesses go through ld*_le_p and st*_le_p (commit 4d9be25, "
hw/net/eepro100.c: Don't use cpu_to_*w() and*_to_cpup()", 2016-06-16).
Cool, I'll update this.
Thank you,
Phil.
PATCH 7/7 i386/pc: use the QEMU_ALIGNED() macro
In reply to Philippe Mathieu-Daudé--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i386/pc.c +2 -2
@@ -93,12 +93,12 @@ struct e820_entry {uint64_t address;uint64_t length;uint32_t type; -} QEMU_PACKED __attribute((__aligned__(4))); +} QEMU_PACKED QEMU_ALIGNED(4);struct e820_table {uint32_t count;struct e820_entry entry[E820_NR_ENTRIES ]; -} QEMU_PACKED __attribute((__aligned__(4))); +} QEMU_PACKED QEMU_ALIGNED(4);static struct e820_table e820_reserve;static struct e820_entry *e820_table;
Signature · 1 line
2.15.1
Re: [Qemu-devel] [PATCH 7/7] i386/pc: use the QEMU_ALIGNED() macro
Quoted 15 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/i386/pc.c +0
-1@@ -93,12 +93,12 @@ struct e820_entry {uint64_t address;uint64_t length;uint32_t type; -} QEMU_PACKED __attribute((__aligned__(4)));
hw/i386/pc.c struct e820_entry { · line 104
Quoted 10 lines
hw/i386/pc.c +2
-1+} QEMU_PACKED QEMU_ALIGNED(4);struct e820_table {uint32_t count;struct e820_entry entry[E820_NR_ENTRIES ]; -} QEMU_PACKED __attribute((__aligned__(4))); +} QEMU_PACKED QEMU_ALIGNED(4);static struct e820_table e820_reserve;static struct e820_entry *e820_table;
Thanks,
Marcel
Re: [Qemu-devel] [PATCH 7/7] i386/pc: use the QEMU_ALIGNED() macro
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/pc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~