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

Memcpy from PCIe memory takes more time than memcpy to PCIe memory

$
0
0

I am trying to do read/write data to/from a Linux PC from/to a PCIe 2.0 (2 lane) device. The memory for reading and writing are at different RAM locations in the PCIe device. Those memories are mapped in Linux PC using ioremap. My use case is to achieve 18MBytes/second read/write throughput which is obviously supported by the PCIe link. The memory at the PCIe device is uncached.

I am able to achieve the write throughput i.e when I write from Linux PC local memory to PCIe device memory using memcpy. The memcpy takes less than 1 ms for 9216 bytes of data in this case. But when I read the ioremapped PCIe memory to Linux local memory, data loss is happening. I profiled the memcpy and it takes more than 1ms, sometimes 2ms for 9216 bytes of data. I don't want to do DMA for this operation.

Any thoughts on what can be the problem in this case? How can I handle this?


How can I get the 'root' boot arg in kernel space?

$
0
0

I am writing a driver and I need to know what disk/partition contains the root filesystem. This can be viewed from userspace using:

cat /proc/cmdline 
root=/dev/mmcblk0p1

How can I get the value of root in kernel space?

Confusion around spin_lock_irqsave: in what nested situation is interrupt state kept?

$
0
0

There are many Q&As about spinlocks, but it's still confusing to me. I think it's because the questions and answers assume different settings or not clearly explain the settings about if it's SMP or if it's preemptive kernel or not when they ask or answer (and some old info is mixed in too).

My first question is: (Q1) in SMP situation, is schedule() run on every processor concurrently (I know the scheduling starts by jiffies timer interrupt)? I'll assume yes in my question below. I would appreciate it if someone could briefly explain it to me how processes move processor cores during scheduling too.

I'm trying to understand how, why, when spin_lock/unlock_irqsave is used. Here is my question.

Suppose there is a code which calls spin_lock_irqsave, and the interrupt state (enable) was a 'disable' at the time of calling spin_lock_irqsave(). Could this code be running in interrupt context? Probably not, because the ISR should not have kicked in in the first place if interrupt was disabled in the corresponding local processor. Therefore, the code calling spin_lock_irqsave must be in process context. Ok, the interrupt had been disabled previously, but a process is trying to lock with spin_lock_irqsave.

In what case the interrupt had been disabled? I think there are two cases.

Case 1: a previous interrupt routine had been preempted by this process (which is calling this spin_lock_irqsave). This is weird because ISR cannot be preempted. (Q2) By the way, in preemptive kernel, can ISR be preempted by a process? (Q3) I guess because the preempt_count() is #defined as (current_thread_info()->preempt_count), the preempt_disable only works for process and not interrupt. Do interrupts also have the current thread info?

Case 2: a previous normal process had acquired the lock with spin_lock_irq (or irqsave). But this also is weird because before locking, spin_lock_irq (or irqsave) disables preemption and interrupt for the task telling the scheduler not to switch to other task after the scheduler timer interrupt. So this case cannot be true.

I know I have to look further about process scheduling for SMP and kernel preemption, and maybe I am misunderstanding something. Could somebody clear things up in my question? Thanks a lot for reading.

Get maximum available register for Linux PCI device

$
0
0

I am currently debugging a Linux kernel driver. I want to sweep a PCI device's mmio registers to scan for certain information. This is the function I wrote so far.

void _sweep_registers(struct pci_dev *dev)
{
        int i;
        int activecontrolstatus;
        int activestatus;

        for (i = 0; i < AMD_P2C_MSG_INTSTS; i++) {
                activecontrolstatus = readl(privdata->mmio + i);
                activestatus = activecontrolstatus >> 4;
                dev_info(&dev->dev, "activecontrolstatus = %d / activestatus = %d",
                         activecontrolstatus, activestatus);
        }
}

Currently I am reading mmio until what's specified in AMD_P2C_MSG_INTSTS (which is 0x10694). But how far can I actually go? I have zero knowledge of Linux kernel development and only rudimentary knowledge of C.

