From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 811E043CFE; Wed, 20 Mar 2024 10:31:19 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1AC59402A2; Wed, 20 Mar 2024 10:31:19 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 74A5940298; Wed, 20 Mar 2024 10:31:17 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4V03Dp4HHXzwPfW; Wed, 20 Mar 2024 17:28:42 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id 369A518005D; Wed, 20 Mar 2024 17:31:15 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 20 Mar 2024 17:31:14 +0800 Subject: Re: [PATCH v3] dmadev: fix structure alignment To: Wenwu Ma , CC: , , Thomas Monjalon References: <20240308053711.1260154-1-wenwux.ma@intel.com> <20240320072332.1433526-1-wenwux.ma@intel.com> From: fengchengwen Message-ID: Date: Wed, 20 Mar 2024 17:31:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20240320072332.1433526-1-wenwux.ma@intel.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500024.china.huawei.com (7.185.36.10) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Reviewed-by: Chengwen Feng On 2024/3/20 15:23, Wenwu Ma wrote: > The structure rte_dma_dev needs to be aligned to the cache line, but > the return value of malloc may not be aligned to the cache line. When > we use memset to clear the rte_dma_dev object, it may cause a segmentation > fault in clang-x86-platform. > > This is because clang uses the "vmovaps" assembly instruction for > memset, which requires that the operands (rte_dma_dev objects) must > aligned on a 16-byte boundary or a general-protection exception (#GP) > is generated. > > Therefore, either additional memory is applied for re-alignment, or the > rte_dma_dev object does not require cache line alignment. The patch > chooses the former option to fix the issue. > > Fixes: b36970f2e13e ("dmadev: introduce DMA device library") > Cc: stable@dpdk.org > > Signed-off-by: Wenwu Ma > --- > v2: > - Because of performance drop, adjust the code to > no longer demand cache line alignment > v3: > - back to v1 patch > > --- > lib/dmadev/rte_dmadev.c | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c > index 5953a77bd6..61e106d574 100644 > --- a/lib/dmadev/rte_dmadev.c > +++ b/lib/dmadev/rte_dmadev.c > @@ -160,15 +160,25 @@ static int > dma_dev_data_prepare(void) > { > size_t size; > + void *ptr; > > if (rte_dma_devices != NULL) > return 0; > > - size = dma_devices_max * sizeof(struct rte_dma_dev); > - rte_dma_devices = malloc(size); > - if (rte_dma_devices == NULL) > + /* The dma device object is expected to align cacheline, but > + * the return value of malloc may not be aligned to the cache line. > + * Therefore, extra memory is applied for realignment. > + * note: We do not call posix_memalign/aligned_alloc because it is > + * version dependent on libc. > + */ > + size = dma_devices_max * sizeof(struct rte_dma_dev) + > + RTE_CACHE_LINE_SIZE; > + ptr = malloc(size); > + if (ptr == NULL) > return -ENOMEM; > - memset(rte_dma_devices, 0, size); > + memset(ptr, 0, size); > + > + rte_dma_devices = RTE_PTR_ALIGN(ptr, RTE_CACHE_LINE_SIZE); > > return 0; > } >