modprobe: ERROR: could not insert 'v4l2loopback': Unknown symbol in module, or unknown parameter (see dmesg) - v4l2

I am trying to set up virtual v4l2 devices on an AWS EC2 instance. I did apt install for v4l2loopback-dkms and v4l2loopback-utils.
I get the following error when i try to set up devices with
sudo modprobe v4l2loopback device=8
modprobe: ERROR: could not insert 'v4l2loopback': Unknown symbol in module, or unknown parameter (see dmesg)
If I check dmesg:
[87243.295525] v4l2loopback: Unknown symbol video_ioctl2 (err -2)
[87243.295553] v4l2loopback: Unknown symbol v4l2_ctrl_handler_init_class (err -2)
[87243.295582] v4l2loopback: Unknown symbol video_devdata (err -2)
[87243.295605] v4l2loopback: Unknown symbol v4l2_ctrl_new_custom (err -2)
[87243.295623] v4l2loopback: Unknown symbol video_unregister_device (err -2)
.
.
.
uname -a
5.4.0-1055-aws #58~18.04.1-Ubuntu SMP Wed Jul 28 03:04:50 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Could you please help me on this?

Using AWS EC2 - ubuntu 20.04 LTS, I installed:
sudo apt -y install v4l2loopback-dkms v4l2loopback-utils linux-modules-extra-$(uname -r)
followed by:
sudo modprobe v4l2loopback
worked for me

Related

Linux Kernel Module Development "module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1"

I am currently trying to develop a simple linux kernel module. It should just log something, its 1:1 copied from the internet.
I have the following files:
lkm_example.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Robert W. Oliver II");
MODULE_DESCRIPTION("A simple example Linux module.");
MODULE_VERSION("0.01");
static int __init lkm_example_init(void) {
printk(KERN_INFO "Hello, World!\n");
return 0;
}
static void __exit lkm_example_exit(void) {
printk(KERN_INFO "Goodbye, World!\n");
}
module_init(lkm_example_init);
module_exit(lkm_example_exit);
Makefile:
obj-m += lkm_example.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
I also did the following:
sudo apt-get install build-essential linux-headers-`uname -r`
For compilation i used:
stbau#kernel-dev-vm:~/src/lkm_example$ sudo make
make -C /lib/modules/5.13.0-39-generic/build M=/home/stbau/src/lkm_example modules
make[1]: Entering directory '/usr/src/linux-headers-5.13.0-39-generic'
CC [M] /home/stbau/src/lkm_example/lkm_example.o
MODPOST /home/stbau/src/lkm_example/Module.symvers
CC [M] /home/stbau/src/lkm_example/lkm_example.mod.o
LD [M] /home/stbau/src/lkm_example/lkm_example.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.13.0-39-generic'
Executing with insmod:
stbau#kernel-dev-vm:~/src/lkm_example$ sudo insmod lkm_example.ko
insmod: ERROR: could not insert module lkm_example.ko: Invalid module format
The dmesg log gives the following error:
[ 49.272618] lkm_example: module verification failed: signature and/or required key missing - tainting kernel
[ 49.272630] module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 0000000054f3f1c5, val ffffffffc0a0a000
I am using the following kernel:
stbau#kernel-dev-vm:~/src/lkm_example$ uname -a
Linux kernel-dev-vm 5.13.0-39-generic #44-Ubuntu SMP Thu Mar 24 15:35:05 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
As you can see in the dmesg log, i only get an error and not the messages i expected. I have no idea what i did wrong/what is missing.
I think the problem is that the module is not signed. I tried signing it using the sign-file but i was not able to generate a private/public key file.
Re-Installing the kernel headers worked for me.
I used the following commands:
sudo apt update && sudo apt upgrade
sudo apt remove --purge linux-headers-*
sudo apt autoremove && sudo apt autoclean
sudo apt install linux-headers-generic

Does Writing Linux Kernel Module Require Compiling Own Kernel?

