Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3330563iob; Sun, 1 May 2022 13:57:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjw5UDm915dnirCiJARDdx8+7jzH/oxn89sQPd8+1IvCnqdpSZ92SNIzxBJKmMiZAoVLfy X-Received: by 2002:a62:8247:0:b0:50d:e3de:3633 with SMTP id w68-20020a628247000000b0050de3de3633mr3135798pfd.44.1651438677750; Sun, 01 May 2022 13:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651438677; cv=none; d=google.com; s=arc-20160816; b=b7BsFkRn1GYxtOAvTRRsQ5PYX5/6oERMJwfLEAQPf1I7nkBrjmqabJvBhHHmvIcQyN Hysdk5MnVp9B+94bQNINOtKNctc5ww3975CpzhMzhrlawHsbDGhmidjQfcjxNDpq2CcO KmugvlRTtJE0sagWLNcFK8GxJnwrtLnlWjcqBjedsX5JG1yL429xIfJH2FFpf4g0bIZ1 sKnBcG7Butv53ulVhaCDJjYWbXYezJle9umKQNxgBbBfQe5LjqcihHXRz+xhzk3jm73o glawvk9V2gPrWxtwhOVn4Z1z2gmJKgYeH/JwASoU1vJYjFgbdV74unynNFPUmP0WYJS7 J32w== 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=TgWk1OrzhJm8KIPseeZpTJ3sK4pPkWoy9iKngLNbReg=; b=Ah5bxH5jgX98z091LaGR1spWPYgfGAOYpbY+tRAJOsno1BBlT8+WPyaIwVgMfPFs6z QllecFcFC3eGSM+GXB+YTBoJ9+P7kvwPP/cUol/tJlIO4v7Yk0Vi9prWBUA5CZliPQbk gVNIZItpujmfoo/mylw8rqUOqD0sSLCVOO9fdmCKDsCeJQuCxdf20J/d0AJ3x1n8MZQT IwJi4bGb8ivOnOHfH4mCHvWz2C1HMTvITWRCLkVRgEaoPV/9+rej7pmhi89iK1XYFYVu 2/t8f2kQRNclZKBmBsSy8IWB7cZiDcbWG90kpjkykWf54gOZoMIuORphBxu+LENiMGSE KG5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gpny65B3; 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 i13-20020a170902eb4d00b00158f04afd74si12535703pli.146.2022.05.01.13.57.17; Sun, 01 May 2022 13:57:57 -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=gpny65B3; 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 S1381641AbiD2X07 (ORCPT + 99 others); Fri, 29 Apr 2022 19:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381502AbiD2X06 (ORCPT ); Fri, 29 Apr 2022 19:26:58 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C84BD3ADF for ; Fri, 29 Apr 2022 16:23:37 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id l6so2008445pls.10 for ; Fri, 29 Apr 2022 16:23:37 -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=TgWk1OrzhJm8KIPseeZpTJ3sK4pPkWoy9iKngLNbReg=; b=gpny65B3540owtoHo6pIiVHUycEUlDOB9gpLH8hucOPahQYLUb/tjUSt6eH0w3zTqk EG6ZvoDr0DuYxBlWpMKXqUCzDu7Tj/q6vSjqpGMrFnkxt02eWpTH7OjwvjjF0yED5qhs NcQz529vZ7+jXOzTypJDfOVxRAGtPZA74vu2MXSvcM5PoJ4DaHOBJogsftOMPAFFZBWI axrUt2P9uuneNICvmmJFg30PZiBDDrA3VpXeKzaThLwIC5KcxQPzbvzSZYryHn4e8bf5 ODv0fgSDSA8AraCPnjSA7BRDBYgy3eV1Uu9CpUZl2OJMxvhlqAzJuzjmZDnWRnizePdz CwjQ== 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=TgWk1OrzhJm8KIPseeZpTJ3sK4pPkWoy9iKngLNbReg=; b=NRSWwMLfrCpxDNCboAbRnmpgT8/iP5ta9BCWmugSx1mRGTdJxycSo0UCzOfDWQPKJO w3DFOJVmGno66a9/TFm85PzWpBWAtMqpq9NcekdK0mvXke5s/0UOyijQBCez86op8tif /lSN/tZpX44vVfhs02ss0uVyqb9wfflq6eRuBY3xtQnsSX8BvgFkufb7jEC/OJ4K5MbA IwTKjcibF1uGvubCUp/67RCTcsdVRZ+XsSypHki/LM38TCNpYE2LJbTL+60/Epr322Gt wskcTcsZ0zlbg43pBfPuRN3KsVCIX9aN6YT3CPu6Ltu1XlR3qo9QVxtpUcRf071Ueik/ 95OQ== X-Gm-Message-State: AOAM532Eo3vtVPD3LYFE+M00Mg9Fxnz5neKT6kzZ1rnNBoYe2vqBDpNU vqZkvBRNo3nSszUukpcnzg/2zdg+W+EfZQ== X-Received: by 2002:a17:902:6ac9:b0:156:a6ae:8806 with SMTP id i9-20020a1709026ac900b00156a6ae8806mr1323364plt.148.1651274616370; Fri, 29 Apr 2022 16:23:36 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id 64-20020a17090a0fc600b001cd4989fedesm15192657pjz.42.2022.04.29.16.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 16:23:35 -0700 (PDT) Date: Fri, 29 Apr 2022 23:23:32 +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: <20220422162103.32736-1-jon@nutanix.com> <645E4ED5-F6EE-4F8F-A990-81F19ED82BFA@nutanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 Sat, Apr 30, 2022, Borislav Petkov wrote: > On Fri, Apr 29, 2022 at 09:59:52PM +0000, Sean Christopherson wrote: > > Correct, but KVM also doesn't do IBPB on VM-Exit (or VM-Entry), > > Why doesn't it do that? Not needed? The host kernel is protected via RETPOLINE and by flushing the RSB immediately after VM-Exit. > > nor does KVM do IBPB before exiting to userspace. > > Same question. I don't know definitively. My guess is that IBPB is far too costly to do on every exit, and so the onus was put on userspace to recompile with RETPOLINE. What I don't know is why it wasn't implemented as an opt-out feature. > > The IBPB we want to whack is issued only when KVM is switching vCPUs. > > Then please document it properly as I've already requested. I'll write up the bits I have my head wrapped around. > > Except that _none_ of that documentation explains why the hell KVM > > does IBPB when switching betwen vCPUs. > > Probably because the folks involved in those patches weren't the hell > mainly virt people. Although I see a bunch of virt people on CC on that > patch. > > > : But stepping back, why does KVM do its own IBPB in the first place? ?The goal is > > : to prevent one vCPU from attacking the next vCPU run on the same pCPU. ?But unless > > : userspace is running multiple VMs in the same process/mm_struct, switching vCPUs, > > : i.e. switching tasks, will also switch mm_structs and thus do IPBP via cond_mitigation. > > : > > : If userspace runs multiple VMs in the same process, > > This keeps popping up. Who does that? Can I get a real-life example to > such VM-based containers or what the hell that is, pls? I don't know of any actual examples. But, it's trivially easy to create multiple VMs in a single process, and so proving the negative that no one runs multiple VMs in a single address space is essentially impossible. The container thing is just one scenario I can think of where userspace might actually benefit from sharing an address space, e.g. it would allow backing the image for large number of VMs with a single set of read-only VMAs. > > enables cond_ipbp, _and_ sets > > : TIF_SPEC_IB, then it's being stupid and isn't getting full protection in any case, > > : e.g. if userspace is handling an exit-to-userspace condition for two vCPUs from > > : different VMs, then the kernel could switch between those two vCPUs' tasks without > > : bouncing through KVM and thus without doing KVM's IBPB. > > : > > : I can kinda see doing this for always_ibpb, e.g. if userspace is unaware of spectre > > : and is naively running multiple VMs in the same process. > > So this needs a clearer definition: what protection are we even talking > about when the address spaces of processes are shared? My na?ve > thinking would be: none. They're sharing address space - branch pred. > poisoning between the two is the least of their worries. I truly have no idea, which is part of the reason I brought it up in the first place. I'd have happily just whacked KVM's IBPB entirely, but it seemed prudent to preserve the existing behavior if someone went out of their way to enable switch_mm_always_ibpb. > So to cut to the chase: it sounds to me like you don't want to do IBPB > at all on vCPU switch. Yes, or do it iff switch_mm_always_ibpb is enabled to maintain "compability". > And the process switch case is taken care of by switch_mm(). Yep.