Solo5 / solo5

A sandboxed execution environment for unikernels
ISC License
883 stars 136 forks source link

Xen console overload #537

Closed palainp closed 1 year ago

palainp commented 1 year ago

Hi, this issue is related to https://github.com/mirage/qubes-mirage-firewall/issues/166. With the following unikernel (config.ml is the same as mirage-skeleton/tutorial/hello/config.ml):

open Lwt.Infix

module Hello (Time : Mirage_time.S) = struct
  let start _time =
    let cs = Cstruct.create 441 in

    Logs.info (fun f -> f "log: %a" Cstruct.hexdump_pp cs);
    Time.sleep_ns (Duration.of_sec 2) >>= fun () ->
    Lwt.return_unit
end

The unikernel leads to an infinite loop with Qubes 4.1 up to date. If I change the Cstruct size to 440, all is fine. With spt it works fine as well so this is probably related to the Xen part of solo5.

palainp commented 1 year ago

Reading console.c I wonder if the "wait for xen to consume data" loop should update the cons position in the if block (like at l106). It's used here: https://github.com/Solo5/solo5/blob/17312abe47a18d145594b1bce454f7d707de8991/bindings/xen/console.c#L122 ?

palainp commented 1 year ago

In fact it wasn't. The infinite loop issue was caused by a loop condition that never comes to false. The PR https://github.com/Solo5/solo5/pull/538 fixes the test unikernel but it still remains an issue with log indentation:

Solo5: Xen console: port 0x2, ring @0x00000000FEFFF000
            |      ___|
  __|  _ \  |  _ \ __ \
\__ \ (   | | (   |  ) |
____/\___/ _|\___/____/
Solo5: Bindings version v0.7.1-62-g71139c2378
Solo5: Memory map: 32 MB addressable:
Solo5:   reserved @ (0x0 - 0xfffff)
Solo5:       text @ (0x100000 - 0x1fffff)
Solo5:     rodata @ (0x200000 - 0x23bfff)
Solo5:       data @ (0x23c000 - 0x30cfff)
Solo5:       heap >= 0x30d000 < stack < 0x2000000
2022-12-05 09:08:55 -00:00: INF [application] log: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 002022-12-05 09:08:55 -00:00: INF [application] log: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
                       00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
...
palainp commented 1 year ago

The indentation was bad as the starting position for reading bytes to be written on the console wasn't updated. I added a commit to the PR which solve that.