From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 9EB7A37AA for ; Sun, 12 Jun 2016 16:29:57 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP; 12 Jun 2016 07:29:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,462,1459839600"; d="scan'208";a="1000356191" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by fmsmga002.fm.intel.com with ESMTP; 12 Jun 2016 07:29:51 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: yuanhan.liu@linux.intel.com, huawei.xie@intel.com, Jianfeng Tan Date: Sun, 12 Jun 2016 14:29:42 +0000 Message-Id: <1465741782-126976-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 Subject: [dpdk-dev] [PATCH] virtio: fix allocating virtnet_rx not mem aligned X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jun 2016 14:30:00 -0000 Compile DPDK with clang, below line in virtio_rxtx.c could be optimized with four "VMOVAPS ymm, m256". memset(&rxvq->fake_mbuf, 0, sizeof(rxvq->fake_mbuf)); This instruction requires memory address is 32-byte aligned. Or, it leads to segfault. Although only tested with Clang 3.6.0, it can be reproduced in any compilers, which do aggressive optimization, aka, change memset of known length to VMOVAPS. The fact that struct rte_mbuf is cache line aligned, can only make sure fake_mbuf is aligned compared to the start address of struct virtnet_rx. Unfortunately, this address is not necessarily aligned because it's allocated by: rxvq = (struct virtnet_rx *)RTE_PTR_ADD(vq, sz_vq); When sz_vq is not aligned, then rxvq cannot be allocated with an aligned address, and then rxvq->fake_mbuf (addr of rxvq + cache line size) is not an aligned address. The fix is very simple that making sz_vq 32-byte aligned. Here we make it cache line aligned for future optimization. Fixes: a900472aedef ("virtio: split virtio Rx/Tx queue") Signed-off-by: Jianfeng Tan --- drivers/net/virtio/virtio_ethdev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index a995520..ad0f5a6 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -337,7 +337,10 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, snprintf(vq_name, sizeof(vq_name), "port%d_%s%d", dev->data->port_id, queue_names[queue_type], queue_idx); - sz_vq = sizeof(*vq) + vq_size * sizeof(struct vq_desc_extra); + + sz_vq = RTE_ALIGN_CEIL(sizeof(*vq) + + vq_size * sizeof(struct vq_desc_extra), + RTE_CACHE_LINE_SIZE); if (queue_type == VTNET_RQ) { sz_q = sz_vq + sizeof(*rxvq); } else if (queue_type == VTNET_TQ) { -- 2.1.4