Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Licensed under the GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <kern_util.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <longjmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <sysdep/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <generated/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /* Set during early boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static int host_has_cmov = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static jmp_buf cmov_test_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static void cmov_sigill_test_handler(int sig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	host_has_cmov = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	longjmp(cmov_test_return, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void arch_check_bugs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	struct sigaction old, new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	printk(UM_KERN_INFO "Checking for host processor cmov support...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	new.sa_handler = cmov_sigill_test_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	/* Make sure that SIGILL is enabled after the handler longjmps back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	new.sa_flags = SA_NODEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	sigemptyset(&new.sa_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	sigaction(SIGILL, &new, &old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	if (setjmp(cmov_test_return) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		unsigned long foo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		__asm__ __volatile__("cmovz %0, %1" : "=r" (foo) : "0" (foo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		printk(UM_KERN_CONT "Yes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		printk(UM_KERN_CONT "No\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	sigaction(SIGILL, &old, &new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void arch_examine_signal(int sig, struct uml_pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	unsigned char tmp[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	 * This is testing for a cmov (0x0f 0x4x) instruction causing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	 * SIGILL in init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	if ((sig != SIGILL) || (get_current_pid() != 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	if (copy_from_user_proc(tmp, (void *) UPT_IP(regs), 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		printk(UM_KERN_ERR "SIGILL in init, could not read "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		       "instructions!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	if ((tmp[0] != 0x0f) || ((tmp[1] & 0xf0) != 0x40))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	if (host_has_cmov == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		       "processor doesn't implement.  Boot a filesystem "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		       "compiled for older processors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	else if (host_has_cmov == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		printk(UM_KERN_ERR "SIGILL caused by cmov, which this "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		       "processor claims to implement");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		printk(UM_KERN_ERR "Bad value for host_has_cmov (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 			host_has_cmov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }