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

cscope not working properly for out of module development

$
0
0

I have generated cscope database using the following command in the linux source code present in my home folder.

$ make cscope

I am writing my sample drivers in another folder say ~/LinuxDeviceDrivers

I open my vim file of my sample driver code in ~/LinuxDeviceDrivers and add the cscope connection:

:cs add /home/jamal/linux-5.2.8/cscope.out

When i now search for a particular tag, for example start_kernel

:cs find g start_kernel

It throws an error: File 'init/main.c' not found

Did i miss any step here?


What are IN & OUT instructions in x86 used for?

$
0
0

I've encoutered these to instructions IN & OUT while reading "Understanding Linux Kernel" book. I've looked up reference manual.

5.1.9 I/O Instructions

These instructions move data between the processor’s I/O ports and a register or memory.

IN    Read from a port
OUT   Write to a port
INS/INSB  Input string from port/Input byte string from port 
INS/INSW  Input string from port/Input word string from port 
INS/INSD  Input string from port/Input doubleword string from port
OUTS/OUTSB    Output string to port/Output byte string to port 
OUTS/OUTSW    Output string to port/Output word string to port 
OUTS/OUTSD    Output string to port/Output doubleword string to port

I didn't get few things:

  1. "processor’s I/O ports". What are they? Why would we want to read & write "strings" to & from these ports?
  2. I never encoutered a scenerio where I need to use these instructions. When would I be needing these?
  3. Give some practical examples.

If I do not acquire a spinlock in a softirq, is it then alright to sleep?

$
0
0

If I do not acquire a spinlock in softirq context, is it then alright to sleep? It is not, but how many different ways will it crash?

I understand that it is incorrect to sleep after acquiring a spinlock. The process put to sleep might wake up on another CPU while the spinlock would've been acquired on some other cpu. Interrupts would have been disabled on the cpu where spinlock was acquired while restore happens on another cpu. (Will this cause a kernel panic immediately?) But if there is no spinlock involved, will the sleep or (schedule() call), work fine? Or is this wrong due to the way context saving/restoring works? If I call schedule() in a softirq, where does the interrupt context/stack gets saved? kernel mode stack of the current process? When the process gets to run again, will it be able to continue from where it left? Or is this where things will go wrong? That is, schedule() does not know about softirq/interrupt stack and will not save them. So when the process gets to run again, it would have no idea about the softirq?

Scenario 1: Separate hardirq,softirq stacks

All registers would have been stored on the softirq stack. Now if a schedule() is invoked here, it saves ebp in the softirq stack. But when this process gets to run again, it would pop from its own kernel stack and anything can happen from here on.

Scenario 2: Kernel stack used for hardirq and softirq

What can go wrong here?

Can a process be swapped out from RAM while holding a lock?

$
0
0

I am trying to understand the working of process context switch and the process swapping mechanism specially when a lock is acquired by the process.

Lets assume that a process A has acquired either Mutex or Spinlock. Please correct me if i am wrong below.

In case of Spinlock: When process has acquired Spinlock, The kernel preemption is disabled hence there will be no context switch, So is it true that disabling preemption(Context Switch) also prevents process from being swapped out? Or there is other way kernel marks the process "not swap-able" while its holding a Spinlock ?

In case of Mutex: A process can go to sleep state while holding a mutex, and also the preemption is not disabled. so can this process be swapped out while its holding a mutex ? If not then how this process will be prevented from being swapped out ?

Pardon me for my not so clear explanation of the problem.

Platform : Linux on x86

fastest to rebuild the linux kernel using rpmbuild

$
0
0

I just built the linux kernel for CentOS using the instructions that can be found here: https://wiki.centos.org/HowTos/Custom_Kernel

Now, I made my changes and I would like to rebuild the kernel and test it with my changes. How do I do that but: 1. Without having to recompile everything. So, build process should reuse whatever object files generated by the first build that wont need to be modified. 2. Without having to build the other packages that are build with the kernel (e.g., debuginfo, tools, debug-devel, ...etc.).

Thanks.

Is running `sync` necessary after writing a disk image?

$
0
0

Common way to write an image to disk looks like:

dd if=file.img of=/dev/device

After this command, is it necessary to run sync?

sync(2) explains it only flushes filesystem caches. Since dd command is not related to any filesystem, I think it is not necessary to run sync. However, block layer is complex and in doubt, most people prefers to run sync.

Does anyone has a proof that it is useful or useless?

Differences between capabilities and permissions in Linux [closed]

$
0
0

