Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all 12308 articles
Browse latest View live

Yocto: overriding kernel configuration

$
0
0

Related to this question. In order to customize the kernel configuration I created in my custom layer this structure:

$ tree recipes-kernel/
recipes-kernel/
└── linux
    ├── files
    │  └── <image>-defconfig
    └── linux-stm32mp_4.19.bbappend

Where the defconfig file is actually the .config used to manually compile the kernel (see the other question). The bbappend file contains the following code:

SRC_URI += "file://<full-path>/meta-custom-layer/recipes-kernel/linux/files/<image>-defconfig"
KERNEL_DEFCONFIG_stm32mp1_<variant> = "{WORKDIR}/<image>-defconfig"

I'm sure the file is processed because if I change the name of the defconfig bitbake raises a file not found error.

The problem is the compiled kernel does not have my customization. But if I copy my defconfig to the build directory (i.e. tmp/work/stm32mp1_<variant>-openstlinux_eglfs-linux-gnueabi/linux-stm32mp/4.19-r0/linux-stm32mp1-<variant>-standard-build/.config) and manually bitbake virtual/kernel) it does.

So it seems it searches and finds my defconfig but then it ignores it. Where is my mistake?


How to write a Linux kernel module makefile?

$
0
0

I'm trying to write a simple hello world kernel module. I'm working in Ubuntu 18.04.2 LTS on Virtual Box. In the directory /usr/src I created a directory named hello and inside that hello directory I've created hello.c and a makefile. Here is my makefile:

obj-m += hello.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

When I make the command "sudo make" I get this output:

make -C /lib/modules/5.3.0-28-generic/build M= modules
make[1]: Entering directory '/usr/src/linux-headers-5.3.0-28-generic'
make[2]: *** No rule to make target 'arch/x89/tools/relocs_32.c', needed by 'arch/x86/tools/relocs_32.o'. Stop.
arch/x86/Makefile:232: recipe for target 'archscripts' failed
make[1]: *** [archscripts] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.3.0-28-generic'
makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

I've tried a few variations of my makefile including changing "PWD" to "shell pwd". I've installed all the essential tools and libraries as far as I know. What could be the problem here?

Set permanent environmental variables in Linux [closed]

$
0
0

I am trying to set permanent environmental variable for Java in Linux. I have tried many things but it didn't work out,any one have experienced this before.

Thanks in advance

How to use Zero-copy sendmsg/Receive in Boost.Asio [closed]

$
0
0

I am using Boost.Asio, I want to improve my system by using Zero-copy sendmsg/Receive. Can I use Zero-copy sendmsg/Receive in Boost.Asio? Could you give me how to use them if I can use them?

Why is the close function is called release in `struct file_operations` in the Linux kernel?

$
0
0

I'm trying to make a linux kernel module, which supports open, close, read and write operations. So I want to register these functions via struct file_operations, however I can't find 'close' entry in the struct. I think I should use 'release' instead of 'close', but I wonder why the name is 'release' and not 'close'?

Kernel crash at snd_ctl_find_numid+0x38/0x6c

$
0
0

I am getting NULL pointer dereference occasionally at snd_ctl_find_numid+0x38/0x6c in 4.4 kernel while accessing snd_kcontrol. The issue is reproduced ocassionally. Can anybody provide any pointer in fixing the issue. Below is the stack trace :

  2662.430298:   <2> PC is at snd_ctl_find_numid+0x38/0x6c
  2662.437819:   <2> LR is at snd_ctl_find_id+0x38/0xd8
  2662.662838:   <2> [<ffffff8008c4e35c>] snd_ctl_find_numid+0x38/0x6c
  2662.667513:   <2> [<ffffff8008c4e900>] snd_ctl_find_id+0x38/0xd8
  2662.673415:   <2> [<ffffff8008c4f488>] snd_ctl_elem_info+0x40/0x11c
  2662.678799:   <2> [<ffffff8008c4df5c>] snd_ctl_ioctl_compat+0x3f4/0x740
  2662.684644:   <2> [<ffffff800823477c>] compat_SyS_ioctl+0x124/0xd88

There is no specific usecase when the issue is observed. Sometimes issue occurs during bootup and sometimes during audio usecase.

Kernel crash due to erase of program code [closed]

$
0
0

Assuming a code of a process can be erased at some random time, could this scenario lead to a kernel crush? I was thinking of such a scenario, where PC is updated to next command, the code of the program is erased, CPU loads an erased command to the CPU state. It seems like there shouldn't be a handler for this situation and therefore a crash, is this possible?

Error at Makefile No rule to make target 'syncconfig'

$
0
0

Dear Stackoverflow community,

Trying to build a wifi dongle driver I am having this issue. The source code is this: https://github.com/xtknight/mt7610u-linksys-ae6000-wifi-fixes

The problem at sudo make is saying:

#make
make -C tools
make[1]: Entering directory '/usr/src/mt7610u-linksys-ae6000-wifi-fixes/tools'
gcc -g bin2h.c -o bin2h
make[1]: Leaving directory '/usr/src/mt7610u-linksys-ae6000-wifi-fixes/tools'
/usr/src/mt7610u-linksys-ae6000-wifi-fixes/tools/bin2h
chipset = mt7610u
cp -f os/linux/Makefile.6 /usr/src/mt7610u-linksys-ae6000-wifi-fixes/os/linux/Makefile
make -C /lib/modules/5.4.0-3parrot1-amd64/build SUBDIRS=/usr/src/mt7610u-linksys-ae6000-wifi-fixes/os/linux modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-3parrot1-amd64'
  GEN     Makefile
make[4]: *** No rule to make target 'syncconfig'.  Stop.
make[3]: *** [/usr/src/linux-headers-5.4.0-3parrot1-common/Makefile:566: syncconfig] Error 2
/usr/src/linux-headers-5.4.0-3parrot1-common/Makefile:659: include/config/auto.conf.cmd: No such file or directory
make[2]: *** [/usr/src/linux-headers-5.4.0-3parrot1-common/Makefile:677: include/config/auto.conf.cmd] Error 2
make[1]: *** [/usr/src/linux-headers-5.4.0-3parrot1-common/Makefile:179: sub-make] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-3parrot1-amd64'
make: *** [Makefile:395: LINUX] Error 2

I did a make menuconfig and a make syncconfig but is not working. make: *** No rule to make target 'syncconfig'. Stop

autoconf is installed. Do I need to configure anything for it? The source code is for an older kernel, and I expected some problems that I was fixing (some paths). but at this point I cannot find what I'm missing. Thanks


Suse Linux kernel version

$
0
0

I am unable to understand the porting of patches from Linux kernel to Suse distribution. Looks like that the SuSE doesn't maintain the kernel version as per upstream, or have their own way of maintaining the kernel version.

For example, a change in the kernel API was done in the kernel as: File include/linux/fs.h in kernel version v4.13.16, is:

extern ssize_t kernel_write(struct file *, const char *, size_t, loff_t);

In kernel version v4.14 is:

extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);

The developers then can use the KERNEL_VERSION macro to distinguish which one to use.

#if KERNEL_VERSION(4, 14, 0) < LINUX_VERSION_CODE
      ret = kernel_write(file_ptr, &value, 1, &position);
#else
      ret = kernel_write(file_ptr, &value, 1, position);
#endif

However this does not work in SuSE kernel. I see that in the SuSE kernel version 4.12.14-195, the patch from v4.14 is included.

So how do driver developers cope with such mismatch? Is there a special macro used in SuSE linux?

How do you know what system call is invoked when an executable file is run? [closed]

$
0
0

If you open sublime-text in Linux Mint, which of exec() or system() gets called?

Executing boot ROM functions in Linux drivers

$
0
0

I'm trying to execute some functions from the boot ROM on an NXP IMX6UL in a Linux device driver. I figured a device driver is the only place I can get manage this.

Currently, I map the boot ROM using devm_ioremap_resource and I can read the ROM table in the device fine and it shows the values as expected. The problem comes when I try and execute a function from there, I get a paging request error and crash.

I get the following crash message:

Unable to handle kernel paging request at virtual address bf968f88
pgd = 8e5fa23c
[bf968f88] *pgd=b839e811, *pte=00008653, *ppte=00008453
Internal error: Oops: 8000000f [#1] PREEMPT ARM
Modules linked in:
CPU: 0 PID: 299 Comm: sh Not tainted 4.19.35-00007-ga99feb79b139-dirty #639
Hardware name: Freescale i.MX6 UltraLite (Device Tree)
PC is at 0xbf968f88
LR is at hab_rvt_entry+0x98/0xb4
pc : [<bf968f88>]    lr : [<804ee430>]    psr: 600f0033
sp : b9f85ea8  ip : 00000000  fp : 00000000
r10: b9e55e90  r9 : b9f85f78  r8 : b9a96800
r7 : 00000002  r6 : bf960000  r5 : 00008f89  r4 : bf968f89
r3 : fde952f0  r2 : fde952f0  r1 : 00000001  r0 : 00000000
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment none
Control: 10c53c7d  Table: b9ea8059  DAC: 00000051
Process sh (pid: 299, stack limit = 0x00d86b0c)
Stack: (0xb9f85ea8 to 0xb9f86000)
5ea0:                   00000002 b9e55e80 00000000 00000000 b9a96800 8027b3ec
5ec0: 00000000 00000000 81004048 8027b304 002478d0 b9f85f78 00000000 002478d0
5ee0: 00000002 802032c0 00002ee7 00000000 81004048 fde952f0 81004048 7e87c490
5f00: 00235a30 80208600 000007ff 00008180 00000001 00001000 00000000 00000000
5f20: 00000000 00000000 00002ee7 00000000 00000000 fde952f0 b98f1164 00000002
5f40: b9cbb840 002478d0 b9f85f78 00000000 002478d0 8020357c 5dca454a 00000000
5f60: 81004048 b9cbb840 00000000 00000000 b9cbb840 80203794 00000000 00000000
5f80: 00000000 fde952f0 00000002 002478d0 76ec0d98 00000004 80101204 b9f84000
5fa0: 00000004 80101000 00000002 002478d0 00000001 002478d0 00000002 00000000
5fc0: 00000002 002478d0 76ec0d98 00000004 002478d0 00000002 00000000 00000000
5fe0: 00000064 7e87c9d0 76de9ce0 76e42a74 600e0010 00000001 00000000 00000000
[<804ee430>] (hab_rvt_entry) from [<8027b3ec>] (kernfs_fop_write+0xe8/0x1c8)
[<8027b3ec>] (kernfs_fop_write) from [<802032c0>] (__vfs_write+0x2c/0x160)
[<802032c0>] (__vfs_write) from [<8020357c>] (vfs_write+0xa4/0x17c)
[<8020357c>] (vfs_write) from [<80203794>] (ksys_write+0x4c/0xac)
[<80203794>] (ksys_write) from [<80101000>] (ret_fast_syscall+0x0/0x54)
Exception stack(0xb9f85fa8 to 0xb9f85ff0)
5fa0:                   00000002 002478d0 00000001 002478d0 00000002 00000000
5fc0: 00000002 002478d0 76ec0d98 00000004 002478d0 00000002 00000000 00000000
5fe0: 00000064 7e87c9d0 76de9ce0 76e42a74
Code: ffc4 f7fd f833 e7fe (b5f0) b087

For reference and to make sense of these error messages a bit, BF960000 is what the base of my boot ROM is mapped to, and the address of the command I'm trying to execute is physically is at 8F89, virtually at BF968F89.

Is there any way to execute commands like this that exist in the boot ROM?

How do I take user command and implement it using exec function (linux) in order to create a shell? [closed]

$
0
0

I am trying to write a shell program

I need to implement something like -

1)cat input.txt

It should support any variation of command like ls -l and so on

I have a char** tokens which is storing the arguments passed by user on cmd line.

