From patchwork Thu Aug 28 18:02:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 4806091 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1CCE49F3EE for ; Thu, 28 Aug 2014 18:02:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E7C920117 for ; Thu, 28 Aug 2014 18:02:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D707C20145 for ; Thu, 28 Aug 2014 18:02:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752085AbaH1SCl (ORCPT ); Thu, 28 Aug 2014 14:02:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41720 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750892AbaH1SCk (ORCPT ); Thu, 28 Aug 2014 14:02:40 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7SI2etu030377 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 28 Aug 2014 14:02:40 -0400 Received: from localhost (ovpn-113-147.phx2.redhat.com [10.3.113.147]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7SI2cY7005828; Thu, 28 Aug 2014 14:02:39 -0400 From: Eduardo Habkost To: kvm@vger.kernel.org Cc: Paolo Bonzini Subject: [PATCH 1/3] x86: apic: Look up MAXPHYADDR on CPUID correctly Date: Thu, 28 Aug 2014 15:02:28 -0300 Message-Id: <1409248950-16268-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1409248950-16268-1-git-send-email-ehabkost@redhat.com> References: <1409248950-16268-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the CPUID xlevel on QEMU is < 0x80000008, we get the following: $ ./x86-run x86/apic.flat -smp 2 -cpu qemu64,xlevel=0x80000007 [...] FAIL: apicbase: reserved physaddr bits That happens because CPUID[0x80000008].EAX won't have the expected data if xlevel < 0x80000008. When the CPUID physical address bits information is not available on CPUID, assume it is 36, as documented on Intel SDM, Volume 3A, section 10.4.4 "Local APIC Status and Location": > Bits 0 through 7, bits 9 and 10, and bits MAXPHYADDR[1] through 63 in the > IA32_APIC_BASE MSR are reserved. > > [1] The MAXPHYADDR is 36 bits for processors that do not support CPUID > leaf 80000008H, or indicated by CPUID.80000008H:EAX[bits 7:0] for > processors that support CPUID leaf 80000008H." Signed-off-by: Eduardo Habkost --- lib/x86/processor.h | 8 ++++++++ x86/apic.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index f5f1c82..d4e295b 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -294,6 +294,14 @@ static inline struct cpuid cpuid(u32 function) return cpuid_indexed(function, 0); } +static inline u8 cpuid_maxphyaddr(void) +{ + if (cpuid(0x80000000).a < 0x80000008) + return 36; + return cpuid(0x80000008).a & 0xff; +} + + static inline void pause(void) { asm volatile ("pause"); diff --git a/x86/apic.c b/x86/apic.c index 3f463a5..2619d85 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -124,7 +124,7 @@ static void test_apicbase(void) report("relocate apic", *(volatile u32 *)(ALTERNATE_APIC_BASE + APIC_LVR) == lvr); - value = orig_apicbase | (1UL << (cpuid(0x80000008).a & 0xff)); + value = orig_apicbase | (1UL << cpuid_maxphyaddr()); report("apicbase: reserved physaddr bits", test_for_exception(GP_VECTOR, do_write_apicbase, &value));