From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 3/3] KVM: VMX: handle segment limit granularity special case in software Date: Wed, 16 Jul 2008 19:07:12 -0300 Message-ID: <20080716221401.578260549@localhost.localdomain> References: <20080716220709.886199616@localhost.localdomain> Cc: kvm@vger.kernel.org, Marcelo Tosatti To: Avi Kivity Return-path: Received: from mx1.redhat.com ([66.187.233.31]:46289 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757925AbYGPWSu (ORCPT ); Wed, 16 Jul 2008 18:18:50 -0400 Content-Disposition: inline; filename=vmx-seg-limit-bits-0-11-zeroed Sender: kvm-owner@vger.kernel.org List-ID: As the comment in the diff mentions, VMX does not accept any bit in the range 11:0 of ES,CS,FS,GS,SS segment registers limit field to be zero with the granulity bit set to one. So clear granularity and adjust the limit accordingly. Signed-off-by: Marcelo Tosatti Index: kvm/arch/x86/kvm/vmx.c =================================================================== --- kvm.orig/arch/x86/kvm/vmx.c +++ kvm/arch/x86/kvm/vmx.c @@ -1665,6 +1665,22 @@ static void vmx_set_segment(struct kvm_v return; } vmcs_writel(sf->base, var->base); + + /* + * section 22.3.1.2: + * - If any bit in the limit field in the range 11:0 is 0, G must be 0. + * - If any bit in the limit field in the range 31:20 is 1, G must be 1. + */ + if (!vcpu->arch.rmode.active && !var->unusable && + seg != VCPU_SREG_TR && seg != VCPU_SREG_LDTR) { +#define SEG_MASK ((1 << 12)-1) + if (var->g && (var->limit & SEG_MASK) != SEG_MASK) { + var->g = 0; + var->limit <<= 12; + var->limit |= SEG_MASK; + } + } + vmcs_write32(sf->limit, var->limit); vmcs_write16(sf->selector, var->selector); if (vcpu->arch.rmode.active && var->s) { --