From patchwork Sat Jan 4 17:59:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3434271 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 7275F9F381 for ; Sat, 4 Jan 2014 18:00:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9A82E20160 for ; Sat, 4 Jan 2014 17:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 171692015F for ; Sat, 4 Jan 2014 17:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754908AbaADR7y (ORCPT ); Sat, 4 Jan 2014 12:59:54 -0500 Received: from mout.web.de ([212.227.17.12]:63734 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754746AbaADR7h (ORCPT ); Sat, 4 Jan 2014 12:59:37 -0500 Received: from mchn199C.home ([95.157.58.223]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0M7Eb0-1VEqRa12ms-00x1DO for ; Sat, 04 Jan 2014 18:59:36 +0100 From: Jan Kiszka To: Gleb Natapov , Paolo Bonzini , Marcelo Tosatti Cc: kvm Subject: [PATCH 08/13] apic: Add test case for relocation and writing reserved bits Date: Sat, 4 Jan 2014 18:59:14 +0100 Message-Id: <73e13709076765876014a272173ead8e1dd53044.1388858359.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.8.1.1.298.ge7eed54 In-Reply-To: References: In-Reply-To: References: X-Provags-ID: V03:K0:zmVPfiW67JvqSFTQQgqCege3THmpL626V3kkzlEEFOxKQwgHFrd 6HlxHa3kqahLOcLM/qkCwJ/PVXwb6LZJyPXJ1+kcPXu+eRFjsSKYGKwnj+yIsV2kb21nfU+ HWC8ycroTgP9mTNgusm9sBq20zWB1vg0dSHcjXdHvtlTMDZmu0JIz7D22mKIu+p4e83UYDK tgGiHpt0TwqQmhy+EQSxA== Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 From: Jan Kiszka Check that the xAPIC is relocatable and that writing a reserved bit to MSR_IA32_APICBASE triggers a #GP. Signed-off-by: Jan Kiszka --- x86/apic.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/x86/apic.c b/x86/apic.c index 4ebcd4f..8febfa2 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -120,6 +120,32 @@ void test_enable_x2apic(void) } } +#define ALTERNATE_APIC_BASE 0x42000000 + +static void test_apicbase(void) +{ + u64 orig_apicbase = rdmsr(MSR_IA32_APICBASE); + u32 lvr = apic_read(APIC_LVR); + u64 value; + + wrmsr(MSR_IA32_APICBASE, orig_apicbase & ~(APIC_EN | APIC_EXTD)); + wrmsr(MSR_IA32_APICBASE, ALTERNATE_APIC_BASE | APIC_BSP | APIC_EN); + + report("relocate apic", + *(volatile u32 *)(ALTERNATE_APIC_BASE + APIC_LVR) == lvr); + + value = orig_apicbase | (1UL << (cpuid(0x80000008).a & 0xff)); + report("apicbase: reserved physaddr bits", + test_for_exception(GP_VECTOR, do_write_apicbase, &value)); + + value = orig_apicbase | 1; + report("apicbase: reserved low bits", + test_for_exception(GP_VECTOR, do_write_apicbase, &value)); + + wrmsr(MSR_IA32_APICBASE, orig_apicbase); + apic_write(APIC_SPIV, 0x1ff); +} + static void eoi(void) { apic_write(APIC_EOI, 0); @@ -366,6 +392,7 @@ int main() mask_pic_interrupts(); test_enable_x2apic(); + test_apicbase(); test_self_ipi();