From patchwork Sat Jan 4 17:59:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3434201 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 23FB3C02DC for ; Sat, 4 Jan 2014 17:59:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49AD120163 for ; Sat, 4 Jan 2014 17:59:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FEFC2015E for ; Sat, 4 Jan 2014 17:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754790AbaADR7j (ORCPT ); Sat, 4 Jan 2014 12:59:39 -0500 Received: from mout.web.de ([212.227.17.12]:51342 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754487AbaADR7f (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 0LxqwW-1VN7uj2Jue-015Efw for ; Sat, 04 Jan 2014 18:59:33 +0100 From: Jan Kiszka To: Gleb Natapov , Paolo Bonzini , Marcelo Tosatti Cc: kvm Subject: [PATCH 05/13] lib/x86: Move exception test code into library Date: Sat, 4 Jan 2014 18:59:11 +0100 Message-Id: <5b43f96a1996b19ae304f27de0bc27f0dac7e19a.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:SZbq/Wuu12ycUaSH7hF2wVVwd9tPvQjPJ21oPgzVy7IB0kMuj3v AX/ywA32khCUhmV/JX7BAS4WcGfZAbnNtmnsNf+dsdaLzN652n0jhD6VkRdBTpCCuOWgKT2 Qa6aXaQ1spqQ0MQ3yIQjO4lWwTwR0a59+1AhtIxcgH8oaD/FTkfajyVFENqQwFPR634d02I ZtK0waHqRv1OGCPCxi0jw== 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 Will also be used by the APIC test. Moving exception_return assignment out of line, we can drop the explicit compiler barrier. Signed-off-by: Jan Kiszka --- lib/x86/desc.c | 24 ++++++++++++++++++++++++ lib/x86/desc.h | 4 ++++ x86/vmx.c | 34 +++++++--------------------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 7c5c721..f75ec1d 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -353,3 +353,27 @@ void print_current_tss_info(void) tr, tss[0].prev, tss[i].prev); } #endif + +static bool exception; +static void *exception_return; + +static void exception_handler(struct ex_regs *regs) +{ + exception = true; + regs->rip = (unsigned long)exception_return; +} + +bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data), + void *data) +{ + handle_exception(ex, exception_handler); + exception = false; + trigger_func(data); + handle_exception(ex, NULL); + return exception; +} + +void set_exception_return(void *addr) +{ + exception_return = addr; +} diff --git a/lib/x86/desc.h b/lib/x86/desc.h index f819452..5c850b2 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -84,4 +84,8 @@ void set_intr_task_gate(int e, void *fn); void print_current_tss_info(void); void handle_exception(u8 v, void (*func)(struct ex_regs *regs)); +bool test_for_exception(unsigned int ex, void (*trigger_func)(void *data), + void *data); +void set_exception_return(void *addr); + #endif diff --git a/x86/vmx.c b/x86/vmx.c index f9d5493..4f0bb8d 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -538,38 +538,18 @@ static void init_vmx(void) memset(guest_syscall_stack, 0, PAGE_SIZE); } -static bool exception; -static void *exception_return; - -static void exception_handler(struct ex_regs *regs) +static void do_vmxon_off(void *data) { - exception = true; - regs->rip = (u64)exception_return; -} - -static int test_for_exception(unsigned int ex, void (*func)(void)) -{ - handle_exception(ex, exception_handler); - exception = false; - func(); - handle_exception(ex, NULL); - return exception; -} - -static void do_vmxon_off(void) -{ - exception_return = &&resume; - barrier(); + set_exception_return(&&resume); vmx_on(); vmx_off(); resume: barrier(); } -static void do_write_feature_control(void) +static void do_write_feature_control(void *data) { - exception_return = &&resume; - barrier(); + set_exception_return(&&resume); wrmsr(MSR_IA32_FEATURE_CONTROL, 0); resume: barrier(); @@ -592,18 +572,18 @@ static int test_vmx_feature_control(void) wrmsr(MSR_IA32_FEATURE_CONTROL, 0); report("test vmxon with FEATURE_CONTROL cleared", - test_for_exception(GP_VECTOR, &do_vmxon_off)); + test_for_exception(GP_VECTOR, &do_vmxon_off, NULL)); wrmsr(MSR_IA32_FEATURE_CONTROL, 0x4); report("test vmxon without FEATURE_CONTROL lock", - test_for_exception(GP_VECTOR, &do_vmxon_off)); + test_for_exception(GP_VECTOR, &do_vmxon_off, NULL)); wrmsr(MSR_IA32_FEATURE_CONTROL, 0x5); vmx_enabled = ((rdmsr(MSR_IA32_FEATURE_CONTROL) & 0x5) == 0x5); report("test enable VMX in FEATURE_CONTROL", vmx_enabled); report("test FEATURE_CONTROL lock bit", - test_for_exception(GP_VECTOR, &do_write_feature_control)); + test_for_exception(GP_VECTOR, &do_write_feature_control, NULL)); return !vmx_enabled; }