/r/kernel

Photograph via snooOG

A moderated community dedicated to technical discussion about the Linux kernel.

Welcome to /r/kernel, a moderated community dedicated to all things about the Linux kernel. Technical articles only, please!

You may be interested in the following links:

And some books:

Related Communities

/r/kernel

17,842 Subscribers

1

What’s the most efficient way to trace dynamic memory leaks in a running Linux kernel process?

0 Comments
2024/12/04
14:58 UTC

1

Where is the source code of `/sys/block/sda/stat` ?

Further, how should I find the source code for any sysfs interface?

3 Comments
2024/12/04
06:37 UTC

6

Kernel modules development without disabling Secure Boot

Hi, i am developing some kernel modules for a short time in my university course. I dual boot Fedora and Windows (sadly it is required for some applications) and i don't want to disable the secure boot or go trough the long procedure of signing the modules as they are simple. Is there any setup to develop the modules via QEMU, docker or any other way?

2 Comments
2024/12/02
20:50 UTC

6

Block Device I/Os

Hi everybody, I'm reaching out seeking some guidance.
I'd be happy to get your help/advice about block device (SCSI specifically) IOs process/path in kernel version 6.x.

I work on a kernel module (module is running on a VM, and captured by the virtualization host kernel driver).
I face 2 problems with the new kernel:
The first one is a completion function, in older kernel such as kernel 5.x scsi_cmnd provided a field that is a function pointer which no longer exists in 6.x:

/* Low-level done function - can be used by low-level driver to point
 *        to completion function.  Not used by mid/upper level code. */
void (*) (struct  *);/* Low-level done function - can be used by low-level driver to point
 *        to completion function.  Not used by mid/upper level code. */
void (*scsi_done) (struct scsi_cmnd *);

The second is that every attempt to generate a scsi_cmnd on the fly (whether it's a new one, or copy the fields of one I've intercepted on it's way down) fails on my attempt to queue it to the kernel.
I've attempted to queue it using Scsi_host->scsi_host_template->queuecommand. all attempts seem to fail on tagging the request properly, but I can't seem to grasp what the author desire was or how one should do it properly.

I've tried the web for information but all guides point to LDD guides for kernel 2.6, which show obsolete/deprecated/non-existing functions. I'd be grateful if you can point me to the right direction, some guidance or a tutorial on what's the correct way for a kernel module to:
1. create a scsi_cmnd and queue it to the kernel to execute it, i.e how the author intended.
2. understand more about the block device infrastructure in the kernel.

To share my efforts so far in attempting to understand this or find a way, I've worked a lot with trace-cmd to see callstacks of successful executions (I/Os that aren't mine), my own dumps, and researched the kernel source code using bootlin and comparing old to new versions attempting to understand how the infra works but to no real solution.
I'd appreciate any pointers to relevant information, and thank you for reading through.
Thanks!

1 Comment
2024/12/02
08:33 UTC

3

Kernel Address Space

I'm aware that user-space programs have only their "portion" of the physical memory (and a little bit of the kernel memory that is necessary for context switches) mapped into their virtual address spaces, and (correct me if I'm wrong) on x86(_64), the entire physical memory is "mapped" into the kernel's address space. Does this also hold for other architectures, for example for ARM64? Is the entire physical memory always accessible to the kernel no matter the context that the kernel-space code is running in?

Also, before KPTI patches, every user-space program had the kernel address space mapped into its virtual address space on x86_64. Was that also the case with ARM64? How did the duality of the registers (TTBR0 and TTBR1 instead of just CR3) to store the address of translation tables affect this?

1 Comment
2024/11/29
22:54 UTC

27

Is there any available option for learning how the Linux kernel works other than reading the source code?

My background is in web backend development and I'm used to learn (primarily) by reading technical documentation. As a Linux user I'm trying to learn how the Linux kernel work, I'm trying to write some drivers in order to learn by doing. I'm finding it tough as the documentation looks kind of incomplete to me. At this point I'm not sure if the only real way is to read the source code or if I'm doing something wrong.

30 Comments
2024/11/25
20:06 UTC

12

What happens when a KVM guest executes a secure monitor call (SMC)?

Ofcourse the hypervisor in EL2 will trap it, but what happens afterwards?

2 Comments
2024/11/11
15:50 UTC

11

Understanding How kernel Works

Are there any books or videos .From which I can understand the inner working of kernel .I just know extremely basic thing about kernel that it manages process and memory management .I want to learn more .

