Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2733436rwo; Thu, 3 Aug 2023 14:10:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHELTXy6GVK6d41pl9C0D5ivbb+vrw5OdSA3F4sGaJ/CpjVCKrH0vPdaFOS89DrNqpJQbv X-Received: by 2002:a5d:4b85:0:b0:317:69d2:35c2 with SMTP id b5-20020a5d4b85000000b0031769d235c2mr7878826wrt.2.1691097052662; Thu, 03 Aug 2023 14:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691097052; cv=none; d=google.com; s=arc-20160816; b=JHbXfbUka/knunUGfqNVLvdaMt8w36wVNf4hA+cje2T748paOfYzmqQu4VYD2SzOa0 vK4r1Uy2ObXhxT+Tj5erOGcVi+cqb2ALYz+N2k8sOTzYPolWxCJI1jsq/xScdTsNMp/o 2tGOIz+Bzreqq4B0TSNG9Ttd8oagLXeah95aFk1buWrJmMnQKrcCYasbLAVJ8qyi7V4f LNcgHIs59tAxACQrzhHNp7Ko6Pcrg6QSiCI7TR0EbuQ/T6ILZwAfSDw2iq1zSYiRwx/H tNMMh8I0YZkiU7m2rG7JOl7J08+kvaDtwZnJ8NExOjX1qZAiOTnCItUzlVvk+P1G/Oxt Lk7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=XHI2s0i4txPTbe1ZJkrSlyGmX0cwqATGsNdHKOH2c80=; fh=sxlBsYQ3FcSyIvaJtOacyomEKiabCKUh5M64M/uSRQU=; b=dRaNym/SMCaUMpCeZYVnG6BVcEcgeHl1pRdntEgce/rNOKKmympddJoFwVL+4uGCH2 crrcOm4TBR8C59k/JIn5btfGXcyxczqmPNV/am+QVYHepBPloansAnGvl37g5G7MHjrb 6bSLvUL9+mFVAqYorCypwocTr/FwzZZXIdBwGDcC51WevPTpfiPzIanKm94gyTJyt4s6 feH+91PaBtAB/v++x9zma0uVwNQ6WmEo/fAZNC7Bkv31WRY+pZSPJ56L/22sMehhPfQE r35Vn/BsbBUmocJX5YrZzKGlVlRmkNRMO1LWQIC7n2h+o0W2PsZqAWqdK52hLvkZqyL+ 4TNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=xR44LSie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p22-20020a056402075600b00522414e0582si441265edy.371.2023.08.03.14.10.28; Thu, 03 Aug 2023 14:10:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=xR44LSie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229576AbjHCU2B (ORCPT + 99 others); Thu, 3 Aug 2023 16:28:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjHCU14 (ORCPT ); Thu, 3 Aug 2023 16:27:56 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4177D10CA for ; Thu, 3 Aug 2023 13:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1691094474; bh=u1lt9tMIgYVhdDY1Tv7aqcW7LU2YS85yFCEbSSPFIik=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=xR44LSieM2jVKrgBndvTW1FeNVa6kBgxkyS8VIPns4u+ojdcQRUJPCeRVnPVthaQU boV914OUnkbHUiNwBh8k95jQHGs6JY5k+A+bvW9WsSvAtfEe8qRVfQMhJA3w6isbVT /nWQLfYYpBGo7VoSOOfWmHeW+WaUJeZmHIdqJ+FsEx0UdZ0yJDLnhRqx2u+p4jmaAz zpc7IeDfuOgoFhXA8WToHcAOdkR9o2blahIIGSakcr7JYBRiuuKH2/D19Yc43Oaobk brCGKKrbdOV3t+i3sYwm2YXAmD/lIWqI/xi3oC+Id+EKlW0euhaLV5kRpIq9BY+cEx OeodwnAXBqUzA== Received: from [IPV6:2605:59c8:2711:c800::c66] (unknown [IPv6:2605:59c8:2711:c800::c66]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4RH0lY3csfz1Kgj; Thu, 3 Aug 2023 16:27:53 -0400 (EDT) Message-ID: <4bf79f06-4593-134a-04dd-b8f89e96a1b8@efficios.com> Date: Thu, 3 Aug 2023 16:28:46 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [RFC PATCH] membarrier: riscv: Provide core serializing command Content-Language: en-US To: Andrea Parri , paulmck@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, mmaas@google.com, hboehm@google.com, striker@us.ibm.com References: <20230803040111.5101-1-parri.andrea@gmail.com> From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/3/23 11:45, Andrea Parri wrote: > Adding Martin, Hans and Derek to the Cc: list, > > Andrea > > > On Thu, Aug 03, 2023 at 06:01:11AM +0200, Andrea Parri wrote: >> Signed-off-by: Andrea Parri >> Suggested-by: Palmer Dabbelt >> --- >> For the MEMBARRIER maintainers: RISC-V does not have "core serializing >> instructions", meaning that there is no occurence of such a term in the >> RISC-V ISA. The discussion and git history about the SYNC_CORE command >> suggested the implementation below: a FENCE.I instruction "synchronizes >> the instruction and data streams" [1] on a CPU; in litmus parlance, >> Can you double-check that riscv switch_mm() implies a fence.i or equivalent on the CPU doing the switch_mm ? AFAIR membarrier use of sync_core_before_usermode relies on switch_mm issuing a core serializing instruction. Thanks, Mathieu >> (single-hart test) >> >> CPU0 >> >> UPDATE text ; >> FENCE.I ; >> EXECUTE text ; /* <-- will execute the updated/new text */ >> >> >> (message-passing test) >> >> CPU0 CPU1 >> >> UPDATE text | IF (flag) { ; >> WMB | FENCE.I ; >> SET flag | EXECUTE text ; /* execute the new text */ >> | } ; >> >> >> (and many others, including "maybe"s! ;-) ) >> >> How do these remarks resonate with the semantics of "a core serializing >> instruction" (to be issued before returning to user-space)? >> >> RISCV maintainers, I'm missing some paths to user-space? (besides xRET) >> >> Andrea >> >> [1] https://github.com/riscv/riscv-isa-manual/blob/main/src/zifencei.adoc >> >> >> .../sched/membarrier-sync-core/arch-support.txt | 2 +- >> arch/riscv/Kconfig | 2 ++ >> arch/riscv/include/asm/sync_core.h | 15 +++++++++++++++ >> 3 files changed, 18 insertions(+), 1 deletion(-) >> create mode 100644 arch/riscv/include/asm/sync_core.h >> >> diff --git a/Documentation/features/sched/membarrier-sync-core/arch-support.txt b/Documentation/features/sched/membarrier-sync-core/arch-support.txt >> index 23260ca449468..a17117d76e6d8 100644 >> --- a/Documentation/features/sched/membarrier-sync-core/arch-support.txt >> +++ b/Documentation/features/sched/membarrier-sync-core/arch-support.txt >> @@ -44,7 +44,7 @@ >> | openrisc: | TODO | >> | parisc: | TODO | >> | powerpc: | ok | >> - | riscv: | TODO | >> + | riscv: | ok | >> | s390: | ok | >> | sh: | TODO | >> | sparc: | TODO | >> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig >> index 4c07b9189c867..ed7ddaedc692e 100644 >> --- a/arch/riscv/Kconfig >> +++ b/arch/riscv/Kconfig >> @@ -27,6 +27,7 @@ config RISCV >> select ARCH_HAS_GCOV_PROFILE_ALL >> select ARCH_HAS_GIGANTIC_PAGE >> select ARCH_HAS_KCOV >> + select ARCH_HAS_MEMBARRIER_SYNC_CORE >> select ARCH_HAS_MMIOWB >> select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE >> select ARCH_HAS_PMEM_API >> @@ -35,6 +36,7 @@ config RISCV >> select ARCH_HAS_SET_MEMORY if MMU >> select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL >> select ARCH_HAS_STRICT_MODULE_RWX if MMU && !XIP_KERNEL >> + select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE >> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST >> select ARCH_HAS_UBSAN_SANITIZE_ALL >> select ARCH_HAS_VDSO_DATA >> diff --git a/arch/riscv/include/asm/sync_core.h b/arch/riscv/include/asm/sync_core.h >> new file mode 100644 >> index 0000000000000..d3ec6ac47ac9b >> --- /dev/null >> +++ b/arch/riscv/include/asm/sync_core.h >> @@ -0,0 +1,15 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +#ifndef _ASM_RISCV_SYNC_CORE_H >> +#define _ASM_RISCV_SYNC_CORE_H >> + >> +/* >> + * Ensure that a core serializing instruction is issued before returning >> + * to user-mode. RISC-V implements return to user-space through an xRET >> + * instruction, which is not core serializing. >> + */ >> +static inline void sync_core_before_usermode(void) >> +{ >> + asm volatile ("fence.i" ::: "memory"); >> +} >> + >> +#endif /* _ASM_RISCV_SYNC_CORE_H */ >> -- >> 2.34.1 >> -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com