Introduce segmented addresses to the emulator
cover Introduce segmented addresses to the emulator
Currently we lose segment information associated with memory operands. This prevents us from doing proper segment checks.
This patchset prepares the way by remembering which segment is associated with a memory operand.
Avi Kivity (2):
KVM: x86 emulator: preserve an operand's segment identity
KVM: x86 emulator: do not perform address calculations on linear
addresses
arch/x86/include/asm/kvm_emulate.h | 5 ++- arch/x86/kvm/emulate.c | 103 ++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 53 deletions(-)
Signature · 1 line
1.7.3.1
PATCH 1/2 KVM: x86 emulator: preserve an operand's segment identity
Currently the x86 emulator converts the segment register associated with an operand into a segment base which is added into the operand address. This loss of information results in us not doing segment limit checks properly.
Replace struct operand's addr.mem field by a segmented_address structure which holds both the effetive address and segment. This will allow us to do the limit check at the point of access.
--- arch/x86/include/asm/kvm_emulate.h | 5 ++- arch/x86/kvm/emulate.c | 102 +++++++++++++++++------------------ 2 files changed, 54 insertions(+), 53 deletions(-)
arch/x86/include/asm/kvm_emulate.h +4 -1
@@ -159,7 +159,10 @@ struct operand { };union {unsigned long *reg; -unsigned long mem; +struct segmented_address { +ulong ea; +unsigned seg; + } mem; } addr;union {unsigned long val;
arch/x86/kvm/emulate.c +50 -52
272 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH 2/2 KVM: x86 emulator: do not perform address calculations on linear addresses
In reply to Avi KivityLinear addresses are supposed to already have segment checks performed on them; if we play with these addresses the checks become invalid.
--- arch/x86/kvm/emulate.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +2 -1
@@ -562,7 +562,8 @@ static int read_descriptor(struct x86_emulate_ctxt *ctxt, ctxt->vcpu, NULL);if (rc !=X86EMUL_CONTINUE )return rc; - rc = ops->read_std (linear (ctxt, addr) +2 , address, op_bytes, + addr.ea +=2 ; + rc = ops->read_std (linear (ctxt, addr, address, op_bytes, ctxt->vcpu, NULL);return rc; }
Signature · 1 line
1.7.3.1
Marcelo Tosatti
AppliedQuoted 6 lines · Avi Kivity
Currently we lose segment information associated with memory operands. This prevents us from doing proper segment checks.
This patchset prepares the way by remembering which segment is associated with a memory operand.
Quoted 8 lines
Avi Kivity (2):
KVM: x86 emulator: preserve an operand's segment identity
KVM: x86 emulator: do not perform address calculations on linear
addressesarch/x86/include/asm/kvm_emulate.h | 5 ++- arch/x86/kvm/emulate.c | 103 ++++++++++++++++++------------------ 2 files changed, 55 insertions(+), 53 deletions(-)
Applied, thanks.