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

Creating New Folder in Linux [closed]

$
0
0

How can I add new folder in linux? I checked the permission but the Owner is mentioned as "root" and I can't change it. Don't know what to do and how?

I tried to get the authorization using terminal by installing "gksu" through these commands:

$ sudo apt install gksu

$ gksu nautilus

also tried this:

$ sudo su

$ chmod 777 ./plugins

nothing worked out. no output Please tell me what to do if someone have idea

enter image description here


PCI error handler in kernel driver never called, even when device is turned off

$
0
0

I'm writing a linux kernel device driver for a custom PCIe device. A user space application is mmapped to this device and frequently accessing its memory (read and write). The PCIe device is driven by an external power supply which may be turned off during runtime.

Whenever the device is reset, all memory reads of my user application return 0xFFFFFFFF. I want to detect device resets as soon as possible in the kernel driver, so I implemented an error_detected callback function according to https://www.kernel.org/doc/html/latest/PCI/pci-error-recovery.html.

static pci_ers_result_t mydevice_error_detected(struct pci_dev* dev, pci_channel_state_t state) {
   printk(KERN_ALERT "mydevice PCI error detected");
   return PCI_ERS_RESULT_DISCONNECT;
}

static struct pci_error_handlers mydevice_error_handlers = {
   .error_detected = mydevice_error_detected,
   .slot_reset = mydevice_slot_reset,
   .resume = mydevice_resume
};

static struct pci_driver mydevice_driver = {
   .name = "mydevice",
   .id_table = mydevice_ids,
   .probe = mydevice_probe,
   .remove = mydevice_remove,
   .suspend = mydevice_suspend,
   .resume = mydevice_resume,
   .err_handler = &mydevice_error_handlers
};

However, mydevice_error_detected is never called during device reset, even though the user space application is continuously trying to unsuccessfully read device memory (and get 0xFFFFFFFF as result).

Also, lspci still lists the device after PCI rescan, even if it got turned off:

01:00.0 Unassigned class [ff00]: MyVendorId Device 5a00 (rev ff)

The only difference is that "rev ff" occurs at the end of the line when the device is in turned off state. Otherwise lspci returns

01:00.0 Unassigned class [ff00]: MyVendorId Device 5a00

I'm pretty sure the device is completely turned off, since configuration space can not be accessed during reset. I'd expect the kernel to call the error detection callback whenever the first memory read request to the device fails/timeouts. Is my assumption correct?

Can't see kernel symbols in 'perf report' when trying to trace a probe on CentOS 7.7

$
0
0

I'm trying to see what kernel code calls a specific function on CentOS 7.7 (x86-64). I've tried this:

perf probe -a vsnprintf
perf record -e probe:vsnprintf -aR sleep 10

Then, when I try:

perf report --stdio

I see only a bunch of hex numbers in the output instead of function names:

# Total Lost Samples: 0
#
# Samples: 331  of event 'probe:vsnprintf'
# Event count (approx.): 331
#
# Children      Self  Trace output      
# ........  ........  ..................
#
   100.00%   100.00%  (ffffffffaf58c750)
            |          
            |--56.19%--0
            |          __GI___libc_read
            |          0xffffffffaf98bede
            |          0xffffffffaf4493bf
            |          0xffffffffaf4484ff
            |          0xffffffffaf4c09b0

