From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: "fengchengwen@huawei.com" <fengchengwen@huawei.com>,
"Ma, WenwuX" <wenwux.ma@intel.com>, "dev@dpdk.org" <dev@dpdk.org>,
"Jiale, SongX" <songx.jiale@intel.com>,
"stable@dpdk.org" <stable@dpdk.org>,
Tyler Retzlaff <roretzla@microsoft.com>,
david.marchand@redhat.com, bruce.richardson@intel.com
Subject: Re: [PATCH v3] dmadev: fix structure alignment
Date: Thu, 21 Mar 2024 09:05:28 -0700 [thread overview]
Message-ID: <20240321160528.GB11257@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)
In-Reply-To: <7851657.gsGJI6kyIV@thomas>
On Thu, Mar 21, 2024 at 11:06:34AM +0100, Thomas Monjalon wrote:
> 21/03/2024 10:18, Ma, WenwuX:
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 21/03/2024 02:25, Ma, WenwuX:
> > > > 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?
> > >
> >
> > using the 'man aligned_alloc' command, we has the following description:
> >
> > VERSIONS
> > The functions memalign(), valloc(), and pvalloc() have been available in all Linux libc libraries.
> >
> > The function aligned_alloc() was added to glibc in version 2.16.
>
> released in 2012-06-30
If we are using C11 we probably already implicitly depend on the glibc
that supports aligned_alloc (introduced in C11).
>
> > The function posix_memalign() is available since glibc 2.1.91.
>
> I think we could bump our libc requirements for these functions.
>
> I understand there is also a concern on Windows,
> but an alternative exists there.
> We may need a wrapper like "rte_alloc_align".
Yes, I'm afraid we would probably have to introduce
rte_aligned_alloc/rte_aligned_free. On Windows this would simply
forward to _aligned_alloc() and _aligned_free() respectively.
ty
prev parent reply other threads:[~2024-03-21 16:05 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 5:37 [PATCH] " Wenwu Ma
2024-03-08 7:01 ` fengchengwen
2024-03-15 1:43 ` [PATCH v2] " Wenwu Ma
2024-03-15 6:02 ` Tyler Retzlaff
2024-03-15 6:06 ` fengchengwen
2024-03-15 6:25 ` Ma, WenwuX
2024-03-15 7:44 ` Ma, WenwuX
2024-03-15 8:31 ` fengchengwen
2024-03-15 9:27 ` Ma, WenwuX
2024-03-20 4:11 ` fengchengwen
2024-03-20 7:34 ` Ma, WenwuX
2024-03-19 9:48 ` Jiale, SongX
2024-03-20 7:23 ` [PATCH v3] " Wenwu Ma
2024-03-20 9:31 ` fengchengwen
2024-06-27 12:46 ` Thomas Monjalon
2024-03-20 11:37 ` Thomas Monjalon
2024-03-21 1:25 ` Ma, WenwuX
2024-03-21 8:30 ` Thomas Monjalon
2024-03-21 8:57 ` Ma, WenwuX
2024-03-21 9:18 ` Ma, WenwuX
2024-03-21 10:06 ` Thomas Monjalon
2024-03-21 16:05 ` Tyler Retzlaff [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240321160528.GB11257@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
--to=roretzla@linux.microsoft.com \
--cc=bruce.richardson@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=fengchengwen@huawei.com \
--cc=roretzla@microsoft.com \
--cc=songx.jiale@intel.com \
--cc=stable@dpdk.org \
--cc=thomas@monjalon.net \
--cc=wenwux.ma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).