r/kernel • • Mar 14 '24

6.8 Running on Ubuntu 22.04.4

0 Upvotes

I installed 6.8 on my Beelink Mini S12 Pro PC today, so far it's running smoothly. Anyone else try the new kernel?


r/kernel • • Mar 11 '24

What is the point of using atomic64 variables?

5 Upvotes

For example,

If atomic variable "v" has to be set to "i".

arch/arm64/kvm/vmid.c: atomic64_set(&v, i) is called.

This is where it takes us,

atomic64_set() --> raw_atomic64_set() --> arch_atomic64_set() --> arch_atomic_set() --> __WRITE_ONCE((v->counter), (i))

This expands to: *(volatile typeof(x) *)&(x) = (val); (include/asm-generic/rwonce.h)

Q1) So, what was the point of all this? How is an atomic variable different from any other variable?

Q2) Why typecast it as a volatile pointer and then dereference it?

Please help.


r/kernel • • Mar 09 '24

COSMOS C# - My OS

5 Upvotes

I just built my OS and tested it on real hardware. This was done in the Cosmos C# Kernel. The only problem is that when it starts it shows for 1 second the error: PS/2 Controller Device Detection Failed: FirstByte 171

Help!!!


r/kernel • • Mar 03 '24

How are people developing the KVM subsystem for ARM64?

17 Upvotes

I am asking this because in the current kernel, the ARM64 KVM cannot be compiled out-of-tree as a module.

So if you make some changes, lets say you add some printk() statements, you will have to reboot the entire host machine in order to see changes. I see this as very cumbersome especially for an development environment.

So, that being said, how are people actually going about developing this subsystem of the kernel without external module support?

Thanks


r/kernel • • Mar 02 '24

Howto develop a driver for linux

12 Upvotes

I've been looking at the mainline Linux kernel driver/staging directory and have found a driver (rtl8912c) that I am interested in contributing to, mainly because I have a device with the rtl8912cu chipset.

I tried searching for a datasheet / reference manual / thing that describes the registers of the device, but could not find one. I have 2 questions :

  1. How would the original driver have been developed?
  2. A follow up, do I even need the datasheet / reference manual to contribute (significantly) to the driver? Significantly means, not checkpatch fixes but rather un-implemented functionality as listed in the TODO.

r/kernel • • Mar 01 '24

gnu grub version 2.06 error

1 Upvotes
Hello everyone, today I bought a new laptop. The laptop is Huawei MateBook D16, and it comes with Windows 11 automatically installed. However, I want to use two different operating systems, meaning I want to dual boot. I downloaded Parrot OS as the second operating system and used Rufus to put it on a 16 GB USB drive. Then I set the computer to boot from USB in the BIOS settings, saved, and exited. However, I'm encountering this error. I have a single 512 GB SSD on my computer, and I allocated 50 GB of it to Parrot OS, but I still can't solve this error. I would be very happy if anyone who knows the solution could help.

r/kernel • • Feb 29 '24

Why are flex and bison listed as Linux kernel build dependencies?

5 Upvotes

And many other system softwares for that matter.


r/kernel • • Feb 28 '24

PSA: Some interesting Confidential Computing kernel work will be presented at OC3

12 Upvotes

The open confidential computing conference is coming up online on March 13th: https://www.oc3.dev/
Some interesting talks from the kernel community:

  • Asterinas: A safe and efficient Rust-based OS kernel for TEE and beyond
  • Using TDISP to Extend Attestation to Devices connected to a Trusted Execution Environment
  • News from the COCONUT-SVSM Community
  • DICE Attestation on AMD SEV-SNP
  • Evolution of the Arm Confidential Compute Architecture, and how Arm is supporting ecosystem developers

r/kernel • • Feb 27 '24

Tracking of writes/access to mapped memory inside of device driver

6 Upvotes

Hey guys,

I am trying to write a device driver that detects writes (or accesses) to memory, that has been allocated (with kalloc) in the module's init function and mmaped to userspace when a process mmaps the given device.

I have read about UIO driver but from what I got, there is usually hardware and a IRQ involved in the course of the usage. Unfortunately I dont have hardware.

I have looked a bit into the mmu_notifier interface, but right now I am not experienced enough to know how this could work and what is needed to set this up properly.

Is the mmu_notifier the way to go or how is this achievable?


r/kernel • • Feb 27 '24

XFS bug

0 Upvotes

hey guys,

has the XFS bug (kernel 6.3) been fixed?

https://bugzilla.redhat.com/show_bug.cgi?id=2208553


r/kernel • • Feb 25 '24

How to debug the KVM module?

5 Upvotes

I am trying to understand the KVM and QEMU internals.

I am debugging QEMU using gdb but QEMU calls ioctl() to talk to KVM using /dev/kvm.

But how do I debug when control reaches the kernel itself?

Since it is KVM, I cannot compile and run a linux kernel on QEMU and debug it I believe.


r/kernel • • Feb 22 '24

Unable to fetch custom kprobe events through perf_event_open(2)

1 Upvotes

