my first kernel patch!
March 11, 2011
Here it is!😛
Well, the patch itself isn’t a big deal, since I didn’t write any code. It was a cleanup of asm-offsets.
Afaik, Linux has quite a lot of assembly code, which needs the offsets of various struct members. Of course, assembly code(or even toplevel inline assembly) cannot use the offsetof marco. That’s also the case for some C constants, eg:
#define PAGE_SIZE (1UL << PAGE_SHIFT))
Thus, these offsets and constants are ‘calcualted’ at build time as ‘absolute values’ so that gas will be ok.😛
Using the macros defined in incldue/linux/kbuild.h
#define DEFINE(sym, val) \ asm volatile("\n->" #sym " %0 " #val : : "i" (val)) #define BLANK() asm volatile("\n->" : : ) #define OFFSET(sym, str, mem) \ DEFINE(sym, offsetof(struct str, mem)) #define COMMENT(x) \ asm volatile("\n->#" x)
the asm-offsets.c is used to create a ‘special’ asm fle, which is then parsed by the kernel build system, in order to create the include/generated/asm-offsets.h file.
However, a patch introduced two new macros in include/linux/const.h
#ifdef __ASSEMBLY__ #define _AC(X,Y) X #define _AT(T,X) X #else #define __AC(X,Y) (X##Y) #define _AC(X,Y) __AC(X,Y) #define _AT(T,X) ((T)(X)) #endif
so that some constants defined in C work with gas too.
And now, the PAGE_SIZE is defined as
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT
and thus, the PAGE_SIZE_asm defined in x86/asm-offsets.c, and used in some places in x86 code was no longer needed(that’s also the case with PAGE_SHIFT and THREAD_SIZE).
So, I deleted PAGE_SIZE_asm/PAGE_SHIFT_asm/THREAD_SIZE_asm from x86/kernel/asm-offsets.c, and replaced them with their non-asm counterparts, in the code that used them.
I posted it to lkml(after some hours experimenting with git format-patch and git send-email :P), and it got accepted.🙂