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

I can't dump a stacktrace when i use linux trace event triggers

$
0
0

The kernel document 'tracing: trace event triggers' said i can use stacktrace cmd to dump a stacktrace to the trace buffer whenever the trigger event is hit. But all i got is a simple string "stacktrace".Here is my configure:

cd /sys/kernel/debug/tracing/events/sched/sched_switch

echo 1 > enable

echo 'stacktrace'> trigger

cat trigger

stacktrace:unlimited

When i Looking at the 'trace' output, here is what i saw:

    kworker/u2:0-4002  [000] d... 1275475.478000: sched_switch: prev_comm=kworker/u2:0 prev_pid=4002 prev_prio=120 prev_state=S ==> next_comm=sshd next_pid=3048 next_prio=120kworker/u2:0-4002  [000] d... 1275475.478000: <stack trace>        sshd-3048  [000] d... 1275475.478000: sched_switch: prev_comm=sshd prev_pid=3048 prev_prio=120 prev_state=S ==> next_comm=vim next_pid=4059 next_prio=120        sshd-3048  [000] d... 1275475.478000: <stack trace>         vim-4059  [000] d... 1275475.479000: sched_switch: prev_comm=vim prev_pid=4059 prev_prio=120 prev_state=R ==> next_comm=rcu_sched next_pid=8 next_prio=120         vim-4059  [000] d... 1275475.479000: <stack trace>   rcu_sched-8     [000] d... 1275475.479000: sched_switch: prev_comm=rcu_sched prev_pid=8 prev_prio=120 prev_state=S ==> next_comm=vim next_pid=4059 next_prio=120   rcu_sched-8     [000] d... 1275475.479000: <stack trace>         vim-4059  [000] d... 1275475.481000: sched_switch: prev_comm=vim prev_pid=4059 prev_prio=120 prev_state=R ==> next_comm=rcu_sched next_pid=8 next_prio=120         vim-4059  [000] d... 1275475.481000: <stack trace>   rcu_sched-8     [000] d... 1275475.481000: sched_switch: prev_comm=rcu_sched prev_pid=8 prev_prio=120 prev_state=S ==> next_comm=vim next_pid=4059 next_prio=120   rcu_sched-8     [000] d... 1275475.481000: <stack trace>         vim-4059  [000] d... 1275475.482000: sched_switch: prev_comm=vim prev_pid=4059 prev_prio=120 prev_state=R ==> next_comm=rcu_sched next_pid=8 next_prio=120         vim-4059  [000] d... 1275475.482000: <stack trace>   rcu_sched-8     [000] d... 1275475.482000: sched_switch: prev_comm=rcu_sched prev_pid=8 prev_prio=120 prev_state=S ==> next_comm=vim next_pid=4059 next_prio=120   rcu_sched-8     [000] d... 1275475.482000: <stack trace>         vim-4059  [000] d... 1275475.483000: sched_switch: prev_comm=vim prev_pid=4059 prev_prio=120 prev_state=R+ ==> next_comm=rcu_sched next_pid=8 next_prio=120         vim-4059  [000] d... 1275475.483000: <stack trace>   rcu_sched-8     [000] d... 1275475.483000: sched_switch: prev_comm=rcu_sched prev_pid=8 prev_prio=120 prev_state=S ==> next_comm=ksoftirqd/0 next_pid=7 next_prio=120   rcu_sched-8     [000] d... 1275475.483000: <stack trace> ksoftirqd/0-7     [000] d... 1275475.483000: sched_switch: prev_comm=ksoftirqd/0 prev_pid=7 prev_prio=120 prev_state=S ==> next_comm=rcu_sched next_pid=8 next_prio=120 ksoftirqd/0-7     [000] d... 1275475.483000: <stack trace>   rcu_sched-8     [000] d... 1275475.483000: sched_switch: prev_comm=rcu_sched prev_pid=8 prev_prio=120 prev_state=S ==> next_comm=vim next_pid=4059 next_prio=120   rcu_sched-8     [000] d... 1275475.483000: <stack trace>

How do I make it so that stacktrace dump all the stack traces.


How does this enumeration work in this driver?

$
0
0

As I was studying the code of the mxs-auart.c driver I noticed the following declaration:

enum mxs_auart_type {    IMX23_AUART,    IMX28_AUART,    ASM9260_AUART,};

and then later on:

static const struct platform_device_id mxs_auart_devtype[] = {    { .name = "mxs-auart-imx23", .driver_data = IMX23_AUART },    { .name = "mxs-auart-imx28", .driver_data = IMX28_AUART },    { .name = "as-auart-asm9260", .driver_data = ASM9260_AUART },    { /* sentinel */ }};MODULE_DEVICE_TABLE(platform, mxs_auart_devtype);static const struct of_device_id mxs_auart_dt_ids[] = {    {        .compatible = "fsl,imx28-auart",        .data = &mxs_auart_devtype[IMX28_AUART]    }, {        .compatible = "fsl,imx23-auart",        .data = &mxs_auart_devtype[IMX23_AUART]    }, {        .compatible = "alphascale,asm9260-auart",        .data = &mxs_auart_devtype[ASM9260_AUART]    }, { /* sentinel */ }};MODULE_DEVICE_TABLE(of, mxs_auart_dt_ids);

The thing I don't understand about this is how can IMX28_AUART, for example, be used like .data = &mxs_auart_devtype[IMX28_AUART]. Don't we have to instanciate a variable beforehand to use the enum values by doing as an example enum mxs_auart_type value = IMX28_AUART?I am aware that in enumerations in C, values are equal to integer starting by default at 0 but I can't help but feel confused about this.

Can anyone help me understand this a bit better?Thanks

Linux: How to find the list of daemon processes and zombie processes

$
0
0

I tried checking on Google, but I couldn't find much information related to the actual question.

How do I get a consolidated list of zombie processes and daemon processes?How do I do it on different operating systems. Linux? AIX? Windows?

I am sure that, based on PID, we cannot identify the type of process. Running through a terminal might not help either.

Why struct linux_dirent members ( d_name, d_reclen, .. ) always getting 0?

$
0
0

This is for educational purposes and I'm new in kernel programming. I'm trying to override sys_call_table[__NR_getdents] with my custom function. The goal of my custom function is to read all the files of my current directory. In man-pages, it says that d_name is the file name and d_reclen is the size of the struct. Form the example code and googling, I understand that to get the next file name, I need to add d_reclen (offset) with the existing structure obj. Keep looping will give me the list of all files in the current directory. Please do correct if understanding is flawed.

However, this is not happening. Here is my Structure,

struct linux_dirent {unsigned long   d_ino;unsigned long   d_off;unsigned short  d_reclen; char        d_name[];};

Here is my custom function to replace sys_call_table[__NR_getdents]

