You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some runtimes there is the option of placing the linear memory at absolute zero in the address space. This can help on the ARM in particular as it frees up more addressing modes for use, but it also frees up a register for the linear memory base on ARM and x64 (tested on Odin). Some systems already have the bottom pages reserved for security purposes, so the low addresses could not be used with good performance (but perhaps emulated in a signal handler). If a start-of-usable-memory could be passed to a module then it could avoid allocating in this low region.
This might also be useful with an option to protect low pages (which was noted as a developer option elsewhere). Even when the linear memory is not placed at absolute zero, when this developer option is enabled the start-of-usable-memory parameter could advise the application to avoid the low protected pages, and the page size will vary between systems so the start might want to be a parameter and would be more general than a simple flag indicating that the low page is protected.
Zero-based heaps is definitely an interesting optimization, but probably not something we want to provision for in the MVP. It's also possible that, with multi-process future feature (where the basic idea is letting wasm ask for a fresh process and avoiding all the sync call semantics that make this hard in general), that we wouldn't even need to reserve the low pages and so no explicit spec provision would be necessary. So perhaps you could file a PR to add a bullet to FutureFeatures.md#multiprocess-support pointing out that it enables this optimization more cleanly. Also, with separate processes, you'd avoid the "there can be only one" pigeonhole problem.
I'm not sure I understand what the concrete proposal is. NaCl's sandbox uses this trick extensively, but I'd like to understand what you're proposing that wasm do concretely.
What I proposed in #306 would also provide this functionality. It's proposing that the WASM instance needs to go through the runtime to allocate pages from its address-space. In this case, you could make the runtime only allocate from pages above a certain address.
@JSStats I see, makes sense. In that case, I think that this feature should be opt-in and low addresses should fault. Otherwise, we'll have to simulate the low pages with signal handlers which is both unnecessary complexity and a hidden performance cliff for users. With opt-in + faulting, though, this gives applications the desired low-memory fault (and perhaps we can primarily pitch the feature as such; the zero-based optimization is just a perk on some platforms). While promising, I think this feature doesn't belong in the MVP; now I'm thinking this belongs as in the finger-grained control over memory bucket.
IIUC your proposal is akin to feature detection in that a developer can query for lowest_addressable_memory, and the wasm runtime would provide a value (potentially 0)?
I see the rationale, but am wondering what happens if a developer addresses below this value?
Our orientation so far had been to let the user protect the lower pages as they wished, because a wasm module sees "addresses" (really: heap offset) that aren't actually the process' virtual address. Your proposal assumes that we allow zero-mapping (i.e. wasm heap offset == virtual address), and different kernels forbid us from controlling the lower pages entirely.
I'd like a proposal on this topic to also address security concerns: this gives knowledge to an attacker that they wouldn't otherwise have. It's workable (NaCl does it) but needs to be designed properly.
Is the 'security concern' that an attacker would have a good clue that the linear memory is located at zero in the address space and could depend on this in conjunction with other security issues?
Correct, it gives an attacker a lot of information that can be combined with ASLR leaks / non-PIC code / fixed-mapped code (e.g. kernel helpers). It's not insurmountable, but it's something that a design has to work through.
@JSStats , can you elaborate more on the experiment and the results ? Do we know where the improvement in ARM is coming from (use of faster addressing modes?) ? And why IA is not benefiting as much ?
I see ~20% code reduction, which I am assuming is the cause of the speedup (lower ICache and/or ITLB misses?), unless there is some ARMv7 uArch detail that favors simpler addressing forms.
Are the IA numbers for Core or Atom ? Atom has smaller ICache, and if we are reducing register pressure and saving some register spills/fills, you might see higher gains.
Activity
lukewagner commentedon Sep 8, 2015
Zero-based heaps is definitely an interesting optimization, but probably not something we want to provision for in the MVP. It's also possible that, with multi-process future feature (where the basic idea is letting wasm ask for a fresh process and avoiding all the sync call semantics that make this hard in general), that we wouldn't even need to reserve the low pages and so no explicit spec provision would be necessary. So perhaps you could file a PR to add a bullet to FutureFeatures.md#multiprocess-support pointing out that it enables this optimization more cleanly. Also, with separate processes, you'd avoid the "there can be only one" pigeonhole problem.
jfbastien commentedon Sep 8, 2015
I'm not sure I understand what the concrete proposal is. NaCl's sandbox uses this trick extensively, but I'd like to understand what you're proposing that wasm do concretely.
AndrewScheidecker commentedon Sep 9, 2015
What I proposed in #306 would also provide this functionality. It's proposing that the WASM instance needs to go through the runtime to allocate pages from its address-space. In this case, you could make the runtime only allocate from pages above a certain address.
lukewagner commentedon Sep 9, 2015
@JSStats I see, makes sense. In that case, I think that this feature should be opt-in and low addresses should fault. Otherwise, we'll have to simulate the low pages with signal handlers which is both unnecessary complexity and a hidden performance cliff for users. With opt-in + faulting, though, this gives applications the desired low-memory fault (and perhaps we can primarily pitch the feature as such; the zero-based optimization is just a perk on some platforms). While promising, I think this feature doesn't belong in the MVP; now I'm thinking this belongs as in the finger-grained control over memory bucket.
jfbastien commentedon Sep 9, 2015
IIUC your proposal is akin to feature detection in that a developer can query for
lowest_addressable_memory, and the wasm runtime would provide a value (potentially0)?I see the rationale, but am wondering what happens if a developer addresses below this value?
Our orientation so far had been to let the user protect the lower pages as they wished, because a wasm module sees "addresses" (really: heap offset) that aren't actually the process' virtual address. Your proposal assumes that we allow zero-mapping (i.e. wasm heap offset == virtual address), and different kernels forbid us from controlling the lower pages entirely.
I'd like a proposal on this topic to also address security concerns: this gives knowledge to an attacker that they wouldn't otherwise have. It's workable (NaCl does it) but needs to be designed properly.
jfbastien commentedon Sep 10, 2015
Correct, it gives an attacker a lot of information that can be combined with ASLR leaks / non-PIC code / fixed-mapped code (e.g. kernel helpers). It's not insurmountable, but it's something that a design has to work through.
nmostafa commentedon Oct 8, 2015
@JSStats , can you elaborate more on the experiment and the results ? Do we know where the improvement in ARM is coming from (use of faster addressing modes?) ? And why IA is not benefiting as much ?
nmostafa commentedon Oct 9, 2015
I see ~20% code reduction, which I am assuming is the cause of the speedup (lower ICache and/or ITLB misses?), unless there is some ARMv7 uArch detail that favors simpler addressing forms.
Are the IA numbers for Core or Atom ? Atom has smaller ICache, and if we are reducing register pressure and saving some register spills/fills, you might see higher gains.