From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69D91C00528 for ; Mon, 31 Jul 2023 19:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229528AbjGaTsP (ORCPT ); Mon, 31 Jul 2023 15:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjGaTsP (ORCPT ); Mon, 31 Jul 2023 15:48:15 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A250A0; Mon, 31 Jul 2023 12:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=G10afZyCNiaw2vu2jAC3R9gIyzTLIVHGE2tClR0IBw8=; b=kBp+2VJp5ZkwgOk6UXkI6Hycfa 6kT98WUmhx2HQkhtNUZTNNoe07jkAj4Lz4PjP+7r5FBs15S+dQQb2piYzaUHD0peDdc8WIdLQxMQK DNFi0PDdxcs5CJoEXFHGSc7/TGeaYG1Ke5nrUTGoljolHji24RtvsxqdvE5A7itlLqUScknltKB3Z zWy96M9RwO8SFgNHBjDdAjDnzHwsoV3IjCqVd1ylRCKJHShmoUN00v/rzC7LsqX7U0zpk2QAtFJhj LWnDr4Thcm4PrDlyS5MM6o9h4m4nkIP9/R16jO8Ry8c5m88Uki668qErHNvG+0fkJkOImHmzuHHTb jeL6dO4A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qQYry-003T3N-E9; Mon, 31 Jul 2023 19:47:54 +0000 Date: Mon, 31 Jul 2023 20:47:54 +0100 From: Matthew Wilcox To: Ian Rogers Cc: Alexandre Ghiti , Brendan Sweeney , Palmer Dabbelt , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Will Deacon , Rob Herring , Andrew Jones , =?iso-8859-1?Q?R=E9mi?= Denis-Courmont , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Atish Patra Subject: Re: [PATCH v4 09/10] tools: lib: perf: Implement riscv mmap support Message-ID: References: <20230727141428.962286-1-alexghiti@rivosinc.com> <20230727141428.962286-10-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Mon, Jul 31, 2023 at 09:46:07AM -0700, Ian Rogers wrote: > On Mon, Jul 31, 2023 at 9:06 AM Alexandre Ghiti wrote: > > I have just had the answer internally (thanks to @Brendan Sweeney): > > csr modifications can alter how the memory is accessed (satp which > > changes the address space, sum which allows/disallows userspace > > access...), so we need the memory barrier to make sure the compiler > > does not reorder the memory accesses. > > The conditions you mention shouldn't apply here though? Even if you > add a memory barrier for the compiler what is stopping the hardware > reordering loads and stores? If it absolutely has to be there then a > comment something like "There is a bug is riscv where the csrr > instruction can clobber memory breaking future reads and some how this > constraint fixes it by ... ". If the hardware doesn't know that writing to a csr can change how memory accesses are done and reorders memory accesses around that csr write, you've got a really broken piece of hardware on your hands ... I know nothing about risc-v, and maybe the definition says that you need to put a memory barrier before and/or after it in the instruction stream, but on all hardware I'm familiar with, writing to a CSR is an implicitly serialising operation.