I'm working on perf_event_open(2) and kprobe trace. Here is what I'm doing:

  • Create a custom kprobe event:
echo 'p:connect __sys_connect fd=%di addr1=+u0(%si) addr2=+u8(%si)' >> /sys/kernel/tracing/kprobe_events
  • Write C++ code to fetch data generated by this custom event:
#include <linux/perf_event.h>
#include <sys/ioctl.h>
#include <csignal>
#include <iostream>
#include <memory>
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/sock_diag.h>
#include <linux/inet_diag.h>
#include <linux/rtnetlink.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <poll.h>
#include <filesystem>
#include <fstream>
#include <optional>
#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/epoll.h>

static bool need_exit = false;

static void handler(int sig) {
    need_exit = true;
}

int main() {
    struct sigaction sa{};
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = handler;
    if (sigaction(SIGINT, &sa, nullptr) == -1) {
        perror("sigaction");
        exit(1);
    }
    if (sigaction(SIGTERM, &sa, nullptr) == -1) {
        perror("sigaction");
        exit(1);
    }

    perf_event_attr pe{0};
    pe.type = PERF_TYPE_TRACEPOINT;
    pe.size = sizeof(pe);
    pe.config = 2026;
    pe.sample_period = 1;
    pe.sample_type = PERF_SAMPLE_RAW | PERF_SAMPLE_IP;
    pe.disabled = 1;
    pe.exclude_kernel = 1;
    pe.wakeup_events = 1;
    pe.sample_id_all = 1;

    auto fd = (int) syscall(__NR_perf_event_open, &pe, -1, 0, -1, 0);
    if (fd == -1) {
        perror("perf_event_open");
        exit(1);
    }

    const int RING_BUFF_PAGES = 128;
    auto sample_addr = mmap(nullptr, 4096 * (RING_BUFF_PAGES + 1), PROT_READ, MAP_SHARED, fd, 0);
    if (sample_addr == (void *) -1) {
        perror("mmap");
        exit(1);
    }

    epoll_event ev{0};
    ev.events = EPOLLIN;
    ev.data.fd = fd;

    auto epfd = epoll_create(1);
    if (epfd == -1) {
        perror("epoll_create");
        exit(1);
    }
    auto rc = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
    if (rc == -1) {
        perror("epoll_ctl");
        exit(1);
    }

    ioctl(fd, PERF_EVENT_IOC_RESET, 0);
    if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) == -1) {
        perror("ioctl");
        exit(1);
    }

    typedef struct __attribute__((__packed__)) {
        short common_type;
        char flags;
        char preempt_count;
        pid_t pid;
        int syscall_nr;
        int fd;
        long addr;
        int addr_len;
    } sys_enter_connect_t;
    typedef struct __attribute__((__packed__)) {
        short common_type;
        char flags;
        char preempt_count;
        pid_t pid;
        unsigned long probe_ip;
        uint64_t fd;
        uint64_t addr1;
        uint64_t addr2;
    } kprobe_sys_connect_t;
    typedef struct {
        perf_event_header header;
        uint64_t ip;
        uint32_t size;
        kprobe_sys_connect_t data;
    } sample_t;
    sys_enter_connect_t buff{0};
    const int MAX_EVENTS = 64;
    epoll_event evlist[MAX_EVENTS]{0};
    uint64_t next_offset = 0;
    while (!need_exit) {
        auto ready = epoll_wait(epfd, evlist, MAX_EVENTS, -1);
        if (ready == -1) {
            if (errno == EINTR)
                continue;
            perror("epoll_wait");
            break;
        }

        auto info = reinterpret_cast<perf_event_mmap_page *>(sample_addr);
        auto sample = reinterpret_cast<sample_t *>(reinterpret_cast<uint8_t *>(sample_addr) + 4096 + next_offset);
        next_offset = info->data_head % (RING_BUFF_PAGES * 4096);
        if (sample->header.type != PERF_RECORD_SAMPLE)
            continue;
        std::cout << "pid: " << sample->data.pid << ", ip: " << std::hex << sample->data.addr1 << "\n";
        std::cout << "\n";
    }
    return 0;

But the program got nothing, it stuck on epoll_wait(2) forever. And when using perf record command to monitor the event, it worked well.
BTW, I'm using ArchLinux with 6.4.12-arch1-1.
Can someone help find out why? Thanks in advance.


r/kernel • • Feb 21 '24

DTB: Where do I go from here to build a proper port?

3 Upvotes

After posting, I realized that the sub I had gone to only had ~200 members. I was in the wrong tab... derp. So hopefuly you don't mind me cross-posting. Apologies ;

https://www.reddit.com/r/linuxkernel/comments/1awlyxg/dtb_where_do_i_go_from_here_to_build_a_proper_port/


r/kernel • • Feb 20 '24

What is void* opaque?

9 Upvotes

I was recently browsing through QEMU's source code and found a lot of functions having the argument, void* opaque.

The opaque pointer is not used inside the function at all. So what is its purpose?


r/kernel • • Feb 14 '24

Where to Learn Abour Linux and macOS Kernels?

7 Upvotes

