Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp6929020ioo; Thu, 2 Jun 2022 17:23:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC+WbNrXQNy38EkAZlmDTsC0tWK803YM1by/yr4Cr65u3KL/LiAzRQdFqNiHx16PIZQ46d X-Received: by 2002:a05:6402:42c6:b0:42d:ed84:6fe0 with SMTP id i6-20020a05640242c600b0042ded846fe0mr8087641edc.58.1654215809948; Thu, 02 Jun 2022 17:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654215809; cv=none; d=google.com; s=arc-20160816; b=yQfaDsNLxt5jBFVV/z42GCfp7iyOcMWTZehr3k7s1yicQB9h5IgJwsvQN5OMk2nb0N Rdmv7YAcPa85pDBRq1qbQS66oEaMn2cuuAmhBHy8DTeIVU7Mwlj8CryGJcvRvT2MND5c ieKSqnCCvrGEZZc2HM8/Mk+WC6TKuNF2uxYMaPRD0PwkjNiGcaLRGgctKF+Bp/xempFm XfdX+AIt/wYQj9j0IpPD0H3KChz2E2sPpOWmEGLlXLjrctPqF+G6rBCB9nE4sDoaKUyU HylNv2suFits58ToMiRhF81nygZDivbOl/DCpfrt8OF7EB3LSjp2rlf4115V4mU3+42o jNGQ== 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=rS5gS+fn8mZ9FxTmxazll5DMWWGBqtfoZzI/ultI6rI=; b=WnnHHSkeG2ufmviMxhUbSb6e2+E67mpJ9GjhyzSLzelAXJ7NT53EIN2iatXdy/k1LZ 8bj3cNUyG90dFZdSByb1HVOjxU6AHZ/aowm6agAqEb3UgXLClw/DFqfs6uHJtBjWwOat gP+7Vi0b2t3UVcoUYK1KfAOU8LWBAkUf+bUjOEzFpRCSzfZO9av70GlDUHUDF/Etbjld OvGQHcc1eoFRG5kXJJDseMqWH3/xkQieYF7oABe+Fn7/SK3u8fbhQlYsm27UpvZThuOK 6NJgbfy1JkylguuaxaDUpe7PEMh1FLXHPmt/tiN9lO7FjR80MwZwlhSnxlzzkPMr7Z7v aVyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vrull.eu header.s=google header.b=Xt8YQow8; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a1709065d0500b006f39645649asi6700161ejt.639.2022.06.02.17.22.55; Thu, 02 Jun 2022 17:23:29 -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=@vrull.eu header.s=google header.b=Xt8YQow8; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237085AbiFBQcZ (ORCPT + 99 others); Thu, 2 Jun 2022 12:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237099AbiFBQcU (ORCPT ); Thu, 2 Jun 2022 12:32:20 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5C78102F for ; Thu, 2 Jun 2022 09:32:18 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-2ff90e0937aso57079217b3.4 for ; Thu, 02 Jun 2022 09:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rS5gS+fn8mZ9FxTmxazll5DMWWGBqtfoZzI/ultI6rI=; b=Xt8YQow8U2MnL3XlWTSeeLF/7QQQ8PzHRBuXmrtlX/go27tiz+R+uWa9AeAmTU+lAZ w42l25Z5rhPozysff08XV5UkWieSgPTwwOZevPXQCWZsWNpBb2nc7hA3NBEaRXHwpr8O TZ2qmhuN/IsMUnidz1swvsvNzknbdzRAnUKmF8NzQ8jG8MG6Sgpwt5feIWR3L3s7yfZH 9YGg2VT2FB55vCYzpQLHlEwOkNdxfZK/nmmd8pmDv3ZI68+UK/oJastE5Ev760eUfk4+ NSXdVzMcOBfvVvzXArQsyjMGFgngRTp+kA2GYCBYIZeTGKQJRAv8UJg330sYtrKF4oYd 32tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rS5gS+fn8mZ9FxTmxazll5DMWWGBqtfoZzI/ultI6rI=; b=5XkpDGwl4ELUA+5ACPI2ewuxrZ0DTgApPeSWbm0/cm0NC78jw3Gswml5SDHMIOigEQ V33E88vLOjB/5Wjc+zjpywh0+JUDxuTKFsQ5FhcLo0hXIY6M70qdi99pYbQ9yUfzu02N BaoqXvAE3AQ9vV4LeZJwVk9uPfknHLFWJf4/sfmyMYbyc1rEyCuLe/6e+anReTLmZaVI jrgwya6kMGc8MVvco/4N2zFeBK0rda1WC5SyDclBDoWBA0HHg6drf2mLPNDYsq6ao+Ko XfEafSNunjaaqaaBq/blGHGB+s2qD5vXhMe5BehBnWUIi6+0Dv7gasvGhoPCf/qeOsHS MbVg== X-Gm-Message-State: AOAM531+7vd5TEJM7KLpavdj3Xst4hFYyCyWACC4qaIV6JtVdwBXe6Im 3foefMtkgw97d8CX2tBQRkiO8FikuUf0ZO/mlkBsLw== X-Received: by 2002:a81:920e:0:b0:30c:201e:b3d1 with SMTP id j14-20020a81920e000000b0030c201eb3d1mr6623178ywg.374.1654187538043; Thu, 02 Jun 2022 09:32:18 -0700 (PDT) MIME-Version: 1.0 References: <20220602141032.169907-1-christoph.muellner@vrull.io> In-Reply-To: From: =?UTF-8?Q?Christoph_M=C3=BCllner?= Date: Thu, 2 Jun 2022 18:32:06 +0200 Message-ID: Subject: Re: [RFC PATCH] riscv: Add Zawrs support for spinlocks To: Randy Dunlap Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Christoph Muellner , Heiko Stuebner , Philipp Tomsich , Aaron Durbin , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Thu, Jun 2, 2022 at 6:24 PM Randy Dunlap wrote: > > Hi-- > > On 6/2/22 07:10, Christoph Muellner wrote: > > The current RISC-V code uses the generic ticket lock implementation, > > that calls the macros smp_cond_load_relaxed() and smp_cond_load_acquire(). > > Currently, RISC-V uses the generic implementation of these macros. > > This patch introduces a RISC-V specific implementation, of these > > macros, that peels off the first loop iteration and modifies the waiting > > loop such, that it is possible to use the WRS instruction of the Zawrs > > ISA extension to stall the CPU. > > > > The resulting implementation of smp_cond_load_*() will only work for > > 32-bit or 64-bit types for RV64 and 32-bit types for RV32. > > This is caused by the restrictions of the LR instruction (RISC-V only > > has LR.W and LR.D). Compiler assertions guard this new restriction. > > > > This patch uses the existing RISC-V ISA extension framework > > to detect the presents of Zawrs at run-time. > > If available a NOP instruction will be replaced by WRS. > > A similar patch could add support for the PAUSE instruction of > > the Zihintpause ISA extension. > > > > The whole mechanism is gated by Kconfig setting, which defaults to Y. > > > > The Zawrs specification can be found here: > > https://github.com/riscv/riscv-zawrs/blob/main/zawrs.adoc > > > > Note, that the Zawrs extension is not frozen or ratified yet. > > Therefore this patch is an RFC and not intended to get merged. > > > > Signed-off-by: Christoph Muellner > > --- > > arch/riscv/Kconfig | 10 +++ > > arch/riscv/include/asm/barrier.h | 97 ++++++++++++++++++++++++++++ > > arch/riscv/include/asm/errata_list.h | 12 +++- > > arch/riscv/include/asm/hwcap.h | 3 +- > > arch/riscv/kernel/cpu.c | 1 + > > arch/riscv/kernel/cpufeature.c | 13 ++++ > > 6 files changed, 133 insertions(+), 3 deletions(-) > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index 905e550e0fd3..054872317d4a 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -358,6 +358,16 @@ config RISCV_ISA_C > > > > If you don't know what to do here, say Y. > > > > +config RISCV_ISA_ZAWRS > > + bool "Zawrs extension support" > > + select RISCV_ALTERNATIVE > > + default y > > + help > > + Adds support to dynamically detect the presence of the Zawrs extension > > + (wait for reservation set) and enable its usage. > > + > > + If you don't know what to do here, say Y. > > + > > With this patch, it is possible to enable XIP_KERNEL and > RISCV_ISA_ZAWRS at the same time. That causes a kconfig warning: > > WARNING: unmet direct dependencies detected for RISCV_ALTERNATIVE > Depends on [n]: !XIP_KERNEL [=y] > Selected by [y]: > - RISCV_ISA_ZAWRS [=y] > - RISCV_ISA_SVPBMT [=y] && 64BIT [=y] && MMU [=y] > > because RISCV_ALTERNATIVE depends on !XIP_KERNEL: > > config RISCV_ALTERNATIVE > bool > depends on !XIP_KERNEL I will add a "depends on !XIP_KERNEL" to RISCV_ISA_ZAWRS. Thanks! > > > > config RISCV_ISA_SVPBMT > > bool "SVPBMT extension support" > > depends on 64BIT && MMU > > > -- > ~Randy