--- cl-original/random/unix.c	2025-02-15 13:01:53.103845066 +0100
+++ cl-patched/random/unix.c	2025-02-15 13:16:57.989053221 +0100
@@ -338,26 +338,48 @@
 #endif /* __clang__ */
 #if ( defined( __GNUC__ ) || defined( __clang__ ) ) && defined( __riscv )
 	{
-	long cycles, timer, instret;
+	/* RISC-V MSR read code, from "The RISC-V Instruction Set Manual,
+	   Volume II: Privileged Architecture", section "Control and Status
+	   Registers", read the cycle count (rdcycle), timer (rdtime), and
+	   instructions-retired count (rdinstret).
 
-	/* RISC-V MSR read code, from "The RISC-V Instruction Set Manual, 
-	   Volume II: Privileged Architecture", section "Control and Status 
-	   Registers", read the cycle count (rdcycle), timer (rdtime), and 
-	   instructions-retired count (rdinstret) */
-	asm volatile( "csrr %[cycles], cycle\n\t"
-		"csrr %[timer], time\n\t"
-		"csrr %[instret], instret\n\n"
-		: [cycles] "=r"(cycles), /* Output */
-			[instret] "=r"(instret),
-			[timer] "=r"(timer)
-		: /* Input */
-		: /* Registers clobbered */
-		);
-	addRandomData( randomState, &cycles, sizeof( long ) );
-	addRandomData( randomState, &timer, sizeof( long ) );
-	addRandomData( randomState, &instret, sizeof( long ) );
+	   Starting with Linux 6.6 it hasn't been possible to read cycle count
+	   and instructions-retired values from userspace because of "security
+	   concerns", see
+	   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3,
+	   https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/REWcwYnzsKE
+	   so we can only use the value from the timer register */
+
+	   #ifdef __linux__
+		long timer;
+
+		asm volatile( "csrr %[timer], time\n\n"
+			: [timer] "=r"(timer) /* Output */
+			: /* Input */
+			: /* Registers clobbered */
+			);
+
+		addRandomData( randomState, &timer, sizeof( long ) );
+	   #else
+		long cycles, timer, instret;
+
+		asm volatile( "csrr %[cycles], cycle\n\t"
+			"csrr %[timer], time\n\t"
+			"csrr %[instret], instret\n\n"
+			: [cycles] "=r"(cycles), /* Output */
+				[instret] "=r"(instret),
+				[timer] "=r"(timer)
+			: /* Input */
+			: /* Registers clobbered */
+			);
+
+       		addRandomData( randomState, &cycles, sizeof( long ) );
+		addRandomData( randomState, &timer, sizeof( long ) );
+		addRandomData( randomState, &instret, sizeof( long ) );
+           #endif /* Linux vs. everything else */
 	}
 #endif /* RISC-V */
+
 #if ( defined( __QNX__ ) && OSVERSION >= 5 )
 	/* Return the output of RDTSC or its equivalent on other systems.  We
 	   don't worry about locking the thread to a CPU since we're not using
