From patchwork Wed Jun 19 09:42:40 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: 1949604 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=vtU5y11K; 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=CDcs3IsQ; 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 4W3zFm0Q8Lz20Wb for ; Wed, 19 Jun 2024 19:43:24 +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:References:In-Reply-To: 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: List-Owner; bh=uh9TVPl7lltaVTHtTizPCyuNfksgdPwlqwhYAKap5Ok=; b=vtU5y11KPM9KFH 9j+TAPcJtMUqJ63bDkYZe59eOCFNyEZoUyWOd5VsvVMdzFFrB46wVrweOVhlv50zVCya2a9YbC37s 5/kDRFXVbEohP+f+5YnqGrqh8N+zfdDXHXy2NPPF22GWQd1O0HHZWvFGhd08CHbeL2nWFCDG0vCM3 evKW8o5VDRr6i2Q+1BcjMHjSRP6DqcT4CIQSuGnlyuXqEhPgnuimXZCbmBsucolq9B3Io16gWHVYv b2964QUjFVYvxEbABM+zWOY1sSAgWaH5w5w1w5lQ8Vg+LOHPQtooB93t9gS8Q/eoVD7ikJuAv2sx8 v5lq4I849/VQobpgjclA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJrqX-00000000dB3-1rhe; Wed, 19 Jun 2024 09:43:17 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJrqU-00000000d9u-0sHC for opensbi@lists.infradead.org; Wed, 19 Jun 2024 09:43:15 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-7063478ff2eso11411b3a.0 for ; Wed, 19 Jun 2024 02:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1718790192; x=1719394992; 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=biywBaYH3kIGoB14Z/xF7VjnNljbdhlW2wgjP/6bsk4=; b=CDcs3IsQdxUEyvibeef38vp2rwEOYGcBYDvb3koQ+KWaCZF6FLd+2kEkEqTkLhWv2j 1Xau8/7/yISTqTJKZ9OdY5Z6UWVXhdx8XyKsqqVtv/1n1JlgV3gE7y+R7LlJsW7KU7I/ ikRq3wfWDRrPuWeYPAxyPE7/oUH279nq1bfqM86Ta+6kX7Va2H5cZJPxGEctwBg9fcSK rvteRPydNcXoIjSDRlzml3TP1lA0c4bTLYc+rbo7QhPAyiIFYT4CzTzYWXVo8QCn3XH8 aOuzTOx7dhfgP1bBYkF7Zv7UKLdfu0FwL7kHqtWC/ISWkOF4yPG3RdhU0jXgH602CE5U JQtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718790192; x=1719394992; 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=biywBaYH3kIGoB14Z/xF7VjnNljbdhlW2wgjP/6bsk4=; b=YWSbf7AEdpkVcTOl0FtbfxxrdwWOldmQaShzo+7rWE8b8sy/Lq6/RIF7Y4MHc30KRV dPDBIA+k/OIKp8kOsaTJqfhrYFEkCzFsrKr+cIZLcjpv7l01FS+DLEWn4V8+61TvNBJ1 qf+qy7sWcn/xkBZVJcwouZqFQ8Ks/ING7UheIvgCUQSj1+iboQzcRCi63tPWgCOwAen1 glDd7M0/vIy6GOnlYbwlciJeWnDJOM1veyGbUNF6mDt3QZ7P5lv8tg1O7KIJPBhbrAhk Q7FTjHn62uytUWZS3wmYCX4L+Ryrrc0DCbYYlB5R/XpJ3G9BlJHSwFC+vXLf8VdQv/MS rbEg== X-Gm-Message-State: AOJu0YzWuMdHoCfFjqQkD9vBwze5iSpPRbPvLBD4RncSBtDJuhv9PFQ2 FJd0OcUYSInXL2byDULrKNqu3jpfs0MO8OMbao9XAW0ePtpl64spxLw25nZ+msCtt2Hm9TpeMav SDao= X-Google-Smtp-Source: AGHT+IFmZjhJc67C/i8CGsXEZ5MIIekxfUm5IjUNCTm7u7Wcb+CXW2dokhNaZLrBGE3W1fU+MCgv8A== X-Received: by 2002:aa7:91cc:0:b0:705:d820:de3c with SMTP id d2e1a72fcca58-70629cc0848mr2016743b3a.2.1718790192191; Wed, 19 Jun 2024 02:43:12 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:b69:7f57:35a2:8f92]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705cc97af20sm10259067b3a.70.2024.06.19.02.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 02:43:11 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Anup Patel , Atish Patra Subject: [PATCH v3 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Date: Wed, 19 Jun 2024 11:42:40 +0200 Message-ID: <20240619094244.603628-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240619094244.603628-1-cleger@rivosinc.com> References: <20240619094244.603628-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240619_024314_360978_2E2A7CF2 X-CRM114-Status: GOOD ( 13.26 ) 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__Add_support_for_SBI=5FFWFT=5FMISALIGNE?= =?unknown-8bit?q?D=5FEXC=5FDELEG_withing_FWFT?= =?unknown-8bit?q?_support=2E_This_support_allows_to_delegate_misaligned_acce?= =?unknown-8bit?q?sses_traps=2E_Signed-off-by=3A?= =?unknown-8bit?q?_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger=40rivosinc=2Ecom=3E_---_?= =?unknown-8bit?q?lib/sbi/sbi=5Ffwft=2Ec_=7C_39_++++++++++++++++++++++++++++?= =?unknown-8bit?q?++++++++++-?= =?unknown-8bit?q?_lib/sbi/sbi=5Fhsm=2Ec_=7C_3_+++_2_files_changed=2C_41_inse?= =?unknown-8bit?q?rtions=28+=29=2C_1_deletion=28-=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-0=2E0_points=2C_5=2E0_re?= =?unknown-8bit?q?quired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?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=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?= =?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?IFsyNjA3OmY4YjA6NDg2NDoyMDowOjA6MDo0MzUgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_-0=2E0_T=5FSCC=5FBODY=5FTEXT=5FLINE___No_description_avail?= =?unknown-8bit?q?able=2E?= 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 Add support for SBI_FWFT_MISALIGNED_EXC_DELEG withing FWFT support. This support allows to delegate misaligned accesses traps. Signed-off-by: Clément Léger Reviewed-by: Anup Patel --- lib/sbi/sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++++++- lib/sbi/sbi_hsm.c | 3 +++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index b302b5d..289a344 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -32,6 +32,8 @@ static unsigned long fwft_ptr_offset; #define fwft_set_hart_state_ptr(__scratch, __phs) \ sbi_scratch_write_type((__scratch), void *, fwft_ptr_offset, (__phs)) +#define MIS_DELEG (1UL << CAUSE_MISALIGNED_LOAD | 1UL << CAUSE_MISALIGNED_STORE) + struct fwft_config; struct fwft_feature { @@ -71,6 +73,33 @@ static bool fwft_is_defined_feature(enum sbi_fwft_feature_t feature) return false; } +static int fwft_misaligned_delegation_supported(struct fwft_config *conf) +{ + if (!misa_extension('S')) + return SBI_ENOTSUPP; + + return SBI_OK; +} + +static int fwft_set_misaligned_delegation(struct fwft_config *conf, + unsigned long value) +{ + if (value) + csr_set(CSR_MEDELEG, MIS_DELEG); + else + csr_clear(CSR_MEDELEG, MIS_DELEG); + + return SBI_OK; +} + +static int fwft_get_misaligned_delegation(struct fwft_config *conf, + unsigned long *value) +{ + *value = (csr_read(CSR_MEDELEG) & MIS_DELEG) != 0; + + return SBI_OK; +} + static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) { int i; @@ -148,7 +177,15 @@ int sbi_fwft_get(enum sbi_fwft_feature_t feature, unsigned long *out_val) return conf->feature->get(conf, out_val); } -static const struct fwft_feature features[] = {}; +static const struct fwft_feature features[] = +{ + { + .id = SBI_FWFT_MISALIGNED_EXC_DELEG, + .supported = fwft_misaligned_delegation_supported, + .set = fwft_set_misaligned_delegation, + .get = fwft_get_misaligned_delegation, + }, +}; int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) { diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index be48d64..2b23e13 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -44,6 +44,7 @@ struct sbi_hsm_data { unsigned long suspend_type; unsigned long saved_mie; unsigned long saved_mip; + unsigned long saved_medeleg; atomic_t start_ticket; }; @@ -417,6 +418,7 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch) hdata->saved_mie = csr_read(CSR_MIE); hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP); + hdata->saved_medeleg = csr_read(CSR_MEDELEG); } static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) @@ -424,6 +426,7 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); + csr_write(CSR_MEDELEG, hdata->saved_medeleg); csr_write(CSR_MIE, hdata->saved_mie); csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP))); }