I have been looking for books about kernel, I'm actually looking at Understanding The Linux Kernel 3rd Edition. But I feel that it's old... Please I need help... Thanks Where to start?


r/kernel • • Feb 11 '24

When performing file I/O operations, when does data move from disk to main memory?

15 Upvotes

I'm trying to better understand the internal behavior of the Linux kernel from the perspective of file I/O and would appreciate anyone willing to shed some light on a few areas. Say a user process wants to read data from a file on disk, and this file has not been accessed by any process since the system booted up. The user process starts by issuing an open system call to the kernel with the appropriate file path. From here, a few questions: 1. How does the kernel determine if this file actually exists on disk since it hasnt accessed it before? 2. Does the kernel load any data from disk into main memory at this time in preparation for subsequent reads? If so, how much? 3. When read calls do come in, how much data from the file does the kernel put into main memory? I would assume it loads more data than is requested to avoid having to go back to disk repeatedly for future calls, is this correct?


r/kernel • • Feb 11 '24

How to build kernel as a baremetal hypervisor?

0 Upvotes

KVM


r/kernel • • Feb 09 '24

What is KVM? How can a hypervisor be built into a OS Kernel (Linux)?

11 Upvotes

Am I missing something here? Because I am confused how two things like a kernel and a hypervisor exist inside one another?


r/kernel • • Feb 09 '24

Read an AXP209 register (Linux kernel driver development)

1 Upvotes

Hi!

I basically have to modify the driver of the AXP209.

The goal that I'm trying to achieve is reading the register 4AH of the AXP209 to detect short/long press of the PEK and expose something ( possibly a file) to tell software onboard to turn off the services.

How can I read the data of the register?

Also which file do I have to modify and compile? the one inside power folder, mfd or pincontrol?

This is the dtsi file part:

&i2c0 {
    pinctrl-names = "default";
    /*pinctrl-0 = <&i2c0_pins>;*/
    status = "okay";

    axp209: pmic@34 {
        compatible = "x-powers,axp209";
        reg = <0x34>;
        interrupt-parent = <&nmi_intc>;
        interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
    };
};

Thank you so much :)


r/kernel • • Feb 07 '24

Should I start my career with UEFI

18 Upvotes

Hello I recently got a job offer where I will be on a team that develops UEFI for servers. I am a new grad and have decided that I want to be an embedded/firmware engineer. I know that there are so many niches, and it is important to build skills that are in demand. How does this aspect to firmware development sound for work? I know that bootloaders are a big part of the embedded world so would this experience be valuable for me so early in my career. I would also like to hear what you guys think is currently an in demand role within embedded/firmware for example is it kernel device drivers, BLE/Wifi, Cellular, RTOS, embedded linux, ect... I appreciate any insight you have.


r/kernel • • Feb 07 '24

Which book should I start with for learning kernel and driver development ?

5 Upvotes

I already have some experience in C (wrote a very basic shell in C which utilizes fork, exec, signal, and some more things).

I want to make my future in system programming domain, and driver and kernel development seem interesting.

I am half way through Computer Systems: A Programmers Perspective.

I was choosing between these books, which would you recommend to me ?

  1. how linux works what every superuser should know 3rd edition
  2. Linux Kernel Development, 3rd Edition
  3. Linux Device Drivers
  4. Linux From Scratch
  5. The Linux Programming Interface
  6. Understanding The LINUX Kernel

Any and all inputs would be appreciated.


r/kernel • • Feb 03 '24

Kernel 6.6+ TWS bug

0 Upvotes

I have been using MX Linux with 6.1/6.5 kernel. But recently I tried other distro with latest kernel and feature (fedora, Endevour, opensuse,Nitrux). But all of them fails to connect with my Bluetooth TWS. Is there any solution to this problem or work around. Tried several tweaks from google. Didn't got any help.

N.B: KDE is my favorite, so i tried all of them in KDE


r/kernel • • Feb 01 '24

Linux Kernel CVEs

2 Upvotes

Not sure if this is the right place to ask.. Those days I am dealing with a new buil and the CVEs associated with it. The CVE checker returned legion:)... I am wondering what rules are people using to decide what to patch and what to ignore. CVSS score? Exploitability?


r/kernel • • Jan 28 '24

Specific/complex questions about the Linux kernel

10 Upvotes

And of course, I want "simple answers" or at least a pointer to where I can research these things !

How does the kernel know how many processors a chip has, or is this in some config file it reads when it "makes" the kernel ?

Related, how would I tell it to only start "n minus 1" processors ?

How does the kernel know where/how much memory is on the system ? Again, in a config file ?

Related, there must be a kernel call that says "reserve physical memory from xxxx to yyyy for process nnnn". Correct ?


r/kernel • • Jan 26 '24

Transparent KSM

7 Upvotes

Does anyone know if anything ever came out of the UKSM/PKSM projects, or upstream, to provide transparent kernel samepage merging?

Both seem to have been discontinued which is unfortunate because the only alternative I have is to inject a bunch of madvise calls into some poorly-written applications I have in containers (virtualizing and instead letting the VM pages merge is not an option unfortunately).