From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16741C3A5A0 for ; Mon, 19 Aug 2019 18:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E9CF822CF5 for ; Mon, 19 Aug 2019 18:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbfHSSgq (ORCPT ); Mon, 19 Aug 2019 14:36:46 -0400 Received: from mga07.intel.com ([134.134.136.100]:25529 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727808AbfHSSgp (ORCPT ); Mon, 19 Aug 2019 14:36:45 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Aug 2019 11:36:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,405,1559545200"; d="scan'208";a="195592515" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga001.fm.intel.com with ESMTP; 19 Aug 2019 11:36:44 -0700 Date: Mon, 19 Aug 2019 11:36:44 -0700 From: Sean Christopherson To: Nicusor CITU Cc: Adalbert =?utf-8?B?TGF6xINy?= , "kvm@vger.kernel.org" , "linux-mm@kvack.org" , "virtualization@lists.linux-foundation.org" , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Konrad Rzeszutek Wilk , Tamas K Lengyel , Mathieu Tarral , Samuel =?iso-8859-1?Q?Laur=E9n?= , Patrick Colp , Jan Kiszka , Stefan Hajnoczi , Weijiang Yang , "Zhang@vger.kernel.org" , Yu C , Mihai =?utf-8?B?RG9uyJt1?= Subject: Re: [RFC PATCH v6 55/92] kvm: introspection: add KVMI_CONTROL_MSR and KVMI_EVENT_MSR Message-ID: <20190819183643.GB1916@linux.intel.com> References: <20190809160047.8319-1-alazar@bitdefender.com> <20190809160047.8319-56-alazar@bitdefender.com> <20190812210501.GD1437@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Thu, Aug 15, 2019 at 06:36:44AM +0000, Nicusor CITU wrote: > > > + void (*msr_intercept)(struct kvm_vcpu *vcpu, unsigned int msr, > > > + bool enable); > > > > This should be toggle_wrmsr_intercept(), or toggle_msr_intercept() > > with a paramter to control RDMSR vs. WRMSR. > > Ok, I can do that. > > > > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > > > index 6450c8c44771..0306c7ef3158 100644 > > > --- a/arch/x86/kvm/vmx/vmx.c > > > +++ b/arch/x86/kvm/vmx/vmx.c > > > @@ -7784,6 +7784,15 @@ static __exit void hardware_unsetup(void) > > > free_kvm_area(); > > > } > > > > > > +static void vmx_msr_intercept(struct kvm_vcpu *vcpu, unsigned int > > > msr, > > > + bool enable) > > > +{ > > > + struct vcpu_vmx *vmx = to_vmx(vcpu); > > > + unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap; Is KVMI intended to play nice with nested virtualization? Unconditionally updating vmcs01.msr_bitmap is correct regardless of whether the vCPU is in L1 or L2, but if the vCPU is currently in L2 then the effective bitmap, i.e. vmcs02.msr_bitmap, won't be updated until the next nested VM-Enter. > > > + > > > + vmx_set_intercept_for_msr(msr_bitmap, msr, MSR_TYPE_W, enable); > > > +} > > > > Unless I overlooked a check, this will allow userspace to disable > > WRMSR interception for any MSR in the above range, i.e. userspace can > > use KVM to gain full write access to pretty much all the interesting > > MSRs. This needs to only disable interception if KVM had interception > > disabled before introspection started modifying state. > > We only need to enable the MSR interception. We never disable it - > please see kvmi_arch_cmd_control_msr(). In that case, drop @enable and use enable_wrmsr_intercept() or something along those lines for kvm_x86_ops instead of toggle_wrmsr_intercept().