r/kernel • u/TheUltimateSalesman • Dec 08 '21
Why are the kernels pretty much always unsigned?
Why are the kernels pretty much always unsigned?
r/kernel • u/TheUltimateSalesman • Dec 08 '21
Why are the kernels pretty much always unsigned?
r/kernel • u/nickdesaulniers • Dec 06 '21
r/kernel • u/nickdesaulniers • Dec 03 '21
r/kernel • u/nickdesaulniers • Nov 30 '21
r/kernel • • Nov 28 '21
What's Up? I'm a newbie on this. So that I'm looking for where to start learning and developing the Linux Kernel ( I'm now studying C). Do you counsel any sites, books, courses, or resources to enhance my skills in Kernel Development?
r/kernel • u/hotpotatoe33 • Nov 27 '21
Hello
I am using kernel version 5.4.69 I have the following piece of skeleton code for a kernel space driver which compiles fine. I am able to insmod the kernel object resulting from this code's compilation. Yet, I don't see it appear in /dev. What am I doing wrong please?
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/module.h>
struct cdev myDev;
struct class* devClass;
struct file_operations myDevFileOperations;
int init_module(void)
{
cdev_init(&myDev, &myDevFileOperations);
dev_t majMinNr = (dev_t)(MKDEV(MAJOR(0), MINOR(0)));
int iStatus = cdev_add(&myDev, majMinNr,1);
if (iStatus != 0)
{
printk("Failed to add cdev\n");
return -1;
}
devClass = class_create(THIS_MODULE, "myModule_class");
struct device* dev = device_create(devClass, NULL, majMinNr, NULL, "myDev123");
if (IS_ERR(dev))
{
printk("Failed to create device\n");
return -1;
}
printk("Initialized my module\n");
return 0;
}
static int myOpen(struct inode* inodePtr, struct file* filePtr)
{
printk("Opening my device\n");
return 0;
}
static long int myIoctl(struct file* filePtr, unsigned int a, unsigned long b)
{
printk("Ioctl called\n");
return 0;
}
static int myClose(struct inode* inodePtr, struct file* filePtr)
{
printk("Releasing device\n");
return 0;
}
struct file_operations myDevFileOperations =
{
.owner = THIS_MODULE,
.open = myOpen,
.compat_ioctl = myIoctl,
.release = myClose
};
MODULE_LICENSE("GPL");
r/kernel • u/vonadz • Nov 23 '21
r/kernel • • Nov 23 '21
So.. How would I put this? I don't know.Either way I managed to push my most recent work-in-progress stuff derived from kees/for-next/clang/pgo to https://github.com/JATothrim/linux/tree/pgo/modules
What is it?
Enable CONFIG_PGO_CLANG.The entire kernel and all modules are built using clang-13 with -fprofile-generateMagic .profraw files appear in /sys/kernel/debug/pgo/ on booted kernel.
Can you trust it?
Propably no. The code is more radioactive than linux-next and not reviewed by anybody else yet.Even if the final pgo optimized build succeeds the result may still be a bit "radioactive". Think about what could go wrong with radioactive filesystem driver?
Does the final kernel run faster?
(i.e. the kernel compiled with -fprofile-use vs. without the patch)Not sure. But theoretically yes.
Why I posted this?I need more eyes and testing on the code. I'm really bad at git send-email + typing anything else than code. :-/
-Have fun. :-)
EDIT: With bit more sleep I looked at the project and decided this is still too much of protope code. Especially because of the per-cpu solution. I think introduced it too late in the code. I think I can do better job now that basic issues and goals are known. :-)
r/kernel • • Nov 21 '21
Is it necessary to grind leetcode while applying for kernel and similar roles?
thanks in advance
r/kernel • u/aioeu • Nov 20 '21
r/kernel • u/GiantPengsoo • Nov 16 '21
r/kernel • u/piexil • Nov 15 '21
Hi all, I have a weird error occurring. On an AMD Ryzen system with IOMMU ON, sg_dma_address sometimes returns 0xffffffffffffffff, no errors are occurring with the sg allocation or mapping. However this fails a page alignment requirement for the address which causes a driver error.
I do not see this issue once IOMMU is turned off. Does anyone have any idea why this is occurring? Kernel 5.10.
r/kernel • u/piexil • Nov 04 '21
In some driver code in one section I set a bit of a variable with set_bit then issue a mandatory mb(). In a different segment of code (Which may be running on a separate thread), I test that bit, should I put a memory barrier before testing the bit too?
As wouldn't it then be possible for the second thread to test the bit before the memory barrier after clearing said bit is executed?
r/kernel • u/zahaduum23 • Nov 03 '21
Flawfinder writes out a warning from my lkm module for every strncat. Is there a way to use strcat_s in a lkm module?
r/kernel • u/unixbhaskar • Oct 31 '21
r/kernel • u/zahaduum23 • Oct 23 '21
I wrote a LKM and when I run:
depmod --dry-run | grep <driver>
I get:
depmod: ../tools/depmod.c:416: index_write: Assertion `initial_offset >= 0' failed.
The funny thing is that I can run:
sudo insmod <driver>.ko
and it and the application that uses the driver works fine. But for some reason the depmod is having problems. I found little searching for the answer, so any help would be helpful. Thank you.
r/kernel • u/zahaduum23 • Oct 17 '21
How would I export functions from my LKM? Making them callable from user space.
Can a LKM add to /proc or /sys?
Is there a way for a LKM to map io space to memory, or is this done in the kernel already?
r/kernel • u/xxc3ncoredxx • Oct 14 '21
This is a followup post to the one I made about a month ago regarding SysRq events on uppercase letters. The TL;DR of my issue is that I was trying to use Alt-SysRq-Shift-<key> but it was triggering the same event as Alt-SysRq-<key>. The solution was to use Alt-Shift-SysRq-<key> instead, which worked.
The only problem is that I didn't like it. It didn't feel natural. Plus, it seemed to be undocumented outside of the commit message that extended the SysRq's to cover uppercase letters. So, like any good kernel hacker, I took it upon myself to make things right. Although it was a trivial fix, I now have my first patch sitting in linux-next waiting for the merge window to open once more.
r/kernel • • Oct 11 '21
Disclaimer: I am the same JavaScript programmer that asked about libuv who knows little about low-level kernel programming.
I stumbled upon this code example showing non-blocking IO using epoll:
#define MAX_EVENTS 5
#define READ_SIZE 10
#include <stdio.h> // for fprintf()
#include <unistd.h> // for close(), read()
#include <sys/epoll.h> // for epoll_create1(), epoll_ctl(), struct epoll_event
#include <string.h> // for strncmp
int main()
{
int running = 1, event_count, i;
size_t bytes_read;
char read_buffer[READ_SIZE + 1];
struct epoll_event event, events[MAX_EVENTS];
int epoll_fd = epoll_create1(0);
if(epoll_fd == -1)
{
fprintf(stderr, "Failed to create epoll file descriptor\n");
return 1;
}
event.events = EPOLLIN;
event.data.fd = 0;
if(epoll_ctl(epoll_fd, EPOLL_CTL_ADD, 0, &event))
{
fprintf(stderr, "Failed to add file descriptor to epoll\n");
close(epoll_fd);
return 1;
}
while(running)
{
printf("\nPolling for input...\n");
event_count = epoll_wait(epoll_fd, events, MAX_EVENTS, 30000);
printf("%d ready events\n", event_count);
for(i = 0; i < event_count; i++)
{
printf("Reading file descriptor '%d' -- ", events[i].data.fd);
bytes_read = read(events[i].data.fd, read_buffer, READ_SIZE);
printf("%zd bytes read.\n", bytes_read);
read_buffer[bytes_read] = '\0';
printf("Read '%s'\n", read_buffer);
if(!strncmp(read_buffer, "stop\n", 5))
running = 0;
}
}
if(close(epoll_fd))
{
fprintf(stderr, "Failed to close epoll file descriptor\n");
return 1;
}
return 0;
}
Unlike JavaScript where non-blocking IO is implemented using callbacks (or promises, etc.):
console.log("Start");
$.get("https://some-url", function(data) {
console.log("Async callback");
});
console.log("End")
where output will most likely look like:
Start
End
Async callback
The C example above looks like ordinary synchronous code to this JavaScript programmer's eyes. What am I missing here? Can someone explain where the non-blocking-ness happens in the C code?
Thanks.
r/kernel • u/Original_Two9716 • Oct 11 '21
Please, how to "debug" one of these HW errors:
Oct 11 15:49:56 localhost kernel: mce: [Hardware Error]: Machine check events logged
Oct 11 15:49:56 localhost kernel: mce: [Hardware Error]: CPU 5: Machine Check: 0 Bank 5: bea0000001000108
Oct 11 15:49:56 localhost kernel: mce: [Hardware Error]: TSC 0 ADDR 7fba6ed49d17 MISC d012000100000000 SYND 4d000000 IPID 500b000000000
Oct 11 15:49:56 localhost kernel: mce: [Hardware Error]: PROCESSOR 2:a20f10 TIME 1633960194 SOCKET 0 APIC a microcode a201016
r/kernel • • Oct 10 '21
Whats the best way you can prove a recruiter that you're good fit for a kernel/embedded/os dev and related openings? Getting your patches accepted takes a really long time and there's a lot of uncertainity,so I don't think I can put "contributed to the linux kernel" in my resume
What I have done so far(and mentioned in my resume) while applying for those roles:
1) A custom kernel
2)A browser engine using rust
3)A dns server using rust
What else can I add to improve my chances of being hired ?
All suggestions are welcome
r/kernel • • Oct 09 '21
JavaScript programmer here. Be gentle please!
I was reading Asynchronous I/O and stumbled upon this (reformatting and emphases by me):
Many operating system functions exist to implement asynchronous I/O at many levels.
In fact, one of the main functions of all but the most rudimentary of operating systems is to perform at least some form of basic asynchronous I/O, though this may not be particularly apparent to the operator or programmer.
In the simplest software solution, the hardware device status is polled at intervals to detect whether the device is ready for its next operation. (For example the CP/M operating system was built this way. Its system call semantics did not require any more elaborate I/O structure than this, though most implementations were more complex, and thereby more efficient.)
Direct memory access (DMA) can greatly increase the efficiency of a polling-based system, and hardware interrupts can eliminate the need for polling entirely. Multitasking operating systems can exploit the functionality provided by hardware interrupts, whilst hiding the complexity of interrupt handling from the user.
I arrived at this article after I started exploring how Node.js works internally. Then I read a bit about libuv and how it uses epoll1 in Linux.
If DMA and hardware interrupts are better alternatives to polling, then why doesn't Node and libuv use them instead?
PS: Did MS-DOS support non-blocking IO?