Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lkl fbsd #220

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7b03790
checkpatch: avoid showing uint*_t warnings for tools/ files
Sep 21, 2015
2daea04
checkpatch: avoid showing BIT_ULL warnings for tools/ files
Sep 21, 2015
d7f3cf0
asm-generic: atomic64: allow using generic atomic64 on 64bit platforms
Jul 23, 2015
0cc6fd2
kbuild: allow architectures to automatically define kconfig symbols
Nov 2, 2015
bdcd92b
lkl: architecture skeleton for Linux kernel library
Sep 15, 2015
c37082e
lkl: host interface
Nov 2, 2015
5456f35
lkl: memory handling
Sep 15, 2015
359c42b
lkl: kernel threads support
Sep 16, 2015
cbf0c57
lkl: interrupt support
Sep 16, 2015
f088db9
lkl: system call interface and application API
Sep 16, 2015
bba49f9
lkl: timers, time and delay support
Sep 16, 2015
ea4fda5
lkl: memory mapped I/O support
Sep 17, 2015
6e8fb31
lkl: basic kernel console support
Sep 17, 2015
47493a4
init: allow architecture code to overide run_init_process
Aug 19, 2015
1ee887e
lkl: initialization and cleanup
Sep 17, 2015
a7ef6b6
lkl: plug in the build system
Sep 17, 2015
4fc2010
lkl tools: skeleton for host side library, tests and tools
Sep 18, 2015
d72f515
lkl tools: host lib: add lkl_strerror and lkl_printf
Sep 18, 2015
1a8636c
lkl tools: host lib: memory mapped I/O helpers
Sep 18, 2015
da15a1b
lkl tools: host lib: virtio devices
Sep 18, 2015
059ac9c
lkl tools: host lib: virtio block device
Sep 18, 2015
5fd23ea
lkl tools: host lib: filesystem helpers
Sep 18, 2015
2cd5d37
lkl tools: host lib: posix host operations
Sep 18, 2015
461a58d
lkl tools: "boot" test
Sep 18, 2015
6c52ac5
lkl tools: tool that converts a filesystem image to tar
Sep 18, 2015
c8e0586
lkl tools: tool that reads/writes to/from a filesystem image
Sep 18, 2015
e2b0cf0
signal: use CONFIG_X86_32 instead of __i386__
Sep 29, 2015
4145718
asm-generic: vmlinux.lds.h: allow customized rodata section name
Oct 27, 2015
c9411ed
lkl: add support for Windows hosts
Nov 3, 2015
d5bc73f
lkl tools: add support for Windows host
Nov 3, 2015
90814da
lkl: add documentation
Sep 28, 2015
8ec7b89
lkl: fix zero page implementation
Nov 8, 2015
fe49079
lkl: add more filesystem related system calls
Nov 8, 2015
d88e0bd
lkl tools: git .gitignore
Nov 8, 2015
c4591a9
lkl tools: add a new lkl_dirfd API
Nov 8, 2015
2a3cf55
lkl tools: add lklfuse
Nov 8, 2015
5ee93e6
lkl: sys_statfs64 takes a middle size parameter
cemeyer Nov 9, 2015
69259d8
lkl: headers_install: Use env(1) to locate python binary
cemeyer Nov 9, 2015
40ce53e
lkl tools: Makefile: Drop lkl.o:lkl.o circular dependency
cemeyer Nov 9, 2015
4efe442
lkl: convert makefile echo \t to inline tab
cemeyer Nov 9, 2015
ed4362d
lkl tools: Add kernel clean to clean target
cemeyer Nov 9, 2015
2bd6dca
tools lkl: Use OUTPUT_FORMAT variable instead of duplicating LD invoc…
cemeyer Nov 9, 2015
5b51c31
lkl tools: build with GCC, turn on the optimizer and more warnings
cemeyer Nov 9, 2015
ce68a0c
lkl tools: Fix compiler warnings
cemeyer Nov 9, 2015
3aa8768
lkl: add support for 64bit FreeBSD
cemeyer Nov 9, 2015
dc4223e
lkl: On FreeBSD, use hw.ncpu sysctl instead of Linux nproc(1)
cemeyer Nov 9, 2015
12f7c73
lkl tools: add support for 64bit FreeBSD
cemeyer Nov 11, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Documentation/lkl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

