From patchwork Fri Mar 18 22:39:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8624111 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C37829F3D1 for ; Fri, 18 Mar 2016 22:39:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1BD620373 for ; Fri, 18 Mar 2016 22:39:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 147A820394 for ; Fri, 18 Mar 2016 22:39:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753763AbcCRWjR (ORCPT ); Fri, 18 Mar 2016 18:39:17 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:33166 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752685AbcCRWjP (ORCPT ); Fri, 18 Mar 2016 18:39:15 -0400 Received: by mail-pf0-f177.google.com with SMTP id 4so54089690pfd.0 for ; Fri, 18 Mar 2016 15:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=wYze03IX6O9Dacq8G/0t5FPY1rUmrG9E65pyv8gpM5k=; b=Yr30PARljJo2fh0fw7O14FTDFDmO458l3kDlL7I9v9yWNqd7xhN7uPugo4MfxmveCc gE5jt4MT2RlRCzU9sUAGftsrS4LnlhgTxELfM448jdcOtPEzAnAMDKFwCc+R8qSwoigT iO6IMwAR+RHZIjh2yDPMSWxI7TpelNmjtnII5NvdgTn3IPlo8GhAREGaSkNzGeqxShfM /bJMY4Yt4hHbVH5TiJK7uWxMRiMxQgAOQIzUsnuvLlKXMDZ7MMGAyzpsxGbR7DWzI3kz X8b4MvLXSy6ZCNS4cf76aybEsUlz3IxY4vRmrNDre3ba8c0fCBId2ImOjrHHiBZMbKl2 1KPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=wYze03IX6O9Dacq8G/0t5FPY1rUmrG9E65pyv8gpM5k=; b=SQGaS2p8SJ4qJ2jrnjD+Z7XdCkvajIY66NjSoxWj5W64Cl2mK7i1KRYHx/n9HNVWJo +6DL9YYkLCud72hXxC8N3GputsTCuiP7C5f8QugaJWs10FUXdy6Vy5IjntgVcv1okUMs JWMR1n+jrbfu6xARBetaT9ZkaftYfOCiUnGErDMS4PJQRj/kH8KX6VcFFjLXY6nTLcuX kMQn6V8Eju06rhfKEPVpVF5eWua1HWg472IPIlwPBgkrCzaTOueSiyu1Oea5JlMoNIU1 DQsQVBnYLpN9NfXsklXq/wW+/GQDhGe/GUsP7sgFSBWxmUqo2IDelWHRRKal6CAJpTsm qE1w== X-Gm-Message-State: AD7BkJJ7rxUWRd1nle0yxDpfirt2xQLv/2RRu4GxHP325EjMNU6v+qfA2dRHiLHImHwgM3RN X-Received: by 10.66.124.130 with SMTP id mi2mr27231762pab.106.1458340755155; Fri, 18 Mar 2016 15:39:15 -0700 (PDT) Received: from localhost ([2620:0:1009:3:cd03:ef39:7648:4957]) by smtp.gmail.com with ESMTPSA id 79sm23283910pfq.65.2016.03.18.15.39.14 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 18 Mar 2016 15:39:14 -0700 (PDT) From: Peter Feiner To: jan.kiszka@siemens.com, pbonzini@redhat.com, kvm@vger.kernel.org Cc: pfeiner@google.com Subject: [PATCH kvm-unit-tests 1/4] x86: vmx: fix vm{launch,resume} asm Date: Fri, 18 Mar 2016 15:39:09 -0700 Message-Id: X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Fixed two problems: 1) Output operands with the '=' constraint are dead-on-arrival. Thus gcc was free to ignore the fail = 0 initialization. Since the asm only set fail when vm{launch,resume} exited early, fail was technically undefined when vm{launch,resume} entered the guest! Using the '+' constraint instead tells gcc the value is live. 2) On early vm{launch,resume} failure, the 'setbe %0' instruction was running with the guest's GPRs since SAVE_GPR_C hadn't run yet. Since %0 is typically replaced with OFFSET(%%rbp), some arbitrary guest stack memory is modified. Solution is to restore the host's registers before using any asm code generated by gcc. Signed-off-by: Peter Feiner --- x86/vmx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x86/vmx.c b/x86/vmx.c index 107a005..b2e015f 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -925,11 +925,14 @@ static int vmx_run() "1: " "vmresume\n\t" "2: " + SAVE_GPR_C "setbe %0\n\t" + "jmp 3f\n\t" "vmx_return:\n\t" SAVE_GPR_C + "3: \n\t" SAVE_RFLAGS - : "=m"(fail) + : "+m"(fail) : "m"(launched), "i"(HOST_RSP) : "rdi", "rsi", "memory", "cc"