From patchwork Wed Oct 23 14:21:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 3088971 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 C3C6C9F2B7 for ; Wed, 23 Oct 2013 14:21:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29FBA203FB for ; Wed, 23 Oct 2013 14:21:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C68FD20375 for ; Wed, 23 Oct 2013 14:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751852Ab3JWOVb (ORCPT ); Wed, 23 Oct 2013 10:21:31 -0400 Received: from thoth.sbs.de ([192.35.17.2]:29301 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577Ab3JWOVa (ORCPT ); Wed, 23 Oct 2013 10:21:30 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id r9NELLTI011023; Wed, 23 Oct 2013 16:21:21 +0200 Received: from mchn199C.mchp.siemens.de ([146.254.78.187]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id r9NELLeA004908; Wed, 23 Oct 2013 16:21:21 +0200 Message-ID: <5267DB60.9090907@siemens.com> Date: Wed, 23 Oct 2013 15:21:20 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Gleb Natapov , Paolo Bonzini CC: kvm , =?UTF-8?B?IuadjuaYpeWlhyA8QXJ0aHVyIENodW5x?= =?UTF-8?B?aSBMaT4i?= Subject: [PATCH][kvm-unit-tests] VMX preemption timer: Make test case more robust 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, 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 If we both print from L2 and, on timer expiry, from L1, we risk a deadlock in L1 on the printf lock that is held by L2 then. Avoid this by only printing from L1. Furthermore, if the timer fails to fire in time, disable it before continuing to avoid that it fire later on in different contexts. Signed-off-by: Jan Kiszka --- x86/vmx_tests.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 8d47bcd..7893a6c 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -128,6 +128,9 @@ void preemption_timer_init() preempt_val = 10000000; vmcs_write(PREEMPT_TIMER_VALUE, preempt_val); preempt_scale = rdmsr(MSR_IA32_VMX_MISC) & 0x1F; + + if (!(ctrl_exit_rev.clr & EXI_SAVE_PREEMPT)) + printf("\tSave preemption value is not supported\n"); } void preemption_timer_main() @@ -137,9 +140,7 @@ void preemption_timer_main() printf("\tPreemption timer is not supported\n"); return; } - if (!(ctrl_exit_rev.clr & EXI_SAVE_PREEMPT)) - printf("\tSave preemption value is not supported\n"); - else { + if (ctrl_exit_rev.clr & EXI_SAVE_PREEMPT) { set_stage(0); vmcall(); if (get_stage() == 1) @@ -148,8 +149,8 @@ void preemption_timer_main() while (1) { if (((rdtsc() - tsc_val) >> preempt_scale) > 10 * preempt_val) { - report("Preemption timer", 0); - break; + set_stage(2); + vmcall(); } } } @@ -170,7 +171,7 @@ int preemption_timer_exit_handler() report("Preemption timer", 0); else report("Preemption timer", 1); - return VMX_TEST_VMEXIT; + break; case VMX_VMCALL: switch (get_stage()) { case 0: @@ -182,24 +183,29 @@ int preemption_timer_exit_handler() EXI_SAVE_PREEMPT) & ctrl_exit_rev.clr; vmcs_write(EXI_CONTROLS, ctrl_exit); } - break; + vmcs_write(GUEST_RIP, guest_rip + insn_len); + return VMX_TEST_RESUME; case 1: if (vmcs_read(PREEMPT_TIMER_VALUE) >= preempt_val) report("Save preemption value", 0); else report("Save preemption value", 1); + vmcs_write(GUEST_RIP, guest_rip + insn_len); + return VMX_TEST_RESUME; + case 2: + report("Preemption timer", 0); break; default: printf("Invalid stage.\n"); print_vmexit_info(); - return VMX_TEST_VMEXIT; + break; } - vmcs_write(GUEST_RIP, guest_rip + insn_len); - return VMX_TEST_RESUME; + break; default: printf("Unknown exit reason, %d\n", reason); print_vmexit_info(); } + vmcs_write(PIN_CONTROLS, vmcs_read(PIN_CONTROLS) & ~PIN_PREEMPT); return VMX_TEST_VMEXIT; }