Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2435472ybf; Mon, 2 Mar 2020 08:34:25 -0800 (PST) X-Google-Smtp-Source: ADFU+vs2uDd98joTFZ1SLcD43nM64A/OPMOyXJV3QdtVmjqkQaZHsKVyW6R3G3naOPx+0yvmlbdd X-Received: by 2002:a9d:5e8b:: with SMTP id f11mr51257otl.110.1583166864731; Mon, 02 Mar 2020 08:34:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583166864; cv=none; d=google.com; s=arc-20160816; b=eAgZ77Bn7s1YaznQ+CLXD534jojN+3yygORQX9e0QdjxLpFLiODLOG2Ob1zRwQ+goQ BneiSxO+6DeWxRMgSvhqls3nOIyE2RsP6Y4L+QNHG1LASLadeagJrm8by+8ciA1rG760 MP26zim5l450whqDBX46mignQuF8uf7YS6d/nNhSlah5YPhlYZctNzdgAsrLbnqnUweh yBywiT691rff+3Vc7V72D8MA4sdGloVH+QhQykClSuhJSuZyacO5OEFSxGrPrbvEZxiH uMfBi/Pfg0VBfMW+LXrUqyVx4yTmAwq1VNvGmHw5oxBJmkmL543ALKzZu8H93IHGQX/9 07ag== 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:cc:to:subject; bh=Xwzm0WpjqZL/QAc3Hm18i23twD/B3akD8ST9uJOqz2Q=; b=SDH/CQnTUmz7psMfnRtiKX99eiXg7bt7ZDFLNqFzK6pI6kxYzY9nmgkTC/3+mj6kJd 7Uk7dLtAOF6JLsGsJgZQuoLJGmaZbrnt5om7ACJMVliFxGagVdLcid/FkAKnlH1bb6Rn I0Q7r+BnfxE8HgGv0CNwSSD25/bSOGlVF4u+cElRy1rBcY49eSAZvmNPDKei36NiWp2b UrVmAndTQjAq51iIZyzh301cB3yDox3kqkqNM6noJ1GU1n6qwHHQV0Ob5JJZFz5qIDsT 0PMl9NXZS9rlIUdjb32WkBzTwZQdj2/PfPTSr+REXeNN9nUN4ME0wWjYUPTT01tjuwng PpoQ== 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=siemens.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f204si4996512oib.16.2020.03.02.08.34.11; Mon, 02 Mar 2020 08:34:24 -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=siemens.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbgCBQeD (ORCPT + 99 others); Mon, 2 Mar 2020 11:34:03 -0500 Received: from lizzard.sbs.de ([194.138.37.39]:39945 "EHLO lizzard.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbgCBQeD (ORCPT ); Mon, 2 Mar 2020 11:34:03 -0500 Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by lizzard.sbs.de (8.15.2/8.15.2) with ESMTPS id 022GXoxm004401 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 2 Mar 2020 17:33:51 +0100 Received: from [139.25.68.37] ([139.25.68.37]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id 022GXoVW007772; Mon, 2 Mar 2020 17:33:50 +0100 Subject: Re: x2apic_wrmsr_fence vs. Intel manual To: Thomas Gleixner , x86 Cc: Linux Kernel Mailing List References: <783add60-f6c7-c8c6-b369-42e5ebfbf8c9@siemens.com> <87lfoienjp.fsf@nanos.tec.linutronix.de> From: Jan Kiszka Message-ID: <9a7c60d5-bbb2-98a4-4564-844f161b212c@siemens.com> Date: Mon, 2 Mar 2020 17:33:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <87lfoienjp.fsf@nanos.tec.linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02.03.20 17:20, 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.... > OK, that explains it. Curious since when (date and CPU generation) we unknowingly started to play roulette here. Jan -- Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux