Skip to contentSkip to conversation

Introduce segmented addresses to the emulator

PATCH Applied Avi Kivity 2 participants 4 messages Nov 17, 2010 – Nov 18, 2010

Subsystems (3)
lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

v2 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
v2: truncate linear address to 32 bits if not in long mode (thanks Gleb)
KVM: x86 emulator: do not perform address calculations on linear
addresses
v2: fix typo

 arch/x86/include/asm/kvm_emulate.h |    5 +-
 arch/x86/kvm/emulate.c             |  107 +++++++++++++++++++-----------------
 2 files changed, 60 insertions(+), 52 deletions(-)
Signature · 1 line
1.7.3.1
author
#1 lore raw

PATCH v2 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             |  106 +++++++++++++++++++-----------------
 2 files changed, 59 insertions(+), 52 deletions(-)
arch/x86/include/asm/kvm_emulate.h +4 -1
index b36c6b3..b48c133 100644
@@ -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 +55 -51

277 lines not on this page · raw message

Signature · 1 line
1.7.3.1
author
#2 lore raw

PATCH v2 2/2 KVM: x86 emulator: do not perform address calculations on linear addresses

In reply to Avi Kivity

Linear 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
index e967055..bdbbb18 100644
@@ -568,7 +568,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
#3 lore raw
In reply to Avi Kivity
Quoted 13 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.

Avi Kivity (2):
KVM: x86 emulator: preserve an operand's segment identity
v2: truncate linear address to 32 bits if not in long mode (thanks Gleb)
KVM: x86 emulator: do not perform address calculations on linear
addresses
v2: fix typo

Quoted 3 lines
 arch/x86/include/asm/kvm_emulate.h |    5 +-
 arch/x86/kvm/emulate.c             |  107 +++++++++++++++++++-----------------
 2 files changed, 60 insertions(+), 52 deletions(-)

Applied, thanks.