The kernel version (I'm running inside a VM on KVM):

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I've picked up vsnprintf because it shows up often in 'perf top' (the kernel symbol - there I see the symbols correctly).

Is there a way to see actual function names?

how to map a certain kernel space to different virtual machine?

$
0
0

I am doing something like "shared memory", I want to map the virtual address in KVM to the same PFN so that I can share information between virtual machines. However I encounter some problems.

  1. the mmap() called inside the virtual machine can not be trapped by host, can I possibly trap that call?

  2. I have try to modify the hva -> pfn mapping by remap_pfn_range() function, but it crash my virtual machine everytime. Is it forbidden to change that mapping in running process? How can I finish that point?

LKM: System freeze upon using insmod

$
0
0

I'm new in kernel development. I'm trying to see if I can make a call to a function from the __init section. But after building the module, when I use insmod XXX.ko to insert my module, my system does not respond. I have to restart my machine. I follow the solution and approach from this question but did not help.

Here is my source code for the __init section, __exit section and the test_readfunction that I'm trying to call:

unsigned long test_read(const struct pt_regs *regs){

  printk(KERN_INFO "Inside test_read");
  unsigned int fd = regs->di;
  char *buf = (char*) regs->si
  unsigned long r=1;

  char *kbuf=(char*)kmalloc(256,GFP_KERNEL);
  printk(KERN_INFO "File descriptor\n");
  printk(KERN_CONT "%lu",fd);
  printk(KERN_INFO "User Buffer\n");
  printk(KERN_CONT "%p",buf);
  return r;
}

static int __init kit_start(void)
{    
 sys_call_table = kallsyms_lookup_name("sys_call_table");
 printk(KERN_INFO "System call address ");
 printk(KERN_CONT "%p",sys_call_table);
 original_read = (void *)sys_call_table[__NR_read];
 printk(KERN_INFO "Original read address ");
 printk(KERN_CONT "%p",original_read);

 register uint64_t cr0;
 cr0 = getcr0();
 rw_enable();
 sys_call_table[__NR_read]=test_read;
 rw_disable( cr0 );

 return 0;
 }

void __exit kit_exit(void)
{
  printk(KERN_INFO "Exiting");
  register uint64_t cr0;
  cr0 = getcr0();

  rw_enable();
  sys_call_table[ __NR_read ] = original_read;        
  rw_disable( cr0 );

 }

Full source code is available here. Any idea what did I do wrong. I'm Using x86-64 with 5.3.0-42-generic kernel

Update Post:

Instead of using rw_enable() and rw_disable( cr0 ), if i use

write_cr0 (read_cr0 () & (~ 0x10000));
sys_call_table[__NR_read]=test_read;
write_cr0 (read_cr0 () | 0x10000);

Upon using the insmod to insert the module, terminal shows "Killed" and dmesg shows an error when try to execute sys_call_table[__NR_read]=test_read;

BUG: unable to handle page fault for address: ffffffff820002a0
#PF: supervisor write access in kernel mode
#PF: error_code(0x0003) - permissions violation

source code here

crypto_akcipher_set_pub_key in kernel asymmetric crypto always returns error

$
0
0

I'm working on a kernel module which uses asymmetric cipher of kernel crypto api, kernel version 4.8.0. I generate asymmetric key pairs by openssl, convert them into DER format (which I knew was a subset of BER), and code into my module. Private key works just fine, but public key always fails at crypto_akcipher_set_pub_key, even if I try more other key pairs. dmesg just prints:

[16891.604718] next_op: pc=0/10 dp=0/161 C=0 J=0
[16891.604721] - match? 30 30 00
[16891.604724] - TAG: 30 158 CONS
[16891.604726] next_op: pc=2/10 dp=3/161 C=1 J=0 
[16891.604727] - match? 30 02 32
[16891.604729] 
               ASN1: Unexpected tag [m=2 d=4 ot=02 t=30 l=158]
[16891.604730] set key error! -74,,,,,0

Here are my questions:

A) Does dmesg mean the public key is wrong? How to generate a kernel-crypto-compatible key pairs?

B) I cannot find a useable rsa key pairs for kernel asymmetric cipher, not even in Linux/crypto/testmgr.h or libkcapi/test/test.sh, can you help me out?

Thanks!