Background

My goal is to find information about which sensors of the AMD Sensor Fusion Hub are marked as active. They should be under the register 0x1068C, but are not on my system (it's 0x0, but at least an accelerometer is available, so the bitmask should at least match 0x1). I want to see, whether they are stored somewhere else.

SysV Init killall5 does not wake up after sleep 5

$
0
0

I have created a custom embedded Linux distro using Yocto based on Poky. I am using SysVInit utilities. When we restart the system and all the rc6 scripts are called. Almost in the end /etc/init.d/sendsigs script is called. This script first send SIGTERM signal to all the running processes and sleep for 5 seconds and then send SIGKILL signal to all the remaining processes. The problem I am seeing is when I restart the system, the script send SIGTERM signal and sleep for 5 seconds but does not wake up after the sleep hence it does not send SIGTERM and hangs the system causing system not to reboot. Following is the /etc/init.d/sendsigs script

echo "Sending TERM signal..."
killall5 -15
sleep 5     # Does not wakeup after sleep.
echo "Sending KILL signal..."
killall5 -9

It looks like kernel scheduler does not wake up the script process. But any ideas where should I be looking to fix the issue or where the problem could possibly be.

Thanks.

How to read PMC(Performance Monitoring Counter) of x86 intel processor

$
0
0

My desktop is Intel x86_64 processor with Ubuntu operating system.

I know there is perf tool to get a list of statistics of a program. But what I am trying to do is read performance counter directly without using the perf tool.

  1. First Question

First Questions is I downloaded this code from Github: Github Code Reference.

It compiled successfully with linux-headers-5.3.0-40-generic kernel without any errors. Once I use "insmod" the .ko file, the system hangs. The .ko file is not inserted when I checked the dmesg, so I have to cease it after I do "insmod" the .ko file. Does it happen because I attempted unauthorized access? If there are suggestions that I can try, I am glad to hear that.

The corresponding code is below.

static void set_pce(void *arg)
{
    int to_val = (arg != 0);
    u_int64_t cr4_val;

    cr4_val = __read_cr4();
    if (to_val) {
        cr4_val |= X86_CR4_PCE;
    } else {
        cr4_val &= ~X86_CR4_PCE;
    }

    __write_cr4(cr4_val);
}

static int __init user_rdpmc_init(void){
    int cpu;

    num_cpus = num_online_cpus();

    printk(KERN_INFO "Enabling RDPMC from ring 3 for %d CPUs\n", num_cpus);
    for (cpu = 0; cpu < num_cpus; cpu++) {
    smp_call_function_single(cpu, set_pce, (void *) 1, 1);
    }

   return 0;
}
  1. Second Question

Second question is I am using linux-headers-5.3.0-40-generic kernel version in my Ubuntu desktop. I downloaded kernel code version 5.5.3 from kernel.org. I followed the perf code given in the 5.5.3 kernel code thoroughly and discovered that core.c file under linux-5.5.3/arch/x86/events/intel directory actually does setting and reading the performance counters. I used the core.c file contents to make it as a module to read the performance counter. When I compile it, it creates a bunch of errors because I use linux-headers-5.3.0-40-generic to build the module but my ubuntu kernel doesn't have all header files linked to the core.c file from kernel code from kernel.org.

How can I make my Ubuntu kernel use all the files linked to core.c from kernel.org and build the .ko file?

Or Is there any module source code that has x86 performance counter reading that I can use as a reference?

Thank you for your help in advance.

Difference between skbuff frags and frag_list

$
0
0

The sk_buff has two places where it can store the next fragmentation data:

skb_shinfo(head)->frag_list 
skb_shinfo(head)->frags[]

May someone please explain the differences between these two ways to handle fragmentation.

Thanks and Best Regards!

Remove previously generated .dtb files on the BeagleBone ai

$
0
0

I'm trying to remove previously generated .dtb files on the BeagleBone-ai the name of my old file is "am5729-beagleboneai-custom.dtb" I did 1) sudo rm /boot/dtbs/am5729-beagleboneai-custom.dtb 2) copied my new generated .dtb file "am5729-custom.dtb" to /boot/dtbs 3) ls /boot/dtbs to check if my new file is existed and it was there 4) Edit my /boot/uEnv.txt to #dtb=am5729-custom.dtb 5) reboot 6) after rebooting, I did "show-pins" and still seeing the old results for my "am5729-beagleboneai-custom.dtb" I'm not sure what should I do to stop getting the results from my old '.dtb' file. Thank you for your help.


How can I change TCP SYN timeout in Linux? [closed]

$
0
0

I was trying to tune some TCP client system and I needed the results to be prepared before a hard deadline. I ran into some problems because of TCP retransmission delays. What I witnessed (using tcpdump) was that whenever a Push segment drops (or by any means, does not reach the destination or its ack is lost), it takes a relatively long time (about 200ms) for the peer to retransmit the segment.

Then, I searched about these timeouts in Linux TCP stack and I found out that TCP_RTO_MIN is a hard-coded constant in Linux kernel (despite that you can tune number of retransmissions with tcp_retries2, If I'm not mistaken).

Then I started looking more widely and I found out about rto_min option on ip-route. By setting this to some little value (5ms), I felt that the maximum response time is lowered in most cases but not in all of cases. Still, there are cases in which the SYN packet remains unACKed, no retransmission is done, and the 500ms deadline is missed.

I am kind of confused about how these parameters interact each other and also I would be pretty glad to find a way for generally lowering retransmission delays (or might be called segment retry timeouts).

BTW, I am using Linux kernel 4.15 and IPv4 on Ubuntu.

C - time() in time.h updates its value every 128 seconds

$
0
0

I've wrote a simple code to test the function time() from time.h:

// time-test.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    float now = (float)time(NULL);
    fprintf(stdout, "time() returns: %f\n", now);

    return 0;
}

But when I run this code, I find that time() only 'refreshes' its value every 128 seconds.So my output is like the following

user@ubuntu:~/workspace$ gcc -o time-test time-test.c
user@ubuntu:~/workspace$ ./time-test
time() returns: 1585473408.000000
user@ubuntu:~/workspace$ ./time-test
time() returns: 1585473408.000000
user@ubuntu:~/workspace$ ./time-test
time() returns: 1585473408.000000

And then a little later,

user@ubuntu:~/workspace$ ./time-test
time() returns: 1585473408.000000
user@ubuntu:~/workspace$ ./time-test
time() returns: 1585473536.000000

If you check, you can actually see that the values that time() returns are multiples of 128 as well. I think it might be the operating system that's doing this on purpose but am not sure.

Is there any way to make the values be updated every 1 second? Any help or push in the right direction would be greatly appreciated!

P.S. I am using Ubuntu 18.04 on Windows with VMWare Workstation Pro.

How to find out the real cause of system soft lock?

$
0
0

I have two database nodes, and this is one of them, yesterday the other one had a system soft lock problem and i unable to solve the soft lock problem in a short time. so I restart it . And now this node also has a system soft lock too. And this is my production database!!,god, someone who can help me to find out what is the real cause of the soft lockup my linux version and os is:

[root@database02 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)
[root@database02 ~]# uname -a
Linux database02 4.1.12-112.16.4.el7uek.x86_64 #2 SMP Mon Mar 12 23:57:12 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@database02 ~]#

Part of system log like below:

Mar 29 17:30:04 database02 kernel: NMI watchdog: BUG: soft lockup - CPU#7 stuck for 22s! [ping:163683]
Mar 29 17:30:04 database02 kernel: Modules linked in: nbd fuse btrfs xor raid6_pq vfat msdos fat ext3 mbcache jbd ext2 cdp(OE) ip_set_bitmap_port ip_set_hash_ipport ip_set_hash_ipportnet ip_set_hash_ipportip dummy tcp_diag inet_diag binfmt_misc xt_set xt_multiport iptable_raw iptable_mangle ip_set_hash_ip ip_set_hash_net ipip tunnel4 ip_tunnel ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6_tables nfsv3 nfs_acl rpcsec_gss_krb5 auth_rpcgss nfsv4 dns_resolver nfs lockd grace fscache veth nf_conntrack_netlink br_netfilter bridge stp llc overlay xt_statistic xt_nat ipt_MASQUERADE nf_nat_masquerade_ipv4 ipt_REJECT nf_reject_ipv4 xt_mark xt_comment xt_conntrack ip_set nfnetlink iptable_filter xt_addrtype iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 ip_vs_sh ip_vs_wrr ip_vs_rr ip_vs nf_conntrack
Mar 29 17:30:04 database02 kernel: sunrpc ext4 jbd2 mbcache2 ppdev parport_pc parport virtio_balloon sg i2c_piix4 acpi_cpufreq pcspkr ip_tables xfs libcrc32c sr_mod cdrom ata_generic virtio_net virtio_blk virtio_console virtio_scsi pata_acpi cirrus syscopyarea sysfillrect sysimgblt drm_kms_helper ttm ata_piix drm virtio_pci libata virtio_ring serio_raw i2c_core virtio floppy dm_mirror dm_region_hash dm_log dm_mod
Mar 29 17:30:04 database02 kernel: CPU: 7 PID: 163683 Comm: ping Tainted: G           OEL Z 4.1.12-112.16.4.el7uek.x86_64 #2
Mar 29 17:30:04 database02 kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
Mar 29 17:30:04 database02 kernel: task: ffff880d00331c00 ti: ffff8809815e8000 task.ti: ffff8809815e8000
Mar 29 17:30:04 database02 kernel: RIP: 0010:[<ffffffff8174e4aa>]  [<ffffffff8174e4aa>] _raw_spin_lock+0x6a/0xd0
Mar 29 17:30:04 database02 kernel: RSP: 0018:ffff8809815ebbc8  EFLAGS: 00000202
Mar 29 17:30:04 database02 kernel: RAX: 000000000000169b RBX: ffff880981448200 RCX: 0000000000000062
Mar 29 17:30:04 database02 kernel: RDX: 00000000000092bc RSI: 00000000000092de RDI: ffffffff821560b8
Mar 29 17:30:04 database02 kernel: RBP: ffff8809815ebbe8 R08: 00000000ffffffff R09: 0000000000000000
Mar 29 17:30:04 database02 kernel: R10: ffffea003a680140 R11: ffffffff8163d6a2 R12: ffffffff8174fc53
Mar 29 17:30:04 database02 kernel: R13: ffffffff8174fc5a R14: ffffffff8174fc61 R15: ffffffff8174fc68
Mar 29 17:30:04 database02 kernel: FS:  00007fa52355b740(0000) GS:ffff880ffbdc0000(0000) knlGS:0000000000000000
Mar 29 17:30:04 database02 kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
Mar 29 17:30:04 database02 kernel: CR2: 00007fa523566000 CR3: 0000000974c9e000 CR4: 0000000000000670
Mar 29 17:30:04 database02 kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
Mar 29 17:30:04 database02 kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Mar 29 17:30:04 database02 kernel: Stack:
Mar 29 17:30:04 database02 kernel: 00000000000000c0 0000000000000001 0000000000000001 00000000000000a0
Mar 29 17:30:04 database02 kernel: ffff8809815ebc78 ffffffff811d80a5 ffff8809815ebcf8 ffffffff00000001
Mar 29 17:30:04 database02 kernel: ffff8809815ebc90 ffff8809815ebc88 00000000000000d0 ffff8809815ebc20
Mar 29 17:30:04 database02 kernel: Call Trace:
Mar 29 17:30:04 database02 kernel: [<ffffffff811d80a5>] __purge_vmap_area_lazy+0x135/0x390
Mar 29 17:30:04 database02 kernel: [<ffffffff811f82d0>] ? kmem_cache_alloc_node_trace+0x240/0x2b0
Mar 29 17:30:04 database02 kernel: [<ffffffff811d8437>] vm_unmap_aliases+0x137/0x160
Mar 29 17:30:04 database02 kernel: [<ffffffff81072ee0>] change_page_attr_set_clr+0xf0/0x520
Mar 29 17:30:04 database02 kernel: [<ffffffff8163d6a2>] ? bpf_convert_filter+0x9c2/0xa60
Mar 29 17:30:04 database02 kernel: [<ffffffff81073e6f>] set_memory_ro+0x2f/0x40
Mar 29 17:30:04 database02 kernel: [<ffffffff81180289>] bpf_prog_select_runtime+0x29/0x40
Mar 29 17:30:04 database02 kernel: [<ffffffff8163d8b3>] bpf_prepare_filter+0x173/0x190
Mar 29 17:30:04 database02 kernel: [<ffffffff8163db6e>] sk_attach_filter+0xee/0x1e0
Mar 29 17:30:04 database02 kernel: [<ffffffff8160ee56>] sock_setsockopt+0x3f6/0x940
Mar 29 17:30:04 database02 kernel: [<ffffffff816095e6>] SyS_setsockopt+0xe6/0x100
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e791>] ? system_call_after_swapgs+0xdb/0x18c
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e85a>] system_call_fastpath+0x18/0xd4
Mar 29 17:30:04 database02 kernel: Code: 08 5b 41 5c 41 5d 5d c3 41 89 d4 45 31 ed 48 33 c0 66 90 85 c0 75 65 41 0f b7 f4 b8 00 80 00 00 eb 0e 0f 1f 80 00 00 00 00 f3 90 <83> e8 01 74 40 0f b7 13 89 d1 44 31 e1 81 e1 fe ff 00 00 75 e9
Mar 29 17:30:04 database02 kernel: NMI watchdog: BUG: soft lockup - CPU#8 stuck for 22s! [sshd:163779]
Mar 29 17:30:04 database02 kernel: Modules linked in: nbd fuse btrfs xor raid6_pq vfat msdos fat ext3 mbcache jbd ext2 cdp(OE) ip_set_bitmap_port ip_set_hash_ipport ip_set_hash_ipportnet ip_set_hash_ipportip dummy tcp_diag inet_diag binfmt_misc xt_set xt_multiport iptable_raw iptable_mangle ip_set_hash_ip ip_set_hash_net ipip tunnel4 ip_tunnel ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6_tables nfsv3 nfs_acl rpcsec_gss_krb5 auth_rpcgss nfsv4 dns_resolver nfs lockd grace fscache veth nf_conntrack_netlink br_netfilter bridge stp llc overlay xt_statistic xt_nat ipt_MASQUERADE nf_nat_masquerade_ipv4 ipt_REJECT nf_reject_ipv4 xt_mark xt_comment xt_conntrack ip_set nfnetlink iptable_filter xt_addrtype iptable_nat nf_nat_ipv4 nf_nat nf_conntrack_ipv4 nf_defrag_ipv4 ip_vs_sh ip_vs_wrr ip_vs_rr ip_vs nf_conntrack
Mar 29 17:30:04 database02 kernel: sunrpc ext4 jbd2 mbcache2 ppdev parport_pc parport virtio_balloon sg i2c_piix4 acpi_cpufreq pcspkr ip_tables xfs libcrc32c sr_mod cdrom ata_generic virtio_net virtio_blk virtio_console virtio_scsi pata_acpi cirrus syscopyarea sysfillrect sysimgblt drm_kms_helper ttm ata_piix drm virtio_pci libata virtio_ring serio_raw i2c_core virtio floppy dm_mirror dm_region_hash dm_log dm_mod
Mar 29 17:30:04 database02 kernel: CPU: 8 PID: 163779 Comm: sshd Tainted: G           OEL Z 4.1.12-112.16.4.el7uek.x86_64 #2
Mar 29 17:30:04 database02 kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
Mar 29 17:30:04 database02 kernel: task: ffff8808f9f9d400 ti: ffff880980814000 task.ti: ffff880980814000
Mar 29 17:30:04 database02 kernel: RIP: 0010:[<ffffffff8174e4aa>]  [<ffffffff8174e4aa>] _raw_spin_lock+0x6a/0xd0
Mar 29 17:30:04 database02 kernel: RSP: 0018:ffff880980817c58  EFLAGS: 00000202
Mar 29 17:30:04 database02 kernel: RAX: 000000000000236c RBX: ffffffff81359980 RCX: 0000000000000058
Mar 29 17:30:04 database02 kernel: RDX: 00000000000092bc RSI: 00000000000092e4 RDI: ffffffff821560b8
Mar 29 17:30:04 database02 kernel: RBP: ffff880980817c78 R08: 00000000ffffffff R09: 0000000000000000
Mar 29 17:30:04 database02 kernel: R10: ffffea0039714800 R11: ffffffff81148d70 R12: ffffffff8174fc53
Mar 29 17:30:04 database02 kernel: R13: ffffffff8174fc5a R14: ffffffff8174fc61 R15: ffffffff8174fc68
Mar 29 17:30:04 database02 kernel: FS:  00007fadbc696880(0000) GS:ffff880ffbe00000(0000) knlGS:0000000000000000
Mar 29 17:30:04 database02 kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Mar 29 17:30:04 database02 kernel: CR2: 00007ffc688d9f84 CR3: 000000083d910000 CR4: 0000000000000670
Mar 29 17:30:04 database02 kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
Mar 29 17:30:04 database02 kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Mar 29 17:30:04 database02 kernel: Stack:
Mar 29 17:30:04 database02 kernel: ffffea000de07000 0000000000000001 0000000000000001 00000000000000a0
Mar 29 17:30:04 database02 kernel: ffff880980817d08 ffffffff811d80a5 ffff880d00e92d00 ffff880800000001
Mar 29 17:30:04 database02 kernel: ffff880980817d20 ffff880980817d18 00000000d421db98 ffff880980817cb0
Mar 29 17:30:04 database02 kernel: Call Trace:
Mar 29 17:30:04 database02 kernel: [<ffffffff811d80a5>] __purge_vmap_area_lazy+0x135/0x390
Mar 29 17:30:04 database02 kernel: [<ffffffff811d8437>] vm_unmap_aliases+0x137/0x160
Mar 29 17:30:04 database02 kernel: [<ffffffff81072ee0>] change_page_attr_set_clr+0xf0/0x520
Mar 29 17:30:04 database02 kernel: [<ffffffff8163d6a2>] ? bpf_convert_filter+0x9c2/0xa60
Mar 29 17:30:04 database02 kernel: [<ffffffff81073e6f>] set_memory_ro+0x2f/0x40
Mar 29 17:30:04 database02 kernel: [<ffffffff81180289>] bpf_prog_select_runtime+0x29/0x40
Mar 29 17:30:04 database02 kernel: [<ffffffff81148d8d>] do_seccomp+0x88d/0x8e0
Mar 29 17:30:04 database02 kernel: [<ffffffff810701e9>] ? __do_page_fault+0x1c9/0x460
Mar 29 17:30:04 database02 kernel: [<ffffffff811491c4>] prctl_set_seccomp+0x24/0x50
Mar 29 17:30:04 database02 kernel: [<ffffffff8109f631>] SyS_prctl+0x3a1/0x490
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e7a6>] ? system_call_after_swapgs+0xf0/0x18c
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e79f>] ? system_call_after_swapgs+0xe9/0x18c
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e791>] ? system_call_after_swapgs+0xdb/0x18c
Mar 29 17:30:04 database02 kernel: [<ffffffff8174e85a>] system_call_fastpath+0x18/0xd4
Mar 29 17:30:04 database02 kernel: Code: 08 5b 41 5c 41 5d 5d c3 41 89 d4 45 31 ed 48 33 c0 66 90 85 c0 75 65 41 0f b7 f4 b8 00 80 00 00 eb 0e 0f 1f 80 00 00 00 00 f3 90 <83> e8 01 74 40 0f b7 13 89 d1 44 31 e1 81 e1 fe ff 00 00 75 e9

