Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp39650rwd; Wed, 31 May 2023 18:41:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75dWmpQfGQV13l4c9eOTWe8kDAGejzBtNIk00DNMsapIQa6In86b1nkcWQ0pIKjyR0A3Tf X-Received: by 2002:a05:6a20:3c8e:b0:10c:b1b0:3ee3 with SMTP id b14-20020a056a203c8e00b0010cb1b03ee3mr440802pzj.21.1685583691255; Wed, 31 May 2023 18:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685583691; cv=none; d=google.com; s=arc-20160816; b=klH8OMe0bD4swDXyUlFulk8Ndg/PmF2XIdFWkhincrBvsbhhyDNNmQyfEqfolSHLD4 2yJ+IHvdsRpsZsoqhe27bJNySK39+oENMHqKcp2KOaXUje6UPrIYa6j6d5TxHHLivtho ogqQiKkqRTcPCZCLrEryzhn5FzkXGuHTZmSxcfsrzeVeAhqZUlMXDCzxCf6k/9qdd+7U pgjnWjbwFllmwuTzseaiHyoRlyZgGLeDIu9SeRunX9QcB1IcjzF5wACw9H4PCsBZyobS v8A2XUEVPRV99oc61zcMpzZf+vN9qefQTC41mX4UaFvYTdtQ80xRfnwBtv372yLdQW9K 7PtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iPZgWgYDKOFveroklTWoX3BKrcCDLCH5At43FLqZK64=; b=NvceoDVDus5goB7623nQucDg9Lvu3iL5AWea21d3861B24MdViandTw7l/s+tENj32 PkZlbGXecS6U+ebWcXBE/y3VM4APHC15tC5TriP7p3z5rSNJC17MqDLUc+uDm4K4epC7 XE/kiLL4VKeOyOUiLuZBMAyHOBF8gkPvc+1v6QUgLU1V//Ehy8qC1Mob22Ht6rfzfGsz /GhN7IcojU2/gQL7Utihb2yV4db7+kkG/7WqpxmLpUkUApsC4HoKBvcAiW/cVuC4yZib ml7Jd1x9OuQM1gcCMevRn0tBaR93Rnbn/0JkrzTBY1YjbMzLbqAD56Oyt8MXDxMYIDF6 qByw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mpt+Z++t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v3-20020a655c43000000b0053427a98b7asi2049761pgr.146.2023.05.31.18.41.16; Wed, 31 May 2023 18:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mpt+Z++t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230391AbjFABYw (ORCPT + 99 others); Wed, 31 May 2023 21:24:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjFABYp (ORCPT ); Wed, 31 May 2023 21:24:45 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3B5101; Wed, 31 May 2023 18:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685582684; x=1717118684; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=MEEMrxv7tA0YbZIe/40VKopn6R+fUhfu8ONccvTrMVU=; b=Mpt+Z++txwoOEU/Vj6pfBZf6RRNAcgEdd29m6wfzZVkc1RLHNIIoHerb nfdegvTisy8Gt7TDafFUX/zW+fVhUeh1SbGt954hzxJFzHDtvIW2lrrh1 IrZP8BlSs9h1h0ZsY80x7HJBVtA+c0heb2RM6nytRNlPh7WlNXkZqLvFr PKrhVjXbtCxMIzjVJvH6eCjmAWH1tvHB99ReL3+4KzvgbwuH2OhgaPZdN 5Vqod+JKekrrnx6Ko3s9ML9buqttxM/rXr3QdVVigUGkny5LD+SJv1S4n AdCT781pxRg0MVdwyylnMLbZ+e6UWPZYxXxmadGziePXGdYRJqE8fBat+ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10727"; a="357815158" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="357815158" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 18:24:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10727"; a="684634736" X-IronPort-AV: E=Sophos;i="6.00,207,1681196400"; d="scan'208";a="684634736" Received: from ksauluck-mobl.amr.corp.intel.com (HELO desk) ([10.212.165.26]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2023 18:24:30 -0700 Date: Wed, 31 May 2023 18:24:29 -0700 From: Pawan Gupta To: Andrew Cooper Cc: Josh Poimboeuf , Jon Kohler , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , "Peter Zijlstra (Intel)" , Daniel Sneddon , "kvm @ vger . kernel . org" , LKML Subject: Re: [PATCH] KVM: VMX: remove LFENCE in vmx_spec_ctrl_restore_host() Message-ID: <20230601012323.36te7hfv366danpf@desk> References: <20230531150112.76156-1-jon@nutanix.com> <20230531231820.trrs2uugc24gegj4@treble> <20230601004202.63yulqs73kuh3ep6@treble> <846dd0c5-d431-e20e-fdb3-a4a26b6a22ca@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <846dd0c5-d431-e20e-fdb3-a4a26b6a22ca@citrix.com> X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 01, 2023 at 01:50:48AM +0100, Andrew Cooper wrote: > On 01/06/2023 1:42 am, Josh Poimboeuf wrote: > > So each LFENCE has a distinct purpose. That said, there are no indirect > > branches or unbalanced RETs between them. > > How lucky are you feeling? > > You're in C at this point, which means the compiler could have emitted a > call to mem{cpy,cmp}() in place of a simple assignment/comparison. Moving the second LFENCE to the else part of WRMSR should be possible? So that the serialization can be achived either by WRMSR or LFENCE. This saves an LFENCE when host and guest value of MSR_SPEC_CTRL differ. --- diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d2d6e1b6c788..d32e6d172dd6 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7157,8 +7157,8 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx, if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) || vmx->spec_ctrl != hostval) native_wrmsrl(MSR_IA32_SPEC_CTRL, hostval); - - barrier_nospec(); + else + barrier_nospec(); } static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu)