x86_emulate: fix wrap around handling for repeated string instructions
authorJan Beulich <jbeulich@suse.com>
Mon, 23 Sep 2013 07:52:29 +0000 (09:52 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 23 Sep 2013 07:52:29 +0000 (09:52 +0200)
commita2e2df452e9cc80844c5de9301862a6285bd30c1
tree7f7ebf5437f97cffe28eba82d0675520feae397b
parent6c1bfef44580d73943bd9453167e5614db13927f
x86_emulate: fix wrap around handling for repeated string instructions

For one, repeat count clipping for MOVS must be done taking into
consideration both source and destination addresses.

And then we should allow a wrap on the final iteration only if either
the wrap is a precise one (i.e. the access itself doesn't wrap, just
the resulting index register value would) or if there is just one
iteration. In all other cases we should do a bulk operation first
without hitting the wrap, and then issue an individual iteration. If
we don't do it that way,
- the last iteration not completing successfully will cause the whole
  operation to fail (i.e. registers not get updated to the failure
  point)
- hvmemul_virtual_to_linear() may needlessly enforce non-repeated
  operation

Additionally with the prior implementation there was a case
(df=1, ea=~0, reps=~0, bytes_per_rep=1) where we'd end up passing zero
reps back to the caller, yet various places assume that there's at
least on iteration.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/arch/x86/x86_emulate/x86_emulate.c