From patchwork Thu May 10 15:46:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 10391987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CCB56053D for ; Thu, 10 May 2018 15:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CA6C28C0D for ; Thu, 10 May 2018 15:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70D2328C11; Thu, 10 May 2018 15:47:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, FROM_EXCESS_BASE64, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0881D28C0D for ; Thu, 10 May 2018 15:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966244AbeEJPrO (ORCPT ); Thu, 10 May 2018 11:47:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965686AbeEJPqn (ORCPT ); Thu, 10 May 2018 11:46:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A463406E970; Thu, 10 May 2018 15:46:42 +0000 (UTC) Received: from flask (ovpn-204-34.brq.redhat.com [10.40.204.34]) by smtp.corp.redhat.com (Postfix) with SMTP id 3B869215CDA7; Thu, 10 May 2018 15:46:39 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Thu, 10 May 2018 17:46:38 +0200 Date: Thu, 10 May 2018 17:46:38 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Jim Mattson Cc: kvm@vger.kernel.org Subject: Re: [PATCH] kvm: nVMX: vmcs02 should only get "use MSR bitmaps" from vmcs12 Message-ID: <20180510154638.GA7217@flask> References: <20180507175553.120151-1-jmattson@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180507175553.120151-1-jmattson@google.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 10 May 2018 15:46:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 10 May 2018 15:46:42 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rkrcmar@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 2018-05-07 10:55-0700, Jim Mattson: > If vmcs12 doesn't specify the "use MSR bitmaps" VM-execution control, > then vmcs02 should not specify this control either. When the MSR > bitmaps are not used, all executions of RDMSR and WRMSR cause > VM-exits. We already clear it at the end of nested_get_vmcs12_pages() in this case. I don't think that adding it here improves readability of the code. Maybe if we made sure that vmcs02 always begins with disabled MSR bitmaps and only set it afterwards, i.e. diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index c7668806163f..3938573cfb19 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10435,9 +10435,6 @@ static void nested_get_vmcs12_pages(struct kvm_vcpu *vcpu, if (nested_vmx_prepare_msr_bitmap(vcpu, vmcs12)) vmcs_set_bits(CPU_BASED_VM_EXEC_CONTROL, CPU_BASED_USE_MSR_BITMAPS); - else - vmcs_clear_bits(CPU_BASED_VM_EXEC_CONTROL, - CPU_BASED_USE_MSR_BITMAPS); } static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu) @@ -11139,6 +11136,9 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, exec_control &= ~CPU_BASED_USE_IO_BITMAPS; exec_control |= CPU_BASED_UNCOND_IO_EXITING; + /* MSR bitmaps are potentially enabled after recomputing the bitmap. */ + exec_control &= ~CPU_BASED_USE_MSR_BITMAPS; + vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, exec_control); /* EXCEPTION_BITMAP and CR0_GUEST_HOST_MASK should basically be the