xen: add support for skipping the current instruction
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 17 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | x86: add support for computing the instruction lengthxen/ xen/ xen/ +6 more | +2529 | 9 replies | |
| 2/3 | x86/hvm: implement hvm_get_insn_length()xen/ | +45 | 0 replies | |
| 3/3 | xen/tools: script for automatically adjusting the coding style to xen stylexen/ | +77 | 5 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] xen: add support for skipping the current instruction
Hi,
Răzvan Cojocaru has posted a patch in July that added support for computing the length of the instruction that generated the VMEXIT:
http://lists.xen.org/archives/html/xen-devel/2014-07/msg00314.html
which he then split into two in order to give himself more time to think about Andrew's proposal to extend the existent x86 emulator. I offered to take that off his hands as he was already working to get several patches in.
The initial code was an almost verbatim copy from Linux, with a very small change to make it compile within xen (replaced 'asm/string.h' with 'xen/string.h').
I spent some time to determine what the code save would be if we were to make use of existent xen functionality and my first impression is that the increase in complexity of an already very complex machinery (caused by both the nature of the architecture and by the design of the emulator itself) would not make it worthwhile.
The starting point would be x86_emulate() which uses a carefully coded switch() to walk through the opcode groups, but it only covers a subset of those and, obviously, expects one to add not just instruction length calculation (ie. next eip/rip) but also _actual_ emulation to which I don't think anyone can commit given the architecture complexity (think MMX, SSEn, AVXn etc). The opportunity for bugs makes this task rather prohibitive.
Masami Hiramatsu, the author of the Linux code, most likely came to the same realization and used a rather simple approach: created x86-opcode-map.txt in which he simply lists the opcode classes in a fairly human readable way. Then he uses an awk script to generate the core of the machinery to which he added a couple of helper functions. I decided to keep this part and see if I can replace some of the helpers, but aside insn_fetch_bytes() which relies on previous calculations made in x86_emulate(), I wasn't able to identify any other code-reuse opportunities. Also, I don't yet have the courage to shuffle code around in x86_emulate.c. :-)
In conclusion, I would opt to bring Masami's code in with very little changes possible (other than coding style which can be handled by a script) so that future updates can be easily ported to xen.
What follows are three patches:
1. adds Masami's et al code (insn_get_length());
2. adds a user in emulate.c;
3. a clang-format script that can be used to do the bulk of the coding style work on the imported files (should someone else other than me were to do it).
The motivation behind the 'instruction skipping' idea is to allow memory introspection technologies to instruct Xen to jump over instructions that reside in memory areas of the guest that are marked as NX in EPT (eg. heap/stack of user processes). In such situations, maintaining the vCPU register state is not needed and, as a bonus, expedites the termination of the in-guest process that attempted to execute the code.
Thanks,
Signature · 6 lines
Mihai Donțu _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel