Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2238461imm; Thu, 7 Jun 2018 07:32:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLUsNZ1ZQXWVCxhAkP3LtFHT7x0qkJwedqqOvw2Z9hE0G/ox8wrsDbiuGUP4C59PjF5EQ+3 X-Received: by 2002:a17:902:683:: with SMTP id 3-v6mr2302442plh.291.1528381925522; Thu, 07 Jun 2018 07:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528381925; cv=none; d=google.com; s=arc-20160816; b=zyH3iGbuluAh/ZaYc4Z0O8DWabaeqhum0gh4QnMx8lvCEqMhsgFiCF+oryf0a+2shn wAUhcM5wE2b9IvKzfGeAOxxoQtQaINGyqUXQBl69abH9Ibjym5dBq+ZMYpAOr8RfvEUT xbnk7cY1eeKZSdlPCQUIQpj4U+I0LNggfU+lVmQ+1m5pIKDJAs7eXqVUmfwLWywZEt1/ LEkI2Kiy4VgRiTSE4m78eekYXp/qoGewxyXtU92Z+xoMeJ/m0PtVtp1tBK8TPsRkBraj tDkoW+C1oLZMrQKha5jw/Kq0xoW4WioczfyHRkhjUNltNoiY1rYsj0BredPxkEg6wbCU 91Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=wrvHaPYZpztmF/Y6v7bo1HIse6irxh2lEo0RTJuPjig=; b=ge+aAoiGPVk+83LhH9jIUdahobiFdRoJpP5LtgriYBUhP8nGgOdlXrErC1D77IphKq cQ7uOkzaEwSUl/au6piEBUpzmSsbZ4HhPTTYKT+ypN2ay0E4U8g6LQ81Yr0YX1AlskMI cKhAV1chtT6wtmGx49nJFAClfnEQ2fn9lyK7wxohNhhvyVxHDEBoja056Anh8ixgnlVT ov/IpwSac78JIAwItomz7BtfG4CGCjaqhGD15j0jnEcm/R4/ryV12W5WbThzAFFGxrCF qtTnhGQYXniUfS0RycNdSQ/YWzQT23+HQVSts9AHtO/510s0UmtCb8Q/oBBJr89y6/rc C5wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a65-v6si26644910pfa.148.2018.06.07.07.31.51; Thu, 07 Jun 2018 07:32:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933701AbeFGO30 (ORCPT + 99 others); Thu, 7 Jun 2018 10:29:26 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40218 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932915AbeFGO3X (ORCPT ); Thu, 7 Jun 2018 10:29:23 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbw-0005Zw-TI; Thu, 07 Jun 2018 15:09:57 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvaz-0002l1-IR; Thu, 07 Jun 2018 15:08:57 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Paolo Bonzini" , "Ingo Molnar" , "David Woodhouse" , "Peter Zijlstra" , "Jim Mattson" , "Radim =?UTF-8?Q?Kr=C4=8Dm=C3=A1=C5=99?=" , "KarimAllah Ahmed" , kvm@vger.kernel.org, "Thomas Gleixner" , "Linus Torvalds" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 061/410] KVM/VMX: Optimize vmx_vcpu_run() and svm_vcpu_run() by marking the RDMSR path as unlikely() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Bonzini commit 946fbbc13dce68902f64515b610eeb2a6c3d7a64 upstream. vmx_vcpu_run() and svm_vcpu_run() are large functions, and giving branch hints to the compiler can actually make a substantial cycle difference by keeping the fast path contiguous in memory. With this optimization, the retpoline-guest/retpoline-host case is about 50 cycles faster. Signed-off-by: Paolo Bonzini Reviewed-by: Jim Mattson Cc: David Woodhouse Cc: KarimAllah Ahmed Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Radim Krčmář Cc: Thomas Gleixner Cc: kvm@vger.kernel.org Link: http://lkml.kernel.org/r/20180222154318.20361-3-pbonzini@redhat.com Signed-off-by: Ingo Molnar [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- arch/x86/kvm/svm.c | 2 +- arch/x86/kvm/vmx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4077,7 +4077,7 @@ static void svm_vcpu_run(struct kvm_vcpu * If the L02 MSR bitmap does not intercept the MSR, then we need to * save it. */ - if (!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL)) + if (unlikely(!msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL))) svm->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); if (svm->spec_ctrl) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -7673,7 +7673,7 @@ static void __noclone vmx_vcpu_run(struc * If the L01 MSR bitmap does not intercept the MSR, then we need to * save it. */ - if (!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL)) + if (unlikely(!msr_write_intercepted_l01(vcpu, MSR_IA32_SPEC_CTRL))) vmx->spec_ctrl = native_read_msr(MSR_IA32_SPEC_CTRL); if (vmx->spec_ctrl)