Build and run the latest linux kernel on your desktop computer

Av Christopher Dahlberg den 25 Mars 2015

If you are eager to try out the new version 4 of the Linux kernel this is the guide for you! This guide will tell you how to download the latest Linux tree and build it for your current setup. At last we will install the image on your system (parallel to your existing one, no worries). So that you at boot-time can choose which to start (dual-boot). Before it was quite a lot a hassle to do this (so I’ve heard ;) ) although today its childs play:

# Clone the official Linux repo
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

# Navigate into the Linux tree
cd linux

# Checkout the latest release (at the time of this post it was 4.0.0-rc5)
git checkout v4.0-rc5

# Copy the configuration from your existing configuration file (your configuration will probably have some other name, depending on your current version)
cp /boot/config-3.11-2-amd64 .config

# Port the configuration to fit the new kernel
make olddefconfig

# Build the kernel and modules
make -j 8

# Install modules in /lib/modules/ (need root permission)
make modules_install

# Install the kernel in boot folder and generate a initrd image (need root permission)
make install

# Assuming that you are using grub, update the grub configuration to also include the new kernel
update-grub

At boot time you will now be able to choose between your old kernel or bleeding edge (4.0.0-rc5 in this case). Enjoy!

Global Azure Bootcamp 2015 i Linköping

Av Per Salmi den 10 Mars 2015

2015-logo-250x169.NET användargruppen Swenug arrangerar i samarbete med Combitech det världsomspännande community eventet Global Azure Bootcamp 2015 i Linköping lördagen den 25 april 2015!

Arrangemanget är en minikonferens  och workshop om Microsoft Azure som körs på samma dag på över 110 platser jorden runt. Dagen innehåller föreläsningar och labbar där vi tillsammans prövar på olika delar av Azure plattformen och dessutom deltar i en global gemensam labb.

Anmälan är öppen för alla utan kostnad, antalet platser är dock begränsat så en anmälan behövs och den fixar man snabbt och enkelt på http://azurelkpg.eventday.com där den senaste informationen om eventet också kommer att publiceras!

Linux 4.0 and live patching

Av Marcus Folkesson den 2 Mars 2015

Linus has released -rc1 for Linux 4.0 and it contains several interesting features.
One of the most top headlines is live patching, which simple let you to patch a running system without miss uptime at all. SUSE and Red Hat has developed their respecive variant on the kernel patching mechanism, independent (and unknowing) of each other. The companies has agreed to base their work on a common API, which is what will takes place in v4.0. Then we will see what really becomes implemented in upcoming versions of the kernel.

Interesting feature indeed, but maybe it is just as Arjan van de Ven say on the mailing list:

Now, live patching sounds great as ideal, but it may end up being (mostly) similar like hardware hotplug: Everyone wants it, but nobody wants to use it.

MMAP memory between kernel- and userspace

Av Marcus Folkesson den 21 Januari 2015

MMAP memory between kernel- and userspace

Allocate memory in kernel and let userspace map is sounds like an easy task, and sure it is. There are just a few things that is good to know about page mapping.
The MMU (Memory Management Unit) contains page tables with entries for mapping between virtual and physical addresses. These pages is the smallest unit that the MMU deals with.
The size of a page is given by the PAGE_SIZE macro in asm/page.h ans is typically 4k for most architectures.

There is a few more useful macros in asm/page.h:

PAGE_SHIFT: How many steps we should shift to left to get a PAGE_SIZE
PAGE_SIZE: Size of a page, defined as (1 << PAGE_SHIFT).
PAGE_ALIGN(len): Will round up the length to the closest alignment of PAGE_SIZE.

How does mmap(2) work?

Every page table entry has a bit that tells us if the entry is valid in supervisor mode (kernel mode) only. And sure, all memory allocated in kernel space will have this bit set.
What the mmap system call do is simply creating a new page table entry with a different virtual address that points to the same physical memory page. The difference is that this supervisor-bit is not set.
This let userspace access the memory as if it was a part of the application, for now it is!
The kernel is not involved in those accesses at all, so it is really fast.
Magic? Kind of.
The magic is called remap_pfn_range().
What remap_pfn_range() do is just essentially to update the processor’s specific page table with these new entries.

