Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp385056pxj; Fri, 7 May 2021 10:41:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBb20ovdqWkXWSSTkeUbaT7gaI1ZKMevv49wRKzN+/N07vMa2aProbzOWP3I6FGYn7oNfc X-Received: by 2002:a17:906:2c55:: with SMTP id f21mr11592705ejh.41.1620409291008; Fri, 07 May 2021 10:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620409291; cv=none; d=google.com; s=arc-20160816; b=qW1GiV5XIApFgJI1+vR8WM+OAUz74At2q98QrmY4A5DSmvzLzqSpv3CiwuLhh/WhrU 6BqxQlmSVAK+kh0dIM7n34B6qftQw3D/WR+VvlPWWGzGIxPDkSSCMPyY7OMqkPut3ynZ lVQ6pceAqUvYlzyItP9/nEmK0NxM+7E9+N+g9uG0lLZcX3MoLQqOkMsa2S2Juu5N42rW XgXH/eL/5EFI2b66lpYiqS2ZRDcvmy6jxH7/V3o7GFgKYjjEsCeoGw6BCNP06D2pBBuN 6Twl8sC0iHiFtlEJ+4rc3V1ftiE5AoryWCo26RkIsdphrVpmETq2iRR7vevYHBfrLxfi osfw== 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=gQ3ipQxbX73bGU2SXA3y2Bzh59V5vke4f329EGQixvg=; b=HpiZteHV+LDP3EX6QK8PQ9ZVtcSDPbJ4zGVsLk/EwVAloZpfFW8CvTQfhTashrsMD5 Eit4uwBc0D8daFKiswMtj53vWZTI/WQuYVImeQOeacsOT5EepxW1bsHQRIZF0OTwtepf 1r2L15xDPloz1t0KnQqVd+M7qgEY9K61+swwf4D4mNbcY2fc+BSxX0eP0u+JQlzU5+GU HokI/afZl+iXNm1rITAm0yBU2WyMwyXJPYCsIv1i/PO9C73zTu+9xh+Gz89S+mw/gSOp /A5KrUQQfLiHdK7Le93RcZJElz+as8bUBSlqft81OvLsOBygvUQb43desY9W6Xp8WBX/ YrzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KH8GL3iN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g6si5612160edb.247.2021.05.07.10.41.07; Fri, 07 May 2021 10:41:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KH8GL3iN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232792AbhEGRXi (ORCPT + 99 others); Fri, 7 May 2021 13:23:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhEGRXi (ORCPT ); Fri, 7 May 2021 13:23:38 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4959CC061761 for ; Fri, 7 May 2021 10:22:38 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 36-20020a9d0ba70000b02902e0a0a8fe36so2224185oth.8 for ; Fri, 07 May 2021 10:22:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gQ3ipQxbX73bGU2SXA3y2Bzh59V5vke4f329EGQixvg=; b=KH8GL3iNV6Z/uD3TMYgD+CrCfLVaUDeAs0zqsk9jCpnDJJCpW0QyHmMSjWWmSLhvJ1 FDtdqZsKLe2uoN2TDpAYLCOrimwhcklk1sSa42lMZ/jWzznAXKuD2WvTNhdBcUnJy88h Q+lub5DzGRR83dIb2AC9agASP4rw1QyRLhGkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gQ3ipQxbX73bGU2SXA3y2Bzh59V5vke4f329EGQixvg=; b=p7Pn4OxWIpA2qMUftSJPSlOF+UOI7S8vnGmF9snAruk9WR3u6OwDBLethfgzFRM30e F6FadThgwi+H+V8n2cv0XDERlgOO5jAP2QX+ov2eOP51JWm3DX5kj+7KjMhkZD4du/a9 wA9LKU+8Nt4WPgRMzbHqukLKGxkERtgjHELxEK7UqNdp6NJjl7zqdtpwB6tgl7oRSWF6 qiyfwUEI4QKIUB39m6POjWNHXdjBGVfcTfVjUfALFx6fy+x7CzSZ6jE+5nQjHQLv0xAv A0HXw2B1IeHPf3yp6mIFwx0Z6RVo2GE1VKwlzZJ6MeJuJIi/0ORK3u46s64/pRjW2Eq+ bJFA== X-Gm-Message-State: AOAM532qT3AHmg8cLz8/56wXTRbhmk00SrLYaW1yJXyi1AXbmELZjZSH nsON++VhFqg+V1B8uvhGKxEKi4y+RAssabec5UCBZQ== X-Received: by 2002:a9d:764f:: with SMTP id o15mr9279052otl.164.1620408157620; Fri, 07 May 2021 10:22:37 -0700 (PDT) MIME-Version: 1.0 References: <20210507150636.94389-1-jon@nutanix.com> In-Reply-To: <20210507150636.94389-1-jon@nutanix.com> From: Venkatesh Srinivas Date: Fri, 7 May 2021 10:22:25 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86: use X86_FEATURE_RSB_CTXSW for RSB stuffing in vmexit To: Jon Kohler Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 7, 2021 at 8:08 AM Jon Kohler wrote: > > cpufeatures.h defines X86_FEATURE_RSB_CTXSW as "Fill RSB on context > switches" which seems more accurate than using X86_FEATURE_RETPOLINE > in the vmxexit path for RSB stuffing. > > X86_FEATURE_RSB_CTXSW is used for FILL_RETURN_BUFFER in > arch/x86/entry/entry_{32|64}.S. This change makes KVM vmx and svm > follow that same pattern. This pairs up nicely with the language in > bugs.c, where this cpu_cap is enabled, which indicates that RSB > stuffing should be unconditional with spectrev2 enabled. > /* > * If spectre v2 protection has been enabled, unconditionally fill > * RSB during a context switch; this protects against two independent > * issues: > * > * - RSB underflow (and switch to BTB) on Skylake+ > * - SpectreRSB variant of spectre v2 on X86_BUG_SPECTRE_V2 CPUs > */ > setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW); > > Furthermore, on X86_FEATURE_IBRS_ENHANCED CPUs && SPECTRE_V2_CMD_AUTO, > we're bypassing setting X86_FEATURE_RETPOLINE, where as far as I could > find, we should still be doing RSB stuffing no matter what when > CONFIG_RETPOLINE is enabled and spectrev2 is set to auto. If I'm reading https://software.intel.com/security-software-guidance/deep-dives/deep-dive-indirect-branch-restricted-speculation correctly, I don't think an RSB fill sequence is required on VMExit on processors w/ Enhanced IBRS. Specifically: """ On processors with enhanced IBRS, an RSB overwrite sequence may not suffice to prevent the predicted target of a near return from using an RSB entry created in a less privileged predictor mode. Software can prevent this by enabling SMEP (for transitions from user mode to supervisor mode) and by having IA32_SPEC_CTRL.IBRS set during VM exits """ On Enhanced IBRS processors, it looks like SPEC_CTRL.IBRS is set across all #VMExits via x86_virt_spec_ctrl in kvm. So is this patch needed? Thanks, -- vs;