What are the differences between capabilities and permissions in the context of Linux Kernel?

Linux OOM Killer and Java Process

$
0
0

I am often facing issue in our production environment of the Tomcat process getting killed by Linux OOM.

Checking /var/log/messages it says java not tainted and java invoked OOM killer.

-Xms20480m -Xmx20480m on a 32 GB box.

I see below crash -

Is the OOM causing this crash ? or the crash happened because of OOM ? How can I debug this issue ?

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f4c3230aad7, pid=16248, tid=139964439296320
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x674ad7]  JVM_Clone+0x97
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x0000000001313800):  JavaThread "http-bio-14080-exec-17" daemon [_thread_in_native, id=18943, stack(0x00007f4c029f7000,0x00007f4c02af8000)]

siginfo:si_signo=SIGSEGV: si_errno=0, si_code=128 (), si_addr=0x0000000000000000

Registers:
RAX=0x0000000000010000, RBX=0x80000001000004db, RCX=0x0000000302bd6fb0, RDX=0x00007f4c32acda50
RSP=0x00007f4c02af2c88, RBP=0x00007f4c02af2d70, RSI=0x00007f4c02af2d80, RDI=0x00000000013139e8
R8 =0x0000000000000001, R9 =0x00000002f8191228, R10=0x00007f4c2e231658, R11=0x00007f4c2e231638
R12=0x0000000302bd6fb0, R13=0x00000007e0002420, R14=0x0000000000000000, R15=0x0000000001313800
RIP=0x00007f4c3230aad7, EFLAGS=0x0000000000010202, CSGSFS=0x0000000000000033, ERR=0x0000000000000000
  TRAPNO=0x000000000000000d

Top of Stack: (sp=0x00007f4c02af2c88)
0x00007f4c02af2c88:   00007f4c3230aa63 00000000129196d1
0x00007f4c02af2c98:   00000002f817b620 00000000013139e8
0x00007f4c02af2ca8:   00007f4c02af2d18 00000002f8191080
0x00007f4c02af2cb8:   0000000000000009 0000000001313800
0x00007f4c02af2cc8:   0000000000000000 0000000001313800
0x00007f4c02af2cd8:   00000000138f5509 0000000000000000
0x00007f4c02af2ce8:   00007f4c2e382ae8 0000000000000000
0x00007f4c02af2cf8:   00007f4c02af2cf8 00000002f817b620
0x00007f4c02af2d08:   00000002f8190fd8 00000007e01ab278
0x00007f4c02af2d18:   00000002f8190ec0 00000007e0002420
0x00007f4c02af2d28:   0000000000000000 00000007e0002420
0x00007f4c02af2d38:   0000000000000000 0000000000000000
0x00007f4c02af2d48:   00000007e0002420 0000000000000000
0x00007f4c02af2d58:   00007f4c02af2de0 0000000000000000
0x00007f4c02af2d68:   0000000001313800 00007f4c02af2dc0
0x00007f4c02af2d78:   00007f4c2e2316c6 0000000302bd6fb0
0x00007f4c02af2d88:   0000000000000000 00007f4c02af2e08
0x00007f4c02af2d98:   00007f4c2e1bc8e1 00007f4c02af2db8
0x00007f4c02af2da8:   00007f4c2e1bc8e1 00000002f8190fd8
0x00007f4c02af2db8:   00000002f817b620 00007f4c02af2e28
0x00007f4c02af2dc8:   00007f4c2e1bc233 00000007e1ec4e9f
0x00007f4c02af2dd8:   00007f4c2e1bc233 0000000302bd6fb0
0x00007f4c02af2de8:   00007f4c02af2de8 00000007e1b7a5db
0x00007f4c02af2df8:   00007f4c02af2e30 00000007e37575a8
0x00007f4c02af2e08:   0000000000000000 00000007e1b7a5e8
0x00007f4c02af2e18:   00007f4c02af2de0 00007f4c02af2e40
0x00007f4c02af2e28:   00007f4c02af2ed0 00007f4c2edaaf34
0x00007f4c02af2e38:   00007f4c2edaaf34 00007f4c0000000a
0x00007f4c02af2e48:   00000007e416ec20 0000000000000000
0x00007f4c02af2e58:   00000007e416e2b8 00007f4c02af2ed0
0x00007f4c02af2e68:   00007f4c2e1bc233 00007f4c02af2ed0
0x00007f4c02af2e78:   00007f4c2e1bc233 000000000000000a 

