diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/amd64/machdep.c | 44 | ||||
-rw-r--r-- | sys/arch/amd64/conf/GENERIC | 1 | ||||
-rw-r--r-- | sys/arch/amd64/isa/i8042.c | 18 | ||||
-rw-r--r-- | sys/crypto/chacha20.c (renamed from sys/dev/random/chacha20.c) | 2 | ||||
-rw-r--r-- | sys/crypto/siphash.c (renamed from sys/dev/random/siphash.c) | 2 | ||||
-rw-r--r-- | sys/dev/random/entropy.c | 2 | ||||
-rw-r--r-- | sys/dev/random/random.c | 4 | ||||
-rw-r--r-- | sys/include/arch/amd64/cpu.h | 2 | ||||
-rw-r--r-- | sys/include/crypto/chacha20.h (renamed from sys/include/dev/random/chacha20.h) | 0 | ||||
-rw-r--r-- | sys/include/crypto/siphash.h (renamed from sys/include/dev/random/siphash.h) | 0 | ||||
-rw-r--r-- | sys/kern/kern_exit.c | 3 | ||||
-rw-r--r-- | sys/kern/kern_panic.c | 17 | ||||
-rw-r--r-- | sys/kern/kern_sched.c | 3 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 3 |
14 files changed, 84 insertions, 17 deletions
diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index 9b65d6e..40950f9 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -44,6 +44,8 @@ #include <machine/intr.h> #include <machine/cdefs.h> #include <machine/isa/i8042var.h> +#include <dev/cons/cons.h> +#include <string.h> #define pr_trace(fmt, ...) kprintf("cpu: " fmt, ##__VA_ARGS__) #define pr_error(...) pr_trace(__VA_ARGS__) @@ -185,9 +187,10 @@ enable_simd(void) } static void -cpu_check_feat(struct cpu_info *ci) +cpu_get_info(struct cpu_info *ci) { - uint32_t unused, ebx; + uint32_t eax, ebx, unused; + uint8_t ext_model, ext_family; /* Extended features */ CPUID(0x07, unused, ebx, unused, unused); @@ -195,6 +198,33 @@ cpu_check_feat(struct cpu_info *ci) ci->feat |= CPU_FEAT_SMEP; if (ISSET(ebx, BIT(20))) ci->feat |= CPU_FEAT_SMAP; + + /* + * Processor info and feature bits + */ + CPUID(0x01, eax, unused, unused, unused); + ci->model = (eax >> 4) & 0xF; + ci->family = (eax >> 8) & 0xF; + + /* + * If the family ID is 15 then the actual family + * ID is the sum of the extended family and the + * family ID fields. + */ + if (ci->family == 0xF) { + ext_family = (eax >> 20) & 0xFF; + ci->family += ext_family; + } + + /* + * If the family has the value of either 6 or 15, + * then the extended model number would be used. + * Slap them together if this is the case. + */ + if (ci->family == 6 || ci->family == 15) { + ext_model = (eax >> 16) & 0xF; + ci->model |= (ext_model << 4); + } } void @@ -224,6 +254,7 @@ md_backtrace(void) uintptr_t rip; off_t off; const char *name; + char line[256]; __ASMV("mov %%rbp, %0" : "=r" (rbp) :: "memory"); while (1) { @@ -236,7 +267,8 @@ md_backtrace(void) if (name == NULL) name = "???"; - kprintf(OMIT_TIMESTAMP "%p @ <%s+0x%x>\n", rip, name, off); + snprintf(line, sizeof(line), "%p @ <%s+0x%x>\n", rip, name, off); + cons_putstr(&g_root_scr, line, strlen(line)); } } @@ -294,6 +326,10 @@ this_cpu(void) { struct cpu_info *ci; + if (rdmsr(IA32_GS_BASE) == 0) { + return NULL; + } + /* * This might look crazy but we are just leveraging the "m" * constraint to add the offset of the self field within @@ -375,7 +411,7 @@ cpu_startup(struct cpu_info *ci) init_tss(ci); try_mitigate_spectre(); - cpu_check_feat(ci); + cpu_get_info(ci); cpu_enable_smep(); enable_simd(); diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index 95fe2e0..e407fa9 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -10,6 +10,7 @@ option SERIAL_DEBUG yes // Enable kmsg serial logging option USER_KMSG no // Show kmsg in user consoles option CPU_SMEP yes // Supervisor Memory Exec Protection option PANIC_SCR no // Clear screen on panic +option I8042_POLL yes // Use polling for the i8042 // Kernel constants setval SCHED_NQUEUE 4 // Number of scheduler queues (for MLFQ) diff --git a/sys/arch/amd64/isa/i8042.c b/sys/arch/amd64/isa/i8042.c index cde70ff..3ae645d 100644 --- a/sys/arch/amd64/isa/i8042.c +++ b/sys/arch/amd64/isa/i8042.c @@ -53,6 +53,13 @@ #include <string.h> #include <assert.h> +/* From kconf(9) */ +#if !defined(__I8042_POLL) +#define I8042_POLL 0 +#else +#define I8042_POLL __I8042_POLL +#endif + #define KEY_REP_MAX 2 #define pr_trace(fmt, ...) kprintf("i8042: " fmt, ##__VA_ARGS__) @@ -424,13 +431,20 @@ i8042_init(void) quirks |= I8042_HOSTILE; pr_trace("ThinkPad T420s detected, assuming hostile\n"); pr_trace("disabling irq 1, polling as fallback\n"); - spawn(&polltd, i8042_sync_loop, NULL, 0, NULL); } - if (!ISSET(quirks, I8042_HOSTILE)) { + /* + * If the i8042 has the hostile quirk or we are + * configured to poll for events, spawn the polling + * thread. + */ + if (!ISSET(quirks, I8042_HOSTILE) && !I8042_POLL) { /* Enable interrupts */ i8042_drain(); i8042_en_intr(); + } else if (ISSET(quirks, I8042_HOSTILE) || I8042_POLL) { + spawn(&polltd, i8042_sync_loop, NULL, 0, NULL); + pr_trace("polling events\n"); } i8042_write(I8042_CMD, I8042_ENABLE_PORT0); diff --git a/sys/dev/random/chacha20.c b/sys/crypto/chacha20.c index 41f823c..5c979a2 100644 --- a/sys/dev/random/chacha20.c +++ b/sys/crypto/chacha20.c @@ -27,7 +27,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <dev/random/chacha20.h> +#include <crypto/chacha20.h> static const char sigma[16] = "expand 32-byte k"; diff --git a/sys/dev/random/siphash.c b/sys/crypto/siphash.c index 2b2243f..e0cad44 100644 --- a/sys/dev/random/siphash.c +++ b/sys/crypto/siphash.c @@ -29,7 +29,7 @@ Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c) */ -#include <dev/random/siphash.h> +#include <crypto/siphash.h> #include <stdint.h> #if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ diff --git a/sys/dev/random/entropy.c b/sys/dev/random/entropy.c index d392b9c..4e723a4 100644 --- a/sys/dev/random/entropy.c +++ b/sys/dev/random/entropy.c @@ -30,7 +30,7 @@ #include <stdint.h> #include <string.h> #include <dev/random/entropy.h> -#include <dev/random/siphash.h> +#include <crypto/siphash.h> void mix_entropy(struct entropy_pool *ep, const uint8_t *input, diff --git a/sys/dev/random/random.c b/sys/dev/random/random.c index d79df69..9bca719 100644 --- a/sys/dev/random/random.c +++ b/sys/dev/random/random.c @@ -30,9 +30,9 @@ #include <sys/sio.h> #include <sys/device.h> #include <sys/driver.h> -#include <dev/random/chacha20.h> -#include <dev/random/siphash.h> #include <dev/random/entropy.h> +#include <crypto/chacha20.h> +#include <crypto/siphash.h> #include <fs/devfs.h> #include <string.h> diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h index 46e5df7..a5f09fb 100644 --- a/sys/include/arch/amd64/cpu.h +++ b/sys/include/arch/amd64/cpu.h @@ -45,6 +45,8 @@ struct cpu_info { uint32_t apicid; uint32_t feat; + uint8_t model : 4; /* CPU model number */ + uint8_t family : 4; /* CPU family ID */ uint8_t has_x2apic : 1; uint8_t tlb_shootdown : 1; uint8_t ipl; diff --git a/sys/include/dev/random/chacha20.h b/sys/include/crypto/chacha20.h index d35702a..d35702a 100644 --- a/sys/include/dev/random/chacha20.h +++ b/sys/include/crypto/chacha20.h diff --git a/sys/include/dev/random/siphash.h b/sys/include/crypto/siphash.h index ecabb4a..ecabb4a 100644 --- a/sys/include/dev/random/siphash.h +++ b/sys/include/crypto/siphash.h diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index b1bd9ba..2c9e2e4 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -33,6 +33,7 @@ #include <sys/panic.h> #include <sys/filedesc.h> #include <sys/vnode.h> +#include <dev/cons/cons.h> #include <vm/physmem.h> #include <vm/dynalloc.h> #include <vm/vm.h> @@ -89,6 +90,8 @@ proc_reap(struct proc *td) vaddr_t stack_va; paddr_t stack_pa; + cons_detach(); + /* Clear out all fds */ for (size_t i = 4; i < PROC_MAX_FILEDES; ++i) { fdp = td->fds[i]; diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c index 2df4537..13b4964 100644 --- a/sys/kern/kern_panic.c +++ b/sys/kern/kern_panic.c @@ -34,6 +34,7 @@ #include <dev/cons/cons.h> #include <machine/cdefs.h> #include <machine/cpu.h> +#include <string.h> #if defined(__PANIC_SCR) #define PANIC_SCR __PANIC_SCR @@ -41,6 +42,15 @@ #define PANIC_SCR 0 #endif +static void +panic_puts(const char *str) +{ + size_t len; + + len = strlen(str); + cons_putstr(&g_root_scr, str, len); +} + /* * Burn and sizzle - the core logic that really ends * things ::) @@ -56,11 +66,11 @@ bas(bool do_trace, int reboot_type) spinlock_acquire(&lock); /* Never released */ if (do_trace) { - kprintf(OMIT_TIMESTAMP "** backtrace\n"); + panic_puts(" ** backtrace\n"); md_backtrace(); } - kprintf(OMIT_TIMESTAMP "\n-- ALL CORES HAVE BEEN HALTED --\n"); + panic_puts("\n-- ALL CORES HAVE BEEN HALTED --\n"); cpu_reboot(reboot_type); __builtin_unreachable(); } @@ -82,7 +92,8 @@ static void do_panic(const char *fmt, va_list *ap) { syslog_silence(false); - kprintf(OMIT_TIMESTAMP "panic: "); + spinlock_release(&g_root_scr.lock); + panic_puts("panic: "); vkprintf(fmt, ap); bas(true, REBOOT_HALT); diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 774ba71..24806db 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -159,6 +159,9 @@ this_td(void) struct cpu_info *ci; ci = this_cpu(); + if (ci == NULL) { + return NULL; + } return ci->curtd; } diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 102648c..e741157 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -68,9 +68,6 @@ sys_sleep(struct syscall_args *scargs) timeout_msec = ts.tv_nsec / 1000000; timeout_msec += ts.tv_sec * 1000; - - md_inton(); tmr.msleep(timeout_msec); - md_intoff(); return 0; } |