Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9457808pxu; Mon, 28 Dec 2020 17:15:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWSQkL89P0TU5eNqFED/zHJnof2YZmKzeJ1lelAnqDubz6vpde5M0B7gurj0B8EIinG4IO X-Received: by 2002:a17:906:354a:: with SMTP id s10mr43630975eja.335.1609204555453; Mon, 28 Dec 2020 17:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609204555; cv=none; d=google.com; s=arc-20160816; b=UI8DKsSMuuy9NnplOQUhHULwwsIwtCb7w2YFhtX06mu1yQzNfZ6letJ7+mSmHH2TDn VgvZIQRbdPBd2RyzcbWEg2owTugWEKrsjOKN9t05X/7I9VRPAXIdxUhLcP3JUU38Ie7K e7kBQOiH0hZd/fbTa3s1ut00gksienXMmPFeJZpC0rm9UzheHFhMUxUs5pxAB6y4waKz xyV6b+yul1R+GOfJIEksE1qBvJFxWX9DsclBJLXKf4LzJ1zJ0j3vLEr08xEVqFAeH1c4 ElfV8eir3umkysmZdsOjtx6fTLD0BHJuyUOrMszt7UK0UsoYboQKL2L4t7Hq9cv8rmhq vxbA== 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=+Z5vPs8836b6YJQnfQk45M0pwlHsJZLGt+yMrNZu//s=; b=nzOPR4WLHvevRfl2FATupSXKE5wNfDdvCfVa7iHXFqazGkOCpjACQh7TBwG55sHClq B7QoGO5gvHKuloAzu+48SyzBFquAw86yi+YGr+xSHdjR2kHTXNJ89LXKclu1bjuJbmmp 5tK7xKMk/KW9GAgYDZbh+YTEfEtGL6YY+UK8l/1TZP24+DYrLpADiGIz749gX0FsWvsm /pNX0IL035DxLIxyA0h7KIS0u5k0DWRJB7u2NXhjyrYQ+ETs6Pd1N43CB2W6LFXi7naq /Zqca8mEcILdSa3GQ0I9HaFR7TYMuVR0VrRVQwAfEdvNkpjjCTLAxmSnCZd0I6zlKViV pTDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZeSX2vRl; 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 s13si15809764eds.57.2020.12.28.17.15.33; Mon, 28 Dec 2020 17:15:55 -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=ZeSX2vRl; 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 S1727927AbgL1RPU (ORCPT + 99 others); Mon, 28 Dec 2020 12:15:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:51354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727784AbgL1RPR (ORCPT ); Mon, 28 Dec 2020 12:15:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27513225AB for ; Mon, 28 Dec 2020 17:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609175676; bh=nMFBr3AvYXRRq2owotQjD2yoFpgfyoWAPgMz9PhnD/Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZeSX2vRlCanroSsW4BK7DGUrK3k2SOzmqV2xEXyMyPjqu44pP9BiMfE8tPd3llJsX HUJ/W5trVCAdI7BSXID6rGbWhICir5MECyTiACa1g1J2CK43kMFJ9WaPpCNkxF8Joo EaN3FUyXtsgJiCyfnKA/EQBgRM+ls3mmBaXjI7gLHAHQBT5L1B+DKxooB1H4Mqx51z ngviP39PLF3mgFDcWB/8wL0SM/PIWLfUIcrvO5KuB8525M997tpEidUOcGxQKUfhxP Pg5tXjIQVuLfdHVd7iWP1C/S4quq69OdNPfQwCRTb4Aj4d6KObdBM86I/C8LATMP5B W7XvKz/a3n/fg== Received: by mail-wr1-f51.google.com with SMTP id a12so11877552wrv.8 for ; Mon, 28 Dec 2020 09:14:36 -0800 (PST) X-Gm-Message-State: AOAM533eBZ8MW+mT7MU+7Dqjab81WrLfycFL1ZmGoyrym1TtwDY3tTrD GSlCukiZz8MtC+D4b2Yi70fEEdjcXQ81hgIMsM+kKw== X-Received: by 2002:a5d:43c3:: with SMTP id v3mr51067579wrr.184.1609175674739; Mon, 28 Dec 2020 09:14:34 -0800 (PST) MIME-Version: 1.0 References: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> <20201228102537.GG1551@shell.armlinux.org.uk> In-Reply-To: <20201228102537.GG1551@shell.armlinux.org.uk> From: Andy Lutomirski Date: Mon, 28 Dec 2020 09:14:23 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode() To: Russell King - ARM Linux admin Cc: Andy Lutomirski , Mathieu Desnoyers , x86 , linux-kernel , Nicholas Piggin , Arnd Bergmann , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev , Catalin Marinas , Will Deacon , linux-arm-kernel , stable 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 2:25 AM Russell King - ARM Linux admin wrote: > > On Sun, Dec 27, 2020 at 01:36:13PM -0800, Andy Lutomirski wrote: > > On Sun, Dec 27, 2020 at 12:18 PM Mathieu Desnoyers > > wrote: > > > > > > ----- On Dec 27, 2020, at 1:28 PM, Andy Lutomirski luto@kernel.org wrote: > > > > > > > > > > > > > I admit that I'm rather surprised that the code worked at all on arm64, > > > > and I'm suspicious that it has never been very well tested. My apologies > > > > for not reviewing this more carefully in the first place. > > > > > > Please refer to Documentation/features/sched/membarrier-sync-core/arch-support.txt > > > > > > It clearly states that only arm, arm64, powerpc and x86 support the membarrier > > > sync core feature as of now: > > > > Sigh, I missed arm (32). Russell or ARM folks, what's the right > > incantation to make the CPU notice instruction changes initiated by > > other cores on 32-bit ARM? > > You need to call flush_icache_range(), since the changes need to be > flushed from the data cache to the point of unification (of the Harvard > I and D), and the instruction cache needs to be invalidated so it can > then see those updated instructions. This will also take care of the > necessary barriers that the CPU requires for you. With what parameters? From looking at the header, this is for the case in which the kernel writes some memory and then intends to execute it. That's not what membarrier() does at all. membarrier() works like this: User thread 1: write to RWX memory *or* write to an RW alias of an X region. membarrier(...); somehow tell thread 2 that we're ready (with a store release, perhaps, or even just a relaxed store.) User thread 2: wait for the indication from thread 1. barrier(); jump to the code. membarrier() is, for better or for worse, not given a range of addresses. On x86, the documentation is a bit weak, but a strict reading indicates that thread 2 must execute a serializing instruction at some point after thread 1 writes the code and before thread 2 runs it. membarrier() does this by sending an IPI and ensuring that a "serializing" instruction (thanks for great terminology, Intel) is executed. Note that flush_icache_range() is a no-op on x86, and I've asked Intel's architects to please clarify their precise rules. No response yet. On arm64, flush_icache_range() seems to send an IPI, and that's not what I want. membarrier() already does an IPI. I suppose one option is to revert support for this membarrier() operation on arm, but it would be nice to just implement it instead. --Andy