Here is my module:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/crypto.h>
#include <linux/scatterlist.h>
#include <linux/gfp.h>
#include <linux/err.h>
#include <linux/syscalls.h>
#include <linux/slab.h>
#include <crypto/skcipher.h>
#include <crypto/akcipher.h>
#include <linux/random.h>
#include <linux/delay.h>
#include <linux/highmem.h>
const char *priv_key =
    "\x30\x82\x02\x5d\x02\x01\x00\x02\x81\x81\x00\xd0""\xb4\x5a\xc1\x9e\x2e\x4d\xae\xbd\x51\x39\xcc\x4b""\x12\xf5\x76\x30\xcf\x39\x97\xf1\xd3\x0d\xaa\x37""\x70\x2d\x2f\x01\xc9\x69\x09\xe3\x4e\xd5\x90\x68""\xfe\xbf\x7c\x8b\x86\xdf\xf3\x14\xb3\x96\xcf\x1b""\x39\xe3\xe6\x8a\x77\x6d\xe4\x89\xef\xdb\xba\x4a""\x40\x6d\xa9\xec\x21\x62\x00\xa4\xc3\x45\xcc\xdd""\x56\xb2\x77\x59\x46\x17\x27\x0e\x2c\xfe\x85\x53""\x72\x26\x9b\xdc\x24\x83\xd1\x67\xa7\x4c\x88\x70""\x78\x3f\x1c\x60\xd4\x95\x14\x57\xfc\xdb\x15\xaa""\xab\x31\x32\xb2\x44\x72\xdd\xb0\x0b\x13\x62\x03""\x50\x1d\xd4\x6a\xf6\xb2\x23\x02\x03\x01\x00\x01""\x02\x81\x80\x7b\x83\x10\xe6\xde\xf7\x26\x30\x10""\x88\x3e\x7d\x61\xbc\xa1\x99\xc5\xbf\x0d\xa5\x97""\x8e\xc0\xda\x88\x9e\x91\x8e\xed\x2e\xc6\x43\xfc""\xcb\x0d\xe6\xbd\xcc\x6d\x84\x86\x8a\x56\x84\xe4""\x2e\x78\x44\xaf\x27\x2e\x71\xa4\x66\x93\x99\x99""\xec\x62\x8c\x38\x1f\x33\x06\x37\xc1\x9d\x17\x6b""\xad\xfb\x8e\x44\xd3\x11\xcb\x74\xa4\x01\x78\xb0""\x9c\x64\xd3\x0d\x63\x99\x65\xe3\xca\xae\x11\xb2""\xc4\x00\x36\xc2\xfc\x4b\x7b\x6f\x9e\x84\xb6\x97""\x00\x56\x5b\x09\xa1\x28\xf5\x28\x8d\xc7\x93\x45""\xba\xc0\x6b\xa9\x2d\xeb\x02\xcd\xde\x1e\x29\x02""\x41\x00\xf6\x0e\x41\xbc\xfa\x40\x82\xba\xa0\x6a""\xa5\x75\x5c\xcd\xfe\xa8\x11\xa6\xef\xbc\xad\x5f""\x86\x40\xb4\x5a\x65\xc1\x7b\x5e\x89\xc2\x60\x38""\x0e\x8b\x7d\x7d\x99\x30\x01\xf1\xea\x1e\x3e\x46""\xf4\xd2\xd9\x80\xaf\x3a\x4b\x2f\xbb\x91\xbb\xb7""\x22\x2d\x6a\x0f\x4e\x6f\x02\x41\x00\xd9\x23\xa7""\x98\x0c\x58\xe1\x5d\xa7\x15\x05\xc6\xd9\x7b\xc5""\x7b\xd3\x01\x8b\x1e\xf1\x2e\x99\xc5\xac\x41\xf1""\x92\x88\xd9\x8e\x50\x86\xf9\x2f\x66\x42\xeb\xf9""\x80\x78\xfa\xc7\xea\x63\x35\x7e\x6f\xc5\x35\x36""\x6b\xa1\x8a\xa3\x49\x97\xbc\xa6\x9b\x5c\x6e\xf1""\x8d\x02\x40\x44\x70\xa0\xbe\x64\xc9\x4e\xd3\x84""\x4d\x45\xaa\x88\x5e\xcf\xe7\x85\xc9\x6e\x43\x87""\xe1\xdb\x20\xe2\x49\x86\xa6\x33\x9f\x8f\x27\xde""\xc5\x98\xde\x19\xd0\xb6\xac\x50\xce\x2e\x35\xad""\x52\xe5\x44\x44\xb5\x73\x87\xfe\x63\xcf\x83\x70""\xb8\x36\xac\x75\x24\xbe\xc7\x02\x41\x00\x87\xd2""\x97\xa8\xb2\x40\x7e\x67\xf8\x75\x5b\xf1\xb0\x64""\x8d\x79\x10\xd9\xec\x4d\xe4\x8b\x43\xc0\xb4\x29""\x63\x94\x47\x69\xde\x6d\x5c\xa0\x4e\x17\xe7\x50""\x77\xf6\xf6\xb5\xd7\x8b\x33\x97\x68\x89\x3d\x90""\x35\x84\x49\xbd\xd0\xb9\xdd\xe2\x31\x4d\x09\x1a""\x94\x99\x02\x41\x00\xc9\x12\xec\x64\xe9\x01\x27""\x10\x6c\xad\xc5\x83\x8a\x26\x39\xe0\x05\xde\xde""\xf9\x1a\x5d\xf6\xcb\xe8\xd2\x9b\x40\xd5\x11\xc8""\x9a\x6d\x29\xb6\x15\x36\x9a\xee\x45\xe2\x51\x14""\xa8\x2d\xab\x57\x86\x80\x87\x0a\x02\xaf\xfa\xda""\x5e\x7d\xfb\x84\xd1\x3a\xe0\xed\x57";
const int priv_key_len = 609;

const char *pub_key =
    "\x30\x81\x9e\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7""\x0d\x01\x01\x01\x05\x00\x03\x81\x8c\x00\x30\x81""\x88\x02\x81\x80\x6d\x4d\xaf\xf5\x32\x98\xfa\x33""\xf2\x4a\xb0\x50\x27\x6f\x50\x0b\x28\xca\x5f\x6e""\xde\xec\x7b\xae\xeb\xd1\x89\xdf\xcf\x8d\x12\x6c""\x0d\xf2\x32\x65\xb7\x04\xf2\xb8\x76\x67\xe9\x28""\xc3\x12\x6b\x4a\x52\x09\xd6\x61\x9b\x21\x25\x04""\xe0\x9a\xec\xbc\x25\x3f\xfc\x6f\x1a\x98\xa8\x02""\xa8\x2e\x89\x91\x20\xcf\xf0\xd1\x9d\x09\x35\xac""\x95\xe2\xe4\x8e\x5b\x7c\x34\x93\x39\x4f\x33\xbd""\x6e\xe7\xc5\xbb\x2a\x28\x32\x13\x62\x39\x37\x87""\x40\xe7\x59\xf8\x94\xad\xc4\x2e\xaf\x23\xf4\x98""\xcd\x90\x27\x96\x41\xc6\x4a\xcd\x6d\x56\xfd\x5b""\x02\x03\x01\x00\x01";
const int pub_key_len = 161;

const char *msg = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
const int msg_len = 8;

char *crypted = NULL;
int crypted_len = 0;

struct tcrypt_result {
    struct completion completion;
    int err;
};

struct akcipher_testvec {
    unsigned char *key;
    unsigned char *msg;
    unsigned int key_size;
    unsigned int msg_size;
};

static inline  void hexdump(unsigned char *buf,unsigned int len) {
    while(len--)
        printk("%02x",*buf++);
    printk("\n");
}

static void tcrypt_complete(struct crypto_async_request *req, int err)
{
    struct tcrypt_result *res = req->data;

    if (err == -EINPROGRESS)
        return;

    res->err = err;
    complete(&res->completion);
}

static int wait_async_op(struct tcrypt_result *tr, int ret)
{
    if (ret == -EINPROGRESS || ret == -EBUSY) {
        wait_for_completion(&tr->completion);
        reinit_completion(&tr->completion);
        ret = tr->err;
    }
    return ret;
}

static int uf_akcrypto(struct crypto_akcipher *tfm,
                         void *data, int datalen, int phase)
{
    void *xbuf = NULL;
    struct akcipher_request *req;
    void *outbuf = NULL;
    struct tcrypt_result result;
    unsigned int out_len_max = 0;
    struct scatterlist src, dst;

    int err = -ENOMEM;
    xbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
    if (!xbuf)
         return err;

    req = akcipher_request_alloc(tfm, GFP_KERNEL);
    if (!req)
         goto free_xbuf;

    init_completion(&result.completion);


    if (!phase)  //test
         err = crypto_akcipher_set_pub_key(tfm, pub_key, pub_key_len);
    else
         err = crypto_akcipher_set_priv_key(tfm, priv_key, priv_key_len);

//  err = crypto_akcipher_set_priv_key(tfm, priv_key, priv_key_len);
    if (err){
        printk("set key error! %d,,,,,%d\n", err,phase);
        goto free_req;
    }

    err = -ENOMEM;
    out_len_max = crypto_akcipher_maxsize(tfm);
    outbuf = kzalloc(out_len_max, GFP_KERNEL);
    if (!outbuf)
         goto free_req;

    if (WARN_ON(datalen > PAGE_SIZE))
         goto free_all;

    memcpy(xbuf, data, datalen);
    sg_init_one(&src, xbuf, datalen);
    sg_init_one(&dst, outbuf, out_len_max);
    akcipher_request_set_crypt(req, &src, &dst, datalen, out_len_max);
    akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
                               tcrypt_complete, &result);

    if (phase){
        err = wait_async_op(&result, crypto_akcipher_encrypt(req));
        if (err) {
            pr_err("alg: akcipher: encrypt test failed. err %d\n", err);
            goto free_all;
        }
        memcpy(crypted,outbuf,out_len_max);
        crypted_len = out_len_max;
        hexdump(crypted, out_len_max);
    }else{
        err = wait_async_op(&result, crypto_akcipher_decrypt(req));
        if (err) {
            pr_err("alg: akcipher: decrypt test failed. err %d\n", err);
            goto free_all;
        }
        hexdump(outbuf, out_len_max);
    }

free_all:
    kfree(outbuf);
free_req:
    akcipher_request_free(req);
free_xbuf:
    kfree(xbuf);
    return err;
}


static int userfaultfd_akcrypto(void *data, int datalen, int phase)
{
     struct crypto_akcipher *tfm;
     int err = 0;

     tfm = crypto_alloc_akcipher("rsa", CRYPTO_ALG_INTERNAL, 0);
     if (IS_ERR(tfm)) {
             pr_err("alg: akcipher: Failed to load tfm for rsa: %ld\n", PTR_ERR(tfm));
             return PTR_ERR(tfm);
     }
     err = uf_akcrypto(tfm,data,datalen,phase);

     crypto_free_akcipher(tfm);
     return err;
}

static int __init test_init(void)
{   
    crypted = kmalloc(PAGE_SIZE, GFP_KERNEL);
    if (!crypted){
        printk("crypted kmalloc error\n");
        return -1;
    }

    userfaultfd_akcrypto(msg,msg_len,1);
    userfaultfd_akcrypto(crypted,crypted_len,0);
    kfree(crypted);
}

static void __exit test_exit(void)
{

}

module_init(test_init);
module_exit(test_exit);

MODULE_LICENSE("GPL");

which function that linux kernel use to kick start the scheduler

$
0
0

Hi I am studying the Linux kernel source code, and am trying to understand how Linux kernel scheduler works, the question I have is: Is there a function in linux kernel for the kernel to kick start the scheduler and is there a flow chart with all the kernel function sys call that I can refer to about the scheduling part? I can find the TCP/IP stack flow chart quite easily but not the scheduling part. Any help is greatly appreciated !

Obtaining real device of VLAN-interface through the netlink

$
0
0

I need to obtain the real_dev (f.e. ID) of the given VLAN-inteface.

I wrote some test snippet using libnl:

int main(void) {
     struct nl_sock *sock;
     struct nl_cache *cache;
     char iface[] = "eno1.10";
     //char iface[] = "eno1";

     if (!(sock = nl_socket_alloc())) {
          perror("nl_socket_alloc");
          return -1; 
     }

     if (nl_connect(sock, NETLINK_ROUTE) < 0) {
          perror("nl_connect");
          nl_socket_free( sock );
          return -1; 
     }

     if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache) < 0) {
          perror("rtnl_link_alloc_cache");
          nl_socket_free( sock );
          nl_close( sock );
          return -1; 
     }
     {   
          int ifindex; 
          struct rtnl_link *link = NULL;

          if (!(ifindex = rtnl_link_name2i(cache, iface))) {
               perror("rtnl_link_name2i");
               return -1; 
          }
          printf("ind: %d\n", ifindex);

          if (!(link = rtnl_link_get(cache, ifindex))) {
               perror("rtnl_link_get");
               return -1; 
          }

          if (rtnl_link_is_vlan(link)) {
               puts("It's VLAN link");

               /* alas it's not about the 'real' device */
               printf("master: %d\n", rtnl_link_get_master(link));
          } else
               puts("It's 'real' link");
     }   

     return 0;
}

