From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6706C04EB8 for ; Wed, 12 Dec 2018 10:08:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C66120839 for ; Wed, 12 Dec 2018 10:08:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alien8.de header.i=@alien8.de header.b="kEOXUyK1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C66120839 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=alien8.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726956AbeLLKIS (ORCPT ); Wed, 12 Dec 2018 05:08:18 -0500 Received: from mail.skyhub.de ([5.9.137.197]:60342 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726796AbeLLKIS (ORCPT ); Wed, 12 Dec 2018 05:08:18 -0500 Received: from zn.tnic (p200300EC2BCDD8002DC08A63FFF8C6E5.dip0.t-ipconnect.de [IPv6:2003:ec:2bcd:d800:2dc0:8a63:fff8:c6e5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 019891EC0BFC; Wed, 12 Dec 2018 11:08:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1544609297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GrLCOdT8HY4i4jpK3TF15BC8SA0WXnvSAbaQiVANtt8=; b=kEOXUyK11mXOuyxZ/n2Lf3vl4ubdxKhviV8iZlzPaHi18O8nGhBcfwrWUsMKYPbDiXcxJd c5Viabsuyb3w8+RPiduYNDkbpOynPAz+BJjRY6aBJf9xhLcbSjY4EMedtPTPbCQkTH2yYc YCYKzw7fhIO7Y9QCQ0X9aTGjtdXsf8E= Date: Wed, 12 Dec 2018 11:08:14 +0100 From: Borislav Petkov To: Andy Lutomirski Cc: Tom Lendacky , LKML , X86 ML , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , John Stultz Subject: Re: [RFC PATCH 4/4] x86/TSC: Use RDTSCP Message-ID: <20181212100814.GB6653@zn.tnic> References: <20181211222326.14581-1-bp@alien8.de> <20181211222326.14581-5-bp@alien8.de> <59aad362-4a5b-dd8b-642f-0dc3f83cf7ee@amd.com> <20181211233901.GV27375@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 11, 2018 at 06:24:44PM -0800, Andy Lutomirski wrote: > This makes me nervous, since no one knows what “serializing” means. Why no one? If you wanna say that X86_FEATURE_LFENCE_SERIALIZING is not really telling, so is X86_FEATURE_LFENCE_RDTSC, TBH. :) > IIRC AMD specifically documents that MFENCE is required before RDTSC > to get sensible ordering. So it’s entirely plausible to me that > LFENCE is okay for Spectre mitigation but MFENCE is needed for RDTSC > on some CPU. Look at init_amd(), the if (cpu_has(c, X86_FEATURE_XMM2)) branch where we make LFENCE serializing. The logic with the new names would be: asm volatile(ALTERNATIVE_3("rdtsc", "mfence; rdtsc", X86_FEATURE_MFENCE, "lfence; rdtsc", X86_FEATURE_LFENCE_SERIALIZING, "rdtscp", X86_FEATURE_RDTSCP) RDTSC is put there during build. At boot time: if CPU has MFENCE use MFENCE to stop RDTSC speculation if LFENCE is serializing use LFENCE... if CPU has RDTSCP even better, use that as it is the fastest or on par. Of course the order of those is important. Ok? -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.