Skip to contentSkip to conversation

eal/freebsd: lock memory device to prevent conflicts

PATCH Applied Bruce Richardson 5 participants 9 messages Sep 13, 2021 – Oct 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/freebsd: lock memory device to prevent conflicts

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")
---
 lib/eal/freebsd/eal_hugepage_info.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/eal/freebsd/eal_hugepage_info.c +4 -0
index 408f054f7a..4a8d87c23e 100644
@@ -90,6 +90,10 @@ eal_hugepage_info_init(void)
 		RTE_LOG(ERR, EAL, "could not open "CONTIGMEM_DEV"\n");
 		return -1;
 	}
+	if (flock(fd, LOCK_EX) < 0) {
+		RTE_LOG(ERR, EAL, "could not lock memory. Is another DPDK process running?\n");
+		return -1;
+	}
 
 	if (buffer_size >= 1<<30)
 		RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dGB\n",
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Bruce Richardson

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")
---
  lib/eal/freebsd/eal_hugepage_info.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/eal/freebsd/eal_hugepage_info.c +0 -0
index 408f054f7a..4a8d87c23e 100644

lib/eal/freebsd/eal_hugepage_info.c eal_hugepage_info_init(void) · line 99

Quoted 10 lines
lib/eal/freebsd/eal_hugepage_info.c +4 -0
@@ -90,6 +90,10 @@ eal_hugepage_info_init(void)
  		RTE_LOG(ERR, EAL, "could not open "CONTIGMEM_DEV"\n");
  		return -1;
  	}
+	if (flock(fd, LOCK_EX) < 0) {
+		RTE_LOG(ERR, EAL, "could not lock memory. Is another DPDK process running?\n");
+		return -1;
+	}
 
  	if (buffer_size >= 1<<30)
  		RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dGB\n",

This only gets triggered when regular init path is chosen, i.e. --no-huge still works. I'm a bit uneasy with --in-memory mode pretending to work on FreeBSD and Windows, but that's a separate problem :) As far as the patch goes, the problem it addresses does get fixed.

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw
Quoted 25 lines · Anatoly
Quoted 24 lines · Bruce Richardson

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")
---
  lib/eal/freebsd/eal_hugepage_info.c | 4 ++++
  1 file changed, 4 insertions(+)
lib/eal/freebsd/eal_hugepage_info.c +2 -0
index 408f054f7a..4a8d87c23e 100644
@@ -90,6 +90,10 @@ eal_hugepage_info_init(void)
  		RTE_LOG(ERR, EAL, "could not open "CONTIGMEM_DEV"\n");
  		return -1;
  	}
+	if (flock(fd, LOCK_EX) < 0) {
+		RTE_LOG(ERR, EAL, "could not lock memory. Is another DPDK process running?\n");
Quoted 8 lines

lib/eal/freebsd/eal_hugepage_info.c eal_hugepage_info_init(void)

Quoted 5 lines
lib/eal/freebsd/eal_hugepage_info.c +2 -0
+		return -1;
+	}
  	if (buffer_size >= 1<<30)
  		RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dGB\n",
 

This only gets triggered when regular init path is chosen, i.e. --no-huge still works.

Yes, but that is ok, I think, since no-huge doesn't use these resources or suffer from this problem. On the other hand, except for running unit tests, no-huge mode is pretty useless on FreeBSD as we don't have any vfio-equivalent support, so all HW access has to use physical addresses which can only be got using contigmem.

Quoted 2 lines

I'm a bit uneasy with --in-memory mode pretending to work on FreeBSD and Windows, but that's a separate problem :)

Yes, it is, though one that does belong is the same area as this one. The "fix" is probably to just print a warning when --in-memory is used, informing the user that the flag is ignored and then continue. Alternatively we can error out, but I think the warn+continue is better, myself.

Quoted 5 lines

As far as the patch
goes, the problem it addresses does get fixed.

Thanks.

/Bruce

#3 lore raw
Quoted 35 lines · Bruce Richardson
Quoted 25 lines · Anatoly
Quoted 24 lines · Bruce Richardson

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")
---
   lib/eal/freebsd/eal_hugepage_info.c | 4 ++++
   1 file changed, 4 insertions(+)
lib/eal/freebsd/eal_hugepage_info.c +2 -0
index 408f054f7a..4a8d87c23e 100644
@@ -90,6 +90,10 @@ eal_hugepage_info_init(void)
   		RTE_LOG(ERR, EAL, "could not open "CONTIGMEM_DEV"\n");
   		return -1;
   	}
