Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp15446ybx; Mon, 4 Nov 2019 15:02:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyCKrsq7bmkZO3x8LMoysrjhaLeqw6WxYq8a3fWsxo8L/EVOH/y3GuNu/aN/tQloA2jAgnN X-Received: by 2002:aa7:d0c4:: with SMTP id u4mr13772170edo.8.1572908526939; Mon, 04 Nov 2019 15:02:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572908526; cv=none; d=google.com; s=arc-20160816; b=Y19vOv8ePHzsLj5Uym2koFbS7EQRhkmFcepkQOeuH1DdoZnF7pHpXDuHPGjLSxXLxT Y20VcmEnnbwRtYOvtLTNuaLbX5AIvJZxDFwpxKIBeQny4tsbuIUwcogSbUC/Uw0Jt2Dh jrbKJo9LvsPXfVFSnAH6HeLOUhPV6INw81rrm8eeiPY3ukNg9gq1LJWQtCGmoIBZvUDY QqCxbs/Im2PDwfGo7wdhm93k/vNKUGSBR+fDkxnYHmj8RGuu9WTvzik5iOvSYJrVZ0o6 +o8azphPqsRYbWk4OxL+h6UxvCFlNI1Vum3hXqU5ZKZxfQAaWM3m6J6I7Z7DaEx7mKfS 69mg== 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 :dkim-signature; bh=iTr27IQdavuGNLXbOWTD/Ig9akRCUdhnHXeA7w4Wy5w=; b=G5/CjByEL43ujnx9UQDahVpuqlNQ8Pk2AE3wz/PpYlBXhvFPOTUONTG+7WuwwTYYGK Ip5gnakb7twS0xVIXLSRHdXDldvKP3hlw47d8IeqyTztLN/JEj0uSgNmv1BZ6jPFVS36 vk3XJFVTl9WkfW2QBhViSfn20o1Tk8JN6so2VgGB777aU1W3bpRPkommEitKNSkP7qYl MiOuXFacuJzO6WY/kexp+Nwl+IYBceyecThaMmHImPeRsynoMFSzqQwFt2gG8YMMULtq cUvk3zW0uoT1OjeuuKfDkBiXstSPqL3nkVcYFy+6HC4BQ89ZqY1dAudq+933nYBd3hiF 7fsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=auJTpblf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si9675464edc.146.2019.11.04.15.01.43; Mon, 04 Nov 2019 15:02:06 -0800 (PST) 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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=auJTpblf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730160AbfKDXAR (ORCPT + 99 others); Mon, 4 Nov 2019 18:00:17 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52154 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730094AbfKDXAP (ORCPT ); Mon, 4 Nov 2019 18:00:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572908414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iTr27IQdavuGNLXbOWTD/Ig9akRCUdhnHXeA7w4Wy5w=; b=auJTpblfzx/tucZ1iNPsoW26ryeUoMqqKetNAy1aQgF4NzDcLH4DhFfy/pDQpAA5i2bIFF TrWoMyFqmQ0vB9HMlcO4poEVM3ZPcSFxKwdOnFY1sVYinSEVV8knEkYJpd9C9ZBT7X1tAd Q/unPGLvSUK0HcEsCIfTXb+qdPnVqkw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-32-0FcWTpJVP6qsaDpEdFTbnA-1; Mon, 04 Nov 2019 18:00:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2BB65EA; Mon, 4 Nov 2019 23:00:09 +0000 (UTC) Received: from mail (ovpn-121-157.rdu2.redhat.com [10.10.121.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 49C6060BF3; Mon, 4 Nov 2019 23:00:09 +0000 (UTC) From: Andrea Arcangeli To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paolo Bonzini , Vitaly Kuznetsov , Sean Christopherson Subject: [PATCH 11/13] KVM: retpolines: x86: eliminate retpoline from vmx.c exit handlers Date: Mon, 4 Nov 2019 17:59:59 -0500 Message-Id: <20191104230001.27774-12-aarcange@redhat.com> In-Reply-To: <20191104230001.27774-1-aarcange@redhat.com> References: <20191104230001.27774-1-aarcange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: 0FcWTpJVP6qsaDpEdFTbnA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's enough to check the exit value and issue a direct call to avoid the retpoline for all the common vmexit reasons. Of course CONFIG_RETPOLINE already forbids gcc to use indirect jumps while compiling all switch() statements, however switch() would still allow the compiler to bisect the case value. It's more efficient to prioritize the most frequent vmexits instead. The halt may be slow paths from the point of the guest, but not necessarily so from the point of the host if the host runs at full CPU capacity and no host CPU is ever left idle. Signed-off-by: Andrea Arcangeli --- arch/x86/kvm/vmx/vmx.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index a6afa5f4a01c..582f837dc8c2 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5905,9 +5905,23 @@ int kvm_x86_handle_exit(struct kvm_vcpu *vcpu) =09} =20 =09if (exit_reason < kvm_vmx_max_exit_handlers -=09 && kvm_vmx_exit_handlers[exit_reason]) +=09 && kvm_vmx_exit_handlers[exit_reason]) { +#ifdef CONFIG_RETPOLINE +=09=09if (exit_reason =3D=3D EXIT_REASON_MSR_WRITE) +=09=09=09return kvm_emulate_wrmsr(vcpu); +=09=09else if (exit_reason =3D=3D EXIT_REASON_PREEMPTION_TIMER) +=09=09=09return handle_preemption_timer(vcpu); +=09=09else if (exit_reason =3D=3D EXIT_REASON_PENDING_INTERRUPT) +=09=09=09return handle_interrupt_window(vcpu); +=09=09else if (exit_reason =3D=3D EXIT_REASON_EXTERNAL_INTERRUPT) +=09=09=09return handle_external_interrupt(vcpu); +=09=09else if (exit_reason =3D=3D EXIT_REASON_HLT) +=09=09=09return kvm_emulate_halt(vcpu); +=09=09else if (exit_reason =3D=3D EXIT_REASON_EPT_MISCONFIG) +=09=09=09return handle_ept_misconfig(vcpu); +#endif =09=09return kvm_vmx_exit_handlers[exit_reason](vcpu); -=09else { +=09} else { =09=09vcpu_unimpl(vcpu, "vmx: unexpected exit reason 0x%x\n", =09=09=09=09exit_reason); =09=09dump_vmcs();