From patchwork Mon Jun 17 15:41:02 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: 1948675 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=bReMDDaF; 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=JKuHGCVz; 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 4W2vJF20cPz20KL for ; Tue, 18 Jun 2024 01:41:49 +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=4Kz9Bito3XAKowXKnDVIVe1kPuFm+nIBOPMZsvRR71c=; b=bReMDDaFBKqmF0 Y44T7tyIDYJJH2xK+ryYZIsID1fOiLiCUKuoJ/7znSU0dJCUwyiqB6QUi+O5nrJdvgr7HzwhGfJI+ il2BVUpeiW9azxoMmevjy24GWDl4MRkX97XySV9ObSpc/7zbEKSQsliujAXmr0rY91PCPiT7kh+n4 UZfunWfWuONnKkHE2TEVwilvLLWwCIKIYJKmRqxgOEYJP8Op+CXSD96oUgQFPSb5enIBz+doqkhPE j2t9GSmV8L4jhKrPoWuOXjabulwThzsDMyYfT1nvkJdgVR+tP6J0+TBvYovDI0o7TQonC5ZliGA3v ikrkXTkq6++eJDZp71dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJEUG-0000000BWxM-48Og; Mon, 17 Jun 2024 15:41:40 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJEUE-0000000BWvG-1Mae for opensbi@lists.infradead.org; Mon, 17 Jun 2024 15:41:40 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a6f2f5ad1d1so31931166b.1 for ; Mon, 17 Jun 2024 08:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1718638896; x=1719243696; 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=XrtkknkD7ZsY20aY+1W+NOqr3PyEBJNio5mr92p4au8=; b=JKuHGCVzD/P04tuv8qe1p4dGdDlHek173iq/Pd2t8KDj8SZID6mDrkNri2Cx39ZBii POs9j8tkzAKbeu/WYH0tReNZy0PFNEDfDUe9AtpPC0QbVHTahK5J/Rs2zTTEqJPhsTvJ WkU62KzNMvnYAmjU6+f2PK7x7GPBTIPMzJ0TFztBfWfjh0LMynu6HKipRpDsjaK+ZHpY KPiXNuyb236aXJLuTGCfq3Zx1z3PZzcS7BLs1x1olDJeYJP1iZf6zp0zG8eXav5wdCGE nyceZWbCUpiADug+8BRXEBWaXbpvlZb7qyiucJJy9aA1xjGbDtRa0D2ZwEEDYvcwLWp/ 9QNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638896; x=1719243696; 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=XrtkknkD7ZsY20aY+1W+NOqr3PyEBJNio5mr92p4au8=; b=vAsXduT2HkIzL0KlCfvK8bv/Y7NRcbk9shLo12BYHuTggXwbdpjPG/+D7iWoUg7NYz VGzvILnJ/ZV2KE7aAsMX1QMC2GoXxdbWE2W3uCS/uNwmORTCBUD59TPXGjeqwN2/NDb4 svkvgBMEycy4cDWM4rng2AgimzPZV30GJ+P11qUL2SMQzbIQtEcW52WRZ2QVj8ZwHpBx Neok/yEwe9g5xsWA2AACQwD3j0/G5k8VlF4eKRcC7chwtgLOhv+C0A2yyBVQwxH2lVCL HdQjqKd0uXhbo8nCK9MqKSM1GLUez5aNv0Pk3ns8Wn8zy+ZeRi1Qz83xtYgJDLUefkUs /gQQ== X-Gm-Message-State: AOJu0YyTg5NUL3x1cDtUEjl+kzQfKuS/8by2lHOFFIsuNRE5kkVj00yk jAHrHx+biliTlGGMQG7/+7qTBvb5qqjE7PU29nn+39vb07pecY5lfcYAqSLVEdQo0TgIT0WFgpV LBGU= X-Google-Smtp-Source: AGHT+IH+Krh0pDfOErQPn5rMfJvdmAVMeEqTcq3KqxeHlqbcmL5HamMW9npdPYixH5JhIqQ9nkM4jA== X-Received: by 2002:a05:6000:2ad:b0:35f:1edb:4695 with SMTP id ffacd0b85a97d-3607a79f435mr7141190f8f.6.1718638875158; Mon, 17 Jun 2024 08:41:15 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:9f43:3ca4:162c:d540]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36075104d88sm12097923f8f.104.2024.06.17.08.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:41:14 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Anup Patel , Atish Patra Subject: [PATCH v2 2/4] lib: sbi: fwft: add support for SBI_FWFT_MISALIGNED_EXC_DELEG Date: Mon, 17 Jun 2024 17:41:02 +0200 Message-ID: <20240617154110.4007865-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240617154110.4007865-1-cleger@rivosinc.com> References: <20240617154110.4007865-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240617_084138_451113_E77FCD2F X-CRM114-Status: GOOD ( 12.60 ) 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_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?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDo2MzQgbGlzdGVkIGluXQ==?= =?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=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?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=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 --- 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..47edab2 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_hedeleg; 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_hedeleg = csr_read(CSR_HEDELEG); } 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_HEDELEG, hdata->saved_hedeleg); csr_write(CSR_MIE, hdata->saved_mie); csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP))); }