I wanted to know how to use exec() to execute the command. I am wondering if I should be passing exec tokens[0] as a command, but how I pass it other arguments followed by NULL?

User namespace - Why ecs_agent container launch as root owner?

$
0
0

Below is the ECS optimised AMI machine:

$ cat /etc/os-release
NAME="Amazon Linux AMI"
VERSION="2018.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2018.03"
PRETTY_NAME="Amazon Linux AMI 2018.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
$
$

Using UserData section of CloudFormation template, below configuration is enforced to configure user namespace in docker daemon:

$ echo testuser:165536:65536 > /etc/subuid
$ echo testuser:165536:65536 > /etc/subgid
$ echo '{"debug":true, "userns-remap":"testuser"}'> /etc/docker/daemon.json

but ecs_agent is still starting as root but not as testuser.


UserData section of cloud formation template runs at boot time of EC2 instance. /var/log/docker shows no error.

Why docker daemon in ECS instance launch ecs_agent as root owner? after configuring user namespace.....

How can i resolve this error in the script

$
0
0

expr: syntax error h2.sh: line 13: [: -gt: unary operator expected

#!/bin/sh


FILE=merchant.xml

OLDTIME=3600

CURTIME=$date
FILETIME=($date -r File)
TIMEDIFF=$(expr $CURTIME - $FILETIME)


if ["$TIMEDIFF" -gt "$OLDTIME" ]; then
   echo "File is older, do stuff here" | mail -s "hello" hardik.pahwa@guemstiger.de
fi

implicit declaration of blk_init_queue

$
0
0

I was trying to write a basic block driver following this link:

https://linux-kernel-labs.github.io/master/labs/block_device_drivers.html

I wrote the following code:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/blkdev.h>


MODULE_LICENSE("GPL");
#define BLK_DEV_NAME        "my_block"
#define MY_BLOCK_MINORS       1


int major;
struct gendisk *gd;
struct request_queue *queue;    /* The device request queue */
spinlock_t lock;                /* For mutual exclusion */


struct block_device_operations my_block_ops = {
    .owner = THIS_MODULE
};

static void my_block_request(struct request_queue *q)
{
    pr_info("%s\n", __func__);
}

static int test_hello_init(void)
{
    major = register_blkdev(0, BLK_DEV_NAME);
    pr_info("major = %d\n", major);
    spin_lock_init(&lock);
    queue = blk_init_queue(my_block_request, &lock);
    if (!queue) {
        pr_err("blk_init_queue failed\n");
        return -ENOMEM;
    }
    blk_queue_logical_block_size(queue, 512);
    gd = alloc_disk(MY_BLOCK_MINORS);   
    if (!gd) {
        pr_err("alloc_disk failure\n");
        return -ENOMEM;
    } 
    gd->major = major;
    gd->first_minor = 0;
    gd->fops = &my_block_ops;
    gd->queue = queue;
    snprintf (gd->disk_name, 32, "myblock");
    add_disk(gd);
    pr_info("adding disk successful\n");
    return 0;
}

static void test_hello_exit(void)
{
    unregister_blkdev(major, BLK_DEV_NAME);
    if (gd) {
        del_gendisk(gd);
    }
}
module_init(test_hello_init);
module_exit(test_hello_exit);

I get the following error when i compile the code:

error: implicit declaration of function ‘blk_init_queue’; did you mean ‘blk_put_queue’? [-Werror=implicit-function-declaration]
     queue = blk_init_queue(my_block_request, &lock);
             ^~~~~~~~~~~~~~
             blk_put_queue

Looks like this API has been removed from latest kernel version. Can anyone provide an alternative API or some reference for basic block driver.


Can't compile a module using buildroot

$
0
0

I need to compile a module with buildroot so I can debug it using QEMU+gdb, and the current guides don't work. I've tried the most basic forms according to the documentation and nothing worked. Maybe I'm missing something but I really can't see it now. I'm using the following:

Module dir contains these files:

  /home/xx/git/buildroot/package/kernel_module/
    Config.in
    hello.c
    kernel_module.mk
    Makefile

Config.in

1 config BR2_PACKAGE_KERNEL_MODULE
2         bool "kernel_module"
3         depends on BR2_LINUX_KERNEL

kernel_module.mk

1 KERNEL_MODULE_SITE = $(KERNEL_MODULE_PKGDIR)
2 KERNEL_MODULE_SITE_METHOD = local
3 $(eval $(kernel-module))
4 $(eval $(generic-package))

Makefile

    1 obj-m += hello.o
    2 ccflags-y := -DDEBUG -g -std=gnu99 -Wno-declaration-after-statement
    3 
    4 .PHONY: all clean
    5 
    6 all:
    7         $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules
    8 
    9 clean:
   10         $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean

hello.c

    1 #include <linux/module.h>
    2 #include <linux/kernel.h>
    3 
    4 MODULE_LICENSE("GPL");
    5 
    6 static int myinit(void)
    7 {
    8     printk(KERN_INFO "hello init\n");
    9     return 0;
   10 }
   11 
   12 static void myexit(void)
   13 {
   14     printk(KERN_INFO "hello exit\n");
   15 }
   16 
   17 module_init(myinit)
   18 module_exit(myexit)

I also edited the packages/Config.in to include the module path. I tried other responses on SO and none work.

Edit: To clarify, the module won't appear anywhere when I boot.

Thanks in advance for your help.

Copying more than 1 page size using sysfs from kernel space to user space

$
0
0

I have created a sysfs entry with store and show functions. I'd like to use show function to copy buffers of size > PAGE_SIZE from the kernel space to userspace.

I am able to currently copy buffers of size PAGE_SIZE from/to kernel space to/from userspace respectively.

Any tips on how we can do it will be really helpful. Can we loop this show function in any possible way?

Also, In case above is not possible. Can you please suggest alternative ways to do the same thing? (which can be done really quickly)

icmp_hdr is wrong on CentOS 6 kernels

$
0
0

I have a simple netfilter module to test icmp_hdr function:

unsigned int hook_func(
    unsigned int hooknum,
    struct sk_buff *skb,
    const struct net_device *in,
    const struct net_device *out,
    int (*okfn)(struct sk_buff *))
{    
    const struct iphdr *ip_header = ip_hdr(skb);
    if (ip_header && ip_header->protocol == IPPROTO_ICMP)
    {
        const struct icmphdr *icmp_header = icmp_hdr(skb);    
        printk(KERN_INFO "ICMP type %d", icmp_header->type);
    }

    return NF_ACCEPT;
}

static int __init startup(void)
{
    hook_ops.hook     = hook_func;
    hook_ops.hooknum  = NF_INET_PRE_ROUTING;
    hook_ops.pf       = PF_INET;
    hook_ops.priority = NF_IP_PRI_FIRST;

    nf_register_hook(&hook_ops);
    return 0;
}

Then I start to PING the HOST.

On CentOS 6 (2.6.32-754.12.1.el6.x86_64), he printed ICMP type is always 69 (INVALID).

On CentOS 7 (3.10) the result is ICMP_ECHO (8), which is correct.

Any ideas? Was there a bug in 2.6.32 kernel?

By only using system call to manipulate the data, is there a call that allows you to compare two strings with each other to see if they're the same? [closed]

$
0
0

I am going through the man on system calls for linux and am having a hard time figuring out how to compare two strings with each other. There is a way of comparing by byte length but how do you differentiate that "hello" and "roads" are not strings that contain the same characters in the same order even though they have the same byte length.

I am coding with C++ but am constricted to only using system calls to manipulate the data.

Linux driver disable_irq() board crash issue [closed]

$
0
0

I am working with touchscreen driver in Linux kernel 4.4 and trying to implement suspend functionality. I am using disable_irq() function to disable the particular IRQ in sleep, and I found that driver is implemented successfully but while device is going in sleep it crashes the entire system.

However there is a work-around by doing disable_irq_nosync() (I haven't seen any crash), but I want to implement the disabling IRQ functionality with disable_irq() only.

Viewing all 12308 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>