From patchwork Thu May 16 12:30:28 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: 1935976 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=emI4TxHJ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=mwXV5OAF; 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 4Vg8Zw3NC8z20KF for ; Thu, 16 May 2024 22:31: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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=PeRAuUuRZl6mYrvT07R/QMxzucW3lmT2XCBqyKlYeEQ=; b=emI4TxHJYdLZul BPX8BeyirRt4y3jEJuq42zZq0rm8HnxOYbmld+7A5kML2xsup60vR9t2n2C+rTAporrm7Zc3LbMYq WVcuZIFJgr7SqZIUECZwDerqu7Q/NVf4sr3ROvZ4IZ8sWxL0Sp82m4avQkRn6a972VQRMkacdy2yE eDgGAlerwFhPsfYzWIiE/5Q66VRgG1+9TozzmGl8z1QZosDM9LZ0F2h//XNnwt1g7T+do7yTalj19 9FHCcnUSq3ciUPM2iZNn35MpPGuXvhNiDAmBJRAvSmT9ASXOC50RjpYzkJcrfAX7lCqO0nLOuMuOD 8s2T3+siKg+ipWXT9Atg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7aG4-00000004oon-1IR5; Thu, 16 May 2024 12:30:52 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s7aG0-00000004onw-3cgo for opensbi@lists.infradead.org; Thu, 16 May 2024 12:30:50 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2b2aab2d46dso48344a91.0 for ; Thu, 16 May 2024 05:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715862645; x=1716467445; 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=xMcCtjL57TZR4q4mO1KHnlD5r3EcsSA+SrEvas1wX5o=; b=mwXV5OAFl7UgxIRi9PgtU19bpByaXilow1VlYoSL6bmWyTYsQh4zPtjfV+yPGEI+pW 3Exqe4YkF5ypsaB+kL6wM9nYzy6G1BkDscHNIjUJcOMYkd19YtgnzLxLLOvC8QEwxtUz azOz3twRDMkHo2pscb/aOrbnHOhHAUSEqeyEImNqzu/YxokSqxkS2FY4r0Ntyoa58oCc uS4Mbsf93VLApTipsSjIPJG5jGli/yIuOWNEDj7PJ5W4qeBtbN2HaVKh3KuzpZr72joP ty+OTGQKJi5IGPHughtnoePC+JvBaXNZIKoRBPJWF6SqlnV0X5x7GgW/SeuwP4Wna5qT jbYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715862645; x=1716467445; 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=xMcCtjL57TZR4q4mO1KHnlD5r3EcsSA+SrEvas1wX5o=; b=hdwgz4nDY18IluH+8n1f2HkWVZhiT9N5+ANw1HkMg4i+jjWv3q9mX7W0He3sd41gHi +/dmpXwY9JzUBq1jO5IMC89RPldmMNZ0gNg/F+rvFgpUWexLVgpQMIP53FyxRqrYlKZs GIg+77bDTDaITbzCSEDo2j9rgmG5D0da4DXXbxrHFurnpjjRWrL0lKYy9+EFXaE0+qWp 8IuxZ1S8Sz2+TX0epaSM29fJN7A1P4xwhwlUOI92SOrHeMe5naEE7P5nvOMw/e7mKJVk nO2H2QyHMEKEbeTC2oJl9TwVI4Tt75byHk2klK/bneMojmsRCiYiRkE0eCOt3CaQ7wxX TogA== X-Gm-Message-State: AOJu0YwbARc887NkZgSqqOASppqfMrDg9B6SjHEcRXB0SlDjjglskz// LTvKCFUVKFRAMsmX5mgniEwQQDq1WuSnLJ8/tA5j1UzMV8enRL1yim9DHQNAOWwsWef4GcLWUM0 qWYE= X-Google-Smtp-Source: AGHT+IHCkW5s9QBknK12nqlzE/zn9vmNXqI4hw1/sjdsqMjaeIKRCU/XHFhILF8FcbNVmoFMw7Sjhg== X-Received: by 2002:a17:902:f547:b0:1e4:397b:492c with SMTP id d9443c01a7336-1ef4405836fmr216040595ad.4.1715862644814; Thu, 16 May 2024 05:30:44 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:9cd2:f307:62c5:d195]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c037207sm136999755ad.221.2024.05.16.05.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 05:30:44 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Subject: [PATCH] lib: sbi: sse: handle missing writable attributes Date: Thu, 16 May 2024 14:30:28 +0200 Message-ID: <20240516123029.18379-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-20240516_053049_037914_DFB52D06 X-CRM114-Status: GOOD ( 12.03 ) X-Spam-Score: 0.0 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__The_spec_states_that_a6=2C_a7=2C_flags?= =?unknown-8bit?q?_and_sepc_are_writable_but?= =?unknown-8bit?q?_the_implementation_was_not_allowing_that=2E_Add_support_fo?= =?unknown-8bit?q?r_these_4_writable?= =?unknown-8bit?q?_attributes=2E_Signed-off-by=3A_Cl=C3=A9ment_L=C3=A9ger_=3C?= =?unknown-8bit?q?cleger=40rivosinc=2Ecom=3E_---_lib/sbi/sbi=5Fsse=2Ec?= =?unknown-8bit?q?_=7C_66_+++++++++++++++++++++++++++++++++_1_file_changed=2C?= =?unknown-8bit?q?_47_insertions=28+=29=2C?= =?unknown-8bit?q?_19_deletions=28-=29_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=280=2E0_points=2C_5=2E0_req?= =?unknown-8bit?q?uired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C_no?= =?unknown-8bit?q?_trust?= =?unknown-8bit?b?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDoxMDM1IGxpc3RlZCBpbl0=?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily_valid?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= 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: Anup Patel , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The spec states that a6, a7, flags and sepc are writable but the implementation was not allowing that. Add support for these 4 writable attributes. Signed-off-by: Clément Léger Reviewed-by: Samuel Holland Reviewed-by: Anup Patel --- lib/sbi/sbi_sse.c | 66 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index 0cd6ba6..e39963f 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -335,30 +335,49 @@ static int sse_event_set_hart_id_check(struct sbi_sse_event *e, static int sse_event_set_attr_check(struct sbi_sse_event *e, uint32_t attr_id, unsigned long val) { - int ret = SBI_OK; - switch (attr_id) { case SBI_SSE_ATTR_CONFIG: + if (sse_event_state(e) >= SBI_SSE_STATE_ENABLED) + return SBI_EINVALID_STATE; + if (val & ~SBI_SSE_ATTR_CONFIG_ONESHOT) - ret = SBI_EINVAL; - break; + return SBI_EINVAL; + + return SBI_OK; case SBI_SSE_ATTR_PRIO: + if (sse_event_state(e) >= SBI_SSE_STATE_ENABLED) + return SBI_EINVALID_STATE; + #if __riscv_xlen > 32 - if (val != (uint32_t)val) { - ret = SBI_EINVAL; - break; - } + if (val != (uint32_t)val) + return SBI_EINVAL; #endif - break; + return SBI_OK; case SBI_SSE_ATTR_PREFERRED_HART: - ret = sse_event_set_hart_id_check(e, val); - break; + if (sse_event_state(e) >= SBI_SSE_STATE_ENABLED) + return SBI_EINVALID_STATE; + + return sse_event_set_hart_id_check(e, val); + case SBI_SSE_ATTR_INTERRUPTED_FLAGS: + if (val & ~(SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPP | + SBI_SSE_ATTR_INTERRUPTED_FLAGS_STATUS_SPIE | + SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPV | + SBI_SSE_ATTR_INTERRUPTED_FLAGS_HSTATUS_SPVP)) + return SBI_EINVAL; + __attribute__((__fallthrough__)); + case SBI_SSE_ATTR_INTERRUPTED_SEPC: + case SBI_SSE_ATTR_INTERRUPTED_A6: + case SBI_SSE_ATTR_INTERRUPTED_A7: + if (sse_event_state(e) != SBI_SSE_STATE_RUNNING) + return SBI_EINVALID_STATE; + + if (current_hartid() != e->attrs.hartid) + return SBI_EINVAL; + + return SBI_OK; default: - ret = SBI_EBAD_RANGE; - break; + return SBI_EBAD_RANGE; } - - return ret; } static void sse_event_set_attr(struct sbi_sse_event *e, uint32_t attr_id, @@ -375,6 +394,19 @@ static void sse_event_set_attr(struct sbi_sse_event *e, uint32_t attr_id, e->attrs.hartid = val; sse_event_invoke_cb(e, set_hartid_cb, val); break; + + case SBI_SSE_ATTR_INTERRUPTED_SEPC: + e->attrs.interrupted.sepc = val; + break; + case SBI_SSE_ATTR_INTERRUPTED_FLAGS: + e->attrs.interrupted.flags = val; + break; + case SBI_SSE_ATTR_INTERRUPTED_A6: + e->attrs.interrupted.a6 = val; + break; + case SBI_SSE_ATTR_INTERRUPTED_A7: + e->attrs.interrupted.a7 = val; + break; } } @@ -903,9 +935,6 @@ static int sse_write_attrs(struct sbi_sse_event *e, uint32_t base_attr_id, uint32_t id, end_id = base_attr_id + attr_count; unsigned long *attrs = (unsigned long *)input_phys; - if (sse_event_state(e) >= SBI_SSE_STATE_ENABLED) - return SBI_EINVALID_STATE; - sbi_hart_map_saddr(input_phys, sizeof(unsigned long) * attr_count); for (id = base_attr_id; id < end_id; id++) { @@ -944,7 +973,6 @@ int sbi_sse_write_attrs(uint32_t event_id, uint32_t base_attr_id, return SBI_EINVAL; ret = sse_write_attrs(e, base_attr_id, attr_count, input_phys_lo); - sse_event_put(e); return ret;