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=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 C7A3DC4360C for ; Fri, 27 Sep 2019 12:11:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A566320673 for ; Fri, 27 Sep 2019 12:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727323AbfI0MLc (ORCPT ); Fri, 27 Sep 2019 08:11:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43052 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfI0MLb (ORCPT ); Fri, 27 Sep 2019 08:11:31 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 436612A09D7 for ; Fri, 27 Sep 2019 12:11:31 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id w10so932944wrl.5 for ; Fri, 27 Sep 2019 05:11:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=QXXOvH8ng89IA6N3wSSYOp1Df58vyIL2WGnGFMauaUI=; b=r28zEo/46dIuH40OOgrGnWaynw2abK6MVZjdUO3qu/TpBQ5loAIkrWflPUA20iYPnq FPB/PjHGyTotyyZDGFd14yyCyAINXhF0SY0LwdAFfMazTl+wLcJ+L4cOHhYlNac9efDX 2tyB7zqxT5ep5jdGCqLBJlqXoK49mpaaXc61qtBSbrYYIjAVjNadGbTBbqpOlUlq7H7j mFEZbr2X7+O0z6r3+A/qPGx004jvpwqw6JqFjcXMc9liqlgAoxPIrKoPM3B3/b7gnY/c QCv2z3i+rVC7Ew03UGh0KvIycxRHpoZu1wolQwywDl1oWqF1ZJClCDMV8V/FQCkFy37Z IJ8g== X-Gm-Message-State: APjAAAUGpdJCcmwjsY44wbUj/V0UEML4QA3JEOrRM+xb57JpMEVztDBm mfbsrkH+52ehZLZluWq0lblJM59zlI6oUoqQMXT38GdTXhyv89gvomaZzCaIjXZ/dvTtJF6XMrV 8m+1CGxVUbGO7ir9B6vs6P1fF X-Received: by 2002:a5d:408c:: with SMTP id o12mr2895360wrp.312.1569586289941; Fri, 27 Sep 2019 05:11:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5ZyaW/h04/JYEn7HO5eYyw8sxSDs1W5SxMRjxONe1MWt8T0HxlpmbELtbQvVz+2LMKI0aHw== X-Received: by 2002:a5d:408c:: with SMTP id o12mr2895338wrp.312.1569586289720; Fri, 27 Sep 2019 05:11:29 -0700 (PDT) Received: from vitty.brq.redhat.com ([95.82.135.182]) by smtp.gmail.com with ESMTPSA id b144sm6822266wmb.3.2019.09.27.05.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 05:11:29 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reto Buerki Subject: Re: [PATCH 2/2] KVM: VMX: Skip GUEST_CR3 VMREAD+VMWRITE if the VMCS is up-to-date In-Reply-To: <20190926214302.21990-3-sean.j.christopherson@intel.com> References: <20190926214302.21990-1-sean.j.christopherson@intel.com> <20190926214302.21990-3-sean.j.christopherson@intel.com> Date: Fri, 27 Sep 2019 14:11:27 +0200 Message-ID: <87r242547k.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > Skip the VMWRITE to update GUEST_CR3 if CR3 is not available, i.e. has > not been read from the VMCS since the last VM-Enter. If vcpu->arch.cr3 > is stale, kvm_read_cr3(vcpu) will refresh vcpu->arch.cr3 from the VMCS, > meaning KVM will do a VMREAD and then VMWRITE the value it just pulled > from the VMCS. > > Note, this is a purely theoretical change, no instances of skipping > the VMREAD+VMWRITE have been observed with this change. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/vmx.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index b530950a9c2b..6de09f60edf3 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -3003,10 +3003,12 @@ void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) > > if (is_guest_mode(vcpu)) > skip_cr3 = true; > - else if (enable_unrestricted_guest || is_paging(vcpu)) > - guest_cr3 = kvm_read_cr3(vcpu); > - else > + else if (!enable_unrestricted_guest && !is_paging(vcpu)) > guest_cr3 = to_kvm_vmx(kvm)->ept_identity_map_addr; > + else if (test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail)) Nit: with 'test_bit(,(ulong *)&vcpu->arch.regs_avail)' spreading more and more I'd suggest creating an inline in kvm_cache_regs.h (e.g. kvm_vcpu_reg_avail()). > + guest_cr3 = vcpu->arch.cr3; > + else > + skip_cr3 = true; /* vmcs01.GUEST_CR3 is up-to-date. */ > ept_load_pdptrs(vcpu); > } -- Vitaly