Bug 252156 - WireGuard kernel module can't be loaded on ARM64 / RPi4
Summary: WireGuard kernel module can't be loaded on ARM64 / RPi4
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-26 10:37 UTC by Gordon Bergling
Modified: 2021-01-12 22:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Bergling freebsd_committer 2020-12-26 10:37:47 UTC
On a recent -CURRENT from 20th of December the WireGuard module can't be loaded on ARM64 / RPi4.

# kldload if_wg
kldload: can't load if_wg: No such file or directory

but the module is present:

$ ls -l /boot/kernel/if_wg.ko
-r-xr-xr-x  1 root  wheel  - 279704 Dec 20 20:34 /boot/kernel/if_wg.ko

dmesg shows that blake2 can't be loaded and indeed it can't be found on arm64.

KLD if_wg.ko: depends on blake2 - not available or version mismatch
Comment 1 Ed Maste freebsd_committer 2020-12-27 00:14:46 UTC
In sys/modules blake2 is built only on i386 and amd64. There is some optimized x86 asm included, but it should build on other archs (and indeed, it is possible to compile it into the kernel anywhere, per sys/conf/files).

commit 088343f0d45b05cc1a087d02997c1fee8e82ebc8 (HEAD -> wipbsd.20201226)
Author: Ed Maste <emaste@FreeBSD.org>
Date:   Sat Dec 26 19:13:36 2020 -0500

    Build blake2 module on all archs
    
    It contains optimized asm routines for x86 but the C implementations
    should build everywhere.
    
    PR:             252156

This might do it:

diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index f8f42a8b6226..e8a6aba400f4 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -415,6 +415,7 @@ SUBDIR+=    opensolaris
 .endif
 
 .if ${MK_CRYPT} != "no" || defined(ALL_MODULES)
+_blake2=       blake2
 .if exists(${SRCTOP}/sys/opencrypto)
 _crypto=       crypto
 _cryptodev=    cryptodev
@@ -659,9 +660,6 @@ _amdsmn=    amdsmn
 _amdtemp=      amdtemp
 _arcmsr=       arcmsr
 _asmc=         asmc
-.if ${MK_CRYPT} != "no" || defined(ALL_MODULES)
-_blake2=       blake2
-.endif
 _bytgpio=      bytgpio
 _chvgpio=      chvgpio
 _ciss=         ciss
Comment 2 Gordon Bergling freebsd_committer 2020-12-27 08:08:55 UTC
(In reply to Ed Maste from comment #1)

I tried the patch, but it fails because of some architecture specific compiler options.

/tank/nfs_public/tiny/src/sys/arm64/arm64/locore.S:794:2: warning: DWARF2 only supports one section per compilation unit
 .section .init_pagetable, "aw", %nobits
 ^
cc: error: argument unused during compilation: '-msse2' [-Werror,-Wunused-command-line-argument]
cc: error: argument unused during compilation: '-msse2' [-Werror,-Wunused-command-line-argument]
--- blake2b-sse2.o ---
*** [blake2b-sse2.o] Error code 1

make[4]: stopped in /tank/nfs_public/tiny/src/sys/modules/blake2
--- modules-all ---
*** [modules-all] Error code 2
Comment 3 Ed Maste freebsd_committer 2020-12-27 18:10:02 UTC
Ah yes, indeed - sys/conf/files contains rules for contrib/libb2/blake2b-ref.c and crypto/blake2/blake2-sw.c; it does not use any of the optimized versions. As a first step we should be able to use this in the module on !x86.
Comment 4 commit-hook freebsd_committer 2021-01-12 22:07:35 UTC
A commit in branch main references this bug:

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

commit d89e1db5a3319f4e3bc9403ed883c64638b67f71
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2021-01-12 21:38:21 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2021-01-12 22:07:10 +0000

    if_wg: fix modules load on !x86

    Only x86 provides optimized implementations via the blake2 module. The
    software "reference" implementation is already included in the crypto(4)
    module, we can drop the extra MODULE_DEPEND for other platforms.

    Without this change, if_wg.ko could not be loaded due to the missing
    dependency.

    PR:             252156
    Reported by:    gbe
    Sponsored by:   The FreeBSD Foundation

 sys/dev/if_wg/module/module.c | 3 +++
 1 file changed, 3 insertions(+)