From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id B453A43CFF
	for <public@inbox.dpdk.org>; Wed, 20 Mar 2024 12:37:21 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 98D1B402B9;
	Wed, 20 Mar 2024 12:37:21 +0100 (CET)
Received: from fhigh4-smtp.messagingengine.com
 (fhigh4-smtp.messagingengine.com [103.168.172.155])
 by mails.dpdk.org (Postfix) with ESMTP id 2E3D5402A2;
 Wed, 20 Mar 2024 12:37:20 +0100 (CET)
Received: from compute6.internal (compute6.nyi.internal [10.202.2.47])
 by mailfhigh.nyi.internal (Postfix) with ESMTP id 8409C11400C2;
 Wed, 20 Mar 2024 07:37:19 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
 by compute6.internal (MEProxy); Wed, 20 Mar 2024 07:37:19 -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=1710934639;
 x=1711021039; bh=jUi0OFC+iNfLm0NlW5hleJAGVdu7+Lq3/8VeP4UOomM=; b=
 MG7VE5R5c+LLFXiaYuMLt3UqcgNEk0/xJI94JYDn8vCpQbEZDHAVVb6WRiMtq6hl
 iJgXpcxcFrCPq+wH+J3GefGbQUWHv/LAdo0NU1QjmWA0sl+unrJEIfnsmZMLqkrY
 IWKIOEVU2Ypy+4QvyFepakWfxNRr2UURQWtZktXcqMTUUhqF9HkQPAKZIfgpm8gV
 H79ItsPlLB9Y60wX0nlnNKXP4AhsxDCXX8dF2w4AfwCPJZglL/dEmT0LQbUDr74R
 qUShx+8VZfUwEoILUczbPU0k2nHblDtRzd7nogbwBLbjBHoAdInanGLnowIlPsSK
 MmDXUS9/nHD9k8ZXvmsaHw==
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=1710934639; x=
 1711021039; bh=jUi0OFC+iNfLm0NlW5hleJAGVdu7+Lq3/8VeP4UOomM=; b=r
 Zg+JIH1HiaJnS+hE4gc8Bd983XTE/wQAWDOvOldmLks+0BvHyl9pow2SWYmSvrXv
 foB7CaVcNd/nr3A1rUPJ3dqycKKRDquugXRIF9HxaiPktpqk/WH5weVehUJxvjr1
 mvx1/p3reJEWV4bHL1KYjf1pgBjOkkXVA1vLbxwXn5GSHvR9jRFcXbLe9ebounvo
 6z5fneXsyNalzY9y7uFVaCJ1RO+B6aAnFMFWVMI+Mjzm9qPMg1bsQiRZMN450mh1
 ZsLFVSNgTRnZrA6Fh0Rd96uXMAAcOJ8R/taKN+wZSBOIXvYGLhX+slPcZoqzU3QI
 ieU8EcJJyRwLtaMX8MOoA==
X-ME-Sender: <xms:b8r6ZcvPnzjQkM9gs2qMdYrB8ZIP6T0ERqpgoPaNtb4nAtLDBIEajQ>
 <xme:b8r6ZZf31ZG3bIWL4VBGfOgrUzKzUWgdgNASFa2BxbSDASwR4s4LxV786ow3EX9cL
 KytHT1GmOAcYCOaWw>
X-ME-Received: <xmr:b8r6ZXxtIH3jTlBGY1qpOM4TikBxZN-dj5-LQW3CQigr644AU4Z51tsNPvw9MbO_9ivA9b3LiTXsCPxePusk62lWRA>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrleeggdeftdcutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkjghfggfgtgesthfure
 dttddtjeenucfhrhhomhepvfhhohhmrghsucfoohhnjhgrlhhonhcuoehthhhomhgrshes
 mhhonhhjrghlohhnrdhnvghtqeenucggtffrrghtthgvrhhnpeeljeeitdefheetvddvvd
 etjedvleeuffdtheeludejfeekieehjeeuhfehfeetleenucffohhmrghinheptghpphhr
 vghfvghrvghntggvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe
 hmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth
X-ME-Proxy: <xmx:b8r6ZfNxXyQHuqGQkKDY01E-5NqE0D8knRZ4sfQzZzP1w33m2fMfWQ>
 <xmx:b8r6Zc-aSz-o-DuSQrj90BYVw-hDaNU16uOLATOyLw1IPmjwyy0Sng>
 <xmx:b8r6ZXWAAZoV00BQJ-qjfYErlRXhMiZvGIv8r5RWogZNTsq_QsSiew>
 <xmx:b8r6ZVdhhkDCzzAu0mQIM-ITIHnG6lSkfWXJOAxocCxaa5xHv2a2Vg>
 <xmx:b8r6Zcy9nJPNVfpk8fWF00FGumekmTm_m33P5iB4xwsFSU5EiEXuyA>
Feedback-ID: i47234305:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed,
 20 Mar 2024 07:37:18 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: fengchengwen@huawei.com, Wenwu Ma <wenwux.ma@intel.com>
Cc: dev@dpdk.org, songx.jiale@intel.com, stable@dpdk.org
Subject: Re: [PATCH v3] dmadev: fix structure alignment
Date: Wed, 20 Mar 2024 12:37:16 +0100
Message-ID: <3047329.687JKscXgg@thomas>
In-Reply-To: <20240320072332.1433526-1-wenwux.ma@intel.com>
References: <20240308053711.1260154-1-wenwux.ma@intel.com>
 <20240320072332.1433526-1-wenwux.ma@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org

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