Example please

Allocate memory
As said before, the smallest unit that the MMU handle is the size of PAGE_SIZE and the mmap(2) only works with full pages. Even if you just want to share only 100 bytes, a whole page frame will be remapped and must therefor be allocated in the kernel.

The allocated memory must also be page aligned.

__get_free_pages()
One way to allocate pages is with __get_free_pages().

unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)

The gft_mask is commonly set to GFP_KERNEL in process/kernel context and GFP_ATOMIC in interrupt context. The order is the number of pages to allocate expressed in 2^order.
For example:

u8 *vbuf = __get_free_pages(GFP_KERNEL, size >> PAGE_SHIFT);

Allocated memory is freed with __free_pages().

vmalloc()

A more common (and preferred) way to allocate virtual continuous memory is with vmalloc().
vmalloc() will allways allocate whole set of pages, no matter what. This is exactly what we want!

Read about vmalloc() in kmalloc(9):

allocates size bytes, and returns a pointer to the allocated memory. size becomes page aligned by vmalloc(), so the smallest allocated amount is 4kB. The allocated pages are mapped to the virtual memory space behind the 1:1 mapped physical memory in the kernel space. Behind every vmalloc’ed area there is at least one unmapped page. So writing behind the end of a vmalloc’ed area will not result in a system crash, but in a segmentation violation in the kernel space. Because memory fragmentation isn’t a big problem for vmalloc(), vmalloc() should be used for huge amounts of memory.

Allocated memory is freed with vfree().

alloc_page()

If you need only one page, alloc_page() will give you that.
If this is the case, insead of using remap_pfn_range(), vm_insert_page() will do the work you for you.
Notice that vm_insert_page() apparently only works on order-0 (single-page) allocation. So if you want to allocate N pages, you will hace to call vm_insert_page() N times.

Now some code

Allocation

priv->a_size = ATTRIBUTE_N * ATTRIBUTE_SIZE;
/* page align */
priv->a_size = PAGE_ALIGN(priv->a_size);
priv->a_area =vmalloc(priv->a_size);

file_operations.mmap

static int scan_mmap (struct file *file, struct vm_area_struct *vma)
{
struct mmap_priv *priv = file->private_data;
unsigned long start = vma->vm_start;
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long page;
size_t size = vma->vm_end – vma->vm_start;

if (size > priv->a_size)
return -EINVAL;

page = vmalloc_to_pfn((void *)priv->a_area);
if (remap_pfn_range(vma, start, page, priv->a_size, PAGE_SHARED))
return -EAGAIN;

vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
return 0;
}

Juleavslutning i Combitech AS

Av Linn Eikeland den 22 December 2014

God jul og et godt nytt år

Årets juleavslutning i Stavanger ble i god tradisjon et stemningsfylt førjulsverksted fylt av små og store. Med båt fra Oljemuseet bar det over til Natvigs Minde, der alver og nisser ventet på oss i julenissens verksted. Alle våre 22 nisseungene satte flittig i gang med laging av julegodteri, kremmerhus, glitrende tegninger og ikke minst snekring av fuglekasser. Med risgrøt, saft, julefortelling og julemusikk falt virkelig julestemningen over oss.

Juleavslutningen til Oslokontoret var i skikkelig Bayescamp-ånd og ble avholdt på Skjennungstua. Skjennungstua er et populært turmål i Nordmarka i Oslo, så for å komme frem ventet en frisk tur gjennom skogen.

Heldigvis er vi Combitechere litt føre-var og sendte Jan inn i skogen for å sjekke forholdene på forhånd. Beskjeden var klar om at veien inn var dekket av is og alle måtte ha på seg brodder (helst typen stegjern).

Ved ankomst til Skjennungstua var peisen tent og vi fikk servert nybakte boller og varm gløgg. Bare bollene gjorde turen verdt strevet. Til middag fikk vi servert herlig suppe og kalkun.

Etter at en god middag var inntatt var det tid for å spasere hjem igjen. Da vi kom ut dørene oppdaget vi til vår glede at snøen lavet ned. Turen gjennom skog opplyst av snø ga oss en magisk julestemning.

Vi i Combitech ønsker med dette alle en god jul og et godt nytt år!