x86/HVM: use single (atomic) MOV for aligned emulated writes
PATCH 1/1 x86/HVM: use single (atomic) MOV for aligned emulated writes
Using memcpy() may result in multiple individual byte accesses (dependening how memcpy() is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back to memcpy() only for accesses not 2, 4, or 8 bytes in size.
---
TBD: Besides it still being open whether the linear_write() path also
needs playing with), a question also continues to be whether we'd want to extend this to reads as well. linear_{read,write}() currently don't use hvmemul_map_linear_addr(), i.e. in both cases I'd need to also fiddle with __hvm_copy() (perhaps by making the construct below a helper function).
xen/arch/x86/hvm/emulate.c +8 -1
@@ -1324,7 +1324,14 @@ static int hvmemul_write(if ( !mapping )return linear_write (addr, bytes, p_data, pfec, hvmemul_ctxt); -memcpy (mapping, p_data, bytes); +/* Where possible use single (and hence generally atomic) MOV insns. */ +switch ( bytes ) + { +case 2 :write_u16_atomic (mapping, *(uint16_t *)p_data);break ; +case 4 :write_u32_atomic (mapping, *(uint32_t *)p_data);break ; +case 8 :write_u64_atomic (mapping, *(uint64_t *)p_data);break ; +default :memcpy (mapping, p_data, bytes);break ; + }hvmemul_unmap_linear_addr (mapping, addr, bytes, hvmemul_ctxt);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
[Xen-devel] Ping: [PATCH] x86/HVM: use single (atomic) MOV for aligned emulated writes
Quoted 25 lines · Jan Beulich
Using
memcpy()may result in multiple individual byte accesses (dependening howmemcpy()is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back tomemcpy()only for accesses not 2, 4, or 8 bytes in size.Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
TBD: Besides it still being open whether thelinear_write()path also
needs playing with, a question also continues to be whether we'd want to extend this to reads as well. linear_{read,write}() currently don't usehvmemul_map_linear_addr(), i.e. in both cases I'd need to also fiddle with__hvm_copy()(perhaps by making the construct below a helper function).xen/arch/x86/hvm/emulate.c +1
-1@@ -1324,7 +1324,14 @@ static int hvmemul_write(if ( !mapping )return linear_write (addr, bytes, p_data, pfec, hvmemul_ctxt); -memcpy (mapping, p_data, bytes); +/* Where possible use single (and hence generally atomic) MOV insns. */
xen/arch/x86/hvm/emulate.c static int hvmemul_write( · line 1337
Quoted 10 lines
xen/arch/x86/hvm/emulate.c +7
-0+switch ( bytes ) + { +case 2 :write_u16_atomic (mapping, *(uint16_t *)p_data);break ; +case 4 :write_u32_atomic (mapping, *(uint32_t *)p_data);break ; +case 8 :write_u64_atomic (mapping, *(uint64_t *)p_data);break ; +default :memcpy (mapping, p_data, bytes);break ; + }hvmemul_unmap_linear_addr (mapping, addr, bytes, hvmemul_ctxt);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Andrew Cooper
Acked-byRe: [Xen-devel] Ping: [PATCH] x86/HVM: use single (atomic) MOV for aligned emulated writes
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Jan Beulich
Using
memcpy()may result in multiple individual byte accesses (dependening howmemcpy()is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back tomemcpy()only for accesses not 2, 4, or 8 bytes in size.Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] Ping: [PATCH] x86/HVM: use single (atomic) MOV for aligned emulated writes
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
Using
memcpy()may result in multiple individual byte accesses (dependening howmemcpy()is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back tomemcpy()only for accesses not 2, 4, or 8 bytes in size.
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>Acked-by Andrew Cooper <[email protected]>
Should xen/arch/x86/mm/shadow/hvm.c:hvm_emulate_write() be similarly changed?
Thanks,
Jason
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Jason Andryuk
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
Using
memcpy()may result in multiple individual byte accesses (dependening howmemcpy()is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back tomemcpy()only for accesses not 2, 4, or 8 bytes in size.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>Acked-by Andrew Cooper <[email protected]>Should xen/arch/x86/mm/shadow/hvm.c:hvm_emulate_write() be similarly changed?
Probably. Care to make a patch?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Jan Beulich
Quoted 11 lines · Jason Andryuk
Quoted 9 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
Using
memcpy()may result in multiple individual byte accesses (dependening howmemcpy()is implemented and how the resulting insns, e.g. REP MOVSB, get carried out in hardware), which isn't what we want/need for carrying out guest insns as correctly as possible. Fall back tomemcpy()only for accesses not 2, 4, or 8 bytes in size.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>Acked-by Andrew Cooper <[email protected]>Should xen/arch/x86/mm/shadow/hvm.c:hvm_emulate_write() be similarly changed?
Probably. Care to make a patch?
Sure :)
-Jason
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel