Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2424321ybf; Mon, 2 Mar 2020 08:21:05 -0800 (PST) X-Google-Smtp-Source: ADFU+vsAIKbZedL1l97uF6ehbZhvlSQHNM0ZODwCIyoPBQgrlk+Udh6hb9ZwTtCX/pvHMsaCinSr X-Received: by 2002:aca:5651:: with SMTP id k78mr164287oib.153.1583166065388; Mon, 02 Mar 2020 08:21:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583166065; cv=none; d=google.com; s=arc-20160816; b=0j6TAMEDQhDvF3iwGGAX9Oh5tJHlRCpI0c2at8jFUgp4tiS0Y8xY2mLrqVcHpIBWXU 1VIUNLfZDfFQre0lsD1tuRHN1/HNjz5fOZk52+9iNwxRMpD1cFinQ/cWFMnU6oDVXCup 0ram3XFy5Y1eEuK6K9UkUiEJWz/dGc4pr79/pBg/kJieKxpFDzMJuzSCteUdmXcDVOE/ x2zUqwuYxLFm8xN3LWVEzOvMUIF6+fiG2RcDpHMgNzzl4VC9PPL76o/+/4XB7YPb0TqH LehTzPo8+7vHW7enq9/JRmP/0LcMH92GeTCDtqN7XgpLQIByr4RQkq6FBvjPvDiP2AlP HAjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=CtcE3V53GCS2NR77cqlVvVs5lVEgG7L1SGXRhiq5Dx4=; b=sdP7oNn7tKqOqjYw3nht3X0iHOI0AbWZD5kIKJxT7brvg1ir8mW+7HAHkryvjELR7/ bnqxOeKSdIBeLs3po0+4WQGVdWJNtQeLYB2a8YrcmIbuWNN8r0Uoh1lieJPP3gjYGhen FTSUE1rMm3OWwr7YQCKXzTLb7Ajasc1FnmeDEaduqY5zpnFKGrzk0H7hdZo/b93+321O C3pRvcXQ8u9HhTWDLSYsnTWe+KeLqejdDqwJy/h5CaqsvZdfKI36uvXWTZ0YbMf4bvua QsfXhsYxFzjGaoa+n4cju2QMAg+DUr+rTfS3fV7g5y01k/nMFXwuQSPUPVg0Rvk5YwUq OudQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si7189482otl.9.2020.03.02.08.20.53; Mon, 02 Mar 2020 08:21:05 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbgCBQUf (ORCPT + 99 others); Mon, 2 Mar 2020 11:20:35 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:42271 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727307AbgCBQUf (ORCPT ); Mon, 2 Mar 2020 11:20:35 -0500 Received: from [5.158.153.55] (helo=nanos.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j8nnz-0004iZ-E0; Mon, 02 Mar 2020 17:20:31 +0100 Received: by nanos.tec.linutronix.de (Postfix, from userid 1000) id 20CF41040A1; Mon, 2 Mar 2020 17:20:26 +0100 (CET) From: Thomas Gleixner To: Jan Kiszka , x86 Cc: Linux Kernel Mailing List Subject: Re: x2apic_wrmsr_fence vs. Intel manual In-Reply-To: <783add60-f6c7-c8c6-b369-42e5ebfbf8c9@siemens.com> References: <783add60-f6c7-c8c6-b369-42e5ebfbf8c9@siemens.com> Date: Mon, 02 Mar 2020 17:20:26 +0100 Message-ID: <87lfoienjp.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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....