Message ID | 20231026143122.279437-1-cleger@rivosinc.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp720213vqb; Thu, 26 Oct 2023 07:31:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvqVWLPnzEiBf4ioGIrIe/IGPtPwGU2DLoONvXQ6CvPpk9VleZdGLXfuGzvnLnjQicKm8J X-Received: by 2002:a05:6902:1083:b0:d0a:8973:b1c with SMTP id v3-20020a056902108300b00d0a89730b1cmr20566139ybu.12.1698330716105; Thu, 26 Oct 2023 07:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698330716; cv=none; d=google.com; s=arc-20160816; b=wAL74oxzFshgTcXyykenrFTbGiMjFx13ToQa32UA97+JaDlnJ6EGk/+L0SH3qaOjLp Aw6feiC0QkeBE7Wz8dm47BKg2vjeDGmV6LFHwnBFN5vfmXi4bLfsW4C404qnlZKrNlir n/SXkIjkgESVuPr1A94TYchd0e/PKsltbdohEWJfCqe/Wmb2VNzweW62Hb6wjlxM1hmT 4ra6QH3Hu1jr/XEpst1mkSgZVmGgajoGlDbcgqu6e/eEPc7X5LqIcpdpQGDf2cWUbXk2 wkQXq+NPv3Z5NVk5EB6NaOOlzXsLWjYAMrAUSWgaCCUrs/Pua8BpVNOwC7ZV5Yp1tumW A6Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=704Flyy7JmjBNi+vrzBFMAfESwzm4xcRGzYRJGjJNUk=; fh=AdjJcfMlYbiYDdKKIz6ysPeqNYJJCfTBHWq2VWscBlk=; b=c7EpRMpnVNZLjT312ktGvSJzxBEkWi3o1mkzKp0zlSgDPeEyatSYoE1FIyVzPqmpWf DOgdgOBXuub4YafmpnMKYwmzAo8TjPMO9FxBkr2uUNvb5wj7okvMCIK6HQGz63Payvnj dkD36JVJflBNsIcj6vcy+g0QTyT6BeFGFAtg2ZRmuqQHTbUfb1At+EGJhZTHv2fgdxcx Vu+SuqUhIadunHez9m/JX35eqSiPa6zmuh6lMytuXDWP77Pex5mUcXo90c49f4rHp+4b 0t9XQNmnsGYY99HzDCGSYgr+a2se94GZCEGbzKk2xntD2f8bOmPf8Ehfuujd/wXIDHlW ZM9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=j6cgvH5V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id e128-20020a25d386000000b00d89e9efce8asi14190799ybf.520.2023.10.26.07.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 07:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=j6cgvH5V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C8C1480F4E03; Thu, 26 Oct 2023 07:31:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345271AbjJZObd (ORCPT <rfc822;aposhian.dev@gmail.com> + 26 others); Thu, 26 Oct 2023 10:31:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345244AbjJZObb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 26 Oct 2023 10:31:31 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57BF5D42 for <linux-kernel@vger.kernel.org>; Thu, 26 Oct 2023 07:31:28 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-32da02fca9aso103610f8f.1 for <linux-kernel@vger.kernel.org>; Thu, 26 Oct 2023 07:31:28 -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=vger.kernel.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=j6cgvH5VWx9Nd2IyIcfvuaD3zSpF6Z4Xm2tNnESVPI3c0fyxg0GoIj3HO0SUYbibWV j9bjonOiq/D3RlRPUjN9+eLUikBEODjiw5CbcQi8ZHKYjv54j8CH/QFgWPY35nfvt0ZS i1ps13Jduj4gPWBggt6fRRDO3dfppN1Cuyg/0RFF7tzC1QXfqPeBSObYu2Sp8DitCfbR 7EPBrhQLdcBPRyqseuU5Kk4tWccoNl0nrFYhZEZjHSNiK1WK858VSxCL+8hN3q8QPvkY qAlhK1fIk2EG2uEHnNDIysHXx6DtIINqRypSpsmzfQzoeSsZfdja6CtWRi27yS6y2wGW aKBA== 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=wer9/oNTTV7WSrW4USCyhW/ngX2OlQOfN5FVdOSsTLBzlBTjCKI7nOX1RRH97IL0dq AnH4pKlqAqRveoaonCWrSoFXGnUipTrxTr4508GIGykZTX61NUWktAj9BO7e4aM/mQqq DgFuqZDJibs+fegIlfjYDr5SFu+mN7f2v5sa5rM/4Bm+4kG+2cTHbfDkSj7teooYYFGX /1rjuVSoO0VVtduItXX4yniby6eexB/G+jhHaX69Y05oA2sWk3VHJLQ2CXGujFE7aoMT Bv6DoL2VAOsjH08ulowxhFWgStfGx8CDl5sxBqtRq6NbDP+768dYkfqScqOTjeyH9dzY FhmA== X-Gm-Message-State: AOJu0YwH3QzIILze9IAL/q/o3UwnDQ5YxOH3BbVbFs1Jld2dghJMwbC1 7j+Ahnnxn9j9UeBrV+zpmfoEXA== 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?= <cleger@rivosinc.com> To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Atish Patra <atishp@atishpatra.org>, Anup Patel <apatel@ventanamicro.com>, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= <cleger@rivosinc.com>, Himanshu Chauhan <hchauhan@ventanamicro.com>, Xu Lu <luxu.kernel@bytedance.com> 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 07:31:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780828828859095101 X-GMAIL-MSGID: 1780828828859095101 |
Series |
riscv: add support for SBI Supervisor Software Events
|
|
Message
Clément Léger
Oct. 26, 2023, 2:31 p.m. UTC
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
Comments
Pardon. It seems that the code in opensbi[1] is not complete for PMU NMI now. For example, the pmu ovf irq is still delegated to supervisor mode and thus can not really play a role as NMI. And neither the kernel nor opensbi will inject a pmu event. To complete the work, we think maybe 'enable_cb' and 'disable_cb' functions can be supplied for sbi_sse_cb_ops. When sbi_sse_enable is called to enable pmu event, the enable_cb will be called to revoke the delegation of pmu ovf irq and enable this irq in CSR_MIE. When pmu ovf irq occurs, kernel traps into opensbi and opensbi injects the event via sbi_sse_inject_event and eret back to kernel. Please point it out if we have any misunderstanding. By the way, how is SSE going now? We will appreciate it very much if we can participate in some development work in kernel or opensbi and be of any help. Regards! Link: https://github.com/rivosinc/opensbi/tree/dev/cleger/sse [1] On Thu, Oct 26, 2023 at 10:31 PM Clément Léger <cleger@rivosinc.com> wrote: > > 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 > > -- > 2.42.0 >
On 07/12/2023 10:09, Xu Lu wrote: > Pardon. It seems that the code in opensbi[1] is not complete for PMU NMI now. > For example, the pmu ovf irq is still delegated to supervisor mode and > thus can not really play a role as NMI. And neither the kernel nor > opensbi will inject a pmu event. > > To complete the work, we think maybe 'enable_cb' and 'disable_cb' > functions can be supplied for sbi_sse_cb_ops. > When sbi_sse_enable is called to enable pmu event, the enable_cb will > be called to revoke the delegation of pmu ovf irq and enable this irq > in CSR_MIE. Hi Xu, Indeed, this part has been developed but was left out for the RFC. But your understanding is correct. > When pmu ovf irq occurs, kernel traps into opensbi and opensbi injects > the event via sbi_sse_inject_event and eret back to kernel. > > Please point it out if we have any misunderstanding. > > By the way, how is SSE going now? We will appreciate it very much if > we can participate in some development work in kernel or opensbi and > be of any help. The development is almost complete, Anup/Himanchu will send a new revision of the spec addressing various comments and I'll resend the RFC following that spec update. Regards, Clément > > Regards! > > Link: https://github.com/rivosinc/opensbi/tree/dev/cleger/sse [1] > > On Thu, Oct 26, 2023 at 10:31 PM Clément Léger <cleger@rivosinc.com> wrote: >> >> 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 >> >> -- >> 2.42.0 >>