From patchwork Fri Jan 12 11:17:12 2024 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: 13518322 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 D30DAC4707C for ; Fri, 12 Jan 2024 11:18:06 +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=M9ub/YmYOkqwckRYSvSMUTR9INuHpOHinwzgF8qbnAI=; b=4Hc6NQBZ21ed7a m6BHDzXfml28QAj/WEl2KlOMFQqLXokS8m+W+2/Ptz0umaE00L6p0x9+0LcHzjbzXgMWL8Tu/AMKx 8oPqhJnjwe9gtbbKMkqp0Hji5ctjmA8N+0gNeSWGvEGLLfZFjr5SildJ4xIfwsOXMpA/Tf0I/ah/W FpK58w/YU4++5zSsxOfNOsuLffLKFukancMiI64UozislgUHQdTEtaa/OqzqOHQ9DuBEESVBCiVWG V3mf1bVGQ674fB4Zo0t4tydHqq1kn6CciYRb141y2B8XX8nL/4zWk5WlqV4lbkzT/CmOViC/fkID6 KQPXpE6PCGtfqnWzJQRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rOFXh-002ZM0-1z; Fri, 12 Jan 2024 11:17:41 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rOFXd-002ZKj-1C for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2024 11:17:39 +0000 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-28bbe484bc0so1334878a91.1 for ; Fri, 12 Jan 2024 03:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705058254; x=1705663054; 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=n/r2CUr6NQRTkWJSfnfsoonlWRwu5UcKq/JbWJG+yiE=; b=QKXrpG2Pqypj3t1OwJ25BXw+mMFrJH3etpXGyNY52mkR/sDF11Gss817I141/Bw/Ts DJK0KUGB2+Ug4dXLs/VUPdq+KaN7E3Q1J0qaea2/15GZAug0WPLQeQIpyluoUo0892jP vDgqEFUwoQjltZY0eKZIciB/5ulOU80OfGpSVGbkrKRExXOxrV9dwn4TgB+aO2EMnrf9 DqzxbewgSBfihZ0YXyBbe4ZwfvlWdhveO+JDHB9kno+nKKsS4Uml66YiAeE43ECeGBg7 D93/HWmsGx//ztfK+0ts7KZEbkzZrxES+IoyC4Efo9xEGTV3R7mi9M8YnG6cuFCgJeek V0jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705058254; x=1705663054; 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=n/r2CUr6NQRTkWJSfnfsoonlWRwu5UcKq/JbWJG+yiE=; b=v4C7RVh/I1i1BnYpHHTUqwM0pWTirXLZ2acFzCRc/NlmNcPWwQ8z/H5EN45m+eYSMM bGDG4wBN2dPmvX4RcoKhtFCn3Sp1jVhoKQJRehvw/0Rw0LPXI+1i7/Z7DSsVaFDvF0gq DiHAT9mmDbGCUl6P0+8lzsQmKZHaLduyey9hXjutd7wjM3dRjll+CoquAUK344TVACUl sCNHSiYVn9dV5TsroHjbT4OryP6fl8PGyrDc/mG3bxLlSwAWV9vP7Zo7/MWZVCzVXB3Z VaCoDHhWTugW45GOXwyRnvhJd+nnM3zgenI1b2+gaR21AVL8WQXPjFSnll5ZTwQwmIF0 Ny9Q== X-Gm-Message-State: AOJu0YzCGxDZ33F7IGKZgnKoX1nnbP8xlWtS0sXP0UimbSJUCe2SKw0G I2EvvT6wR0lYv6ZOYnq+2Pp/ItaUb1ZG4g== X-Google-Smtp-Source: AGHT+IGQohed/oEcJo01neyqBjBHsaj+nu3i/3udCsZR7M7O8D2uGXWtzMc93+BA3NLF+ZCUdujm1w== X-Received: by 2002:a17:90a:ad8b:b0:28e:1609:88e4 with SMTP id s11-20020a17090aad8b00b0028e160988e4mr326280pjq.3.1705058254520; Fri, 12 Jan 2024 03:17:34 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:a276:8a4e:2aa1:5f09]) by smtp.gmail.com with ESMTPSA id sd12-20020a17090b514c00b0028cef021d45sm3794179pjb.17.2024.01.12.03.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 03:17:34 -0800 (PST) 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 v2 0/3] riscv: add support for SBI Supervisor Software Events Date: Fri, 12 Jan 2024 12:17:12 +0100 Message-ID: <20240112111720.2975069-1-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240112_031737_409278_573BDA65 X-CRM114-Status: GOOD ( 22.05 ) 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 for SSE events 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/744 [1] Link: https://lore.kernel.org/lkml/20231023082911.23242-10-luxu.kernel@bytedance.com/T/ [2] Link: https://github.com/rivosinc/opensbi/tree/sse_v2 [3] --- Changes in v2: - Implemented specification v2 - Fix various error handling cases - Added shadow stack support v1: https://lore.kernel.org/linux-riscv/20231026143122.279437-1-cleger@rivosinc.com/ 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 | 4 + arch/riscv/include/asm/asm.h | 42 +- arch/riscv/include/asm/sbi.h | 47 ++ arch/riscv/include/asm/scs.h | 7 + arch/riscv/include/asm/sse.h | 12 + arch/riscv/include/asm/thread_info.h | 1 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/asm-offsets.c | 26 ++ arch/riscv/kernel/entry.S | 202 +++++++++ arch/riscv/kernel/sbi.c | 4 + arch/riscv/kernel/sse.c | 130 ++++++ 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 | 567 ++++++++++++++++++++++++ drivers/perf/riscv_pmu_sbi.c | 46 +- include/linux/riscv_sse.h | 76 ++++ 18 files changed, 1176 insertions(+), 19 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