Introduction
------------

LKL (Linux Kernel Library) is aiming to allow reusing the Linux kernel code as
extensively as possible with minimal effort and reduced maintenance overhead.

Examples of how LKL can be used are: creating userspace applications (running on
Linux and other operating systems) that can read or write Linux filesystems or
can use the Linux networking stack, creating kernel drivers for other operating
systems that can read Linux filesystems, bootloaders support for reading/writing
Linux filesystems, etc.

With LKL, the kernel code is compiled into an object file that can be directly
linked by applications. The API offered by LKL is based on the Linux system call
interface.

LKL is implemented as an architecture port in arch/lkl. It uses host operations
defined by the application or a host library (tools/lkl/lib).


Building LKL on FreeBSD
-----------------------

$ pkg install binutils gcc49

If you don't have a gcc binary:
$ ln -sf /usr/local/bin/gcc49 /usr/local/bin/gcc

Prefer ports binutils:
$ export PATH=/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib64/ccache

$ cd tools/lkl
$ gmake


Building LKL the host library and LKL applications
--------------------------------------------------

% cd tools/lkl
% make

will build LKL as a object file, it will install it in tools/lkl/lib together
with the headers files in tools/lkl/include then will build the host library,
tests and a few of application examples:

* tests/boot - a simple applications that uses LKL and exercises the basic LKL
APIs

* fs2tar - a tool that converts a filesystem image to a tar archive

* cptofs/cpfromfs - a tool that copies files to/from a filesystem image


Supported hosts
---------------

The supported hosts for now are POSIX and Windows userspace applications.

FAQ
---

Q: How is LKL different from UML?

A: UML prodivides a full OS environment (e.g. user/kernel separation, user
processes) and also has requirements (a filesystem, processes, etc.) that makes
it hard to use it for standalone applications. UML also relies heavily on Linux
hosts. On the other hand LKL is designed to be linked directly with the
application and hence does not have user/kernel separation which makes it easier
to use it in standalone applications.


Q: How is LKL different from LibOS?

A: LibOS re-implements high-level kernel APIs for timers, softirqs, scheduling,
sysctl, SLAB/SLUB, etc. LKL behaves like any arch port, implementing the arch
level operations requested by the Linux kernel. LKL also offers a host interface
so that support for multiple hosts can be implemented.


