From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 97CF843D11;
	Thu, 21 Mar 2024 09:30:56 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 75E8D42830;
	Thu, 21 Mar 2024 09:30:56 +0100 (CET)
Received: from wfout5-smtp.messagingengine.com
 (wfout5-smtp.messagingengine.com [64.147.123.148])
 by mails.dpdk.org (Postfix) with ESMTP id 29599402D7;
 Thu, 21 Mar 2024 09:30:54 +0100 (CET)
Received: from compute2.internal (compute2.nyi.internal [10.202.2.46])
 by mailfout.west.internal (Postfix) with ESMTP id 8233E1C000CF;
 Thu, 21 Mar 2024 04:30:51 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162])
 by compute2.internal (MEProxy); Thu, 21 Mar 2024 04:30:51 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 cc:cc:content-transfer-encoding:content-type:content-type:date
 :date:from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:subject:subject:to:to; s=fm2; t=1711009851;
 x=1711096251; bh=PkEIk39UM7hfsOhUw/TMIydIeo0m6jiil8ZdCJ8i5JA=; b=
 Pu0V3IDNzgm06o9smWiu6BVqEOYKksG5GqAFz9hF0cip1Fzb2W8v1OEl/cl6fHfK
 bYq+MOjKQVi7Ba0TcH8fCQ1pDk047tX4NElyrXn0xQQ5oLU5asV6xzmXbW3+4yL0
 2vVm2r713z8Qj6aY37GDu6QKqY/33hKnUjQTl1it5fGrU024gC7f1AagkONg/qIs
 zMmwb0P/FL11DdIBaegaCTbv4KOnQbhakA5TuaVX7D5l2XVlPRKmRfGg+8t+I0fk
 i0Qobun9VKiuf0eLjntZyNo/dVNkc616nwNt+xEcgVDtPK/v0ceQuLRm4RSjOehe
 lQUs5znoKEcvlN/8b6xB5g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:cc:content-transfer-encoding
 :content-type:content-type:date:date:feedback-id:feedback-id
 :from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy
 :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1711009851; x=
 1711096251; bh=PkEIk39UM7hfsOhUw/TMIydIeo0m6jiil8ZdCJ8i5JA=; b=Z
 aUZB+ek6/I8AZ7WgQ5TPukOv41yQwbh3QR1ewiiSPNg/UZyQDrgUb1ilL6nJmnTu
 BJAAHhptva7SwOIMcv2HYSgoipfI+hOBYCAZl1y5XMvUfUVXOUz8+hxQZjT2RSQN
 bRZ123xPDbn674BncdZM5PsevIhKvrRl8d5ZkrsyWgHfAYQkgu3wrhoO68I7sPeA
 ++zzLN2QEYlUof3Bdu7PcbEdtQMOR25XuWRJxG6mTK3MRoWPd5qzhEKgCsn1+Mbp
 8CJzjUj0P9yZlatRt5rYgZ2h+UzXnOTnbal4cq0GZX/b3GLbotJQGEKPOtGT3aCC
 eaKErFmXiDpYEFNFhg60Q==
X-ME-Sender: <xms:OvD7Zdv9gGDyB74eP0L3DEcMGE7nyfI_9wATfJQ9F7IHu7SzSC0mFQ>
 <xme:OvD7ZWf02DJODTn20BlF1hTR0n8usU2mvcuSUHYwZyRPG56qvicQDOinvq477Xo7s
 PQfF6CjZl7om9nIvA>
X-ME-Received: <xmr:OvD7ZQzySCq_aOP7YAJM_QTVja1tyHbSzez12uwNNBgThfBbh506s9xsgsJveqPNDXaoPRBJ-_L-tBl6oRXmvLaO_Q>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrleehgdduvddtucetufdoteggodetrfdotf
 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
 uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
 cujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepvfhhohhm
 rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc
 ggtffrrghtthgvrhhnpeeljeeitdefheetvddvvdetjedvleeuffdtheeludejfeekieeh
 jeeuhfehfeetleenucffohhmrghinheptghpphhrvghfvghrvghntggvrdgtohhmnecuve
 hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghs
 sehmohhnjhgrlhhonhdrnhgvth
X-ME-Proxy: <xmx:OvD7ZUNDeVqnTaV_dmFhfIPqq3p_el1djK0-BNH6ySOBHYGqZUvunw>
 <xmx:O_D7Zd-ZF9DvWfedzfi3ALOjrjM4UlqMU3Z9OXXSNHQLg2J__TM8wA>
 <xmx:O_D7ZUV6xYosoiPg44Xkkzth2EPgBHjVHdOAjpbGp5HtyFx__375Iw>
 <xmx:O_D7ZeeeKIKc3-pWBSXFe5Td657TUa4kcK7mWUvXRx_9XLOE_WaAiw>
 <xmx:O_D7ZdyPZVVmlJs4Le-n5Qjr3_79rQrtUP0wzJWAbK60oxzMlidMO5Ycohw>
Feedback-ID: i47234305:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu,
 21 Mar 2024 04:30:49 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: "fengchengwen@huawei.com" <fengchengwen@huawei.com>,
 "Ma, WenwuX" <wenwux.ma@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "Jiale, SongX" <songx.jiale@intel.com>,
 "stable@dpdk.org" <stable@dpdk.org>
Subject: Re: [PATCH v3] dmadev: fix structure alignment
Date: Thu, 21 Mar 2024 09:30:48 +0100
Message-ID: <2631241.9Mp67QZiUf@thomas>
In-Reply-To: <MN0PR11MB6110CF9BC68B30AC0A35EBECEB322@MN0PR11MB6110.namprd11.prod.outlook.com>
References: <20240308053711.1260154-1-wenwux.ma@intel.com>
 <3047329.687JKscXgg@thomas>
 <MN0PR11MB6110CF9BC68B30AC0A35EBECEB322@MN0PR11MB6110.namprd11.prod.outlook.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

21/03/2024 02:25, Ma, WenwuX:
> Hi, Thomas
> 
> From: Thomas Monjalon <thomas@monjalon.net>
> > 20/03/2024 08:23, Wenwu Ma:
> > > 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 <wenwux.ma@intel.com>
> > [..]
> > > -	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);
> > 
> > Why not using aligned_alloc()?
> > https://en.cppreference.com/w/c/memory/aligned_alloc
> > 
> > 
> because it is version dependent on libc.

Which libc is required?