Bug 274306 - The nlsysevent kernel module fails to load.
Summary: The nlsysevent kernel module fails to load.
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Kristof Provost
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-06 12:47 UTC by crest
Modified: 2023-10-17 06:34 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description crest 2023-10-06 12:47:00 UTC
I've compiled FreeBSD 14.0-BETA5/amd64 from sources (commit hash = 243550d32f4231d4407cd57220d36e42153d97f0) from sources, installed it and rebooted into it. The running kernel, installed kernel, and userland are in sync unless `make installkernel installworld` is broken.

I tried to load the Netlink system event kernel module using `kldload -v nlsysevent.ko`. This failed to load.

The output from kldload is:

    kldload: an error occurred while loading module nlsysevent.ko. Please check dmesg(8) for more details.

The details as logged by the kernel:

    link_elf_obj: symbol nlmsg_get_group_writer undefined
    linker_load_file: /boot/kernel/nlsysevent.ko - unsupported file type

The module can be loaded from /usr/obj by running `make load` in /usr/src/sys/modules/nlsysevent which loads /usr/obj/usr/src/amd64.amd64/sys/modules/nlsysevent/nlsysevent.ko instead. I don't have problems loading other kernel modules. Is there something missing in either the nlsysevent or netlink kernel modules in how the  nlmsg_get_group_writer symbol is declared and referenced across module boundries?
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2023-10-12 13:13:04 UTC
A quick hack which fixes the problem is to make sys/modules/nlsysevent/Makefile define NETLINK_MODULE.  But these parts of netlink_message_writer.h don't really make sense:

 84 #if defined(NETLINK) || defined(NETLINK_MODULE)                                                                                                                                                                                                                                                                           
 85 /* Provide optimized calls to the functions inside the same linking unit */
...
163 #else                                                                                                                                                                                                                                                                                                                     
164 /* Provide access to the functions via netlink_glue.c */

The implementations in netlink_glue.c are just stubs that get defined when the kernel is compiled without netlink support, so these comments are just wrong.  I'm not sure what the intent is.  Do we want to support loading netlink kernel modules even when the kernel is compiled without netlink support?
Comment 2 Kristof Provost freebsd_committer freebsd_triage 2023-10-12 13:19:41 UTC
diff --git a/sys/netlink/netlink_sysevent.c b/sys/netlink/netlink_sysevent.c
index 01d0837b14d2..e3abdd688e66 100644
--- a/sys/netlink/netlink_sysevent.c
+++ b/sys/netlink/netlink_sysevent.c
@@ -25,6 +25,8 @@
  * SUCH DAMAGE.
  */

+#include "opt_netlink.h"
+
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/devctl.h>

