<feed xmlns='http://www.w3.org/2005/Atom'>
<title>opensbi.git/lib/sbi/sbi_emulate_csr.c, branch master</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://cgit.235523.xyz/opensbi.git/atom/lib/sbi/sbi_emulate_csr.c?h=master</id>
<link rel='self' href='http://cgit.235523.xyz/opensbi.git/atom/lib/sbi/sbi_emulate_csr.c?h=master'/>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/'/>
<updated>2024-10-25T18:23:18Z</updated>
<entry>
<title>lib: sbi: factorize previous mode computation</title>
<updated>2024-10-25T18:23:18Z</updated>
<author>
<name>Clément Léger</name>
<email>cleger@rivosinc.com</email>
</author>
<published>2024-10-18T08:40:03Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=80656bdb1daf380b5562cba11f43754fe916d631'/>
<id>urn:sha1:80656bdb1daf380b5562cba11f43754fe916d631</id>
<content type='text'>
Previous privilege mode retrieval from mstatus is done at different
places, factorize it rather than copy/pasting it again.

Signed-off-by: Clément Léger &lt;cleger@rivosinc.com&gt;
Reviewed-by: Samuel Holland &lt;samuel.holland@sifive.com&gt;
</content>
</entry>
<entry>
<title>lib: sbi: factorize previous virtualization mode read from regs</title>
<updated>2024-10-25T18:22:51Z</updated>
<author>
<name>Clément Léger</name>
<email>cleger@rivosinc.com</email>
</author>
<published>2024-10-18T08:40:02Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=daa282573ffac0f295de7631c98840668f20a568'/>
<id>urn:sha1:daa282573ffac0f295de7631c98840668f20a568</id>
<content type='text'>
The same pattern is used at multiple places to verify in which mode
the exception was actually taken. Factorize it.

Signed-off-by: Clément Léger &lt;cleger@rivosinc.com&gt;
Reviewed-by: Samuel Holland &lt;samuel.holland@sifive.com&gt;
</content>
</entry>
<entry>
<title>lib: sbi: Respect scounteren when emulating the time CSR</title>
<updated>2024-09-23T12:42:39Z</updated>
<author>
<name>Samuel Holland</name>
<email>samuel.holland@sifive.com</email>
</author>
<published>2024-08-29T20:22:36Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=beef2f693785499153b00f330d0205f91c3add4e'/>
<id>urn:sha1:beef2f693785499153b00f330d0205f91c3add4e</id>
<content type='text'>
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 &lt;samuel.holland@sifive.com&gt;
Reviewed-by: Anup Patel &lt;anup@brainfault.org&gt;
</content>
</entry>
<entry>
<title>lib: sbi_emulate_csr: Do not log illegal CSR accesses</title>
<updated>2024-07-04T05:12:16Z</updated>
<author>
<name>Samuel Holland</name>
<email>samuel.holland@sifive.com</email>
</author>
<published>2024-07-01T14:54:58Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=d8608e615fae150ddb54e9b54d0e1fb5f16a9d9c'/>
<id>urn:sha1:d8608e615fae150ddb54e9b54d0e1fb5f16a9d9c</id>
<content type='text'>
Illegal CSR accesses from lower privilege modes are delegated to S-mode
and do not necessarily indicate a bug. Supervisor software may want to
emulate some CSRs, or may intentionally disable access to certain
existing CSRs, and thus will expect traps when those CSRs are accessed.

For example, Linux disables sstatus.VS by default in order to detect
when userspace first accesses vector register state; this includes the
CSRs defined by the V extesion. As a result, if the first vector
instruction in a process is a CSR access, OpenSBI will log the illegal
instruction exception, even though there is no unexpected or erroneous
behavior occurring.

Since the illegal instruction exception is delegated to S-mode, S-mode
software should be responsible for reporting the exception, not OpenSBI.

Signed-off-by: Samuel Holland &lt;samuel.holland@sifive.com&gt;
Reviewed-by: Anup Patel &lt;anup@brainfault.org&gt;
</content>
</entry>
<entry>
<title>lib: sbi_pmu: remove mhpm_count field in hart feature</title>
<updated>2023-08-22T07:56:09Z</updated>
<author>
<name>Inochi Amaoto</name>
<email>inochiama@outlook.com</email>
</author>
<published>2023-08-11T00:24:43Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=ee1f83ca848d3639b808e52719bc7111f5a1be7c'/>
<id>urn:sha1:ee1f83ca848d3639b808e52719bc7111f5a1be7c</id>
<content type='text'>
After supporting noncontigous hpm event and counters in opensbi, the
number of hpm counters can be calculated by the mhpm_mask. So this field
is unnecessary and can be removed to save some space.

Signed-off-by: Inochi Amaoto &lt;inochiama@outlook.com&gt;
Reviewed-by: Anup Patel  &lt;anup@brainfault.org&gt;
</content>
</entry>
<entry>
<title>lib: sbi: Remove unnecessary semicolon</title>
<updated>2023-05-11T07:01:34Z</updated>
<author>
<name>Xiang W</name>
<email>wxjstz@126.com</email>
</author>
<published>2023-04-25T08:56:23Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=4e3353057a3b975ca58c9b831749e2760f7812c0'/>
<id>urn:sha1:4e3353057a3b975ca58c9b831749e2760f7812c0</id>
<content type='text'>
We have redundant semicolon at quite a few places so let's remove it.

Signed-off-by: Xiang W &lt;wxjstz@126.com&gt;
Reviewed-by: Anup Patel &lt;anup@brainfault.org&gt;
</content>
</entry>
<entry>
<title>treewide: Replace TRUE/FALSE with true/false</title>
<updated>2023-01-06T11:56:35Z</updated>
<author>
<name>Bin Meng</name>
<email>bmeng@tinylab.org</email>
</author>
<published>2022-12-21T11:38:06Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=440fa818fbffd0771d75890c4fcda062ceab7ebd'/>
<id>urn:sha1:440fa818fbffd0771d75890c4fcda062ceab7ebd</id>
<content type='text'>
C language standard uses true/false for the boolean type.
Let's switch to that for better language compatibility.

Signed-off-by: Bin Meng &lt;bmeng@tinylab.org&gt;
Reviewed-by: Anup Patel &lt;anup@brainfault.org&gt;
Reviewed-by: Samuel Holland &lt;samuel@sholland.org&gt;
Tested-by: Samuel Holland &lt;samuel@sholland.org&gt;
</content>
</entry>
<entry>
<title>lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features</title>
<updated>2022-05-07T04:34:54Z</updated>
<author>
<name>Anup Patel</name>
<email>apatel@ventanamicro.com</email>
</author>
<published>2022-04-28T13:01:57Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=d4b563c881d6bca15bd0c4123c245c875a80ffe6'/>
<id>urn:sha1:d4b563c881d6bca15bd0c4123c245c875a80ffe6</id>
<content type='text'>
If a hart implements privileged spec v1.10 (or higher) then we can
safely assume that [m|s]counteren CSR are present and we don't need
MCOUNTEREN and SCOUNTEREN as hart features.

Signed-off-by: Anup Patel &lt;apatel@ventanamicro.com&gt;
Reviewed-by: Atish Patra &lt;atishp@rivosinc.com&gt;
</content>
</entry>
<entry>
<title>lib: sbi: illegal CSR 0x306 access in hpm_allowed()</title>
<updated>2021-03-22T03:48:56Z</updated>
<author>
<name>Heinrich Schuchardt</name>
<email>xypron.glpk@gmx.de</email>
</author>
<published>2021-03-19T10:04:50Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=ddad02d62550ca8884a2bd21345dad8c6c216777'/>
<id>urn:sha1:ddad02d62550ca8884a2bd21345dad8c6c216777</id>
<content type='text'>
The trap handler sbi_emulate_csr_read() invokes hpm_allowed() which reads
CSR 0x306 (mcounteren). The K210 does not support CSR 0x306. While trying
to handle a trap occurring in S-mode code this creates an additional trap
in M-mode. This results in failure to redirect to S-mode and the system
hanging in sbi_hart_hang().

In hart_detect_features() we have already determined if CSR 0x306 is
available and stored that information in the scratch area. We can use this
information to decide if CSR 0x306 shall be accessed in hpm_allowed() and
thus avoid the M-mode trap.

Likewise if CSR scounteren is not available we have to avoid reading CSR
0x106.

Signed-off-by: Heinrich Schuchardt &lt;xypron.glpk@gmx.de&gt;
Reviewed-by: Anup Patel &lt;anup.patel@wdc.com&gt;
</content>
</entry>
<entry>
<title>lib: sbi: Improve HPM CSR read/write emulation</title>
<updated>2020-09-01T04:58:35Z</updated>
<author>
<name>Anup Patel</name>
<email>anup.patel@wdc.com</email>
</author>
<published>2020-08-21T12:54:14Z</published>
<link rel='alternate' type='text/html' href='http://cgit.235523.xyz/opensbi.git/commit/?id=ebc8ebc0f84618b2cef8b9b77cc705e4c7c2d8d6'/>
<id>urn:sha1:ebc8ebc0f84618b2cef8b9b77cc705e4c7c2d8d6</id>
<content type='text'>
We improve HPM CSR read/write emulation as follows:
1. Fail for unimplemented counters so that trap is redirected
   to S-mode which can further help debugging S-mode software.
2. Check permissions in both MCOUNTEREN and SCOUNTEREN for
   HS-mode and U-mode.
3. Don't check permissions for TIME CSR because we emulate
   TIME CSR for both Host (HS/U-mode) and Guest (VS/VU-mode).
   Also, faster TIME CSR read is very helpful for good
   performance of S-mode software.
4. Don't emulate S-mode CSR read/write to M-mode HPM CSRs
   because these should not be accessible to S-mode software.

Signed-off-by: Anup Patel &lt;anup.patel@wdc.com&gt;
Reviewed-by: Atish Patra &lt;atish.patra@wdc.com&gt;
</content>
</entry>
</feed>