26 Comments
2024/11/07
07:18 UTC

7

Calling convention with parameters on separate stack?

Hi,

How feasible is it to have a calling convention where the parameters are passed in a separate stack from the address stack?

The advantages of this would be:

  1. In the event of bugs etc, the parameters can't overwrite the return addresses. This would make stack overflow exploits a lot harder.
  2. The CPU and CPU designers can make assumptions that the return address stack only contains addresses. This might make caching and lookahead easier.

The disadvantages:

  1. You need to manage another stack. But this might not be a big problem - nowadays many computers have lots of RAM and CPUs with billions of transistors.

Best regards,

313243358d5ca7bcf6d4a0f12bc48e56d3f712a00b4c1d0fdd646cb9582602ad

2 Comments
2024/11/03
08:53 UTC

0

what does "runtime" mean in programming?

hello, quick question, what does "runtime" mean in programming?

for example, i can go to wikipedia and go to

https://en.wikipedia.org/wiki/Runtime

and it's giving me several different things that runtime could mean, so i wanted to ask, what is runtime to you?

thank you

10 Comments
2024/10/31
11:03 UTC

43

A note on acceptable dialogue

You are more than welcome to disagree with the decisions and opinions expressed by anyone in the upstream community, including Linus, so long as you express your opinion on the matter in a measured and respectful way. This subreddit is to some degree meant to reflect the culture of the Linux kernel community. You can call it like you see it, and say things that may otherwise be considered somewhat “mean”, “prickly”, or overly direct in normal circles. In other words, for the most part, this community can reflect the tone and standards followed on LKML, and it will be fine.

What we absolutely will not tolerate is calling anyone a derogatory slur, or make offensive comparisons that are grossly slanderous. For instance, do not call someone a nazi because you disagree with them, or compare them to Hitler. Doing so will result in an instant ban, no warning.

It’s sad that this even needs to be said, but this latest unfortunate and understandably controversial news about banning Russian maintainers has resulted in some of the worst takes I’ve ever seen.

That is all.

7 Comments
2024/10/27
03:17 UTC

13

Harald Welte's Open Letter

10 Comments
2024/10/26
16:10 UTC

23

Are there more companies that need compiler engineers or kernel engineers?

Speaking from a demand perspective, what skill set is typically more needed by more companies? Of course the two disciplines are relatively niche and most companies don't need either. Regardless, I am curious to know!

15 Comments
2024/10/23
03:08 UTC

0

wsl2 kernel dev

Is it viable to do kernel dev on wsl2 or not? I wish I could use arch which I have but games hold me back so I need something that is not as slow as a vm but fast and just works ootb aka wsl 2. TIA

9 Comments
2024/10/15
06:29 UTC

26

Dynamic queue as a Kernel module.

Hi,

I created a kernel module that implements a dynamic queue within a Kernel module for educational purposes.

It supports IOCTL so that userspace programs may communicate with it.

It might be helpful for beginners.

Link: https://github.com/mirimmad/kernel-module

7 Comments
2024/10/14
09:03 UTC

0

erreur lors de la compilation kernel debian

message d'erreur kernel/makefile:1926: .] error 2

1 Comment
2024/10/11
21:41 UTC

6

is creating a low latency kernel bypass framework doable and worth it as my masters graduation project?

Hello everyone, I'm a master's student, soon to become a computer engineer. After a long journey searching for the right project idea for my degree, I knew I wanted to focus on something related to operating systems, low-level programming, or networking. However, I was unsure about the exact direction, especially since I now lean more toward software-oriented work. Recently, I came across an interesting theme: "Low-Latency Kernel Bypass Framework for High-Performance Networking." I'm considering pursuing this idea, but I have a few concerns. Is it feasible to complete within a one-year period? Also, would this project be a case of reinventing the wheel, given that some existing tools already perform similar tasks? if you have better project ideas please feel free to share them here! THANK YOU!!

9 Comments
2024/10/10
16:18 UTC

1

can luks create two paritions on the same drive and encrypt both with different passwords?

ok, so i'm doing research for a new laptop, and when i look for a new laptop i like to get a laptop with two drives, one that is ssd for my linux operating system

and another that is hdd for all my files, i like to encrypt both of them with two different passwords.

now, i have been doing research into buying a new laptop, and i can't find any laptops with both a hdd and sdd, it's either one or the other.

so i wanted to ask, is this a feature that linux's encryption "luks" can do for me?

