[-- Attachment #1.1: Type: text/plain, Size: 1763 bytes --] Dear All, I am trying to implement prefetching using machine learning in the kernel. I need some data from the kernel directly. In this regard I have got very useful comment that > Don't do that (directly). Pass the data to userspace via netlink or debugfs or shared memory or other means, and have userspace handle it. I am trying to pass data to the kernel space using netlink. Following this link <https://gist.github.com/arunk-s/c897bb9d75a6c98733d6>, I have developed kernel space, and user space programs. Kernel and user space programs working perfectly when I load and run these modules from the terminal using “sudo insmod kernelmodule.ko”, and “./userspaceApp” respectively. But, when I try to use kernel program (directly as a header file #include "kernelmodule.h") with the kernel original file that is “vmx.c” then it returns “NULL” while creating socket (nl_sk = NULL in nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);) . I call user defined function, i.e., create_socket(unsigned long int addr) of kernelmodule.h from handle_ept_voilation() in vmx.c. handle_ept_voilation() is called when ept fault occurs in case of virtual machine. Furthermore, I have observed one weird behaviour: if I put 1-3 seconds sleep just before the socket creating statement , then it works just during booting of my virtual machine, after successful boot I get the same socket NULL error. Thank you for your help. -- *Best Regards,* *Mr. Irfan Ullah* PhD Candidate Data and Knowledge Engineering(DKE) Lab Department of Computer Science and Engineering Kyung Hee University, South Korea. +82-010-591-51651 <+82%2010-3877-8867> sahibzada.iu@gmail.com sahibzada_irfanullah [-- Attachment #1.2: Type: text/html, Size: 3721 bytes --] [-- Attachment #2: Type: text/plain, Size: 170 bytes --] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
[-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1.1: Type: text/plain; charset=us-ascii, Size: 680 bytes --] On Wed, 16 Oct 2019 13:54:08 +0900, Irfan Ullah said: > developed kernel space, and user space programs. Kernel and user space > programs working perfectly when I load and run these modules from the > terminal using “sudo insmod kernelmodule.ko”, and “./userspaceApp” > respectively. But, when I try to use kernel program (directly as a header > file #include "kernelmodule.h") with the kernel original file that is > “vmx.c” then it returns “NULL” while creating socket (nl_sk = NULL in nl_sk You're going to have to explain in more detail what you're doing, and possibly share your code. "when I try to use kernel program directly" doesn't make sense.... [-- Attachment #1.2: Type: application/pgp-signature, Size: 832 bytes --] [-- Attachment #2: Type: text/plain, Size: 170 bytes --] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
[-- Attachment #1.1: Type: text/plain, Size: 3345 bytes --] My actual goal is to develop kernel space and user space programs to establish communication in which kernel should initiate the communication. The kernel will send information (e.g., guest physical address from handle_ept_violation() in vmx.c, finding the corresponding page of that address, owner process (or if possible the application, i.e., VLC, open office) of the page, process/application releasing the page) at run time to the user space application. I have written code consists of three file i.e., netlink_kernel_module.c, netlink_kernel_space.h, netlink_user_module.c. "netlink_kernel_module.c" contains just kernel loading/ unloading module functions i.e., __init hello_init(), and _exit hello_exit(). "netlink_kernel_space.h" contains all the rest of the kernel space code for sending/ receiving data while "netlink_user_module.c" contains the user space application code for sending/receiving data. *During development and testing* I use "netlink_kernel_module.c" to load and unload kernel module, in which the "__init hello_init()" just call the "create_socket(int data)" defined in "netlink_kernel_space.h" with the data which I want to pass to the user space program. And my code works perfectly in this way. *But, To get the required data from the kernel in real time*, I include " netlink_kernel_space.h " in kernel file i.e., vmx.c and call the "create_socket(int data)" from the handle_ept_voilation() defined in vmx.c <https://elixir.bootlin.com/linux/latest/source/arch/x86/kvm/vmx/vmx.c#L5079> after line#5098. I compile, and install the kernel, and reboot the system (and thus I don't need "netlink_kernel_module.c" because I don't load/unload the kernel module but include "netlink_kernel_space.h" in the vmx.c by using #include "netlink_kernel_space.h"). But, I am getting “NULL” while creating socket (nl_sk = NULL in nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);). Here code also shows weird behaviour. If I put 1-3 seconds sleep just before the socket creating statement, then it works just during booting of the virtual machine, after successful boot I get the same socket NULL error. Please find the code in the attachment.. Thank you very much. On Wed, Oct 16, 2019 at 11:29 PM Valdis Klētnieks <valdis.kletnieks@vt.edu> wrote: > On Wed, 16 Oct 2019 13:54:08 +0900, Irfan Ullah said: > > > developed kernel space, and user space programs. Kernel and user space > > programs working perfectly when I load and run these modules from the > > terminal using “sudo insmod kernelmodule.ko”, and “./userspaceApp” > > respectively. But, when I try to use kernel program (directly as a > header > > file #include "kernelmodule.h") with the kernel original file that is > > “vmx.c” then it returns “NULL” while creating socket (nl_sk = NULL in > nl_sk > > You're going to have to explain in more detail what you're doing, and > possibly > share your code. "when I try to use kernel program directly" doesn't make > sense.... > > -- *Best Regards,* *Mr. Irfan Ullah* PhD Candidate Data and Knowledge Engineering(DKE) Lab Department of Computer Science and Engineering Kyung Hee University, South Korea. +82-010-591-51651 <+82%2010-3877-8867> sahibzada.iu@gmail.com sahibzada_irfanullah [-- Attachment #1.2: Type: text/html, Size: 5610 bytes --] [-- Attachment #2: Kernel_User_comm.zip --] [-- Type: application/zip, Size: 7514 bytes --] [-- Attachment #3: Type: text/plain, Size: 170 bytes --] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
[-- Attachment #1.1: Type: text/plain, Size: 4004 bytes --] Still, I am stuck in the same problem, I have also used share memory, and while(!nl_sk) but nothing work:(. Can you please tell me what's the mistake I am doing? On Thu, Oct 17, 2019 at 3:23 PM Irfan Ullah (울라 이르판) <irfan@dke.khu.ac.kr> wrote: > My actual goal is to develop kernel space and user space programs to > establish communication in which kernel should initiate the communication. > The kernel will send information (e.g., guest physical address from > handle_ept_violation() in vmx.c, finding the corresponding page of that > address, owner process (or if possible the application, i.e., VLC, open > office) of the page, process/application releasing the page) at run time to > the user space application. > I have written code consists of three file i.e., netlink_kernel_module.c, > netlink_kernel_space.h, netlink_user_module.c. "netlink_kernel_module.c" > contains just kernel loading/ unloading module functions i.e., __init > hello_init(), and _exit hello_exit(). "netlink_kernel_space.h" contains > all the rest of the kernel space code for sending/ receiving data while > "netlink_user_module.c" contains the user space application code for > sending/receiving data. > > *During development and testing* I use "netlink_kernel_module.c" to load > and unload kernel module, in which the "__init hello_init()" just call the > "create_socket(int data)" defined in "netlink_kernel_space.h" with the > data which I want to pass to the user space program. And my code works > perfectly in this way. > > *But, To get the required data from the kernel in real time*, I include > " netlink_kernel_space.h " in kernel file i.e., vmx.c and call the > "create_socket(int data)" from the handle_ept_voilation() defined in > vmx.c > <https://elixir.bootlin.com/linux/latest/source/arch/x86/kvm/vmx/vmx.c#L5079> after > line#5098. I compile, and install the kernel, and reboot the system (and > thus I don't need "netlink_kernel_module.c" because I don't load/unload > the kernel module but include "netlink_kernel_space.h" in the vmx.c by > using #include "netlink_kernel_space.h"). But, I am getting “NULL” while > creating socket (nl_sk = NULL in nl_sk = netlink_kernel_create(&init_net, > NETLINK_USER, &cfg);). Here code also shows weird behaviour. If I put 1-3 > seconds sleep just before the socket creating statement, then it works just > during booting of the virtual machine, after successful boot I get the same > socket NULL error. Please find the code in the attachment.. > Thank you very much. > > On Wed, Oct 16, 2019 at 11:29 PM Valdis Klētnieks <valdis.kletnieks@vt.edu> > wrote: > >> On Wed, 16 Oct 2019 13:54:08 +0900, Irfan Ullah said: >> >> > developed kernel space, and user space programs. Kernel and user space >> > programs working perfectly when I load and run these modules from the >> > terminal using “sudo insmod kernelmodule.ko”, and “./userspaceApp” >> > respectively. But, when I try to use kernel program (directly as a >> header >> > file #include "kernelmodule.h") with the kernel original file that is >> > “vmx.c” then it returns “NULL” while creating socket (nl_sk = NULL in >> nl_sk >> >> You're going to have to explain in more detail what you're doing, and >> possibly >> share your code. "when I try to use kernel program directly" doesn't >> make sense.... >> >> > > -- > *Best Regards,* > > > *Mr. Irfan Ullah* > PhD Candidate > Data and Knowledge Engineering(DKE) Lab > Department of Computer Science and Engineering > Kyung Hee University, South Korea. > +82-010-591-51651 <+82%2010-3877-8867> > sahibzada.iu@gmail.com > sahibzada_irfanullah > -- *Best Regards,* *Mr. Irfan Ullah* PhD Candidate Data and Knowledge Engineering(DKE) Lab Department of Computer Science and Engineering Kyung Hee University, South Korea. +82-010-591-51651 <+82%2010-3877-8867> sahibzada.iu@gmail.com sahibzada_irfanullah [-- Attachment #1.2: Type: text/html, Size: 8106 bytes --] [-- Attachment #2: Type: text/plain, Size: 170 bytes --] _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies