From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751517AbcGNIeB (ORCPT ); Thu, 14 Jul 2016 04:34:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44416 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751238AbcGNIdy (ORCPT ); Thu, 14 Jul 2016 04:33:54 -0400 Subject: Re: [PATCH] kvm: x86: nVMX: maintain internal copy of current VMCS To: David Matlack , kvm@vger.kernel.org References: <1468455397-22003-1-git-send-email-dmatlack@google.com> Cc: jmattson@google.com, pfeiner@google.com, linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <7f189511-4432-8208-28f0-701f1d05e91e@redhat.com> Date: Thu, 14 Jul 2016 10:33:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <1468455397-22003-1-git-send-email-dmatlack@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 14 Jul 2016 08:33:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/07/2016 02:16, David Matlack wrote: > KVM maintains L1's current VMCS in guest memory, at the guest physical > page identified by the argument to VMPTRLD. This makes hairy > time-of-check to time-of-use bugs possible,as VCPUs can be writing > the the VMCS page in memory while KVM is emulating VMLAUNCH and > VMRESUME. > > The spec documents that writing to the VMCS page while it is loaded is > "undefined". Therefore it is reasonable to load the entire VMCS into > an internal cache during VMPTRLD and ignore writes to the VMCS page > -- the guest should be using VMREAD and VMWRITE to access the current > VMCS. > > To adhere to the spec, KVM should flush the current VMCS during VMPTRLD, > and the target VMCS during VMCLEAR (as given by the operand to VMCLEAR). > Since this implementation of VMCS caching only maintains the the current > VMCS, VMCLEAR will only do a flush if the operand to VMCLEAR is the > current VMCS pointer. > > KVM will also flush during VMXOFF, which is not mandated by the spec, > but also not in conflict with the spec. > > Signed-off-by: David Matlack This is a good change. There is another change that is possible on top: with this change you don't need current_vmcs12/current_vmcs12_page at all, I think. You can just use current_vmptr and kvm_read/write_guest to write back the VMCS12, possibly the cached variants. Of course this would just be a small simplification, so I'm applying the patch as is to kvm/next. Thanks, Paolo