Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2436717ybf; Mon, 2 Mar 2020 08:35:51 -0800 (PST) X-Google-Smtp-Source: ADFU+vuFcV4qDnAfpLrCTzOpDN2yxWaBPuuLYiQjPOXJEozXOmUZNNPX+/fSq/jCO2xdDOYweiwU X-Received: by 2002:a54:4181:: with SMTP id 1mr225076oiy.61.1583166950791; Mon, 02 Mar 2020 08:35:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583166950; cv=none; d=google.com; s=arc-20160816; b=lzbwWsslM5RDWCwYhznRdPhf57c/xaUdzZNPX3HfoDu+Q3Vv6RiC6yFO1Hx0+lr0Mi q07/zDfmAK8IgvI818lkRJ2V4cGBkFB+sh59xVv+FSYBCmr6AcGM1JUtBidru42iourV UGzDioXEDHsQNCB8af506CHWWyJoeB6Hda3wCAdiZTDbzeSMRJz1UDASti30q5vww5me NKDlzdc7B0zwdd2yqeWgxC2k4mRalC3CkgnfqQFR4VJXS9a3ABOafLjVYvn+OlhGTD4C HnpIKPKmcnAl3btyYDfRLZYNVNXPDBEFszjfHZC6L+pGMX/R6WBNfiY7Ow9RLIsygnDF Zw4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=luRVVK0pX3V9dHOJ/EkElogYTnQsICycmjNTVj/0FE0=; b=cKU4mIroPq0b0iuhnDQhu5sYsKikbstlGQ6yyDzFUVZ585I1GSx6lb52dX8ncH6OZm g/zjZYcqsj5h3YMTfonjffBpS+QgLrOZRUGH+1QN3jmi8emGBOLffv0kvUWe4WahSYXj KeFaDO+AP28SaGR9ssNIGAPrFUZf8n2eRdtY7gQ2AtQt2LGmq1WNWSqSdrQ7PLz0fS+K m63XmmdXVJoM9MpeAmlTOhW/0rXfzGLnX/zHPoe7lk64WAefEhQGDl8h9kMAY81Gl8VL ixX9jO8pvr56oqdY27gltlKDUpWqC2X0SdrDTWw+moEB9ELBVKjbkvMGht29gMn2JKrx vCgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hITb9uSk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si6629826oth.247.2020.03.02.08.35.38; Mon, 02 Mar 2020 08:35:50 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hITb9uSk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727471AbgCBQfX (ORCPT + 99 others); Mon, 2 Mar 2020 11:35:23 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:52364 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727113AbgCBQfW (ORCPT ); Mon, 2 Mar 2020 11:35:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=luRVVK0pX3V9dHOJ/EkElogYTnQsICycmjNTVj/0FE0=; b=hITb9uSkJF6M/Ma3L74kyzbAOt 2YOOQ2jXvdq5b5xCTEySAZQVbevObolRGus06OBmoe7T9mLkdvVwb+JYtOqD3NM4i9HVQW7NJPn06 pGm9UwzfaKfwbWnC34PAkZzd4MvEu50E/N/mXFcE/zT6Ew0EPfyI8LsQ5brivWA4Wa+TGfXFWyjy5 kUpU9QJ6/i5jB8KQNF9ytq6unB2m3/O2/bLjYsPodG8a3XJUEPJYLeW6cIsyjGuLkBzupCTFVNqgg 6WeGL2gQWrIz2LkT746MZKUkyU5MTwb+FaIwHPjwdVJpEhAflID2hv0nUySrMkJymyuN28G02obIr oHhRqPrw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j8o2I-0001E5-UE; Mon, 02 Mar 2020 16:35:19 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2A9FA304D2B; Mon, 2 Mar 2020 17:33:19 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E0FB5203E9E4B; Mon, 2 Mar 2020 17:35:16 +0100 (CET) Date: Mon, 2 Mar 2020 17:35:16 +0100 From: Peter Zijlstra To: Thomas Gleixner Cc: Jan Kiszka , x86 , Linux Kernel Mailing List , "H. Peter Anvin" Subject: Re: x2apic_wrmsr_fence vs. Intel manual Message-ID: <20200302163516.GB2579@hirez.programming.kicks-ass.net> References: <783add60-f6c7-c8c6-b369-42e5ebfbf8c9@siemens.com> <87lfoienjp.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lfoienjp.fsf@nanos.tec.linutronix.de> 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 Mon, Mar 02, 2020 at 05:20:26PM +0100, Thomas Gleixner wrote: > Jan Kiszka writes: > > as I generated a nice bug around fence vs. x2apic icr writes, I studied > > the kernel code and the Intel manual in this regard more closely. But > > there is a discrepancy: > > > > arch/x86/include/asm/apic.h: > > > > /* > > * Make previous memory operations globally visible before > > * sending the IPI through x2apic wrmsr. We need a serializing instruction or > > * mfence for this. > > */ > > static inline void x2apic_wrmsr_fence(void) > > { > > asm volatile("mfence" : : : "memory"); > > } > > > > Intel SDM, 10.12.3 MSR Access in x2APIC Mode: > > > > "A WRMSR to an APIC register may complete before all preceding stores > > are globally visible; software can prevent this by inserting a > > serializing instruction or the sequence MFENCE;LFENCE before the WRMSR." > > > > The former dates back to ce4e240c279a, but that commit does not mention > > why lfence is not needed. Did the manual read differently back then? Or > > why are we safe? To my reading of lfence, it also has a certain > > instruction serializing effect that mfence does not have. > > The 2011 SDM says: > > A WRMSR to an APIC register may complete before all preceding stores > are globally visible; software can prevent this by inserting a > serializing instruction, an SFENCE, or an MFENCE before the WRMSR. > > Sigh.... *groan*, The only way I can explain this is... ... because we changed the definition of LFENCE from: - wait until completion of all prior LOADs to - wait until completion of all prior instructions Because Spectre (and because apparently it was implemented that way, mostly). It could be that MFENCE, which is basically a completion barrier for all prior LOADs *AND* STOREs, is no longer a stict superset of LFENCE anymore... Which makes the otherwise perverted sequence: MFENCE;LFENCE, actually mean something :/ la-la-la Would be good to have that clarified though.