Skip to contentSkip to conversation

eal/linux: fix VFIO hotplug with multiprocess

PATCH In review David Marchand 3 participants 8 messages Sep 16, 2024 – Oct 14, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 eal/linux: fix VFIO hotplug with multiprocess

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

---
 lib/eal/linux/eal.c      | 18 +-----------------
 lib/eal/linux/eal_vfio.c |  9 ++++++---
 2 files changed, 7 insertions(+), 20 deletions(-)
lib/eal/linux/eal.c +1 -17
index d742cc98e2..54577b7718 100644
@@ -867,16 +867,6 @@ rte_eal_iopl_init(void)
 	return 0;
 }
 
-#ifdef VFIO_PRESENT
-static int rte_eal_vfio_setup(void)
-{
-	if (rte_vfio_enable("vfio"))
-		return -1;
-
-	return 0;
-}
-#endif
-
 static void rte_eal_init_alert(const char *msg)
 {
 	fprintf(stderr, "EAL: FATAL: %s\n", msg);
@@ -1162,7 +1152,7 @@ rte_eal_init(int argc, char **argv)
 	}
 
 #ifdef VFIO_PRESENT
-	if (rte_eal_vfio_setup() < 0) {
+	if (rte_vfio_enable("vfio")) {
 		rte_eal_init_alert("Cannot init VFIO");
 		rte_errno = EAGAIN;
 		rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed);
@@ -1291,12 +1281,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-#ifdef VFIO_PRESENT
-	/* Register mp action after probe() so that we got enough info */
-	if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
-		return -1;
-#endif
-
 	/* initialize default service/lcore mappings and start running. Ignore
 	 * -ENOTSUP, as it indicates no service coremask passed to EAL.
 	 */
lib/eal/linux/eal_vfio.c +6 -3
index 4e69e72e3b..7132e24cba 100644
@@ -1120,9 +1120,12 @@ rte_vfio_enable(const char *modname)
 	}
 
 	if (internal_conf->process_type == RTE_PROC_PRIMARY) {
-		/* open a new container */
-		default_vfio_cfg->vfio_container_fd =
-				rte_vfio_get_container_fd();
+		if (vfio_mp_sync_setup() == -1) {
+			default_vfio_cfg->vfio_container_fd = -1;
+		} else {
+			/* open a new container */
+			default_vfio_cfg->vfio_container_fd = rte_vfio_get_container_fd();
+		}
 	} else {
 		/* get the default container from the primary process */
 		default_vfio_cfg->vfio_container_fd =
Signature · 1 line
2.46.0
#1 lore raw

PATCH 2/2 bus/pci: enhance hotplug for VFIO bound devices

VFIO modules may get loaded/initialized after DPDK initialized (like when starting an application without knowing which devices will be used, and whether their drivers require VFIO).

Retry enabling VFIO if not available.
This way, it is not required to restart the DPDK application anymore.

---
 drivers/bus/pci/linux/pci_vfio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci_vfio.c +7 -1
index adc34a5c51..5317170231 100644
@@ -1319,6 +1319,12 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,
 int
 pci_vfio_is_enabled(void)
 {
-	return rte_vfio_is_enabled("vfio_pci");
+	int status = rte_vfio_is_enabled("vfio_pci");
+
+	if (!status) {
+		rte_vfio_enable("vfio");
+		status = rte_vfio_is_enabled("vfio_pci");
+	}
+	return status;
 }
 #endif
Signature · 1 line
2.46.0
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] bus/pci: enhance hotplug for VFIO bound devices

Quoted 20 lines · David Marchand

VFIO modules may get loaded/initialized after DPDK initialized (like when starting an application without knowing which devices will be used, and whether their drivers require VFIO).

Retry enabling VFIO if not available.
This way, it is not required to restart the DPDK application anymore.

---
  drivers/bus/pci/linux/pci_vfio.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci_vfio.c +0 -0
