From patchwork Fri Apr 15 01:55:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Zhang X-Patchwork-Id: 8844281 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 66E14C0553 for ; Fri, 15 Apr 2016 01:56:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94A682021F for ; Fri, 15 Apr 2016 01:56:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B7487202FF for ; Fri, 15 Apr 2016 01:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751529AbcDOBz5 (ORCPT ); Thu, 14 Apr 2016 21:55:57 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36632 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbcDOBz4 (ORCPT ); Thu, 14 Apr 2016 21:55:56 -0400 Received: by mail-pf0-f193.google.com with SMTP id p185so4291894pfb.3 for ; Thu, 14 Apr 2016 18:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=oAuV4IEmV9EVv2kGmSbt7jsT3ccSh5V+WuMEvOPHJpY=; b=iTrf51+Lg9LzxWOxAWYmIaZShnWesMufZUjI2S/3azIas6Akjv5Ht3vCgLYMLmUU8E 567lUuQoQItB0fsP91KS3iUveUWZXlsGP/tcvvTYsTN9qSmpgLMID1RkiaFPubr43Pfu pDYd6eu7anDv12Fad99O1aZ5pnK38Jlzteb7pgoJMC8ZIs1Nhk2S5y/fH47/qvoK46of JS45Tr7NNonMYNi63OCIdZqw/8sODTikj4nth080uT7EByLzlCkYqF+CVbVuIQcxF/GP 7AstYF6N83okIzOi/emAbc+AQ6H332PxqWBwKhjgIQndQeilhsq0FzAs7mnJ6DfUGe1r uRAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=oAuV4IEmV9EVv2kGmSbt7jsT3ccSh5V+WuMEvOPHJpY=; b=gDfXfrqA7SCe40xlzMWnWlsAC87Rceth3GQeGpEoeRAynx4OAE5WYWMGKvwT8ZA8Xf tyztI45O3LlFgDPTcSp0RuY/ZVdAitxyHvU9N1S3tLMHKnbkhWJT2wvzBNfycj/UjjTV CRkO2bxdu0i94BRW+cspkc91SCEsNKS2Uz2ooAyvtUyYIfKE4zNHkX63kW5AG/obEkYG 77iZwVfZG3v3vmNmefsa6cgImVZf8O92O1h5QqQ0FTDyDNqjBsl1bn/cYI9mtbuBCUhT pl+8EecrynljIVQfXt9mpezWsCJOlWu5Y2jRpsMY+L5lt7FF6XmOjMx2B0MgpcCzzSPM X11A== X-Gm-Message-State: AOPr4FVciGl4zf9Y+lJs05XlV6eEdZxcthVg5mdKudgWPOqIrkNC9ZyNKNLVDgguFjXtng== X-Received: by 10.98.28.195 with SMTP id c186mr14222834pfc.53.1460685355477; Thu, 14 Apr 2016 18:55:55 -0700 (PDT) Received: from [127.0.0.1] ([47.88.103.70]) by smtp.gmail.com with ESMTPSA id k65sm60721888pfb.30.2016.04.14.18.55.52 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Apr 2016 18:55:54 -0700 (PDT) To: "kvm@vger.kernel.org" , Paolo Bonzini , "rkrcmar@redhat.com" From: Yang Zhang Subject: [PATCH] KVM: x86: no need to check CPL for XSETBV on VMX Message-ID: <57104A23.4070405@gmail.com> Date: Fri, 15 Apr 2016 09:55:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 The CPL check for XSETBV instruction is done by hardware on VMX. It only needs by SVM. Signed-off-by: Yang Zhang --- arch/x86/kvm/svm.c | 4 +++- arch/x86/kvm/x86.c | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) } diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 31346a3..14680f5 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2715,7 +2715,9 @@ static int xsetbv_interception(struct vcpu_svm *svm) u64 new_bv = kvm_read_edx_eax(&svm->vcpu); u32 index = kvm_register_read(&svm->vcpu, VCPU_REGS_RCX); - if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) { + if (svm_get_cpl(&svm->vcpu) != 0) + kvm_inject_gp(&svm->vcpu, 0); + else if (kvm_set_xcr(&svm->vcpu, index, new_bv) == 0) { svm->next_rip = kvm_rip_read(&svm->vcpu) + 3; skip_emulated_instruction(&svm->vcpu); } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 8f57335..3cfc59f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -709,8 +709,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) int kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) { - if (kvm_x86_ops->get_cpl(vcpu) != 0 || - __kvm_set_xcr(vcpu, index, xcr)) { + if (__kvm_set_xcr(vcpu, index, xcr)) { kvm_inject_gp(vcpu, 0); return 1;