How to build linux kernel module using Yocto SDK?

$
0
0

I am trying to build a linux kernel module using Yocto SDK. However, I am running into compilation error where it complains about

./include/uapi/asm-generic/int-ll64.h:12:10: fatal error: asm/bitsperlong.h: No such file or directory
 #include <asm/bitsperlong.h>

Here is my Makefile

ARCH ?= arm
CROSS_COMPILE ?= arm-poky-linux-gnueabi-
KERNELDIR ?= /opt/poky/2.7.3/sysroots/cortexa9t2hf-neon-poky-linux-gnueabi/usr/src/kernel/
PWD := $(shell pwd)

.PHONY: build clean

build:
    $(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c modules.order  Module.symvers

# Incorporate modules into a multi-part driver
my-objs := hello.o    


$(info Building with KERNELRELEASE = ${KERNELRELEASE})
EXTRA_CFLAGS+=-I$(PWD)/../include
obj-m := hello.o

Before I invoke make, I am setting up the source environment.

$source /opt/poky/2.7.3/environment-setup-cortexa9t2hf-neon-poky-linux-gnueabi     
$make

recv with flags MSG_DONTWAIT | MSG_PEEK on TCP socket

$
0
0

I have a TCP stream connection used to exchange messages. This is inside Linux kernel. The consumer thread keeps processing incoming messages. After consuming one message, I want to check if there are more pending messages; in which case I would process them too. My code to achieve this looks like below. krecv is wrapper for sock_recvmsg(), passing value of flags without modification (krecv from ksocket kernel module)

With MSG_DONTWAIT, I am expecting it should not block, but apparently it blocks. With MSG_PEEK, if there is no data to be read, it should just return zero. Is this understanding correct ? Is there a better way to achieve what I need here ? I am guessing this should be a common requirement as message passing across nodes is used frequently.

int recvd = 0;

do {
            recvd   += krecv(*sockp, (uchar*)msg + recvd, sizeof(my_msg) - recvd, 0); 
            printk("recvd = %d / %lu\n", recvd, sizeof(my_msg));
} while(recvd < sizeof(my_msg));
BUG_ON(recvd != sizeof(my_msg));

/* For some reason, below line _blocks_ even with no blocking flags */
recvd = krecv(*sockp, (uchar*)tempbuf, sizeof(tempbuf), MSG_PEEK | MSG_DONTWAIT);
if (recvd) {
            printk("more data waiting to be read");
            more_to_process = true;
} else {
            printk("NO more data waiting to be read");
}

Confused on creation of binary sysfs entry

$
0
0

On kernel 4.0, when stepping through the kernel source for sysfs_create_bin_file, I notice it passes to sysfs_add_file(kobj->sd, &attr->attr, true); The &attr->attr being the struct attribute struct within the bin_attribute struct.

This makes sense until I visit sysfs_add_file_mode_ns, which is directly called from sysfs_add_file, and on line #277 sets temp variable stuct bin_attribute *battr = (void*)attr;

Isn't this pointing to a struct attribute at this point, how is it resolving this to the proper struct (due to the call to sysfs_add_file using &attr->attr on line #483)?

Code

int sysfs_create_bin_file(struct kobject *kobj,
              const struct bin_attribute *attr)
{
    BUG_ON(!kobj || !kobj->sd || !attr);

    return sysfs_add_file(kobj->sd, &attr->attr, true);
}

int sysfs_add_file(struct kernfs_node *parent, const struct attribute *attr,
           bool is_bin)
{
    return sysfs_add_file_mode_ns(parent, attr, is_bin, attr->mode, NULL);
}

int sysfs_add_file_mode_ns(struct kernfs_node *parent,
               const struct attribute *attr, bool is_bin,
               umode_t mode, const void *ns)
{
    struct lock_class_key *key = NULL;
    const struct kernfs_ops *ops;
    struct kernfs_node *kn;
    loff_t size;

    if (!is_bin) {
        ...
    } else {


        struct bin_attribute *battr = (void *)attr;
         ...
    }

Hardware chip : Nand gate [closed]

$
0
0

Presently their is a requirement to replace the old nand chip with the new one in the hardware which runs linux OS. As i am new to linux device drivers. Can anyone help me out like what is the procedure and 2. what all things to take care off. like device file or driver.

Can anyone explain me what happens when a nand driver gets updated in the linux system.

Using : linux system v18


adding a simple system call to linux kernel

$
0
0

I've just added a system call to the linux kernel. It simply takes a char* argument name and prints Hello name.

This is system call code:

asmlinkage long sys_hello(char* name) { printk("Hello %s \n", name); return 0; }

and this is the code which should run the system call for testing:

int main() 
{
    long int amma  = syscall(318,"Winston");
    printf("Returned %lu \n" ,amma);  
    return 0; 
}

but when I run this, I get a killed output. Any ideas about fixing this? Thanks in advance.

How to get list of deprecated kernel functions for different kernel versions (and possibly replacements)?

$
0
0

While compiling an external linux kernel module for a 5.0 kernel version (x64 module on native x64 system) with deprecated function 'timespec_sub' (was compileable at least until kernel version 4.15) it occurred that it is difficult to find suitable replacements or updated kernel functions for the deprecated ones.

Is there a list or other summary of deprecated kernel functions and recommended function replacements/updates for different kernel versions?

How do I install a custom kernel on a google compute engine instance?

$
0
0

I would like to install a custom kernel image on a Google Compute Engine instance. I have an instance running with:

foo@instance-1:/boot/efi$ uname -a
Linux instance-1 4.10.0-22-generic #24-Ubuntu SMP Mon May 22 17:43:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

And I've built and installed my kernel image:

sudo dpkg -i linux-image-4.10.0-rc8.10.0-rc8_amd64.deb

It shows up in the grub configuration file, I've set the default grub menu item to correct number, and I've run

sudo update-grub

Yet, when I reboot, I get the same kernel I started with.

Google documentation on this seems to be non-existent. There is one spot that suggests I might have to create the image externally, install the kernel, and import it. However, I will need to do this a lot, so I'd rather just install new kernels the old fashioned way.

Compile gpio-mockup in 5.4

$
0
0

I've checked out kernel 5.4 source and tried to compile gpio-mockup.c by running make -C /lib/modules/$(uname -r)/build M=$(pwd) modules the build succeeds but there is no gpio-mockup.ko. I think this means that I need to provide some configuration value but I don't know how and I don't know where. Regardless, can anyone help me to build the gpio-mockup kernel module?

Clone a file in linux kernel module

$
0
0

I'm having some problem with a linux module, I want to clone a file from a file descriptor. I tried using

vfs_clone_file_range

but i receive EOPNOTSUPP error. So I tried to use vfs_copy_file_range, and the copy works correctly, but I need to have also the same flags of the original one, but in this way, even if the original is open with O_APPEND the pointer of the copy is always at the begin of the file.

This is my code:

//The file descriptor is taken correctly and it works
original_filp = fcheck(o_fd);
copy_filp = filp_open(addr, O_CREAT | O_RDWR  , 0644);
vfs_copy_file_range(original_filp, 0, copy_filp, 0, i_size_read(original_filp->f_inode), 0);

The content is the right but the pointer, as I said is at the begin even with the O_APPEND flag, so I should move the pointer explicitly. I also tried to add this line, but without results:

copy_filp->f_pos = original_filp->f_pos;

I really have no idea what to change in order to make it working. Thank you in advance for your help

Viewing all 12290 articles
Browse latest View live


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