|
[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 22 July 2014 04:00, Anil Madhavapeddy <anil@xxxxxxxxxx> wrote:
> 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).
I notice that FLOW explicitly states that the buffer need not be page-aligned:
module type FLOW = sig
type buffer
(** Abstract type for a memory buffer that may not be page aligned. *)
val write : flow -> buffer -> [`Ok of unit | `Eof | `Error of error ] io
Also, it can fail even if it is aligned:
S.TCPV4.write flow (Io_page.get 10 |> Io_page.to_cstruct)
gives
RX exn Failure("Invalid page: offset=2920, length=1460")
(presumably because splitting the pages into TCP-packet-sized chunks
loses the alignment)
--
Dr Thomas Leonard http://0install.net/
GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1
GPG: DA98 25AE CAD0 8975 7CDA BD8E 0713 3F96 CA74 D8BA
_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |