mbox series

[v3,0/6] use IOVAs check based on DMA mask

Message ID 1538743527-8285-1-git-send-email-alejandro.lucero@netronome.com (mailing list archive)
Headers
Series use IOVAs check based on DMA mask |

Message

Alejandro Lucero Oct. 5, 2018, 12:45 p.m. UTC
  I sent a patchset about this to be applied on 17.11 stable. The memory
code has had main changes since that version, so here it is the patchset
adjusted to current master repo.

This patchset adds, mainly, a check for ensuring IOVAs are within a
restricted range due to addressing limitations with some devices. There
are two known cases: NFP and IOMMU VT-d emulation.

With this check IOVAs out of range are detected and PMDs can abort
initialization. For the VT-d case, IOVA VA mode is allowed as long as
IOVAs are within the supported range, avoiding to forbid IOVA VA by
default.

For the addressing limitations known cases, there are just 40(NFP) or
39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
most systems. With machines using more memory, the added check will
ensure IOVAs within the range.

With IOVA VA, and because the way the Linux kernel serves mmap calls
in 64 bits systems, 39 or 40 bits are not enough. It is possible to
give an address hint with a lower starting address than the default one
used by the kernel, and then ensuring the mmap uses that hint or hint plus
some offset. With 64 bits systems, the process virtual address space is
large enoguh for doing the hugepages mmaping within the supported range
when those addressing limitations exist. This patchset also adds a change
for using such a hint making the use of IOVA VA a more than likely
possibility when there are those addressing limitations.

The check is not done by default but just when it is required. This
patchset adds the check for NFP initialization and for setting the IOVA
mode is an emulated VT-d is detected. Also, because the recent patchset
adding dynamic memory allocation, the check is also invoked for ensuring
the new memsegs are within the required range.

This patchset could be applied to stable 18.05.

v2:
 - change logs from INFO to DEBUG
 - only keeps dma mask if device capable of addressing allocated memory
 - add ABI changes
 - change hint address increment to page size
 - split pci/bus commit in two
 - fix commits

v3:
 - remove previous code about keeping dma mask
  

Comments

Thomas Monjalon Oct. 28, 2018, 9:04 p.m. UTC | #1
05/10/2018 14:45, Alejandro Lucero:
> I sent a patchset about this to be applied on 17.11 stable. The memory
> code has had main changes since that version, so here it is the patchset
> adjusted to current master repo.
> 
> This patchset adds, mainly, a check for ensuring IOVAs are within a
> restricted range due to addressing limitations with some devices. There
> are two known cases: NFP and IOMMU VT-d emulation.
> 
> With this check IOVAs out of range are detected and PMDs can abort
> initialization. For the VT-d case, IOVA VA mode is allowed as long as
> IOVAs are within the supported range, avoiding to forbid IOVA VA by
> default.
> 
> For the addressing limitations known cases, there are just 40(NFP) or
> 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> most systems. With machines using more memory, the added check will
> ensure IOVAs within the range.
> 
> With IOVA VA, and because the way the Linux kernel serves mmap calls
> in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> give an address hint with a lower starting address than the default one
> used by the kernel, and then ensuring the mmap uses that hint or hint plus
> some offset. With 64 bits systems, the process virtual address space is
> large enoguh for doing the hugepages mmaping within the supported range
> when those addressing limitations exist. This patchset also adds a change
> for using such a hint making the use of IOVA VA a more than likely
> possibility when there are those addressing limitations.
> 
> The check is not done by default but just when it is required. This
> patchset adds the check for NFP initialization and for setting the IOVA
> mode is an emulated VT-d is detected. Also, because the recent patchset
> adding dynamic memory allocation, the check is also invoked for ensuring
> the new memsegs are within the required range.
> 
> This patchset could be applied to stable 18.05.

Applied, thanks
  
Yao, Lei A Oct. 29, 2018, 8:23 a.m. UTC | #2
Hi, Lucero, Thomas

This patch set will cause deadlock during memory initialization. 
rte_memseg_walk and try_expand_heap both will lock 
the file &mcfg->memory_hotplug_lock. So dead lock will occur. 

#0       rte_memseg_walk
#1  <-rte_eal_check_dma_mask
#2  <-alloc_pages_on_heap
#3  <-try_expand_heap_primary   
#4  <-try_expand_heap

Log as following:
EAL: TSC frequency is ~2494156 KHz
EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
[New Thread 0x7ffff5e0d700 (LWP 330350)]
EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
EAL: Trying to obtain current memory policy.
EAL: Setting policy MPOL_PREFERRED for socket 0
EAL: Restoring previous memory policy: 0

Could you have a check on this? A lot of test cases in our validation 
team fail because of this. Thanks a lot!

BRs
Lei


> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> Sent: Monday, October 29, 2018 5:04 AM
> To: Alejandro Lucero <alejandro.lucero@netronome.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
> mask
> 
> 05/10/2018 14:45, Alejandro Lucero:
> > I sent a patchset about this to be applied on 17.11 stable. The memory
> > code has had main changes since that version, so here it is the patchset
> > adjusted to current master repo.
> >
> > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > restricted range due to addressing limitations with some devices. There
> > are two known cases: NFP and IOMMU VT-d emulation.
> >
> > With this check IOVAs out of range are detected and PMDs can abort
> > initialization. For the VT-d case, IOVA VA mode is allowed as long as
> > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > default.
> >
> > For the addressing limitations known cases, there are just 40(NFP) or
> > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> > most systems. With machines using more memory, the added check will
> > ensure IOVAs within the range.
> >
> > With IOVA VA, and because the way the Linux kernel serves mmap calls
> > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > give an address hint with a lower starting address than the default one
> > used by the kernel, and then ensuring the mmap uses that hint or hint plus
> > some offset. With 64 bits systems, the process virtual address space is
> > large enoguh for doing the hugepages mmaping within the supported
> range
> > when those addressing limitations exist. This patchset also adds a change
> > for using such a hint making the use of IOVA VA a more than likely
> > possibility when there are those addressing limitations.
> >
> > The check is not done by default but just when it is required. This
> > patchset adds the check for NFP initialization and for setting the IOVA
> > mode is an emulated VT-d is detected. Also, because the recent patchset
> > adding dynamic memory allocation, the check is also invoked for ensuring
> > the new memsegs are within the required range.
> >
> > This patchset could be applied to stable 18.05.
> 
> Applied, thanks
> 
> 
>
  
Thomas Monjalon Oct. 29, 2018, 8:42 a.m. UTC | #3
29/10/2018 09:23, Yao, Lei A:
> Hi, Lucero, Thomas
> 
> This patch set will cause deadlock during memory initialization. 
> rte_memseg_walk and try_expand_heap both will lock 
> the file &mcfg->memory_hotplug_lock. So dead lock will occur. 
> 
> #0       rte_memseg_walk
> #1  <-rte_eal_check_dma_mask
> #2  <-alloc_pages_on_heap
> #3  <-try_expand_heap_primary   
> #4  <-try_expand_heap
> 
> Log as following:
> EAL: TSC frequency is ~2494156 KHz
> EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> [New Thread 0x7ffff5e0d700 (LWP 330350)]
> EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> EAL: Trying to obtain current memory policy.
> EAL: Setting policy MPOL_PREFERRED for socket 0
> EAL: Restoring previous memory policy: 0
> 
> Could you have a check on this? A lot of test cases in our validation 
> team fail because of this. Thanks a lot!

Can we just call rte_memseg_walk_thread_unsafe()?

+Cc Anatoly


> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> > 05/10/2018 14:45, Alejandro Lucero:
> > > I sent a patchset about this to be applied on 17.11 stable. The memory
> > > code has had main changes since that version, so here it is the patchset
> > > adjusted to current master repo.
> > >
> > > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > > restricted range due to addressing limitations with some devices. There
> > > are two known cases: NFP and IOMMU VT-d emulation.
> > >
> > > With this check IOVAs out of range are detected and PMDs can abort
> > > initialization. For the VT-d case, IOVA VA mode is allowed as long as
> > > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > > default.
> > >
> > > For the addressing limitations known cases, there are just 40(NFP) or
> > > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> > > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> > > most systems. With machines using more memory, the added check will
> > > ensure IOVAs within the range.
> > >
> > > With IOVA VA, and because the way the Linux kernel serves mmap calls
> > > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > > give an address hint with a lower starting address than the default one
> > > used by the kernel, and then ensuring the mmap uses that hint or hint plus
> > > some offset. With 64 bits systems, the process virtual address space is
> > > large enoguh for doing the hugepages mmaping within the supported
> > range
> > > when those addressing limitations exist. This patchset also adds a change
> > > for using such a hint making the use of IOVA VA a more than likely
> > > possibility when there are those addressing limitations.
> > >
> > > The check is not done by default but just when it is required. This
> > > patchset adds the check for NFP initialization and for setting the IOVA
> > > mode is an emulated VT-d is detected. Also, because the recent patchset
> > > adding dynamic memory allocation, the check is also invoked for ensuring
> > > the new memsegs are within the required range.
> > >
> > > This patchset could be applied to stable 18.05.
> > 
> > Applied, thanks
  
Thomas Monjalon Oct. 29, 2018, 9:07 a.m. UTC | #4
One more comment about this issue,

There was no reply to the question asked by Alejandro on October 11th:
	http://mails.dpdk.org/archives/dev/2018-October/115402.html
and there were no more reviews despite all my requests:
	http://mails.dpdk.org/archives/dev/2018-October/117475.html
Without any more comment, I had to apply the patchset.

Now we need to find a solution. Please suggest.


29/10/2018 09:42, Thomas Monjalon:
> 29/10/2018 09:23, Yao, Lei A:
> > Hi, Lucero, Thomas
> > 
> > This patch set will cause deadlock during memory initialization. 
> > rte_memseg_walk and try_expand_heap both will lock 
> > the file &mcfg->memory_hotplug_lock. So dead lock will occur. 
> > 
> > #0       rte_memseg_walk
> > #1  <-rte_eal_check_dma_mask
> > #2  <-alloc_pages_on_heap
> > #3  <-try_expand_heap_primary   
> > #4  <-try_expand_heap
> > 
> > Log as following:
> > EAL: TSC frequency is ~2494156 KHz
> > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > EAL: Trying to obtain current memory policy.
> > EAL: Setting policy MPOL_PREFERRED for socket 0
> > EAL: Restoring previous memory policy: 0
> > 
> > Could you have a check on this? A lot of test cases in our validation 
> > team fail because of this. Thanks a lot!
> 
> Can we just call rte_memseg_walk_thread_unsafe()?
> 
> +Cc Anatoly
> 
> 
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> > > 05/10/2018 14:45, Alejandro Lucero:
> > > > I sent a patchset about this to be applied on 17.11 stable. The memory
> > > > code has had main changes since that version, so here it is the patchset
> > > > adjusted to current master repo.
> > > >
> > > > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > > > restricted range due to addressing limitations with some devices. There
> > > > are two known cases: NFP and IOMMU VT-d emulation.
> > > >
> > > > With this check IOVAs out of range are detected and PMDs can abort
> > > > initialization. For the VT-d case, IOVA VA mode is allowed as long as
> > > > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > > > default.
> > > >
> > > > For the addressing limitations known cases, there are just 40(NFP) or
> > > > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> > > > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> > > > most systems. With machines using more memory, the added check will
> > > > ensure IOVAs within the range.
> > > >
> > > > With IOVA VA, and because the way the Linux kernel serves mmap calls
> > > > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > > > give an address hint with a lower starting address than the default one
> > > > used by the kernel, and then ensuring the mmap uses that hint or hint plus
> > > > some offset. With 64 bits systems, the process virtual address space is
> > > > large enoguh for doing the hugepages mmaping within the supported
> > > range
> > > > when those addressing limitations exist. This patchset also adds a change
> > > > for using such a hint making the use of IOVA VA a more than likely
> > > > possibility when there are those addressing limitations.
> > > >
> > > > The check is not done by default but just when it is required. This
> > > > patchset adds the check for NFP initialization and for setting the IOVA
> > > > mode is an emulated VT-d is detected. Also, because the recent patchset
> > > > adding dynamic memory allocation, the check is also invoked for ensuring
> > > > the new memsegs are within the required range.
> > > >
> > > > This patchset could be applied to stable 18.05.
> > > 
> > > Applied, thanks
  
Alejandro Lucero Oct. 29, 2018, 9:25 a.m. UTC | #5
Can we have the configuration triggering this issue?

On Mon, Oct 29, 2018 at 9:07 AM Thomas Monjalon <thomas@monjalon.net> wrote:

> One more comment about this issue,
>
> There was no reply to the question asked by Alejandro on October 11th:
>         http://mails.dpdk.org/archives/dev/2018-October/115402.html
> and there were no more reviews despite all my requests:
>         http://mails.dpdk.org/archives/dev/2018-October/117475.html
> Without any more comment, I had to apply the patchset.
>
> Now we need to find a solution. Please suggest.
>
>
> 29/10/2018 09:42, Thomas Monjalon:
> > 29/10/2018 09:23, Yao, Lei A:
> > > Hi, Lucero, Thomas
> > >
> > > This patch set will cause deadlock during memory initialization.
> > > rte_memseg_walk and try_expand_heap both will lock
> > > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
> > >
> > > #0       rte_memseg_walk
> > > #1  <-rte_eal_check_dma_mask
> > > #2  <-alloc_pages_on_heap
> > > #3  <-try_expand_heap_primary
> > > #4  <-try_expand_heap
> > >
> > > Log as following:
> > > EAL: TSC frequency is ~2494156 KHz
> > > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > > EAL: Trying to obtain current memory policy.
> > > EAL: Setting policy MPOL_PREFERRED for socket 0
> > > EAL: Restoring previous memory policy: 0
> > >
> > > Could you have a check on this? A lot of test cases in our validation
> > > team fail because of this. Thanks a lot!
> >
> > Can we just call rte_memseg_walk_thread_unsafe()?
> >
> > +Cc Anatoly
> >
> >
> > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> > > > 05/10/2018 14:45, Alejandro Lucero:
> > > > > I sent a patchset about this to be applied on 17.11 stable. The
> memory
> > > > > code has had main changes since that version, so here it is the
> patchset
> > > > > adjusted to current master repo.
> > > > >
> > > > > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > > > > restricted range due to addressing limitations with some devices.
> There
> > > > > are two known cases: NFP and IOMMU VT-d emulation.
> > > > >
> > > > > With this check IOVAs out of range are detected and PMDs can abort
> > > > > initialization. For the VT-d case, IOVA VA mode is allowed as long
> as
> > > > > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > > > > default.
> > > > >
> > > > > For the addressing limitations known cases, there are just 40(NFP)
> or
> > > > > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those
> limitations
> > > > > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely
> enough for
> > > > > most systems. With machines using more memory, the added check will
> > > > > ensure IOVAs within the range.
> > > > >
> > > > > With IOVA VA, and because the way the Linux kernel serves mmap
> calls
> > > > > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > > > > give an address hint with a lower starting address than the
> default one
> > > > > used by the kernel, and then ensuring the mmap uses that hint or
> hint plus
> > > > > some offset. With 64 bits systems, the process virtual address
> space is
> > > > > large enoguh for doing the hugepages mmaping within the supported
> > > > range
> > > > > when those addressing limitations exist. This patchset also adds a
> change
> > > > > for using such a hint making the use of IOVA VA a more than likely
> > > > > possibility when there are those addressing limitations.
> > > > >
> > > > > The check is not done by default but just when it is required. This
> > > > > patchset adds the check for NFP initialization and for setting the
> IOVA
> > > > > mode is an emulated VT-d is detected. Also, because the recent
> patchset
> > > > > adding dynamic memory allocation, the check is also invoked for
> ensuring
> > > > > the new memsegs are within the required range.
> > > > >
> > > > > This patchset could be applied to stable 18.05.
> > > >
> > > > Applied, thanks
>
>
>
>
  
