Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6026610rwd; Mon, 5 Jun 2023 11:51:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6bIaylksm64s6FI3kVXeOe7azQ3KyIfeFJ9CL5hc01kWeIVOziCNqeqiuncphgP1gXi/20 X-Received: by 2002:a05:6214:dc8:b0:626:ca8:e4f7 with SMTP id 8-20020a0562140dc800b006260ca8e4f7mr11013694qvt.56.1685991061990; Mon, 05 Jun 2023 11:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685991061; cv=none; d=google.com; s=arc-20160816; b=oNXU4waOhJpjju6JnLLskR1veGjaPqS6JVQxY06lgrur4pYGFWJpHbRAEPeN3c+d1k yg5LX/8tIWAzFrfbzl3GL2ro91ML6+9EbkXaVGyb6okVkgjj+bK3gHAFKDV2biTIFkTU oJQWm0ghE3FowZ4b0uYvFYIYB3ChuK6mbD8oO1PIbVWF+bNJwuanexDa9d4FvOH2nU/0 P1uPdPVWD29cv/FnCRueT5WiBCJ+FRze8ztJUQTZclQ4ouaBveIWmTGekH0LDe9FTAO7 aG+HVEemDNYS2RMOL4mWRy4/VFTzgGAWOTZzKej86lEvAz5NpcMjTRL0Sf39cmJWMiuF tLaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=IO/Fs3eGWzo23DrzeVi6xYXoO5D8M7e0QwyLF6JWXrg=; b=HKQ4fz1CVQW5ARtRR21nzsXQLJ6MrPA/SdJAZv3acLDGSmtxVWpZ+D6D0VdiAIt/3U hp/3LWvIQZXUeTKSUwJUZ0CLkapXJm/eJGZpv3G21XaZViztVT2VR3u7ElU1aDbP0HX7 jPGgi6kkB4cO64H7Ydq7N9pbufeYnOKib1SYEmolObjOGb4ro4LYT21KyqqOneKBYRCm 2RfqxF6/iWZXQLAb2sDgpAYZ4ncjhauLdARZ5vNDacdnwR6k/6LsfyXsD3/SSaLOuGAK 7pUZOWsJynB+pGaWhToOpvxYMUy/Xkk3+X2snmANH7cz3YfXutOBnfispbht1LdNq6Fo 3YJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ycRoK2Of; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020ad45ae1000000b00625b5ee1e47si5480709qvh.368.2023.06.05.11.50.48; Mon, 05 Jun 2023 11:51:01 -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=@google.com header.s=20221208 header.b=ycRoK2Of; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235428AbjFESbo (ORCPT + 99 others); Mon, 5 Jun 2023 14:31:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235305AbjFESbl (ORCPT ); Mon, 5 Jun 2023 14:31:41 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB306F4 for ; Mon, 5 Jun 2023 11:31:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-bb2202e0108so6092753276.1 for ; Mon, 05 Jun 2023 11:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685989897; x=1688581897; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=IO/Fs3eGWzo23DrzeVi6xYXoO5D8M7e0QwyLF6JWXrg=; b=ycRoK2OfE9MEm1ayzDiR63HOQqu8GiIfBSQVBKpNGRHXt5GdzNLQRrq7NwCVD6vG3U ZQWh4PjDb5hstSmguBpzROCAC+EnQQfgZbqXUCOuPoMCqVALO9JHWg0EPyz2UPOuzDvg eP9kjPGLYVCejjfWdVh9/11Ea8S8eTMEfBDOCDXbovxOJ/XsvTL0J58jwVfMYRq5w5oB 9q++eh1qTFl1szhzEBhCYIT1W0LM5yGC575YzxsZ4VWd+TUFUP53RQHECjtVW+f+kIm/ myhvUEVRvdfpwdilcp0kaQ6s1aMZVgHMSa/LUtGFpY9k1gGTPOA5mAZXVtv4bOJPNp2G GVLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685989897; x=1688581897; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=IO/Fs3eGWzo23DrzeVi6xYXoO5D8M7e0QwyLF6JWXrg=; b=UKMcRAR0WplDPk6C2q2eEcBmDET+y0ScLL/VW8QVh09qM2nJnAFjxuoj/XGToSoktv c+f+TKH+23yE60kg3Zs5272hHXe+R/mfPg1xq77TVVuuanSbJfTizceIJB7IkCE/yyEA mD2N8sSbCOKpVvsUjUoyS+jBaY4zr9zlEEvUMOv42WDiCGqsCdZRqrYJvbaviUXvx+XT qzY/vE1X73sWzEwdki+1oa1AqGmCjhy0sn1c8jbYeBEoOlGsIYqYmaWIQjNAfh4Q8yrh wYVj4qmIK51Mc5ZbNtoJ6e5KLiF+y7zMgJX4oYfDConKHRo0p+8qc8X824ykCGXOZSTV nTfw== X-Gm-Message-State: AC+VfDzGY69+ugTRY8DJ8Vn1m075xlWt6qNlvRC/Mkkz79Vc2LlkLnuD oi3bGgmCZOISy1mdjAskaX2GjjeQfVU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:120d:b0:bb0:f056:cf43 with SMTP id s13-20020a056902120d00b00bb0f056cf43mr4262890ybu.1.1685989896966; Mon, 05 Jun 2023 11:31:36 -0700 (PDT) Date: Mon, 5 Jun 2023 11:31:34 -0700 In-Reply-To: <20230605173101.iflfly3bt6ydvvyk@desk> Mime-Version: 1.0 References: <20230531231820.trrs2uugc24gegj4@treble> <20230601004202.63yulqs73kuh3ep6@treble> <846dd0c5-d431-e20e-fdb3-a4a26b6a22ca@citrix.com> <20230601012323.36te7hfv366danpf@desk> <20230601042345.52s5337uz62p6aow@treble> <21D1D290-7DE9-4864-A05B-A36779D9DC26@nutanix.com> <20230605163552.hi5kvh5wijegmus6@treble> <20230605173101.iflfly3bt6ydvvyk@desk> Message-ID: Subject: Re: [PATCH] KVM: VMX: remove LFENCE in vmx_spec_ctrl_restore_host() From: Sean Christopherson To: Pawan Gupta Cc: Jon Kohler , Josh Poimboeuf , Andrew Cooper , 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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 Mon, Jun 05, 2023, Pawan Gupta wrote: > On Mon, Jun 05, 2023 at 04:39:02PM +0000, Jon Kohler wrote: > > >>> Yes. Though in practice it might not make much of a difference. W= ith > > >>> wrmsr+lfence, the lfence has nothing to do so it might be almost > > >>> instantaneous anyway. > > >>>=20 > > >>> --=20 > > >>> Josh > > >>=20 > > >> Coming back to this, what if we hoisted call vmx_spec_ctrl_restore_h= ost above > > >> FILL_RETURN_BUFFER, and dropped this LFENCE as I did here? > > >>=20 > > >> That way, we wouldn=E2=80=99t have to mess with the internal LFENCE = in nospec-branch.h, > > >> and that would act as the =E2=80=9Cfinal line of defense=E2=80=9D LF= ENCE. > > >>=20 > > >> Would that be acceptable? Or does FILL_RETURN_BUFFER *need* to occur > > >> before any sort of calls no matter what? > > >=20 > > > If we go by Intel's statement that only unbalanced RETs are a concern= , > > > that *might* be ok as long as there's a nice comment above the > > > FILL_RETURN_BUFFER usage site describing the two purposes for the > > > LFENCE. >=20 > We would then need FILL_RETURN_BUFFER to unconditionally execute LFENCE > to account for wrmsr branch misprediction. Currently LFENCE is not > executed for !X86_BUG_EIBRS_PBRSB. >=20 > > > However, based on Andy's concerns, which I've discussed with him > > > privately (but I'm not qualified to agree or disagree with), we may w= ant > > > to just convert vmx_spec_ctrl_restore_host() to asm. Better safe tha= n > > > sorry. My original implementation of that function was actually asm.= I > > > can try to dig up that code. >=20 > Note: >=20 > VMexit > CALL > RET > RET <---- This is also a problem if the first call hasn't retired ye= t. > LFENCE >=20 > Converting vmx_spec_ctrl_restore_host() to ASM should be able to take car= e > of this. Is there an actual bug here, or are we just micro-optimizing something that= may or may not need additional optimization? Unless there's a bug to be fixed, mo= ving code into ASM and increasing complexity doesn't seem worthwhile.