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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D7EAC77B7A for ; Wed, 31 May 2023 22:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbjEaWs2 (ORCPT ); Wed, 31 May 2023 18:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbjEaWs1 (ORCPT ); Wed, 31 May 2023 18:48:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0487311F; Wed, 31 May 2023 15:48:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 91811634AD; Wed, 31 May 2023 22:48:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E324C433EF; Wed, 31 May 2023 22:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685573304; bh=7+T+ESDx7lTbGl9478hJKHlghZjeUr+1ylaQB5WdoCw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A4HZtknVVOdPtECvEG05BMFKO+8SJ/FmPZBB2VNpW35jTADntXWLW9mYsjgOBALQb 8vnXKDsH6Ddnwm3zNTX8ebXtauMHXuyo1IF6lXWA014CJ//cuZfkhIoNxJ343QokCP UYYmG12bc3YqwbFRnSR3n3UvYGOwL1fcFBToVX6/TZsuw+yN7wqxClx8RbnfB6P+Y4 bqpcl5Pf/zcxrp7/gNbVgmCRQWt4u7kCjmXlvyQMg7NDjtzIia9w2K8Hxv4Oyrc1p9 tr0Ly6ssdaDo5sKICPS3+p0et0TqtvPOcvGTp3DVmTLQL1GQmQYFkYwRElIVYqrm9G td03KiCTyg+bg== Date: Wed, 31 May 2023 15:48:22 -0700 From: Josh Poimboeuf To: Jon Kohler Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Kees Cook , Andrea Arcangeli , Waiman Long , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Josh Poimboeuf Subject: Re: [PATCH v4] KVM: VMX: do not disable interception for MSR_IA32_SPEC_CTRL on eIBRS Message-ID: <20230531224822.ceglenvl6w5wfiar@treble> References: <20230531144128.73814-1-jon@nutanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230531144128.73814-1-jon@nutanix.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 31, 2023 at 10:41:28AM -0400, Jon Kohler wrote: > Avoid expensive rdmsr on every VM Exit for MSR_IA32_SPEC_CTRL on > eIBRS enabled systems iff the guest only sets IA32_SPEC_CTRL[0] (IBRS) > and not [1] (STIBP) or [2] (SSBD) by not disabling interception in > the MSR bitmap. Note: this logic is only for eIBRS, as Intel's guidance > has long been that eIBRS only needs to be set once, so most guests with > eIBRS awareness should behave nicely. We would not want to accidentally > regress misbehaving guests on pre-eIBRS systems, who might be spamming > IBRS MSR without the hypervisor being able to see it today. > > eIBRS enabled guests using just IBRS will only write SPEC_CTRL MSR > once or twice per vCPU on boot, so it is far better to take those > VM exits on boot than having to read and save this msr on every > single VM exit forever. This outcome was suggested on Andrea's commit > 2f46993d83ff ("x86: change default to spec_store_bypass_disable=prctl spectre_v2_user=prctl") > however, since interception is still unilaterally disabled, the rdmsr > tax is still there even after that commit. > > This is a significant win for eIBRS enabled systems as this rdmsr > accounts for roughly ~50% of time for vmx_vcpu_run() as observed > by perf top disassembly, and is in the critical path for all > VM-Exits, including fastpath exits. > > Opportunistically update comments for both MSR_IA32_SPEC_CTRL and > MSR_IA32_PRED_CMD to make it clear how L1 vs L2 handling works. > > Fixes: 2f46993d83ff ("x86: change default to spec_store_bypass_disable=prctl spectre_v2_user=prctl") > Signed-off-by: Jon Kohler Acked-by: Josh Poimboeuf -- Josh