Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9474001pxu; Mon, 28 Dec 2020 17:51:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTT/3EBR5dbNZrOI9UAiAuSrkzUzZzJRK09XuCEg78jylSjiRg2ALoP/yZJvsPXyS4IOKT X-Received: by 2002:a05:6402:8da:: with SMTP id d26mr42910092edz.157.1609206691005; Mon, 28 Dec 2020 17:51:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609206690; cv=none; d=google.com; s=arc-20160816; b=R0CWZBSDF0I95nXGgdrC9bzcnLk4RQWyV/RGeQGBEXge+TkVcsThSdJb76dL2qt3UT ayld5D9lgdlqiYUh4F3skWs3nonBf0anKWHcB39nGVUH2ANOCjZuiMft7fZMH0vimscd WuG6ldY8iafb7ACBRRs0NNjggCGINvbhEHet5JzYeUriiFmVb3JsTYcVfJcwvoEmJLbV lpEl+RPVoloWEA+UyMD155PU1h2u7lI+xqQoWc85zPiYy32cRvq6dx81WqL5mb0xElwI SjkGUw5Kpy8zb7liFJnviLszofY6Ittzsyp8Khtn3FLDBX9HZlEN/uss9mIUBg5EHh2o YZiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UBpqXbZzxD6Q8jO84Md82cP/9PG8yAdlKrlvAjLqud4=; b=LrZA09Nblia91XAda6cAxUTC0TcJ2STpwC45A543pv2W/dTE+gndk+n9jnIPjbnv0U 8dhlfmk9qiScfw5t3D93W5YQ5n1Nu3ER7b9e5WDagCBfAn4A/+bKsDeV/ppFxPAxTzqz 18cRe1LhN+cqyl98ilS6S6nWMJVtUGdMI9xgVWxA1OvSLXM3EcYLHP90CpPr2q65+gbD zUMGR+zg+gup9fl8ICcYCKnfP0FHYH4nKpv9ozpyy94OY8lKf51TXWhWdcnEHnAtibgh q578l9zc2DtDesHG+NqjIXu+8DRE2tgYBzLSYx0IrHZVhWwq+T0acsVx2K04b9o1glDx jwow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=klsW25bg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si19603238ejr.242.2020.12.28.17.51.09; Mon, 28 Dec 2020 17:51:30 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=klsW25bg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730506AbgL2AhG (ORCPT + 99 others); Mon, 28 Dec 2020 19:37:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:46652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730191AbgL2AhG (ORCPT ); Mon, 28 Dec 2020 19:37:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F27B8221F8 for ; Tue, 29 Dec 2020 00:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609202185; bh=VX6lw2IJ/z/WjavzOW0lIGvJ2PJ7vI+cPiWmgFXCEi4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=klsW25bgbw2Tvtt4HCiG69FQv4hapU7eCpnsPT82tb4h4tFP+WN5MPXW0TPAeMUpE W1Bb4qLn/j8DCfX8hQQAiqGNj6lXOleMlM9evE8WGtODI/8ERWwzB3l6X0EzFK+iXl aG8FI0bAypxmmj1Cy8x44bo2yHoNpPH/NHkJKPAgCIV0dUb1vP3BbS8Q9dZ/pLQvqM JZtvRnlxRT1vQPPEfvC8rvHwMH6aovwMSGTBsxsIRvSryxDzpGLkz8A85O/i6JFVz8 7hZEJ81kX43ATdY1/1QvFDU5BZScQNXGrav0we/3oQWufomEIHb9hrB9kNKBfqj888 5Bi+xNXHb2INg== Received: by mail-wr1-f41.google.com with SMTP id m5so12780453wrx.9 for ; Mon, 28 Dec 2020 16:36:24 -0800 (PST) X-Gm-Message-State: AOAM532+J6HOZugLpQQVCRWpLr4o2mE1IMKNFOg6R/RjboAEi+7bq0Qu lRYAaWhauq9PBBqvsZAPVpdMSNp2WffOBeB3pEjAxA== X-Received: by 2002:a5d:43c3:: with SMTP id v3mr52282122wrr.184.1609202183585; Mon, 28 Dec 2020 16:36:23 -0800 (PST) MIME-Version: 1.0 References: <1609199804.yrsu9vagzk.astroid@bobo.none> In-Reply-To: <1609199804.yrsu9vagzk.astroid@bobo.none> From: Andy Lutomirski Date: Mon, 28 Dec 2020 16:36:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode() To: Nicholas Piggin Cc: Andy Lutomirski , Mathieu Desnoyers , X86 ML , Arnd Bergmann , Benjamin Herrenschmidt , Catalin Marinas , linux-arm-kernel , LKML , linuxppc-dev , Michael Ellerman , Paul Mackerras , stable , Will Deacon Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 28, 2020 at 4:11 PM Nicholas Piggin wrote: > > Excerpts from Andy Lutomirski's message of December 28, 2020 4:28 am: > > The old sync_core_before_usermode() comments said that a non-icache-syncing > > return-to-usermode instruction is x86-specific and that all other > > architectures automatically notice cross-modified code on return to > > userspace. Based on my general understanding of how CPUs work and based on > > my atttempt to read the ARM manual, this is not true at all. In fact, x86 > > seems to be a bit of an anomaly in the other direction: x86's IRET is > > unusually heavyweight for a return-to-usermode instruction. > > "sync_core_before_usermode" as I've said says nothing to arch, or to the > scheduler, or to membarrier. Agreed. My patch tries to fix this. I agree that the name is bad and could be improved further. We should define what membarrier(...SYNC_CORE) actually does and have arch hooks to make it happen. > > So let's drop any pretense that we can have a generic way implementation > > behind membarrier's SYNC_CORE flush and require all architectures that opt > > in to supply their own. This means x86, arm64, and powerpc for now. Let's > > also rename the function from sync_core_before_usermode() to > > membarrier_sync_core_before_usermode() because the precise flushing details > > may very well be specific to membarrier, and even the concept of > > "sync_core" in the kernel is mostly an x86-ism. > > The concept of "sync_core" (x86: serializing instruction, powerpc: context > synchronizing instruction, etc) is not an x86-ism at all. x86 just wanted > to add a serializing instruction to generic code so it grew this nasty API, > but the concept applies broadly. I mean that the mapping from the name "sync_core" to its semantics is x86 only. The string "sync_core" appears in the kernel only in arch/x86, membarrier code, membarrier docs, and a single SGI driver that is x86-only. Sure, the idea of serializing things is fairly generic, but exactly what operations serialize what, when things need serialization, etc is quite architecture specific. Heck, on 486 you serialize the instruction stream with JMP. > > +static inline void membarrier_sync_core_before_usermode(void) > > +{ > > + /* > > + * XXX: I know basically nothing about powerpc cache management. > > + * Is this correct? > > + */ > > + isync(); > > This is not about memory ordering or cache management, it's about > pipeline management. Powerpc's return to user mode serializes the > CPU (aka the hardware thread, _not_ the core; another wrongness of > the name, but AFAIKS the HW thread is what is required for > membarrier). So this is wrong, powerpc needs nothing here. Fair enough. I'm happy to defer to you on the powerpc details. In any case, this just illustrates that we need feedback from a person who knows more about ARM64 than I do.