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

Malformed entry 2 in list file/etc/apt/sources.list

$
0
0

I am getting following error whenever i am going to update or do anything on my terminal of Linux mint.

malformed entry 2 in list file/etc/apt/sources.list.d/additional-repositories.list(suite)
the list of souces could not read

how to test a specific algorithm using tcrypt.ko module in linux kernel

$
0
0

I have noticed that there is a test module(tcrypt.c) in linux kernel crypto subsytem. I am able to use this module for any bench marking scenarios like aes with following command "modprobe tcrypt sec=1 mode=200"

But I am not able to test the individual algorithms using the same like below

"modprobe tcrypt mode=10 "

It throws an error "alg: skcipher: Failed to load transform for ctr(aes): -22"

when mode value is 0 it executes to test every algorithm till mode value reaches 200,almost every scenario it fails with similar type of error for respective algorithms like hash/hmac etc.

Please can any one let me know how this issue can be addressed?

BR, & sanumala

asmlinkage defined to nothing in linux code

$
0
0

I was looking into asmlinkage tag.

From https://kernelnewbies.org/FAQ/asmlinkage

This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack.

Looking into definition, it is defined to empty for x86_64

#ifdef __cplusplus
#define CPP_ASMLINKAGE extern "C"
#else
#define CPP_ASMLINKAGE
#endif

#ifndef asmlinkage
#define asmlinkage CPP_ASMLINKAGE
#endif

Also, i read that the ABI spec says that we should place system call number in a register, and paramters in some other registers.

Then why we are looking for function parameters in stack. Is system call number also placed in stack?

purpose of error injection macro in linux kernel

$
0
0

I have seen a macro ALLOW_ERROR_INJECTION which is used in SYSCALL_DEFINEx

#ifdef CONFIG_FUNCTION_ERROR_INJECTION
/*
 * Whitelist ganerating macro. Specify functions which can be
 * error-injectable using this macro.
 */
#define ALLOW_ERROR_INJECTION(fname, _etype)                            \
static struct error_injection_entry __used                              \
        __attribute__((__section__("_error_injection_whitelist")))      \
        _eil_addr_##fname = {                                           \
                .addr = (unsigned long)fname,                           \
                .etype = EI_ETYPE_##_etype,                             \
        };
#else
#define ALLOW_ERROR_INJECTION(fname, _etype)
#endif
#endif

Can anyone provide me enough documentation on this.

What is the use of it. What is whitelist

Getting error when compiling kernel for page table walk

$
0
0

I am doing a page table walk. When I am getting ready to update the kernel I get an error:

./arch/x86/include/asm/pgtable.h:988:40: warning: right shift count >= width of type [-Wshift-count-overflow]
 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
                                        ^
./arch/x86/include/asm/pgtable.h:994:45: note: in expansion of macro ‘pgd_index’
 #define pgd_offset_pgd(pgd, address) (pgd + pgd_index((address)))
                                             ^
./arch/x86/include/asm/pgtable.h:998:33: note: in expansion of macro ‘pgd_offset_pgd’
 #define pgd_offset(mm, address) pgd_offset_pgd((mm)->pgd, (address))
                                 ^
kernel/sys.c:2733:19: note: in expansion of macro ‘pgd_offset’
      pgd_t *pgd = pgd_offset(task_mm, vmpage);
                   ^
kernel/sys.c:2734:30: error: passing argument 1 of ‘pud_offset’ from incompatible pointer type [-Werror=incompatible-pointer-types]
      pud_t *pud = pud_offset(pgd, vmpage);
                              ^
In file included from ./include/linux/mm.h:99:0,
                 from kernel/sys.c:19:
./arch/x86/include/asm/pgtable.h:905:22: note: expected ‘p4d_t * {aka struct <anonymous> *}’ but argument is of type ‘pgd_t * {aka struct <anonymous> *}’
 static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
                      ^

This is where the code is being used:

....
struct mm_struct *task_mm;
    if ((task_mm = task->mm))
    {
        vma = task_mm->mmap;
        while (vma)
        {
            for (int i = 1, vmpage = vma->vm_start; vmpage < vma->vm_end; vmpage += PAGE_SIZE, i++)
            {
                pgd_t *pgd = pgd_offset(task_mm, vmpage);
                pud_t *pud = pud_offset(pgd, vmpage);
                pmd_t *pmd = pmd_offset(pud, vmpage);
                pte_t *ptep = pte_offset_kernel(pmd, vmpage);
                pte_t pte = *ptep;
                ...

I looked up the errors and notes but didn't find anything about resolving this problem. Is this a well known problem or am I doing something wrong?

what's the execution order of multiple child processes

$
0
0

use the follwing code to fork four chile processes

#define _GNU_SOURCE
#include  <stdio.h>
#include  <unistd.h>
#include  <sys/wait.h>
#include  <stdlib.h>

pid_t pid;
int child(int id);

int main(void)
{
    int cpus = 0; 
    cpus = sysconf(_SC_NPROCESSORS_CONF);
    printf("cpu number %ld\n",cpus);

    if ((pid = fork())==0)
        child(1);  
    if ((pid = fork())==0)
        child(2);
    if ((pid = fork())==0)
        child(3);
    if ((pid = fork())==0)
        child(4);

    printf("fork over\n");
    int i,status;  
    for (i=0;i<4;i++)
    { 
    pid = wait(&status);
    }
    exit(0);
}

int child(int id)
{
    printf("child %d is running!pid :%d\n",id,getpid());
    exit(id);
}

I run that code in vmware and I set the cpu num to 1.
The expected output is the first child is the first to exectue. But the real output is on the contrary.

output: fork over
child 4 is running!pid :4258
child 3 is running!pid :4257
child 2 is running!pid :4256
child 1 is running!pid :4255

They are normal processes so the scheduling algorithm is CFS.
The process which has min vruntime should run first.
Obviously the child 1's vruntime is smaller than others.
So it's so confusing to get such output. I hope someone can help me to figure out it.

The Linux distribution is Ubuntu 16.04
The kernel version is 4.4

How can I access or enumerate available LEDs from kernel code (BeagleBone Black)?

$
0
0

I am trying to write a custom syscall handler that manipulates the LEDs on a BeagleBone Black board. I have gone through the kernel LED API (include/leds.h), but I am unable to find anything that'd give me a handle to the available LED devices or some other mechanism to manipulate (on/off/toggle) them. Most of the functions seem to require a led_classdev object, but I can't find a way of getting one.

I can do this from userspace using the /sys/class/leds/... interface. But I want to do something similar from kernel space. I am open to hard-coding any device names specific to BeagleBone Black as portability is not an issue.

How does a file transfer over the internet work?

$
0
0

As soon as the network card receives a packet that is a response to file request, is it passed on to the memory, or is it passed onto the hard disk directly? I guess, dma-buf and such provisions in the kernel are fundamentally intended to take care of such situations. Also when a static file is sent over the network, is there some provision by which it can avoid the detour to the main-memory and directly make its way from the hard disk to the network card?


adding i2c client devices on x86_64

$
0
0

On my x86_64 board, there is i2c-bus coming out of a MFD device. There are devices on to this i2c-bus. I am able to detect these devices using i2cdetect program.

# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- 4c -- -- -- 
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

I need the kernel to detect these devices automatically, So, I tried writing i2c_board_info as in given below code, But still, the kernel is not able to detect these devices automatically.

#include <linux/init.h>
#include <linux/i2c.h>

#define BUS_NUMBER      0

static struct __init i2c_board_info tst_i2c0_board_info[]  = {                   
    {
        I2C_BOARD_INFO("ltc2990", 0x4c),
    },
    {
        I2C_BOARD_INFO("24c128", 0x57),
    },
};

static int tst_i2c_board_setup(void)
{
    int ret=-1;
    ret = i2c_register_board_info(BUS_NUMBER, tst_i2c0_board_info, ARRAY_SIZE(tst_i2c0_board_info));
    return ret;
}
device_initcall(tst_i2c_board_setup);

Any suggestions on how can I solve this ?

Wrong Return Value for I2C_SLAVE and I2C_RDWR on Raspberry pi

$
0
0

I am using Raspberry pi for I2C communication to a chip.

The I2C Runs on i2c-1 and the chip I want to communicate is mux0 for which the address is specified. I used a wrong address to see what value I get from I2C_SLAVE and I2C_RDWR.

I want to check if the I'm opening correct bus or not. So I'm using the if statement and it's working fine for me. `

int file;
file = open(i2c_adapt, O_RDWR);
if (file == -1)
  {
    perror("Check I2C Bus");
    exit(1);
  }

`

Then I saw there are two functions I can use to define the chip address. I2C_SLAVE and I2C_RDWR.

I want to check if the chip address is correct or not but both of them return same values.

I printed their return value to check.

`

printf("\nThe file value when Mux0 is %d", open("/dev/i2c-1", O_RDWR));
printf("\nThe file value of random bus is %d\n", open("/dev/i2c-0", O_RDWR));
printf("\nThe i2c_Slave value when Mux0 is %d", ioctl(file, I2C_SLAVE, mux0));
printf("\nThe i2c_Slave value of random address is %d\n\n", ioctl(file, I2C_SLAVE, 0x60));
printf("\nThe I2C_RDWR value when Mux0 is %d", ioctl(file, I2C_RDWR, mux0));
printf("\nThe i2c_RDWR value of random address is %d\n\n", ioctl(file, I2C_RDWR, 0x60));

When I run these commands I get the following values:

The file value when Mux0 is 4 The file value of random bus is -1

so I can use if statement to see if I'm using wrong bus

The i2c_Slave value when Mux0 is 0 The i2c_Slave value random address is 0

The i2c_RDRW value when Mux0 is -1 The i2c_RDRW value of random address is -1enter image description here

Can someone tell me why I'm getting same value for wrong chip as well?

undefined reference to `__kmalloc'

$
0
0

While compiling code that uses the SCTP kernel header <sctp/chunk.h>I got a puzzling compiler error(with blue text instead of read) that was trigged by the calling of the kmalloc function whose prototype is defined in <linux/slob-def.h>. Here is the function that caused it:

/* Allocate and initialize datamsg. */
SCTP_STATIC struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
{
    struct sctp_datamsg *msg;
    msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
    if (msg) {
        sctp_datamsg_init(msg);
        SCTP_DBG_OBJCNT_INC(datamsg);
    }
    return msg;
}

The gcc error message(compiling in native C):

/tmp/ccKDKVjf.o: In function `sctp_datamsg_new':
s.c:(.text+0x2215): undefined reference to `__kmalloc'
collect2: error: ld returned 1 exit status

So what I'm wondering is if the kmalloc function source code properly defined(or not actually implemented at all, or if code that calls this function can only be compiled in kernel mode. I was not actually trying to build an output file(yet), the compile command I issued in Emacs was: gcc s.c (where s.c is the .c file that contains the <sctp/chunk.h> header — just trying to make sure everything compiles properly before building an output file).

Wrong Return Value of I2C_SLAVE on Raspberry pi

$
0
0

My device address is 0x70.

If I do

ioctl(file, I2C_SLAVE, 0x70));

it returns me 0 which is fine.

But if I give a wrong address:

ioctl(file, I2C_SLAVE, 0x00));

it still returns me a 0 instead of -1.

If I use a very big number it returns me -1.

Can someone help me what I'm doing wrong?

How to generate network impairments only on udp packets in linux

$
0
0

I'm trying to generate impairments on my linux ubuntu 18.04 and use it as a hotspot to affect a mobile app with those impairments but I need it to affect only the UDP traffic.

I'm trying to test my app under bad network and when the test is done I want the app to upload the results, this flow should run in a loop so i can't switch networks between each iteration. The problem is that linux tc using netem generates impairments both on TCP connections and UDP connections and I'm using the TCP connection for collecting the test results so the results are malformed or not coming at all.

I used it like this:

tc qdisc add dev <name> root netem delay XXms loss gemodel 20% 30% 1% 15%

do you know if there is a way to limit the tc using netem or any other way to affect only UDP packets?

Unexpected IOCTL sent to my uclinux (ARM) driver(s)

$
0
0

Having written my character drivers to use .unlocked_ioctl and a user-space app to test them I am getting an unexpected call to the ioctl function when the devices are opened from user-space.

The driver and app both use the same header file where I define "my" identifying character to be '8'. A dev-err output message from the driver shows that the unexpected ioctl identifying character is 'T' (see below).

When running the test app, which opens both drivers but only targets one based on the command line arguments, the unexpected ioctl call shows up for each driver.

I wondered about a 'debug' kernel configuration for ioctl but could not find any setting like that.

The header file has the following:

#define RLY_IOCTL_BASE  '8'
#define IOC_RLY_GETLAST _IOR(RLY_IOCTL_BASE, 0, u8)
#define IOC_RLY_SETRELAYS _IOW(RLY_IOCTL_BASE, 1, u8)

The driver source has this in their respective ioctl callback functions:

if (_IOC_TYPE(cmd) != RLY_IOCTL_BASE) {
    dev_err(&RLYspi->dev,
        "IOCTL: cmd is not for us! (Ty=%c, num=%d, size=%d, dir=%d)\n",
            _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd));
    return -EINVAL;
}
dev_info(&RLYspi->dev, "IOCTL: cmd num-%d, size=%d, dir=%x\n",
                            _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd));

switch (cmd)

And the user-space test application has this for opening the /dev/x drivers to get file handles and descriptors:

afe_fp = fopen(AFE_DEVICE_NAME, "r");
if (NULL == afe_fp) {
    printf ("Could not open device %s!\n", AFE_DEVICE_NAME);
    return 1;
}

afe_fd = fileno (afe_fp);       /* Gets the file descriptor from fp */

/* Open dev/ame_sq_rly */
rly_fp = fopen(RLY_DEVICE_NAME, "r");
if (NULL == rly_fp) {
    printf ("Could not open device %s!\n", RLY_DEVICE_NAME);
    return 1;
}

rly_fd = fileno (rly_fp);       /* Gets the file descriptor from fp */

The calls are like this from the test application based on the command line arguments (one command shown):

if (IOBase == 8) {
    /* driverapp r b (read_command) */
    else if ((argc == 3) && ((argv[1][0] == 'r') || (argv[1][0] == 'R'))){
        ret = ioctl(rly_fd, IOC_RLY_GETLAST, &RlyVal);
        if (ret < 0) {
            perror("ioctl('IOC_RLY_GETLAST')");
            exit (EXIT_FAILURE);
        }

        printf ("Relay shifter last value: 0x%02X\n", RlyVal);
        return 0;
    }
}

I expect to just get the output from the accepted command from the driver (dev_info) and then the output from the printf in the test application.

When the driverapp (test application) is run I get the following console output:

# driverapp r 8
<device A info>: IOCTL: cmd is not for us! (Ty=T, num=1, size=0, dir=0)
<device B info>: IOCTL: cmd is not for us! (Ty=T, num=1, size=0, dir=0)
<device B info>: IOCTL: cmd num-0, size=1, dir=2
Relay shifter last value: 0x00
#

Both drivers (shown as 'device A' and 'device B' above) are called with the unexpected ioctl call on device open. I tested this by just opening one of the devices instead of both and I only get one unexpected ioctl call for the driver that was opened.

Where are the two unexpected 'T' ioctl commands coming from?

Many thanks for any information.

I am working on one project where i have to read temperature from soc temperature sensors

$
0
0

I am working on one project where I want to read the temperature from userspace for soc temperature sensors. I have register addresses from where I can read the values.

I have the following questions.
1. How to use these register addresses to read the temperature in Linux.
2. I studied that sys/class/thermal/ is used to read temp. from userspace. But in my project there is no /thermal exist. So should I have to enable it?

So my questions are how to use these register and how to read it from userspace. As I am new to Linux world. Can anyone help me out on how to proceed with this?


Linux Module Programming fails and caught in loop

$
0
0

OK, So I am programming this for a HW assignment but could either use some help or insight. I know I've read everywhere that you shouldnt open files in modules but its our assignment...

Anyway my module code is here: http://pastebin.com/LU8hWraL

and my user level code is here: http://pastebin.com/RC0Zk1kQ

Ok, my issue is that sometimes it works, other times it doesnt... most of the time when it doesnt work, it catches in a loop on the kernel and I dont understand what is causing the issue and how I can resolve it. Any help on this situation would be incredibly appreciated, I just am getting frustrated having to constantly shut down and restart my VM.

Even if someone tells me how to find the error when my VM loops like that...?

Guide build kubernetes on custom OS [closed]

$
0
0

Context: I have built my own OS linux based, with specific kernel modifications with docker available.
Aim: I would like to use this custom OS like a node in k8s, so i have to install k8s on it.

Is there any guide, checklist, recommendations, requirements for what does k8s need from the OS kernel to be installed?

I would like to know what requirements have k8s to make my custom linux based OS compilant with it.

Understanding pmap output for Linux 5.0 kernel and pmap version 3.3.12

$
0
0

I have pmap output as follows:

$ pmap -X `pidof a.out`
6148:   ./a.out
         Address Perm   Offset Device   Inode Size  Rss Pss Referenced Anonymous LazyFree ShmemPmdMapped Shared_Hugetlb Private_Hugetlb Swap SwapPss Locked THPeligible Mapping
    55d5afaea000 r-xp 00000000  08:05 1459416    4    4   4          4         0        0              0              0               0    0       0      0           0 a.out
    55d5afcea000 r--p 00000000  08:05 1459416    4    4   4          4         4        0              0              0               0    0       0      0           0 a.out
    55d5afceb000 rw-p 00001000  08:05 1459416    4    4   4          4         4        0              0              0               0    0       0      0           0 a.out
    55d5b00ff000 rw-p 00000000  00:00       0  132    4   4          4         4        0              0              0               0    0       0      0           0 [heap]
    7fe235546000 r-xp 00000000  08:05 8524447 1948 1064   7       1064         0        0              0              0               0    0       0      0           0 libc-2.27.so
    7fe23572d000 ---p 001e7000  08:05 8524447 2048    0   0          0         0        0              0              0               0    0       0      0           0 libc-2.27.so
    7fe23592d000 r--p 001e7000  08:05 8524447   16   16  16         16        16        0              0              0               0    0       0      0           0 libc-2.27.so
    7fe235931000 rw-p 001eb000  08:05 8524447    8    8   8          8         8        0              0              0               0    0       0      0           0 libc-2.27.so
    7fe235933000 rw-p 00000000  00:00       0   16   12  12         12        12        0              0              0               0    0       0      0           0 
    7fe235937000 r-xp 00000000  08:05 8524419  156  156   1        156         0        0              0              0               0    0       0      0           0 ld-2.27.so
    7fe235b24000 rw-p 00000000  00:00       0    8    8   8          8         8        0              0              0               0    0       0      0           0 
    7fe235b5e000 r--p 00027000  08:05 8524419    4    4   4          4         4        0              0              0               0    0       0      0           0 ld-2.27.so
    7fe235b5f000 rw-p 00028000  08:05 8524419    4    4   4          4         4        0              0              0               0    0       0      0           0 ld-2.27.so
    7fe235b60000 rw-p 00000000  00:00       0    4    4   4          4         4        0              0              0               0    0       0      0           0 
    7fff98249000 rw-p 00000000  00:00       0  132   12  12         12        12        0              0              0               0    0       0      0           0 [stack]
    7fff9837b000 r--p 00000000  00:00       0   12    0   0          0         0        0              0              0               0    0       0      0           0 [vvar]
    7fff9837e000 r-xp 00000000  00:00       0    4    4   0          4         0        0              0              0               0    0       0      0           0 [vdso]
ffffffffff600000 r-xp 00000000  00:00       0    4    0   0          0         0        0              0              0               0    0       0      0           0 [vsyscall]
                                              ==== ==== === ========== ========= ======== ============== ============== =============== ==== ======= ====== =========== 
                                              4508 1308  92       1308        80        0              0              0               0    0       0      0           0 KB 

The manual page has no information regarding what the columns mean. Other questions on stackoverflow pertain to some different or older version of pmap. This link https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/ seems to be a good resource, but it doesn't cover everything.

I want to understand what the column headers signify in the pmap output.

Writing device driver for embedded boards

$
0
0

I am a newbie to embedded world. I am trying to write device drivers on Embedded Linux Systems which built using Yocto project. I don't exactly know how linux drivers work and how to write a new driver for testing a peripheral.

In my products documentation, in page 569 - 1199 there is a section called "Linux Kernel Drivers". It's describing device tree sources and variables of drivers for interested hardware(PCIE,SPI....). What i understood for now is, product owner has already written some functions to reach peripheral hardware and all i have to do is reaching them with calling some special functions using its .c files.

I am here to ask stackoverflow professionals that, am I thinking right or am I on the right way? and also any suggestions for writing device drivers for a special product?

How to automatically run 'sudo modprobe -r ftdi_sio' whenever the device is plugged into my computer

$
0
0

I have a USB device that I'm using and I'm developing an application using WebUSB with Google Chrome. The thing is whenever I plug the USB device into my Linux computer, I have to manually run 'sudo modprobe -r ftdi_sio' to unload it.

I want it to be unloaded automatically whenever I plug that device into my computer instead of having to type it manually every single time.

Any ideas on how this could be implemented ? Help would be much appreciated

I thought this would've been an easy thing to find online but I couldn't find something like this anywhere

Viewing all 12296 articles
Browse latest View live


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