The current code ignores mcounteren in U-mode. It should check both mcounteren and scounteren.
Section 3.1.17: "When the CY, TM, IR, or HPMn bit in the mcounteren register is clear, attempts to read the cycle, time, instret, or hpmcountern register while executing in S-mode or U-mode will cause an illegal instruction exception."
The current code ignores mcounteren in U-mode. It should check both mcounteren and scounteren.
Section 3.1.17: "When the CY, TM, IR, or HPMn bit in the mcounteren register is clear, attempts to read the cycle, time, instret, or hpmcountern register while executing in S-mode or U-mode will cause an illegal instruction exception."