lkl / linux

Linux kernel source tree
https://lkl.github.io/
Other
814 stars 138 forks source link

Does LKL support non-blocking sockets? #360

Open speedingdaemon opened 7 years ago

speedingdaemon commented 7 years ago

Trying to port my code: sd = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); to: sd = lkl_sys_socket(PF_INET, LKL_SOCK_STREAM | LKL_SOCK_NONBLOCK, 0);

But I don't see LKL_SOCK_NONBLOCK being defined anywhere. Also, has anyone implemented polling using LKL?

tavip commented 7 years ago

Yes, polling is supported and it has been tested with libhijack, via fcntl.

I'll push a patch to define LKL_SOCK_NONBLOCK later but in the meanwhile I think you can use LKL_O_NONBLOCK.

liuyuan10 commented 7 years ago

Yes. I've used epoll with LKL.

You can just use SOCKNONBLOCK if LKL ones are not defined.

On Fri, Jul 14, 2017 at 12:25 PM, speedingdaemon notifications@github.com wrote:

Trying to port my code: sd = socket(PF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); to: sd = lkl_sys_socket(PF_INET, LKL_SOCK_STREAM | LKL_SOCK_NONBLOCK, 0);

But I don't see LKL_SOCK_NONBLOCK being defined anywhere. Also, has anyone implemented polling using LKL?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lkl/linux/issues/360, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVfUvO7S9gPOennH_m7lmc6gbcIJoZHks5sN8CagaJpZM4OYpID .

speedingdaemon commented 7 years ago

Ok. The reason I asked was because I have a polling server code that works without any issues if I don't use LKL APIs. But when I replaced with LKL APIs, I am getting following error (printed in my application code) with SSL_accept: [ERROR]: FATAL SSL_retcode for OPERATION=SSL_ACCEPT Retcode=5 Error:error:00000000:lib(0):func(0):reason(0)

Here, Retcode=5 corresponds to SSL_ERROR_SYSCALL in OpenSSL.

speedingdaemon commented 7 years ago

This is the place (in openssl/ssl/statem/statem.c) that is causing state_machine() to return -1 for SSL_accept call: while (st->state != MSG_FLOW_FINISHED) { if (st->state == MSG_FLOW_READING) { ssret = read_state_machine(s); if (ssret == SUB_STATE_FINISHED) { st->state = MSG_FLOW_WRITING; init_write_state_machine(s); } else { / NBIO or error / <<<<<<<<===== this one goto end; } This is the bt:

0 state_machine (s=0x56391929fff0, server=1) at ssl/statem/statem.c:398

1 0x00007f4a0b934734 in ossl_statem_accept (s=0x56391929fff0) at ssl/statem/statem.c:234

2 0x00007f4a0b92bd27 in ssl_do_handshake_intern (vargs=0x56391929dbb0) at ssl/ssl_lib.c:3303

3 0x00007f4a0b4b57b0 in async_start_func () at crypto/async/async.c:154

4 0x00007f4a0ae81a90 in ?? () from /lib/x86_64-linux-gnu/libc.so.6

Any clue on what am I missing?

speedingdaemon commented 7 years ago

I think I found the offending code. But I am not sure why it causes things to break. WIll really help if someone can explain.

This was my working non-lkl code: client = accept(gl_server_fd, NULL, NULL); ret = fcntl(client, F_SETFL, fcntl(client, F_GETFL, 0) | O_NONBLOCK);

The following LKL code didn't let SSL work: client = lkl_sys_accept(gl_server_fd, NULL, NULL); ret = lkl_sys_fcntl(client, LKL_F_SETFL, lkl_sys_fcntl(client, LKL_F_GETFL, 0) | LKL_O_NONBLOCK);

Removing the call to lkl_sys_fcntl() got things working for me. But I dont think that is what I want because my FD won't be NONBLOCKING anymore otherwise.

Can someone please help me understand what might have happened inside LKL that doesn't seem to like call to lkl_sys_fcntl()?

speedingdaemon commented 7 years ago

Any clues?

speedingdaemon commented 7 years ago

@tavip

tavip commented 7 years ago

Hmm, no idea. Can yoy reproduce the issue without openssl, with a simple server?