From 8269e097d658bd3d2bd595db24854238e03d11b1 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sat, 20 Sep 2025 00:55:18 +0200 Subject: [PATCH] spinlock only restore RFLAGS IF flag --- kernel/spinlock/spinlock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/spinlock/spinlock.c b/kernel/spinlock/spinlock.c index 97307db..23521a8 100644 --- a/kernel/spinlock/spinlock.c +++ b/kernel/spinlock/spinlock.c @@ -12,12 +12,14 @@ void spinlock_init(SpinLock *sl) { uint64_t spinlock_irqsave(void) { uint64_t flags; - asm volatile("pushfq; cli; popq %0" : "=r"(flags)); + asm volatile("pushfq; cli; popq %0" : "=r"(flags) :: "memory"); return flags; } void spinlock_irqrestore(uint64_t flags) { - asm volatile("pushq %0; popfq" :: "r"(flags)); + if (flags & (1<<9)) { + asm volatile("sti" ::: "memory"); + } } void spinlock_acquire(SpinLock *sl) {