Instructions: (pc=0x00007f4c3230aad7)
0x00007f4c3230aab7:   85 60 02 00 00 06 00 00 00 4c 89 6d b0 4c 8b 23
0x00007f4c3230aac7:   4d 85 e4 0f 84 68 02 00 00 49 8b 9d 20 01 00 00
0x00007f4c3230aad7:   48 83 7b 10 f7 0f 87 6e 02 00 00 48 8b 43 10 48
0x00007f4c3230aae7:   8d 50 08 48 3b 53 18 0f 87 9c 02 00 00 48 89 53 

Register to memory mapping:

RAX=0x0000000000010000 is an unknown value
RBX=0x80000001000004db is an unknown value
RCX=0x0000000302bd6fb0 is an oop
[Lcom.mycompany.MyClass$Type; 
 - klass: 'com/mycompany/MyClass$Type'[]
 - length: 16
RDX=0x00007f4c32acda50: <offset 0xe37a50> in /usr/java/jre64-1.7.0_45/jre/lib/amd64/server/libjvm.so at 0x00007f4c31c96000
RSP=0x00007f4c02af2c88 is pointing into the stack for thread: 0x0000000001313800
RBP=0x00007f4c02af2d70 is pointing into the stack for thread: 0x0000000001313800
RSI=0x00007f4c02af2d80 is pointing into the stack for thread: 0x0000000001313800
RDI=0x00000000013139e8 is an unknown value
R8 =0x0000000000000001 is an unknown value
R9 =
[error occurred during error reporting (printing register info), id 0xb]

Stack: [0x00007f4c029f7000,0x00007f4c02af8000],  sp=0x00007f4c02af2c88,  free space=1007k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x674ad7]  JVM_Clone+0x97
J  java.lang.Object.clone()Ljava/lang/Object;
j  com.mycompany.MyClass$Type.values()[Lcom/mycompany/MyClass$Type;+3

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  java.lang.Object.clone()Ljava/lang/Object;
j  com.mycompany.MyClass$Type.values()[Lcom/mycompany/MyClass$Type;+3

/var/log/messages output -

myhostname kernel: java invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0
myhostname kernel: java cpuset=/ mems_allowed=0
myhostname kernel: Pid: 32307, comm: java Not tainted 2.6.39-400.209.1.el5uek #1
myhostname kernel: Call Trace:
myhostname kernel:  [<ffffffff811136b4>] dump_header+0x94/0xe0
myhostname kernel:  [<ffffffff811137fd>] oom_kill_process+0x6d/0x160
myhostname kernel:  [<ffffffff811139ec>] out_of_memory+0xfc/0x210
myhostname kernel:  [<ffffffff811187ec>] __alloc_pages_slowpath+0x64c/0x660
myhostname kernel:  [<ffffffff811189b4>] __alloc_pages_nodemask+0x1b4/0x200
myhostname kernel:  [<ffffffff8111b140>] ? __do_page_cache_readahead+0xe0/0x170
myhostname kernel:  [<ffffffff81150893>] alloc_pages_current+0xb3/0x120
myhostname kernel:  [<ffffffff811100da>] __page_cache_alloc+0x9a/0xb0
myhostname kernel:  [<ffffffff8111097f>] page_cache_read+0x4f/0xb0
myhostname kernel:  [<ffffffff81111a54>] filemap_fault+0x174/0x270
myhostname kernel:  [<ffffffff81137a2c>] __do_fault+0x5c/0x550
myhostname kernel:  [<ffffffff81137fc6>] do_linear_fault+0x36/0x40
myhostname kernel:  [<ffffffff81510b6e>] ? call_function_interrupt+0xe/0x20
myhostname kernel:  [<ffffffff81138044>] handle_pte_fault+0x74/0x190
myhostname kernel:  [<ffffffff815106ae>] ? apic_timer_interrupt+0xe/0x20
myhostname kernel:  [<ffffffff8113828f>] handle_mm_fault+0x12f/0x1b0
myhostname kernel:  [<ffffffff8150b1cd>] do_page_fault+0x17d/0x4b0
myhostname kernel:  [<ffffffff8117b821>] ? user_path_at+0x11/0x20
myhostname kernel:  [<ffffffff81170516>] ? vfs_fstatat+0x56/0x90
myhostname kernel:  [<ffffffff8117067b>] ? vfs_stat+0x1b/0x20
myhostname kernel:  [<ffffffff81507cd5>] page_fault+0x25/0x30
myhostname kernel: Mem-Info:
myhostname kernel: Node 0 DMA per-cpu:
myhostname kernel: CPU    0: hi:    0, btch:   1 usd:   0
myhostname kernel: CPU    1: hi:    0, btch:   1 usd:   0
myhostname kernel: CPU    2: hi:    0, btch:   1 usd:   0
myhostname kernel: CPU    3: hi:    0, btch:   1 usd:   0
myhostname kernel: CPU    4: hi:    0, btch:   1 usd:   0
myhostname kernel: CPU    5: hi:    0, btch:   1 usd:   0
myhostname kernel: Node 0 DMA32 per-cpu:
myhostname kernel: CPU    0: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    1: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    2: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    3: hi:  186, btch:  31 usd:  11
myhostname kernel: CPU    4: hi:  186, btch:  31 usd:  30
myhostname kernel: CPU    5: hi:  186, btch:  31 usd:   0
myhostname kernel: Node 0 Normal per-cpu:
myhostname kernel: CPU    0: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    1: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    2: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    3: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    4: hi:  186, btch:  31 usd:   0
myhostname kernel: CPU    5: hi:  186, btch:  31 usd:   0
myhostname kernel: active_anon:4372468 inactive_anon:275213 isolated_anon:0
myhostname kernel:  active_file:17 inactive_file:21 isolated_file:0
myhostname kernel:  unevictable:6002 dirty:24 writeback:4 unstable:0
myhostname kernel:  free:38369 slab_reclaimable:3708 slab_unreclaimable:9265
myhostname kernel:  mapped:1253 shmem:67 pagetables:10880 bounce:0
myhostname kernel: Node 0 DMA free:15880kB min:8kB low:8kB high:12kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:15688kB mlocked:0kB dirty:0kB writeback:0kB mapped:0kB shmem:0kB slab_reclaimable:0kB slab_unreclaimable:0kB kernel_stack:0kB pagetables:0kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? yes
myhostname kernel: lowmem_reserve[]: 0 3000 32290 32290
myhostname kernel: Node 0 DMA32 free:119288kB min:2136kB low:2668kB high:3204kB active_anon:30224kB inactive_anon:9152kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:3072096kB mlocked:0kB dirty:16kB writeback:4kB mapped:36kB shmem:0kB slab_reclaimable:40kB slab_unreclaimable:232kB kernel_stack:24kB pagetables:48kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:67 all_unreclaimable? yes
myhostname kernel: lowmem_reserve[]: 0 0 29290 29290
myhostname kernel: Node 0 Normal free:17564kB min:20856kB low:26068kB high:31284kB active_anon:17459648kB inactive_anon:1091700kB active_file:120kB inactive_file:88kB unevictable:24008kB isolated(anon):0kB isolated(file):0kB present:29992960kB mlocked:24008kB dirty:80kB writeback:12kB mapped:4976kB shmem:268kB slab_reclaimable:14792kB slab_unreclaimable:36828kB kernel_stack:2768kB pagetables:43472kB unstable:0kB bounce:0kB writeback_tmp:0kB pages_scanned:14972 all_unreclaimable? yes
myhostname kernel: lowmem_reserve[]: 0 0 0 0
myhostname kernel: Node 0 DMA: 0*4kB 1*8kB 0*16kB 0*32kB 2*64kB 1*128kB 1*256kB 0*512kB 1*1024kB 1*2048kB 3*4096kB = 15880kB
myhostname kernel: Node 0 DMA32: 458*4kB 494*8kB 284*16kB 55*32kB 7*64kB 4*128kB 5*256kB 7*512kB 7*1024kB 6*2048kB 20*4096kB = 119288kB
myhostname kernel: Node 0 Normal: 3333*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 1*4096kB = 17428kB
myhostname kernel: 115783 total pagecache pages
myhostname kernel: 114466 pages in swap cache
myhostname kernel: Swap cache stats: add 2183060, delete 2068594, find 1860109/1985849
myhostname kernel: Free swap  = 0kB
myhostname kernel: Total swap = 2097148kB
myhostname kernel: 8388592 pages RAM
myhostname kernel: 134806 pages reserved
myhostname kernel: 6845 pages shared
myhostname kernel: 8210059 pages non-shared

What is the difference between rel kernel versions of Linux?

$
0
0

I want to know what is the difference between r34-rel, r37-rel, r38-rel, r39-rel and r40-rel in the Linux 4.4 kernel. The official kernel sources are https://github.com/android-linux-stable/msm-4.4. And so not only with 4.4 version of the Linux kernel. This is also found in others.

I tried to find on the Internet, but still could not find the answer.

I would be very grateful for the answer.

Cannot find pid in system call in linux kernel

$
0
0

Using Ubuntu 18.04.3 x64 I upgraded the kernel from 4.x.x to 5.1.0. Then I made a new system call below.

SYSCALL_DEFINE1(get_mem_info, pid_t, input_pid)
{
    printk("Starting system call (get_mem_info)\n");
    struct task_struct *task;
    int found = 0;
    for (task = &init_task; next_task(task) != &init_task; task = next_task(task))
    {
        if (task->pid == input_pid)
        {
            found = 1;
            printk("Task was found\n");
            break;
        }
    }
    if (found)
    {
        struct vm_area_struct *vma;
        unsigned long total_size = 0;
        int i = 0;

        vma = task->mm->mmap;

        while (vma != NULL)
        {
            printk("The number %d vma's access permissions is %lu\n", i, vma->vm_page_prot.pgprot);
            printk("The file name mapped to this vma is %s\n", vma->vm_file->f_path.dentry->d_name.name);

            total_size += (vma->vm_end - vma->vm_start);
            i++;
            vma = vma->vm_next;
        }

        printk("The size of the process' virtual address space is %lu\n", total_size);
    }
    else
    {
        printk("Task not found\n");
    }
  return 0;
}

Then I compiled the kernel to reflect this change. Then using a tester file I have the below:

#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>

#define __NR_get_mem_info 338


int main(int argc, char *argv[])
{
    pid_t pid = getpid();   //get current process pid
    syscall (__NR_get_mem_info, pid);
    return 0;
}

But when I run the tester file I get:

"Task not found."

Where is the problem?

RAW socket and NF_INET_POST_ROUTING

$
0
0

Is there a way to know in NF_INET_POST_ROUTING if the packet is generate via RAW socket:

#include <sys/socket.h>
#include <netinet/in.h>
raw_socket = socket(AF_INET, SOCK_RAW, int protocol); 

Any help is greatly appreciated!

Fatal error in #include "restart.h" library [closed]

$
0
0

After I try to compile the code in the linux kernel I get an error which states: sServer.c:5:10: fatal error: 'restart.h' file not found

include "restart.h"

     ^~~~~~~~~~~

1 error generated.

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "restart.h"
#include "uici.h"

int main(int argc, char *argv[])
{
 int bytescopied;
 char client[MAX_CANON];
 int communfd;
 int listenfd;
 u_port_t portnumber;
 if (argc != 2) 
 {
   fprintf(stderr, "Usage: %s port\n", argv[0]);
   return 1;
 }
 portnumber = (u_port_t) atoi(argv[1]);
 if ((listenfd = u_open(portnumber)) == -1) 
{
  perror("Failed to create listening endpoint");
  return 1;
}
fprintf(stderr, "[%ld]:waiting for the first connection on port %d\n",(long)getpid(), (int)portnumber);
for ( ; ; ) 
{
 if ((communfd = u_accept(listenfd, client, MAX_CANON)) == -1) 
{
 perror("Failed to accept connection");
 continue;
}
fprintf(stderr, "[%ld]:connected to %s\n", (long)getpid(), client);
bytescopied = copyfile(communfd, STDOUT_FILENO);
fprintf(stderr, "[%ld]:received %d bytes\n", (long)getpid(),        bytescopied);
if (r_close(communfd) == -1)
 {
  perror("Failed to close communfd\n");
 }
}
}

Why does some mmio-only arch still have inb/outb and etc in linux kernel?

$
0
0

afaik, port-mapped io only exists on x86, and inb, outb, inw, outw and their friends are all c functions for port-maped io. But I still find many arch under kernel/arch/ use them: enter image description hereenter image description here

Question: 1. why doesn these non-x86 arch also use these functions? 2. why arm use these functions while arm64 doesn't?

Why do some mmio-only arch still have inb/outb and etc in linux kernel?

$
0
0

afaik, port-mapped io only exists on x86, and inb, outb, inw, outw and their friends are all c functions for port-maped io. But I still find many arch under kernel/arch/ use them: enter image description hereenter image description here

Question: 1. why doesn these non-x86 arch also use these functions? 2. why arm use these functions while arm64 doesn't?

What is the correct usage of wake_up_interruptible() in linux kernel 4.12?

$
0
0

I have two functions, the kernel thread which blocks on

Work Kernel Thread()
{
 set_current_state(TASK_INTERRUPTIBLE);
wait_event_interruptible(..work.queue, condition)
  __set_current_state(TASK_RUNNING);
}

ISR
{

  wake_up_interruptible(..work queue..)
}

However, when I execute, the kernel complains that the

  WARNING: CPU: 0 PID: 565 at /usr/src/kernel/kernel/sched/core.c:6234 __might_sleep+0x78/0x9c 
    do not call blocking ops when !TASK_RUNNING; state=1 set at 0x...

Understanding /proc/iomem

$
0
0

I was looking into the "/proc/iomem" entries and have a doubt regarding the same.

My Linux PC is running a Intel Xeon and has a system RAM of 4GB.

/proc/iomem entry of my system looks like

00000000-0000ffff : reserved
00010000-0009f3ff : System RAM
0009f400-0009ffff : reserved
000a0000-000bffff : PCI Bus 0000:00
000c0000-000c7fff : Video ROM
000ca000-000cbfff : reserved
  000ca000-000cafff : Adapter ROM
  000cb000-000cbfff : Adapter ROM
000cc000-000cffff : PCI Bus 0000:00
000d0000-000d3fff : PCI Bus 0000:00
000d4000-000d7fff : PCI Bus 0000:00
000d8000-000dbfff : PCI Bus 0000:00
000dc000-000fffff : reserved
  000f0000-000fffff : System ROM
00100000-7fedffff : System RAM
  01000000-01520fa4 : Kernel code
  01520fa5-01c0e44f : Kernel data
  01d56000-0201d963 : Kernel bss
  03000000-0b0fffff : Crash kernel
7fee0000-7fefefff : ACPI Tables
7feff000-7fefffff : ACPI Non-volatile Storage
7ff00000-7fffffff : System RAM
c0000000-febfffff : PCI Bus 0000:00
fec00000-fec0ffff : reserved
  fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
  fed00000-fed003ff : pnp 00:08
fee00000-fee00fff : Local APIC
  fee00000-fee00fff : reserved
fffe0000-ffffffff : reserved

Now, assuming that my processor has 32 address lines ( i feel that it has 40 address lines - i see this from /proc/cpuinfo), this means that my processor will be able to address 4GB of physical memory.

Looking from my "/proc/iomem" entries, I see that only 2GB of system RAM is being directly addressed by my CPU.

Now my doubt is

  1. How does my CPU addresses other 2 GB of RAM ? Where can I see the memory mapping for that ?

Zero-copy user-space TCP send of dma_mmap_coherent() mapped memory

$
0
0

I'm running Linux 5.1 on a Cyclone V SoC, which is an FPGA with two ARMv7 cores in one chip. My goal is to gather lots of data from an external interface and stream (part of) this data out through a TCP socket. The challenge here is that the data rate is very high and could come close to saturating the GbE interface. I have a working implementation that just uses write() calls to the socket, but it tops out at 55MB/s; roughly half the theoretical GbE limit. I'm now trying to get zero-copy TCP transmission to work to increase the throughput, but I'm hitting a wall.

To get the data out of the FPGA into Linux user-space, I've written a kernel driver. This driver uses a DMA block in the FPGA to copy a large amount of data from an external interface into DDR3 memory attached to the ARMv7 cores. The driver allocates this memory as a bunch of contiguous 1MB buffers when probed using dma_alloc_coherent() with GFP_USER, and exposes these to the userspace application by implementing mmap() on a file in /dev/ and returning an address to the application using dma_mmap_coherent() on the preallocated buffers.

So far so good; the user-space application is seeing valid data and the throughput is more than enough at >360MB/s with room to spare (the external interface is not fast enough to really see what the upper bound is).

To implement zero-copy TCP networking, my first approach was to use SO_ZEROCOPY on the socket:

sent_bytes = send(fd, buf, len, MSG_ZEROCOPY);
if (sent_bytes < 0) {
    perror("send");
    return -1;
}

However, this results in send: Bad address.

After googling for a bit, my second approach was to use a pipe and splice() followed by vmsplice():

ssize_t sent_bytes;
int pipes[2];
struct iovec iov = {
    .iov_base = buf,
    .iov_len = len
};

pipe(pipes);

sent_bytes = vmsplice(pipes[1], &iov, 1, 0);
if (sent_bytes < 0) {
    perror("vmsplice");
    return -1;
}
sent_bytes = splice(pipes[0], 0, fd, 0, sent_bytes, SPLICE_F_MOVE);
if (sent_bytes < 0) {
    perror("splice");
    return -1;
}

However, the result is the same: vmsplice: Bad address.

Note that if I replace the call to vmsplice() or send() to a function that just prints the data pointed to by buf (or a send()withoutMSG_ZEROCOPY), everything is working just fine; so the data is accessible to userspace, but the vmsplice()/send(..., MSG_ZEROCOPY) calls seem unable to handle it.

What am I missing here? Is there any way of using zero-copy TCP sending with a user-space address obtained from a kernel driver through dma_mmap_coherent()? Is there another approach I could use?

UPDATE

So I dove a bit deeper into the sendmsg()MSG_ZEROCOPY path in the kernel, and the call that eventually fails is get_user_pages_fast(). This call returns -EFAULT because check_vma_flags() finds the VM_PFNMAP flag set in the vma. This flag is apparently set when the pages are mapped into user space using remap_pfn_range() or dma_mmap_coherent(). My next approach is to find another way to mmap these pages.

U-Boot i2c detects my device (70) but Linux i2c does not. Why?

$
0
0

I am in the process of migrating from Linux 3.10 to a slightly newer version, Linux 4.4.8. After the migration it seems that i2c can no longer see some of my hardware. The hardware itself has not changed whatsoever and works fine in the previous linux version (3.10).

The problem I am running into now is that my i2c commands are no longer working.

When trying to write to the device I get a failed write.

[]# i2cset -y 0 0x70 0 1 b
Error: Write failed

Then I decided to run the i2cdetect to determine what can be seen and this is the output i get

In Linux:

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

In U-Boot:

[u-boot]# i2c probe
Valid chip addresses: 20 21 64 70

What would be the reason that I can see my device in U-Boot but I can't see my device in Linux?

I suspect the device tree might need to be modified? But I checked the old dtsi files and nothing is different between the i2c0's in the two Linux versions...

i2cdump gives all X's for output

[]# i2cdump -y 0 0x70
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX    XXXXXXXXXXXXXXXX
10: XX XX XX XX XX XX XX XX XX XX...

i2c host controller: linux-4-4-8/drivers/i2c/busses/i2c-mv64xxx.c

Devices

0x20, 0x21: PCA9555 IO Port Expanders

0x70: PCA9548A i2c Multiplexer

Use signals to notify about an input hardware event for a push button in C?

$
0
0

I am developing a Linux kernel module that communicates with a user-space application through signals in order to notify about the push-button event from my embedded board, therefore, the LED turns on.

For that, I started developing a simple module and userspace application as an example and to understand well how it works. The module searches for the application PID, send a signal through call back function named receiveData and print 1234 as a result.

This is the module :

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <asm/siginfo.h>    //siginfo
#include <linux/rcupdate.h>    //rcu_read_lock
#include <linux/sched/signal.h>    //find_task_by_pid_type
#include <linux/debugfs.h>
#include <linux/uaccess.h>

#define SIG_TEST 44    // we choose 44 as our signal number (real-time signals are in the range of 33 to 64)

struct dentry *file;

static ssize_t write_pid(struct file *file, const char __user *buf,
                                size_t count, loff_t *ppos)
{
    char mybuf[10];
    int pid = 0;
    int ret;
    struct siginfo info;
    struct task_struct *t;
    /* read the value from user space */
    if(count > 10)
        return -EINVAL;
    copy_from_user(mybuf, buf, count);
    sscanf(mybuf, "%d", &pid);
    printk("pid = %d\n", pid);

    /* send the signal */
    memset(&info, 0, sizeof(struct siginfo));
    info.si_signo = SIG_TEST;
    info.si_code = SI_QUEUE;    // this is bit of a trickery: SI_QUEUE is normally used by sigqueue from user space,
                    // and kernel space should use SI_KERNEL. But if SI_KERNEL is used the real_time data 
                    // is not delivered to the user space signal handler function. 
    info.si_int = 1234;          //real time signals may have 32 bits of data.

    rcu_read_lock();
    t = pid_task(find_vpid(pid), PIDTYPE_PID);  //find the task_struct associated with this pid
    if(t == NULL){
        printk("no such pid\n");
        rcu_read_unlock();
        return -ENODEV;
    }
    rcu_read_unlock();

    ret = send_sig_info(SIG_TEST, &info, t);    //send the signal
    if (ret < 0) {
        printk("error sending signal\n");
        return ret;
    }
    return count;
}

static const struct file_operations my_fops = {
    .write = write_pid,
};

static int __init signalexample_module_init(void)
{
    /* we need to know the pid of the user space process
      * -> we use debugfs for this. As soon as a pid is written to 
      * this file, a signal is sent to that pid
      */
    /* only root can write to this file (no read) */
    file = debugfs_create_file("signalconfpid", 0200, NULL, NULL, &my_fops);
    return 0;
}
static void __exit signalexample_module_exit(void)
{
    debugfs_remove(file);

}

module_init(signalexample_module_init);
module_exit(signalexample_module_exit);
MODULE_LICENSE("GPL");

This is the user space application :

#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

#define SIG_TEST 44 /* we define our own signal, hard coded since SIGRTMIN is different in user and in kernel space */ 


void receiveData(int n, siginfo_t *info, void *unused) {
    printf("received value %i\n", info->si_int);
}

int main ( int argc, char **argv )
{
    int configfd;
    char buf[10];
    /* setup the signal handler for SIG_TEST 
      * SA_SIGINFO -> we want the signal handler function with 3 arguments
      */

    struct sigaction sig;
    sig.sa_sigaction = receiveData;
    sig.sa_flags = SA_SIGINFO;
    sigaction(SIG_TEST, &sig, NULL);

     /* kernel needs to know our pid to be able to send us a signal ->
      * we use debugfs for this -> do not forget to mount the debugfs!
      */
    configfd = open("/sys/kernel/debug/signalconfpid", O_WRONLY);
    if(configfd < 0) {
        perror("open");
        return -1;
    }
    sprintf(buf, "%i", getpid());
    if (write(configfd, buf, strlen(buf) + 1) < 0) {
        perror("fwrite"); 
        return -1;
    }

    return 0;
}

This works fine. But the problem for me now, how can we base on that method in order to notify about an embedded board push-button device that make led turn on and off?

I developed an application for the led and button that works fine but without using signals or kernel modules :

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>

#include <linux/input.h>

#define BTN_FILE_PATH "/dev/input/event0"
#define LED_PATH "/sys/class/leds"
#define red "red"

void change_led_state(char *led_path, int led_value)
{
    char    lpath[64];
    FILE    *led_fd;

    strncpy(lpath, led_path, sizeof(lpath) - 1);
    lpath[sizeof(lpath) - 1] = '\0';

    led_fd = fopen(lpath, "w");

    if (led_fd == NULL) {
        fprintf(stderr, "simplekey: unable to access led\n");
        return;
    }

    fprintf(led_fd, "%d\n", led_value);

    fclose(led_fd);
}

void reset_leds(void)
{
    change_led_state(LED_PATH "/" red "/brightness", 0);
}

int configure_leds(void)
{
    FILE    *r_fd;
    char    *none_str = "none";

    /* Configure leds for hand control */
    r_fd = fopen(LED_PATH "/" red "/trigger", "w");

    fprintf(r_fd, "%s\n", none_str);

    fclose(r_fd);

    /* Switch off leds */
    reset_leds();

    return 0;
}

void eval_keycode(int code)
{
    static int red_state = 0;

    switch (code) {
    case 260:
        printf("BTN left pressed\n");

        /* figure out red state */
        red_state = red_state ? 0 : 1;

        change_led_state(LED_PATH "/" red "/brightness", red_state);
        break;
    }
}


int main(void)
{
    int file;
    /* how many bytes were read */
    size_t  rb;
    int ret;
    int yalv;
    /* the events (up to 64 at once) */
    struct input_event  ev[64];
    char    *str = BTN_FILE_PATH;

    printf("Starting simplekey app\n");

    ret = configure_leds();
    if (ret < 0)
        exit(1);

    printf("File Path: %s\n", str);

    if((file = open(str, O_RDONLY)) < 0) {
        perror("simplekey: File can not open");
        exit(1);
    }

    for (;;) {
        /* Blocking read */
        rb= read(file, &ev, sizeof(ev));

        for (yalv = 0;
            yalv < (int) (rb / sizeof(struct input_event));
            yalv++) {
            if (ev[yalv].type == EV_KEY){

                /* Change state on button pressed */
                if (ev[yalv].value == 0)
                    eval_keycode(ev[yalv].code);
            }
        }
    }

    close(file);
    reset_leds();
    exit(0);
}

If anybody could help me I will be grateful. I have been stuck in that for so many days and I did not find a solution.

Thank you.

Linux Kernel Version numbering after 3.0

$
0
0

How are the Linux Kernel version numbers updated.

Are we only following x.y version model for mainline kernels and x.y.z model for stable kernels.

Can you please provide documentation for this, Googling this I mostly get results regarding w.x.y.z numbering

Viewing all 12190 articles
Browse latest View live


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