From patchwork Sat Jan 4 17:59:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3434261 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 EBB029F2E9 for ; Sat, 4 Jan 2014 17:59:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1790F20160 for ; Sat, 4 Jan 2014 17:59:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49A572015E for ; Sat, 4 Jan 2014 17:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754771AbaADR7h (ORCPT ); Sat, 4 Jan 2014 12:59:37 -0500 Received: from mout.web.de ([212.227.15.4]:55126 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754408AbaADR7f (ORCPT ); Sat, 4 Jan 2014 12:59:35 -0500 Received: from mchn199C.home ([95.157.58.223]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0LjP7H-1VQA9p0v2l-00daWR for ; Sat, 04 Jan 2014 18:59:34 +0100 From: Jan Kiszka To: Gleb Natapov , Paolo Bonzini , Marcelo Tosatti Cc: kvm Subject: [PATCH 06/13] x2apic: Test for invalid state transitions Date: Sat, 4 Jan 2014 18:59:12 +0100 Message-Id: <54ef8db7c3d723cbbf3d486bdbd69c124178557b.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:bv6WemvdCeZii3aG0w4Wo0whIURgtkqokfnep3NpIfv4Fe81JEm ailhx9auu2dT2biEf4Az+MqOZQfxnfLWetUtzhr56xqEbt2ZT8Q9yUh5VnJrTWy5NSdjGhG WhiLBTEyWrKjt8iywmuC3Ly5m6thNYtwgQEihpSRQqnD8p4MSLDH+A+yawG95fRknDwNRW3 thDv3e4nKpAyVUXL+mizg== 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 This checks if KVM properly acknowledges invalid state transitions on MSR_APIC_BASE writes with a #GP. Signed-off-by: Jan Kiszka --- lib/x86/apic-defs.h | 3 +++ x86/apic.c | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/x86/apic-defs.h b/lib/x86/apic-defs.h index c061e3d..94112b4 100644 --- a/lib/x86/apic-defs.h +++ b/lib/x86/apic-defs.h @@ -9,6 +9,9 @@ */ #define APIC_DEFAULT_PHYS_BASE 0xfee00000 +#define APIC_BSP (1UL << 8) +#define APIC_EXTD (1UL << 10) +#define APIC_EN (1UL << 11) #define APIC_ID 0x20 diff --git a/x86/apic.c b/x86/apic.c index d06153f..4ebcd4f 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -4,6 +4,7 @@ #include "smp.h" #include "desc.h" #include "isr.h" +#include "msr.h" static int g_fail; static int g_tests; @@ -70,14 +71,52 @@ static void test_tsc_deadline_timer(void) } } -#define MSR_APIC_BASE 0x0000001b +static void do_write_apicbase(void *data) +{ + set_exception_return(&&resume); + wrmsr(MSR_IA32_APICBASE, *(u64 *)data); +resume: + barrier(); +} void test_enable_x2apic(void) { + u64 invalid_state = APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EXTD; + u64 apic_enabled = APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EN; + u64 x2apic_enabled = + APIC_DEFAULT_PHYS_BASE | APIC_BSP | APIC_EN | APIC_EXTD; + if (enable_x2apic()) { printf("x2apic enabled\n"); + + report("x2apic enabled to invalid state", + test_for_exception(GP_VECTOR, do_write_apicbase, + &invalid_state)); + report("x2apic enabled to apic enabled", + test_for_exception(GP_VECTOR, do_write_apicbase, + &apic_enabled)); + + wrmsr(MSR_IA32_APICBASE, APIC_DEFAULT_PHYS_BASE | APIC_BSP); + report("disabled to invalid state", + test_for_exception(GP_VECTOR, do_write_apicbase, + &invalid_state)); + report("disabled to x2apic enabled", + test_for_exception(GP_VECTOR, do_write_apicbase, + &x2apic_enabled)); + + wrmsr(MSR_IA32_APICBASE, apic_enabled); + report("apic enabled to invalid state", + test_for_exception(GP_VECTOR, do_write_apicbase, + &invalid_state)); + + wrmsr(MSR_IA32_APICBASE, x2apic_enabled); + apic_write(APIC_SPIV, 0x1ff); } else { printf("x2apic not detected\n"); + + report("enable unsupported x2apic", + test_for_exception(GP_VECTOR, do_write_apicbase, + &x2apic_enabled)); } }