From patchwork Thu Aug 29 20:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1978613 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=DQkb0Wbr; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=WujbfBfI; 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 4WvsmM6bz1z1yZ9 for ; Fri, 30 Aug 2024 06:08:35 +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:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=MxyCwoxwuzwDY6fUMuWTefQOOIVL8pY2XDwEIEI9dzY=; b=DQkb0WbrFUbD2i wnqcAzz/XpshmySpfYuR16YfwoMznpfPiAGgQZ8qcb6gPQEAhj61NhCkhVtWP4UxaTtwehmdejlx7 HGx5jzUVXT1k/49Z0EHaT+PmykkU4YR4AFubWjFMeCJi9bCYPXESVL4WGB3H9iaZJrjKcKCLKlaBv hoXwGzBlel5QhouIsx0X4HykBjHbme1VkfdGynILpwSNdB0Jf/iwBrYWDmtivgKF3BcLgGttkgV0z UOAGtGyTORjoTqqb5G0HNFF8P0rKAKPExbHi0R9cgt0dumfLo+JxFyfZp41nfJubdZO54iTW4YNbn 7xKTERevr2mWPIOzEFiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlRS-00000003UFb-0wvN; Thu, 29 Aug 2024 20:08:26 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlRO-00000003UEy-3Wza for opensbi@lists.infradead.org; Thu, 29 Aug 2024 20:08:24 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-201f2b7fe0dso9169145ad.1 for ; Thu, 29 Aug 2024 13:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1724962102; x=1725566902; 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=xiJvQn+wc4DQugl+q7nm+gjRi5Muu06lEkhjdu/Sea8=; b=WujbfBfIIx8YfpXW63l3KX120WOEFoz4rf9wFFNMhWkANAG6lf06kiUImC6OY5/bqw CAHZaixuzK0rGXJJvBOi6PycGIkC8p2HZT455THBS5EbkQPEd7CuFoNUghbo926atPaR mTgrFtWksFniSTQsTE32KqJtYNn96Q+kBv8yE5jgHbUh2qXXeGSNnAKcZy+BQJPjgSV3 ++mfofi4EHcWR32QLgqQgJCxXpx9l9+iXpn6Zll3lziB9o1Agu6gRh4COV8CbNxIgZoD NZJiANeK+7rLb5Ysh5D9c6T5z59WO2xUHk0aKHKKjB+677exX0K83YHvVZrVnxm9cnE4 BFdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962102; x=1725566902; 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=xiJvQn+wc4DQugl+q7nm+gjRi5Muu06lEkhjdu/Sea8=; b=AkFi9VC4ltt3f7NFbzO4sfjWiOgyr7jLMbiMoZ0LZ1PLRiCd880D0CsR3resE2+Wu7 RjGGA73RJsrrNPew71P7qLFVpsA7PIEx21z9rGnePqqHlQTpMXdYniY1yXOBW2wQQxMO RgkxdpAyJ31sb3AhCwAOLuJQeQl0kiWyE6Rn0takhUMBukwG4YB7XcymJVkh8uM2hg25 qWWXe9iU7NnJpxXZsaEgUV4vqvy6Gsq1mapYj2/bhQ9veDg+Iswmm0KtQkA8HdPLhyxy rPFrgoEffxx0wXqxLmbtnoSEB91uIqno8TR7R0/id0JFQvwbcfWSBDW9GTswf2tH8wW3 Eu5Q== X-Gm-Message-State: AOJu0YxDbiyQtPEihUunB++n0iFnrbQKdWvGMq4TT6t1LRskCFLDfuyU qZFCSGuQOUYWrkJUhrYzQrkWGfaQOVgMIrJmoHreHqpFU43VC09mgjF45iwlaAsM67hicGsgvZ+ zLqrP8xAgrx0y8u5hzqKqWheKh7RbWtnsthO2HXjPPyWK0MeiJgHJz4fSn/2wEmPGmLrEggz6/i tNlR1gVL8GWQjOyGmeskqdJTQFp6amgaW2uvTr01rK70vd/F7VdU8= X-Google-Smtp-Source: AGHT+IFgb2+uVA4szyGYlEq4GKPPAhYjQPhMRMYA6/AxApdvDaFldJl5wTb9gxspb9fu60+QeJWgHw== X-Received: by 2002:a17:902:fa8d:b0:202:2dfb:9a61 with SMTP id d9443c01a7336-2050c4baa19mr29604185ad.48.1724962101423; Thu, 29 Aug 2024 13:08:21 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20515534618sm15182525ad.175.2024.08.29.13.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:08:20 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH] lib: sbi: Fix writes to emulated 32-bit htimedelta CSR Date: Thu, 29 Aug 2024 13:08:10 -0700 Message-ID: <20240829200819.3657942-1-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_130823_064171_40332F6A X-CRM114-Status: UNSURE ( 8.57 ) X-CRM114-Notice: Please train this message. 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: Writes to the low half CSR should not affect the high half of the value. Make this separation explicit by writing to the delta in memory as two adjacent XLEN-sized values. Fixes: 1e9f88889f8b ("lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSR") Signed-off-by: Samuel Holland --- 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:636 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 Writes to the low half CSR should not affect the high half of the value. Make this separation explicit by writing to the delta in memory as two adjacent XLEN-sized values. Fixes: 1e9f88889f8b ("lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSR") Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- include/sbi/sbi_timer.h | 2 ++ lib/sbi/sbi_timer.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h index ac48e2b8..ac2c7be5 100644 --- a/include/sbi/sbi_timer.h +++ b/include/sbi/sbi_timer.h @@ -78,8 +78,10 @@ u64 sbi_timer_get_delta(void); /** Set timer delta value for current HART */ void sbi_timer_set_delta(ulong delta); +#if __riscv_xlen == 32 /** Set upper 32-bits of timer delta value for current HART */ void sbi_timer_set_delta_upper(ulong delta_upper); +#endif /** Start timer event for current HART */ void sbi_timer_event_start(u64 next_event); diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c index 7b618de1..32955183 100644 --- a/lib/sbi/sbi_timer.c +++ b/lib/sbi/sbi_timer.c @@ -114,20 +114,21 @@ u64 sbi_timer_get_delta(void) void sbi_timer_set_delta(ulong delta) { - u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(), - time_delta_off); + ulong *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(), + time_delta_off); - *time_delta = (u64)delta; + *time_delta = delta; } +#if __riscv_xlen == 32 void sbi_timer_set_delta_upper(ulong delta_upper) { - u64 *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(), - time_delta_off); + ulong *time_delta = sbi_scratch_offset_ptr(sbi_scratch_thishart_ptr(), + time_delta_off); - *time_delta &= 0xffffffffULL; - *time_delta |= ((u64)delta_upper << 32); + *(time_delta + 1) = delta_upper; } +#endif void sbi_timer_event_start(u64 next_event) {