From patchwork Tue Jun 2 11:52:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 27444 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 n52BqqSs028724 for ; Tue, 2 Jun 2009 11:52:52 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760212AbZFBLwl (ORCPT ); Tue, 2 Jun 2009 07:52:41 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760193AbZFBLwl (ORCPT ); Tue, 2 Jun 2009 07:52:41 -0400 Received: from mx2.redhat.com ([66.187.237.31]:60116 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760064AbZFBLwl (ORCPT ); Tue, 2 Jun 2009 07:52:41 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n52BqhHC022128 for ; Tue, 2 Jun 2009 07:52:43 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n52BqgwU006867; Tue, 2 Jun 2009 07:52:42 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n52BqflP014565; Tue, 2 Jun 2009 07:52:41 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 8F28118D462; Tue, 2 Jun 2009 14:52:40 +0300 (IDT) Date: Tue, 2 Jun 2009 14:52:40 +0300 From: Gleb Natapov To: avi@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH] Fix tpr patching to get cpu index from Windows per cpu area. Message-ID: <20090602115240.GB25846@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Using cpu_index for this purpose work only by luck. Signed-off-by: Gleb Natapov --- Gleb. -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kvm-tpr-opt.c b/kvm-tpr-opt.c index 246e08d..bdbc742 100644 --- a/kvm-tpr-opt.c +++ b/kvm-tpr-opt.c @@ -220,13 +220,29 @@ static int bios_is_mapped(CPUState *env, uint64_t rip) return 1; } +static int get_pcr_cpu(CPUState *env) +{ + struct kvm_sregs sregs; + uint8_t b; + + kvm_save_registers(env); + + if (cpu_memory_rw_debug(env, env->segs[R_FS].base + 0x51, &b, 1, 0) < 0) + return -1; + + return (int)b; +} + static int enable_vapic(CPUState *env) { static uint8_t one = 1; + int pcr_cpu = get_pcr_cpu(env); + + if (pcr_cpu < 0) + return 0; - kvm_enable_vapic(kvm_context, env->cpu_index, - vapic_phys + (env->cpu_index << 7)); - cpu_physical_memory_rw(vapic_phys + (env->cpu_index << 7) + 4, &one, 1, 1); + kvm_enable_vapic(kvm_context, env->cpu_index, vapic_phys + (pcr_cpu << 7)); + cpu_physical_memory_rw(vapic_phys + (pcr_cpu << 7) + 4, &one, 1, 1); bios_enabled = 1; return 1;