Yao, Lei A Oct. 29, 2018, 9:36 a.m. UTC | #6
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Monday, October 29, 2018 4:43 PM
> To: Yao, Lei A <lei.a.yao@intel.com>
> Cc: Alejandro Lucero <alejandro.lucero@netronome.com>; dev@dpdk.org;
> Xu, Qian Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
> mask
> 
> 29/10/2018 09:23, Yao, Lei A:
> > Hi, Lucero, Thomas
> >
> > This patch set will cause deadlock during memory initialization.
> > rte_memseg_walk and try_expand_heap both will lock
> > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
> >
> > #0       rte_memseg_walk
> > #1  <-rte_eal_check_dma_mask
> > #2  <-alloc_pages_on_heap
> > #3  <-try_expand_heap_primary
> > #4  <-try_expand_heap
> >
> > Log as following:
> > EAL: TSC frequency is ~2494156 KHz
> > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > EAL: Trying to obtain current memory policy.
> > EAL: Setting policy MPOL_PREFERRED for socket 0
> > EAL: Restoring previous memory policy: 0
> >
> > Could you have a check on this? A lot of test cases in our validation
> > team fail because of this. Thanks a lot!
> 
> Can we just call rte_memseg_walk_thread_unsafe()?
> 
> +Cc Anatoly

Hi, Thomas

I change to rte_memseg_walk_thread_unsafe(), still
Can't work. 

EAL: Setting policy MPOL_PREFERRED for socket 0
EAL: Restoring previous memory policy: 0
EAL: memseg iova 140000000, len 40000000, out of range
EAL:    using dma mask ffffffffffffffff
EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
EAL: Trying to obtain current memory policy.
EAL: Setting policy MPOL_PREFERRED for socket 1
EAL: Restoring previous memory policy: 0
EAL: memseg iova 1bc0000000, len 40000000, out of range
EAL:    using dma mask ffffffffffffffff
EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
error allocating rte services array
EAL: FATAL: rte_service_init() failed
EAL: rte_service_init() failed
PANIC in main():

BRs
Lei
> 
> 
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
> > > 05/10/2018 14:45, Alejandro Lucero:
> > > > I sent a patchset about this to be applied on 17.11 stable. The memory
> > > > code has had main changes since that version, so here it is the patchset
> > > > adjusted to current master repo.
> > > >
> > > > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > > > restricted range due to addressing limitations with some devices. There
> > > > are two known cases: NFP and IOMMU VT-d emulation.
> > > >
> > > > With this check IOVAs out of range are detected and PMDs can abort
> > > > initialization. For the VT-d case, IOVA VA mode is allowed as long as
> > > > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > > > default.
> > > >
> > > > For the addressing limitations known cases, there are just 40(NFP) or
> > > > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> > > > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> > > > most systems. With machines using more memory, the added check
> will
> > > > ensure IOVAs within the range.
> > > >
> > > > With IOVA VA, and because the way the Linux kernel serves mmap calls
> > > > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > > > give an address hint with a lower starting address than the default one
> > > > used by the kernel, and then ensuring the mmap uses that hint or hint
> plus
> > > > some offset. With 64 bits systems, the process virtual address space is
> > > > large enoguh for doing the hugepages mmaping within the supported
> > > range
> > > > when those addressing limitations exist. This patchset also adds a
> change
> > > > for using such a hint making the use of IOVA VA a more than likely
> > > > possibility when there are those addressing limitations.
> > > >
> > > > The check is not done by default but just when it is required. This
> > > > patchset adds the check for NFP initialization and for setting the IOVA
> > > > mode is an emulated VT-d is detected. Also, because the recent
> patchset
> > > > adding dynamic memory allocation, the check is also invoked for
> ensuring
> > > > the new memsegs are within the required range.
> > > >
> > > > This patchset could be applied to stable 18.05.
> > >
> > > Applied, thanks
> 
>
  
Yao, Lei A Oct. 29, 2018, 9:44 a.m. UTC | #7
Hi, Lucero

My server info:
Intel(R) Xeon(R) Platinum 8180 CPU @ 2.50GHz
Hugepage: 1G
Kernel: 4.15.0
OS: Ubuntu

Steps are simple:

1.       Bind one i40e/ixgbe  NIC to igb_uio

2.       Launch testpmd:

./x86_64-native-linuxapp-gcc/app/testpmd -c 0x03 -n 4 --log-level=eal,8 -- -i

BRs
Lei


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Monday, October 29, 2018 5:26 PM
To: Thomas Monjalon <thomas@monjalon.net>
Cc: Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Richardson, Bruce <bruce.richardson@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask

Can we have the configuration triggering this issue?

On Mon, Oct 29, 2018 at 9:07 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
One more comment about this issue,

There was no reply to the question asked by Alejandro on October 11th:
        http://mails.dpdk.org/archives/dev/2018-October/115402.html
and there were no more reviews despite all my requests:
        http://mails.dpdk.org/archives/dev/2018-October/117475.html
Without any more comment, I had to apply the patchset.

Now we need to find a solution. Please suggest.


29/10/2018 09:42, Thomas Monjalon:
> 29/10/2018 09:23, Yao, Lei A:
> > Hi, Lucero, Thomas
> >
> > This patch set will cause deadlock during memory initialization.
> > rte_memseg_walk and try_expand_heap both will lock
> > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
> >
> > #0       rte_memseg_walk
> > #1  <-rte_eal_check_dma_mask
> > #2  <-alloc_pages_on_heap
> > #3  <-try_expand_heap_primary
> > #4  <-try_expand_heap
> >
> > Log as following:
> > EAL: TSC frequency is ~2494156 KHz
> > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > EAL: Trying to obtain current memory policy.
> > EAL: Setting policy MPOL_PREFERRED for socket 0
> > EAL: Restoring previous memory policy: 0
> >
> > Could you have a check on this? A lot of test cases in our validation
> > team fail because of this. Thanks a lot!
>
> Can we just call rte_memseg_walk_thread_unsafe()?
>
> +Cc Anatoly
>
>
> > From: dev [mailto:dev-bounces@dpdk.org<mailto:dev-bounces@dpdk.org>] On Behalf Of Thomas Monjalon
> > > 05/10/2018 14:45, Alejandro Lucero:
> > > > I sent a patchset about this to be applied on 17.11 stable. The memory
> > > > code has had main changes since that version, so here it is the patchset
> > > > adjusted to current master repo.
> > > >
> > > > This patchset adds, mainly, a check for ensuring IOVAs are within a
> > > > restricted range due to addressing limitations with some devices. There
> > > > are two known cases: NFP and IOMMU VT-d emulation.
> > > >
> > > > With this check IOVAs out of range are detected and PMDs can abort
> > > > initialization. For the VT-d case, IOVA VA mode is allowed as long as
> > > > IOVAs are within the supported range, avoiding to forbid IOVA VA by
> > > > default.
> > > >
> > > > For the addressing limitations known cases, there are just 40(NFP) or
> > > > 39(VT-d) bits for handling IOVAs. When using IOVA PA, those limitations
> > > > imply 1TB(NFP) or 512M(VT-d) as upper limits, which is likely enough for
> > > > most systems. With machines using more memory, the added check will
> > > > ensure IOVAs within the range.
> > > >
> > > > With IOVA VA, and because the way the Linux kernel serves mmap calls
> > > > in 64 bits systems, 39 or 40 bits are not enough. It is possible to
> > > > give an address hint with a lower starting address than the default one
> > > > used by the kernel, and then ensuring the mmap uses that hint or hint plus
> > > > some offset. With 64 bits systems, the process virtual address space is
> > > > large enoguh for doing the hugepages mmaping within the supported
> > > range
> > > > when those addressing limitations exist. This patchset also adds a change
> > > > for using such a hint making the use of IOVA VA a more than likely
> > > > possibility when there are those addressing limitations.
> > > >
> > > > The check is not done by default but just when it is required. This
> > > > patchset adds the check for NFP initialization and for setting the IOVA
> > > > mode is an emulated VT-d is detected. Also, because the recent patchset
> > > > adding dynamic memory allocation, the check is also invoked for ensuring
> > > > the new memsegs are within the required range.
> > > >
> > > > This patchset could be applied to stable 18.05.
> > >
> > > Applied, thanks
  
Thomas Monjalon Oct. 29, 2018, 9:48 a.m. UTC | #8
29/10/2018 10:36, Yao, Lei A:
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > 29/10/2018 09:23, Yao, Lei A:
> > > Hi, Lucero, Thomas
> > >
> > > This patch set will cause deadlock during memory initialization.
> > > rte_memseg_walk and try_expand_heap both will lock
> > > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
> > >
> > > #0       rte_memseg_walk
> > > #1  <-rte_eal_check_dma_mask
> > > #2  <-alloc_pages_on_heap
> > > #3  <-try_expand_heap_primary
> > > #4  <-try_expand_heap
> > >
> > > Log as following:
> > > EAL: TSC frequency is ~2494156 KHz
> > > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > > EAL: Trying to obtain current memory policy.
> > > EAL: Setting policy MPOL_PREFERRED for socket 0
> > > EAL: Restoring previous memory policy: 0
> > >
> > > Could you have a check on this? A lot of test cases in our validation
> > > team fail because of this. Thanks a lot!
> > 
> > Can we just call rte_memseg_walk_thread_unsafe()?
> > 
> > +Cc Anatoly
> 
> Hi, Thomas
> 
> I change to rte_memseg_walk_thread_unsafe(), still
> Can't work. 
> 
> EAL: Setting policy MPOL_PREFERRED for socket 0
> EAL: Restoring previous memory policy: 0
> EAL: memseg iova 140000000, len 40000000, out of range
> EAL:    using dma mask ffffffffffffffff
> EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
> EAL: Trying to obtain current memory policy.
> EAL: Setting policy MPOL_PREFERRED for socket 1
> EAL: Restoring previous memory policy: 0
> EAL: memseg iova 1bc0000000, len 40000000, out of range
> EAL:    using dma mask ffffffffffffffff
> EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
> error allocating rte services array
> EAL: FATAL: rte_service_init() failed
> EAL: rte_service_init() failed
> PANIC in main():

I think it is showing there are at least 2 issues:
	1/ deadlock
	2/ allocation does not comply with mask check (out of range)
  
Alejandro Lucero Oct. 29, 2018, 10:11 a.m. UTC | #9
I know what is going on.

In patchset version 3 I forgot to remove an old code. Anatoly spotted that
and I was going to send another version for fixing it. Before sending the
new version I saw that report about a problem with dma_mask and I'm afraid
I did not send another version with the fix ...

Yao, can you try with next patch?:

*diff --git a/lib/librte_eal/common/eal_common_memory.c
b/lib/librte_eal/common/eal_common_memory.c*

*index ef656bbad..26adf46c0 100644*

*--- a/lib/librte_eal/common/eal_common_memory.c*

*+++ b/lib/librte_eal/common/eal_common_memory.c*

@@ -458,10 +458,6 @@ rte_eal_check_dma_mask(uint8_t maskbits)

                return -1;

        }



-       /* keep the more restricted maskbit */

-       if (!mcfg->dma_maskbits || maskbits < mcfg->dma_maskbits)

-               mcfg->dma_maskbits = maskbits;

-

        /* create dma mask */

        mask = ~((1ULL << maskbits) - 1);

On Mon, Oct 29, 2018 at 9:48 AM Thomas Monjalon <thomas@monjalon.net> wrote:

> 29/10/2018 10:36, Yao, Lei A:
> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > 29/10/2018 09:23, Yao, Lei A:
> > > > Hi, Lucero, Thomas
> > > >
> > > > This patch set will cause deadlock during memory initialization.
> > > > rte_memseg_walk and try_expand_heap both will lock
> > > > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
> > > >
> > > > #0       rte_memseg_walk
> > > > #1  <-rte_eal_check_dma_mask
> > > > #2  <-alloc_pages_on_heap
> > > > #3  <-try_expand_heap_primary
> > > > #4  <-try_expand_heap
> > > >
> > > > Log as following:
> > > > EAL: TSC frequency is ~2494156 KHz
> > > > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
> > > > [New Thread 0x7ffff5e0d700 (LWP 330350)]
> > > > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
> > > > EAL: Trying to obtain current memory policy.
> > > > EAL: Setting policy MPOL_PREFERRED for socket 0
> > > > EAL: Restoring previous memory policy: 0
> > > >
> > > > Could you have a check on this? A lot of test cases in our validation
> > > > team fail because of this. Thanks a lot!
> > >
> > > Can we just call rte_memseg_walk_thread_unsafe()?
> > >
> > > +Cc Anatoly
> >
> > Hi, Thomas
> >
> > I change to rte_memseg_walk_thread_unsafe(), still
> > Can't work.
> >
> > EAL: Setting policy MPOL_PREFERRED for socket 0
> > EAL: Restoring previous memory policy: 0
> > EAL: memseg iova 140000000, len 40000000, out of range
> > EAL:    using dma mask ffffffffffffffff
> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
> > EAL: Trying to obtain current memory policy.
> > EAL: Setting policy MPOL_PREFERRED for socket 1
> > EAL: Restoring previous memory policy: 0
> > EAL: memseg iova 1bc0000000, len 40000000, out of range
> > EAL:    using dma mask ffffffffffffffff
> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
> > error allocating rte services array
> > EAL: FATAL: rte_service_init() failed
> > EAL: rte_service_init() failed
> > PANIC in main():
>
> I think it is showing there are at least 2 issues:
>         1/ deadlock
>         2/ allocation does not comply with mask check (out of range)
>
>
>
  
Alejandro Lucero Oct. 29, 2018, 10:15 a.m. UTC | #10
Apologies. Forget my previous email. Just using the wrong repo.

Looking at solving this asap.