1_can i make two paritions on the same sdd drive,

2_can it encrypt both when two different passwords

3_can one the operating system partition be unencrypted while my file partition be encrypted?

4_how can i do this? how can i set this up on my new laptop? what would i need to do when i format and install linux on my new laptop?

4 Comments
2024/10/09
13:37 UTC

3

Help with LFD103 course. Cloning the right kernel/git/stable/ repository

Hi,

I'm following the A Beginner's Guide to Linux Kernel Development (LFD103) course and I a bit confused about one part.

According to the tutorial, I should be cloning :

git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

But after looking a bit at https://git.kernel.org/ there is no linux-stable.git

There are :

|| || |kernel/git/stable/linux.git|Linux kernel stable treekernel/git/stable/linux.gitLinux kernel stable tree|

|| || |kernel/git/stable/linux-stable-rc.git|Linux Stable -rc releaseskernel/git/stable/linux-stable-rc.gitLinux Stable -rc releases|

And I don't know which one is the correct one to use.

Any help is appreciated.

Thank you.

0 Comments
2024/10/08
20:31 UTC

9

Mimic Race conditions in OS programming

How do you testrace conditions to see if the written logic works ?

Or, in general how do mutex providers (kernel) test their code ?

What are the involved tools ?

How can I mimic a race to check a piece of code ?

3 Comments
2024/10/07
14:56 UTC

7

What effect would incorrect L2 cache size have on performance

I'm looking at an SoC with a reconfigurable L2 cache, some can be RAM some can be L2 and you can dynamically allocate it before any OS comes up.

Its 2MB total but in reality the out of the box set up is 1MB as cache. Looking at the dt for the device its set as 2MB in the dt.

I'm guessing this would have some impact on performance but the scale of the impact I'm not sure of. Can anyone explain what this might be? Linux thinking it has a 2MB L2 and actually only having 1MB.

10 Comments
2024/10/07
12:40 UTC

3

Need help compiling a kernel (Config Mismatch)

Not sure if I can post this here, but I've been trying to compile an android kernel (source) and got this error:
WARNING: vmlinux.o(.data+0x1f3288): Section mismatch in reference from the variable modem_spi_boot_driver to the function .init.text:modem_spi_boot_probe()

The variable modem_spi_boot_driver references

the function __init modem_spi_boot_probe()

If the reference is valid then annotate the

variable with __init* or __refdata (see linux/init.h) or name the variable:

*_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console

I'm not sure exactly what this means or what I would have to do to fix it. I'd really appreciate any help I could get.

EDIT: just tried compiling the Pixel OS kernel (source) for the same phone and got the same error. It might not be an error with a kernel, but something wrong with my build environment instead. I'n not sure how I would fix that either.

3 Comments
2024/10/07
06:52 UTC

0

Will MIGRATE_UNMOVABLE type pages be reclaimed?

If a page is allocated using GFP_HIGHUSER, and its type is MIGRATE_UNMOVABLE as obtained through get_pageblock_migratetype, will this page be reclaimed? My current understanding is that as long as the page type is MIGRATE_UNMOVABLE, it will neither be migrated nor reclaimed. However, I'm not sure if this is correct. I've been searching online but haven't found a definitive answer, and I couldn't find any explanation in the official documentation either. I would greatly appreciate it if someone could clarify this for me. Thanks!

2 Comments
2024/10/06
12:47 UTC

8

what is process 0?

hello, i'm doing researching into process 0 and i can't seem to get answers on the most basic questions?

what is process 0?

what does it do?

why does it do it?

and so i wanted to ask here and ask what is process 0?

i checked around online and found this

https://blog.dave.tf/post/linux-pid0/

and this

https://superuser.com/questions/377572/what-is-the-main-purpose-of-the-swapper-process-in-unix

but i can't seem to get answers for basic questions, so i thought you guys might know

thank you

5 Comments
2024/10/05
08:48 UTC

2

Thunderbird Plugin for LKML?

Does anyone know of something like a Thunderbird (or any other email application) plugin, configuration, template, etc. that enforces the Linux Kernel Mailing List conventions? In-line replies, plain text, possibly some integration with Git or syntax highlighting for patches.

I have been manually composing and formatting replies in Vim, and then sending with git-send-email. It does the job, but gets really tedious.

I'm sure most Linux kernel developers know some black magic to do all of the above with command line tools, but I'm very GUI-centric.

0 Comments
2024/10/05
00:11 UTC

Back To Top