+	if (flock(fd, LOCK_EX) < 0) {
+		RTE_LOG(ERR, EAL, "could not lock memory. Is another DPDK process running?\n");
Quoted 8 lines

lib/eal/freebsd/eal_hugepage_info.c eal_hugepage_info_init(void)

Quoted 5 lines
lib/eal/freebsd/eal_hugepage_info.c +2 -0
+		return -1;
+	}
   	if (buffer_size >= 1<<30)
   		RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dGB\n",
 

This only gets triggered when regular init path is chosen, i.e. --no-huge still works.

Quoted 5 lines

Yes, but that is ok, I think, since no-huge doesn't use these resources or suffer from this problem. On the other hand, except for running unit tests, no-huge mode is pretty useless on FreeBSD as we don't have any vfio-equivalent support, so all HW access has to use physical addresses which can only be got using contigmem.

What i meant to say was, i've checked this against '--no-huge' which *should* still work with this patch, and it does :) So, the phrasing was unfortunate, but we agree!

Quoted 9 lines
Quoted 3 lines

I'm a bit uneasy with --in-memory mode pretending to work on FreeBSD and Windows, but that's a separate problem :)

Yes, it is, though one that does belong is the same area as this one. The "fix" is probably to just print a warning when --in-memory is used, informing the user that the flag is ignored and then continue. Alternatively we can error out, but I think the warn+continue is better, myself.

I think erroring out is better. The feature is intended to work a certain way, so if we can't guarantee that it does, we can't pretend it is "supported" or "is working". But again, irrelevant to this patch :)

Quoted 10 lines
Quoted 6 lines

As far as the patch
goes, the problem it addresses does get fixed.

Thanks.

/Bruce

Signature · 2 lines
Thanks,
Anatoly
#4 lore raw
Quoted 9 lines · Anatoly
Quoted 8 lines
Quoted 2 lines

I'm a bit uneasy with --in-memory mode pretending to work on FreeBSD and Windows, but that's a separate problem :)

Yes, it is, though one that does belong is the same area as this one. The "fix" is probably to just print a warning when --in-memory is used, informing the user that the flag is ignored and then continue. Alternatively we can error out, but I think the warn+continue is better, myself.

Quoted 4 lines

I think erroring out is better. The feature is intended to work a certain way, so if we can't guarantee that it does, we can't pretend it is "supported" or "is working". But again, irrelevant to this patch :)

Please, can you review
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/
?
Thanks.

Signature · 1 line
David Marchand
#5 lore raw
In reply to Burakov, Anatoly

2021-09-13 14:14 (UTC+0100), Burakov, Anatoly:

Quoted 3 lines

[...]
I'm a bit uneasy with --in-memory mode pretending
to work on FreeBSD and Windows, but that's a separate problem :)

On Windows, --in-memory does not pretend to work, just the opposite, it is enabled implicitly as it's the only working mode.

#6 lore raw
In reply to Burakov, Anatoly
Quoted 7 lines · Anatoly
Quoted 6 lines · Bruce Richardson

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Quoted 5 lines
Quoted 4 lines
Fixes 764bf26873b9 ("add FreeBSD support")

Applied, thanks.

Signature · 1 line
David Marchand
#7 lore raw

PATCH v2 1/1 eal/freebsd: lock memory device to prevent conflicts

In reply to Bruce Richardson

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")

---

V2: Adding missing LOCK_NB flag to make sure the process doesn't sit
waiting for the lock to be released

 lib/eal/freebsd/eal_hugepage_info.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/eal/freebsd/eal_hugepage_info.c +4 -0
index 408f054f7a..9dbe375bd3 100644
@@ -90,6 +90,10 @@ eal_hugepage_info_init(void)
 		RTE_LOG(ERR, EAL, "could not open "CONTIGMEM_DEV"\n");
 		return -1;
 	}
+	if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
+		RTE_LOG(ERR, EAL, "could not lock memory. Is another DPDK process running?\n");
+		return -1;
+	}
 
 	if (buffer_size >= 1<<30)
 		RTE_LOG(INFO, EAL, "Contigmem driver has %d buffers, each of size %dGB\n",

--
2.30.2

#8 lore raw

13/09/2021 16:08, Bruce Richardson:

Quoted 11 lines

Only a single DPDK process on the system can be using the /dev/contigmem mappings at a time, but this was never explicitly enforced, e.g. when using --in-memory flag on two processes. To prevent possible conflict issues, we lock the dev node when it's in use, preventing other DPDK processes from starting up and causing problems for us.

Fixes 764bf26873b9 ("add FreeBSD support")

Looks to be applied by David.