asmlinkage int ( *orig_getdents )(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count);asmlinkage int sys_getdents_new(unsigned int fd, struct linux_dirent __user *dirent, unsigned int count) {struct linux_dirent *retn; int r, RemainingBytes;r = (*orig_getdents)(fd, dirent, count);printk(KERN_INFO "Inside sys_getdents_new, Total Bytes : %d", r);retn = (struct linux_dirent *) kmalloc(r, GFP_KERNEL);printk(KERN_INFO "length retn->d_reclen %hu", retn->d_reclen);printk(KERN_INFO "retn->d_ino %lu", retn->d_ino);printk(KERN_INFO "retn->d_off %lu", retn->d_off);RemainingBytes = r;int i=10;//while(RemainingBytes > 0){ // runs infinitely as RemainingBytes never decreasedwhile(i > 0){        RemainingBytes -= retn->d_reclen;               printk(KERN_INFO "Remaining Bytes %d   \t File: %s " ,  RemainingBytes , retn->d_name );    retn = (struct linux_dirent *) ((char *)retn + retn->d_reclen);    printk(KERN_INFO "New retn->d_reclen: %d", retn->d_reclen);    i--;}return r;}

Here is the error screenshot that I'm getting.

error screenshot

As you can see, all the members of the linux_dirent are showing 0 which is not expected. Therefor inside while loop nothing is changing. Any Idea what I did wrong? Please help

Unable to boot 64-bit kernel after installation

$
0
0

My system supports 64-bit architecture and I am able to use debian-buster meant for amd64 architecture separately. Now, I have an os running debian-buster having kernel as "linux-image-686-pae". I want it to use the kernel "linux-image-amd64:amd64". For that, I updated the system using apt update then I installed the other kernel using apt-get install linux-image-amd64:amd64. Then on rebooting I chose the amd64 version from the grub menu. It prints the list for starting various processes, but it just halts at that and doesn't progress further. It halts at the starting processes list printing screen. I am unable to configure the problem. Any help or suggestion is appreciated.

MAP_DENYWRITE option of mmap was a source of denial-of-service attacks?

$
0
0

The man page of mmap function mentioned MAP_DENYWRITE can cause denial-of-service attacks. But why?

MAP_DENYWRITE This flag is ignored. (Long ago, it signaled that attempts to write to the underlying file should fail with ETXTBUSY. But this was a source of denial-of-service attacks.)

How does `cpupower frequency-set -g performance` work?

$
0
0

I looked at the source code, and I don't see exactly how to tell the cpu to stay at highest possible frequency. Through interrupt? Some dummy workload? or?

Any pointer would be highly appreciate.

How to find the LLC size and BW peak from the Linux kernel

$
0
0

I need to know the size of the system's Last Level Cache from a kernel module as well as the capacity of the Bandwidth in between L3 and Main Memory.

Does any struct store such information within the kernel? It would be fantastic if I can find it digging somewhere within a given task_struct instead of with some extra library, but that is also ok.


missing MODULE_LICENSE() when two module using same object file

$
0
0

I have two files:main.c will become module calc, it will use API in expression.c.livepatch-calc.c will become module livepatch-calc.

I have following makefile and work well

obj-m += calc.oobj-m += livepatch-calc.ocalc-objs += main.o expression.occflags-y := -std=gnu99 -Wno-declaration-after-statement

Currently, I need call expression's API in livepatch-calc.c. So, I have new makefile like:

obj-m += calc.oobj-m += livepatch-calc.ocalc-objs += main.o expression.olivepatch-calc-objs += expression.occflags-y := -std=gnu99 -Wno-declaration-after-statement

Unfortunately, when I make it. Warning message show up:

WARNING: modpost: missing MODULE_LICENSE() in ..../livepatch-calc.o

I wondering are there anything wrong in my makefile?

What is the difference between DMA and memory-mapped IO?

$
0
0

What is the difference between DMA and memory-mapped IO? They both look similar to me.

Simple SPI device driver

$
0
0

I have written a simple driver for a character device in Non Blocking mode using epoll.Now I would like to use that driver for SPI interface.

What should be the device name or how will I map the actual device with the kernel ? How will I use the interrupt?

Also who is the Master and Slave?Suppose I am connecting a SPI compatible device to the panda board.Will that device becomes a slave and the development board becomes Master?

I am a newbie.I am using a panda board.In what way should I go through the Technical Reference manual?

I would really appreciate if anybody would explain and clarify my doubts.

aarch64-linux-gnu-ld: no input files

$
0
0

In general, I restarted the collection and the log is the following:

root@W-PC:/home/w-pc/kernel_dev/android_kernel_huawei_hi6210sft# make -j5CHK     include/generated/uapi/linux/version.hCC      scripts/mod/devicetable-offsets.sGEN     scripts/mod/devicetable-offsets.hHOSTCC  scripts/mod/file2alias.oCHK     include/generated/utsrelease.hCALL    scripts/checksyscalls.shHOSTLD  scripts/mod/modpostCHK     include/generated/compile.hLD      init/mounts.o/home/w-pc/kernel_dev/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ld: no input filesmake[1]: *** [scripts/Makefile.build:454: init/mounts.o] Ошибка 1 (Error 1)make[1]: *** Ожиданиезавершениязаданий…(Waiting for tasks to complete...)LD      arch/arm64/crypto/sha1-ce.o/home/w-pc/kernel_dev/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ld: no input filesmake[1]: *** [scripts/Makefile.build:454: arch/arm64/crypto/sha1-ce.o] Ошибка 1make: *** [Makefile:883: arch/arm64/crypto] Ошибка 2make: *** Ожиданиезавершениязаданий… (Waiting for tasks to complete...)make: *** [Makefile:883: init] Ошибка 2 (Error 2)CHK     kernel/config_data.hroot@W-PC:/home/w-pc/kernel_dev/android_kernel_huawei_hi6210sft# 

Google has not yet given any solutions ...As for the line numbers of Makefile, then they are like this:

scripts / Makefile.build

454: $ (call if_changed, link_multi-y)

line 883 is not in this macafile (makefile)

line 454 in the kernel directory is like this:

export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE

line 883 should be like this:

$ (Q) $ (MAKE) $ (build) = $ @

In the makefile along the path arch/arm64/crypto there are no lines with such numbers.

Postscript: It is not clear how the kernel was under 4.0 EMUI, but this is under 4.1. Yes, that is right, it stayed the same... weird.

Please help me fix this issue.

Vim configuration for Linux kernel development [closed]

$
0
0

Kernel development is actually different from a traditional C project development (from my view, as a newbie). So, I always wonder what is the vim configuration of a kernel hacker.

The most important is that how to navigate kernel source tree in vim.. I tried ctags, however, it works terribly.

Can someone give me a clue?

Understanding how the copying of the compressed Linux kernel works in head_64.S

$
0
0

I am working on understanding how the Linux kernel v3.19 prepares for decompression on a machine with x86_64 architecture in arch/x86/boot/compressed/head_64.S. The part that is confusing me is the copying of the compressed kernel image to another location in memory before decompression takes place. I have copied the code below with my understanding of each line; the lines with // ? comments are the ones I am having trouble with.

/* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe. */    pushq   %rsi  // %rsi contains the pointer to `boot_params`    leaq    (_bss-8)(%rip), %rsi  // ?    leaq    (_bss-8)(%rbx), %rdi  // ?    movq    $_bss /* - $startup_32 */, %rcx  // ?    shrq    $3, %rcx  // ?    std           // set the direction so %rsi and %edi are decremented    rep movsq     // copy data from %rsi to %rdi 8 bytes at a time    cld           // clear the direction flag    popq    %rsi  // restore pointer to `boot_params`

I know that at this point %rbx contains the location where the kernel will be relocated for decompression and that %rbp (while not mentioned in this code snippet) contains the location the kernel was loaded at runtime. Further, I am aware that _bss refers to the start of the .bss section as given by the linker script in arch/x86/boot/compressed/vmlinux.lds.S, and that the compressed kernel image that we want to copy is at .rodata..compressed, which sits between .head.text and .text (where we are currently, I believe).

What I am not following and need help with is:

  1. What section does _bss-8 refer to?

  2. This may become clear once I understand what _bss-8 is, but how does (_bss-8)(%rip) and (_bss-8)(%rbx) give us where the compressed kernel currently is and where it is going?

  3. Why are we putting $_bss >> 3 into %rcx as the counter for copying data? Why not something related to rodata..compressed?

Write into /sys/bus/usb/drivers_probe with C++ application

$
0
0

I am trying to make C/C++ application which should block some USB devices.

I have similar problem described here, but now I need to implement that solution into C++. I just need to write some string into /sys/bus/usb/drivers_probe. I tried something like:

ofstream fDriversProbe;fDriversProbe.open("/sys/bus/usb/drivers_probe", ios::out | ios::binary | ios::app);if(!fDriversProbe){   cout << "Could not open file drivers_probe.";}fDriversProbe.write("1-1:1.1", strlen("1-1:1.1"));if(!fDriversProbe.good()){   cout << "Could not write data to file\n";}

which do not bring any errors or warnings but also do not seems to be working.

Then I decided to execute working command from code.

system("sudo sh -c \"echo 1-1:1.1 > /sys/bus/usb/drivers_probe\"");

or

system("echo 1-1:1.1 | sudo tee /sys/bus/usb/drivers_probe");

with no luck. When I do the same command (with same interface) manually from terminal, everything is working fine and USB device start to work.


How do I write a Linux device driver for SPI based ADC, MCP3462?

$
0
0

I'm working on a Linux Device Driver for an SPI based ADC, MCP3462.Kernel series : 4.9

As the driver is not available anywhere, I am referring the closest one i.e. MCP320x. But I realised the architecture of the two ADCs are completely different.

Also in MCP3462, I need to configure some registers as well. I've used spi_write to configure the registers but unfortunately it's not working out.

The sysfs entries, under /sys/bus/iio/devices/iio:device0/, gives always 0 after reading any input channel.

I'm new into this. Can anyone guide me to port the existing driver or to write a fresh one for the same?

What is the use of struct cpufreq_policy in Linux Kernel CPU Frequency Subsystem

$
0
0

I was reading about CPUFreq subsystem. There are two drivers

  • Scaling Governors: Which decide what should be the next frequency to choose
  • Scaling drivers: Which directly communicate with the hardware and set the frequency provided by scaling governors

Going through the various structures, i understood that

struct cpufreq_driver -> Structure representing a scaling driver which talk to hardware and changes frequency

struct cpufreq_governor - Structure representing a CPU Frequency Governor

What is the use of the struct cpufreq_policy, it is passed as a callback to all the members of struct cpufreq_governor?

unsure about structure of platform device driver for i2c/spi device

$
0
0

I am after some clarification/guidance. For a leaning experiment I am wanting to implement a driver for both the MCP23xxx gpio expander ICs. One series using i2c and the other SPI.

I have experience with i2c drivers for onboard sensors but am now a little unsure of the approach I should take. This exceptional answer and the LWM article it links gave some great insight into platform drivers. I understand that a platform drivers would make sense as thee gpio expanders are not discoverable devices. Now I am unsure of how one would implement a platform drivers that is really an i2c driver(focusing on just one of the chip variants for now). The sensors I have worked with in the past are instantiated in the device tree and the the device driver can make easy use of the i2c_client to interface with the device. Something that I am unsure of is how a platform driver would, for example, interface with i2c devices. I have struggled to find any resources in this.

I would be greatly appreciative if someone would quickly outline for me how platform drivers could be used as device drivers for devices that are, in their most basic form, i2c devices or spi devices. It could be that my understanding of platform drivers is also won't in this context. Clarification there would , as such, also be greatly appreciated.

What RTDM class and subclass for uart?

$
0
0

I am building a Xenomai Uart RTDM driver for an IMX28 based on the mxs-auart.c (which is the Linux version of the driver). In order to do that, I also looked at the rt_imx_uart.c because it is very much similar to what I am trying to build.

Here's my question: I have seen the following in rt_imx_uart.c

static struct rtdm_driver imx_uart_driver = {    .profile_info       = RTDM_PROFILE_INFO(imx_uart,                            RTDM_CLASS_SERIAL,                            RTDM_SUBCLASS_16550A,                            RTSER_PROFILE_VER),    .device_count       = RT_IMX_UART_MAX,    .device_flags       = RTDM_NAMED_DEVICE | RTDM_EXCLUSIVE,    .context_size       = sizeof(struct rt_imx_uart_ctx),    .ops = {        .open       = rt_imx_uart_open,        .close      = rt_imx_uart_close,        .ioctl_rt   = rt_imx_uart_ioctl,        .ioctl_nrt  = rt_imx_uart_ioctl,        .read_rt    = rt_imx_uart_read,        .write_rt   = rt_imx_uart_write,    },};

concerning the class and subclass shown in this structure, can I use the same ones for my driver? How do I know which ones are suited for my use case?

Why more memory (than being required) is allocated to a struct with flexible array member in cfg80211 scan request?

$
0
0

I am learning linux wifi drivers, and was exploring the code in cfg80211 subsytem for a scan request.

I can't understand why the following struct is allocated more memory than required. Or, I can't understand the way the size of memory to be allocated is calculated in this way.

The struct is defined in cfg80211.h:

struct cfg80211_scan_request {    struct cfg80211_ssid *ssids;    int n_ssids;    u32 n_channels;    enum nl80211_bss_scan_width scan_width;    const u8 *ie;    size_t ie_len;    u16 duration;    bool duration_mandatory;    u32 flags;    u32 rates[NUM_NL80211_BANDS];    struct wireless_dev *wdev;    u8 mac_addr[ETH_ALEN] __aligned(2);    u8 mac_addr_mask[ETH_ALEN] __aligned(2);    u8 bssid[ETH_ALEN] __aligned(2);    /* internal */    struct wiphy *wiphy;    unsigned long scan_start;    struct cfg80211_scan_info info;    bool notified;    bool no_cck;    /* keep last */    struct ieee80211_channel *channels[0];};

In file /net/wireless/nl80211.c, memory is being allocated to the struct as follows:

static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info){    // ...    struct cfg80211_scan_request *request;    // ...    request = kzalloc(sizeof(*request)+ sizeof(*request->ssids) * n_ssids+ sizeof(*request->channels) * n_channels+ ie_len, GFP_KERNEL);    // ...}

I have a doubt that more memory is being allocated than required. Or, the way size is calculated in kzalloc doesn't make sense to me.

This is what I expect the code to be like:

static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info){    // ...    struct cfg80211_scan_request *request;    // ...    request = kzalloc(sizeof(*request)+ sizeof(*request->channels) * n_channels,               GFP_KERNEL);    // ...}

Why that much size of memory is allocated then? What I'm understanding is kzalloc(struct + flexible_array_member + extra_len_but_why).

Viewing all 12308 articles
Browse latest View live


Latest Images

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