Skip to main content

Posts

DailyLog: 20200916

 Workflow: Allocating a page from user space                       Learning     Enable Tracing: https://www.kernel.org/doc/html/v4.18/trace/events.html  Not able to enable the same Tracing is enabled for my kernel - I was able to turn on for page allocation Check vim /sys/kernel/debug/tracing/trace https://events.static.linuxfound.org/sites/events/files/slides/praesentation_0.pdf  Another PPT:  https://events19.linuxfoundation.org/wp-content/uploads/2017/12/oss-eu-2018-fun-with-dynamic-trace-events_steven-rostedt.pdf (Even better!)        
Recent posts

DailyLog: 20200913

 DailyLog: 20200913 Part I: Linux Kernel Module Compilation + Loading Question: Having trouble loading up your module Answer:   #1 Finally found something on it. It appears to be a "feature" where unsigned code can't be loaded into the kernel when UEFI secure boot is enabled (which it is). To get the module loading, disable kernel lockdown via sys-rq: # echo 1 > /proc/sys/kernel/sysrq # echo x > /proc/sysrq-trigger Then modprobe should work: modprobe wireguard For more information, see: https://mjg59.dreamwidth.org/50577.html https://bugzilla.redhat.com/show_bug.cgi?id=1599197   Issue 1. Cannot turn the sysrq off (Hmmm...)   #2 From https://stackoverflow.com/questions/29036987/insmod-error-in-kernel-module-programming Steps to securely sign your kernel modules: Create a X509 certificate that can be imported in firmware Enrolling the public key just created Sign the module you want to install Install the module    To sign kernel modules, we can

mmap.c

mmap.c 1. 3 kinds of protection: Read, Write and Execute 2. 2 kinds of mappings: Private and Shared 3. VMA flags are set in vm area struct . This is in the lask struct structure (aka current for the currently executing process 4. Arch may decide to not have its page protection returned - This is why the page protection part is within a config loop.     1. Note that this is different from the way config options are generally used in kernel. Generally the entire function is either callable (with correct behavior) or callable (with no behavior) => The second case pertains to config option not being specified. 5. There is a concept of write notify. Need to understand this better. Specific question - How will the VMA user get notified?     1.  if (vma_wants_writenotify(vma, vm_page_prot)) { 6. Something called interval tree - Find out what it is.     vma_interval_tree_remove(vma, &mapping->i_mmap); 7. Main concepts are rb_tree and vma_cache ##Important functions **void vma_set_pag

Linux Memory management Deep Dive

Focussing on Linux memory management for Feb 2018 The main idea is as follows Main Idea 1. MM hierarchy deals with segmenting discovered machine memory into pages. 2. It also provides memory algorithms like SLAB, SLUB, SLOB 3. Provides page related functions like allocation, deallocation etc 4. Provides abstraction and interfaces to swapping, virtual memory etc I'll be working at several small workflows and will iterate them here. Here's an initial list Core Workflows (All these workflows will be studied) 1. Initialize all discovered memory 2. Allocating a page from user space 3. Allocating a page from kernel space 4. Deallocating both user and kernel space pages 5. Number of free pages fall below lowest watermark 6. SLUB,SLOB, SLAB algorithm working (I can start here) 7. Page Fault Handling 8. Swap In and Swap Out modules 9. Virtual memory working Open Question 1. Tracing: How do I validate above workflows in practice??
Change in Plans.. This ain't working.. I need to show more focus, commitment and planning. The idea is to do some planned kernel things everyday For example since I'm focussing on scheduler these days, I will keep on doing some titbits here and there for a complete month to max 6 weeks. Since I started on May 1, this will end by mid June and then I will start digging into perforce and patches.
Restarting... Restarting the kernel travels after a long time.. I have made some minor efforts in the last couple of years but have lost almost all record of the same. I'm making one more determined effort to do and record stuff. The idea is to be true with myself about my effort.
ULK Chapter #2 Chapter2. Memory Addressing * Types of Memory Address 1. Logical : Machine view; segments and offsets 2. Linear : Virtual address; Unsigned num upto 4 GB 3. Physical: Used to address memory cells in memory chips. They correspond to the electrical signals sent along the address pins of the microprocessor to the memory bus. Physical addresses are represented as 32-bit or 36-bit unsigned integers. Interaction between various address types ------------------------------------------ The Memory Management Unit (MMU) transforms a logical address into a linear address by means of a hardware circuit called a segmentation unit ; subsequently, a second hardware circuit called a paging unit transforms the linear address into a physical address Memory Arbiter ------------- In multiprocessor systems, all CPUs usually share the same memory; this means that RAM chips may be accessed concurrently by independent CPUs. Because read or write operations on a RAM chip must be performed se
Linux VM Notes #2 Zones Each zone is described by a struct zone_struct. zone_structs keep track of information like page usage statistics, free area information and locks. Here is the zone struct.. /* * On machines where it is needed (eg PCs) we divide physical memory * into multiple physical zones. On a PC we have 3 zones: * * ZONE_DMA < 16 MB ISA DMA capable memory * ZONE_NORMAL 16-896 MB direct mapped by the kernel * ZONE_HIGHMEM > 896 MB only page cache and user processes */ struct zone { /* Fields commonly accessed by the page allocator */ unsigned long free_pages; unsigned long pages_min, pages_low, pages_high; /* * We don't know if the memory that we're going to allocate will be freeable * or/and it will be released eventually, so to avoid totally wasting several * GB of ram we must reserve some of the lower zone memory (otherwise we risk * to run OOM on the lower zones despite there's tons of freeable ram * on the higher zones). Th