From 78ff4bcea4066762b291fafba1ae344fb22a9192 Mon Sep 17 00:00:00 2001 From: mlarkin Date: Wed, 11 Jul 2018 12:55:01 +0000 Subject: [PATCH] vmm(4): respect argument size when reading from undefined ports. --- sys/arch/amd64/amd64/vmm.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index c405ade5a4f..6dc20d5545c 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.211 2018/07/11 12:45:01 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.212 2018/07/11 12:55:01 mlarkin Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -5099,8 +5099,6 @@ svm_handle_inout(struct vcpu *vcpu) * * XXX something better than a hardcoded list here, maybe * configure via vmd via the device list in vm create params? - * - * XXX handle not eax target */ switch (vcpu->vc_exit.vei.vei_port) { case IO_ICU1 ... IO_ICU1 + 1: @@ -5119,8 +5117,20 @@ svm_handle_inout(struct vcpu *vcpu) default: /* Read from unsupported ports returns FFs */ if (vcpu->vc_exit.vei.vei_dir == 1) { - vcpu->vc_gueststate.vg_rax = 0xFFFFFFFF; - vmcb->v_rax = 0xFFFFFFFF; + switch(vcpu->vc_exit.vei.vei_size) { + case 1: + vcpu->vc_gueststate.vg_rax |= 0xFF; + vmcb->v_rax |= 0xFF; + break; + case 2: + vcpu->vc_gueststate.vg_rax |= 0xFFFF; + vmcb->v_rax |= 0xFFFF; + break; + case 4: + vcpu->vc_gueststate.vg_rax |= 0xFFFFFFFF; + vmcb->v_rax |= 0xFFFFFFFF; + break; + } } ret = 0; } @@ -5182,8 +5192,6 @@ vmx_handle_inout(struct vcpu *vcpu) * * XXX something better than a hardcoded list here, maybe * configure via vmd via the device list in vm create params? - * - * XXX handle not eax target */ switch (vcpu->vc_exit.vei.vei_port) { case IO_ICU1 ... IO_ICU1 + 1: @@ -5203,7 +5211,7 @@ vmx_handle_inout(struct vcpu *vcpu) /* Read from unsupported ports returns FFs */ if (vcpu->vc_exit.vei.vei_dir == VEI_DIR_IN) { if (vcpu->vc_exit.vei.vei_size == 4) - vcpu->vc_gueststate.vg_rax = 0xFFFFFFFF; + vcpu->vc_gueststate.vg_rax |= 0xFFFFFFFF; else if (vcpu->vc_exit.vei.vei_size == 2) vcpu->vc_gueststate.vg_rax |= 0xFFFF; else if (vcpu->vc_exit.vei.vei_size == 1) -- 2.20.1