Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1795587pxy; Fri, 23 Apr 2021 17:55:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVJicLzvRbunLzgSI6hCibtgTuyRvi3HCWFbGe9rBmiC+XiSXP6gajjlqRdFMbHpZFB0nx X-Received: by 2002:a17:907:2177:: with SMTP id rl23mr6910049ejb.160.1619225729430; Fri, 23 Apr 2021 17:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619225729; cv=none; d=google.com; s=arc-20160816; b=gl3y1Tt/ibZaKXQHnz4CgnUuJ5i08sdMcN7XDg7sBNmbzYKp2ipSGQDS6nyDEwcnGs mhEznaaFd4uI8fdeV1JlfkZmuoYZyWedpSUhssErXeytpV5fcW7+EiyBpC8Jwci9iNdk nT4O08dSIZbvcRyJMj8Q7lYnqyHq9h1qE2brGRcO12T2U2Td+db0LJlMfqMFE6spXmgj HANpuvXKqvNdujVOjK3FsXPX1von2NRnQdWp9JFcfElg8dp/OglLfVYuEqHy2G8/IlCw IiOU1P3NfLB7aCL4nlXFeL4sosuqZBNBCKKCSFhnzmACEo5N+KqXNimjfAoSSjKXJqB9 Psyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=BdoSnjJxYw1zfGUU/Z7GRrV8PpQo7mVoIG98cidoNPE=; b=N13K/0qQaM7hfHywc0wDwJE+1g6Oy+Snm+D4wVVPDXgxKCa5QA0KbbhCiS8pNHM1f6 W+uvGrIZO92EVS4LltT23T1KI412xOdcsMe3oAeoYd5EXBJh12NVZohfFAODEcyNcydH RRBFHv3FOSNC8DSoF14dHnrUYYiYHCeNduxzJmYUZ46FJEBHCdv0CyQg2sZZwJSdwx7w TshhM5jwcIesisy6BQ1IqFXeyHgxdlAfWGR4EcTNK93vLagaeqoUPc1Ok4tPBUc7TOyD L0zmIMZwXcIMu14AKs5OBfkqf0pr8K1VlJ9Y3tLLJb68DirYmgIQEcqyyZHN8tEoOPQb xijA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZXyR7PW5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si5878174ejg.212.2021.04.23.17.55.06; Fri, 23 Apr 2021 17:55:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZXyR7PW5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244411AbhDXAyk (ORCPT + 99 others); Fri, 23 Apr 2021 20:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244410AbhDXAxG (ORCPT ); Fri, 23 Apr 2021 20:53:06 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB6E2C0612EF for ; Fri, 23 Apr 2021 17:48:11 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id a7-20020a5b00070000b02904ed415d9d84so4617225ybp.0 for ; Fri, 23 Apr 2021 17:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=BdoSnjJxYw1zfGUU/Z7GRrV8PpQo7mVoIG98cidoNPE=; b=ZXyR7PW511+wiI+r2z9sDLy0bn0R5t8+YYcLnYmh7WaFjgQWhFS6rovcK5dI6JHnlf KI+2ZzBslvkOwq2PEeWwR9ep+zwT7rrBaLcQkBX/RbCQxCxGjt7ypzGich2z8BnjhR4s qISIoA1jRnc5m3+Wk56tidUt6Zvx4lRgcTUDITmRZtq2YTrj+l4As3q4u4RtfEQ7SoT7 8/Xyso6YE9kY7cN+qAtFpwWyWusn8447Xu0ZG8v99Xn2XUxUBz9nVtdjEURfL7YbeTsa 9byiJ2akf/jQbdqZvhAgyf2enceQnK8WKNOs+E69qt6hTgsUJ4scu6PlzJXpcKyTmULh fCVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=BdoSnjJxYw1zfGUU/Z7GRrV8PpQo7mVoIG98cidoNPE=; b=dM+d7a3dxJhDudKmJx9Zkt6ltdYYHbP/wye1rEKxkt2UJyX0/B3w3phOnyrdABrMIt 7idVVtLpyNnWjJ1Ibp2+HGhGFL6Xw9Rs4dxyxYzp2sE/ffFGxF/juJe9ELOvP2VvZWhM R+0UIoBhc/cYQvTXB7x/CKQx3rz0NZbSeweM96Ln42Nq/EhpddOM242Q/2bjd8jXhSG7 DySK8LYwdSgGvalUHgUh7OgIXTJERPbcGPqIZs/k/nCEZE5kRjSsgqFTrT9MCv8mdY6C kmsUzqrBrj6+yM/guIIUbow9l4ob+aH9jFT1OhA7b5GXAYYzxHD0EwFt/7pSRhqylGPu ZyNg== X-Gm-Message-State: AOAM532e5N5AmVglCcTyf5hMlBGPLhfwavZZwlxruMJ9aFOZMSYNnuOH oQFLm4ddSyIZd/SQJUh5NyQzaDrysFk= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:ad52:3246:e190:f070]) (user=seanjc job=sendgmr) by 2002:a25:9a01:: with SMTP id x1mr9232033ybn.269.1619225291193; Fri, 23 Apr 2021 17:48:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 23 Apr 2021 17:46:34 -0700 In-Reply-To: <20210424004645.3950558-1-seanjc@google.com> Message-Id: <20210424004645.3950558-33-seanjc@google.com> Mime-Version: 1.0 References: <20210424004645.3950558-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH 32/43] KVM: VMX: Skip pointless MSR bitmap update when setting EFER From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split setup_msrs() into vmx_setup_uret_msrs() and an open coded refresh of the MSR bitmap, and skip the latter when refreshing the user return MSRs during an EFER load. Only the x2APIC MSRs are dynamically exposed and hidden, and those are not affected by a change in EFER. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 594975dc3f94..bdfb3def8526 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1767,11 +1767,12 @@ static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr) } /* - * Set up the vmcs to automatically save and restore system - * msrs. Don't touch the 64-bit msrs if the guest is in legacy - * mode, as fiddling with msrs is very expensive. + * Configuring user return MSRs to automatically save, load, and restore MSRs + * that need to be shoved into hardware when running the guest. Note, omitting + * an MSR here does _NOT_ mean it's not emulated, only that it will not be + * loaded into hardware when running the guest. */ -static void setup_msrs(struct vcpu_vmx *vmx) +static void vmx_setup_uret_msrs(struct vcpu_vmx *vmx) { vmx->guest_uret_msrs_loaded = false; vmx->nr_active_uret_msrs = 0; @@ -1793,9 +1794,6 @@ static void setup_msrs(struct vcpu_vmx *vmx) vmx_setup_uret_msr(vmx, MSR_TSC_AUX); vmx_setup_uret_msr(vmx, MSR_IA32_TSX_CTRL); - - if (cpu_has_vmx_msr_bitmap()) - vmx_update_msr_bitmap(&vmx->vcpu); } static u64 vmx_write_l1_tsc_offset(struct kvm_vcpu *vcpu, u64 offset) @@ -2982,7 +2980,7 @@ int vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer) msr->data = efer & ~EFER_LME; } - setup_msrs(vmx); + vmx_setup_uret_msrs(vmx); return 0; } @@ -4572,7 +4570,10 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) if (kvm_mpx_supported()) vmcs_write64(GUEST_BNDCFGS, 0); - setup_msrs(vmx); + vmx_setup_uret_msrs(vmx); + + if (cpu_has_vmx_msr_bitmap()) + vmx_update_msr_bitmap(&vmx->vcpu); vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ -- 2.31.1.498.g6c1eba8ee3d-goog