Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9466541pxu; Mon, 28 Dec 2020 17:34:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoq7O+/RNFpAswX7v8xjgMlpcEYmX7uqpIeR4JMGMXdYH0IkAgUOygddtxsb57w9L2xnSX X-Received: by 2002:a50:9310:: with SMTP id m16mr44799338eda.94.1609205663353; Mon, 28 Dec 2020 17:34:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609205663; cv=none; d=google.com; s=arc-20160816; b=CnicW8bHJ39FDvWr4R7O/mJQomG83had2/PvWPFFLXeOkw1cdwfy/eqign1SfKAc+J 5mIoMaADq7UZ8TCMCnnKaC5+hPvqDw9bvDG9bpAK/waDYaJ+nhUGIQreLXE8G1ye/N+Q 4uTIi2LYJ59J/v4D2n1hY963LIgwdib7prBJMSDjoCfM7KeI4xkaxMKARkv0gmoRhzeJ QP2w80K/lylMwd+mS2f4wN2JTLBVVFQTXrlLCG6DTBZl6jBDqIRgebHBu1i3R7XGP3EP FRQwMT3TL8qLFI9Z+r+V1O2Mnl1Yk2sBkXlJHwWhSRfxh8DMJhWkicUTne0/kyzXJKwN 2oyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=A+A/Blx9QD1hoONN5Jxqqa59/BnSFAuRhzOnDZD8md8=; b=Q1V63fidQaW0Kw3cUTkFOz7WGIBDM1n5q5wiSyygiEYcrBqVzblBanr5WmRGyBwDUL kNm4N/aFG1TFpYB0JP0q9s/kNcP15a8naeIrXY1gZ1XYCWF9fKP5Hxt1C4J6o4XaC/BQ 3w7plWpRHgeYAZSLoUxsASg2i++l3fbbu+f8eTtqSPNeH32Yti5PBm0II/9WVukGfoyZ pXqecVysyDmAdfoauC8cJnUNtA/0CWsa92waaPfHxSoKAXRfRrzlVrw/r37oT4xiZ6Ft vwQOkOSvl8NQ/zq5/rKPcTOBjMocByABu6Az3ZH3eVfd+s8o52yzq6fhpUh6CDoRMieZ mIvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b="p/szlAxK"; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si21143268edq.353.2020.12.28.17.34.01; Mon, 28 Dec 2020 17:34:23 -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=@efficios.com header.s=default header.b="p/szlAxK"; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731503AbgL1W4K (ORCPT + 99 others); Mon, 28 Dec 2020 17:56:10 -0500 Received: from mail.efficios.com ([167.114.26.124]:40400 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729494AbgL1VKV (ORCPT ); Mon, 28 Dec 2020 16:10:21 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 063922761C7; Mon, 28 Dec 2020 16:09:40 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Xl2HNlqr6BSs; Mon, 28 Dec 2020 16:09:39 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 8512E2761C5; Mon, 28 Dec 2020 16:09:39 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 8512E2761C5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1609189779; bh=A+A/Blx9QD1hoONN5Jxqqa59/BnSFAuRhzOnDZD8md8=; h=Date:From:To:Message-ID:MIME-Version; b=p/szlAxKXnb8sMCXgDpGdE6is/o1rjODbnzdRovA9owiEjuUPlM3+dte9oFxY/+Hd pvcRHGvBLx8S5o5ANGCMKBwMqzBmFMfuacgLtZuDT1vBtUVUSIdSFMD3lwBW0Mm8Sq XkulYMWharVGPEE76YIKlwesiZMP7dKhpXj/gToE1q4CiEAv+QDgP6f1MTue34+EDL yC7abPFDn6sQU4EVRsjnLUgN48sbY+nRlQq9VYRasErERk2As+18wk5Q0JRbIc/lci ltQp4+4byni+b6Qb7IBjB/By21MOffNXi7Ev/3OOnq+SzZHcRZHXttXzb3ZGlGI4S3 +WkZTiCC1H5Hw== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id BWu1pC_47JoY; Mon, 28 Dec 2020 16:09:39 -0500 (EST) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 725FE27640E; Mon, 28 Dec 2020 16:09:39 -0500 (EST) Date: Mon, 28 Dec 2020 16:09:39 -0500 (EST) From: Mathieu Desnoyers To: Andy Lutomirski , paulmck , Peter Zijlstra Cc: "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 Message-ID: <1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com> In-Reply-To: References: <1836294649.3345.1609100294833.JavaMail.zimbra@efficios.com> Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3991 (ZimbraWebClient - FF84 (Linux)/8.8.15_GA_3980) Thread-Topic: membarrier: Rewrite sync_core_before_usermode() Thread-Index: UfUbgHPNYlsGbr5X+VxS/QBaGieq4w== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- 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. 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" Membarrier only takes care of making sure the "ISB" part of the algorithm can be done easily and efficiently on multiprocessor systems. Thanks, Mathieu [1] https://developer.arm.com/documentation/den0024/a/Memory-Ordering/Barriers/ISB-in-more-detail [2] https://montcs.bloomu.edu/Information/ARMv8/ARMv8-A_Architecture_Reference_Manual_(Issue_A.a).pdf -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com