6 changes: 6 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -6355,6 +6355,12 @@ F: arch/powerpc/platforms/pasemi/
F: drivers/*/*pasemi*
F: drivers/*/*/*pasemi*

LINUX KERNEL LIBRARY
M: Octavian Purdila <[email protected]>
S: Maintained
F: arch/lkl/
F: tools/lkl/

LINUX SECURITY MODULE (LSM) FRAMEWORK
M: Chris Wright <[email protected]>
L: [email protected]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ endif # KBUILD_EXTMOD

ifeq ($(dot-config),1)
# Read in config
-include arch/$(SRCARCH)/auto.conf
-include include/config/auto.conf

ifeq ($(KBUILD_EXTMOD),)
Expand Down
1 change: 1 addition & 0 deletions arch/lkl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kernel/vmlinux.lds
84 changes: 84 additions & 0 deletions arch/lkl/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
config LKL
def_bool y
depends on !SMP && !MMU && !COREDUMP && !AUDITSYSCALL && !SECCOMP && !TRACEPOINTS && !UPROBES && !COMPAT && !USER_RETURN_NOTIFIER
select ARCH_THREAD_INFO_ALLOCATOR
select RWSEM_GENERIC_SPINLOCK
select GENERIC_ATOMIC64
select SEMAPHORE_SLEEPERS
select GENERIC_TIME
select GENERIC_FIND_NEXT_BIT
select GENERIC_HWEIGHT
select GENERIC_HARDIRQS
select FLATMEM
select FLAT_NODE_MEM_MAP
select GENERIC_CLOCKEVENTS
select GENERIC_CPU_DEVICES
select NO_HZ_IDLE
select NO_PREEMPT
select ARCH_WANT_FRAME_POINTERS
select PHYS_ADDR_T_64BIT if 64BIT
select 64BIT if OUTPUT_FORMAT = "elf64-x86-64"
select HAVE_UNDERSCORE_SYMBOL_PREFIX if OUTPUT_FORMAT = "pe-i386"
select 64BIT if OUTPUT_FORMAT = "elf64-x86-64-freebsd"

config OUTPUTFORMAT
string
option env="OUTPUT_FORMAT"

config OUTPUT_FORMAT
string "Output format"
default OUTPUTFORMAT

config ARCH_DMA_ADDR_T_64BIT
def_bool 64BIT

config 64BIT
def_bool n

config BIG_ENDIAN
def_bool n

config NO_DMA
def_bool y

config GENERIC_CSUM
def_bool y

config GENERIC_HWEIGHT
def_bool y

config NO_IOPORT_MAP
def_bool y

config RWSEM_GENERIC_SPINLOCK
bool
default y

source init/Kconfig

source net/Kconfig

source drivers/base/Kconfig

source drivers/virtio/Kconfig

source drivers/block/Kconfig

source fs/Kconfig

source mm/Kconfig

source kernel/Kconfig.preempt

source kernel/Kconfig.locks

source kernel/Kconfig.hz

source security/Kconfig

source crypto/Kconfig

source lib/Kconfig

source lib/Kconfig.debug

47 changes: 47 additions & 0 deletions arch/lkl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include arch/lkl/auto.conf

KBUILD_CFLAGS += -fno-builtin

ifneq (,$(filter $(OUTPUT_FORMAT),elf64-x86-64 elf64-x86-64-freebsd))
KBUILD_CFLAGS += -fPIC
else ifeq ($(OUTPUT_FORMAT),pe-i386)
prefix=_
# workaround for #include_next<stdarg.h> errors
LINUXINCLUDE := -isystem arch/lkl/include/system $(LINUXINCLUDE)
else
$(error Unrecognized platform: $(OUTPUT_FORMAT))
endif

ifneq (,$(filter $(OUTPUT_FORMAT),elf64-x86-64-freebsd))
NPROC=$(shell sysctl -n hw.ncpu)
else
NPROC=$(shell nproc)
endif

LDFLAGS_vmlinux += -r
LKL_ENTRY_POINTS := lkl_start_kernel lkl_sys_halt lkl_syscall lkl_trigger_irq \
lkl_get_free_irq lkl_put_irq

core-y += arch/lkl/kernel/

all: lkl.o

lkl.o: vmlinux
$(OBJCOPY) $(foreach sym,$(LKL_ENTRY_POINTS),-G$(prefix)$(sym)) vmlinux lkl.o

install: lkl.o __headers
@echo " INSTALL $(INSTALL_PATH)/lib/lkl.o"
@cp lkl.o $(INSTALL_PATH)/lib/
@arch/lkl/scripts/headers_install.py \
$(subst -j,-j$(NPROC),$(findstring -j,$(MAKEFLAGS))) \
$(INSTALL_PATH)/include

archclean:
$(Q)$(MAKE) $(clean)=$(boot)

define archhelp
echo ' install - Install library and headers to INSTALL_PATH/{lib,include}'
endef



1 change: 1 addition & 0 deletions arch/lkl/auto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export OUTPUT_FORMAT=$(shell $(LD) -r -print-output-format)
35 changes: 35 additions & 0 deletions arch/lkl/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CONFIG_LOCALVERSION_AUTO is not set
# CONFIG_USELIB is not set
# CONFIG_SYSFS_SYSCALL is not set
CONFIG_KALLSYMS_ALL=y
# CONFIG_BASE_FULL is not set
# CONFIG_FUTEX is not set
# CONFIG_EPOLL is not set
# CONFIG_SIGNALFD is not set
# CONFIG_TIMERFD is not set
# CONFIG_EVENTFD is not set
# CONFIG_AIO is not set
# CONFIG_ADVISE_SYSCALLS is not set
CONFIG_EMBEDDED=y
# CONFIG_VM_EVENT_COUNTERS is not set
# CONFIG_COMPAT_BRK is not set
# CONFIG_BLK_DEV_BSG is not set
# CONFIG_UEVENT_HELPER is not set
# CONFIG_FW_LOADER is not set
CONFIG_VIRTIO_MMIO=y
CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
CONFIG_VIRTIO_BLK=y
CONFIG_EXT4_FS=y
CONFIG_EXT4_FS_POSIX_ACL=y
CONFIG_EXT4_FS_SECURITY=y
# CONFIG_FILE_LOCKING is not set
# CONFIG_DNOTIFY is not set
# CONFIG_INOTIFY_USER is not set
# CONFIG_MISC_FILESYSTEMS is not set
CONFIG_CRYPTO_ANSI_CPRNG=y
CONFIG_PRINTK_TIME=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_INFO_REDUCED=y
# CONFIG_ENABLE_WARN_DEPRECATED is not set
# CONFIG_ENABLE_MUST_CHECK is not set
CONFIG_SLUB_DEBUG_ON=y
77 changes: 77 additions & 0 deletions arch/lkl/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
generic-y += atomic.h
generic-y += barrier.h
generic-y += bitops.h
generic-y += bug.h
generic-y += bugs.h
generic-y += cache.h
generic-y += cacheflush.h
generic-y += checksum.h
generic-y += cmpxchg-local.h
generic-y += cmpxchg.h
generic-y += cputime.h
generic-y += current.h
generic-y += delay.h
generic-y += device.h
generic-y += div64.h
generic-y += dma.h
generic-y += emergency-restart.h
generic-y += errno.h
generic-y += exec.h
generic-y += ftrace.h
generic-y += futex.h
generic-y += hardirq.h
generic-y += hw_irq.h
generic-y += ioctl.h
generic-y += ipcbuf.h
generic-y += irq_regs.h
generic-y += irqflags.h
generic-y += irq_work.h
generic-y += kdebug.h
generic-y += kmap_types.h
generic-y += linkage.h
generic-y += local.h
generic-y += local64.h
generic-y += mcs_spinlock.h
generic-y += mmu.h
generic-y += mmu_context.h
generic-y += module.h
generic-y += msgbuf.h
generic-y += page.h
generic-y += param.h
generic-y += parport.h
generic-y += pci.h
generic-y += percpu.h
generic-y += pgalloc.h
generic-y += poll.h
generic-y += preempt.h
generic-y += resource.h
generic-y += rwsem.h
generic-y += scatterlist.h
generic-y += seccomp.h
generic-y += sections.h
generic-y += segment.h
generic-y += sembuf.h
generic-y += serial.h
generic-y += shmbuf.h
generic-y += siginfo.h
generic-y += signal.h
generic-y += simd.h
generic-y += sizes.h
generic-y += socket.h
generic-y += sockios.h
generic-y += stat.h
generic-y += statfs.h
generic-y += string.h
generic-y += swab.h
generic-y += switch_to.h
generic-y += termbits.h
generic-y += termios.h
generic-y += time.h
generic-y += timex.h
generic-y += tlb.h
generic-y += tlbflush.h
generic-y += topology.h
generic-y += trace_clock.h
generic-y += uaccess.h
generic-y += unaligned.h
generic-y += word-at-a-time.h
11 changes: 11 additions & 0 deletions arch/lkl/include/asm/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __LKL_BITSPERLONG_H
#define __LKL_BITSPERLONG_H

#include <uapi/asm/bitsperlong.h>

#define BITS_PER_LONG __BITS_PER_LONG

#define BITS_PER_LONG_LONG 64

#endif

10 changes: 10 additions & 0 deletions arch/lkl/include/asm/byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _ASM_LKL_BYTEORDER_H
#define _ASM_LKL_BYTEORDER_H

#if defined(CONFIG_BIG_ENDIAN)
#include <linux/byteorder/big_endian.h>
#else
#include <linux/byteorder/little_endian.h>
#endif

#endif /* _ASM_LKL_BYTEORDER_H */
6 changes: 6 additions & 0 deletions arch/lkl/include/asm/dma-mapping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _ASM_LKL_DMA_MAPPING_H
#define _ASM_LKL_DMA_MAPPING_H

#include <asm-generic/dma-mapping-broken.h>

#endif
13 changes: 13 additions & 0 deletions arch/lkl/include/asm/elf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _ASM_LKL_ELF_H
#define _ASM_LKL_ELF_H

#define elf_check_arch(x) 0

#ifdef CONFIG_64BIT
#define ELF_CLASS ELFCLASS64
#else
#define ELF_CLASS ELFCLASS32
#endif

#endif

Loading