From patchwork Mon Sep 23 05:56:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Chauhan X-Patchwork-Id: 1988395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2amkt6JZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=FZbeYpO1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XBsh66J51z1xsp for ; Mon, 23 Sep 2024 15:56:52 +1000 (AEST) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3ipmQ5KqL8FzRHGjAvkeR9bb4aCuCrh82RqIVL0FwcE=; b=2amkt6JZAwPiZ/ oLzvODEfyOUgDayKw1K4VEOYNjX8RkvcV5qdcW2V5TgWaF3p5BvA8p5VrkeKQlvIVNSVxGKCfxy/R 08/1a4eTBXg5PLGlaiVO9SR4Irtsi1UQh9kHQmnEqIAzNLhhESSvN5ip6qjMN2OhDIcep1G6Ih0DR DPpOVBq4o5G211pYohZFd5i4dPe19vV1PHjileEBctWQe7/BNJ3JmN8WUD/s6Zes6QSXyqNbhdAsU tx2zNzrAcZBHLxnXhmGQ2MPUnHkDiBnpx8M1IrY3QPYJcLZhR2hZmdC2XCXvRmFuRhpR8uEcYOKBa RMnzPahM2MCs/H0nk6dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssc3w-0000000GNdA-0yG7; Mon, 23 Sep 2024 05:56:44 +0000 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssc3t-0000000GNcU-40EY for opensbi@lists.infradead.org; Mon, 23 Sep 2024 05:56:43 +0000 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-71781f42f75so3778402b3a.1 for ; Sun, 22 Sep 2024 22:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1727071001; x=1727675801; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5YvUZVUEibBAByFSpzNzlF0GUcDaXuT3TyniTiZ2xvM=; b=FZbeYpO1thrd5Fz+IPoiQkR1TAAvyTT5TvF039KfW4viv1enKJKZf0NLQJBIB/rm5M ABPacKlvjbBd3pYuwT+kRLBdZSgEKwFnX37yZI1gfzvidpCkd7KHSHoTPsrehgfSgZWs bz8B7KHuKxL2ZdApJxkw0qel8V41Vb5TsRHxeMQDZZupDdEHbR2Omeo4FRLDlRTNlye4 hlUrRq5ghAMq1IPykOqyBizXQem1+fQdjn6R++Kf+FDspC7YSha3gg9nWUp2Ud+1KhNl XM8asSFSLgOKwwThGpIEDdZe2A8C7u35ihF1W4fC8MgX6L5VmgzXpuh1WUfVnxY/N5jM VJjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727071001; x=1727675801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5YvUZVUEibBAByFSpzNzlF0GUcDaXuT3TyniTiZ2xvM=; b=vmi0TphS+WHeDWjlKHtx3Zbv8A0DZkEMHhmoiDiHfnWuWbXbAwjqC9WyChe0Qnx1Al JrozoslRSdkL0TEfnVABKIORnhwavECAtAJTMzFXNkBcXMV8EfiZBJvqwU9B7nPGG6NA QdkRQFnN2PUf9A+iIkZyvhjmL2BEpwOuXPDU7oCa6IC/9Rbm3pzMJZA+RE+MxgjTEntN M3UEQR8JgzEJKP+7P6nOm4GbF84+HSGt3pk+8gngJ6fWWtpikjA7Q+F8XU2yuWFnvBJ3 2HaGIS4hb+wIPpaRd5CKVyZXf9fHTq/O6Z0cyeyRCsvUXkASOkY6/XxjSUvrV81Al94n oX0w== X-Gm-Message-State: AOJu0YxwYVAjySIKQaLGie7P8MvKhrCP9rOMImI+Gm3zcwZc2GR1Egip GlQWoS1Qt0ED1lTNfA6VZBAczDLayGqJC6/Jw9EeM4uY9yLqZ/abIiFmMdKOtnpw8EwTI6a5Jpa q X-Google-Smtp-Source: AGHT+IHJymy4tLL/+3DsefnIqlfXvNg67TrtdSpKR7nFGRg8XF9bxXymrCJ6Ux/ApoOpPuijIyKYqg== X-Received: by 2002:a05:6a00:92a2:b0:710:da27:f176 with SMTP id d2e1a72fcca58-7199cd6bbc4mr18333267b3a.12.1727071000639; Sun, 22 Sep 2024 22:56:40 -0700 (PDT) Received: from ventana.dc1.ventanamicro.com ([2405:201:d019:c0ce:333c:8d20:57b8:2704]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944a9831esm13192582b3a.24.2024.09.22.22.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2024 22:56:40 -0700 (PDT) From: Himanshu Chauhan To: opensbi@lists.infradead.org Subject: [PATCH v2 1/1] lib: sbi: Add support to mask/unmask SSE events Date: Mon, 23 Sep 2024 11:26:26 +0530 Message-ID: <20240923055626.1146237-2-hchauhan@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240923055626.1146237-1-hchauhan@ventanamicro.com> References: <20240923055626.1146237-1-hchauhan@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240922_225642_019763_D1E93AE3 X-CRM114-Status: GOOD ( 13.25 ) X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add functions to globally mask/unmask supervisor software events on the calling hart. Signed-off-by: Himanshu Chauhan --- include/sbi/sbi_ecall_interface.h | 2 ++ include/sbi/sbi_sse.h | 2 ++ lib/sbi/sbi_ecall_sse.c | 6 +++++ lib/sbi/sbi_sse.c | 43 +++++++++ [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42f listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Himanshu Chauhan Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add functions to globally mask/unmask supervisor software events on the calling hart. Signed-off-by: Himanshu Chauhan --- include/sbi/sbi_ecall_interface.h | 2 ++ include/sbi/sbi_sse.h | 2 ++ lib/sbi/sbi_ecall_sse.c | 6 +++++ lib/sbi/sbi_sse.c | 43 +++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index e9a81677..40ab32aa 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -341,6 +341,8 @@ enum sbi_cppc_reg_id { #define SBI_EXT_SSE_DISABLE 0x00000005 #define SBI_EXT_SSE_COMPLETE 0x00000006 #define SBI_EXT_SSE_INJECT 0x00000007 +#define SBI_EXT_SSE_HART_UNMASK 0x00000008 +#define SBI_EXT_SSE_HART_MASK 0x00000009 /* SBI SSE Event Attributes. */ enum sbi_sse_attr_id { diff --git a/include/sbi/sbi_sse.h b/include/sbi/sbi_sse.h index e5b0ad69..7419698a 100644 --- a/include/sbi/sbi_sse.h +++ b/include/sbi/sbi_sse.h @@ -78,6 +78,8 @@ void sbi_sse_exit(struct sbi_scratch *scratch); int sbi_sse_register(uint32_t event_id, unsigned long handler_entry_pc, unsigned long handler_entry_arg); int sbi_sse_unregister(uint32_t event_id); +int sbi_sse_hart_mask(void); +int sbi_sse_hart_unmask(void); int sbi_sse_enable(uint32_t event_id); int sbi_sse_disable(uint32_t event_id); int sbi_sse_complete(struct sbi_trap_regs *regs, struct sbi_ecall_return *out); diff --git a/lib/sbi/sbi_ecall_sse.c b/lib/sbi/sbi_ecall_sse.c index a28a033e..beddc2cd 100644 --- a/lib/sbi/sbi_ecall_sse.c +++ b/lib/sbi/sbi_ecall_sse.c @@ -36,6 +36,12 @@ static int sbi_ecall_sse_handler(unsigned long extid, unsigned long funcid, case SBI_EXT_SSE_INJECT: ret = sbi_sse_inject_from_ecall(regs->a0, regs->a1, out); break; + case SBI_EXT_SSE_HART_MASK: + ret = sbi_sse_hart_mask(); + break; + case SBI_EXT_SSE_HART_UNMASK: + ret = sbi_sse_hart_unmask(); + break; default: ret = SBI_ENOTSUPP; } diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index 52172fcd..aff64268 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -141,6 +141,12 @@ struct sse_hart_state { * List of local events allocated at boot time. */ struct sbi_sse_event *local_events; + + /** + * State to track if the hart is ready to take sse events. + * One hart cannot modify this state of another hart. + */ + bool masked; }; /** @@ -608,6 +614,10 @@ void sbi_sse_process_pending_events(struct sbi_trap_regs *regs) struct sbi_sse_event *e; struct sse_hart_state *state = sse_thishart_state_ptr(); + /* if sse is masked on this hart, do nothing */ + if (state->masked) + return; + spin_lock(&state->enabled_event_lock); sbi_list_for_each_entry(e, &state->enabled_event_list, node) { @@ -805,6 +815,36 @@ int sbi_sse_disable(uint32_t event_id) return ret; } +int sbi_sse_hart_mask(void) +{ + struct sse_hart_state *state = sse_thishart_state_ptr(); + + if (!state) + return SBI_EFAIL; + + if (state->masked) + return SBI_EALREADY_STARTED; + + state->masked = true; + + return SBI_SUCCESS; +} + +int sbi_sse_hart_unmask(void) +{ + struct sse_hart_state *state = sse_thishart_state_ptr(); + + if (!state) + return SBI_EFAIL; + + if (!state->masked) + return SBI_EALREADY_STOPPED; + + state->masked = false; + + return SBI_SUCCESS; +} + int sbi_sse_inject_from_ecall(uint32_t event_id, unsigned long hartid, struct sbi_ecall_return *out) { @@ -1123,6 +1163,9 @@ int sbi_sse_init(struct sbi_scratch *scratch, bool cold_boot) shs->local_events = (struct sbi_sse_event *)(shs + 1); + /* SSE events are masked until hart unmasks them */ + shs->masked = true; + sse_set_hart_state_ptr(scratch, shs); }