[dpdk-dev,v2] examples/vhost: fix strict aliasing error on gcc 4.4.7

Message ID 1449653999-55759-1-git-send-email-pablo.de.lara.guarch@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

De Lara Guarch, Pablo Dec. 9, 2015, 9:39 a.m. UTC
  From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>

Fixes following error on gcc 4.4.7:

make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
  CC main.o
cc1: warnings being treated as errors
/tmp/dpdk-tmp/examples/vhost/main.c: In function ‘new_device’:
/tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
    dereferencing pointer ‘mbuf.486’ does break strict-aliasing rules
/tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
...
/tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
/tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
    dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules
/tmp/dpdk-tmp/examples/vhost/main.c:1804: note: initialized from here
make[1]: *** [main.o] Error 1

Fixes: d19533e8 ("examples/vhost: copy old vhost example")

Reported-by: Qian Xu <qian.q.xu@intel.com>
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
Changes in v2:
- Remove unnecessary casting

 examples/vhost/main.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
  

Comments

Bruce Richardson Dec. 9, 2015, 10:32 a.m. UTC | #1
On Wed, Dec 09, 2015 at 09:39:59AM +0000, Pablo de Lara wrote:
> From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>
> 
> Fixes following error on gcc 4.4.7:
> 
> make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
>   CC main.o
> cc1: warnings being treated as errors
> /tmp/dpdk-tmp/examples/vhost/main.c: In function ‘new_device’:
> /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
>     dereferencing pointer ‘mbuf.486’ does break strict-aliasing rules
> /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> ...
> /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
>     dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules
> /tmp/dpdk-tmp/examples/vhost/main.c:1804: note: initialized from here
> make[1]: *** [main.o] Error 1
> 
> Fixes: d19533e8 ("examples/vhost: copy old vhost example")
> 
> Reported-by: Qian Xu <qian.q.xu@intel.com>
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> ---
> Changes in v2:
> - Remove unnecessary casting

You've remove some, but not all unnecessary casting. You don't need a cast when
assigning void * to any other type, so you can remove the mbuf casts too.

/Bruce
  
Huawei Xie Dec. 9, 2015, 10:45 a.m. UTC | #2
On 12/9/2015 5:40 PM, De Lara Guarch, Pablo wrote:
> From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>
>
> Fixes following error on gcc 4.4.7:
>
> make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
>   CC main.o
> cc1: warnings being treated as errors
> /tmp/dpdk-tmp/examples/vhost/main.c: In function ‘new_device’:
> /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
>     dereferencing pointer ‘mbuf.486’ does break strict-aliasing rules
> /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> ...
> /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740: error:
>     dereferencing pointer ‘({anonymous})’ does break strict-aliasing rules
> /tmp/dpdk-tmp/examples/vhost/main.c:1804: note: initialized from here
> make[1]: *** [main.o] Error 1
>
> Fixes: d19533e8 ("examples/vhost: copy old vhost example")
>
> Reported-by: Qian Xu <qian.q.xu@intel.com>
> Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Huawei Xie <huawei.xie@intel.com>
  
De Lara Guarch, Pablo Dec. 9, 2015, 10:52 a.m. UTC | #3
Hi Huawei,

> -----Original Message-----
> From: Xie, Huawei
> Sent: Wednesday, December 09, 2015 10:45 AM
> To: De Lara Guarch, Pablo; dev@dpdk.org
> Cc: yuanhan.liu@linux.intel.com
> Subject: Re: [PATCH v2] examples/vhost: fix strict aliasing error on gcc 4.4.7
> 
> On 12/9/2015 5:40 PM, De Lara Guarch, Pablo wrote:
> > From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>
> >
> > Fixes following error on gcc 4.4.7:
> >
> > make: Entering directory `/tmp/dpdk-tmp/examples/vhost'
> >   CC main.o
> > cc1: warnings being treated as errors
> > /tmp/dpdk-tmp/examples/vhost/main.c: In function 'new_device':
> > /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740:
> error:
> >     dereferencing pointer 'mbuf.486' does break strict-aliasing rules
> > /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> > ...
> > /tmp/dpdk-tmp/examples/vhost/main.c:1503: note: initialized from here
> > /tmp/dpdk-tmp/x86_64-native-linuxapp-gcc/include/rte_ring.h:740:
> error:
> >     dereferencing pointer '({anonymous})' does break strict-aliasing rules
> > /tmp/dpdk-tmp/examples/vhost/main.c:1804: note: initialized from here
> > make[1]: *** [main.o] Error 1
> >
> > Fixes: d19533e8 ("examples/vhost: copy old vhost example")
> >
> > Reported-by: Qian Xu <qian.q.xu@intel.com>
> > Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
> Acked-by: Huawei Xie <huawei.xie@intel.com>
> 

I am going to send a v3 for this patch, removing the other casting that Bruce mentioned.
I will pre-ack it, unless you have any concerns.

Thanks,
Pablo
  

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index dc3a012..2000a3a 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1449,7 +1449,8 @@  attach_rxmbuf_zcp(struct virtio_net *dev)
 	uint64_t buff_addr, phys_addr;
 	struct vhost_virtqueue *vq;
 	struct vring_desc *desc;
-	struct rte_mbuf *mbuf = NULL;
+	void *obj = NULL;
+	struct rte_mbuf *mbuf;
 	struct vpool *vpool;
 	hpa_type addr_type;
 	struct vhost_dev *vdev = (struct vhost_dev *)dev->priv;
@@ -1500,7 +1501,8 @@  attach_rxmbuf_zcp(struct virtio_net *dev)
 		}
 	} while (unlikely(phys_addr == 0));
 
-	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
+	rte_ring_sc_dequeue(vpool->ring, &obj);
+	mbuf = (struct rte_mbuf *)obj;
 	if (unlikely(mbuf == NULL)) {
 		LOG_DEBUG(VHOST_DATA,
 			"(%"PRIu64") in attach_rxmbuf_zcp: "
@@ -1517,7 +1519,7 @@  attach_rxmbuf_zcp(struct virtio_net *dev)
 			"size required: %d\n",
 			dev->device_fh, desc->len, desc_idx, vpool->buf_size);
 		put_desc_to_used_list_zcp(vq, desc_idx);
-		rte_ring_sp_enqueue(vpool->ring, (void *)mbuf);
+		rte_ring_sp_enqueue(vpool->ring, obj);
 		return;
 	}
 
@@ -1789,7 +1791,8 @@  virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 {
 	struct mbuf_table *tx_q;
 	struct rte_mbuf **m_table;
-	struct rte_mbuf *mbuf = NULL;
+	void *obj = NULL;
+	struct rte_mbuf *mbuf;
 	unsigned len, ret, offset = 0;
 	struct vpool *vpool;
 	uint16_t vlan_tag = (uint16_t)vlan_tags[(uint16_t)dev->device_fh];
@@ -1801,7 +1804,8 @@  virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 
 	/* Allocate an mbuf and populate the structure. */
 	vpool = &vpool_array[MAX_QUEUES + vmdq_rx_q];
-	rte_ring_sc_dequeue(vpool->ring, (void **)&mbuf);
+	rte_ring_sc_dequeue(vpool->ring, &obj);
+	mbuf = (struct rte_mbuf *)obj;
 	if (unlikely(mbuf == NULL)) {
 		struct vhost_virtqueue *vq = dev->virtqueue[VIRTIO_TXQ];
 		RTE_LOG(ERR, VHOST_DATA,