Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6368902iob; Tue, 10 May 2022 17:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRbVLR9858Fm7hhpYK9HUsMQaBYCEiOxs+IrkLJxhThrYvvzxM5vPcNdzZHr7KHxnqfiT8 X-Received: by 2002:a17:906:7315:b0:6f4:c84f:9eab with SMTP id di21-20020a170906731500b006f4c84f9eabmr20945739ejc.759.1652228396961; Tue, 10 May 2022 17:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652228396; cv=none; d=google.com; s=arc-20160816; b=n8A5rUjiwCYO5b1GPGcVkzT+GCQsa4f4WAObmjWv8zB//CIEJpmeiIILR3QhHt0iVY eUgRjoR13BfnfGRYJjNLZflk7gRB5kfWvVj6kPjKxx2vqm3sVHatGROUc5rOLByktB7s EPJ69W0vHnA9/OvHEMauvEcp5EpG63c7x8M4IWAuCQA/sYMrnYOHs4qqOam4nX/LzIDd l4C3MGyy7i+VsyCuNc+3VhYOsG1YV8Qbbu+Dhv03AeZlvr+im6bHhEbwAHYhtB+4Z/sK XlA2INTu7glvMzz+BEAeMCX7evxz65QUoBq7OKOhBqkmygecropuMmy46RMkEzLsSVJB qg5Q== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=J+j65+g15fCsV+Woqx6SguatojsTFMU+fypv/4RCtgE=; b=gQZiHxTyduE0VcPrdrLK2ia+6+W3A+xgZvsb7IcgsEcXfBL2PBRpk6qALCE6UMcwZC NzsIvbDh+scuOC4EhcQLaq2dyP6uFrCX22VmpYvl0DJWz9pfhC5ZPxMfPV5ssYFtXBF8 wWGrslVgVND1ZylADDF+CCS6S+euDn3ET9mYKmz+k9NnP8d9AWJHrRRnGHEaAjLMUCzI pTfW86KbigrluXGVaUkNCvS6vDbbgT2dsXN6T9AvUUKxgFvHQGjmqeRuAICQHHIq+vHd M4Wrms030By2AsIcIQ9Jb8hqJJ9QPVrmLopRdAXMotPMrvKRL9XOAD+HjZ9QF1MiMAAD aCbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UTKi9sbH; 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 qf30-20020a1709077f1e00b006f3b1db5347si730137ejc.950.2022.05.10.17.19.31; Tue, 10 May 2022 17:19:56 -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=20210112 header.b=UTKi9sbH; 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 S1345403AbiEJPMZ (ORCPT + 99 others); Tue, 10 May 2022 11:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346080AbiEJPLt (ORCPT ); Tue, 10 May 2022 11:11:49 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92A8125BA46 for ; Tue, 10 May 2022 07:44:59 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id x88so4521105pjj.1 for ; Tue, 10 May 2022 07:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=J+j65+g15fCsV+Woqx6SguatojsTFMU+fypv/4RCtgE=; b=UTKi9sbH4ZRyjDc/7lHYfVs9p+QExxFt9/+sbFXNine0VCZsiYBonNCzQr9PVXDNu9 QWx7xX/dW3O0HVOK8KbAOsU0vj7r1WZj64aBaM42JQrWhvHplMFMlet/XWgeCe+fBX1M 5/obDfisv/+8zQrzGAaXXgJovXZmvJPru63YyrKVxAY/He8u9DhzcDaIfLqwezGoPfCs Mt1bVCF6ZEdokq17J2DgC5oXLJTxjhB6jqeQ4DlifycFKhjIQ/WvF6CK0l2BQKFhniHg KnklIDO0Qq3yf1Y46nZtjYBZ9wcmnYlIZO62+aWAcG+vWvJbv9+tNUccgFmHuE7mM/hB pWow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=J+j65+g15fCsV+Woqx6SguatojsTFMU+fypv/4RCtgE=; b=W3KBHT54SsNKPQTL5762lgULicn9vaZftaHddHi/eY/uKj1AKMdhUMvOzPMzb1LFUe O5w/ZIXDAXzXz9msBVSj1a+7UGAIMQ5SqeMs76RRGdjprIKrFTGpVvCsxVX3Hqozgia2 PrP4qu2fwqmmgRcQEffQTkQbP69HUuRhedq2tYURzd1kCxdmo6oLNmZ0UmMMH0hmwaDc WogNEi6f6Zq3rqr60MYONDQlk1lSi+ZiR9d0aCaQU15p+bKZhNaRVkGKFiB/AmHyoHeq As2oGejjwU4EpEuXJU9m3DV/3NFEJQZ/z1HoS4lFtI4U8foHQHqg5Y73r1Os346F4JqC Hmzg== X-Gm-Message-State: AOAM533ZSSxcd/fpia4mDR2ojlBmOYR1jHMoZv0C7WeniuN6U4UdeO7A c5BZ2dy5faxCx8PrkgkewixgNg== X-Received: by 2002:a17:903:2312:b0:15e:a6c8:a313 with SMTP id d18-20020a170903231200b0015ea6c8a313mr20952499plh.122.1652193898495; Tue, 10 May 2022 07:44:58 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id k22-20020a170902761600b0015e8d4eb1d4sm2181590pll.30.2022.05.10.07.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 07:44:57 -0700 (PDT) Date: Tue, 10 May 2022 14:44:54 +0000 From: Sean Christopherson To: Borislav Petkov Cc: Jon Kohler , Thomas Gleixner , Ingo Molnar , Dave Hansen , "x86@kernel.org" , "H. Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Josh Poimboeuf , Peter Zijlstra , Balbir Singh , Kim Phillips , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , Andrea Arcangeli , Kees Cook , Waiman Long Subject: Re: [PATCH v3] x86/speculation, KVM: only IBPB for switch_mm_always_ibpb on vCPU load Message-ID: References: <645E4ED5-F6EE-4F8F-A990-81F19ED82BFA@nutanix.com> <4E46337F-79CB-4ADA-B8C0-009E7500EDF8@nutanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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, T_SCC_BODY_TEXT_LINE,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 Sat, Apr 30, 2022, Borislav Petkov wrote: > On Sat, Apr 30, 2022 at 02:50:35PM +0000, Jon Kohler wrote: > > This is 100% a fair ask, I appreciate the diligence, as we’ve all been there > > on the ‘other side’ of changes to complex areas and spend hours digging on > > git history, LKML threads, SDM/APM, and other sources trying to derive > > why the heck something is the way it is. > > Yap, that's basically proving my point and why I want stuff to be > properly documented so that the question "why was it done this way" can > always be answered satisfactorily. > > > AFAIK, the KVM IBPB is avoided when switching in between vCPUs > > belonging to the same vmcs/vmcb (i.e. the same guest), e.g. you could > > have one VM highly oversubscribed to the host and you wouldn’t see > > either the KVM IBPB or the switch_mm IBPB. All good. > > > > Reference vmx_vcpu_load_vmcs() and svm_vcpu_load() and the > > conditionals prior to the barrier. > > So this is where something's still missing. > > > However, the pain ramps up when you have a bunch of separate guests, > > especially with a small amount of vCPUs per guest, so the switching is more > > likely to be in between completely separate guests. > > If the guests are completely separate, then it should fall into the > switch_mm() case. > > Unless it has something to do with, as I looked at the SVM side of > things, the VMCBs: > > if (sd->current_vmcb != svm->vmcb) { > > So it is not only different guests but also within the same guest and > when the VMCB of the vCPU is not the current one. Yep. > But then if VMCB of the vCPU is not the current, per-CPU VMCB, then that > CPU ran another guest so in order for that other guest to attack the > current guest, then its branch pred should be flushed. That CPU ran a different _vCPU_, whether or not it ran a different guest, i.e. a different security domain, is unknown. > But I'm likely missing a virt aspect here so I'd let Sean explain what > the rules are... I don't think you're missing anything. I think the original 15d45071523d ("KVM/x86: Add IBPB support") was simply wrong. As I see it: 1. If the vCPUs belong to the same VM, they are in the same security domain and do not need an IPBP. 2. If the vCPUs belong to different VMs, and each VM is in its own mm_struct, defer to switch_mm_irqs_off() to handle IBPB as an mm switch is guaranteed to occur prior to loading a vCPU belonging to a different VMs. 3. If the vCPUs belong to different VMs, but multiple VMs share an mm_struct, then the security benefits of an IBPB when switching vCPUs are dubious, at best. If we only consider #1 and #2, then KVM doesn't need an IBPB, period. #3 is the only one that's a grey area. I have no objection to omitting IBPB entirely even in that case, because none of us can identify any tangible value in doing so.