From patchwork Thu Sep 12 12:10:47 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: 1984645 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=3ud+1CIN; 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=PrF0+3Fl; 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 4X4GXx2xs0z1y25 for ; Thu, 12 Sep 2024 22:12: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=Bn0vfn823Qw77eQF6Mv3qlzxgvmxtQ4pSwce9nQnd88=; b=3ud+1CIN8yTbxo Qz+QWUY7vj6FephSMvYoCvzbcPzFweznewR2pnNvmyktQOMnMXMSmmg0JdKPIkf5pPhY5Crdk8uk3 18nbEKhD8QLlNJahVVYvXG3UB/P+p7DZ4Uk/kMWgNjg0B2j6T0zk/VJUfAMFPOXO4Lx/hu0cIX7e9 OQrGLvr6wdLq79gyHl/xA1Whvl75GA6IRFSI8JJxsDy8R6Dh4Nm11kQjjIx7YbGF3hzKkKduVsbsu e/avplSPZc92M3gOGuH7EN48mOE8m1UYjZkDthax3JYL3tz5WqnZrDFoJLZ6MCvxJHuljkrmOfTCZ WT+5lRIp2f2DRQzY2K+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soigk-0000000CyA6-07qS; Thu, 12 Sep 2024 12:12:42 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soif8-0000000CxhW-1rhQ for opensbi@lists.infradead.org; Thu, 12 Sep 2024 12:11:03 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42cde6b5094so6065245e9.3 for ; Thu, 12 Sep 2024 05:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1726143060; x=1726747860; 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=rJFxqQ2KJDupp9rk4vjQdvA/KJwi5G8RZ0SjemSNMqI=; b=PrF0+3FldwN1e6roYZfZP2MyQnGqtPyf4IdMIj+vClh9uYbIfjj7iYToOQYQnKfFbH v23AnBjfalkso7nVmgtNSPZWXvbznc6fBmlatbHo+7CxKzO3Zd1KCKWC+jnCub+L1wI2 VpTwdo74x1i8vLFD1L6yZlSgY40Fyt8kYZs95JuXjGeNM/ZAoPmjW8qfEM+jsQVZAM18 Koj7l0vO2DmvF5JeJzqljOMaSw9AN+CH2ohBJeuyC+op2s4RkTukklvHB7lS3QZ9NOlF WMldCmTE0fqjuUUuS4ahf/Em4NrDUkKOvmIQeJwx4cAoHXP7V7GqzWEcS6fEYDFKd79a MWHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726143060; x=1726747860; 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=rJFxqQ2KJDupp9rk4vjQdvA/KJwi5G8RZ0SjemSNMqI=; b=SE7EaUP60Ea+05ET6YICUIiG+H0FEF1iMDD8enMqSblFj8RmfzJM74hRBmQFvHw+Wy 3OXBkVXb50wrVh+phpgJszwoyQKdVWMLiefYdNf0MXFXG/dO7HsYQMrBrbtJ5ZGqpopS xSFG6bTRpCDWIitOgPKsLV2HulSwHIEU1xYIdD2LxJAJWKqpqroVl3Pn7uoH67ieqllU m1ortxKfYkh1PiZCIM9bKXu+Wy9lxoazjfbvD73X5+5hLwpAMn/zBMrKUh4sgQpxyI3R CsnlZcSM/wLE1FLUOZVRMjtDWQ8RCKvysBW4LwkqE+56DxPZe/2nZfOFFZ/E3zw5RjZV doxQ== X-Gm-Message-State: AOJu0YzRKZB7H++DwQjWF12BT8YSZkljh42ZxzPjrQZHKdUh5IJopnhK zXdDhw1O9U7YHbHgWMXgoNRHxyk4R2dEgkmkqkudsnXsdLOSBdzrU7xJooodktNUKsYHlCXS+hN DniM= X-Google-Smtp-Source: AGHT+IHKtAsCWcoga3jpUKCaWErJJkr42bWwDkvdvZ0+cpZRZRvT0ArRfhIwobmwOHtXUmj05nlS2Q== X-Received: by 2002:a05:600c:4f82:b0:42c:b8cc:205a with SMTP id 5b1f17b1804b1-42cdb58dfe7mr18303355e9.32.1726143059807; Thu, 12 Sep 2024 05:10:59 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb5ba4532sm146884895e9.38.2024.09.12.05.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 05:10:58 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: opensbi@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Atish Patra , Anup Patel , Ved Shanbhogue Subject: [PATCH 3/5] lib: sbi: fwft: factorize menvcfg read/write Date: Thu, 12 Sep 2024 14:10:47 +0200 Message-ID: <20240912121052.2959596-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240912121052.2959596-1-cleger@rivosinc.com> References: <20240912121052.2959596-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_051102_614398_8AF38E59 X-CRM114-Status: GOOD ( 11.51 ) X-Spam-Score: -1.9 (-) 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__MENVCFG_access_will_be_used_as_well_fo?= =?unknown-8bit?q?r_double_trap=2C_landing?= =?unknown-8bit?q?_pad_and_shadow_stack_fwft_support=2E_Factorize_that_in_a_c?= =?unknown-8bit?q?ommon_function=2E_Signed-off-by=3A?= =?unknown-8bit?q?_Cl=C3=A9ment_L=C3=A9ger_=3Ccleger=40rivosinc=2Ecom=3E_---_?= =?unknown-8bit?q?include/sbi/riscv=5Fencoding=2Eh_=7C?= =?unknown-8bit?q?_3_++-_lib/sbi/sbi=5Ffwft=2Ec_=7C_50_+++++++++++++++++++++_?= =?unknown-8bit?q?2_files_changed=2C_32_insertions=28+=29=2C?= =?unknown-8bit?b?IDIxIGRlbGV0aW8gWy4uLl0g?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=28-1=2E9_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?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDozMmQgbGlzdGVkIGluXQ==?= =?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?_-1=2E9_BAYES=5F00_______________BODY=3A_Bayes_spam_probabi?= =?unknown-8bit?q?lity_is_0_to_1=25?= =?unknown-8bit?q?_=5Bscore=3A_0=2E0000=5D?= 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 MENVCFG access will be used as well for double trap, landing pad and shadow stack fwft support. Factorize that in a common function. Signed-off-by: Clément Léger --- include/sbi/riscv_encoding.h | 3 ++- lib/sbi/sbi_fwft.c | 50 +++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 4728c63..5b3bbc5 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -211,7 +211,8 @@ #define ENVCFG_STCE (_ULL(1) << 63) #define ENVCFG_PBMTE (_ULL(1) << 62) -#define ENVCFG_ADUE (_ULL(1) << 61) +#define ENVCFG_ADUE_SHIFT 61 +#define ENVCFG_ADUE (_ULL(1) << ENVCFG_ADUE_SHIFT) #define ENVCFG_CDE (_ULL(1) << 60) #define ENVCFG_DTE (_ULL(1) << 59) #define ENVCFG_CBZE (_UL(1) << 7) diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index ef881ef..bc9cfd1 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -111,40 +111,50 @@ static int fwft_adue_supported(struct fwft_config *conf) return SBI_OK; } -static int fwft_set_adue(struct fwft_config *conf, unsigned long value) +static int fwft_menvcfg_set_bit(unsigned long value, unsigned long bit) { - if (value == 1) -#if __riscv_xlen == 32 - csr_set(CSR_MENVCFGH, ENVCFG_ADUE >> 32); -#else - csr_set(CSR_MENVCFG, ENVCFG_ADUE); -#endif - else if (value == 0) -#if __riscv_xlen == 32 - csr_clear(CSR_MENVCFGH, ENVCFG_ADUE >> 32); -#else - csr_clear(CSR_MENVCFG, ENVCFG_ADUE); -#endif - else + if (value == 1) { + if (bit >= 32 && __riscv_xlen == 32) + csr_set(CSR_MENVCFGH, _ULL(1) << (bit - 32)); + else + csr_set(CSR_MENVCFG, _ULL(1) << bit); + + } else if (value == 0) { + if (bit >= 32 && __riscv_xlen == 32) + csr_clear(CSR_MENVCFGH, _ULL(1) << (bit - 32)); + else + csr_clear(CSR_MENVCFG, _ULL(1) << bit); + } else { return SBI_EINVAL; + } return SBI_OK; } -static int fwft_get_adue(struct fwft_config *conf, unsigned long *value) +static int fwft_menvcfg_read_bit(unsigned long *value, unsigned long bit) { unsigned long cfg; -#if __riscv_xlen == 32 - cfg = csr_read(CSR_MENVCFGH) & (ENVCFG_ADUE >> 32); -#else - cfg = csr_read(CSR_MENVCFG) & ENVCFG_ADUE; -#endif + if (bit >= 32 && __riscv_xlen == 32) + cfg = csr_read(CSR_MENVCFGH) & (_ULL(1) << (bit - 32)); + else + cfg = csr_read(CSR_MENVCFG) & (_ULL(1) << bit); + *value = cfg != 0; return SBI_OK; } +static int fwft_set_adue(struct fwft_config *conf, unsigned long value) +{ + return fwft_menvcfg_set_bit(value, ENVCFG_ADUE_SHIFT); +} + +static int fwft_get_adue(struct fwft_config *conf, unsigned long *value) +{ + return fwft_menvcfg_read_bit(value, ENVCFG_ADUE_SHIFT); +} + static struct fwft_config* get_feature_config(enum sbi_fwft_feature_t feature) { int i;