Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1522137rdb; Thu, 7 Dec 2023 01:10:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHz/nC3UwiRwPiXaEC8a/Ald+E7Tzh1JkpGEUWmGEyjOz87MmmEe3KCeFEHMNPkDFWamjZA X-Received: by 2002:a05:6a00:2d01:b0:6cd:ec0b:61ae with SMTP id fa1-20020a056a002d0100b006cdec0b61aemr2225842pfb.0.1701940237219; Thu, 07 Dec 2023 01:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701940237; cv=none; d=google.com; s=arc-20160816; b=ll+p5h7qJQHBH4zwOgykalfPqys4DtNabR08iM8+iV5CBirf8dZEFf/ynFASNh/07f Z+9Bq39rR7GAeSaLtR/LbG/7HSZJFb0MRGb/SABDOF1Dk6VK7Iqn2zhsWfrJqrS96zrV WMVaOOUgBZQ3RB64C4AOA0tS6t/kZG+F5qAAbmVJUtWTmDpWWh3GIEPFRH47quOKZ9JM bFg1cEnjLSCDKWcjFdPl7Zmks/wxQ8GnCqS598Alwx/oSHUF8Gbxz4KiqeXH+Qu96mb9 p+qtmPkm/Lnlq/Q3NpjD7MMNnJSuqvLzLX6qAcwfRQ+8sOno7FKBbDn058drZQvwJB4r +Iuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=2c4C3n0LRxWIX1WwXTdUDTm3hHPBj3ay99ram+tbJ5c=; fh=P55SO06TUyboS36XERnJ9AzV14aNuMIGn7xc2O4xJUc=; b=NiDjauBJid0iG3sZWo/iL1zwHJlKUjzU8amJcq3TmbY44N6P9HUQTOgik/YsyFNMmp NPgaSkM5GlH2RmBizhyg3bL8ur+4rihTE0jOwmUAbGgsQCv1baMrhL5LDFqvu9u+tEAE ZpjH1s3kyStPrSY+IfH4rLy2GPemFegDeNGAIytLzrBtGcJxv4BWVpEROaEhnkJwAy6r /86tYfOfXBIXR5sCb7SUKF/EMDvnSvpCH8ZEGF8v2rTprNoMVvo0Q6aza/nJ3pQLPCLy CU5PgnI11S3hVvfjaEU6l3ppGTZCr/tcGwy1ZEe6Kj1fQr95HdQjR/+BGleL6Wt1xWQC 9YxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=R+MpIeHs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h5-20020a056a00170500b006ce3c0dd603si890439pfc.340.2023.12.07.01.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 01:10:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=R+MpIeHs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4BD6280CA096; Thu, 7 Dec 2023 01:10:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbjLGJKT (ORCPT + 99 others); Thu, 7 Dec 2023 04:10:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231439AbjLGJKP (ORCPT ); Thu, 7 Dec 2023 04:10:15 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22F6B10DF for ; Thu, 7 Dec 2023 01:09:45 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-28657040cdcso637260a91.3 for ; Thu, 07 Dec 2023 01:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1701940185; x=1702544985; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2c4C3n0LRxWIX1WwXTdUDTm3hHPBj3ay99ram+tbJ5c=; b=R+MpIeHsJHivnaHL432W9ENPykPVOhtTnA0XNkp4U6jtWmSSG6NT6HlDA9h+igazof dVgosixcAb518PZlhr6gii+lu36hYymcZbzggLkwArOmI8WVYD4zutQxANL0vzVJeZjo WdU6eFKQzkXiWnQ/szG5krgjo4Etiy69Kek0uAuIQhyPF3PZCxNAVLFTKDoGdC4QTWux a2luye57uxXmBdNAfqjF4kgjo2evgIa6MK4pcLQ/YR6r3IRkMpq3VTBjRX6H4DBgb6ox tubfHCzzsrZ1k8uz9EFAbgRgoqNOmYLSqeosC38v2FJYIzjeVMwKEl+VknfDaEmAha2J mI6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701940185; x=1702544985; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2c4C3n0LRxWIX1WwXTdUDTm3hHPBj3ay99ram+tbJ5c=; b=EK4rm4ge105k9/TvpE0ZU5dEr3ni2vxxxbTijD2TrFcClYdvNSkvrruc+r4z2puXXR 5JJXt8IwAP4sMj8KtgdGzCYVseeDiRVMwTZKHBN9CmpWOXlHhP6aCE8yoFimEXme0jrq ayEx3jlSxSxI90c8Ivomi19PyFrH2naXlTgIvS8Mgo4wH4UuxL7STfM/a23GWJ/BseT6 mWwGdjQjBuOOmUvHExykTG+A/DoP549V/S2mvO6jzI6A34l/p7GSs8CiNi0fEWdb/Pq1 iVXA7wxtOosfy1YNipYsgVV1t/FDAdVEtsbnCi4ntXhyRYt6zUe19Z1PV+94OhDLj2tK hgVw== X-Gm-Message-State: AOJu0Yxesy8ENutvCFFBSCtH7oZ5y0xdC9A1O98lt0jNjOfc63ekEAow 12OpmMSS04rn569Fxlhl4S+Z6HZxTBilcapBUh9UTQ== X-Received: by 2002:a17:90b:3509:b0:286:9231:c5c1 with SMTP id ls9-20020a17090b350900b002869231c5c1mr1903943pjb.7.1701940185105; Thu, 07 Dec 2023 01:09:45 -0800 (PST) MIME-Version: 1.0 References: <20231026143122.279437-1-cleger@rivosinc.com> In-Reply-To: <20231026143122.279437-1-cleger@rivosinc.com> From: Xu Lu Date: Thu, 7 Dec 2023 17:09:33 +0800 Message-ID: Subject: Re: [External] [RFC PATCH 0/3] riscv: add support for SBI Supervisor Software Events To: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: 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, Himanshu Chauhan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 07 Dec 2023 01:10:34 -0800 (PST) Pardon. It seems that the code in opensbi[1] is not complete for PMU NMI no= w. 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=E2=80=AFPM Cl=C3=A9ment L=C3=A9ger 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@by= tedance.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-ale= xghiti@rivosinc.com/ [4] > > --- > > Cl=C3=A9ment L=C3=A9ger (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 >