lkl / linux Goto Github PK
View Code? Open in Web Editor NEWThis project forked from torvalds/linux
Linux kernel source tree
Home Page: https://lkl.github.io/
License: Other
This project forked from torvalds/linux
Linux kernel source tree
Home Page: https://lkl.github.io/
License: Other
As far as I can see, the scope of lkl is pretty similar to the NetBSD Rump kernels (http://rumpkernel.org/). The difference there is that it has developed several back-ends already (directly on Xen, bare metal, GenodeOS, Hurd, ...).
So the crazy thing I just throw "out there" is : does it make any sense to build lkl on top of Rump (specifically, rumprun libc)?
At first sight it seems as convoluted as running Cygwin on top of Wine, but people do that sometimes...
lklfuse_utimens doesn't call utimensat with the AT_SYMLINK_NOFOLLOW flag.
This makes untar fail if it extracts a symlink before its target and attempts to set the mtime. lklfuse will follow the broken link and return ENOENT.
Upper layers translate utimensat on a symlink to the link or the target depending on the flags before calling utimens on the VFS, which is why FUSE does not receive the flags.
Simple repro that fails in an lklfuse mount:
ln -s bad link
touch --no-dereference link
This bug originates in older FUSE examples, and has been fixed:
http://marc.info/?l=fuse-devel&m=130902410132197&w=2
http://unix.stackexchange.com/questions/89886/modify-date-of-symlink-on-bindfs
This is possible after 0acaaa7 , I think.
Perhaps as simple as:
-$(execs): lib/liblkl.a
+$(execs): $(lib)
in tools/lkl/Makefile.
lkl> gcc -o lklfuse lklfuse.o lib/liblkl.a -lpthread -lrt -lfuse
/usr/bin/ld: error in lib/liblkl.a(lkl.o)(.eh_frame); no .eh_frame_hdr table will be created.
Is this error expected?
I want to use lkl in one of my projects and currently the bulid process is a bit clumsy. There ist no make install
and the build is only within the tree, and the Kernel's Kbulid won't install lkl headers like lkl.h
and similar issues that are all minor by themselves.
I therefore want to volunteer to clean up the build system a little bit, provide a sensible install target, provide a .pc file for pkg-config
and maybe make the featureset of lkl more configurable (e.g. separate the liblkl* stuff from current userspace tools like lklfuse
and fs2tar
.
Before I start, I have two questions:
Looking at fs2tar
I'm very much interested in doing the reverse operation - untarring into a filesystem image.
While the thought crosses my mind to port tar
to link LKL, it seems like what I want could also be accomplished by having a binary which wraps the syscalls to write files to LKL initialized with an existing filesystem.
Has any such work already been done (or does it suffer an obvious drawback) ?
tools/lib/Makefile provides two targets with slightly different names:
ifneq (,$(filter $(OUTPUT_FORMAT),elf64-x86-64))
lib += lib/liblkl_hijack.so
hijack_objs = $(patsubst %.c,%.o,$(wildcard lib/hijack/*.c))
objs += $(hijack_objs)
endif
lib/liblkl_hijack.so: LDFLAGS += -ldl
lib/liblkl_hijack.so: $(hijack_objs) lib/liblkl.a
$(CC) -o $@ -shared $^ $(LDFLAGS)
# order of -lxxx again really matters for LD_PRELOAD
lib/liblkl-hijack.so: $(hijack_objs) Makefile lib/liblkl.so
$(CC) -shared -nodefaultlibs $(lib_objs) -Llib -llkl $(hijack_objs) \
-ldl -lpthread -lrt -o $@
On my machine, I can't get liblkl_hijack.so
to work:
➜ lib git:(debug) ✗ LD_LIBRARY_PATH=. LD_PRELOAD=liblkl_hijack.so ping localhost
ERROR: ld.so: object 'liblkl_hijack.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
The rules for liblkl_hijack.so
don't make sense to me --- why would the hijacking code need to be linked against lkl on some architectures but not others? --- but if they're correct then the conditional should be rewritten to ifeq (elf64-x86-64,$(OUTPUT_FORMAT))
and the _ version should get a more descriptive name.
My suspicion is that this is a bad copy+paste or something like that --- is there a reason for it that I'm missing?
Feel free to ignore or close this one — I realize the README.md symlink is mostly a convenience for Github users and will never go upstream, while Documentation/lkl.txt
may well land in Linus' tree.
However, some of lkl.txt renders ugly in Github Markdown. Individual lines that should be left unformatted (code / shell examples) get merged (in the "Building" sections).
In generated lkl/linux/if.h, the net_device_flags enum is defined and used
It should be renamed to lkl_net_device_flags
enum's values are properly renamed, only the name of the enum itself is not renamed
This leads to build error when including host and lkl's include
After grepping, it is the case for all named enums.
It seems impossible at the moment to run two instances of LKL (e.g. two separate calls to lkl_start_kernel
etc.) in a same process. Any idea how to do that easily?
I'm currently writing an application using LKL that waits for data on a network socket using a blocking call to read()
and occasionally write()
s data from another application thread. Once the read()
syscall has been issued, no write()
s can be performed until the socket receives some data and returns from the read()
.
While in theory I could use select()
or poll()
here because the data I want to write also comes from another socket, I cannot in practice because the other socket is a non-LKL "normal" socket and we cannot mix LKL and non-LKL FDs (yet?).
I digged into the syscall handling and understand that supporting SMP is probably a bigger issue (I also don't fully understand all the internals of LKL's threading yet), but I would like to see support for it (because I have an actual use case for that) and think it should be tracked in an issue :-)
I'm very excited by lkl
for a project I"m working on, however I need access to the kernel's x509 functions, specifically x509_cert_parse
(https://github.com/torvalds/linux/blob/master/crypto/asymmetric_keys/x509_cert_parser.c#L68).
However, I don't see this in strings lkl.o
. I'd be great if this could be added! Not sure if that's just a matter of adjusting the .config
or if more work is involved.
I'm having some problems getting passive open TCP connections to work on LKL. It looks like LKL_HIJACK_NET_GATEWAY might be the ticket for getting routing info to the LKL kernel, but I can't figure out how to use it --- am I supposed to hijack a device from the host kernel? The TAP device in the LKL kernel? Something else? Would it be possible to give a usage example/testcase (to go in tests/hijack.sh)?
Valgrind runs code in LD_PRELOAD
twice for any process it is used on, so it can't be used as-is for checking memory access in hijacked executables that need to use TAP devices. The first execution starts up the LKL kernel and takes control of the TAP device, and then the second execution errors out because the device is already in use.
As a heads up to anyone else trying to track down memory errors, I patched Valgrind to support using LKL_PRELOAD
and LKL_LIBRARY_PATH
as replacements for LD_*
versions. The repo is here --- let me know if there's anything I should do with that repo to make it more useful to LKL. I changed the Linux launcher in particular so no other platforms are supported.
Hi.
I have packaged lkl for Arch linux AUR
https://aur.archlinux.org/packages/lkl-linux-git/
and I was now going to package the MinGW cross-compiled version too:
https://aur.archlinux.org/packages/mingw-w64-lkl-linux-git/
This one does however fail during Make test:
[....]
i686-w64-mingw32-ar -rc lib/liblkl.a lib/iomem.o lib/utils.o lib/virtio.o lib/virtio_blk.o lib/fs.o lib/nt-host.o lib/lkl.o
i686-w64-mingw32-gcc -o tests/boot tests/boot.o lib/liblkl.a
lib/liblkl.a(lkl.o): In function `timekeeping_init':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/time/timekeeping.c:1240: undefined reference to `clocksource_default_clock'
lib/liblkl.a(lkl.o): In function `clocksource_done_booting':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/time/clocksource.c:623: undefined reference to `clocksource_default_clock'
lib/liblkl.a(lkl.o): In function `alloc_large_system_hash':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/mm/page_alloc.c:6506: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `mm_release':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/fork.c:892: undefined reference to `sys_futex'
lib/liblkl.a(lkl.o): In function `print_worker_info':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4148: undefined reference to `probe_kernel_read'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4149: undefined reference to `probe_kernel_read'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4150: undefined reference to `probe_kernel_read'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4151: undefined reference to `probe_kernel_read'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4154: undefined reference to `probe_kernel_read'
lib/liblkl.a(lkl.o):/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/workqueue.c:4156: more undefined references to `probe_kernel_read' follow
lib/liblkl.a(lkl.o): In function `register_die_notifier':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/notifier.c:555: undefined reference to `vmalloc_sync_all'
lib/liblkl.a(lkl.o): In function `init_idle':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/core.c:4942: undefined reference to `sched_clock'
lib/liblkl.a(lkl.o): In function `sched_clock_cpu':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/clock.c:406: undefined reference to `sched_clock'
lib/liblkl.a(lkl.o): In function `cpu_clock':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/clock.c:411: undefined reference to `sched_clock'
lib/liblkl.a(lkl.o): In function `local_clock':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/clock.c:416: undefined reference to `sched_clock'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/clock.c:416: undefined reference to `sched_clock'
lib/liblkl.a(lkl.o): In function `div_u64_rem':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `ktime_divns':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/ktime.h:181: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `nsec_low':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/debug.c:56: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `nsec_high':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/debug.c:46: undefined reference to `__div64_32'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/debug.c:43: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `sched_debug_header':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/sched/debug.c:354: undefined reference to `sched_clock'
lib/liblkl.a(lkl.o): In function `print_time':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/printk/printk.c:1043: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `msg_print_ext_header':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/printk/printk.c:534: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `div_u64_rem':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o):/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: more undefined references to `__div64_32' follow
lib/liblkl.a(lkl.o): In function `panic':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/panic.c:101: undefined reference to `bust_spinlocks'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/kernel/panic.c:148: undefined reference to `bust_spinlocks'
lib/liblkl.a(lkl.o): In function `_setup_per_zone_wmarks':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/mm/page_alloc.c:6181: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `_wb_calc_thresh':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/mm/page-writeback.c:739: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `wb_update_write_bandwidth':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/mm/page-writeback.c:1064: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o): In function `div_u64_rem':
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: undefined reference to `__div64_32'
lib/liblkl.a(lkl.o):/home/jens/Devel/Arch/AUR-build/lkl-mingw/src/linux/include/linux/math64.h:66: more undefined references to `__div64_32' follow
collect2: error: ld returned 1 exit status
Makefile:47: recipe for target 'tests/boot' failed
make: *** [tests/boot] Error 1
[....]
Is there a library that I explicitly need to link?
Not a serious issue, but it would be nice --- on Ubuntu here I had to look into the circle.yml file to realize that I needed
bc
ships with pretty much all *nix systems as far as I know and the wine/minigw dependencies seem to be for the sake of a Windows integration test, correct me if I'm wrong.
Then to get the test to run I needed:
Also, it seems a little strange to me to give installation instructions for FreeBSD and Windows but not any Linux distros --- it is a kernel fork, after all.
I'll put together a PR with the info, if you'd like --- I don't know if there is a good reason that it's missing at the moment or what.
Is there a reason for this default? It looks like it causes a hit to performance, and since lkl doesn't make any changes to slub, I can't imagine it would catch many useful bugs.
I played around a bit with cross-compiling to Win64 with mingw-w64 by adding the needed "pe-x86-64" in tools/lkl/Makefile and arch/lkl/Makefile.
"interestingly" it fails in two different ways if I add or don't add
select 64BIT if OUTPUT_FORMAT = "pe-x86-64"
in arch/lkl/Kbuild
Without it, it fails on the compilation check
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
in include/linux/bug.h
With it, it fails on
include/linux/tty.h
Width of "unused" is longer than its type
unused:BITS_PER_LONG - 2
I have tried setting BITS_PER_LONG=32 manually as a KBUILD_CFLAG
(which it should be on Win64)
I am guessing that both of these issues is due to Win64 being LLP64 which means that assumptions in compilation checks etc are not always correct.
The question is just - what would be the advisable approach - go for 64bit and try to solve the incompatibilities or rather go for 32bit and try to solve incompatibilities?
If someone smarter than me is already working on this I will just drop it :)
I was thinking that it might be interesting to pull in some patches from llvmlinux to support building lkl with clang? It would make one less makedepend for FreeBSD and other OSes that default to llvm/clang.
http://git.linuxfoundation.org/?p=llvmlinux.git;a=summary
Since many patches are architecture-specific, they are most likely not needed for lkl so some cherry picking could be done.
To keep lkl "clean" (in order to simplify upstreaming), the clang-supported lkl could be maintained in a parallell branch.
Thoughts?
If you think it is interesting/useful I could try to have a go at it this evening.
I would like to use LKL in an Android app, so I added elf32-littlearm
as a supported POSIX output format in the Makefiles and attempted to build with a standalone arm-linux-androideabi
toolchain, but I get this:
arm-linux-androideabi-gcc -Iinclude -Wall -g -O2 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -fPIC -c -o lib/net.o lib/net.c
In file included from /home/david/Android/toolchains/arm-linux-androideabi-4.9-21/sysroot/usr/include/linux/signal.h:21:0,
from /home/david/Android/toolchains/arm-linux-androideabi-4.9-21/sysroot/usr/include/signal.h:48,
from /home/david/Android/toolchains/arm-linux-androideabi-4.9-21/sysroot/usr/include/sys/select.h:35,
from /home/david/Android/toolchains/arm-linux-androideabi-4.9-21/sysroot/usr/include/unistd.h:34,
from include/lkl/linux/shm.h:6,
from include/lkl/asm/syscalls.h:81,
from include/lkl.h:6,
from include/lkl_host.h:5,
from lib/net.c:5:
include/lkl/asm-generic/signal.h:103:22: error: expected ':', ',', ';', '}' or '__attribute__' before '.' token
__lkl__sighandler_t sa_handler;
^
<builtin>: recipe for target 'lib/net.o' failed
make: *** [lib/net.o] Error 1
I'm not a kernel developer at all, so I don't really know where to go from here.
.... perhaps something to add to the FAQ in the lkl.txt?
DDEKit seems to have some overlapping interests with LKL when it comes to building native drivers for other kernels with a "glue" layer. As far as I know, they implemented L4 kernel and Hurd kernel targets. As far as I know, the only users are the GenodeOS project and Hurd, and both seem to move towards Rump kernels instead. It is very hard to know how active it is or what uses it has.
Are the "glue" implementations in DDEKit for those alternative kernels possible to re-use for LKL?
I need wider support of drivers in LKL.
I changed my arch/lkl/Kconfig to add SCSI, input, USB, TTY and to drop NO_DMA
FIY, the associated usecase is to have a userspace usbip client.
I implemented trivial dma_map_ops, which only trigger a warning when called. (perhaps it would be better to even panic())
This is enough to have mass-storage/serial port/... over usbip working.
The usecase would be to have wide driver support as an Android application. On Android, one can access to /dev/bus/usb/XXX/YYY, but not the kernel functions.
Would it be possible to source drivers/Kconfig? Or is it too much work?
Is it better to activate one section at a time?
LKL pretends to be a nommu architecture, and the nommu generic code BUG()
s on vm_map_ram()
. (As mentioned in #4.)
While building this project I noticed the following weird result. When I run strings liblkl.a | grep lkl_sys | sort -u
I get the following syscalls:
lkl_sys_access
lkl_syscall
lkl_sys_close
lkl_sys_getdents64
lkl_sys_halt
lkl_sys_mkdir
lkl_sys_mknod
lkl_sys_mount
lkl_sys_nanosleep
lkl_sys_open
lkl_sys_read
lkl_sys_rmdir
lkl_sys_umount
lkl_sys_unlink
However, lklfuce.c
refers to a lot of extra lkl_sys_*
functions. One example is lkl_sys_chown
. I ran find -type f|xargs grep lkl_sys_chown
on the whole linux tree that includes my built objects and the only references to this function were in lklfuse.c
, lklfuse.o
and lklfuse
.
How is this linking happening? And why only this specific set of syscalls appears in the output of strings
? I couldn't find anything unique about their definition either.
I see the following when trying to compile:
cd tools/lkl; make -j
scripts/kconfig/conf --defconfig Kconfig
kernel/time/Kconfig:155:warning: range is invalid
fs/sysfs/Kconfig:1:error: recursive dependency detected!
fs/sysfs/Kconfig:1: symbol SYSFS is selected by AT91_ADC
drivers/iio/adc/Kconfig:121: symbol AT91_ADC depends on IIO
drivers/iio/Kconfig:5: symbol IIO is selected by RTC_DRV_HID_SENSOR_TIME
drivers/rtc/Kconfig:1608: symbol RTC_DRV_HID_SENSOR_TIME depends on USB_HID
drivers/hid/usbhid/Kconfig:4: symbol USB_HID depends on USB
drivers/usb/Kconfig:41: symbol USB is selected by MOUSE_APPLETOUCH
drivers/input/mouse/Kconfig:177: symbol MOUSE_APPLETOUCH depends on INPUT
drivers/input/Kconfig:8: symbol INPUT is selected by VT
drivers/tty/Kconfig:12: symbol VT is selected by FB_STI
drivers/video/fbdev/Kconfig:670: symbol FB_STI depends on FB
drivers/video/fbdev/Kconfig:5: symbol FB is selected by DRM_KMS_FB_HELPER
drivers/gpu/drm/Kconfig:34: symbol DRM_KMS_FB_HELPER is selected by DRM_VIRTIO_GPU
drivers/gpu/drm/virtio/Kconfig:1: symbol DRM_VIRTIO_GPU depends on VIRTIO
drivers/virtio/Kconfig:1: symbol VIRTIO is selected by INTEL_MIC_CARD
drivers/misc/mic/Kconfig:57: symbol INTEL_MIC_CARD depends on 64BIT
arch/lkl/Kconfig:35: symbol 64BIT is selected by LKL
arch/lkl/Kconfig:1: symbol LKL depends on AUDITSYSCALL
init/Kconfig:308: symbol AUDITSYSCALL depends on AUDIT
init/Kconfig:296: symbol AUDIT is selected by SECURITY_APPARMOR
security/apparmor/Kconfig:1: symbol SECURITY_APPARMOR depends on SECURITY
security/Kconfig:21: symbol SECURITY depends on SYSFS
Is this harmless, or does it matter?
Client-Server program is not working when both sides are using LKL. But its working when only one side is LKL. Please find the logs for working case (only client side is using LKL here) below.
I have 2 simple program. one is server (it will read the input file and send it to port 9600) and one is client (it will connect to the server by giving the IP as input , read it and print the statistics). in my setup server is running in 172.27.10.29 and client is in 172.27.10.24.
I created the TAP interface (lkl_ptt0) and created a bridge br-lkl. Added TAP interface and my physical interface(eth12) to this bridge.
hadmin@VFSR2:~$ ./tcpfs ccnd.c
End of file
Total bytes sent = {192135}
root@ICSCHELAP0027:/home/hadmin/linux/tools/lkl/bin# LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=172.27.10.2 LKL_HIJACK_NET_NETMASK_LEN=24 ./lkl-hijack.sh ./tcpfc 172.27.10.29
Start time = {16:00:02:765}
Total Bytes received 192135
End time = {16:00:02:792}
root@ICSCHELAP0027:/home/hadmin/linux/tools/lkl/bin#
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
int main(int argc, char** argv)
{
int listenfd = 0;
int connfd = 0;
struct sockaddr_in serv_addr;
char sendBuff[1025];
int numrv;
int totalbyteswritten = 0;
int byteswritten = 0;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(9600);
bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));
if(listen(listenfd, 10) == -1)
{
printf("Failed to listen\n");
return -1;
}
while(1)
{
connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL);
FILE *fp = fopen(argv[1],"rb");
if(fp==NULL)
{
printf("File opern error");
return 1;
}
while(1)
{
unsigned char buff[256]={0};
int nread = fread(buff,1,256,fp);
if(nread > 0)
{
byteswritten = write(connfd, buff, nread);
totalbyteswritten += byteswritten;
// printf("totalbyteswritten so far = {%d}\n", totalbyteswritten);
}
if (nread < 256)
{
if (feof(fp))
printf("End of file\n");
if (ferror(fp))
printf("Error reading\n");
break;
}
}
printf("Total bytes sent = {%d}\n", totalbyteswritten);
totalbyteswritten = 0;
close(connfd);
sleep(1);
}
return 0;
}
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <time.h>
void getlogtime(char *currentTime);
int main(int argc, char** argv)
{
int sockfd = 0;
int bytesReceived = 0;
char recvBuff[256];
memset(recvBuff, '0', sizeof(recvBuff));
struct sockaddr_in serv_addr;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
{
printf("\n Error : Could not create socket \n");
return 1;
}
serv_addr.sin_family = AF_INET;
//serv_addr.sin_port = htons(atoi(argv[2])); // port
serv_addr.sin_port = htons(9600);
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
{
printf("\n inet_pton error occured\n");
return 1;
}
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
{
perror("Error : Connect Failed \n");
return 1;
}
FILE *fp;
char fname[256];
char logtime[100];
int totalBytesRcvd = 0;
getlogtime(logtime);
sprintf(fname, "rcvdfle.%s", logtime);
fp = fopen(fname, "ab");
if(NULL == fp)
{
printf("Error opening file");
return 1;
}
getlogtime(logtime);
printf("Start time = {%s}\n", logtime);
while((bytesReceived = read(sockfd, recvBuff, 256)) > 0)
{
totalBytesRcvd += bytesReceived;
// recvBuff[n] = 0;
fwrite(recvBuff, 1,bytesReceived,fp);
// printf("%s \n", recvBuff);
}
printf("Total Bytes received %d\n",totalBytesRcvd);
getlogtime(logtime);
printf("End time = {%s}\n", logtime);
if(bytesReceived < 0)
{
printf("\n Read Error \n");
}
close(sockfd);
return 0;
}
void getlogtime(char *currentTime)
{
struct timeval curTime;
int milli;
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
gettimeofday(&curTime, NULL);
milli = curTime.tv_usec / 1000;
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%H:%M:%S", timeinfo);
if(currentTime)
sprintf(currentTime, "%s:%d", buffer, milli);
//printf("current time: %s \n", currentTime);
}
hi,
I am interested in testing the ntp protocol and real implementations such as chrony (http://chrony.tuxfamily.org) or ntpd (www.ntp.org) in a simulated environement, more precisely in the ns3 simulator (www.nsnam.org). ns3 makes it possible to run real code thanks to its Direct Code Execution (DCE) extension (https://github.com/direct-code-execution/ns-3-dce).
This issue is a way to assess my understanding as well as checking for possible solutions of what I want to achieve. Hence it's likely Ive misunderstood some parts, hope you will correct me.
So far I found a few testing projects:
Now there seems to be 2 modes for clocks:
The scenario I would like to achieve is:
ns3 is a discrete event simulator, ie. it is tickless: if you schedule an event at t0=5sec and a second one at t1=100s, then ns3 will just execute the first event, set the integer representing time to t1=100 and execute the event.
So far in ns3, the nodes share the time value and are all perfectly synchronized, I want to introduce per node clocks.
My problem is step 4:
Sorry if it sounds confused or for mentioning you if you are not interested. I think this LKL project or libOS can help in what I want to achieve. I am willing to contribute to LKL if that helps but I would need directions.
Matt
It would be nice if a stack trace can be printed in WARN_UNLESS so it's easier to identify the code path that's triggering that warning.
Can we reuse dump_stack in kernel code?
raised during #90.
at lease at the moment, we have the following configurable environmental variable.
char *tap = getenv("LKL_HIJACK_NET_TAP");
char *mtu_str = getenv("LKL_HIJACK_NET_MTU");
char *ip = getenv("LKL_HIJACK_NET_IP");
char *mac_str = getenv("LKL_HIJACK_NET_MAC");
char *netmask_len = getenv("LKL_HIJACK_NET_NETMASK_LEN");
char *gateway = getenv("LKL_HIJACK_NET_GATEWAY");
char *debug = getenv("LKL_HIJACK_DEBUG");
and with #90,
char *mount = getenv("LKL_HIJACK_MOUNT");
and with #67,
char *iftype = getenv("LKL_HIJACK_NET_IFTYPE");
char *ifname = getenv("LKL_HIJACK_NET_IFNAME");
stress-ng --class filesystem --all 0
stress-ng --class filesystem --seq 0 -v -t 60
Looks like a race condition between lkl init and fuse calls:
~/src/linux/tools/lkl$ addr2line -ie ./lklfuse
0x0000000000404d4d
/home/tavi/src/linux/arch/lkl/kernel/syscalls.c:112
Dump: https://clbin.com/6CS35
Toolchain: x86_64-unknown-linux-gnu
Command: cd tools/lkl; make
PR #9 started to report various errors in circle ci test. what we can do next is:
e.g.,
https://circleci.com/gh/lkl/linux/38#tests
Syscall param preadv(vector) points to uninitialised byte(s)
0x534E6D2: preadv (preadv.c:47)
0x403BE4: fd_do_rw (posix-host.c:185)
0x40351F: virtio_process_avail_one (virtio.c:127)
0x40351F: virtio_process_avail (virtio.c:137)
0x40351F: virtio_write (virtio.c:281)
0x672FDE: __raw_writel (io.h:80)
0x672FDE: writel (io.h:163)
0x672FDE: vm_notify (virtio_mmio.c:287)
0x671C94: virtqueue_notify (virtio_ring.c:396)
0x6813BA: virtio_queue_rq (virtio_blk.c:230)
0x643005: __blk_mq_run_hw_queue (blk-mq.c:794)
0x642C54: blk_mq_run_hw_queue (blk-mq.c:884)
0x6435AE: blk_sq_make_request (blk-mq.c:1398)
0x638E6F: generic_make_request (blk-core.c:1969)
0x638F37: submit_bio (blk-core.c:2021)
0x48E577: submit_bh_wbc.isra.38 (buffer.c:3065)
anybody volunteer to tackle those is really appreciated !
Is there a target for boot time of defconfig's kernel?
The kernel can boot in 16ms on my computer by disabling btrfs .
Enabling btrfs make it go to >500ms, because of RAID6 and XOR benchmarking
I think that defconfig should be as fast as possible.
I understand that cptofs/fs2tar are currently main examples of LKL so the choice is not easy.
I see three options:
For XOR benchmark, we can set XOR_SELECT_TEMPLATE in asm/xor.h
Any recommendation?
Dear all,
Is there a patched source tarball or git branch somewhere available where the "Weak NT externals" patch has been applied already in order to build lkl with MinGW?
I always get errors when I try to apply the patches (perhaps formatting issues from copying from browser, perhaps wrong target binutils source....)
Hi everyone,
I have a question regarding the correct usage of the LKL system call API. I ran into a problem when running an application linked against musl-libc on top of lkl on my x86_64 system. Using the stat
system call (via the musl libc wrapper function) "fails", because there is a mismatch between the definition of struct stat
used in my application code and the one used by lkl. When the results are copied from an instance of struct kstat
into the user-provided buffer in the function cp_new_stat
https://github.com/lkl/linux/blob/master/fs/stat.c#L229
it uses the following definition of struct stat
:
https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/stat.h#L23
However, musl reuses the x86_64-specific definition of struct stat
:
http://git.musl-libc.org/cgit/musl/tree/arch/x86_64/bits/stat.h, derived from:
https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/stat.h#L82
Now, the problem is that both definitions differ in the order and types of their fields (see st_mode
and st_nlink
) which means that dereferencing those fields in my application code will return nonsensical values.
Can anyone tell me what the right way would be to deal with an issue like this?
Thanks!
Example:
make -C tests valgrind
make[1]: Entering directory `~/lkl-linux-master/tools/lkl/tests'
VALGRIND_CMD="valgrind --suppressions=valgrind.supp --leak-check=full --show-leak-kinds=all" ./boot.sh -t ext4
20480+0 records in
20480+0 records out
20971520 bytes (21 MB) copied, 0.0601454 s, 349 MB/s
mke2fs 1.42.9 (4-Feb-2014)
==51041== Memcheck, a memory error detector
==51041== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==51041== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==51041== Command: ./boot -d /tmp/tmp.WW4HVFKxn7 -t ext4 -n lkl_boot
==51041==
disk_add passed [3 0]
netdev_add passed [0 4 0]
==51041== Thread 6:
...<snip>...
==51041==
getpid passed [1]
umask passed [22 777]
creat passed [0]
close passed [0]
failopen passed [-2]
open passed [0]
write passed [5]
lseek passed [0 ]
read passed [5 test]
fstat passed [0 100721 5]
mkdir passed [0]
stat passed [0 40721]
nanosleep **failed** [97188672]
mount passed [0]
chdir passed [0]
opendir passed [1]
getdents64 passed [1 lost+found .. . ]
umount passed [0 0 0]
lo_ifup passed [0]
netdev_ifup passed [0 2]
==51041==
==51041== HEAP SUMMARY:
Presumably because there's an upper bound on the time that passes while the test thread sleeps (under test_nanosleep
in boot.c):
clock_gettime(CLOCK_MONOTONIC, &start);
ret = lkl_sys_nanosleep(&ts, NULL);
clock_gettime(CLOCK_MONOTONIC, &stop);
delta = 1e9*(stop.tv_sec - start.tv_sec) +
(stop.tv_nsec - start.tv_nsec);
snprintf(str, len, "%ld", delta);
if (ret == 0 && delta > sleep_ns * 0.9 && delta < sleep_ns * 1.1)
return 1;
return 0;
I'm not sure how important you consider this part of the test to be --- is there a very compelling reason to check that delta < sleep_ns * 1.1
, or can that line be changed to "if (ret == 0 && delta > sleep_ns)" instead?
Is there a good usecase for this? It seems to me like giving a host fd to LKL is going to be programmer error 99.9% of the time, and passing it along silently to the host will generally hide the error until someone tries to mix the two together down the line. It would be nice to have an assertion fire off and fail loudly to make it clear that something has gone wrong.
Is the pass-to-host behavior needed for syscalls that touch STDOUT or something like that? If not, the hijack code could be cut simplified a lot. If it is needed for something, it would be nice at least print a warning or something.
Can this part of the library be made stricter? Or does it need to be the way it is?
In my attempt to fuzz the kernel X.509 API (#58), I've ran into an interesting bug. I'm using the following patch:
diff --git a/arch/lkl/Makefile b/arch/lkl/Makefile
index cd4ae2a..b3e62dc 100644
--- a/arch/lkl/Makefile
+++ b/arch/lkl/Makefile
@@ -22,7 +22,7 @@ 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
+ lkl_get_free_irq lkl_put_irq x509_cert_parse
core-y += arch/lkl/kernel/
diff --git a/tools/lkl/Makefile b/tools/lkl/Makefile
index e3bd8b2..78148a2 100644
--- a/tools/lkl/Makefile
+++ b/tools/lkl/Makefile
@@ -61,6 +61,14 @@ lib/liblkl-hijack.so: $(hijack_objs) Makefile lib/liblkl.so
lib/lkl.o:
$(MAKE) -C ../.. ARCH=lkl defconfig
+ echo "CONFIG_ASN1=y" >> ../../.config
+ echo "CONFIG_ASYMMETRIC_KEY_TYPE=y" >> ../../.config
+ echo "CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=y" >> ../../.config
+ echo "CONFIG_PUBLIC_KEY_ALGO_RSA=y" >> ../../.config
+ echo "CONFIG_X509_CERTIFICATE_PARSER=y" >> ../../.config
+ echo "CONFIG_PKCS7_MESSAGE_PARSER=n" >> ../../.config
+ echo "CONFIG_KEYS=y" >> ../../.config
+ $(MAKE) -C ../.. ARCH=lkl silentoldconfig
$(MAKE) -C ../.. ARCH=lkl $(KOPT) install INSTALL_PATH=$(PWD)
%: %.o
And it all compiles ok, but when I try to load liblkl.so
, no bueno:
vagrant@vagrant-ubuntu-trusty-64:/vagrant/lkl-linux/tools/lkl$ python -c "import ctypes; ctypes.CDLL('./lib/liblkl.so')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./lib/liblkl.so: undefined symbol: timer_create
Here's the complete build log:
build.log.txt
On non-64bit platforms, passing 64bit parameters will lead to parameter corruptions.
long params[6] = { MAP(x, __SC_LONG, __VA_ARGS) }; (That code on 32bit platform will likely pass garbage to the corresponding syscall routine that ingest long long parameter, while the higher part of the value is very likely to be dropped.)
I managed to solve the problem ngkaho1234@7b655e4 , albeit the implementation doesn't look neat and tidy.
It is due to _FILE_OFFSET_BITS=64 not being set when building liblkl.
My temporary solution is to add -D_FILE_OFFSET_BITS=64 to CFLAGS.
The work seems to have last for a few years. So I wonder if there is someone already using it in some real-world products. If there's any, we might want to create a wiki page listing them?
I checked out 2b6ea3c and did
cd tools/lkl
make
and I'm seeing warnings like this
CALL scripts/checksyscalls.sh
<stdin>:257:2: warning: #warning syscall setuid not implemented [-Wcpp]
<stdin>:311:2: warning: #warning syscall dup not implemented [-Wcpp]
<stdin>:317:2: warning: #warning syscall times not implemented [-Wcpp]
<stdin>:326:2: warning: #warning syscall setgid not implemented [-Wcpp]
<stdin>:335:2: warning: #warning syscall geteuid not implemented [-Wcpp]
<stdin>:338:2: warning: #warning syscall getegid not implemented [-Wcpp]
<stdin>:341:2: warning: #warning syscall acct not implemented [-Wcpp]
<stdin>:353:2: warning: #warning syscall fcntl not implemented [-Wcpp]
<stdin>:359:2: warning: #warning syscall setpgid not implemented [-Wcpp]
<stdin>:380:2: warning: #warning syscall getppid not implemented [-Wcpp]
<stdin>:386:2: warning: #warning syscall setsid not implemented [-Wcpp]
<stdin>:398:2: warning: #warning syscall setreuid not implemented [-Wcpp]
<stdin>:401:2: warning: #warning syscall setregid not implemented [-Wcpp]
<stdin>:410:2: warning: #warning syscall sethostname not implemented [-Wcpp]
<stdin>:413:2: warning: #warning syscall setrlimit not implemented [-Wcpp]
<stdin>:416:2: warning: #warning syscall getrlimit not implemented [-Wcpp]
<stdin>:419:2: warning: #warning syscall getrusage not implemented [-Wcpp]
<stdin>:422:2: warning: #warning syscall gettimeofday not implemented [-Wcpp]
<stdin>:425:2: warning: #warning syscall settimeofday not implemented [-Wcpp]
<stdin>:428:2: warning: #warning syscall getgroups not implemented [-Wcpp]
<stdin>:431:2: warning: #warning syscall setgroups not implemented [-Wcpp]
<stdin>:467:2: warning: #warning syscall ftruncate not implemented [-Wcpp]
...
Are they really not implemented yet, or the warnings are just spurious?
when you added two virtio devices, in a single program like below,
bs.fd = open("disk.img", O_RDWR);
lkl_disk_add(bs);
nd.fd = tap_alloc("tap0");
lkl_netdev_add(nd, NULL);
2nd device is failed to register.
[ 0.704000] virtio-mmio: Registering device virtio-mmio.0 at 0x27e5010-0x27e5133, IRQ 1.
[ 0.704000] virtio-mmio: Registering device virtio-mmio.1 at 0x27e5120-0x27e5243, IRQ 2.
[ 0.704000] platform virtio-mmio.1: failed to claim resource 0
[ 0.704000] device: `292@0x27e5120:2' invalid for parameter `virtio_mmio.device'
vagrant@vagrant-ubuntu-trusty-64:/vagrant/lkl-linux/tools/lkl$ make
make: Warning: File `Makefile' has modification time 1.1e+03 s in the future
gcc -Iinclude -Wall -g -O2 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fno-strict-aliasing -fPIC -D_FILE_OFFSET_BITS=64 -c -o lib/virtio.o lib/virtio.c
lib/virtio.c: In function ‘virtio_deliver_irq’:
lib/virtio.c:65:2: error: too few arguments to function ‘lkl_trigger_irq’
lkl_trigger_irq(dev->irq);
^
In file included from include/lkl/asm/syscalls.h:108:0,
from include/lkl.h:6,
from include/lkl_host.h:5,
from lib/virtio.c:3:
include/lkl/asm/irq.h:14:5: note: declared here
int lkl_trigger_irq(int irq, void *data);
^
make: *** [lib/virtio.o] Error 1
Is it possible to support loadable kernel modules in LKL and, if so, what sort of changes would have to be made to get that working? I would like to create a USB host controller driver that delegates to the host system's USB API and it would be great if I could test it without rebuilding and redeploying my entire application every time.
Opening this up to track the issue that came up in #126 --- it seems that sometimes on Windows there is a deadlock during test_syscall_thread
in tools/lkl/tests/boot.c
.
is there any plans/news to create virtio-net so that networking code with lkl can send/recv packets from outside ?
if not, i'm going to bite a bullet (oops, to have a fun :)).
I'm running netserver
and netperf
(version 2.7.0, built from the source on netperf's site) as follows:
## Server
➜ lkl git:(passive-open) ✗ sudo LKL_HIJACK_NET_TAP=eth0 LKL_HIJACK_NET_IP=192.168.13.2 LKL_HIJACK_NET_NETMASK_LEN=1 LKL_HIJACK_DEBUG=1 taskset -c 10 bin/lkl-hijack.sh netserver -L 192.168.13.2 -d -v 99 -D -f
## Client
➜ lkl git:(passive-open) ✗ netperf -H 192.168.13.2 -t TCP_STREAM -l 1
The test runs fine for a while, but it eventually says:
[ 3625.088000] virtio_net virtio0: input.0:id 24 is not a head!
and hangs forever. tcpdump
on the interface shows that packets go back and forth normally until LKL stops ack-ing part way through, the sender retries a few times, then starts sending out ARP requests to find out where the host has gone with no response. Looking at it under gdb
shows that the netserver
thread is blocked on a recv
call, and LKL continues to spin up and kill worker threads periodically. strace
shows that it continues polling the fd associated with the TAP device. TCP_RR
tests with the same options work fine.
I had to make some changes to the host's routing table to get it to force it not to go through lo
, the relevant info is:
➜ lkl git:(passive-open) ✗ ip addr
2: em1: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
....
inet 172.x.y.z/q brd ??.??.??.?? scope global em1
valid_lft forever preferred_lft forever
861: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 500
link/ether f2:e4:2a:59:2b:03 brd ff:ff:ff:ff:ff:ff
inet 192.168.13.1/24 scope global eth0
valid_lft forever preferred_lft forever
...
➜ lkl git:(passive-open) ✗ ip route
...
192.168.13.1 dev eth0 scope link src 172.x.y.z
192.168.13.2 dev eth0 scope link src 172.x.y.z
What might be going on here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.