Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9460718pxu; Mon, 28 Dec 2020 17:21:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqt/t9rcLeGt3/s1KToMEgS+KL+WkSxrqdPyorxlHGVa5cw1NPn+obEsKLOIMaFSL9Z/qw X-Received: by 2002:a17:906:ce2b:: with SMTP id sd11mr44292970ejb.334.1609204902304; Mon, 28 Dec 2020 17:21:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609204902; cv=none; d=google.com; s=arc-20160816; b=BZllCL9baN8KK8snx0+oXhB7qx0YDwx5yHKUSs/+PUk7/N+5qB1Uoz/kj/BQpA9ke3 pLfDb1tvTUOyaEpOSZ9XYALymWaYK43IPeQOQT7vty3lvNDdriuxv3+FnMfNO6KMdd8d tP5P//ftr8rReOaT/T3O646Lknts0AgDjYHDRpKkQ/2bhN5tcOpgTEQ2nEdkPpu0Jzc2 4lG70mWW0c+Q5cdI0b115r4UnHbttVgSc4MgDBbaaesSzJZTPncfBazj4BIW3gkQ6odp MiZuRYtNtMvnZ7waLm2Do2JSux+8AZY6PLNGURKXYiGgen0F0aQAKS84i0IVagVdX/Bi 5cHA== 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=xtTA1Q7T9Kq0yZ0UmjLnuZ+yGY4VCX10h41AwXf6grM=; b=vKesNOc06OqsIk6ouh+LaKruMjK+OWY8/oX97yBGjh8RTeCjsUu4hV0ck9UtME3mzd DBlNV7tmf98jXBTMKEjDakoH2A9sy2of9JU8m9M/CbHsm/qDPExgrerVEKFSlUEi+kbN xH+oZnda2/boFjEiJVmB6NoCPik8Q3JEgVCB7duFq7ky4ODxZ4YGCb8p5AtMddOJsZQq 4+ihC3NcN9CyY/EQCIz3b8Vuhke1OJ9R4rsJX+gL4qBHeINN/22i9O44+6G/o7okzOJv s2zTTBaneIBVPnKw3fpPDFfNJf/kLLFwQQnwOIc2xx0QqxHLUFYG2TT7Hfnf/nIw73uB LmPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NtSbNU38; 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 m7si23959091edq.123.2020.12.28.17.21.19; Mon, 28 Dec 2020 17:21:42 -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=NtSbNU38; 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 S1728073AbgL1SK5 (ORCPT + 99 others); Mon, 28 Dec 2020 13:10:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:33670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728094AbgL1SK5 (ORCPT ); Mon, 28 Dec 2020 13:10:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1078D22B2A for ; Mon, 28 Dec 2020 18:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609179016; bh=UU5ZJ7wo09eeQJfHCA8zAN6QsAu7KkQNIOEasIFeWmg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NtSbNU38MzOGGEZybmJrqVrXIkZ7riOP6KLyDWXdcKOzPn2oBkVpWfP68WXcUvTXw QPCvxMa9V7U58EGvYn028q8tNODv/ggjHZYdRKTszI+dI2VtLCOS/w4qSKGYw3UIh0 bYN14vc0bpBVomQt5g8Pobew4A1eaZjEyh7ugB5j3AJXzki4F6GHeV/cJ6tzgGs3Xi jccf0pLuMoDyHVDChw9mxOzf/70bEUpgqc8fLJvWl/A0AJV94HAAkLYtXrSnTSxJ9R Voqz0zee4pqZj7x4dfz/8/WNsBT6+tgi33/b34do1ws/GbSSgdpVtXhVSGrPvVgBLL xHvCEkW1rbJ7A== Received: by mail-wr1-f41.google.com with SMTP id r7so12078797wrc.5 for ; Mon, 28 Dec 2020 10:10:15 -0800 (PST) X-Gm-Message-State: AOAM530+lmY4t+YZe2C0/NJDBdin+JWNV9v38468Yr0uE9qHBiP8POp2 Xz+3rN/LkyvZIfBE/efK06e+HXP7Ejfvl0EkcZILJg== X-Received: by 2002:a5d:62c7:: with SMTP id o7mr336085wrv.257.1609179014608; Mon, 28 Dec 2020 10:10:14 -0800 (PST) MIME-Version: 1.0 References: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> <20201228102537.GG1551@shell.armlinux.org.uk> <20201228172301.GH1551@shell.armlinux.org.uk> In-Reply-To: <20201228172301.GH1551@shell.armlinux.org.uk> From: Andy Lutomirski Date: Mon, 28 Dec 2020 10:10:02 -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 9:23 AM Russell King - ARM Linux admin wrote: > > On Mon, Dec 28, 2020 at 09:14:23AM -0800, Andy Lutomirski wrote: > > 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: > > You didn't specify that you weren't looking at kernel memory. > > If you're talking about userspace, then the interface you require > is flush_icache_user_range(), which does the same as > flush_icache_range() but takes userspace addresses. Note that this > requires that the memory is currently mapped at those userspace > addresses. > > If that doesn't fit your needs, there isn't an interface to do what > you require, and it basically means creating something brand new > on every architecture. > > What you are asking for is not "just a matter of a few instructions". > I have stated the required steps to achieve what you require above; > that is the minimum when you have non-snooping harvard caches, which > the majority of 32-bit ARMs have. > > > 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. > > Then, I'm sorry, it can't work on 32-bit ARM. Is there a way to flush the *entire* user icache? If so, and if it has reasonable performance, then it could probably be used here. Otherwise I'll just send a revert for this whole mechanism on 32-bit ARM. --Andy