From patchwork Fri Mar 18 22:39:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8624131 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B5DEDC0554 for ; Fri, 18 Mar 2016 22:39:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB99C20375 for ; Fri, 18 Mar 2016 22:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F32B120394 for ; Fri, 18 Mar 2016 22:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753846AbcCRWjW (ORCPT ); Fri, 18 Mar 2016 18:39:22 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35203 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234AbcCRWjS (ORCPT ); Fri, 18 Mar 2016 18:39:18 -0400 Received: by mail-pf0-f182.google.com with SMTP id n5so184958530pfn.2 for ; Fri, 18 Mar 2016 15:39:18 -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=h86dqK9TRoInnxPKayyOAiS5Av/3UhFO+BwBs4mQ2k8=; b=DhrZItjn1xEPiOIVi16QkJ/fZogtW/zziWriva36OeYBYunPSmc78dKmcCpMKQmlVY DooSj2kz9/YKHkSlrvOuDJppqrCafk0S4zqb3FkHTEJ3kUwiWxNywf30dVgsz2rwNzA1 Veu2F2lZ+tAwpEy4S3dwOJMzSxNgVZxeAk6JYestxvX/CIiJ2LvikDh7A8cwyb53k3QQ yzN4duie8qZ+rYQdPfc7aVkxGqhFS2zMCVt3WVIqs+gyDwfgbsnf0agG9i4I92BQBOnM NbjaC5uAy20w/8aEhdiQW/f0dtCzSTNYKxVPqk11U5rXrX2enmTVdlbsx7Otu5EmCWzl 7rng== 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=h86dqK9TRoInnxPKayyOAiS5Av/3UhFO+BwBs4mQ2k8=; b=T+9fMrzeG3QMQkUnuFYcSVw8BJYVZpKaRgqgPx9jfKdz0wLACE35g8RTjaFuzvfRyP /Opf0XobXK2G6VuJwV8DNa4RTQ1XMMAfp72pWUctufrJmWimdblpFrOUOW3YTjoCSeTS qQeYkEsys8y5jTM4yi4bZGQuS+KOhpmRPrqKWiJaai0I0DLGRk3EE19HYlC08tMHBKHX 1vl4AjIuTFo7kQ5UWeNECqOzJOD2rrOzDnbIB/8UYPKH/JfiXu4tBtRgZBqYEpXNGuJn OlWR6oAK9R0RF30mwoliiBFJXXd68rwo3Y74j/bB/Ay9SlQ0t5eoTGIZ7+xtAPf4zaeV mg+g== X-Gm-Message-State: AD7BkJI27eWkZ4ZyA46ra9KBukObLX/lo8+qYIgd6YdjrdgUXq4T+YfXo/tdjDY0ZEihQlya X-Received: by 10.98.70.67 with SMTP id t64mr27281681pfa.110.1458340758149; Fri, 18 Mar 2016 15:39:18 -0700 (PDT) Received: from localhost ([2620:0:1009:3:cd03:ef39:7648:4957]) by smtp.gmail.com with ESMTPSA id g6sm23324961pfg.15.2016.03.18.15.39.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 18 Mar 2016 15:39:17 -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 3/4] x86: vmx: clean up vm{launch, resume} asm Date: Fri, 18 Mar 2016 15:39:11 -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=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 Did a few things to make the code easier to fllow: * named I/O operands * removed pointless LOAD_RFLAGS * replaced global host_rflags with local * only save rflags when they're meaningful (i.e., after early failure) * got rid of unecessary %rsi scratch register Signed-off-by: Peter Feiner --- x86/vmx.c | 23 +++++++++++------------ x86/vmx.h | 8 -------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 27e85eb..67f8650 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -46,7 +46,6 @@ struct regs regs; struct vmx_test *current; u64 hypercall_field; bool launched; -u64 host_rflags; union vmx_basic basic; union vmx_ctrl_msr ctrl_pin_rev; @@ -909,33 +908,33 @@ static int exit_handler() static int vmx_run() { u32 ret = 0, fail = 0; + unsigned long host_rflags; while (1) { asm volatile ( - "mov %%rsp, %%rsi\n\t" - "mov %2, %%rdi\n\t" - "vmwrite %%rsi, %%rdi\n\t" - + "mov %[HOST_RSP], %%rdi\n\t" + "vmwrite %%rsp, %%rdi\n\t" LOAD_GPR_C - "cmpl $0, %1\n\t" + "cmpl $0, %[launched]\n\t" "jne 1f\n\t" - LOAD_RFLAGS "vmlaunch\n\t" "jmp 2f\n\t" "1: " "vmresume\n\t" "2: " SAVE_GPR_C - "movl $1, %0\n\t" + "pushf\n\t" + "pop %%rdi\n\t" + "mov %%rdi, %[host_rflags]\n\t" + "movl $1, %[fail]\n\t" "jmp 3f\n\t" "vmx_return:\n\t" SAVE_GPR_C "3: \n\t" - SAVE_RFLAGS - : "+m"(fail) - : "m"(launched), "i"(HOST_RSP) - : "rdi", "rsi", "memory", "cc" + : [fail]"+m"(fail), [host_rflags]"=m"(host_rflags) + : [launched]"m"(launched), [HOST_RSP]"i"(HOST_RSP) + : "rdi", "memory", "cc" ); if (fail) diff --git a/x86/vmx.h b/x86/vmx.h index 34e9be4..aba5642 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -396,14 +396,6 @@ enum Ctrl1 { #define LOAD_GPR_C SAVE_GPR_C -#define SAVE_RFLAGS \ - "pushf\n\t" \ - "pop host_rflags\n\t" - -#define LOAD_RFLAGS \ - "push host_rflags\n\t" \ - "popf\n\t" - #define VMX_IO_SIZE_MASK 0x7 #define _VMX_IO_BYTE 0 #define _VMX_IO_WORD 1