So I have some interface ID and I can check if it's a VLAN-interface, but I have no idea how to obtain the interface the vlan is attached to. It seems that libnl's API does not provide such possibility.

Is there a way to obtain the VLAN's "parent" interface ID through the libnl or the native netlink API?


I couldn't boot the Linux kernel with my new U-Boot environment variable

$
0
0

Use the following command to start the kernel:

setenv bootnet 'tftp 80800000 zImage;tftp 83000000 xxx.dtb'
saveenv
run bootnet
bootz 80800000 - 83000000

But using the following command will stop at the Starting Kernel:

setenv bootnet 'tftp 80800000 zImage; tftp 83000000 xxx.dtb; bootz 80800000 - 83000000’
saveenv
run bootnet

SoC is Freescale IMX6ULL.

Thanks.

Android Dalvik scheduler linux kernel question

$
0
0

Dalvik VM can run several independent processes that are managed by the linux kernel and are executed according to priority, but kerel uses CFS (completely fair scheduler). can the scheduler be changed so that it doesn't use CFS? And could it become a Real time system? I am asking for any information

Read from /proc/$PID/smaps is slow

$
0
0

We need to monitor memory usage of our high-loaded service every minute by cron.

For this we are reading /proc/PID/smaps and somehow parse it.

But we are encountering timing problems exactly every minute. When monitoring cron is turned off, there is no timing problems.

Only expensive and suspicious operation in our code is that reading of /proc/PID/smaps.

Is there in Linux kernel any lock/mutex/something else while reading smaps?

And is there any other more transparent method to detect memory usage?

There's problem if remove one kernel from centos 7

$
0
0

have problem with install Symantec agent in amzn2 ec2 , need to remove the kernel version kernel-4.14.152-127.182.amzn2.x86_64 , there's problem if delete it

Using float, double arithmeetic causes warnings on arm

$
0
0

I have a device driver which was compiling fine using arm-linux-gnueabi- I added a few double and float operations into the code and I have been getting the following warnings at compilation:

WARNING: "__aeabi_dsub" [/home/preetam/Desktop/pwm_driver/driver/pwm_dev.ko] undefined! WARNING: "__aeabi_d2uiz" [/home/preetam/Desktop/pwm_driver/driver/pwm_dev.ko] undefined! WARNING: "__aeabi_dmul" [/home/preetam/Desktop/pwm_driver/driver/pwm_dev.ko] undefined! WARNING: "__aeabi_ddiv" [/home/preetam/Desktop/pwm_driver/driver/pwm_dev.ko] undefined! WARNING: "__aeabi_ui2d" [/home/preetam/Desktop/pwm_driver/driver/pwm_dev.ko] undefined!

Does it mean that the compiler and/or the arm platform does not support floating and double data types?

How do I deal with this situation. I need to be able to do the math to get the proper functionality.

Yocto device-tree interrupt on certain pin

$
0
0

I am working on a custom .dts file for my beaglebone cape. I've successfully created a bsp-layer and custom image, everythin is working fine. Now i want to make changes in a device-tree to assign certain pins to their roles. I've used a tool provided by ti (pinmux). I am struggling to assign an interrupt to few certain gpio pins. Let's say i've got this inside my .dtsi:

gpio0_pins_default: gpio0_pins_default {
    pinctrl-single,pins = <
        AM33XX_IOPAD(0x820, PIN_INPUT | MUX_MODE7) /* (U10) gpmc_ad8.gpio0[22] */
        AM33XX_IOPAD(0x824, PIN_INPUT_PULLUP | MUX_MODE7) /* (T10) gpmc_ad9.gpio0[23] */
        AM33XX_IOPAD(0x828, PIN_INPUT | MUX_MODE7) /* (T11) gpmc_ad10.gpio0[26] */
        AM33XX_IOPAD(0x82c, PIN_INPUT | MUX_MODE7) /* (U12) gpmc_ad11.gpio0[27] */
    >;
};

Now, i want to assign an interrupt to pin 27 of gpio0 which is active low. How do i proceed? I've read too many sources providing different information, and got confused hence i'm asking for some advice.

