Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4297684rwb; Tue, 8 Nov 2022 15:11:11 -0800 (PST) X-Google-Smtp-Source: AMsMyM6oeqfWYuZsYaDhPzTWKK89Q2r7KNWhDj0DI/wGPLP61lCP4S9Pvp3vFrY2xabCxSVtUcn/ X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr59425712edb.347.1667949071637; Tue, 08 Nov 2022 15:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667949071; cv=none; d=google.com; s=arc-20160816; b=i9DeJlJ1OZAefHah4wqYsOMNfjX2rcycgoo0ePOQ+WFswUsHf2qwZ6zaqz79qNVxX8 PYxRw+elVyw/1yAh3F/wegJsQlig6GPMP4oi5z7J4cs2QL67fqwqVp/JAaMTpIBW+N/o ZZcH086NrluL27G4GO0UZW4btlLgsM+/1+sinYCYGmqIY3fY5REoWKPbpVA/vz+X89Bb Yt66NKOVQczwxut1IZ1ENBlzHQzMarFoO1GoPA3a8OXkenN+Wu2ZjY7hXucTxBzqPs/N VgwxSHJs8WeKlU/IfaUG3UCR3ZUfvGf4tgIlL2/t99qenZh2Jpex2ljEZQ/EyOm1HaOF R9TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BksNmJr9/G65J0IUfruVbXUCosG4IvOng5/LXlEyWfc=; b=F26OHCyydpZMjKeEYp9j0Ywo8S0pQNElPn+Z4Jy4+XtAWqCH0JdjPRilRyh0EV5HLA 7zrCmQ301UO68Bw+NS/vfT7nAt5vfKoPtS/DxsivrXx500VbdnK3HNEOV49MdzPVp2gg lF/bsczRJOEtnMs2rgkeWTzFG6TxwND+3Vvatocqj9Le20E0wH5hnjaBK+lIkN4hQdvX JUdz69d06IGMraDVVyndSHnsj6Bepf60a0rmgA7g5LFFoQ7SU8fC5n4EIjbOC/2E51+5 8YF+GeBv4TZYC29i2ENhKHebIFXAko1Ta2cXBz8xhZ+qU4l4DmFxa04oJisUuzIzZL3k K9Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sP90Hxk8; 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 di19-20020a170906731300b0078de8d119d5si16762316ejc.899.2022.11.08.15.10.47; Tue, 08 Nov 2022 15:11:11 -0800 (PST) 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=20210112 header.b=sP90Hxk8; 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 S229868AbiKHW71 (ORCPT + 92 others); Tue, 8 Nov 2022 17:59:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiKHW7Y (ORCPT ); Tue, 8 Nov 2022 17:59:24 -0500 Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F086623A2 for ; Tue, 8 Nov 2022 14:59:23 -0800 (PST) Received: by mail-oo1-xc33.google.com with SMTP id e11-20020a4ab14b000000b0049be568062bso2246672ooo.4 for ; Tue, 08 Nov 2022 14:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=BksNmJr9/G65J0IUfruVbXUCosG4IvOng5/LXlEyWfc=; b=sP90Hxk8uTXToM6rA+n0zpJf4uCmThqIh4903RqZLnhC5dvBplEpETcRcMMDOhghLN FcbqjoX88LzuOcU2Kcahd5PpWUNrUYxOw4P04oNu0Be8nrVALqxMSV2EgNuU1nnkQId0 gAHqYW+Z6K/788cFCxGeL5pM9Au59ZUxSnt6ufp68NBeTK5M2oRK2g36FB+v/GQKFiLI BDalbHYMSp/HVLxq++ub5yCc75h5UWJadDp8H/gyK+68DY0Zky2kLiWT4tjXxJ/rc1vm AqyNUm767N3cugAIRaLVTrDpqT4v551YbPWeqKY7fj9VUfDyFsVefGX9i6o8YR45eb4O /pRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BksNmJr9/G65J0IUfruVbXUCosG4IvOng5/LXlEyWfc=; b=Up4/S7xJIsRzVT1sWo7QQ1/9ZN+gWF4QwdGksf0bkQ+Jy27k0cJI97lLSRzt80Y8aO 4cJjD8AL3Bmx2AwAaxicVCedlz46LdKTEH0QK2YvZWTFRJOmW4d4UwwiEJyDOKbSBpAa qZq2Lne1A8z65Xdtzu/XgsZw1AjIzfyZxOSAy4uaSFSpLtaOpHt6J3f/wGWKp87m3F9/ m7f0iugBLUIjZ42GIiZCcME39+Es3nxF3Mg4ZuwpYiN2yYnKswL+Ye6qyPO6Bq5jXFW9 ny3HLAIqu+anX7Qoty7dhO9r85rJFVwDcblNh5PyOWormnsbu4hPL4/m/9wy4CRiiRNW aq/g== X-Gm-Message-State: ACrzQf0SSa74Qgvtx8AuLnhyN7ihECpird+R3DYoY+KjFSIuSH5Ij26V vBvuCW0wylJvyDHhVk6tgq22kQxX0u0F0fAe+1fRUQ== X-Received: by 2002:a4a:d8d4:0:b0:49c:e0de:ebbe with SMTP id c20-20020a4ad8d4000000b0049ce0deebbemr15766402oov.31.1667948362297; Tue, 08 Nov 2022 14:59:22 -0800 (PST) MIME-Version: 1.0 References: <20221104213651.141057-1-kim.phillips@amd.com> <20221104213651.141057-4-kim.phillips@amd.com> <4c8945ae-62c4-7550-dc75-068cca99e678@amd.com> In-Reply-To: <4c8945ae-62c4-7550-dc75-068cca99e678@amd.com> From: Jim Mattson Date: Tue, 8 Nov 2022 14:59:11 -0800 Message-ID: Subject: Re: [PATCH 3/3] x86/speculation: Support Automatic IBRS under virtualization To: Kim Phillips Cc: x86@kernel.org, Borislav Petkov , Boris Ostrovsky , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Joao Martins , Jonathan Corbet , Konrad Rzeszutek Wilk , Paolo Bonzini , Sean Christopherson , Thomas Gleixner , David Woodhouse , Greg Kroah-Hartman , Juergen Gross , Peter Zijlstra , Tony Luck , Babu Moger , Tom Lendacky , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Tue, Nov 8, 2022 at 2:48 PM Kim Phillips wrote: > > On 11/7/22 4:42 PM, Jim Mattson wrote: > > On Mon, Nov 7, 2022 at 2:29 PM Kim Phillips wrote: > >> > >> On 11/4/22 5:00 PM, Jim Mattson wrote: > >>> On Fri, Nov 4, 2022 at 2:38 PM Kim Phillips wrote: > >>>> > >>>> VM Guests may want to use Auto IBRS, so propagate the CPUID to them. > >>>> > >>>> Co-developed-by: Babu Moger > >>>> Signed-off-by: Kim Phillips > >>> > >>> The APM says that, under AutoIBRS, CPL0 processes "have IBRS > >>> protection." I'm taking this to mean only that indirect branches in > >>> CPL0 are not subject to steering from a less privileged predictor > >>> mode. This would imply that indirect branches executed at CPL0 in L1 > >>> could potentially be subject to steering by code running at CPL0 in > >>> L2, since L1 and L2 share hardware predictor modes. > >> > >> That's true for AMD processors that don't support Same Mode IBRS, also > >> documented in the APM. > >> > >> Processors that support AutoIBRS also support Same Mode IBRS (see > >> CPUID Fn8000_0008_EBX[IbrsSameMode] (bit 19)). > >> > >>> Fortunately, there is an IBPB when switching VMCBs in svm_vcpu_load(). > >>> But it might be worth noting that this is necessary for AutoIBRS to > >>> work (unless it actually isn't). > >> > >> It is needed, but not for kernel/CPL0 code, rather to protect one > >> guest's user-space code from another's. > > > > The question is whether it's necessary when switching between L1 and > > L2 on the same vCPU of the same VM. > > > > On the Intel side, this was (erroneously) optimized away in commit > > 5c911beff20a ("KVM: nVMX: Skip IBPB when switching between vmcs01 and > > vmcs02"). > > Then why hasn't it been reverted? Sometimes, the wheels turn slowly. See https://lore.kernel.org/kvm/20221019213620.1953281-1-jmattson@google.com/. > Does its rationale not make sense?: > > The IBPB is intended to prevent one guest from attacking another, which > is unnecessary in the nested case as it's the same guest from KVM's > perspective. No, it doesn't. IBRS promises to protect the host from the guest. To properly virtualize IBRS, KVM has to provide that protection, regardless of its "perspective."