I have a simple hello world kernel module on Ubuntu x86_64:
#include <linux/module.h>
static int
mod_init(void)
{
printk(KERN_INFO "RYANhello world\n");
return 0;
}
static void
mod_exit(void)
{
printk(KERN_INFO "RYANgoodbye world\n");
}
MODULE_LICENSE("GPL");
module_init(mod_init);
module_exit(mod_exit);
Makefile:
KERNEL_DIR := /lib/modules/$(shell uname -r)/build
CUR_DIR := $(shell pwd)
obj-m := module.o
default:
$(MAKE) -C $(KERNEL_DIR) M=$(CUR_DIR) modules
When I sudo insmod module.ko I get insmod: ERROR: could not insert module module.ko: Invalid parameters. Inspecting dmesg:
loading out-of-tree module taints kernel
module verification failed: signature and/or required key missing - tainting kernel
Repeating insmod yields module is already loaded however /var/log/syslog shows no trace of it loading (i.e printk messages not present). Also, running sudo rmmod module.ko:
rmmod: ERROR: ../libkmod/libkmod-module.c:1941 kmod_module_get_holders() could not open '/sys/module/module/holders': No such file or directory
rmmod: ERROR: Module unloading is not supported
This seems to indicate it's not loaded, even though dmesg says it is?
Addressing common issues; my host kernel and gcc version are the same as ones I compiling with.
So, this leads me to think that the module not being signed is the issue. To disable this do I have to compile and install my own kernel with appropriate .config? In other words, to write and test your own kernel modules on a modern GNU/Linux OS with enforced signing, do you have to compile and install your own kernel?
EDIT
CONFIG_MODULE_SIG_FORCE is not set in my /boot/config-5.8.0-53-generic, so it seems I should be able to load my module albeit with a tainted kernel message. So, why would I be getting Invalid parameters?
Inspecting dmesg on first insmod it was saying that the module was already loaded. As I had never loaded this before, this prompted me to think that this name was already taken.
Low and behold, renaming module.c/module.o --> example.c/example.o fixed the problem. The invalid parameters message was what threw me.

i2c_register_board_info symbol is undefined