ought to fix it, but this is a more common problem, so I wonder if we can't do the include in the relevant netlink code instead.
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2023-10-12 13:29:05 UTC
(In reply to Kristof Provost from comment #2)
That looks good to me if you want to commit it.

I don't see any problem with including opt_netlink.h in netlink.h.  Assuming that this problem exists in stable/14, I might go for the smaller patch first and MFC, then fix everything.
Comment 4 Kristof Provost freebsd_committer freebsd_triage 2023-10-12 17:31:28 UTC
(In reply to Mark Johnston from comment #3)
I'd prefer this: https://reviews.freebsd.org/D42170 because that'll fix everything. I've already run into this issue in carp and pf, and I'm not confident this is the last one.
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-10-13 07:25:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ab393e9548f8cc0ee28499c411963b798ebb38a5

commit ab393e9548f8cc0ee28499c411963b798ebb38a5
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-10-12 19:55:57 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-10-13 07:23:47 +0000

    netlink: move NETLINK define to opt_global.h

    Move the NETLINK define into opt_global.h so we can rely on it being
    set correctly, without having to remember to include opt_netlink.h.
    This ensures that the NETLINK define is correctly set. If not we
    may end up with unloadable modules, due to missing symbols (such as
    nlmsg_get_group_writer).

    PR:             274306
    Reviewed by:    imp, markj
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D42179

 sys/compat/linux/linux_netlink.c                        | 1 -
 sys/conf/options                                        | 2 +-
 sys/modules/carp/Makefile                               | 2 +-
 sys/modules/ktest/ktest/Makefile                        | 1 -
 sys/modules/ktest/ktest_example/Makefile                | 1 -
 sys/modules/ktest/ktest_netlink_message_writer/Makefile | 1 -
 sys/modules/linux/Makefile                              | 3 +--
 sys/modules/linux_common/Makefile                       | 3 +--
 sys/modules/netlink/Makefile                            | 2 +-
 sys/net/if_clone.c                                      | 2 --
 sys/net/if_vlan.c                                       | 1 -
 sys/netinet/ip_carp.c                                   | 2 --
 sys/netlink/ktest_netlink_message_writer.c              | 2 --
 sys/netlink/netlink_domain.c                            | 1 -
 sys/netlink/netlink_generic.c                           | 2 --
 sys/netlink/netlink_glue.c                              | 2 --
 sys/netlink/netlink_io.c                                | 2 --
 sys/netlink/netlink_message_writer.c                    | 2 --
 sys/netlink/netlink_module.c                            | 2 --
 sys/netlink/route/iface.c                               | 2 --
 sys/netlink/route/iface_drivers.c                       | 1 -
 sys/netlink/route/neigh.c                               | 2 --
 sys/netlink/route/nexthop.c                             | 2 --
 sys/netlink/route/rt.c                                  | 2 --
 sys/netpfil/pf/pf_nl.c                                  | 2 --
 sys/tests/ktest.c                                       | 2 --
 26 files changed, 5 insertions(+), 42 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-10-16 11:32:17 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ff15498894e2546fcce7ffc24967e714de3805ed

commit ff15498894e2546fcce7ffc24967e714de3805ed
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-10-12 19:55:57 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-10-16 07:42:33 +0000

    netlink: move NETLINK define to opt_global.h

    Move the NETLINK define into opt_global.h so we can rely on it being
    set correctly, without having to remember to include opt_netlink.h.
    This ensures that the NETLINK define is correctly set. If not we
    may end up with unloadable modules, due to missing symbols (such as
    nlmsg_get_group_writer).

    PR:             274306
    Reviewed by:    imp, markj
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D42179

    (cherry picked from commit ab393e9548f8cc0ee28499c411963b798ebb38a5)

 sys/compat/linux/linux_netlink.c                        | 1 -
 sys/conf/options                                        | 2 +-
 sys/modules/carp/Makefile                               | 2 +-
 sys/modules/ktest/ktest/Makefile                        | 1 -
 sys/modules/ktest/ktest_example/Makefile                | 1 -
 sys/modules/ktest/ktest_netlink_message_writer/Makefile | 1 -
 sys/modules/linux/Makefile                              | 3 +--
 sys/modules/linux_common/Makefile                       | 3 +--
 sys/modules/netlink/Makefile                            | 2 +-
 sys/net/if_clone.c                                      | 2 --
 sys/net/if_vlan.c                                       | 1 -
 sys/netinet/ip_carp.c                                   | 2 --
 sys/netlink/ktest_netlink_message_writer.c              | 2 --
 sys/netlink/netlink_domain.c                            | 1 -
 sys/netlink/netlink_generic.c                           | 2 --
 sys/netlink/netlink_glue.c                              | 2 --
 sys/netlink/netlink_io.c                                | 2 --
 sys/netlink/netlink_message_writer.c                    | 2 --
 sys/netlink/netlink_module.c                            | 2 --
 sys/netlink/route/iface.c                               | 2 --
 sys/netlink/route/iface_drivers.c                       | 1 -
 sys/netlink/route/neigh.c                               | 2 --
 sys/netlink/route/nexthop.c                             | 2 --
 sys/netlink/route/rt.c                                  | 2 --
 sys/tests/ktest.c                                       | 2 --
 25 files changed, 5 insertions(+), 40 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2023-10-17 05:57:53 UTC
A commit in branch releng/14.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2ae26ba673384a075f31cea0ef495a02af293262

commit 2ae26ba673384a075f31cea0ef495a02af293262
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-10-12 19:55:57 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-10-17 05:56:51 +0000

    netlink: move NETLINK define to opt_global.h

    Move the NETLINK define into opt_global.h so we can rely on it being
    set correctly, without having to remember to include opt_netlink.h.
    This ensures that the NETLINK define is correctly set. If not we
    may end up with unloadable modules, due to missing symbols (such as
    nlmsg_get_group_writer).

    PR:             274306
    Reviewed by:    imp, markj
    Approved by:    re (karels)
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D42179

    (cherry picked from commit ab393e9548f8cc0ee28499c411963b798ebb38a5)
    (cherry picked from commit ff15498894e2546fcce7ffc24967e714de3805ed)

 sys/compat/linux/linux_netlink.c                        | 1 -
 sys/conf/options                                        | 2 +-
 sys/modules/carp/Makefile                               | 2 +-
 sys/modules/ktest/ktest/Makefile                        | 1 -
 sys/modules/ktest/ktest_example/Makefile                | 1 -
 sys/modules/ktest/ktest_netlink_message_writer/Makefile | 1 -
 sys/modules/linux/Makefile                              | 3 +--
 sys/modules/linux_common/Makefile                       | 3 +--
 sys/modules/netlink/Makefile                            | 2 +-
 sys/net/if_clone.c                                      | 2 --
 sys/net/if_vlan.c                                       | 1 -
 sys/netinet/ip_carp.c                                   | 2 --
 sys/netlink/ktest_netlink_message_writer.c              | 2 --
 sys/netlink/netlink_domain.c                            | 1 -
 sys/netlink/netlink_generic.c                           | 2 --
 sys/netlink/netlink_glue.c                              | 2 --
 sys/netlink/netlink_io.c                                | 2 --
 sys/netlink/netlink_message_writer.c                    | 2 --
 sys/netlink/netlink_module.c                            | 2 --
 sys/netlink/route/iface.c                               | 2 --
 sys/netlink/route/iface_drivers.c                       | 1 -
 sys/netlink/route/neigh.c                               | 2 --
 sys/netlink/route/nexthop.c                             | 2 --
 sys/netlink/route/rt.c                                  | 2 --
 sys/tests/ktest.c                                       | 2 --
 25 files changed, 5 insertions(+), 40 deletions(-)