luigirizzo / netmap

Automatically exported from code.google.com/p/netmap
BSD 2-Clause "Simplified" License
1.86k stars 537 forks source link

Netmap module fails to load on OpenWrt MIPS malta (Qemu) #178

Closed ratkaj closed 8 years ago

ratkaj commented 8 years ago

Hello,

I'm trying to create a working netmap package for OpenWrt. With modifications to the provided Makefile netmap successfully compiles for various architectures supported by OpenWrt.

I want a working Qemu OpenWrt MIPS image for testing, however netmap module fails to start producing a error. Here is the dmesg from the point i tried to load netmap module.

dmesg.txt

I get the same results when i first unload all related modules before i load netmap, and also the same error is present on other architectures, for instance brcm2708 (raspberry)

Strace might show a clue.

strace.txt

And here is ifconfig.

ifconfig.txt

I will provide any requested info, and hopefully the new OpenWrt Makefile once everything is fixed and tested.

vmaffione commented 8 years ago

It seems that the malloc() call done by the netmap_init_bridges2() function fails, because the requested memory size (almost 147KB) is larger than the value of KMALLOC_MAX_SIZE macro, defined in include/linux/slab.h.

Can you try to print this macro to check how much it is in your VMs? In my physical machine the macro resolves to 8MB.

ratkaj commented 8 years ago

Apologies if i did this wrong, i still have a lot to learn. I patched the kernel source to print the macro at compile time. This is the result.

pragma message: KMALLOC_MAX_SIZE=(1UL << ((11 + 12 - 1) <= 17 ? (11 + 12 - 1) : 17))

vmaffione commented 8 years ago

No problems, but the easy way is to apply this patch:

diff --git a/LINUX/netmap_linux.c b/LINUX/netmap_linux.c
index 7c2c434..1697467 100644
--- a/LINUX/netmap_linux.c
+++ b/LINUX/netmap_linux.c
@@ -2454,6 +2454,7 @@ struct miscdevice netmap_cdevsw = { /* same name as FreeBSD */
 static int linux_netmap_init(void)
 {
        int err;
+       printk("KMALLOC_MAX_SIZE %u\n", KMALLOC_MAX_SIZE);
        /* Errors have negative values on linux. */
        err = -netmap_init();
        if (err) {

compile and reinsert the netmap module. You will see the result in the kernel log.

ratkaj commented 8 years ago

Thank you for your response. Here is the real value KMALLOC_MAX_SIZE 131072

vmaffione commented 8 years ago

Ok, and you see it is less than 147 KB, and that's why netmap_init_bridges2 fails.

As a consequence, you have an easy fix. Just apply these patches:

diff --git a/LINUX/netmap_linux.c b/LINUX/netmap_linux.c
index 7c2c434..6e656ab 100644
--- a/LINUX/netmap_linux.c
+++ b/LINUX/netmap_linux.c
@@ -1812,7 +1812,7 @@ netmap_pernet_init(struct net *net)
                return error;

        ns->net = net;
-       ns->num_bridges = 8;
+       ns->num_bridges = 4;
        ns->bridges = netmap_init_bridges2(ns->num_bridges);
        if (ns->bridges == NULL) {
                nm_bns_destroy(net, ns);
diff --git a/sys/dev/netmap/netmap_vale.c b/sys/dev/netmap/netmap_vale.c
index dcae261..d61521d 100644
--- a/sys/dev/netmap/netmap_vale.c
+++ b/sys/dev/netmap/netmap_vale.c
@@ -147,7 +147,7 @@ __FBSDID("$FreeBSD: head/sys/dev/netmap/netmap.c 257176 2013-10-26 17:58:36Z gle
 #define NM_BDG_BATCH_MAX       (NM_BDG_BATCH + NM_MULTISEG)
 /* NM_FT_NULL terminates a list of slots in the ft */
 #define NM_FT_NULL             NM_BDG_BATCH_MAX
-#define        NM_BRIDGES              8       /* number of bridges */
+#define        NM_BRIDGES              4       /* number of bridges */

 /*
ratkaj commented 8 years ago

Thank you for your great support, this has resolved the issue and all modules load.

There is however a issue when i call pkt-gen for testing.

# pkt-gen -i eth0 -f tx -l 60

678.781098 nm_open [847] NIOCREGIF failed: Device or resource busy eth0
678.783029 main [2436] Unable to open netmap:eth0: Device or resource busy
678.785100 main [2517] aborting

I will do some research to try and resolve the issue, of course any advice is welcomed. Once again thank you for your support. The original issue has been resolved.

vmaffione commented 8 years ago

Ok, I'm closing this.

For the other issue, check that your eth0 is "free", e.g. is not attached to a software bridge/openvswitch or similar.

In any case you can grep the code for EBUSY and put debug prints to see where the interface registration fails.