From patchwork Thu Aug 29 20:22:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1978620 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=q9V3X/79; 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=DG+8JGD+; 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 4Wvt4x2tC6z1yZ9 for ; Fri, 30 Aug 2024 06:22:57 +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=i1HYFLMs9QAXnVzUCNHSwJHbNo8CddM4QTB/TmNQNvg=; b=q9V3X/79PBz4tC y6PkUN99b+I5mhZBHPhUUcrUB+PqGnxOg2V5yhBOwjT+5V6Ts69PjYxX8VWTCsiegaYGtpKAsttSA jzXYRyWPQSKS0+Qlp0eWu9+V8Am2aT9BjtZiG0uyjJ6u16vveW/u5TOWg1eWX6CcUA4UFBNDGvIXW pGBaAiOU6C8dCuVrnUHKbUVNXpcV3klytn7F99iJyl9rmv+UtZ/QMMG8Nd6lNFsbpbVnMkC72cYFx b2PvIp2BKMo+v+BMk79eOV2DUIiDLCrVeMV861gV51j7I3kH8dAoBniUNVgKFv6ISi+meANVDvwq4 cTdQQIqQhp1obEiAp2OQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlfM-00000003Wmn-3YHE; Thu, 29 Aug 2024 20:22:48 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlfJ-00000003Wly-0UMR for opensbi@lists.infradead.org; Thu, 29 Aug 2024 20:22:46 +0000 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-39f392161e4so4376855ab.3 for ; Thu, 29 Aug 2024 13:22:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1724962964; x=1725567764; 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=GxXktoId3O0juclr+Mkr7p6dUKUcjtWqDTxQsta6/vY=; b=DG+8JGD+QG9mIyTLZgpJeoW0hGZVtKKTBTsOyoc4mw+Yglf1GSYU+Wzn0PB7YyPukV ZBbIIvL0UMFeiaLJJu/EhoBGXl4tZrM1jmA/xyYcbM4o7ileRH1/fy1MLY0FiXTKSpzv dm7ktk7ByNWwK9dDDhby/U1FYyURRJM6FfbDu+ptjZo3k6U8Flt/nc9D+/EXxbJl9NJ9 CyktNDkW2bR03YxMnUUXX5TShaxJlQ4zdaXBN7YepLaJh5nE1/SQ4IYSpZXj9ltB15k0 re/g8QRovDw+yLzv7wZPDwoWyoNYw8aPqtbGaftbsIl8mGuza6kGJeQS5wEssBo6xvDi mKJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962964; x=1725567764; 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=GxXktoId3O0juclr+Mkr7p6dUKUcjtWqDTxQsta6/vY=; b=VBIvKzsCMPShxZTLDz9akDVfE7y9L9IenMRsqsjyxjwPMBQVR4D7io9sX1+VSPsXm6 Dzx7W/cmW44qU7UQRshNNQHbCvnCSl41NYZ3KsCK4uf6wEUcQYwMtSVsKKq17NQAOi23 lzO64tpNYHrGI2E2WWPyU/YLTc35JtTR0OEm3S2o6sqKPJ3E+44M8L6pY2heNP2fZ6K9 8DHKplbGlgYS/zYGOETfqggCmVqhI9C3qNeqNci/fD/r7b58kcGXlZn9rxVE6hhhrj7c RfZ1et0KJ565OCo2ZSiyWCSEcEU66uswMK555SOd96ekMdyj0pnnGks0jtvr9US5f96X 7UTw== X-Gm-Message-State: AOJu0Yy9QLZq0nLFG9QITAY3CLMhu3e71deaiXMNbBqBSc5921hrOiJA oJ06RFhP48DE2EDP78SSBPfQiuv5xhWgRo5LXtC6vXzlLX7OjzX5+JRy2p9yve4BDhXKnSD4Uze NCtt6QdG3d+LzLG0wiycLc8ZbqUMKYNAXrWD14LM9/yBUikzXf+8kRGz0tFQgJJ3MWUaL998WjQ uW/g3ndmV4KqFYVtaU4vvlEwuYk13pNAwDaXd5XGwv7PGtMbNPUFU= X-Google-Smtp-Source: AGHT+IFxbJG+0rIFru+ssf5dUryH5bhwAPLAV7z8dEBrkkuvKq5aNcjsxvQZ1EzyBP9Cni5VTudRJA== X-Received: by 2002:a92:c264:0:b0:36c:4688:85aa with SMTP id e9e14a558f8ab-39f377ed0e4mr51892375ab.10.1724962963785; Thu, 29 Aug 2024 13:22:43 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d22e9d4ee3sm1425434a12.83.2024.08.29.13.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:22:43 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH] lib: sbi: Respect scounteren when emulating the time CSR Date: Thu, 29 Aug 2024 13:22:36 -0700 Message-ID: <20240829202242.3659520-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_132245_197464_D291FBDE X-CRM114-Status: GOOD ( 10.02 ) 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: This optimization creates a correctness issue, as it prevents supervisor software from restricting VS-mode or U-mode access to the time CSR for its own purposes. Closes: https://github.com/riscv-software-src/opensbi/issues/370 Fixes: ebc8ebc0f846 ("lib: sbi: Improve HPM CSR read/write emulation") 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:134 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 This optimization creates a correctness issue, as it prevents supervisor software from restricting VS-mode or U-mode access to the time CSR for its own purposes. Closes: https://github.com/riscv-software-src/opensbi/issues/370 Fixes: ebc8ebc0f846 ("lib: sbi: Improve HPM CSR read/write emulation") Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- lib/sbi/sbi_emulate_csr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c index 869c81f4..3adec78d 100644 --- a/lib/sbi/sbi_emulate_csr.c +++ b/lib/sbi/sbi_emulate_csr.c @@ -66,12 +66,11 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs, *csr_val = csr_read(CSR_MCYCLE); break; case CSR_TIME: + if (!hpm_allowed(csr_num - CSR_CYCLE, prev_mode, virt)) + return SBI_ENOTSUPP; /* * We emulate TIME CSR for both Host (HS/U-mode) and * Guest (VS/VU-mode). - * - * Faster TIME CSR reads are critical for good performance - * in S-mode software so we don't check CSR permissions. */ *csr_val = (virt) ? sbi_timer_virt_value(): sbi_timer_value();