I am trying to write a kernel module for a BeagleBone Black that would communicate with my custom I2C slave device. I tried following several kernel module development tutorials, they all seem incomplete at some point, or assume that I know something I clearly don't... My current problem now is that the Makefile doesnt see the i2c_register_board_info symbol. I am writing this driver as a separate module, its not compiled during kernel compilation. Also, I have enabled the I2C tools when building using buildroot. Using the I2C tools I am able to detect and interface with my device. My Makefile looks as follows:
MODULE_NAME = PowerManagerDriver
PWD := $(shell pwd)
SRC_DIR = user_files
BUILD_DIR = build
BUILD_EXT = *.o .*.cmd *.ko *.mod.c *.order *.symvers *.dwo
SRCS = $(SRC_DIR)/main.c $(SRC_DIR)/pmd_i2c.c
OBJS = $(SRCS:.c=.o)
obj-m += $(MODULE_NAME).o
$(MODULE_NAME)-y = $(OBJS)
KERNELDIR ?= /home/lukasz/brl/Machine/beaglebone/build/linux-a75d8e93056181d512f6c818e8627bd4554aaf92
all: default
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
mv $(SRC_DIR)/*.o $(BUILD_DIR)/
mv $(BUILD_EXT) $(BUILD_DIR)/ &> /dev/null
clean:
rm -rf $(BUILD_DIR)/*
rm -rf $(BUILD_EXT)
make output:
13:45:33 **** Incremental Build of configuration Default for project PowerManagerDriver ****
make ARCH=arm CROSS_COMPILE=arm-buildroot-linux-uclibcgnueabihf- -j6 all
make -C /home/lukasz/brl/Machine/beaglebone/build/linux-a75d8e93056181d512f6c818e8627bd4554aaf92 M=/home/lukasz/eclipse-workspace/PowerManagerDriver modules
make[1]: Entering directory '/home/lukasz/brl/Machine/beaglebone/build/linux-a75d8e93056181d512f6c818e8627bd4554aaf92'
CC [M] /home/lukasz/eclipse-workspace/PowerManagerDriver/user_files/main.o
CC [M] /home/lukasz/eclipse-workspace/PowerManagerDriver/user_files/pmd_i2c.o
/home/lukasz/eclipse-workspace/PowerManagerDriver/user_files/pmd_i2c.c:99:26: warning: ‘pdm_i2cClient’ defined but not used [-Wunused-variable]
static struct i2c_client pdm_i2cClient = { 0 };
^
LD [M] /home/lukasz/eclipse-workspace/PowerManagerDriver/PowerManagerDriver.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "i2c_register_board_info" [/home/lukasz/eclipse-workspace/PowerManagerDriver/PowerManagerDriver.ko] undefined!
CC /home/lukasz/eclipse-workspace/PowerManagerDriver/PowerManagerDriver.mod.o
LD [M] /home/lukasz/eclipse-workspace/PowerManagerDriver/PowerManagerDriver.ko
make[1]: Leaving directory '/home/lukasz/brl/Machine/beaglebone/build/linux-a75d8e93056181d512f6c818e8627bd4554aaf92'
mv user_files/*.o build/
mv *.o .*.cmd *.ko *.mod.c *.order *.symvers *.dwo build/ &> /dev/null
13:45:35 Build Finished. 0 errors, 1 warnings. (took 1s.394ms)
So far I have only few functions for I2C interfacing:
static int pdm_i2cProbe(struct i2c_client* client,
const struct i2c_device_id* id)
{
PMD_ASSERT(client);
PMD_ASSERT(id);
return 0;
}
static struct i2c_driver pdm_i2cDriver =
{
.driver =
{
.name = "pdm-driver",
.owner = THIS_MODULE,
},
.probe = pdm_i2cProbe,
};
static struct i2c_board_info pdm_i2cBoardInfo[] =
{
{
I2C_BOARD_INFO("pdm-driver", 0x30),
.irq = 69,
},
};
/**
* #brief Initializes the I2C module.
* #param busNr: The I2C peripheral number on which the device is connected.
* #return \ref e_pdmStatus_OK on succesfull init.
*/
pmdStatus_t pdm_i2cInit(const unsigned int busNr)
{
if (i2c_register_board_info((int)busNr, pdm_i2cBoardInfo,
ARRAY_SIZE(pdm_i2cBoardInfo)))
return e_pmdStatus_BADPARAM;
if (i2c_add_driver(&pdm_i2cDriver))
return e_pmdStatus_EXE;
return e_pmdStatus_OK;
}
At this point even though I dont probe anything, as the probe function is empty, I was hoping to at least load the module correctly. I dont even get to the testing phase since the i2c_register_board_info is not found. My .config file for when building the kernel consists of those lines:
# I2C support
#
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=y
# CONFIG_I2C_MUX is not set
CONFIG_I2C_HELPER_AUTO=y
I have found this topic previously i2c registering macro not found? but I can't get anything out of it.
When trying to load the module with insmod as requested:
# uname -a
Linux buildroot 4.9.59 #1 SMP Fri Oct 5 11:55:54 CEST 2018 armv7l GNU/Linux
# insmod PowerManagerDriver.ko
[ 39.438108] PowerManagerDriver: loading out-of-tree module taints kernel.
[ 39.445800] PowerManagerDriver: Unknown symbol i2c_register_board_info (err 0)
[ 39.455743] PowerManagerDriver: Unknown symbol i2c_register_board_info (err 0)
insmod: can't insert 'PowerManagerDriver.ko': unknown symbol in module, or unknown parameter
#
If your hardware is 'guaranteed' to be there, you do not need to define the device imperatively. You can use device tree (dtb) to declare the existence of your slave at a particular address on a particular bus, provide params to your driver etc. So your module never needs to do the register board info thing.
This is explained in the docs: https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
In other words you should be able to write a driver for your slave device as a kernel module using only open firmware (of) hooks and a populated device tree (dtb).
OK, it sounds like this is a duplicate of Build Linux Kernel module with warning i2c_register_board_info undefined.
PROBLEM:
# insmod PowerManagerDriver.ko
[ 39.438108] PowerManagerDriver: loading out-of-tree module taints kernel.
[ 39.445800] PowerManagerDriver: Unknown symbol i2c_register_board_info (err 0)
[ 39.455743] PowerManagerDriver: Unknown symbol i2c_register_board_info (err 0)
insmod: can't insert 'PowerManagerDriver.ko': unknown symbol in module, or unknown parameter
CAUSE:
Build Linux Kernel module with warning i2c_register_board_info undefined
Function i2c_register_board_info isn't exported (with EXPORT_SYMBOL)
for kernel modules. Only code compiled into the kernel may use such
functions. As far as I understand from its description, the function
is intended to use by boards developers
Your problem is you are mixing two things in one driver, i.e. driver
itself which can be a module and platform (legacy!) code, which can't.
You have to drop platform code for ACPI or device tree resource
provider, or as a last resort to split it out to another compile unit.
WORKAROUND:
I removed i2c_register_board_info then I can build driver to module
(.ko) without warning and can insmod by adding these function in init
function called by module_init:
...
adapter = i2c_get_adapter(CONFIG_I2C_BUS);
...
client = i2c_new_device(adapter, &i2c_pn535_sample_devs);
...
not sure if it is good or bad. because when i remove driver (rmmod),
driver does not release device and can not insmod again, I have to
reboot device to insmod again
Please feel free to add (and accept!) your own response if you find a different - or better - solution.
Sorry I couldn't be of more help :(

Go 1.8 plugins, fatal error: stddef.h: No such file

Observe:
$ cat /tmp/plugin.go
package main
import "fmt"
var V int
func F() { fmt.Printf("Hello, number %d\n", V) }
$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
cgo-builtin-prolog:1:57: fatal error: stddef.h: No such file or directory
compilation terminated.
Why is that?
This is under Ubuntu 17.04, and I have build-essentials installed:
$ go version
go version go1.9 linux/amd64
$ uname -r
4.10.0-37-generic
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.04
Release: 17.04
Codename: zesty
$ apt-cache policy build-essential
build-essential:
Installed: 12.1ubuntu2
Candidate: 12.1ubuntu2
please not the "Compilation error: "stddef.h: No such file or directory"" is NOT the answer as my gcc-core package and gcc-g++ are of the same version -- here are my gcc related packages:
gcc_4:6.3.0-2ubuntu1
gcc-6_6.3.0-12ubuntu2
gcc-6-base:amd64_6.3.0-12ubuntu2
libgcc-6-dev:amd64_6.3.0-12ubuntu2
libgcc1:amd64_1:6.3.0-12ubuntu2
UPDATE:
thanks #peterSO, seems to be my gcc's own problem:
$ cat /tmp/foo.c
#include <stdio.h>
$ gcc /tmp/foo.c
In file included from /tmp/foo.c:1:0:
/usr/include/stdio.h:33:21: fatal error: stddef.h: No such file or directory
# include <stddef.h>
While searching for solution for it, I found someone suggested to reinstall gcc, so I did, together with libc6-dev:
apt-get --reinstall install libgcc-6-dev gcc-6 gcc-6-base:amd64 libc6-dev:amd64
Now my simple .c file compiles OK now, but I'm bumped into a new problem with cgo:
$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
In file included from /usr/include/errno.h:35:0,
from cgo-gcc-prolog:21:
/usr/include/x86_64-linux-gnu/bits/errno.h:24:26: fatal error: linux/errno.h: No such file or directory
# include <linux/errno.h>
^
compilation terminated.
I know this might be a Ubuntu/gcc specific problem (Ref: Why is stddef.h not in /usr/include? and my stddef.h is under /usr/src/linux-headers-4.10.0-37/include/linux/stddef.h), but anybody here knows Go and gcc good enough to know how to fix it, so that Go plugins can be compiled properly?
Thx!

Pkg-config file is on the pkg-config path but can not be found by configure script

I am trying to install libvirt from source. The version I am trying to install is 1.2.7. I want libssh2 enabled. Here is how I call the configure script:
./configure --prefix=/home/administrator/dev/workspaces/libvirt/built/libvirt-1.2.7/ --with-sasl --with-qemu --with-lxc --with-gnutls --with-remote --with-ssh2 --with-polkit
I got the following error:
configure: error: You must install the libssh2 >= 1.3 pkg-config module to compile libvirt
I downloaded the libssh2 lib version 1.4.3 and installed it using the default options:
$ ./configure
$ make
$ sudo make install
Here is some useful info:
$ sudo ldconfig
$ sudo updatedb
$ locate libssh2.so
/usr/local/lib/libssh2.so
/usr/local/lib/libssh2.so.1
/usr/local/lib/libssh2.so.1.0.1
$ locate libssh2.pc
/usr/local/lib/pkgconfig/libssh2.pc
$ pkg-config --variable pc_path pkg-config
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
Obviously the libssh2.pc file is on the pkg-config path. However, when I tried executing the configure script for libvirt, the same error occurred. Any ideas what I am doing wrong ? Thank you.
EDIT: Fragment of the config.log file:
34475 configure:59141: checking for SSH2
34476 configure:59148: $PKG_CONFIG --exists --print-errors "libssh2 >= 1.3"
34477 configure:59151: $? = 0
34478 configure:59165: $PKG_CONFIG --exists --print-errors "libssh2 >= 1.3"
34479 configure:59168: $? = 0
34480 configure:59182: result: no
34481 Package libssl was not found in the pkg-config search path.
34482 Perhaps you should add the directory containing `libssl.pc'
34483 to the PKG_CONFIG_PATH environment variable
34484 Package 'libssl', required by 'libssh2', not found
34485 configure:59225: error: You must install the libssh2 >= 1.3 pkg-config module to compile libvirt
...
34576 ac_cv_env_PKG_CONFIG_LIBDIR_set=
34577 ac_cv_env_PKG_CONFIG_LIBDIR_value=
34578 ac_cv_env_PKG_CONFIG_PATH_set=
34579 ac_cv_env_PKG_CONFIG_PATH_value=
34580 ac_cv_env_PKG_CONFIG_set=
34581 ac_cv_env_PKG_CONFIG_value=
...
34874 ac_cv_path_ac_pt_PKG_CONFIG=/usr/bin/pkg-config
36432 PKG_CONFIG='/usr/bin/pkg-config'
36433 PKG_CONFIG_LIBDIR=''
36434 PKG_CONFIG_PATH=''

Resources