From patchwork Tue Sep 10 13:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Chauhan X-Patchwork-Id: 1983240 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=JCdQGqK7; 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=gF2Zy2EY; 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 4X34GN501Bz1y1S for ; Tue, 10 Sep 2024 23:26:04 +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: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=b1uoyjdeCxLcaV5dK/myZ109sUzFVYStIDpUwa8cEjg=; b=JCdQGqK7ImOm5G ZIYRQAViT9SZm7levI4BCpi9eWgxYxfQhwYs6DFIzPDacKICwrb2yzBCkucWTd/tmPt0pZkaVCb84 XQu9HO8+XEUp9gwwTi8gwU/qOePtWdCLDraykLf8jJFY5wIgFdzj+HtVLL4/0jiS9oxf5H9kcE0+0 pK+p8hNqX47e4Hk3sLlF0OeoYhLLZo81xp3qIe7tiQEtRwd+ZpUSxNrtS1f9zSlr1k9ku26fyULrN xuQr44Ck4w1jmgD0z6sp+rTU7/4dsDFk9MHZm+9bAqPtBDqRtn5zsN22NzZOXGJV8wdM7jfKla837 ZpX/NuQExvd120mZ3lBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1so0sW-00000005hjy-0ysv; Tue, 10 Sep 2024 13:25:56 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1so0rb-00000005hYz-0rCm for opensbi@lists.infradead.org; Tue, 10 Sep 2024 13:25:00 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7178df70f28so600786b3a.2 for ; Tue, 10 Sep 2024 06:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1725974697; x=1726579497; 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=WFpmLutbRz8yHx1ItAd7FXV0J6cZ7s81wrcxgOebB3o=; b=gF2Zy2EYXMBg30Et/J3c46DZy1thtKKAepkKBGloUVDYTDSQL8vU2cO01x5oHIIc60 PY9jaq9LQE8B/oeAHbali7KMVe+Qtnmm5JpUvS3HsdBKkvdIRJVH8u4/in8XtPPg/UhW Vv5iEB3CLS+J4skWWAsjgAXZKz/42VKuL8j9ngdZXj4Q1tJQEN2unaFcXJKdIfJQpjSY ApJNYcJ9Jnsl1C8w0Y7VnlbptdunB5IAcsJECIvB65LBkQvSYTlgjc7kvxN8Faeq1wRn o3KNGlZfZLPioMGEoM0nhBvyo/3UwppDCntqN7a4dFD/kQ+GrCjmEdqa81ta9GuIxKUG OleQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725974697; x=1726579497; 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=WFpmLutbRz8yHx1ItAd7FXV0J6cZ7s81wrcxgOebB3o=; b=BhCWPMfBUN5e6x8DeBwost9MuFDWn4QmsvQq2mzsFqcOW++EUqU0FYJgN4R9U6ef/t p6pdmu3LXgaucyJZrVSSO4I88n3YE75sNDsFYozcy0ltZCeVnii1HKCp9o5Ve2ZiyLDr ld94wvN9RDoXtwVGV+oeHuEjpYUw+qGVG9ev7ZlsGu1jLnE1vLv8Wy/UAxp4tQc08BYl 3Xyu2r7DqNLOadhEUA66h4w/qza7OIkq9W3CIrGo+b5ugp/If5C3BvKAgYRlNqOwsyua rYVikB+9Q9BctbaPeBc3izP3l4Xf7vk10ICFTVxeYpvzJfp3pja29TUeMdjxU70g3Dnl u9ig== X-Gm-Message-State: AOJu0YxDCn/Md1Ogw3Rg0YLSoNjnz/GMOrRcMJcpf4Q3oSM2+kxfIrSh HdRGR5KHS8FruIEHSLYnHsimgNWYorwFSe7BXXW8McALdhnvUIEV0JpnMcLf+lfS7fTRvdFkvyJ M X-Google-Smtp-Source: AGHT+IEXLGd2M4sVFCJ10ZtA7JNQm1bvaih6ofCJnHhRkkoxzgyJZI3Molac5RfH5h/hQZCO3hSN5w== X-Received: by 2002:a05:6a00:27a0:b0:710:7fd2:c91 with SMTP id d2e1a72fcca58-718d5f1e7d7mr13459744b3a.26.1725974697378; Tue, 10 Sep 2024 06:24:57 -0700 (PDT) Received: from ventana.dc1.ventanamicro.com ([49.37.251.1]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71908fc8506sm1357643b3a.5.2024.09.10.06.24.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 06:24:56 -0700 (PDT) From: Himanshu Chauhan To: opensbi@lists.infradead.org Cc: Himanshu Chauhan Subject: [PATCH] lib: sbi: Add support to mask/unmask SSE events Date: Tue, 10 Sep 2024 18:54:49 +0530 Message-Id: <20240910132449.1977063-1-hchauhan@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240910_062459_270647_3C973771 X-CRM114-Status: GOOD ( 14.44 ) 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: A hart in non-retentive suspend state can't handle software events until the hart has come out of the non-retentive suspend and restored the hart state. To support this, define separate hart mask/unmask functions for the SSE extension which allow supervisor software to globally mask/unmask software event delivery on the calling hart. 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:436 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -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 Message has at least one valid DKIM or DK signature -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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org A hart in non-retentive suspend state can't handle software events until the hart has come out of the non-retentive suspend and restored the hart state. To support this, define separate hart mask/unmask functions for the SSE extension which allow supervisor software to globally mask/unmask software event delivery 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 | 31 +++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 085b33e7..3bf8f1da 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -342,6 +342,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_MASK 0x00000008 +#define SBI_EXT_SSE_HART_UNMASK 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..e9085324 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 sse_masked; }; /** @@ -608,6 +614,11 @@ 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->sse_masked) { + return; + } + spin_lock(&state->enabled_event_lock); sbi_list_for_each_entry(e, &state->enabled_event_list, node) { @@ -805,6 +816,24 @@ 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(); + + state->sse_masked = true; + + return SBI_SUCCESS; +} + +int sbi_sse_hart_unmask(void) +{ + struct sse_hart_state *state = sse_thishart_state_ptr(); + + state->sse_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 +1152,8 @@ 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->sse_masked = true; sse_set_hart_state_ptr(scratch, shs); }