index adc34a5c51..5317170231 100644
@@ -1319,6 +1319,12 @@ pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar,
  int
  pci_vfio_is_enabled(void)
  {

drivers/bus/pci/linux/pci_vfio.c pci_vfio_mmio_write(const struct rte_pci_device *dev, int bar, · line 1330

Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c +7 -1
-	return rte_vfio_is_enabled("vfio_pci");
+	int status = rte_vfio_is_enabled("vfio_pci");
+
+	if (!status) {
+		rte_vfio_enable("vfio");
+		status = rte_vfio_is_enabled("vfio_pci");
+	}
+	return status;
  }
  #endif

Also wondering if it could be considered a fix.

Thanks,
Maxime

Reviewed-by on v1 1/2
#3 lore raw
In reply to David Marchand
Quoted 19 lines · David Marchand

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

Quoted 6 lines
---
  lib/eal/linux/eal.c      | 18 +-----------------
  lib/eal/linux/eal_vfio.c |  9 ++++++---
  2 files changed, 7 insertions(+), 20 deletions(-)

Should it be considered as a fix, and so a candidate for stable? Or do you think it is too risky to change the behaviour?

Other than that, it looks good to me:

Thanks,
Maxime

#4 lore raw
Quoted 27 lines · Maxime Coquelin
Quoted 19 lines · David Marchand

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

Quoted 6 lines
---
  lib/eal/linux/eal.c      | 18 +-----------------
  lib/eal/linux/eal_vfio.c |  9 ++++++---
  2 files changed, 7 insertions(+), 20 deletions(-)
Quoted 2 lines

Should it be considered as a fix, and so a candidate for stable? Or do you think it is too risky to change the behaviour?

Cc stable maintainers (fyi)

I don't think it is risky: existing applications which relied on multi process had no choice but to make sure VFIO was properly setup before DPDK init.
Yet, a change in behavior impact is always hard to estimate.

(same comment for the second patch of the series)

Signature · 1 line
David Marchand
#5 lore raw
Quoted 32 lines · David Marchand
Quoted 27 lines · Maxime Coquelin
Quoted 19 lines · David Marchand

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

Quoted 6 lines
---
  lib/eal/linux/eal.c      | 18 +-----------------
  lib/eal/linux/eal_vfio.c |  9 ++++++---
  2 files changed, 7 insertions(+), 20 deletions(-)
Quoted 2 lines

Should it be considered as a fix, and so a candidate for stable? Or do you think it is too risky to change the behaviour?

Quoted 10 lines
Cc stable maintainers (fyi)

I don't think it is risky: existing applications which relied on multi process had no choice but to make sure VFIO was properly setup before DPDK init.
Yet, a change in behavior impact is always hard to estimate.

(same comment for the second patch of the series)

They seem borderline fixes for usability. I think it's a good candidate for 22.11/23.11.

For 21.11, it is the last release and the behaviour has been like that for 3 years, so would probably skip that one.

#6 lore raw
In reply to Maxime Coquelin
Quoted 13 lines · Maxime Coquelin
Quoted 13 lines

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Quoted 8 lines
Quoted 7 lines

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

Series applied for rc1.
Thanks for the review Maxime.

Signature · 1 line
David Marchand
#7 lore raw
In reply to David Marchand

Hello Anatoly,

Quoted 14 lines · David Marchand

At the moment, if VFIO is not available at DPDK init, it won't be available unless a subsequent rte_vfio_enable() is done.

Yet, even if rte_vfio_enable() is called again in primary and secondary processes, a secondary process will never get to know that VFIO has been enabled in the primary process as the MP requests handler is only registered in EAL init.

On the other hand, moving the MP requests handler registration earlier in EAL init is ok, as secondary process are supposed to be waiting on eal_mcfg_wait_complete() until the primary process calls eal_mcfg_complete().

Quoted 7 lines

Move vfio_mp_sync_setup() in rte_vfio_enable().

Besides, rte_eal_vfio_setup() is useless and its name with a rte_ prefix is ambiguous as it gives the impression it is an exported/public symbol. Remove it and directly call rte_vfio_enable() where needed.

Can I get a review on this 2 patches series?
Thanks.

Signature · 1 line
David Marchand