Inside interrupt-controller documentation i've found this, but i dont understand few things.

           gpioext: gpio-adnp@41 {
                    compatible = "ad,gpio-adnp";
                    reg = <0x41>;

                    interrupt-parent = <&gpio>;
                    interrupts = <160 1>;

                    gpio-controller;
                    #gpio-cells = <1>;

                    interrupt-controller;
                    #interrupt-cells = <2>;

                    nr-gpios = <64>;s

Where does reg value 41 some from? So far i've thought this was supposed to be an address of a certain GPIO (ex. reg = <0x4804c00 0x1000>;). I understand interrupt-cells and interrupts declaration. Does nr-gpios = pin number to which I want to assign interrupt to ?

Inside am33xx.file i've found this declaration:

gpio0: gpio@44e07000 {
            compatible = "ti,omap4-gpio";
            ti,hwmods = "gpio1";
            gpio-controller;
            #gpio-cells = <2>;
            interrupt-controller;
            #interrupt-cells = <2>;
            reg = <0x44e07000 0x1000>;
            interrupts = <96>;
        };

But in my understanding it's just a setting for a whole GPIO, correct?

Could anybody be so king and provide me an example of a code for setting up an interrupt for lets say pin 27 and 23 active low?

Thanks in advance BR

When VmallocUsed in /proc/meminfo will increase

$
0
0

I see the following fields in /proc/meminfo related to vmalloc.

VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB

So, i wrote a basic kernel module which allocates memory using vmalloc to find out whether the 'VmallocUsed' field updates to the memory i allocated.

Here is the kernel module

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/vmalloc.h>
#include <linux/moduleparam.h>

MODULE_LICENSE("GPL");

static char *ptr;
int alloc_size = 4096*1234;


static int test_hello_init(void)
{
    ptr = vmalloc(alloc_size);
    if(!ptr) {
        /* handle error */
        pr_err("memory allocation failed\n");
        return -ENOMEM;
    } else {
        pr_info("Physical address:%px\t Virtual Address:%llx\n", 
                ptr+4096, virt_to_phys(ptr+(4096*1234)));
    }
    return 0;
}

static void test_hello_exit(void)
{
    vfree(ptr);
    pr_info("Memory freed\n");

}

module_init(test_hello_init);
module_exit(test_hello_exit);

After loading the module, I don't see the 'VmallocUsed' incremented by what I allocate.

What is the use of 'VmallocUsed' and 'VmallocChunk' field in the /proc/meminfo?


How can I tell the compiler/CPU to execute instructions back to back in kernel space's code?

$
0
0

How can I tell the compiler not to optimize and not to add any other instructions in between, and force the CPU to execute them back to back?

For example I'd like the kernel module to execute write (or read or mixed) commands as fast as possible

writel(0, addr);
writel(1, addr);
writel(0, addr);

or

writel(0, addr1);
writel(1, addr2);
writel(0, addr3);

Edit:

  • I replaced iowrite32 with writel that has a definition with volatile void __iomem *addr

  • addr* can be allocated with dma_alloc_coherent() or simply ioremap().

  • My question isn't about order of execution (that is solved with memory barrier or volatile) but delay between them.

  • Might be possible by combining my commands in a single assembly asm volatile() but I'd rather use something safer.

How beaglbone black linux is booted?

$
0
0

I am trying to make my own image for beaglbone black and I am a bit lost in boot process. I understand the sequence: ROM bootloader -> MLO -> u-boot -> kernel. However going from theory to practice is hard.

The questions are simple:

  1. Where should MLO, u-boot, kernel image and dtb files be placed?
  2. How should my kernel image be named?

Some articles state that I have to create bootable FAT32 partition at the very beginning of flash memory and place MLO, u-boot there.

Other articles state that I have to copy MLO and u-boot.img to rootfs/boot just do it before populating any other files. Same article has kernel image named zImage however if u-boot is used shouldn't it be uImage?

Other articles use uImage. However I can not see any consensus on LOADADDR. It seems like everyone chooses it randomly between several somewhere defined values(often 0x8000000, 0x80008000, 0x82000000).

Nevertheless having installed official image I can not see neither u-boot or MLO in /boot nor FAT32 partition with them:

ls boot/
config-4.14.108-ti-r113  dtbs  initrd.img-4.14.108-ti-r113  SOC.sh  System.map-4.14.108-ti-r113  uboot  uEnv.txt  vmlinuz-4.14.108-ti-r113
ls boot/uboot/
# Nothing here 

sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL /dev/mmcblk0
NAME        FSTYPE  SIZE MOUNTPOINT          LABEL
mmcblk0            14,4G                     
└─mmcblk0p1 ext4    3,5G /media/yuriy/rootfs rootfs

On top of that kernel image is called vmlinuz-4.14.108-ti-r113 so what the hell is it, uImage or zImage?

So I have 4 source and all of them tell me to do a different thing. What am I missing here?

Extending Kaldi Aspire: bad variable error while Recompiling HCLG.fst using new lexicon and grammar files

$
0
0

I have successfully setup and run the Kaldi Aspire recipe on my WSL. Now i was working on a POC where i want to extend the ASPIRE recipe by making a new corpus, dictionary, language model and merge it with the original HCLG.fst. I followed this blog post. I have been able to sucessfully create the new dictionary, language model and merged the input files. However i am getting the following error when i try to recompile the HCLG.fst with new Lexicon and grammar.

Checking update-model/local/dict/silence_phones.txt ...
--> reading update-model/local/dict/silence_phones.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/silence_phones.txt is OK

Checking update-model/local/dict/optional_silence.txt ...
--> reading update-model/local/dict/optional_silence.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/optional_silence.txt is OK

Checking update-model/local/dict/nonsilence_phones.txt ...
--> reading update-model/local/dict/nonsilence_phones.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/nonsilence_phones.txt is OK

Checking disjoint: silence_phones.txt, nonsilence_phones.txt
--> disjoint property is OK.

Checking update-model/local/dict/lexicon.txt
--> reading update-model/local/dict/lexicon.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/lexicon.txt is OK

Checking update-model/local/dict/lexiconp.txt
--> reading update-model/local/dict/lexiconp.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/lexiconp.txt is OK

Checking lexicon pair update-model/local/dict/lexicon.txt and update-model/local/dict/lexiconp.txt
--> lexicon pair update-model/local/dict/lexicon.txt and update-model/local/dict/lexiconp.txt match

Checking update-model/local/dict/extra_questions.txt ...
--> reading update-model/local/dict/extra_questions.txt
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/local/dict/extra_questions.txt is OK
--> SUCCESS [validating dictionary directory update-model/local/dict]

fstaddselfloops update-model/dict/phones/wdisambig_phones.int update- 
model/dict/phones/wdisambig_words.int
prepare_lang.sh: validating output directory
utils/validate_lang.pl update-model/dict
Checking existence of separator file
separator file update-model/dict/subword_separator.txt is empty or does not exist, deal in word case.
Checking update-model/dict/phones.txt ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/dict/phones.txt is OK

Checking words.txt: #0 ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> update-model/dict/words.txt is OK

Checking disjoint: silence.txt, nonsilence.txt, disambig.txt ...
--> silence.txt and nonsilence.txt are disjoint
--> silence.txt and disambig.txt are disjoint
--> disambig.txt and nonsilence.txt are disjoint
--> disjoint property is OK

Checking sumation: silence.txt, nonsilence.txt, disambig.txt ...
--> found no unexplainable phones in phones.txt

Checking update-model/dict/phones/context_indep.{txt, int, csl} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 20 entry/entries in update-model/dict/phones/context_indep.txt
--> update-model/dict/phones/context_indep.int corresponds to update-model/dict/phones/context_indep.txt
--> update-model/dict/phones/context_indep.csl corresponds to update-model/dict/phones/context_indep.txt
--> update-model/dict/phones/context_indep.{txt, int, csl} are OK

Checking update-model/dict/phones/nonsilence.{txt, int, csl} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 156 entry/entries in update-model/dict/phones/nonsilence.txt
--> update-model/dict/phones/nonsilence.int corresponds to update-model/dict/phones/nonsilence.txt
--> update-model/dict/phones/nonsilence.csl corresponds to update-model/dict/phones/nonsilence.txt
--> update-model/dict/phones/nonsilence.{txt, int, csl} are OK

Checking update-model/dict/phones/silence.{txt, int, csl} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 20 entry/entries in update-model/dict/phones/silence.txt
--> update-model/dict/phones/silence.int corresponds to update-model/dict/phones/silence.txt
--> update-model/dict/phones/silence.csl corresponds to update-model/dict/phones/silence.txt
--> update-model/dict/phones/silence.{txt, int, csl} are OK

Checking update-model/dict/phones/optional_silence.{txt, int, csl} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 1 entry/entries in update-model/dict/phones/optional_silence.txt
--> update-model/dict/phones/optional_silence.int corresponds to update-model/dict/phones/optional_silence.txt
--> update-model/dict/phones/optional_silence.csl corresponds to update-model/dict/phones/optional_silence.txt
--> update-model/dict/phones/optional_silence.{txt, int, csl} are OK

Checking update-model/dict/phones/disambig.{txt, int, csl} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 10 entry/entries in update-model/dict/phones/disambig.txt
--> update-model/dict/phones/disambig.int corresponds to update-model/dict/phones/disambig.txt
--> update-model/dict/phones/disambig.csl corresponds to update-model/dict/phones/disambig.txt
--> update-model/dict/phones/disambig.{txt, int, csl} are OK

Checking update-model/dict/phones/roots.{txt, int} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 43 entry/entries in update-model/dict/phones/roots.txt
--> update-model/dict/phones/roots.int corresponds to update-model/dict/phones/roots.txt
--> update-model/dict/phones/roots.{txt, int} are OK

Checking update-model/dict/phones/sets.{txt, int} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 43 entry/entries in update-model/dict/phones/sets.txt
--> update-model/dict/phones/sets.int corresponds to update-model/dict/phones/sets.txt
--> update-model/dict/phones/sets.{txt, int} are OK

Checking update-model/dict/phones/extra_questions.{txt, int} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 10 entry/entries in update-model/dict/phones/extra_questions.txt
--> update-model/dict/phones/extra_questions.int corresponds to update-model/dict/phones/extra_questions.txt
--> update-model/dict/phones/extra_questions.{txt, int} are OK

Checking update-model/dict/phones/word_boundary.{txt, int} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 176 entry/entries in update-model/dict/phones/word_boundary.txt
--> update-model/dict/phones/word_boundary.int corresponds to update-model/dict/phones/word_boundary.txt
--> update-model/dict/phones/word_boundary.{txt, int} are OK

Checking optional_silence.txt ...
--> reading update-model/dict/phones/optional_silence.txt
--> update-model/dict/phones/optional_silence.txt is OK

Checking disambiguation symbols: #0 and #1
--> update-model/dict/phones/disambig.txt has "#0" and "#1"
--> update-model/dict/phones/disambig.txt is OK

Checking topo ...

Checking word_boundary.txt: silence.txt, nonsilence.txt, disambig.txt ...
--> update-model/dict/phones/word_boundary.txt doesn't include disambiguation symbols
--> update-model/dict/phones/word_boundary.txt is the union of nonsilence.txt and silence.txt
--> update-model/dict/phones/word_boundary.txt is OK

Checking word-level disambiguation symbols...
--> update-model/dict/phones/wdisambig.txt exists (newer prepare_lang.sh)
Checking word_boundary.int and disambig.int
sh: 2: export: (x86)/Intel/Intel(R): bad variable name
--> generating a 88 word/subword sequence
sh: 2: export: (x86)/Intel/Intel(R): bad variable name
--> ERROR: number of reconstructed words 0 does not match real number of words 88; indicates problem in L.fst or word_boundary.int.  phoneseq = , wordseq = finches pei reservations rambo mommy courtship dawdling divas vox reorient boomtown whore protectorate hurt rayner topeka adamant mugs fouls birth a._k. stand discontents amazed laurels buttering sidetrack boundary lamport occasional suspicion shortcut melons until threats droppings tourette's greece boo competence fire's throat reimburse buffington waged griffith's meshes twiddling forecasting peters catastrophe tiptoe psychoanalysis statewide polar diluting bandit acronyms alvarez snatching nolte dreary fonder snacked navigate foolish severe barbara influenza shelled manuel adulterous antisocial army palace dollars whiff chalice paws injuries pop legume hyped invalids chide goodridge crappie raving
--> generating a 48 word/subword sequence
sh: 2: export: (x86)/Intel/Intel(R): bad variable name

Checking update-model/dict/oov.{txt, int} ...
--> text seems to be UTF-8 or ASCII, checking whitespaces
--> text contains only allowed whitespaces
--> 1 entry/entries in update-model/dict/oov.txt
--> update-model/dict/oov.int corresponds to update-model/dict/oov.txt
--> update-model/dict/oov.{txt, int} are OK

sh: 2: export: (x86)/Intel/Intel(R): bad variable name
--> ERROR: update-model/dict/L.fst is not olabel sorted
sh: 2: export: (x86)/Intel/Intel(R): bad variable name
--> ERROR: update-model/dict/L_disambig.fst is not olabel sorted
--> ERROR (see error messages above)
prepare_lang.sh: error validating output

I had asked this question on Kaldi help group as well. Dan Povey had suggested that this might be a local issue where a subshell might be spawning which is throwing this error.

Any Linux captain here who might help me with this?

Forwarding packets from NIC to WiFi using raw sockets in kernel space

$
0
0

For a project, I have 2 laptops with 2 wireless interfaces (wlan0 and wlan1) and one NIC, let's call the laptops Sender and Receiver. What I would like to do is to send the odd packets that arrive to Sender through its Ethernet interface through wlan0 and even packets through wlan1 to the Receiver laptop. I want to do so by any means that allow me to inspect every packet by code so that I can modify anything if needed or change the sending policy and I want to do it in kernel space because for this particular task low latency is very important.

Assuming all interfaces are correctly set up (wlan0 from Sender connected to wlan0 from Receiver and the same for wlan1) would Raw Sockets be the fastest choice?

Is there any "easy" way to change 802.3 headers to 802.11 headers?

The steps I am going to try are roughly:

  1. Open a Receiving Raw Socket and a Sending Raw Socket
  2. Receive the Ethernet packet, and extract the upper layers
  3. Encapsulate it with 802.11 headers
  4. Send the modified packet over the Raw Socket

The only step I am not clear on is the 3rd one, I would appreciate any help in this regard.

How to use the kernel hash table?

$
0
0

I'm trying to understand and use the kernel hash tables and I've already read this and this link, but I didn't understand none of them. My first question is: Why our struct has to have the struct h_list inside it? If we're gonna access our struct through the struct h_list our struct shouldn't be within struct h_list and not the opposite? After reading the tutorial I've tried to write the following code:

DECLARE_HASHTABLE(nodes_hash, 3)

hash_init(nodes_hash);

struct h_node{
    int data;
    char name[MAX_NAME_SIZE]; /*The key is the name of lua state*/
    struct hlist_node node;
};

struct h_node a = {
    .data = 3,
    .name = "foo",
    .node = 0   
};

struct h_node b = {
    .data = 7,
    .name = "bar",
    .node = 0   
};    

hash_add(nodes_hash,&a.node, "foo");
hash_add(nodes_hash,&b.node, "bar");

But this does not even compile. What I'm doing wrong? I need that the key be the same name present in the struct h_node. So I would like that my hash table be like this:

enter image description here

PS: In my hash table it will never occur a collision (I'll handle it to never occur) so the key can be the name in the struct h_node

Viewing all 12285 articles
Browse latest View live


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