[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] wireshark capture of failed download from mirage-www on ARM



On 21 Jul 2014, at 16:10, Thomas Leonard <talex5@xxxxxxxxx> wrote:

> What are the rules about alignment for cstructs?
> 
> Allocating the buffer like this works:
> 
>  let data = Io_page.get 1 |> Io_page.to_cstruct
>  let () = Cstruct.blit_from_string (Buffer.contents buffer) 0 data 0
> (Buffer.length buffer)
> 
> But using Cstruct.of_string doesn't. It does look like Netif assumes
> the structs are page aligned. e.g.
> 
>  if page.Cstruct.off + len > page_size then begin
>    (* netback rejects packets that cross page boundaries *)
>    let msg =
>      Printf.sprintf "Invalid page: offset=%d, length=%d"
> page.Cstruct.off len in
>    print_endline msg;
>    Lwt.fail (Failure msg)
>  end else

Argh, this is exactly the problem.  Netif requires page aligned buffers
(in theory, sub-page grants are possible, but ill-advised for performance
reasons).

Cstruct.of_string calls Cstruct.create, which calls Bigarray.Array1.create
which isn't page-aligned.  It does need to go through Io_page to ensure it's
page-aligned.

We don't protect this distinction using phantom types, and it's bitten us
several times now through these hard-to-spot dynamic failures :-/

Making Cstruct's always page aligned is too expensive for the 'casual'
small Cstructs (as seen in OCaml TLS for example), so ensure your buffer
originates from Io_page is the best bet for now.  An issue on how to 
ensure this is checked statically would be good to have (but involve
a fair bit of mechanical code motion).

-anil

_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.