Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9473930pxu; Mon, 28 Dec 2020 17:51:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDO1q2JlWfDj/T/qBoom6Pu2yhyuxPGqQTNXWv6Q6Mg0/yWmOxPHlMOZd/+pWbM+HgKlHc X-Received: by 2002:a17:906:49c2:: with SMTP id w2mr42216980ejv.12.1609206681139; Mon, 28 Dec 2020 17:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609206681; cv=none; d=google.com; s=arc-20160816; b=GhlxEOG3RsNXREENuQaisgvCB2DM4McM2jabiVhTMpTwgkn+zlmRZGgKpwGW//lWMB M1FEtWe9vEiYxyPw3m5yJ9O41W8q3mbf0PJnuE69zMBkexklWXlI/XVw9jxP9yEzOaHa IFEi4q1ezrRTtugBo6oLhtfh0AB7h3ATiO546OPFTLARk9Ikuma4l0LAQqBm6wyVYdBu 3612bt6jk2Vfz4mOIfLsJH7ocYyNCcGTqjmJ2zxBy9zcLMgdPa4tXWi3XzrcZ+3YxSub kgz3WMjYhfFawYHRWqlPpKecc5SpdoTdeanUDYXTfJMx3OtMBFdzg3UVKyT7A/5ZiQm6 2GsA== 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=TfoTtB8Or2cLJU99JbzHUPs+0qWvMHe+WThmyyLyqq4=; b=yKqHHFmjHhm309XIzTd9/wRfHYMbwK3cqEhOvG/PHoqJC9JW4IT2BiJe1bbZJW297u S0urRPfY+YPxbe/2eEX6P1npR7TYCiJ02ebHpsT6BXKoLeJJfPlTKcKDB0Z8FAkCBHhp ZlEh59fMxm4zwBx8QE4bwK6UDtGVwlwrZAtT8YOwFsxHZRTbF6lNR1Kx6FLEVZY342IQ Yd86xMoojYIE1ML1yzA9ySf/8KuMQK0Xi+/t20uhjd2w7jWMYTgUoiFoA4AUiYbn9P8q dkEVYcq9ivpRxJ49BaVtWYcUzuLQzBzarPMumaSV28HdAMN6jIb3912ZG9ws5hf+JsOf ZClw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5OovboT; 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 j20si19706326ejs.76.2020.12.28.17.50.59; Mon, 28 Dec 2020 17:51:21 -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=f5OovboT; 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 S1730467AbgL2Abe (ORCPT + 99 others); Mon, 28 Dec 2020 19:31:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:45950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730191AbgL2Abd (ORCPT ); Mon, 28 Dec 2020 19:31:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9CA4B2226A for ; Tue, 29 Dec 2020 00:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609201852; bh=yV4j/cRgE8H7aOVGN5jCQGtvZBZobooTVQ66898JI4I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=f5OovboTlW7EYpT8oivw2g8c4aQCg45IJs780xMsZVv9BXlppqEZqy3983beo0x51 kFMuwRgSh0/pRPeHHA20PsWMQmrb9zMZ6QqyMI/pLw0gOiomHhkRC7FHT0chpCeFj0 QWCj2/OWKlLN3lFN+EQ8jvqmX67Op9swBowXWGtd1BIrwQkdP/5XH+oR4o5a74MF+d 4BHKEJlBKCraDuT70SOJkWP8mxSfeiGcFCmj2MxMhIxG2DAuhYkqV06UPt8Iw3reyP 0RVrPJOloYf8YlLTPvAgv1smAbWsM3TS3YPalrnRrPy9vni75J5C/h+t61dUR/GoRh K4yiWQpZEE7+A== Received: by mail-wm1-f48.google.com with SMTP id y23so812773wmi.1 for ; Mon, 28 Dec 2020 16:30:52 -0800 (PST) X-Gm-Message-State: AOAM532XnNdhleM075cn/n5kq2wrwlBDpe8Pk3AREnb1cKaFbpV+yaam mvy3hGXP+XTmJZLbhhDTOUWWop3fcRouLkW4WL0cyg== X-Received: by 2002:a1c:2188:: with SMTP id h130mr1080293wmh.176.1609201851177; Mon, 28 Dec 2020 16:30:51 -0800 (PST) MIME-Version: 1.0 References: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> <1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com> In-Reply-To: <1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com> From: Andy Lutomirski Date: Mon, 28 Dec 2020 16:30:39 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode() To: Mathieu Desnoyers Cc: Andy Lutomirski , paulmck , Peter Zijlstra , "Russell King, ARM Linux" , 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 1:09 PM Mathieu Desnoyers wrote: > > ----- On Dec 27, 2020, at 4:36 PM, Andy Lutomirski luto@kernel.org wrote: > > [...] > > >> You seem to have noticed odd cases on arm64 where this guarantee does not > >> match reality. Where exactly can we find this in the code, and which part > >> of the architecture manual can you point us to which supports your concern ? > >> > >> Based on the notes I have, use of `eret` on aarch64 guarantees a context > >> synchronizing > >> instruction when returning to user-space. > > > > Based on my reading of the manual, ERET on ARM doesn't synchronize > > anything at all. I can't find any evidence that it synchronizes data > > or instructions, and I've seen reports that the CPU will happily > > speculate right past it. > > Reading [1] there appears to be 3 kind of context synchronization events: > > - Taking an exception, > - Returning from an exception, > - ISB. My reading of [1] is that all three of these are "context synchronization event[s]", but that only ISB flushes the pipeline, etc. The little description of context synchronization seems to suggest that it only implies that certain register changes become effective. > > This other source [2] adds (search for Context synchronization operation): > > - Exit from Debug state > - Executing a DCPS instruction > - Executing a DRPS instruction > > "ERET" falls into the second kind of events, and AFAIU should be context > synchronizing. That was confirmed to me by Will Deacon when membarrier > sync-core was implemented for aarch64. If the architecture reference manuals > are wrong, is there an errata ? > > As for the algorithm to use on ARMv8 to update instructions, see [2] > B2.3.4 Implication of caches for the application programmer > "Synchronization and coherency issues between data and instruction accesses" This specifically discusses ISB. Let's wait for an actual ARM64 expert to chime in, though.