From patchwork Wed Nov 11 19:29:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 59417 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nABJjSEJ004821 for ; Wed, 11 Nov 2009 19:45:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758641AbZKKTpT (ORCPT ); Wed, 11 Nov 2009 14:45:19 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758632AbZKKTpT (ORCPT ); Wed, 11 Nov 2009 14:45:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42757 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758557AbZKKTpS (ORCPT ); Wed, 11 Nov 2009 14:45:18 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjLtc027355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Nov 2009 14:45:21 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjKs3001546; Wed, 11 Nov 2009 14:45:21 -0500 Received: from amt.cnet (vpn-8-242.rdu.redhat.com [10.11.8.242]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id nABJjHfo014716; Wed, 11 Nov 2009 14:45:17 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id A14C8588058; Wed, 11 Nov 2009 17:39:47 -0200 (BRST) Received: (from root@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id nABJdlm6013227; Wed, 11 Nov 2009 17:39:47 -0200 Message-Id: <20091111193837.229269590@localhost.localdomain> References: <20091111192947.348198723@localhost.localdomain> User-Agent: quilt/0.46-1 Date: Wed, 11 Nov 2009 17:29:49 -0200 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: gleb@redhat.com, jan.kiszka@siemens.com, joerg.roedel@amd.com, Marcelo Tosatti Subject: [patch 2/2] KVM: x86: raise TSS exception for NULL CS and SS segments Content-Disposition: inline; filename=taskswitch X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Index: kvm/arch/x86/kvm/x86.c =================================================================== --- kvm.orig/arch/x86/kvm/x86.c +++ kvm/arch/x86/kvm/x86.c @@ -4091,6 +4091,15 @@ static int is_vm86_segment(struct kvm_vc (kvm_x86_ops->get_rflags(vcpu) & X86_EFLAGS_VM); } +static void kvm_check_segment_descriptor(struct kvm_vcpu *vcpu, int seg, + u16 selector) +{ + /* NULL selector is not valid for CS and SS */ + if (seg == VCPU_SREG_CS || seg == VCPU_SREG_SS) + if (!selector) + kvm_queue_exception_e(vcpu, TS_VECTOR, selector >> 3); +} + int kvm_load_segment_descriptor(struct kvm_vcpu *vcpu, u16 selector, int type_bits, int seg) { @@ -4100,6 +4109,8 @@ int kvm_load_segment_descriptor(struct k return kvm_load_realmode_segment(vcpu, selector, seg); if (load_segment_descriptor_to_kvm_desct(vcpu, selector, &kvm_seg)) return 1; + + kvm_check_segment_descriptor(vcpu, seg, selector); kvm_seg.type |= type_bits; if (seg != VCPU_SREG_SS && seg != VCPU_SREG_CS &&