Received: by 10.223.185.116 with SMTP id b49csp520171wrg; Tue, 20 Feb 2018 03:27:34 -0800 (PST) X-Google-Smtp-Source: AH8x2241HZeaGCXS5ftzEL0XswbbhF0237PNXlVAWxUomZAPZi1uQTK/yfNaMcC34i23hpS02eNv X-Received: by 10.98.254.19 with SMTP id z19mr2742423pfh.76.1519126054602; Tue, 20 Feb 2018 03:27:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519126054; cv=none; d=google.com; s=arc-20160816; b=Lwr+obxLkA8UvnvkvbHuUxdf9VO5wNCFTB8yeExNtbTFOKNFcrEUjKfFCsCLKbD6eW ronXyAwhfRNUQZjtpS/LLBVPPFPq552/qEDk0H1qX9N6O5diOVP0LXTswz2WTHmft+ld +pDTigblta1PmJ3SKsy69VnELF1lowOBpgeAfNiSDokyLks/4/HZ8Mp6d9VoH2EtLSaa 9jIV5ykB2yh1uXNleQI4s36QwuiC/9gHGR/e7QCLjnc+p9QbqC4Yvg9K6yxanaobxN+j zf69p8+7XYi4hUZvoceTrJJsyyM8UcSZcJdiol35zK4tpdUZIFowRoVn2rnYwm8ikfEi nXeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:arc-authentication-results; bh=NfRMOwKrMYqAgbw32cBJkjf3zLpE7TsWf65BtbLxhxY=; b=qcr0jTXNiH81llfb81ZNtOSohw88o2tjwLgm7oqT/V+PY8CWUKFIcTeTloLWRYFof7 XSc4ST8qZlORuokP9Dy2GKiNooLQwAXgTjkC5J2a5C0iyxBtZmhtiUs4xxhohJqzIe0X Kr8TqxAQLA3m6Lnn8RXw07hLABuM7Wu+ibwtbzuejt0oZNyQ20pc07dULIghpfJ+qG5x 0qV8gl5viC56LUeVLCLA5ub/glOs1bsdW9qxuCVV58rRCf05dQMyyVUZl/4/7id2HZz6 QY4vbnWaG6g4EbV8Wl8rzRdSRe2sAjWFIYMf5rED31Xf4YlUXTMCAUUKf0/xq4AJmhdK 7EXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si825248pgn.157.2018.02.20.03.27.20; Tue, 20 Feb 2018 03:27:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751716AbeBTL0o (ORCPT + 99 others); Tue, 20 Feb 2018 06:26:44 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49746 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751516AbeBTL0m (ORCPT ); Tue, 20 Feb 2018 06:26:42 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 361B1402290A; Tue, 20 Feb 2018 11:26:42 +0000 (UTC) Received: from [10.36.118.42] (unknown [10.36.118.42]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFA5C2026E0E; Tue, 20 Feb 2018 11:26:39 +0000 (UTC) Subject: Re: [PATCH v3 2/4] x86/speculation: Support "Enhanced IBRS" on future CPUs To: David Woodhouse , tglx@linutronix.de, karahmed@amazon.de, x86@kernel.org, kvm@vger.kernel.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, jmattson@google.com, rkrcmar@redhat.com, arjan.van.de.ven@intel.com, dave.hansen@intel.com, mingo@kernel.org References: <1519037457-7643-1-git-send-email-dwmw@amazon.co.uk> <1519037457-7643-3-git-send-email-dwmw@amazon.co.uk> From: Paolo Bonzini Message-ID: <79c73482-9509-e67a-da8f-43ba0cb6d0fa@redhat.com> Date: Tue, 20 Feb 2018 12:26:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1519037457-7643-3-git-send-email-dwmw@amazon.co.uk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 20 Feb 2018 11:26:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 20 Feb 2018 11:26:42 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/02/2018 11:50, David Woodhouse wrote: > Cope with this by trapping and emulating *all* access to SPEC_CTRL from > KVM guests when the IBRS_ALL feature is present, so it can never be > turned off. Guests who see IBRS_ALL should never do anything except > turn it on at boot anyway. And if they didn't know about IBRS_ALL and > they keep frobbing IBRS on every kernel entry/exit... well the vmexit > for a no-op is probably going to be faster than they were expecting > anyway, so they'll live. The problem is, it isn't. On a Haswell (which has fairly slow SPEC_CTRL) toggling IBRS is 200 cycles. This gives a context switch time of around 2000 clock cycles with PTI enabled. This is fairly awful, but with a vmexit cost of ~1100 cycles that goes up to 2000+(1100-200)*2 = 3800. That's more or less doubling the cost of a system call. With newer machines SPEC_CTRL cost goes down but vmexit cost doesn't, so it's only worse. For now, we really should do something like if (vmx->spec_ctrl != host_spec_ctrl) wrmsrl(MSR_IA32_SPEC_CTRL, host_spec_ctrl); else lfence(); which later can become if (vmx->spec_ctrl != host_spec_ctrl) wrmsrl(MSR_IA32_SPEC_CTRL, host_spec_ctrl); else { /* lfence not needed if host_spec_ctrl == 0 */ if (static_cpu_has(BUG_REALLY_WANTS_IBRS)) nospec_barrier(); } Paolo