On Mon, Oct 29, 2018 at 10:11 AM Alejandro Lucero <
alejandro.lucero@netronome.com> wrote:

> I know what is going on.
>
> In patchset version 3 I forgot to remove an old code. Anatoly spotted that
> and I was going to send another version for fixing it. Before sending the
> new version I saw that report about a problem with dma_mask and I'm afraid
> I did not send another version with the fix ...
>
> Yao, can you try with next patch?:
>
> *diff --git a/lib/librte_eal/common/eal_common_memory.c
> b/lib/librte_eal/common/eal_common_memory.c*
>
> *index ef656bbad..26adf46c0 100644*
>
> *--- a/lib/librte_eal/common/eal_common_memory.c*
>
> *+++ b/lib/librte_eal/common/eal_common_memory.c*
>
> @@ -458,10 +458,6 @@ rte_eal_check_dma_mask(uint8_t maskbits)
>
>                 return -1;
>
>         }
>
>
>
> -       /* keep the more restricted maskbit */
>
> -       if (!mcfg->dma_maskbits || maskbits < mcfg->dma_maskbits)
>
> -               mcfg->dma_maskbits = maskbits;
>
> -
>
>         /* create dma mask */
>
>         mask = ~((1ULL << maskbits) - 1);
>
> On Mon, Oct 29, 2018 at 9:48 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
>> 29/10/2018 10:36, Yao, Lei A:
>> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
>> > > 29/10/2018 09:23, Yao, Lei A:
>> > > > Hi, Lucero, Thomas
>> > > >
>> > > > This patch set will cause deadlock during memory initialization.
>> > > > rte_memseg_walk and try_expand_heap both will lock
>> > > > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
>> > > >
>> > > > #0       rte_memseg_walk
>> > > > #1  <-rte_eal_check_dma_mask
>> > > > #2  <-alloc_pages_on_heap
>> > > > #3  <-try_expand_heap_primary
>> > > > #4  <-try_expand_heap
>> > > >
>> > > > Log as following:
>> > > > EAL: TSC frequency is ~2494156 KHz
>> > > > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
>> > > > [New Thread 0x7ffff5e0d700 (LWP 330350)]
>> > > > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
>> > > > EAL: Trying to obtain current memory policy.
>> > > > EAL: Setting policy MPOL_PREFERRED for socket 0
>> > > > EAL: Restoring previous memory policy: 0
>> > > >
>> > > > Could you have a check on this? A lot of test cases in our
>> validation
>> > > > team fail because of this. Thanks a lot!
>> > >
>> > > Can we just call rte_memseg_walk_thread_unsafe()?
>> > >
>> > > +Cc Anatoly
>> >
>> > Hi, Thomas
>> >
>> > I change to rte_memseg_walk_thread_unsafe(), still
>> > Can't work.
>> >
>> > EAL: Setting policy MPOL_PREFERRED for socket 0
>> > EAL: Restoring previous memory policy: 0
>> > EAL: memseg iova 140000000, len 40000000, out of range
>> > EAL:    using dma mask ffffffffffffffff
>> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
>> > EAL: Trying to obtain current memory policy.
>> > EAL: Setting policy MPOL_PREFERRED for socket 1
>> > EAL: Restoring previous memory policy: 0
>> > EAL: memseg iova 1bc0000000, len 40000000, out of range
>> > EAL:    using dma mask ffffffffffffffff
>> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
>> > error allocating rte services array
>> > EAL: FATAL: rte_service_init() failed
>> > EAL: rte_service_init() failed
>> > PANIC in main():
>>
>> I think it is showing there are at least 2 issues:
>>         1/ deadlock
>>         2/ allocation does not comply with mask check (out of range)
>>
>>
>>
  
Alejandro Lucero Oct. 29, 2018, 11:39 a.m. UTC | #11
I got a patch that solves a bug when calling rte_eal_dma_mask using the
mask instead of the maskbits. However, this does not solves the deadlock.

Interestingly, the problem looks like a compiler one. Calling
rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
you modify the call like this:

*diff --git a/lib/librte_eal/common/eal_common_memory.c
b/lib/librte_eal/common/eal_common_memory.c*

*index 12dcedf5c..69b26e464 100644*

*--- a/lib/librte_eal/common/eal_common_memory.c*

*+++ b/lib/librte_eal/common/eal_common_memory.c*

@@ -462,7 +462,7 @@ rte_eal_check_dma_mask(uint8_t maskbits)

        /* create dma mask */

        mask = ~((1ULL << maskbits) - 1);



-       if (rte_memseg_walk(check_iova, &mask))

+       if (!rte_memseg_walk(check_iova, &mask))

                /*

                 * Dma mask precludes hugepage usage.

                 * This device can not be used and we do not need to keep


it works, although the value returned to the invoker changes, of course.
But the point here is it should be the same behaviour when calling
rte_memseg_walk than before and it is not.


Anatoly, maybe you can see something I can not.



On Mon, Oct 29, 2018 at 10:15 AM Alejandro Lucero <
alejandro.lucero@netronome.com> wrote:

> Apologies. Forget my previous email. Just using the wrong repo.
>
> Looking at solving this asap.
>
> On Mon, Oct 29, 2018 at 10:11 AM Alejandro Lucero <
> alejandro.lucero@netronome.com> wrote:
>
>> I know what is going on.
>>
>> In patchset version 3 I forgot to remove an old code. Anatoly spotted
>> that and I was going to send another version for fixing it. Before sending
>> the new version I saw that report about a problem with dma_mask and I'm
>> afraid I did not send another version with the fix ...
>>
>> Yao, can you try with next patch?:
>>
>> *diff --git a/lib/librte_eal/common/eal_common_memory.c
>> b/lib/librte_eal/common/eal_common_memory.c*
>>
>> *index ef656bbad..26adf46c0 100644*
>>
>> *--- a/lib/librte_eal/common/eal_common_memory.c*
>>
>> *+++ b/lib/librte_eal/common/eal_common_memory.c*
>>
>> @@ -458,10 +458,6 @@ rte_eal_check_dma_mask(uint8_t maskbits)
>>
>>                 return -1;
>>
>>         }
>>
>>
>>
>> -       /* keep the more restricted maskbit */
>>
>> -       if (!mcfg->dma_maskbits || maskbits < mcfg->dma_maskbits)
>>
>> -               mcfg->dma_maskbits = maskbits;
>>
>> -
>>
>>         /* create dma mask */
>>
>>         mask = ~((1ULL << maskbits) - 1);
>>
>> On Mon, Oct 29, 2018 at 9:48 AM Thomas Monjalon <thomas@monjalon.net>
>> wrote:
>>
>>> 29/10/2018 10:36, Yao, Lei A:
>>> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
>>> > > 29/10/2018 09:23, Yao, Lei A:
>>> > > > Hi, Lucero, Thomas
>>> > > >
>>> > > > This patch set will cause deadlock during memory initialization.
>>> > > > rte_memseg_walk and try_expand_heap both will lock
>>> > > > the file &mcfg->memory_hotplug_lock. So dead lock will occur.
>>> > > >
>>> > > > #0       rte_memseg_walk
>>> > > > #1  <-rte_eal_check_dma_mask
>>> > > > #2  <-alloc_pages_on_heap
>>> > > > #3  <-try_expand_heap_primary
>>> > > > #4  <-try_expand_heap
>>> > > >
>>> > > > Log as following:
>>> > > > EAL: TSC frequency is ~2494156 KHz
>>> > > > EAL: Master lcore 0 is ready (tid=7ffff7fe3c00;cpuset=[0])
>>> > > > [New Thread 0x7ffff5e0d700 (LWP 330350)]
>>> > > > EAL: lcore 1 is ready (tid=7ffff5e0d700;cpuset=[1])
>>> > > > EAL: Trying to obtain current memory policy.
>>> > > > EAL: Setting policy MPOL_PREFERRED for socket 0
>>> > > > EAL: Restoring previous memory policy: 0
>>> > > >
>>> > > > Could you have a check on this? A lot of test cases in our
>>> validation
>>> > > > team fail because of this. Thanks a lot!
>>> > >
>>> > > Can we just call rte_memseg_walk_thread_unsafe()?
>>> > >
>>> > > +Cc Anatoly
>>> >
>>> > Hi, Thomas
>>> >
>>> > I change to rte_memseg_walk_thread_unsafe(), still
>>> > Can't work.
>>> >
>>> > EAL: Setting policy MPOL_PREFERRED for socket 0
>>> > EAL: Restoring previous memory policy: 0
>>> > EAL: memseg iova 140000000, len 40000000, out of range
>>> > EAL:    using dma mask ffffffffffffffff
>>> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
>>> > EAL: Trying to obtain current memory policy.
>>> > EAL: Setting policy MPOL_PREFERRED for socket 1
>>> > EAL: Restoring previous memory policy: 0
>>> > EAL: memseg iova 1bc0000000, len 40000000, out of range
>>> > EAL:    using dma mask ffffffffffffffff
>>> > EAL: alloc_pages_on_heap(): couldn't allocate memory due to DMA mask
>>> > error allocating rte services array
>>> > EAL: FATAL: rte_service_init() failed
>>> > EAL: rte_service_init() failed
>>> > PANIC in main():
>>>
>>> I think it is showing there are at least 2 issues:
>>>         1/ deadlock
>>>         2/ allocation does not comply with mask check (out of range)
>>>
>>>
>>>
  
Thomas Monjalon Oct. 29, 2018, 11:46 a.m. UTC | #12
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
> 
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
> 
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 29, 2018, 12:55 p.m. UTC | #13
On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
wrote:

> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the deadlock.
>
> The deadlock is a bigger concern I think.
>
>
I think once the call to rte_eal_check_dma_mask uses the maskbits instead
of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?


> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but
> if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
>
  
Yao, Lei A Oct. 29, 2018, 1:18 p.m. UTC | #14
From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net>
Cc: Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 29, 2018, 1:40 p.m. UTC | #15
On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:

>
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 8:56 PM
> *To:* Thomas Monjalon <thomas@monjalon.net>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the
> deadlock.
>
> The deadlock is a bigger concern I think.
>
>
>
> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>
>
>
> Yao, can you try with the attached patch?
>
>
>
> Hi, Lucero
>
>
>
> This patch can fix the issue at my side. Thanks a lot
>
> for you quick action.
>
>
>

Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where
legacy_mem was still there and therefore dynamic memory allocation code not
used during memory initialization.

There is something that concerns me though. Using
rte_memseg_walk_thread_unsafe could be a problem under some situations
although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then
it is safe to use the unsafe function for walking memsegs, but with device
hotplug and dynamic memory allocation, there exists a potential race
condition when the primary process is allocating more memory and
concurrently a device is hotplugged and a secondary process does the device
initialization. By now, this is just a problem with the NFP, and the
potential race condition window really unlikely, but I will work on this
asap.


> BRs
>
> Lei
>
>
>
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> but if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
  
Thomas Monjalon Oct. 29, 2018, 2:18 p.m. UTC | #16
29/10/2018 14:40, Alejandro Lucero:
> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
> > *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> > On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> > wrote:
> >
> > 29/10/2018 12:39, Alejandro Lucero:
> > > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > > mask instead of the maskbits. However, this does not solves the
> > deadlock.
> >
> > The deadlock is a bigger concern I think.
> >
> > I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> > of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
> >
> > Yao, can you try with the attached patch?
> >
> > Hi, Lucero
> >
> > This patch can fix the issue at my side. Thanks a lot
> > for you quick action.
> 
> Great!
> 
> I will send an official patch with the changes.

Please, do not forget my other request to better comment functions.


> I have to say that I tested the patchset, but I think it was where
> legacy_mem was still there and therefore dynamic memory allocation code not
> used during memory initialization.
> 
> There is something that concerns me though. Using
> rte_memseg_walk_thread_unsafe could be a problem under some situations
> although those situations being unlikely.
> 
> Usually, calling rte_eal_check_dma_mask happens during initialization. Then
> it is safe to use the unsafe function for walking memsegs, but with device
> hotplug and dynamic memory allocation, there exists a potential race
> condition when the primary process is allocating more memory and
> concurrently a device is hotplugged and a secondary process does the device
> initialization. By now, this is just a problem with the NFP, and the
> potential race condition window really unlikely, but I will work on this
> asap.

Yes, this is what concerns me.
You can add a comment explaining the unsafe which is not handled.


> > > Interestingly, the problem looks like a compiler one. Calling
> > > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> > but if
> > > you modify the call like this:
> > >
> > > -       if (rte_memseg_walk(check_iova, &mask))
> > > +       if (!rte_memseg_walk(check_iova, &mask))
> > >
> > > it works, although the value returned to the invoker changes, of course.
> > > But the point here is it should be the same behaviour when calling
> > > rte_memseg_walk than before and it is not.
> >
> > Anyway, the coding style requires to save the return value in a variable,
> > instead of nesting the call in an "if" condition.
> > And the "if" check should be explicitly != 0 because it is not a real
> > boolean.
> >
> > PS: please do not top post and avoid HTML emails, thanks
> >
> >
>
  
Alejandro Lucero Oct. 29, 2018, 2:35 p.m. UTC | #17
On Mon, Oct 29, 2018 at 2:18 PM Thomas Monjalon <thomas@monjalon.net> wrote:

> 29/10/2018 14:40, Alejandro Lucero:
> > On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
> > > *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> > > On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> > > wrote:
> > >
> > > 29/10/2018 12:39, Alejandro Lucero:
> > > > I got a patch that solves a bug when calling rte_eal_dma_mask using
> the
> > > > mask instead of the maskbits. However, this does not solves the
> > > deadlock.
> > >
> > > The deadlock is a bigger concern I think.
> > >
> > > I think once the call to rte_eal_check_dma_mask uses the maskbits
> instead
> > > of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
> > >
> > > Yao, can you try with the attached patch?
> > >
> > > Hi, Lucero
> > >
> > > This patch can fix the issue at my side. Thanks a lot
> > > for you quick action.
> >
> > Great!
> >
> > I will send an official patch with the changes.
>
> Please, do not forget my other request to better comment functions.
>
>
>
Sure.


> > I have to say that I tested the patchset, but I think it was where
> > legacy_mem was still there and therefore dynamic memory allocation code
> not
> > used during memory initialization.
> >
> > There is something that concerns me though. Using
> > rte_memseg_walk_thread_unsafe could be a problem under some situations
> > although those situations being unlikely.
> >
> > Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then
> > it is safe to use the unsafe function for walking memsegs, but with
> device
> > hotplug and dynamic memory allocation, there exists a potential race
> > condition when the primary process is allocating more memory and
> > concurrently a device is hotplugged and a secondary process does the
> device
> > initialization. By now, this is just a problem with the NFP, and the
> > potential race condition window really unlikely, but I will work on this
> > asap.
>
> Yes, this is what concerns me.
> You can add a comment explaining the unsafe which is not handled.
>
>
I'' do.

Thanks!


>
> > > > Interestingly, the problem looks like a compiler one. Calling
> > > > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> > > but if
> > > > you modify the call like this:
> > > >
> > > > -       if (rte_memseg_walk(check_iova, &mask))
> > > > +       if (!rte_memseg_walk(check_iova, &mask))
> > > >
> > > > it works, although the value returned to the invoker changes, of
> course.
> > > > But the point here is it should be the same behaviour when calling
> > > > rte_memseg_walk than before and it is not.
> > >
> > > Anyway, the coding style requires to save the return value in a
> variable,
> > > instead of nesting the call in an "if" condition.
> > > And the "if" check should be explicitly != 0 because it is not a real
> > > boolean.
> > >
> > > PS: please do not top post and avoid HTML emails, thanks
> > >
> > >
> >
>
>
>
>
>
>
  
Yongseok Koh Oct. 29, 2018, 6:54 p.m. UTC | #18
> On Oct 29, 2018, at 7:18 AM, Thomas Monjalon <thomas@monjalon.net> wrote:
> 
> 29/10/2018 14:40, Alejandro Lucero:
>> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
>>> wrote:
>>> 
>>> 29/10/2018 12:39, Alejandro Lucero:
>>>> I got a patch that solves a bug when calling rte_eal_dma_mask using the
>>>> mask instead of the maskbits. However, this does not solves the
>>> deadlock.
>>> 
>>> The deadlock is a bigger concern I think.
>>> 
>>> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
>>> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>>> 
>>> Yao, can you try with the attached patch?
>>> 
>>> Hi, Lucero
>>> 
>>> This patch can fix the issue at my side. Thanks a lot
>>> for you quick action.
>> 
>> Great!
>> 
>> I will send an official patch with the changes.
> 
> Please, do not forget my other request to better comment functions.

Alejandro,

This patchset has been merged to stable/17.11 per your request for the last release.
You must send a fix to stable/17.11 as well, if you think there's a same issue there.

Thanks,
Yongseok

>> I have to say that I tested the patchset, but I think it was where
>> legacy_mem was still there and therefore dynamic memory allocation code not
>> used during memory initialization.
>> 
>> There is something that concerns me though. Using
>> rte_memseg_walk_thread_unsafe could be a problem under some situations
>> although those situations being unlikely.
>> 
>> Usually, calling rte_eal_check_dma_mask happens during initialization. Then
>> it is safe to use the unsafe function for walking memsegs, but with device
>> hotplug and dynamic memory allocation, there exists a potential race
>> condition when the primary process is allocating more memory and
>> concurrently a device is hotplugged and a secondary process does the device
>> initialization. By now, this is just a problem with the NFP, and the
>> potential race condition window really unlikely, but I will work on this
>> asap.
> 
> Yes, this is what concerns me.
> You can add a comment explaining the unsafe which is not handled.
> 
> 
>>>> Interestingly, the problem looks like a compiler one. Calling
>>>> rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
>>> but if
>>>> you modify the call like this:
>>>> 
>>>> -       if (rte_memseg_walk(check_iova, &mask))
>>>> +       if (!rte_memseg_walk(check_iova, &mask))
>>>> 
>>>> it works, although the value returned to the invoker changes, of course.
>>>> But the point here is it should be the same behaviour when calling
>>>> rte_memseg_walk than before and it is not.
>>> 
>>> Anyway, the coding style requires to save the return value in a variable,
>>> instead of nesting the call in an "if" condition.
>>> And the "if" check should be explicitly != 0 because it is not a real
>>> boolean.
>>> 
>>> PS: please do not top post and avoid HTML emails, thanks
>>> 
>>> 
>> 
> 
> 
> 
> 
>
  
Alejandro Lucero Oct. 29, 2018, 7:37 p.m. UTC | #19
On Mon, Oct 29, 2018 at 6:54 PM Yongseok Koh <yskoh@mellanox.com> wrote:

>
> > On Oct 29, 2018, at 7:18 AM, Thomas Monjalon <thomas@monjalon.net>
> wrote:
> >
> > 29/10/2018 14:40, Alejandro Lucero:
> >> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
> >>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> >>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> >>> wrote:
> >>>
> >>> 29/10/2018 12:39, Alejandro Lucero:
> >>>> I got a patch that solves a bug when calling rte_eal_dma_mask using
> the
> >>>> mask instead of the maskbits. However, this does not solves the
> >>> deadlock.
> >>>
> >>> The deadlock is a bigger concern I think.
> >>>
> >>> I think once the call to rte_eal_check_dma_mask uses the maskbits
> instead
> >>> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
> >>>
> >>> Yao, can you try with the attached patch?
> >>>
> >>> Hi, Lucero
> >>>
> >>> This patch can fix the issue at my side. Thanks a lot
> >>> for you quick action.
> >>
> >> Great!
> >>
> >> I will send an official patch with the changes.
> >
> > Please, do not forget my other request to better comment functions.
>
> Alejandro,
>
> This patchset has been merged to stable/17.11 per your request for the
> last release.
> You must send a fix to stable/17.11 as well, if you think there's a same
> issue there.
>
>
The patchset for 17.11 was much more simpler. There have been a lot of
changes to the memory code since 17.11, and this problem should not be
present in stable 17.11.

Once I have said that, if there are any reports about a problem with this
patchset in 17.11, I will work on it as a priority.

Thanks.


> Thanks,
> Yongseok
>
> >> I have to say that I tested the patchset, but I think it was where
> >> legacy_mem was still there and therefore dynamic memory allocation code
> not
> >> used during memory initialization.
> >>
> >> There is something that concerns me though. Using
> >> rte_memseg_walk_thread_unsafe could be a problem under some situations
> >> although those situations being unlikely.
> >>
> >> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then
> >> it is safe to use the unsafe function for walking memsegs, but with
> device
> >> hotplug and dynamic memory allocation, there exists a potential race
> >> condition when the primary process is allocating more memory and
> >> concurrently a device is hotplugged and a secondary process does the
> device
> >> initialization. By now, this is just a problem with the NFP, and the
> >> potential race condition window really unlikely, but I will work on this
> >> asap.
> >
> > Yes, this is what concerns me.
> > You can add a comment explaining the unsafe which is not handled.
> >
> >
> >>>> Interestingly, the problem looks like a compiler one. Calling
> >>>> rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> >>> but if
> >>>> you modify the call like this:
> >>>>
> >>>> -       if (rte_memseg_walk(check_iova, &mask))
> >>>> +       if (!rte_memseg_walk(check_iova, &mask))
> >>>>
> >>>> it works, although the value returned to the invoker changes, of
> course.
> >>>> But the point here is it should be the same behaviour when calling
> >>>> rte_memseg_walk than before and it is not.
> >>>
> >>> Anyway, the coding style requires to save the return value in a
> variable,
> >>> instead of nesting the call in an "if" condition.
> >>> And the "if" check should be explicitly != 0 because it is not a real
> >>> boolean.
> >>>
> >>> PS: please do not top post and avoid HTML emails, thanks
> >>>
> >>>
> >>
> >
> >
> >
> >
> >
>
>
  
Lin, Xueqin Oct. 30, 2018, 3:20 a.m. UTC | #20
Hi Lucero&Thomas,

Find the patch can’t fix multi-process cases.
Steps:

1.       Setup primary process successfully

./hotplug_mp --proc-type=auto



2.       Fail to setup secondary process

./hotplug_mp --proc-type=auto

EAL: Detected 88 lcore(s)

EAL: Detected 2 NUMA nodes

EAL: Auto-detected process type: SECONDARY

EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23

Segmentation fault (core dumped)


More information as below:

Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.

0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

264             for (idx = first; idx < msk->n_masks; idx++) {

#0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

#1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0, next=true,

    used=true) at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001

#2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4, start=0)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018

#3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401 <check_iova>,

    arg=0x7fffffffcc38) at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589

#4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')

    at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465

#5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)

    at /root/dpdk/drivers/bus/pci/linux/pci.c:593

#6  0x00000000005b9738 in pci_devices_iommu_support_va ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:626

#7  0x00000000005b97a7 in rte_pci_get_iommu_class ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:650

#8  0x000000000058f1ce in rte_bus_get_iommu_class ()

    at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237

#9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919

#10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Monday, October 29, 2018 9:41 PM
To: Yao, Lei A <lei.a.yao@intel.com>
Cc: Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>> wrote:


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.


Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where legacy_mem was still there and therefore dynamic memory allocation code not used during memory initialization.

There is something that concerns me though. Using rte_memseg_walk_thread_unsafe could be a problem under some situations although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then it is safe to use the unsafe function for walking memsegs, but with device hotplug and dynamic memory allocation, there exists a potential race condition when the primary process is allocating more memory and concurrently a device is hotplugged and a secondary process does the device initialization. By now, this is just a problem with the NFP, and the potential race condition window really unlikely, but I will work on this asap.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 30, 2018, 9:41 a.m. UTC | #21
On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:

> Hi Lucero&Thomas,
>
>
>
> Find the patch can’t fix multi-process cases.
>

Hi,

I think it is not specifically about multiprocess but about hotplug with
multiprocess because I can execute the symmetric_mp successfully with a
secondary process.

Working on this as a priority.

Thanks.


> Steps:
>
> 1.       Setup primary process successfully
>
> ./hotplug_mp --proc-type=auto
>
>
>
> 2.       Fail to setup secondary process
>
> ./hotplug_mp --proc-type=auto
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23
>
> Segmentation fault (core dumped)
>
>
>
> More information as below:
>
> Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> 264             for (idx = first; idx < msk->n_masks; idx++) {
>
> #0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0,
> used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> #1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0,
> next=true,
>
>     used=true) at
> /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001
>
> #2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4,
> start=0)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018
>
> #3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401
> <check_iova>,
>
>     arg=0x7fffffffcc38) at
> /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589
>
> #4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465
>
> #5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:593
>
> #6  0x00000000005b9738 in pci_devices_iommu_support_va ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:626
>
> #7  0x00000000005b97a7 in rte_pci_get_iommu_class ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:650
>
> #8  0x000000000058f1ce in rte_bus_get_iommu_class ()
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237
>
> #9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919
>
> #10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28
>
>
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 9:41 PM
> *To:* Yao, Lei A <lei.a.yao@intel.com>
> *Cc:* Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian
> Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>
>
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 8:56 PM
> *To:* Thomas Monjalon <thomas@monjalon.net>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the
> deadlock.
>
> The deadlock is a bigger concern I think.
>
>
>
> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>
>
>
> Yao, can you try with the attached patch?
>
>
>
> Hi, Lucero
>
>
>
> This patch can fix the issue at my side. Thanks a lot
>
> for you quick action.
>
>
>
>
>
> Great!
>
>
>
> I will send an official patch with the changes.
>
>
>
> I have to say that I tested the patchset, but I think it was where
> legacy_mem was still there and therefore dynamic memory allocation code not
> used during memory initialization.
>
>
>
> There is something that concerns me though. Using
> rte_memseg_walk_thread_unsafe could be a problem under some situations
> although those situations being unlikely.
>
>
>
> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then it is safe to use the unsafe function for walking memsegs, but with
> device hotplug and dynamic memory allocation, there exists a potential race
> condition when the primary process is allocating more memory and
> concurrently a device is hotplugged and a secondary process does the device
> initialization. By now, this is just a problem with the NFP, and the
> potential race condition window really unlikely, but I will work on this
> asap.
>
>
>
> BRs
>
> Lei
>
>
>
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> but if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
  
Anatoly Burakov Oct. 30, 2018, 10:10 a.m. UTC | #22
On 29-Oct-18 7:37 PM, Alejandro Lucero wrote:
> 
> 
> On Mon, Oct 29, 2018 at 6:54 PM Yongseok Koh <yskoh@mellanox.com 
> <mailto:yskoh@mellanox.com>> wrote:
> 
> 
>      > On Oct 29, 2018, at 7:18 AM, Thomas Monjalon <thomas@monjalon.net
>     <mailto:thomas@monjalon.net>> wrote:
>      >
>      > 29/10/2018 14:40, Alejandro Lucero:
>      >> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com
>     <mailto:lei.a.yao@intel.com>> wrote:
>      >>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com
>     <mailto:alejandro.lucero@netronome.com>]
>      >>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon
>     <thomas@monjalon.net <mailto:thomas@monjalon.net>>
>      >>> wrote:
>      >>>
>      >>> 29/10/2018 12:39, Alejandro Lucero:
>      >>>> I got a patch that solves a bug when calling rte_eal_dma_mask
>     using the
>      >>>> mask instead of the maskbits. However, this does not solves the
>      >>> deadlock.
>      >>>
>      >>> The deadlock is a bigger concern I think.
>      >>>
>      >>> I think once the call to rte_eal_check_dma_mask uses the
>     maskbits instead
>      >>> of the mask, calling rte_memseg_walk_thread_unsafe avoids the
>     deadlock.
>      >>>
>      >>> Yao, can you try with the attached patch?
>      >>>
>      >>> Hi, Lucero
>      >>>
>      >>> This patch can fix the issue at my side. Thanks a lot
>      >>> for you quick action.
>      >>
>      >> Great!
>      >>
>      >> I will send an official patch with the changes.
>      >
>      > Please, do not forget my other request to better comment functions.
> 
>     Alejandro,
> 
>     This patchset has been merged to stable/17.11 per your request for
>     the last release.
>     You must send a fix to stable/17.11 as well, if you think there's a
>     same issue there.
> 
> 
> The patchset for 17.11 was much more simpler. There have been a lot of 
> changes to the memory code since 17.11, and this problem should not be 
> present in stable 17.11.
> 
> Once I have said that, if there are any reports about a problem with 
> this patchset in 17.11, I will work on it as a priority.
> 
> Thanks.
> 

17.11 will definitely be immune to the deadlock issue since there are no 
memseg walks there :) It however may still have incorrect mask handling.
  
Anatoly Burakov Oct. 30, 2018, 10:11 a.m. UTC | #23
On 29-Oct-18 2:18 PM, Thomas Monjalon wrote:
> 29/10/2018 14:40, Alejandro Lucero:
>> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
>>> wrote:
>>>
>>> 29/10/2018 12:39, Alejandro Lucero:
>>>> I got a patch that solves a bug when calling rte_eal_dma_mask using the
>>>> mask instead of the maskbits. However, this does not solves the
>>> deadlock.
>>>
>>> The deadlock is a bigger concern I think.
>>>
>>> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
>>> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>>>
>>> Yao, can you try with the attached patch?
>>>
>>> Hi, Lucero
>>>
>>> This patch can fix the issue at my side. Thanks a lot
>>> for you quick action.
>>
>> Great!
>>
>> I will send an official patch with the changes.
> 
> Please, do not forget my other request to better comment functions.
> 
> 
>> I have to say that I tested the patchset, but I think it was where
>> legacy_mem was still there and therefore dynamic memory allocation code not
>> used during memory initialization.
>>
>> There is something that concerns me though. Using
>> rte_memseg_walk_thread_unsafe could be a problem under some situations
>> although those situations being unlikely.
>>
>> Usually, calling rte_eal_check_dma_mask happens during initialization. Then
>> it is safe to use the unsafe function for walking memsegs, but with device
>> hotplug and dynamic memory allocation, there exists a potential race
>> condition when the primary process is allocating more memory and
>> concurrently a device is hotplugged and a secondary process does the device
>> initialization. By now, this is just a problem with the NFP, and the
>> potential race condition window really unlikely, but I will work on this
>> asap.
> 
> Yes, this is what concerns me.
> You can add a comment explaining the unsafe which is not handled.

The issue here is that this code is called from both memory-locked and 
memory-unlocked context. Virtio had a similar issue with their mem table 
update code - they solved it by manually locking the memory before doing 
everything else, and using thread_unsafe version of the walk.

Could something like that be done here?

> 
> 
>>>> Interestingly, the problem looks like a compiler one. Calling
>>>> rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
>>> but if
>>>> you modify the call like this:
>>>>
>>>> -       if (rte_memseg_walk(check_iova, &mask))
>>>> +       if (!rte_memseg_walk(check_iova, &mask))
>>>>
>>>> it works, although the value returned to the invoker changes, of course.
>>>> But the point here is it should be the same behaviour when calling
>>>> rte_memseg_walk than before and it is not.
>>>
>>> Anyway, the coding style requires to save the return value in a variable,
>>> instead of nesting the call in an "if" condition.
>>> And the "if" check should be explicitly != 0 because it is not a real
>>> boolean.
>>>
>>> PS: please do not top post and avoid HTML emails, thanks
>>>
>>>
>>
> 
> 
> 
> 
> 
>
  
Anatoly Burakov Oct. 30, 2018, 10:18 a.m. UTC | #24
On 29-Oct-18 11:39 AM, Alejandro Lucero wrote:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the 
> mask instead of the maskbits. However, this does not solves the deadlock.
> 
> Interestingly, the problem looks like a compiler one. Calling 
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but 
> if you modify the call like this:
> 
> *diff --git a/lib/librte_eal/common/eal_common_memory.c 
> b/lib/librte_eal/common/eal_common_memory.c*
> 
> *index 12dcedf5c..69b26e464 100644*
> 
> *--- a/lib/librte_eal/common/eal_common_memory.c*
> 
> *+++ b/lib/librte_eal/common/eal_common_memory.c*
> 
> @@ -462,7 +462,7 @@rte_eal_check_dma_mask(uint8_t maskbits)
> 
> /* create dma mask */
> 
> mask = ~((1ULL << maskbits) - 1);
> 
> - if (rte_memseg_walk(check_iova, &mask))
> 
> +if (!rte_memseg_walk(check_iova, &mask))
> 
> /*
> 
> * Dma mask precludes hugepage usage.
> 
> * This device can not be used and we do not need to keep
> 
> 
> it works, although the value returned to the invoker changes, of course. 
> But the point here is it should be the same behaviour when calling 
> rte_memseg_walk than before and it is not.
> 
> 
> Anatoly, maybe you can see something I can not.
> 

memseg walk will return 0 only when each callback returned 0 and there 
were no more segments left to call callbacks on. If your code always 
returns 0, then return value of memseg_walk will always be zero.

If your code returns 1 or -1 in some cases, then this error condition 
will trigger. If it doesn't, then your condition by which you decide to 
return 1 or 0, is incorrect :) I couldn't spot any obvious issues there, 
but i'll recheck.
  
Alejandro Lucero Oct. 30, 2018, 10:19 a.m. UTC | #25
On Tue, Oct 30, 2018 at 10:11 AM Burakov, Anatoly <anatoly.burakov@intel.com>
wrote:

> On 29-Oct-18 2:18 PM, Thomas Monjalon wrote:
> > 29/10/2018 14:40, Alejandro Lucero:
> >> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
> >>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> >>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> >>> wrote:
> >>>
> >>> 29/10/2018 12:39, Alejandro Lucero:
> >>>> I got a patch that solves a bug when calling rte_eal_dma_mask using
> the
> >>>> mask instead of the maskbits. However, this does not solves the
> >>> deadlock.
> >>>
> >>> The deadlock is a bigger concern I think.
> >>>
> >>> I think once the call to rte_eal_check_dma_mask uses the maskbits
> instead
> >>> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
> >>>
> >>> Yao, can you try with the attached patch?
> >>>
> >>> Hi, Lucero
> >>>
> >>> This patch can fix the issue at my side. Thanks a lot
> >>> for you quick action.
> >>
> >> Great!
> >>
> >> I will send an official patch with the changes.
> >
> > Please, do not forget my other request to better comment functions.
> >
> >
> >> I have to say that I tested the patchset, but I think it was where
> >> legacy_mem was still there and therefore dynamic memory allocation code
> not
> >> used during memory initialization.
> >>
> >> There is something that concerns me though. Using
> >> rte_memseg_walk_thread_unsafe could be a problem under some situations
> >> although those situations being unlikely.
> >>
> >> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then
> >> it is safe to use the unsafe function for walking memsegs, but with
> device
> >> hotplug and dynamic memory allocation, there exists a potential race
> >> condition when the primary process is allocating more memory and
> >> concurrently a device is hotplugged and a secondary process does the
> device
> >> initialization. By now, this is just a problem with the NFP, and the
> >> potential race condition window really unlikely, but I will work on this
> >> asap.
> >
> > Yes, this is what concerns me.
> > You can add a comment explaining the unsafe which is not handled.
>
> The issue here is that this code is called from both memory-locked and
> memory-unlocked context. Virtio had a similar issue with their mem table
> update code - they solved it by manually locking the memory before doing
> everything else, and using thread_unsafe version of the walk.
>
> Could something like that be done here?
>
>
I have a patch adding a safe and an unsafe dma mask check versions.
However, because the multiprocess problem reported, I think the fixing
requires other type of work.

The problem I see now is calling rte_eal_check_dma_mask from set_iova_mode
code path is wrong. This can not be done at that point because the memory
has not been initialized yet.



> >
> >
> >>>> Interestingly, the problem looks like a compiler one. Calling
> >>>> rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> >>> but if
> >>>> you modify the call like this:
> >>>>
> >>>> -       if (rte_memseg_walk(check_iova, &mask))
> >>>> +       if (!rte_memseg_walk(check_iova, &mask))
> >>>>
> >>>> it works, although the value returned to the invoker changes, of
> course.
> >>>> But the point here is it should be the same behaviour when calling
> >>>> rte_memseg_walk than before and it is not.
> >>>
> >>> Anyway, the coding style requires to save the return value in a
> variable,
> >>> instead of nesting the call in an "if" condition.
> >>> And the "if" check should be explicitly != 0 because it is not a real
> >>> boolean.
> >>>
> >>> PS: please do not top post and avoid HTML emails, thanks
> >>>
> >>>
> >>
> >
> >
> >
> >
> >
> >
>
>
> --
> Thanks,
> Anatoly
>
  
Alejandro Lucero Oct. 30, 2018, 10:23 a.m. UTC | #26
On Tue, Oct 30, 2018 at 10:19 AM Burakov, Anatoly <anatoly.burakov@intel.com>
wrote:

> On 29-Oct-18 11:39 AM, Alejandro Lucero wrote:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the deadlock.
> >
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but
> > if you modify the call like this:
> >
> > *diff --git a/lib/librte_eal/common/eal_common_memory.c
> > b/lib/librte_eal/common/eal_common_memory.c*
> >
> > *index 12dcedf5c..69b26e464 100644*
> >
> > *--- a/lib/librte_eal/common/eal_common_memory.c*
> >
> > *+++ b/lib/librte_eal/common/eal_common_memory.c*
> >
> > @@ -462,7 +462,7 @@rte_eal_check_dma_mask(uint8_t maskbits)
> >
> > /* create dma mask */
> >
> > mask = ~((1ULL << maskbits) - 1);
> >
> > - if (rte_memseg_walk(check_iova, &mask))
> >
> > +if (!rte_memseg_walk(check_iova, &mask))
> >
> > /*
> >
> > * Dma mask precludes hugepage usage.
> >
> > * This device can not be used and we do not need to keep
> >
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
> >
> >
> > Anatoly, maybe you can see something I can not.
> >
>
> memseg walk will return 0 only when each callback returned 0 and there
> were no more segments left to call callbacks on. If your code always
> returns 0, then return value of memseg_walk will always be zero.
>
> If your code returns 1 or -1 in some cases, then this error condition
> will trigger. If it doesn't, then your condition by which you decide to
> return 1 or 0, is incorrect :) I couldn't spot any obvious issues there,
> but i'll recheck.
>
>
Thanks for looking at this, but I was wrong. The return code changes
everything so it does not make sense to compare both.
  
Lin, Xueqin Oct. 30, 2018, 10:33 a.m. UTC | #27
Hi Lucero,

No, we have reproduced multi-process issues(include symmetric_mp, simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
It is also strange that 1~2 servers don’t have the issue.

Bind two NNT ports or FVL ports

./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4 --proc-id=1

EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Auto-detected process type: SECONDARY
[New Thread 0x7ffff6eda700 (LWP 90103)]
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
[New Thread 0x7ffff66d9700 (LWP 90104)]

Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
0x00000000005566b5 in rte_fbarray_find_next_used ()
(gdb) bt
#0  0x00000000005566b5 in rte_fbarray_find_next_used ()
#1  0x000000000054da9c in rte_eal_check_dma_mask ()
#2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
#3  0x0000000000573988 in rte_pci_get_iommu_class ()
#4  0x000000000054f743 in rte_bus_get_iommu_class ()
#5  0x000000000053c123 in rte_eal_init ()
#6  0x000000000046be2b in main ()

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Tuesday, October 30, 2018 5:41 PM
To: Lin, Xueqin <xueqin.lin@intel.com>
Cc: Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero&Thomas,

Find the patch can’t fix multi-process cases.

Hi,

I think it is not specifically about multiprocess but about hotplug with multiprocess because I can execute the symmetric_mp successfully with a secondary process.

Working on this as a priority.

Thanks.

Steps:

1.       Setup primary process successfully

./hotplug_mp --proc-type=auto



2.       Fail to setup secondary process

./hotplug_mp --proc-type=auto

EAL: Detected 88 lcore(s)

EAL: Detected 2 NUMA nodes

EAL: Auto-detected process type: SECONDARY

EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23

Segmentation fault (core dumped)


More information as below:

Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.

0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

264             for (idx = first; idx < msk->n_masks; idx++) {

#0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

#1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0, next=true,

    used=true) at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001

#2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4, start=0)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018

#3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401 <check_iova>,

    arg=0x7fffffffcc38) at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589

#4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')

    at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465

#5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)

    at /root/dpdk/drivers/bus/pci/linux/pci.c:593

#6  0x00000000005b9738 in pci_devices_iommu_support_va ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:626

#7  0x00000000005b97a7 in rte_pci_get_iommu_class ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:650

#8  0x000000000058f1ce in rte_bus_get_iommu_class ()

    at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237

#9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919

#10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 9:41 PM
To: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>
Cc: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>> wrote:


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.


Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where legacy_mem was still there and therefore dynamic memory allocation code not used during memory initialization.

There is something that concerns me though. Using rte_memseg_walk_thread_unsafe could be a problem under some situations although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then it is safe to use the unsafe function for walking memsegs, but with device hotplug and dynamic memory allocation, there exists a potential race condition when the primary process is allocating more memory and concurrently a device is hotplugged and a secondary process does the device initialization. By now, this is just a problem with the NFP, and the potential race condition window really unlikely, but I will work on this asap.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 30, 2018, 10:38 a.m. UTC | #28
On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:

> Hi Lucero,
>
>
>
> No, we have reproduced multi-process issues(include symmetric_mp,
> simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
>
> It is also strange that 1~2 servers don’t have the issue.
>
>
>

Yes, you are right. I could execute it but it was due to how this problem
triggers.
I think I can fix this and at the same time solving properly the initial
issue without any limitation like that potential race condition I
mentioned.
I can give you a patch to try in a couple of hours.

Thanks


> Bind two NNT ports or FVL ports
>
>
>
> ./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4
> --proc-id=1
>
>
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> [New Thread 0x7ffff6eda700 (LWP 90103)]
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
>
> [New Thread 0x7ffff66d9700 (LWP 90104)]
>
>
>
> Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> (gdb) bt
>
> #0  0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> #1  0x000000000054da9c in rte_eal_check_dma_mask ()
>
> #2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
>
> #3  0x0000000000573988 in rte_pci_get_iommu_class ()
>
> #4  0x000000000054f743 in rte_bus_get_iommu_class ()
>
> #5  0x000000000053c123 in rte_eal_init ()
>
> #6  0x000000000046be2b in main ()
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 5:41 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Hi Lucero&Thomas,
>
>
>
> Find the patch can’t fix multi-process cases.
>
>
>
> Hi,
>
>
>
> I think it is not specifically about multiprocess but about hotplug with
> multiprocess because I can execute the symmetric_mp successfully with a
> secondary process.
>
>
>
> Working on this as a priority.
>
>
>
> Thanks.
>
>
>
> Steps:
>
> 1.       Setup primary process successfully
>
> ./hotplug_mp --proc-type=auto
>
>
>
> 2.       Fail to setup secondary process
>
> ./hotplug_mp --proc-type=auto
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23
>
> Segmentation fault (core dumped)
>
>
>
> More information as below:
>
> Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> 264             for (idx = first; idx < msk->n_masks; idx++) {
>
> #0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0,
> used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> #1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0,
> next=true,
>
>     used=true) at
> /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001
>
> #2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4,
> start=0)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018
>
> #3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401
> <check_iova>,
>
>     arg=0x7fffffffcc38) at
> /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589
>
> #4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465
>
> #5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:593
>
> #6  0x00000000005b9738 in pci_devices_iommu_support_va ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:626
>
> #7  0x00000000005b97a7 in rte_pci_get_iommu_class ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:650
>
> #8  0x000000000058f1ce in rte_bus_get_iommu_class ()
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237
>
> #9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919
>
> #10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28
>
>
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 9:41 PM
> *To:* Yao, Lei A <lei.a.yao@intel.com>
> *Cc:* Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian
> Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>
>
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 8:56 PM
> *To:* Thomas Monjalon <thomas@monjalon.net>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the
> deadlock.
>
> The deadlock is a bigger concern I think.
>
>
>
> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>
>
>
> Yao, can you try with the attached patch?
>
>
>
> Hi, Lucero
>
>
>
> This patch can fix the issue at my side. Thanks a lot
>
> for you quick action.
>
>
>
>
>
> Great!
>
>
>
> I will send an official patch with the changes.
>
>
>
> I have to say that I tested the patchset, but I think it was where
> legacy_mem was still there and therefore dynamic memory allocation code not
> used during memory initialization.
>
>
>
> There is something that concerns me though. Using
> rte_memseg_walk_thread_unsafe could be a problem under some situations
> although those situations being unlikely.
>
>
>
> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then it is safe to use the unsafe function for walking memsegs, but with
> device hotplug and dynamic memory allocation, there exists a potential race
> condition when the primary process is allocating more memory and
> concurrently a device is hotplugged and a secondary process does the device
> initialization. By now, this is just a problem with the NFP, and the
> potential race condition window really unlikely, but I will work on this
> asap.
>
>
>
> BRs
>
> Lei
>
>
>
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> but if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
  
Lin, Xueqin Oct. 30, 2018, 12:21 p.m. UTC | #29
Some found on some our servers:
If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1: Success to setup testpmd  and secondary process.

If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1:  Fail to setup testpmd  and secondary process.
18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to setup secondary process.

Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
Most of our team servers should enable the IOMMU for VT-d and vfio test.

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Tuesday, October 30, 2018 6:38 PM
To: Lin, Xueqin <xueqin.lin@intel.com>
Cc: Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero,

No, we have reproduced multi-process issues(include symmetric_mp, simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
It is also strange that 1~2 servers don’t have the issue.


Yes, you are right. I could execute it but it was due to how this problem triggers.
I think I can fix this and at the same time solving properly the initial issue without any limitation like that potential race condition I mentioned.
I can give you a patch to try in a couple of hours.

Thanks

Bind two NNT ports or FVL ports

./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4 --proc-id=1

EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Auto-detected process type: SECONDARY
[New Thread 0x7ffff6eda700 (LWP 90103)]
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
[New Thread 0x7ffff66d9700 (LWP 90104)]

Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
0x00000000005566b5 in rte_fbarray_find_next_used ()
(gdb) bt
#0  0x00000000005566b5 in rte_fbarray_find_next_used ()
#1  0x000000000054da9c in rte_eal_check_dma_mask ()
#2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
#3  0x0000000000573988 in rte_pci_get_iommu_class ()
#4  0x000000000054f743 in rte_bus_get_iommu_class ()
#5  0x000000000053c123 in rte_eal_init ()
#6  0x000000000046be2b in main ()

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 5:41 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero&Thomas,

Find the patch can’t fix multi-process cases.

Hi,

I think it is not specifically about multiprocess but about hotplug with multiprocess because I can execute the symmetric_mp successfully with a secondary process.

Working on this as a priority.

Thanks.

Steps:

1.       Setup primary process successfully

./hotplug_mp --proc-type=auto



2.       Fail to setup secondary process

./hotplug_mp --proc-type=auto

EAL: Detected 88 lcore(s)

EAL: Detected 2 NUMA nodes

EAL: Auto-detected process type: SECONDARY

EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23

Segmentation fault (core dumped)


More information as below:

Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.

0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

264             for (idx = first; idx < msk->n_masks; idx++) {

#0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

#1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0, next=true,

    used=true) at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001

#2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4, start=0)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018

#3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401 <check_iova>,

    arg=0x7fffffffcc38) at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589

#4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')

    at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465

#5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)

    at /root/dpdk/drivers/bus/pci/linux/pci.c:593

#6  0x00000000005b9738 in pci_devices_iommu_support_va ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:626

#7  0x00000000005b97a7 in rte_pci_get_iommu_class ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:650

#8  0x000000000058f1ce in rte_bus_get_iommu_class ()

    at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237

#9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919

#10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 9:41 PM
To: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>
Cc: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>> wrote:


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.


Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where legacy_mem was still there and therefore dynamic memory allocation code not used during memory initialization.

There is something that concerns me though. Using rte_memseg_walk_thread_unsafe could be a problem under some situations although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then it is safe to use the unsafe function for walking memsegs, but with device hotplug and dynamic memory allocation, there exists a potential race condition when the primary process is allocating more memory and concurrently a device is hotplugged and a secondary process does the device initialization. By now, this is just a problem with the NFP, and the potential race condition window really unlikely, but I will work on this asap.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 30, 2018, 12:37 p.m. UTC | #30
On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com> wrote:

> Some found on some our servers:
>
> If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
> reboot to make it effective.
>
> 18.11 rc1: Success to setup testpmd  and secondary process.
>
>
>
> If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
> reboot to make it effective.
>
> 18.11 rc1:  Fail to setup testpmd  and secondary process.
>
> 18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to setup
> secondary process.
>
>
>
> Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
>
> Most of our team servers should enable the IOMMU for VT-d and vfio test.
>
>
>

It makes sense because the problem is when the IOVA mode is set inside
drivers/bus/pci/linux/pci.c and if there is not IOMMU, not call to
rte_eal_check_dma_mask at all.



> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 6:38 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Hi Lucero,
>
>
>
> No, we have reproduced multi-process issues(include symmetric_mp,
> simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
>
> It is also strange that 1~2 servers don’t have the issue.
>
>
>
>
>
> Yes, you are right. I could execute it but it was due to how this problem
> triggers.
>
> I think I can fix this and at the same time solving properly the initial
> issue without any limitation like that potential race condition I
> mentioned.
>
> I can give you a patch to try in a couple of hours.
>
>
>
> Thanks
>
>
>
> Bind two NNT ports or FVL ports
>
>
>
> ./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4
> --proc-id=1
>
>
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> [New Thread 0x7ffff6eda700 (LWP 90103)]
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
>
> [New Thread 0x7ffff66d9700 (LWP 90104)]
>
>
>
> Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> (gdb) bt
>
> #0  0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> #1  0x000000000054da9c in rte_eal_check_dma_mask ()
>
> #2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
>
> #3  0x0000000000573988 in rte_pci_get_iommu_class ()
>
> #4  0x000000000054f743 in rte_bus_get_iommu_class ()
>
> #5  0x000000000053c123 in rte_eal_init ()
>
> #6  0x000000000046be2b in main ()
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 5:41 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Hi Lucero&Thomas,
>
>
>
> Find the patch can’t fix multi-process cases.
>
>
>
> Hi,
>
>
>
> I think it is not specifically about multiprocess but about hotplug with
> multiprocess because I can execute the symmetric_mp successfully with a
> secondary process.
>
>
>
> Working on this as a priority.
>
>
>
> Thanks.
>
>
>
> Steps:
>
> 1.       Setup primary process successfully
>
> ./hotplug_mp --proc-type=auto
>
>
>
> 2.       Fail to setup secondary process
>
> ./hotplug_mp --proc-type=auto
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23
>
> Segmentation fault (core dumped)
>
>
>
> More information as below:
>
> Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> 264             for (idx = first; idx < msk->n_masks; idx++) {
>
> #0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0,
> used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> #1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0,
> next=true,
>
>     used=true) at
> /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001
>
> #2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4,
> start=0)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018
>
> #3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401
> <check_iova>,
>
>     arg=0x7fffffffcc38) at
> /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589
>
> #4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465
>
> #5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:593
>
> #6  0x00000000005b9738 in pci_devices_iommu_support_va ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:626
>
> #7  0x00000000005b97a7 in rte_pci_get_iommu_class ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:650
>
> #8  0x000000000058f1ce in rte_bus_get_iommu_class ()
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237
>
> #9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919
>
> #10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28
>
>
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 9:41 PM
> *To:* Yao, Lei A <lei.a.yao@intel.com>
> *Cc:* Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian
> Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>
>
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 8:56 PM
> *To:* Thomas Monjalon <thomas@monjalon.net>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the
> deadlock.
>
> The deadlock is a bigger concern I think.
>
>
>
> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>
>
>
> Yao, can you try with the attached patch?
>
>
>
> Hi, Lucero
>
>
>
> This patch can fix the issue at my side. Thanks a lot
>
> for you quick action.
>
>
>
>
>
> Great!
>
>
>
> I will send an official patch with the changes.
>
>
>
> I have to say that I tested the patchset, but I think it was where
> legacy_mem was still there and therefore dynamic memory allocation code not
> used during memory initialization.
>
>
>
> There is something that concerns me though. Using
> rte_memseg_walk_thread_unsafe could be a problem under some situations
> although those situations being unlikely.
>
>
>
> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then it is safe to use the unsafe function for walking memsegs, but with
> device hotplug and dynamic memory allocation, there exists a potential race
> condition when the primary process is allocating more memory and
> concurrently a device is hotplugged and a secondary process does the device
> initialization. By now, this is just a problem with the NFP, and the
> potential race condition window really unlikely, but I will work on this
> asap.
>
>
>
> BRs
>
> Lei
>
>
>
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> but if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
  
Alejandro Lucero Oct. 30, 2018, 2:04 p.m. UTC | #31
On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero <
alejandro.lucero@netronome.com> wrote:

>
>
> On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
>> Some found on some our servers:
>>
>> If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
>> reboot to make it effective.
>>
>> 18.11 rc1: Success to setup testpmd  and secondary process.
>>
>>
>>
>> If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
>> reboot to make it effective.
>>
>> 18.11 rc1:  Fail to setup testpmd  and secondary process.
>>
>> 18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to
>> setup secondary process.
>>
>>
>>
>> Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
>>
>> Most of our team servers should enable the IOMMU for VT-d and vfio test.
>>
>>
>>
>
> It makes sense because the problem is when the IOVA mode is set inside
> drivers/bus/pci/linux/pci.c and if there is not IOMMU, not call to
> rte_eal_check_dma_mask at all.
>
>
>
>> Best regards,
>>
>> Xueqin
>>
>>
>>
>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>> *Sent:* Tuesday, October 30, 2018 6:38 PM
>> *To:* Lin, Xueqin <xueqin.lin@intel.com>
>> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
>> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
>> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
>> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
>> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
>> mask
>>
>>
>>
>>
>>
>> On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com>
>> wrote:
>>
>> Hi Lucero,
>>
>>
>>
>> No, we have reproduced multi-process issues(include symmetric_mp,
>> simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
>>
>> It is also strange that 1~2 servers don’t have the issue.
>>
>>
>>
>>
>>
>> Yes, you are right. I could execute it but it was due to how this problem
>> triggers.
>>
>> I think I can fix this and at the same time solving properly the initial
>> issue without any limitation like that potential race condition I
>> mentioned.
>>
>> I can give you a patch to try in a couple of hours.
>>
>>
>>
>
Hi Lin,

Can you try the patch attached?

Thanks


> Thanks
>>
>>
>>
>> Bind two NNT ports or FVL ports
>>
>>
>>
>> ./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4
>> --proc-id=1
>>
>>
>>
>> EAL: Detected 88 lcore(s)
>>
>> EAL: Detected 2 NUMA nodes
>>
>> EAL: Auto-detected process type: SECONDARY
>>
>> [New Thread 0x7ffff6eda700 (LWP 90103)]
>>
>> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
>>
>> [New Thread 0x7ffff66d9700 (LWP 90104)]
>>
>>
>>
>> Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
>>
>> 0x00000000005566b5 in rte_fbarray_find_next_used ()
>>
>> (gdb) bt
>>
>> #0  0x00000000005566b5 in rte_fbarray_find_next_used ()
>>
>> #1  0x000000000054da9c in rte_eal_check_dma_mask ()
>>
>> #2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
>>
>> #3  0x0000000000573988 in rte_pci_get_iommu_class ()
>>
>> #4  0x000000000054f743 in rte_bus_get_iommu_class ()
>>
>> #5  0x000000000053c123 in rte_eal_init ()
>>
>> #6  0x000000000046be2b in main ()
>>
>>
>>
>> Best regards,
>>
>> Xueqin
>>
>>
>>
>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>> *Sent:* Tuesday, October 30, 2018 5:41 PM
>> *To:* Lin, Xueqin <xueqin.lin@intel.com>
>> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
>> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
>> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
>> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
>> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
>> mask
>>
>>
>>
>>
>>
>> On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>>
>> Hi Lucero&Thomas,
>>
>>
>>
>> Find the patch can’t fix multi-process cases.
>>
>>
>>
>> Hi,
>>
>>
>>
>> I think it is not specifically about multiprocess but about hotplug with
>> multiprocess because I can execute the symmetric_mp successfully with a
>> secondary process.
>>
>>
>>
>> Working on this as a priority.
>>
>>
>>
>> Thanks.
>>
>>
>>
>> Steps:
>>
>> 1.       Setup primary process successfully
>>
>> ./hotplug_mp --proc-type=auto
>>
>>
>>
>> 2.       Fail to setup secondary process
>>
>> ./hotplug_mp --proc-type=auto
>>
>> EAL: Detected 88 lcore(s)
>>
>> EAL: Detected 2 NUMA nodes
>>
>> EAL: Auto-detected process type: SECONDARY
>>
>> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23
>>
>> Segmentation fault (core dumped)
>>
>>
>>
>> More information as below:
>>
>> Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.
>>
>> 0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)
>>
>>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>>
>> 264             for (idx = first; idx < msk->n_masks; idx++) {
>>
>> #0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0,
>> used=true)
>>
>>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>>
>> #1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0,
>> next=true,
>>
>>     used=true) at
>> /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001
>>
>> #2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4,
>> start=0)
>>
>>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018
>>
>> #3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401
>> <check_iova>,
>>
>>     arg=0x7fffffffcc38) at
>> /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589
>>
>> #4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')
>>
>>     at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465
>>
>> #5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)
>>
>>     at /root/dpdk/drivers/bus/pci/linux/pci.c:593
>>
>> #6  0x00000000005b9738 in pci_devices_iommu_support_va ()
>>
>>     at /root/dpdk/drivers/bus/pci/linux/pci.c:626
>>
>> #7  0x00000000005b97a7 in rte_pci_get_iommu_class ()
>>
>>     at /root/dpdk/drivers/bus/pci/linux/pci.c:650
>>
>> #8  0x000000000058f1ce in rte_bus_get_iommu_class ()
>>
>>     at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237
>>
>> #9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)
>>
>>     at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919
>>
>> #10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)
>>
>>     at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28
>>
>>
>>
>>
>>
>> Best regards,
>>
>> Xueqin
>>
>>
>>
>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>> *Sent:* Monday, October 29, 2018 9:41 PM
>> *To:* Yao, Lei A <lei.a.yao@intel.com>
>> *Cc:* Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu,
>> Qian Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>;
>> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
>> ferruh.yigit@intel.com>
>> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
>> mask
>>
>>
>>
>>
>>
>> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>>
>>
>>
>>
>>
>> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
>> *Sent:* Monday, October 29, 2018 8:56 PM
>> *To:* Thomas Monjalon <thomas@monjalon.net>
>> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
>> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
>> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
>> ferruh.yigit@intel.com>
>> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA
>> mask
>>
>>
>>
>>
>>
>> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
>> wrote:
>>
>> 29/10/2018 12:39, Alejandro Lucero:
>> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
>> > mask instead of the maskbits. However, this does not solves the
>> deadlock.
>>
>> The deadlock is a bigger concern I think.
>>
>>
>>
>> I think once the call to rte_eal_check_dma_mask uses the maskbits
>> instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the
>> deadlock.
>>
>>
>>
>> Yao, can you try with the attached patch?
>>
>>
>>
>> Hi, Lucero
>>
>>
>>
>> This patch can fix the issue at my side. Thanks a lot
>>
>> for you quick action.
>>
>>
>>
>>
>>
>> Great!
>>
>>
>>
>> I will send an official patch with the changes.
>>
>>
>>
>> I have to say that I tested the patchset, but I think it was where
>> legacy_mem was still there and therefore dynamic memory allocation code not
>> used during memory initialization.
>>
>>
>>
>> There is something that concerns me though. Using
>> rte_memseg_walk_thread_unsafe could be a problem under some situations
>> although those situations being unlikely.
>>
>>
>>
>> Usually, calling rte_eal_check_dma_mask happens during initialization.
>> Then it is safe to use the unsafe function for walking memsegs, but with
>> device hotplug and dynamic memory allocation, there exists a potential race
>> condition when the primary process is allocating more memory and
>> concurrently a device is hotplugged and a secondary process does the device
>> initialization. By now, this is just a problem with the NFP, and the
>> potential race condition window really unlikely, but I will work on this
>> asap.
>>
>>
>>
>> BRs
>>
>> Lei
>>
>>
>>
>> > Interestingly, the problem looks like a compiler one. Calling
>> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
>> but if
>> > you modify the call like this:
>> >
>> > -       if (rte_memseg_walk(check_iova, &mask))
>> > +       if (!rte_memseg_walk(check_iova, &mask))
>> >
>> > it works, although the value returned to the invoker changes, of course.
>> > But the point here is it should be the same behaviour when calling
>> > rte_memseg_walk than before and it is not.
>>
>> Anyway, the coding style requires to save the return value in a variable,
>> instead of nesting the call in an "if" condition.
>> And the "if" check should be explicitly != 0 because it is not a real
>> boolean.
>>
>> PS: please do not top post and avoid HTML emails, thanks
>>
>>
  
Anatoly Burakov Oct. 30, 2018, 2:14 p.m. UTC | #32
On 30-Oct-18 2:04 PM, Alejandro Lucero wrote:
> 
> 
> On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero 
> <alejandro.lucero@netronome.com <mailto:alejandro.lucero@netronome.com>> 
> wrote:
> 
> 
> 
>     On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com
>     <mailto:xueqin.lin@intel.com>> wrote:
> 
>         Some found on some our servers:____
> 
>         If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg
>         file, then reboot to make it effective.____
> 
>         18.11 rc1: Success to setup testpmd  and secondary process.____
> 
>         __ __
> 
>         If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file,
>         then reboot to make it effective.____
> 
>         18.11 rc1:  Fail to setup testpmd  and secondary process.____
> 
>         18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but
>         fail to setup secondary process.____
> 
>         __ __
> 
>         Maybe ”intel_iommu=on iommu=pt” enable or not result in our test
>         gap. ____
> 
>         Most of our team servers should enable the IOMMU for VT-d and
>         vfio test. ____
> 
>         __
> 
> 
>     It makes sense because the problem is when the IOVA mode is set
>     inside drivers/bus/pci/linux/pci.c and if there is not IOMMU, not
>     call to rte_eal_check_dma_mask at all.
> 
>         __
> 
>         Best regards,____
> 
>         Xueqin____
> 
>         __ __
> 
>         *From:*Alejandro Lucero [mailto:alejandro.lucero@netronome.com
>         <mailto:alejandro.lucero@netronome.com>]
>         *Sent:* Tuesday, October 30, 2018 6:38 PM
>         *To:* Lin, Xueqin <xueqin.lin@intel.com
>         <mailto:xueqin.lin@intel.com>>
>         *Cc:* Yao, Lei A <lei.a.yao@intel.com
>         <mailto:lei.a.yao@intel.com>>; Thomas Monjalon
>         <thomas@monjalon.net <mailto:thomas@monjalon.net>>; dev
>         <dev@dpdk.org <mailto:dev@dpdk.org>>; Xu, Qian Q
>         <qian.q.xu@intel.com <mailto:qian.q.xu@intel.com>>; Burakov,
>         Anatoly <anatoly.burakov@intel.com
>         <mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh
>         <ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>; Zhang,
>         Qi Z <qi.z.zhang@intel.com <mailto:qi.z.zhang@intel.com>>
>         *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based
>         on DMA mask____
> 
>         __ __
> 
>         __ __
> 
>         On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin
>         <xueqin.lin@intel.com <mailto:xueqin.lin@intel.com>> wrote:____
> 
>             Hi Lucero,____
> 
>             ____
> 
>             No, we have reproduced multi-process issues(include
>             symmetric_mp, simple_mp, hotplug_mp, multi-process unit
>             test… )on most of our servers. ____
> 
>             It is also strange that 1~2 servers don’t have the issue.____
> 
>             ____
> 
>         __ __
> 
>         Yes, you are right. I could execute it but it was due to how
>         this problem triggers. ____
> 
>         I think I can fix this and at the same time solving properly the
>         initial issue without any limitation like that potential race
>         condition I mentioned. ____
> 
>         I can give you a patch to try in a couple of hours. ____
> 
>         __
> 
> 
> Hi Lin,
> 
> Can you try the patch attached?
> 
> Thanks
> 
Hi Alejandro,

Attachments are not supported on the mailing list :)
  
Alejandro Lucero Oct. 30, 2018, 2:45 p.m. UTC | #33
On Tue, Oct 30, 2018 at 2:14 PM Burakov, Anatoly <anatoly.burakov@intel.com>
wrote:

> On 30-Oct-18 2:04 PM, Alejandro Lucero wrote:
> >
> >
> > On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero
> > <alejandro.lucero@netronome.com <mailto:alejandro.lucero@netronome.com>>
>
> > wrote:
> >
> >
> >
> >     On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com
> >     <mailto:xueqin.lin@intel.com>> wrote:
> >
> >         Some found on some our servers:____
> >
> >         If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg
> >         file, then reboot to make it effective.____
> >
> >         18.11 rc1: Success to setup testpmd  and secondary process.____
> >
> >         __ __
> >
> >         If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file,
> >         then reboot to make it effective.____
> >
> >         18.11 rc1:  Fail to setup testpmd  and secondary process.____
> >
> >         18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but
> >         fail to setup secondary process.____
> >
> >         __ __
> >
> >         Maybe ”intel_iommu=on iommu=pt” enable or not result in our test
> >         gap. ____
> >
> >         Most of our team servers should enable the IOMMU for VT-d and
> >         vfio test. ____
> >
> >         __
> >
> >
> >     It makes sense because the problem is when the IOVA mode is set
> >     inside drivers/bus/pci/linux/pci.c and if there is not IOMMU, not
> >     call to rte_eal_check_dma_mask at all.
> >
> >         __
> >
> >         Best regards,____
> >
> >         Xueqin____
> >
> >         __ __
> >
> >         *From:*Alejandro Lucero [mailto:alejandro.lucero@netronome.com
> >         <mailto:alejandro.lucero@netronome.com>]
> >         *Sent:* Tuesday, October 30, 2018 6:38 PM
> >         *To:* Lin, Xueqin <xueqin.lin@intel.com
> >         <mailto:xueqin.lin@intel.com>>
> >         *Cc:* Yao, Lei A <lei.a.yao@intel.com
> >         <mailto:lei.a.yao@intel.com>>; Thomas Monjalon
> >         <thomas@monjalon.net <mailto:thomas@monjalon.net>>; dev
> >         <dev@dpdk.org <mailto:dev@dpdk.org>>; Xu, Qian Q
> >         <qian.q.xu@intel.com <mailto:qian.q.xu@intel.com>>; Burakov,
> >         Anatoly <anatoly.burakov@intel.com
> >         <mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh
> >         <ferruh.yigit@intel.com <mailto:ferruh.yigit@intel.com>>; Zhang,
> >         Qi Z <qi.z.zhang@intel.com <mailto:qi.z.zhang@intel.com>>
> >         *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based
> >         on DMA mask____
> >
> >         __ __
> >
> >         __ __
> >
> >         On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin
> >         <xueqin.lin@intel.com <mailto:xueqin.lin@intel.com>> wrote:____
> >
> >             Hi Lucero,____
> >
> >             ____
> >
> >             No, we have reproduced multi-process issues(include
> >             symmetric_mp, simple_mp, hotplug_mp, multi-process unit
> >             test… )on most of our servers. ____
> >
> >             It is also strange that 1~2 servers don’t have the issue.____
> >
> >             ____
> >
> >         __ __
> >
> >         Yes, you are right. I could execute it but it was due to how
> >         this problem triggers. ____
> >
> >         I think I can fix this and at the same time solving properly the
> >         initial issue without any limitation like that potential race
> >         condition I mentioned. ____
> >
> >         I can give you a patch to try in a couple of hours. ____
> >
> >         __
> >
> >
> > Hi Lin,
> >
> > Can you try the patch attached?
> >
> > Thanks
> >
> Hi Alejandro,
>
> Attachments are not supported on the mailing list :)
>

Apologies. I should have sent it just to Lin.


>
> --
> Thanks,
> Anatoly
>
  
Lin, Xueqin Oct. 30, 2018, 2:45 p.m. UTC | #34
Hi Lucero,

The patch could fix both testpmd  and multi-process can’t setup issues on my environment.
Hope that you could upload fix patch to patches page in community.
Thanks a lot.

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Tuesday, October 30, 2018 10:05 PM
To: Lin, Xueqin <xueqin.lin@intel.com>
Cc: Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero <alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>> wrote:

On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Some found on some our servers:
If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1: Success to setup testpmd  and secondary process.

If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1:  Fail to setup testpmd  and secondary process.
18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to setup secondary process.

Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
Most of our team servers should enable the IOMMU for VT-d and vfio test.


It makes sense because the problem is when the IOVA mode is set inside drivers/bus/pci/linux/pci.c and if there is not IOMMU, not call to rte_eal_check_dma_mask at all.


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 6:38 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero,

No, we have reproduced multi-process issues(include symmetric_mp, simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
It is also strange that 1~2 servers don’t have the issue.


Yes, you are right. I could execute it but it was due to how this problem triggers.
I think I can fix this and at the same time solving properly the initial issue without any limitation like that potential race condition I mentioned.
I can give you a patch to try in a couple of hours.


Hi Lin,

Can you try the patch attached?

Thanks

Thanks

Bind two NNT ports or FVL ports

./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4 --proc-id=1

EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Auto-detected process type: SECONDARY
[New Thread 0x7ffff6eda700 (LWP 90103)]
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
[New Thread 0x7ffff66d9700 (LWP 90104)]

Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
0x00000000005566b5 in rte_fbarray_find_next_used ()
(gdb) bt
#0  0x00000000005566b5 in rte_fbarray_find_next_used ()
#1  0x000000000054da9c in rte_eal_check_dma_mask ()
#2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
#3  0x0000000000573988 in rte_pci_get_iommu_class ()
#4  0x000000000054f743 in rte_bus_get_iommu_class ()
#5  0x000000000053c123 in rte_eal_init ()
#6  0x000000000046be2b in main ()

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 5:41 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero&Thomas,

Find the patch can’t fix multi-process cases.

Hi,

I think it is not specifically about multiprocess but about hotplug with multiprocess because I can execute the symmetric_mp successfully with a secondary process.

Working on this as a priority.

Thanks.

Steps:

1.       Setup primary process successfully

./hotplug_mp --proc-type=auto



2.       Fail to setup secondary process

./hotplug_mp --proc-type=auto

EAL: Detected 88 lcore(s)

EAL: Detected 2 NUMA nodes

EAL: Auto-detected process type: SECONDARY

EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23

Segmentation fault (core dumped)


More information as below:

Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.

0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

264             for (idx = first; idx < msk->n_masks; idx++) {

#0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

#1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0, next=true,

    used=true) at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001

#2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4, start=0)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018

#3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401 <check_iova>,

    arg=0x7fffffffcc38) at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589

#4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')

    at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465

#5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)

    at /root/dpdk/drivers/bus/pci/linux/pci.c:593

#6  0x00000000005b9738 in pci_devices_iommu_support_va ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:626

#7  0x00000000005b97a7 in rte_pci_get_iommu_class ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:650

#8  0x000000000058f1ce in rte_bus_get_iommu_class ()

    at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237

#9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919

#10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 9:41 PM
To: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>
Cc: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>> wrote:


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.


Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where legacy_mem was still there and therefore dynamic memory allocation code not used during memory initialization.

There is something that concerns me though. Using rte_memseg_walk_thread_unsafe could be a problem under some situations although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then it is safe to use the unsafe function for walking memsegs, but with device hotplug and dynamic memory allocation, there exists a potential race condition when the primary process is allocating more memory and concurrently a device is hotplugged and a secondary process does the device initialization. By now, this is just a problem with the NFP, and the potential race condition window really unlikely, but I will work on this asap.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks
  
Alejandro Lucero Oct. 30, 2018, 2:57 p.m. UTC | #35
On Tue, Oct 30, 2018 at 2:45 PM Lin, Xueqin <xueqin.lin@intel.com> wrote:

> Hi Lucero,
>
>
>
> The patch could fix both testpmd  and multi-process can’t setup issues on
> my environment.
>
> Hope that you could upload fix patch to patches page in community.
>
> Thanks a lot.
>
>
>

Great.

I need to format the patchset properly and clean things up but I hope I can
send a patchset this week.

Thanks for testing!

By the way, is this testing something you are doing by yourself or it is
part of Intel DPDK work?



> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 10:05 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero <
> alejandro.lucero@netronome.com> wrote:
>
>
>
> On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Some found on some our servers:
>
> If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
> reboot to make it effective.
>
> 18.11 rc1: Success to setup testpmd  and secondary process.
>
>
>
> If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then
> reboot to make it effective.
>
> 18.11 rc1:  Fail to setup testpmd  and secondary process.
>
> 18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to setup
> secondary process.
>
>
>
> Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
>
> Most of our team servers should enable the IOMMU for VT-d and vfio test.
>
>
>
>
>
> It makes sense because the problem is when the IOVA mode is set inside
> drivers/bus/pci/linux/pci.c and if there is not IOMMU, not call to
> rte_eal_check_dma_mask at all.
>
>
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 6:38 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Hi Lucero,
>
>
>
> No, we have reproduced multi-process issues(include symmetric_mp,
> simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
>
> It is also strange that 1~2 servers don’t have the issue.
>
>
>
>
>
> Yes, you are right. I could execute it but it was due to how this problem
> triggers.
>
> I think I can fix this and at the same time solving properly the initial
> issue without any limitation like that potential race condition I
> mentioned.
>
> I can give you a patch to try in a couple of hours.
>
>
>
>
>
> Hi Lin,
>
>
>
> Can you try the patch attached?
>
>
>
> Thanks
>
>
>
> Thanks
>
>
>
> Bind two NNT ports or FVL ports
>
>
>
> ./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4
> --proc-id=1
>
>
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> [New Thread 0x7ffff6eda700 (LWP 90103)]
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
>
> [New Thread 0x7ffff66d9700 (LWP 90104)]
>
>
>
> Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> (gdb) bt
>
> #0  0x00000000005566b5 in rte_fbarray_find_next_used ()
>
> #1  0x000000000054da9c in rte_eal_check_dma_mask ()
>
> #2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
>
> #3  0x0000000000573988 in rte_pci_get_iommu_class ()
>
> #4  0x000000000054f743 in rte_bus_get_iommu_class ()
>
> #5  0x000000000053c123 in rte_eal_init ()
>
> #6  0x000000000046be2b in main ()
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Tuesday, October 30, 2018 5:41 PM
> *To:* Lin, Xueqin <xueqin.lin@intel.com>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <
> thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>;
> Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <
> ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com> wrote:
>
> Hi Lucero&Thomas,
>
>
>
> Find the patch can’t fix multi-process cases.
>
>
>
> Hi,
>
>
>
> I think it is not specifically about multiprocess but about hotplug with
> multiprocess because I can execute the symmetric_mp successfully with a
> secondary process.
>
>
>
> Working on this as a priority.
>
>
>
> Thanks.
>
>
>
> Steps:
>
> 1.       Setup primary process successfully
>
> ./hotplug_mp --proc-type=auto
>
>
>
> 2.       Fail to setup secondary process
>
> ./hotplug_mp --proc-type=auto
>
> EAL: Detected 88 lcore(s)
>
> EAL: Detected 2 NUMA nodes
>
> EAL: Auto-detected process type: SECONDARY
>
> EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23
>
> Segmentation fault (core dumped)
>
>
>
> More information as below:
>
> Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.
>
> 0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> 264             for (idx = first; idx < msk->n_masks; idx++) {
>
> #0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0,
> used=true)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264
>
> #1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0,
> next=true,
>
>     used=true) at
> /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001
>
> #2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4,
> start=0)
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018
>
> #3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401
> <check_iova>,
>
>     arg=0x7fffffffcc38) at
> /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589
>
> #4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465
>
> #5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:593
>
> #6  0x00000000005b9738 in pci_devices_iommu_support_va ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:626
>
> #7  0x00000000005b97a7 in rte_pci_get_iommu_class ()
>
>     at /root/dpdk/drivers/bus/pci/linux/pci.c:650
>
> #8  0x000000000058f1ce in rte_bus_get_iommu_class ()
>
>     at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237
>
> #9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919
>
> #10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)
>
>     at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28
>
>
>
>
>
> Best regards,
>
> Xueqin
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 9:41 PM
> *To:* Yao, Lei A <lei.a.yao@intel.com>
> *Cc:* Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian
> Q <qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com> wrote:
>
>
>
>
>
> *From:* Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
> *Sent:* Monday, October 29, 2018 8:56 PM
> *To:* Thomas Monjalon <thomas@monjalon.net>
> *Cc:* Yao, Lei A <lei.a.yao@intel.com>; dev <dev@dpdk.org>; Xu, Qian Q <
> qian.q.xu@intel.com>; Lin, Xueqin <xueqin.lin@intel.com>; Burakov,
> Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com
> >
> *Subject:* Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask
>
>
>
>
>
> On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
> 29/10/2018 12:39, Alejandro Lucero:
> > I got a patch that solves a bug when calling rte_eal_dma_mask using the
> > mask instead of the maskbits. However, this does not solves the
> deadlock.
>
> The deadlock is a bigger concern I think.
>
>
>
> I think once the call to rte_eal_check_dma_mask uses the maskbits instead
> of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.
>
>
>
> Yao, can you try with the attached patch?
>
>
>
> Hi, Lucero
>
>
>
> This patch can fix the issue at my side. Thanks a lot
>
> for you quick action.
>
>
>
>
>
> Great!
>
>
>
> I will send an official patch with the changes.
>
>
>
> I have to say that I tested the patchset, but I think it was where
> legacy_mem was still there and therefore dynamic memory allocation code not
> used during memory initialization.
>
>
>
> There is something that concerns me though. Using
> rte_memseg_walk_thread_unsafe could be a problem under some situations
> although those situations being unlikely.
>
>
>
> Usually, calling rte_eal_check_dma_mask happens during initialization.
> Then it is safe to use the unsafe function for walking memsegs, but with
> device hotplug and dynamic memory allocation, there exists a potential race
> condition when the primary process is allocating more memory and
> concurrently a device is hotplugged and a secondary process does the device
> initialization. By now, this is just a problem with the NFP, and the
> potential race condition window really unlikely, but I will work on this
> asap.
>
>
>
> BRs
>
> Lei
>
>
>
> > Interestingly, the problem looks like a compiler one. Calling
> > rte_memseg_walk does not return when calling inside rt_eal_dma_mask,
> but if
> > you modify the call like this:
> >
> > -       if (rte_memseg_walk(check_iova, &mask))
> > +       if (!rte_memseg_walk(check_iova, &mask))
> >
> > it works, although the value returned to the invoker changes, of course.
> > But the point here is it should be the same behaviour when calling
> > rte_memseg_walk than before and it is not.
>
> Anyway, the coding style requires to save the return value in a variable,
> instead of nesting the call in an "if" condition.
> And the "if" check should be explicitly != 0 because it is not a real
> boolean.
>
> PS: please do not top post and avoid HTML emails, thanks
>
>
  
Lin, Xueqin Oct. 30, 2018, 3:09 p.m. UTC | #36
Hi Lucero,

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com]
Sent: Tuesday, October 30, 2018 10:57 PM
To: Lin, Xueqin <xueqin.lin@intel.com>
Cc: Yao, Lei A <lei.a.yao@intel.com>; Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>; Xu, Qian Q <qian.q.xu@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; Yigit, Ferruh <ferruh.yigit@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 2:45 PM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero,

The patch could fix both testpmd  and multi-process can’t setup issues on my environment.
Hope that you could upload fix patch to patches page in community.
Thanks a lot.


Great.

I need to format the patchset properly and clean things up but I hope I can send a patchset this week.

Thanks for testing!

By the way, is this testing something you are doing by yourself or it is part of Intel DPDK work?


We are from Intel DPDK validation team☺
It is 18.11 rc1 cycle, the issue block most of our cases can’t continue, include NIC, NIC VF, vhost/virtio, sample…
It is very urgent for us to check DPDK QA in very limit time.
Hope you could send fix patch officially soon, then merge to master branch after review.
Thanks.
Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 10:05 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 12:37 PM Alejandro Lucero <alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>> wrote:

On Tue, Oct 30, 2018 at 12:22 PM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Some found on some our servers:
If  not add ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1: Success to setup testpmd  and secondary process.

If  add  ”intel_iommu=on iommu=pt” in /boot/grub2/grub.cfg file, then reboot to make it effective.
18.11 rc1:  Fail to setup testpmd  and secondary process.
18.11 rc1+ dma_mask_fix patch: success to setup testpmd, but fail to setup secondary process.

Maybe ”intel_iommu=on iommu=pt” enable or not result in our test gap.
Most of our team servers should enable the IOMMU for VT-d and vfio test.


It makes sense because the problem is when the IOVA mode is set inside drivers/bus/pci/linux/pci.c and if there is not IOMMU, not call to rte_eal_check_dma_mask at all.


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 6:38 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 10:34 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero,

No, we have reproduced multi-process issues(include symmetric_mp, simple_mp, hotplug_mp, multi-process unit test… )on most of our servers.
It is also strange that 1~2 servers don’t have the issue.


Yes, you are right. I could execute it but it was due to how this problem triggers.
I think I can fix this and at the same time solving properly the initial issue without any limitation like that potential race condition I mentioned.
I can give you a patch to try in a couple of hours.


Hi Lin,

Can you try the patch attached?

Thanks

Thanks

Bind two NNT ports or FVL ports

./build/symmetric_mp -c 4 --proc-type=auto -- -p 3 --num-procs=4 --proc-id=1

EAL: Detected 88 lcore(s)
EAL: Detected 2 NUMA nodes
EAL: Auto-detected process type: SECONDARY
[New Thread 0x7ffff6eda700 (LWP 90103)]
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_90099_2f1b553882b62
[New Thread 0x7ffff66d9700 (LWP 90104)]

Thread 1 "symmetric_mp" received signal SIGSEGV, Segmentation fault.
0x00000000005566b5 in rte_fbarray_find_next_used ()
(gdb) bt
#0  0x00000000005566b5 in rte_fbarray_find_next_used ()
#1  0x000000000054da9c in rte_eal_check_dma_mask ()
#2  0x0000000000572ae7 in pci_one_device_iommu_support_va ()
#3  0x0000000000573988 in rte_pci_get_iommu_class ()
#4  0x000000000054f743 in rte_bus_get_iommu_class ()
#5  0x000000000053c123 in rte_eal_init ()
#6  0x000000000046be2b in main ()

Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Tuesday, October 30, 2018 5:41 PM
To: Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>; Zhang, Qi Z <qi.z.zhang@intel.com<mailto:qi.z.zhang@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Tue, Oct 30, 2018 at 3:20 AM Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>> wrote:
Hi Lucero&Thomas,

Find the patch can’t fix multi-process cases.

Hi,

I think it is not specifically about multiprocess but about hotplug with multiprocess because I can execute the symmetric_mp successfully with a secondary process.

Working on this as a priority.

Thanks.

Steps:

1.       Setup primary process successfully

./hotplug_mp --proc-type=auto



2.       Fail to setup secondary process

./hotplug_mp --proc-type=auto

EAL: Detected 88 lcore(s)

EAL: Detected 2 NUMA nodes

EAL: Auto-detected process type: SECONDARY

EAL: Multi-process socket /var/run/dpdk/rte/mp_socket_147212_2bfe08ee88d23

Segmentation fault (core dumped)


More information as below:

Thread 1 "hotplug_mp" received signal SIGSEGV, Segmentation fault.

0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

264             for (idx = first; idx < msk->n_masks; idx++) {

#0  0x0000000000597cfb in find_next (arr=0x7ffff7ff20a4, start=0, used=true)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:264

#1  0x0000000000598573 in fbarray_find (arr=0x7ffff7ff20a4, start=0, next=true,

    used=true) at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1001

#2  0x000000000059929b in rte_fbarray_find_next_used (arr=0x7ffff7ff20a4, start=0)

    at /root/dpdk/lib/librte_eal/common/eal_common_fbarray.c:1018

#3  0x000000000058c877 in rte_memseg_walk_thread_unsafe (func=0x58c401 <check_iova>,

    arg=0x7fffffffcc38) at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:589

#4  0x000000000058ce08 in rte_eal_check_dma_mask (maskbits=48 '0')

    at /root/dpdk/lib/librte_eal/common/eal_common_memory.c:465

#5  0x00000000005b96c4 in pci_one_device_iommu_support_va (dev=0x11b3d90)

    at /root/dpdk/drivers/bus/pci/linux/pci.c:593

#6  0x00000000005b9738 in pci_devices_iommu_support_va ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:626

#7  0x00000000005b97a7 in rte_pci_get_iommu_class ()

    at /root/dpdk/drivers/bus/pci/linux/pci.c:650

#8  0x000000000058f1ce in rte_bus_get_iommu_class ()

    at /root/dpdk/lib/librte_eal/common/eal_common_bus.c:237

#9  0x0000000000577c7a in rte_eal_init (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/lib/librte_eal/linuxapp/eal/eal.c:919

#10 0x000000000045dd56 in main (argc=2, argv=0x7fffffffdf98)

    at /root/dpdk/examples/multi_process/hotplug_mp/main.c:28


Best regards,
Xueqin

From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 9:41 PM
To: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>
Cc: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 1:18 PM Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>> wrote:


From: Alejandro Lucero [mailto:alejandro.lucero@netronome.com<mailto:alejandro.lucero@netronome.com>]
Sent: Monday, October 29, 2018 8:56 PM
To: Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>>
Cc: Yao, Lei A <lei.a.yao@intel.com<mailto:lei.a.yao@intel.com>>; dev <dev@dpdk.org<mailto:dev@dpdk.org>>; Xu, Qian Q <qian.q.xu@intel.com<mailto:qian.q.xu@intel.com>>; Lin, Xueqin <xueqin.lin@intel.com<mailto:xueqin.lin@intel.com>>; Burakov, Anatoly <anatoly.burakov@intel.com<mailto:anatoly.burakov@intel.com>>; Yigit, Ferruh <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH v3 0/6] use IOVAs check based on DMA mask


On Mon, Oct 29, 2018 at 11:46 AM Thomas Monjalon <thomas@monjalon.net<mailto:thomas@monjalon.net>> wrote:
29/10/2018 12:39, Alejandro Lucero:
> I got a patch that solves a bug when calling rte_eal_dma_mask using the
> mask instead of the maskbits. However, this does not solves the deadlock.

The deadlock is a bigger concern I think.

I think once the call to rte_eal_check_dma_mask uses the maskbits instead of the mask, calling rte_memseg_walk_thread_unsafe avoids the deadlock.

Yao, can you try with the attached patch?

Hi, Lucero

This patch can fix the issue at my side. Thanks a lot
for you quick action.


Great!

I will send an official patch with the changes.

I have to say that I tested the patchset, but I think it was where legacy_mem was still there and therefore dynamic memory allocation code not used during memory initialization.

There is something that concerns me though. Using rte_memseg_walk_thread_unsafe could be a problem under some situations although those situations being unlikely.

Usually, calling rte_eal_check_dma_mask happens during initialization. Then it is safe to use the unsafe function for walking memsegs, but with device hotplug and dynamic memory allocation, there exists a potential race condition when the primary process is allocating more memory and concurrently a device is hotplugged and a secondary process does the device initialization. By now, this is just a problem with the NFP, and the potential race condition window really unlikely, but I will work on this asap.

BRs
Lei

> Interestingly, the problem looks like a compiler one. Calling
> rte_memseg_walk does not return when calling inside rt_eal_dma_mask, but if
> you modify the call like this:
>
> -       if (rte_memseg_walk(check_iova, &mask))
> +       if (!rte_memseg_walk(check_iova, &mask))
>
> it works, although the value returned to the invoker changes, of course.
> But the point here is it should be the same behaviour when calling
> rte_memseg_walk than before and it is not.

Anyway, the coding style requires to save the return value in a variable,
instead of nesting the call in an "if" condition.
And the "if" check should be explicitly != 0 because it is not a real boolean.

PS: please do not top post and avoid HTML emails, thanks