Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3149088ybt; Mon, 22 Jun 2020 16:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPbMkSLBCDQDWOvglwd21NJIFk2KSCguynkxZJG87f8ZCxPQ4yer247j9nzsyqnROZ8bol X-Received: by 2002:a50:f058:: with SMTP id u24mr10245554edl.351.1592868995093; Mon, 22 Jun 2020 16:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592868995; cv=none; d=google.com; s=arc-20160816; b=JqP10xXxZpQT8AadmbV2R82gMi8b8J+qvmTTJPaq3J65Jv9LG0tPzq9i6uV5wNY3aK oYtTNFCWr/mGKm8eUFTybuUNvtul0+dEMiY+Tsp8Qgwc2nvW+NqESY+h1aSqBHog6R8Q 5F8p6wMPkGxX2cilV+TtITnANZJSSmGoGt0TdgLrpG2FQss4SQ8VyEAcK76wEVJlnTOb bT1V7ROzecwEKIB8PmzEEwkrUjMyuW7uGtMG8Z6VSr4nMcYBfGxB3euq5G8+gqWgS0F0 9g4I7yRW55oq4jRsA7RAszUejNG3CtScSFSYnuuCUiiz1CtgUPHzrQuv1V/llkRAdzcs jFMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=K0Nr84jdOXghVUtPTVjtG3C+lZf1iRFQENR7K0AwVZo=; b=jgMRtZt5eFRqGXJFoxYSFqp1GkVTebjVUqroYWUu30ykfcTmYeX55NRbNx+adJfhC2 91jvK+lmAbBgIBCCMYmEz+M7Ffhcf5cQstpGw+uhL6a9fd5lCTAf1tS5BIpC33xoF60i x5OtH7zIR7vO0LNDq4O+LLXnQuJfw2+HVS0mmyOtnW+dXERUVJ7WASc9NZZP3GtPCY+2 htW+Q7lFglNjl+EnzSsBWIDgxgAisdhuipM/J26szUlZQxxNIwZ26NJTDWyOluTc/M8I tJO7VMpnSK9Zuf8viKXSNd4nD2HCpqYrSXS69eUsYFRJWxDcGEsTPyZw/wEzrMu/WeEZ QXMw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l4si3604753ede.133.2020.06.22.16.36.12; Mon, 22 Jun 2020 16:36:35 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731523AbgFVWoq (ORCPT + 99 others); Mon, 22 Jun 2020 18:44:46 -0400 Received: from mga18.intel.com ([134.134.136.126]:27426 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731198AbgFVWm6 (ORCPT ); Mon, 22 Jun 2020 18:42:58 -0400 IronPort-SDR: /aa+26LgBxu85NVKIQQPdMbK0FgKzX3Hnp9ik4ONQl5GsYg0U/c/DT03dyk6WOofNuyOIGmlx7 PrvKyChbxGYQ== X-IronPort-AV: E=McAfee;i="6000,8403,9660"; a="131303576" X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="131303576" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2020 15:42:55 -0700 IronPort-SDR: tKrppNG3mwzVZRukBF6u1Hs7VizfIz28P7GOyMnJcUAPBG8CoLhTDbDdyU8JdOjWyOX5hZZZsU L2u1BBRSY6Bw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="264634933" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by fmsmga008.fm.intel.com with ESMTP; 22 Jun 2020 15:42:54 -0700 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 Subject: [PATCH 11/15] KVM: VMX: Add vmx_setup_uret_msr() to handle lookup and swap Date: Mon, 22 Jun 2020 15:42:45 -0700 Message-Id: <20200622224249.29562-12-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200622224249.29562-1-sean.j.christopherson@intel.com> References: <20200622224249.29562-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add vmx_setup_uret_msr() to wrap the lookup and manipulation of the uret MSRs array during setup_msrs(). In addition to consolidating code, this eliminates move_msr_up(), which while being a very literally description of the function, isn't exacly helpful in understanding the net effect of the code. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 49 ++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 8731ca8ca2b0..f3cd1de7b0ff 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1714,12 +1714,15 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu) vmx_clear_hlt(vcpu); } -/* - * Swap MSR entry in host/guest MSR entry array. - */ -static void move_msr_up(struct vcpu_vmx *vmx, int from, int to) +static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr) { struct vmx_uret_msr tmp; + int from, to; + + from = __vmx_find_uret_msr(vmx, msr); + if (from < 0) + return; + to = vmx->nr_active_uret_msrs++; tmp = vmx->guest_uret_msrs[to]; vmx->guest_uret_msrs[to] = vmx->guest_uret_msrs[from]; @@ -1733,42 +1736,26 @@ static void move_msr_up(struct vcpu_vmx *vmx, int from, int to) */ static void setup_msrs(struct vcpu_vmx *vmx) { - int nr_active_uret_msrs, index; - - nr_active_uret_msrs = 0; + vmx->guest_uret_msrs_loaded = false; + vmx->nr_active_uret_msrs = 0; #ifdef CONFIG_X86_64 /* * The SYSCALL MSRs are only needed on long mode guests, and only * when EFER.SCE is set. */ if (is_long_mode(&vmx->vcpu) && (vmx->vcpu.arch.efer & EFER_SCE)) { - index = __vmx_find_uret_msr(vmx, MSR_STAR); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); - index = __vmx_find_uret_msr(vmx, MSR_LSTAR); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); - index = __vmx_find_uret_msr(vmx, MSR_SYSCALL_MASK); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); + vmx_setup_uret_msr(vmx, MSR_STAR); + vmx_setup_uret_msr(vmx, MSR_LSTAR); + vmx_setup_uret_msr(vmx, MSR_SYSCALL_MASK); } #endif - if (update_transition_efer(vmx)) { - index = __vmx_find_uret_msr(vmx, MSR_EFER); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); - } - if (guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP)) { - index = __vmx_find_uret_msr(vmx, MSR_TSC_AUX); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); - } - index = __vmx_find_uret_msr(vmx, MSR_IA32_TSX_CTRL); - if (index >= 0) - move_msr_up(vmx, index, nr_active_uret_msrs++); + if (update_transition_efer(vmx)) + vmx_setup_uret_msr(vmx, MSR_EFER); - vmx->nr_active_uret_msrs = nr_active_uret_msrs; - vmx->guest_uret_msrs_loaded = false; + if (guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP)) + 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); -- 2.26.0