From 72d2c4f3718ba5293e9e0fa8726406ee7d9f3940 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Thu, 5 Apr 2018 21:32:29 +0200 Subject: plugins: unload plugin if early init fails Change-Id: I32f68e2ee8f5d32962acdefb0193583f71d342b3 Signed-off-by: Damjan Marion --- src/plugins/dpdk/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/plugins/dpdk') diff --git a/src/plugins/dpdk/main.c b/src/plugins/dpdk/main.c index f2f1ba22ed5..5437e2fafdc 100644 --- a/src/plugins/dpdk/main.c +++ b/src/plugins/dpdk/main.c @@ -13,6 +13,13 @@ * limitations under the License. */ +#include +#include +#include +#include +#include +#include + #include #include #include @@ -88,9 +95,45 @@ static clib_error_t * dpdk_main_init (vlib_main_t * vm) VLIB_INIT_FUNCTION (dpdk_main_init); + +clib_error_t * +dpdk_early_init (vlib_main_t *vm) +{ + int fd = -1; + u64 *pt = 0; + clib_error_t *err = 0; + + /* check if pagemap is accessible - if we get zero result + dpdk will not be able to get physical memory address and game is over + unless we have IOMMU */ + pt = clib_mem_vm_get_paddr (&pt, min_log2 (sysconf (_SC_PAGESIZE)), 1); + if (pt && pt[0]) + goto done; + + if ((fd = open ("/dev/vfio/vfio", O_RDWR) == -1)) + goto error; + + if (ioctl (fd, VFIO_GET_API_VERSION) != VFIO_API_VERSION) + goto error; + + /* if we have type 1 IOMMU page map is not needed */ + if (ioctl (fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) == 1) + goto done; + +error: + err = clib_error_return (0, "access to physical devices is not allowed"); + +done: + if (fd != -1) + close (fd); + vec_free (pt); + return err; +} + /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, .description = "Data Plane Development Kit (DPDK)", + .early_init = "dpdk_early_init", }; /* *INDENT-ON* */ -- cgit 1.2.3-korg