From patchwork Thu Oct 26 14:31:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13437614 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EEA65C25B67 for ; Thu, 26 Oct 2023 14:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=u/wMGif296abvZLQOoPzJx0l1s4mfVSgZylsKKsNMRk=; b=fazCuTSFRCbFRz Wsxp7YrfhtZuxw9bB1Y9piRPltChTCxVWKWlmkt8int8sJNSBG9kv0yuf9VqKHCQNVcEOMq+rhu23 zXMrWRGYti0542x5kgIWUykAeOpaYr8u4qGiA9wdVV0G2xZXHSnpgHaj7hfZaRDzv9N7+3azQdzJb XFin6VZHJjfwktmX6BMH5CGQKFKtHBbR+rUy5rLzJZFRDZXOdu5CmO1dARIdC6ORiBMh8iKeYrK61 FVdjkdZJbkmBctIrgYoS06TlHe/ie54mz0t38jLBASGXZ2OTeyxf52khCVbwS64uU/lyeVpcxc3lw nXlyo6dmdYGqKtYGJJcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qw1OX-00EgV1-1o; Thu, 26 Oct 2023 14:31:33 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qw1OU-00EgRQ-1m for linux-arm-kernel@lists.infradead.org; Thu, 26 Oct 2023 14:31:32 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-32de9764793so106440f8f.0 for ; Thu, 26 Oct 2023 07:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698330687; x=1698935487; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=704Flyy7JmjBNi+vrzBFMAfESwzm4xcRGzYRJGjJNUk=; b=VC4+If+XdRPy0rF9NHPEFANGlDkpZDl5dUXl8AjwqEJ6I+jZ0s2oog7LDnAEhGAiok 1qwc+rUYxxBNQGWnO6DCXd+7EjYBdCymIX/1d5knvgGFrxUvilzWbnONQ1/bTvUOuKas B0lQ3HqE+gTW/3MauVlu+ImF5SuzPc2uRy/KdBdi7HHl14IfU6NhQgunLJ8P5YOnhwUW yx/1o2KmZyVc0Jtd1yNizUOPDzFw41Noi/hs8gsQ9FuMc5kvH7/kOqpt936kidFPai9a /yZlthLSROCjMmFtTZqWTMqVPB9MlbA1Tl6UHTrvAVwdrtuLAcmOItAyJAoZi4cLUM7q /scg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698330687; x=1698935487; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=704Flyy7JmjBNi+vrzBFMAfESwzm4xcRGzYRJGjJNUk=; b=r5rQhJ0UGtI1Mp1IzaqwPY0rGByd/E6bpcXKjEVsEZSwvnP5Zp5RP/83PSmW0k33Ub 1FvTuYu7uBxHs6BXJElK6JGcEKvyZHpszcm/pKlvg44T2BRya6kpUr+So7T1fDTm+VZc f/cRhv54oEQiZ4MPkSJ/oN2vycihyStfrZ8gkcjmOJsy6VByFXKCJ1t+qP6qqCZZ0k/i E8g7s8NKJ4L7DOM+sL0ZjMj8NuJkG74J9qN/waKnBSMZurQMuUmTaTqDdp99PEtjb3rB g9Q3ryPW93nLRVW5MyhpDp+EDx+56eD7jjJo79/CXl8Z+gq3cHOcdhrCxS0vBzRah/5q Pbpw== X-Gm-Message-State: AOJu0Yy1EUyneRXsNvQ9pmjFL4Hrgq8WhA8jZKerGn2bnAF1Mnqr2LZ2 v2pOD07O9XSxykW4h3R8UHAbkA== X-Google-Smtp-Source: AGHT+IGGS8KnMtYMw9jVJnd0yOMEqJbxVZiWH5Aj4AZIhVK0vIfZ2PSwmXaPa8ekX7sIAeERTvK8aQ== X-Received: by 2002:a05:6000:1e87:b0:32d:f126:5a57 with SMTP id dd7-20020a0560001e8700b0032df1265a57mr10474423wrb.3.1698330686591; Thu, 26 Oct 2023 07:31:26 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:b380:32be:257:5381]) by smtp.gmail.com with ESMTPSA id r9-20020a056000014900b003232f167df5sm14316589wrx.108.2023.10.26.07.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 07:31:26 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Himanshu Chauhan , Xu Lu Subject: [RFC PATCH 0/3] riscv: add support for SBI Supervisor Software Events Date: Thu, 26 Oct 2023 16:31:19 +0200 Message-ID: <20231026143122.279437-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231026_073130_591544_5932BDA8 X-CRM114-Status: GOOD ( 21.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The SBI Supervisor Software Events (SSE) extensions provides a mechanism to inject software events from an SBI implementation to supervisor software such that it preempts all other supervisor level traps and interrupts [1]. Various events are defined and can be send asynchronously to supervisor software (RAS, PMU, DEBUG, Asynchronous page fault) from SBI as well as platform specific events. Events can be either local (per-hart) or global. Events can be nested on top of each other based on priority and can interrupt the kernel at any time. First patch adds the SSE definitions. Second one adds support for SSE itself. Implementation is split between arch specific code and generic part (similarly to what is done for ARM SDEI). Finally, the last patch add support fro SSE event in the SBI PMU driver. If the SSE event is available from the SBI then, it will be used instead of the normal interrupt. Amongst the specific points that needs to be handle is the interruption at any point of the kernel execution and more specifically during exception handling. Due to the fact that the exception entry implementation uses the SCRATCH CSR as both the current task struct and as the temporary register to switch the stack and save register, it is difficult to reliably get the current task struct if we get interrupted at this specific moment. A fixup-like mechanism allows to mark the location of the current task struct depending on the entry level (user/kernel) and the location. This is then used in the SSE assembly to determine where is located the current task_struct. Contrary to pseudo NMI [2], SSE does not modifies the way interrupts are handled and does not adds any overhead to existing code. Moreover, it provides "true" NMI-like interrupts which can interrupt the kernel at any time (even in exception handling). This is particularly crucial for RAS errors which needs to be handled as fast as possible to avoid any fault propagation. Additionally, SSE event handling is faster that the standard IRQ handling path with almost half executed instruction (700 vs 1590). Some complementary tests/perf measurements will be done. For testing purpose, one can use the provided SBI implementation at [3]. This series also needs patch [4] to fix a bug in the PMU driver. Link: https://lists.riscv.org/g/tech-prs/message/515 [1] Link: https://lore.kernel.org/lkml/20231023082911.23242-10-luxu.kernel@bytedance.com/T/ [2] Link: https://github.com/rivosinc/opensbi/tree/dev/cleger/sse [3] Link: https://lore.kernel.org/linux-arm-kernel/20231026084010.11888-1-alexghiti@rivosinc.com/ [4] --- Clément Léger (3): riscv: add SBI SSE extension definitions riscv: add support for SBI Supervisor Software Events extension perf: RISC-V: add support for SSE event arch/riscv/include/asm/asm-prototypes.h | 5 + arch/riscv/include/asm/sbi.h | 40 ++ arch/riscv/include/asm/sse.h | 94 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 17 + arch/riscv/kernel/entry.S | 156 ++++++++ arch/riscv/kernel/sbi.c | 4 + arch/riscv/kernel/sse.c | 97 +++++ arch/riscv/kernel/stacktrace.c | 13 + arch/riscv/kernel/vmlinux.lds.S | 6 + drivers/firmware/Kconfig | 10 + drivers/firmware/Makefile | 1 + drivers/firmware/riscv_sse.c | 496 ++++++++++++++++++++++++ drivers/perf/riscv_pmu_sbi.c | 51 ++- include/linux/riscv_sse.h | 56 +++ 15 files changed, 1038 insertions(+), 9 deletions(-) create mode 100644 arch/riscv/include/asm/sse.h create mode 100644 arch/riscv/kernel/sse.c create mode 100644 drivers/firmware/riscv_sse.c create mode 100644 include/linux/riscv_sse.h