Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2097878ybh; Fri, 17 Jul 2020 09:14:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWbaoejGe1Y4ijJ44tzPvhIffSFbYgD+mT55F4hKnvSfWrxvHrGnVS/liVnJ099eaNCJx0 X-Received: by 2002:a17:906:c002:: with SMTP id e2mr9603567ejz.244.1595002471943; Fri, 17 Jul 2020 09:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595002471; cv=none; d=google.com; s=arc-20160816; b=ylTp6LxjB3q41W8dqTGpGrwrMjDTqKfZ0re0pUAzBe8Ukmhx3/4tI5wwOuG0s1Kwd2 yV9kHh816ox508VoH4JIPNLGB19qKy0DuqAJUx9O2q7Js0tZKm4IqsotEYFTFr0+Ez83 AGvJW0PWoWDDcoiqcQ7Db5v7+TpuQmW7fybfC4fe7r+PvAvSB5SRqfjGiUZivS0LpAv2 tymqkep0nBIFmGCpihJA2tP/lA15M3qFkTwkNeJ5hJTZSB0EnHx39+QEuurxplG0FwjP +cy/N9GWHGPfeIJrk5nxJrrJxohGZpLTRxE1llCq1H5/AE/dXuU3zXAkqbYhSWcwDNWO n2Lg== 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; bh=noQ/AdCOImZY/m4zdoNPdxw6Azx9+dCE7AaoAYPwBWU=; b=zlDzqLm/+x0H5SEte2K4Ugy8lfLWZUAcsILh0EKww+dXc3xPFgFqxBqSm4j/czGi8Q /Ki480Y/or2Ta8QppbCeSFikBMtAp7zISLXS+kVKvuE2FB7gJoXfI6m3pUi087EJxuwP K8/7bynx8GMwlG8bwSskd4Xw3BL5A4g4JtV87le98G1bY9KzFCNqHa6eZZNTE7TRyVTp CeGdu6LM15YWPTgPDC3/KkzInU06PBQpESHg0hALlvBINW/Q7KoiaeOzatYym/Euuzqs Q4pzK9bAjrlVWyhEpkQNnxHgKSf+QZ/ZeDAEgACUWXLmPtkMmGchbddxlPUy7AN/o1zz Fo5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si5114253ejb.579.2020.07.17.09.14.08; Fri, 17 Jul 2020 09:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbgGQQLs (ORCPT + 99 others); Fri, 17 Jul 2020 12:11:48 -0400 Received: from netrider.rowland.org ([192.131.102.5]:51325 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726104AbgGQQLs (ORCPT ); Fri, 17 Jul 2020 12:11:48 -0400 Received: (qmail 1153242 invoked by uid 1000); 17 Jul 2020 12:11:45 -0400 Date: Fri, 17 Jul 2020 12:11:45 -0400 From: Alan Stern To: Mathieu Desnoyers Cc: Nicholas Piggin , paulmck , Anton Blanchard , Arnd Bergmann , linux-arch , linux-kernel , linux-mm , linuxppc-dev , Andy Lutomirski , Peter Zijlstra , x86 Subject: Re: [RFC PATCH 4/7] x86: use exit_lazy_tlb rather than membarrier_mm_sync_core_before_usermode Message-ID: <20200717161145.GA1150454@rowland.harvard.edu> References: <20200710015646.2020871-1-npiggin@gmail.com> <1594873644.viept6os6j.astroid@bobo.none> <1494299304.15894.1594914382695.JavaMail.zimbra@efficios.com> <1370747990.15974.1594915396143.JavaMail.zimbra@efficios.com> <595582123.17106.1594925921537.JavaMail.zimbra@efficios.com> <20200716212416.GA1126458@rowland.harvard.edu> <1770378591.18523.1594993165391.JavaMail.zimbra@efficios.com> <20200717145102.GC1147780@rowland.harvard.edu> <1697220787.18880.1595000348405.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1697220787.18880.1595000348405.JavaMail.zimbra@efficios.com> 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 > > I agree with Nick: A memory barrier is needed somewhere between the > > assignment at 6 and the return to user mode at 8. Otherwise you end up > > with the Store Buffer pattern having a memory barrier on only one side, > > and it is well known that this arrangement does not guarantee any > > ordering. > > Yes, I see this now. I'm still trying to wrap my head around why the memory > barrier at the end of membarrier() needs to be paired with a scheduler > barrier though. The memory barrier at the end of membarrier() on CPU0 is necessary in order to enforce the guarantee that any writes occurring on CPU1 before the membarrier() is executed will be visible to any code executing on CPU0 after the membarrier(). Ignoring the kthread issue, we can have: CPU0 CPU1 x = 1 barrier() y = 1 r2 = y membarrier(): a: smp_mb() b: send IPI IPI-induced mb c: smp_mb() r1 = x The writes to x and y are unordered by the hardware, so it's possible to have r2 = 1 even though the write to x doesn't execute until b. If the memory barrier at c is omitted then "r1 = x" can be reordered before b (although not before a), so we get r1 = 0. This violates the guarantee that membarrier() is supposed to provide. The timing of the memory barrier at c has to ensure that it executes after the IPI-induced memory barrier on CPU1. If it happened before then we could still end up with r1 = 0. That's why the pairing matters. I hope this helps your head get properly wrapped. :-) Alan Stern