Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2182078imu; Wed, 12 Dec 2018 10:53:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/VwsH5QztTC6ikVs6oFm0NqTjxD7SxtsMEPIdnV9kC6ZyEfM6yQWwkhv1KwOjiCuwDMK5kV X-Received: by 2002:a17:902:d891:: with SMTP id b17mr21225292plz.80.1544640826923; Wed, 12 Dec 2018 10:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544640826; cv=none; d=google.com; s=arc-20160816; b=F1D+C7xxKSXwSqX9jPPbo8lAWn3aNY1Dbh5gQYtZvskqPkY/ENA5xghIfKQ+4PVZJ7 BBAkpTjvZzhbccxsJ3+uqczctDlOlatIuCAgMqG+UMvYorTlpKL0AijrFdGbYQqrm8qm XbiI3GU6fuxiTj2zZRZmyWPf7zqdKoD9pJ8KWV/QdT4M/2nmBKJuzZX7zqJ8eiR/cW5W vaqrGtXW6enEhTd7PqPcHAX3c+DmtxxHLrsyPokHqDcCswSzykDTigep7qBNhwj90/Y3 cy9siO3wczZKUdbPbjvIsIKJT/L3Lr++5Y3Vqb64sXs7mLRIXCa4eEdDX2U9Kx5du0ZX ZRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qaNJoes8m1T5czvZAOosJm23hT+njbCd4CustiZPuzs=; b=hKhgtY/KIRQ+xP39FtVcSh/LVsW+PKKaOkXlmD22KYsaUQLyHcvJds1wqw/UWxoske afkvezD62+td4Nyl/Hkcrtn7KtGdqP0yWGd5TFR3qLnnHIjrDmTaOmC/Mvzg/UOm7BnY 0EO9TWeuaYdZV/hmjuzUQpDRbkstH3fIZhFU8CkVRXrWYHmI1Jj3noTreeVmHvxVOjfo g0TS5r3gvwUh3wtjbVkq+1WR7C+nfeHuRa3aa3hucDQ3iZOqttWBQC1pegDnAUib21J+ zVb6bCB9VrUAxdoHV3IdsyQoht1o2Z2Us1BksuCIePP+b0K1noLCW3crVik8DFvW4YIC JsxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qxUDi6Hj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si14908621pgs.126.2018.12.12.10.53.31; Wed, 12 Dec 2018 10:53:46 -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; dkim=pass header.i=@kernel.org header.s=default header.b=qxUDi6Hj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728331AbeLLSuq (ORCPT + 99 others); Wed, 12 Dec 2018 13:50:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:45388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbeLLSup (ORCPT ); Wed, 12 Dec 2018 13:50:45 -0500 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2591F20870 for ; Wed, 12 Dec 2018 18:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544640644; bh=tLTZL75cjM73TG58rvf9vbqeJpQNMAZEGvUCBpbzC2A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=qxUDi6HjcC5qz5OeKqU36Q/2jW7T7aLOf7WvVBLCtH7YufXrVCmMK5roOTOlCER8s 2XXt5nbYJKtjnvHMzU0uOckdKWqmxNFDoK08ucyCdE6bdYP/F4ptlYdiBQT1Pl8CAJ /QQm66N77C9P1JPOo/VOvlYR1fnIMBcBsy7PMh7s= Received: by mail-wr1-f46.google.com with SMTP id p4so18743520wrt.7 for ; Wed, 12 Dec 2018 10:50:44 -0800 (PST) X-Gm-Message-State: AA+aEWZxJpJYLAyOQQ1avumIRibQnqNEiabY/Olks8sLRlQ64m4Ab2Vk hG3SHRorzViawOq89MMMQtILp73iCSM2+1ZG9qBajg== X-Received: by 2002:adf:f0c5:: with SMTP id x5mr17518695wro.77.1544640642617; Wed, 12 Dec 2018 10:50:42 -0800 (PST) MIME-Version: 1.0 References: <20181211222326.14581-1-bp@alien8.de> <20181211222326.14581-5-bp@alien8.de> <59aad362-4a5b-dd8b-642f-0dc3f83cf7ee@amd.com> <20181211233901.GV27375@zn.tnic> <20181212100814.GB6653@zn.tnic> <20181212184459.GE6653@zn.tnic> In-Reply-To: <20181212184459.GE6653@zn.tnic> From: Andy Lutomirski Date: Wed, 12 Dec 2018 10:50:30 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 4/4] x86/TSC: Use RDTSCP To: Borislav Petkov Cc: Andrew Lutomirski , Tom Lendacky , LKML , X86 ML , "H. Peter Anvin" , Josh Poimboeuf , Peter Zijlstra , John Stultz Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 12, 2018 at 10:45 AM Borislav Petkov wrote: > > On Wed, Dec 12, 2018 at 10:07:03AM -0800, Andy Lutomirski wrote: > > You're proving my point, I think. CPUID, IRET, MOV to CR, etc are > > "serializing". LFENCE, on many CPUd and depending on MSRs, is a > > different kind of serializing. MFENCE is something else. All LOCK > > instructions are some kind of barrier, but I don't think anyone calls > > them "serializing". > > Yeah, peterz and I hashed it out a bit today on IRC about the different > meanings of serializing. I see your point now. > > > The uaccess users of barrier_nospec() are presumably looking for a > > speculation barrier in the sense of "CPU, please don't execute the > > code after this until you're sure that this code should be executed > > for real and until all inputs are known, not guessed." > > Yeah, I believe AMD's paper has this nicely written: > > "MITIGATION G-2 > > Description: Set an MSR in the processor so that LFENCE is a dispatch > serializing instruction and then use LFENCE in code streams to > serialize dispatch (LFENCE is faster than RDTSCP which is also dispatch > serializing). This mode of LFENCE may be enabled by setting MSR > C001_1029[1]=1. > > Effect: Upon encountering an LFENCE when the MSR bit is set, dispatch > will stop until the LFENCE instruction becomes the oldest instruction in > the machine." > > https://developer.amd.com/wp-content/resources/90343-B_SoftwareTechniquesforManagingSpeculation_WP_7-18Update_FNL.pdf > > which is basically what you want for the whole mitigation crap if you > want to kill speculation - you simply hold dispatch until the LFENCE > retires. > > > The property I want for RDTSC ordering is much weaker: I want it to be > > ordered like a load. Imagine that, instead of an on-chip TSC, the TSC > > is literally a location in main memory that gets incremented by an > > extra dedicated CPU every nanosecond or so. I want users of RDTSC to > > work as if they were reading such a location in memory using an > > ordinary load. I believe this gives the real desired property that it > > should be impossible to observe the TSC going backwards. This is a > > much weaker form of serialization. > > Well, in that case you need something new. > > Because, the moment you have a RDTSC in flight and a second RDTSC comes > in and that second RDTSC must *not* bypass the first one and execute > earlier due to OoO, you need to impose some ordering. And that's pretty > much uarch-dependent, I'd say. > > And I guess on AMD the way to do that is to stop dispatch until the > first RDTSC retires. > > Can it be done faster? Sure. And I'm pretty sure there's a lot of pesky > little hw details we're not even hearing of, which get in the way. > As far as I know, RDTSCP gets the job done, as does LFENCE, RDTSC on Intel. There was a big discussion a few years ago where we changed it from LFENCE;RDTSC;LFENCE to just LFENCE;RDTSC after everyone was reasonably convinced that the uarch would not dispatch two RDTSCs backwards if the first one was immediately preceeded by LFENCE.