summaryrefslogtreecommitdiff
path: root/Kernel/Arch/x86/common
AgeCommit message (Collapse)Author
2021-11-30Kernel: Handle string format error in page_fault_handler(..) :^)Brian Gianforcaro
Utilize the new KString::formatted to provide a fallback if formatting fails because of OOM or whatever reason.
2021-10-21Kernel: Call try_set_coredump_property with StringView argumentsDaniel Bertalan
Storing assigning a string literal to a String object just to pass it to a function expecting a StringView is wasteful. Let's just not do that. For consistency's sake, this commit changes all of the other invocations to use StringView literals, too.
2021-10-16Kernel: Move ScopedCritical + SmapDisabler CPP files into x86 commonJames Mintram
2021-10-15Kernel: Add cross platform RegisterState header and Aarch64 versionJames Mintram
A new RegisterState header includes the platform specific RegisterState header based on the platform being compiled. The Aarch64 RegisterState header contains stubs for Debug
2021-10-15Kernel: Split ScopedCritical so header is platform independentJames Mintram
A new header file has been created in the Arch/ folder while the implementation has been moved into a CPP living in the X86 folder.
2021-10-14Kernel: Add per platform Processor.h headersJames Mintram
The platform independent Processor.h file includes the shared processor code and includes the specific platform header file. All references to the Arch/x86/Processor.h file have been replaced with a reference to Arch/Processor.h.
2021-10-14Kernel: Remove unused includesJames Mintram
2021-10-14Kernel: Add header includes closer to their useJames Mintram
2021-10-07Kernel: Note if the page fault address is a destroyed smart pointerLuke Wilde
While I was working on LibWeb, I got a page fault at 0xe0e0e0e4. This indicates a destroyed RefPtr if compiled with SANITIZE_PTRS defined. However, the page fault handler didn't print out this indication. This makes the page fault handler print out a note if the faulting address looks like a recently destroyed RefPtr, OwnPtr, NonnullRefPtr, NonnullOwnPtr, ThreadSafeRefPtr or ThreadSafeNonnullRefPtr. It will only do this if SANITIZE_PTRS is defined, as smart pointers don't get scrubbed without it being defined.
2021-10-07Kernel: Add Processor::time_spent_idle()Idan Horowitz
2021-10-05Kernel: Validate x86_64 address canonicality before SafeMem operationsIdan Horowitz
This ensures we don't GP on x86_64 when a non-canonical address is fed to a safe_foo() operation.
2021-10-05Kernel: Detect and store the virtual address bit width during CPU initIdan Horowitz
2021-10-02Kernel: Access MemoryManager static functions staticallyBrian Gianforcaro
SonarCloud flagged this "Code Smell", where we are accessing these static methods as if they are instance methods. While it is technically possible, it is very confusing to read when you realize they are static functions.
2021-09-10Kernel: Replace inline assembly for turning on IA32_EFER.NXE with MSRIdan Horowitz
This fixes a triple fault that occurs when compiling serenity with the i686 clang toolchain. (The underlying issue is that the old inline assembly did not specify that it clobbered the eax/ecx/edx registers and as such the compiler assumed they were not changed and used their values across it) Co-authored-by: Brian Gianforcaro <bgianf@serenityos.org>
2021-09-07Kernel: Track when a thread is in the middle of crashingBrian Gianforcaro
There are certain checks that we should skip if the system is crashing. The system can avoid stack overflow during crash, or even triple faulting while while handling issues that can causes recursive panics or aborts.
2021-09-06Kernel: Rename ProcessPagingScope => ScopedAddressSpaceSwitcherAndreas Kling
2021-09-06Kernel: Improve API names for switching address spacesAndreas Kling
- enter_space => enter_address_space - enter_process_paging_scope => enter_process_address_space
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-09-04Kernel: Add x2APIC supportTom
This allows addressing all cores on more modern processors. For now, we still have a hardcoded limit of 64 due to s_processors being a static array.
2021-08-30Kernel: Fix Clang not initializing `s_bsp_processor` correctlyDaniel Bertalan
Initializing the variable this way fixes a kernel panic in Clang where the object was zero-initialized, so the `m_in_scheduler` contained the wrong value. GCC got it right, but we're better off making this change, as leaving uninitialized fields in constant-initialized objects can cause other weird situations like this. Also, initializing only a single field to a non-zero value isn't worth the cost of no longer fitting in `.bss`. Another two variables suffer from the same problem, even though their values are supposed to be zero. Removing these causes the `_GLOBAL_sub_I_` function to no longer be generated and the (not handled) `.init_array` section to be omitted.
2021-08-29Kernel: Rename Spinlock::is_owned_by_current_thread()Andreas Kling
...to is_owned_by_current_processor(). As Tom pointed out, this is much more accurate. :^)
2021-08-29Kernel: {Mutex,Spinlock}::own_lock() => is_locked_by_current_thread()Andreas Kling
Rename these API's to make it more clear what they are checking.
2021-08-23Kernel: Consolidate I386/X86_64 implementations of do_init_context()Andreas Kling
We can use ThreadRegisters::set_flags() to avoid the #ifdef's here.
2021-08-23Kernel: Fix some trivial clang-tidy warnings in x86/common/Processor.cppAndreas Kling
2021-08-23Kernel: Rename Processor::id() => current_id()Andreas Kling
And let id() be the non-static version that gives you the ID of a Processor object.
2021-08-23Kernel: Convert Processor::in_irq() to static current_in_irq()Andreas Kling
This closes the race window between Processor::current() and a context switch happening before in_irq().
2021-08-22Kernel: Rename ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-19Kernel: Make Process::current() return a Process& instead of Process*Idan Horowitz
This has several benefits: 1) We no longer just blindly derefence a null pointer in various places 2) We will get nicer runtime error messages if the current process does turn out to be null in the call location 3) GCC no longer complains about possible nullptr dereferences when compiling without KUBSAN
2021-08-19Kernel: Consolidate a bunch of i386/x86_64 code pathsAndreas Kling
Add some arch-specific getters and setters that allow us to merge blocks that were previously specific to either ARCH(I386) or ARCH(X86_64).
2021-08-10Kernel/SMP: Change critical sections to not disable interruptsAndreas Kling
Leave interrupts enabled so that we can still process IRQs. Critical sections should only prevent preemption by another thread. Co-authored-by: Tom <tomut@yahoo.com>
2021-08-10Kernel/SMP: Make entering/leaving critical sections multi-processor safeAndreas Kling
By making these functions static we close a window where we could get preempted after calling Processor::current() and move to another processor. Co-authored-by: Tom <tomut@yahoo.com>
2021-08-09Kernel/SMP: Don't process SMP messages in non-SMP modeAndreas Kling
Processing SMP messages outside of non-SMP mode is a waste of time, and now that we don't rely on the side effects of calling the message processing function, let's stop calling it entirely. :^)
2021-08-09Kernel/SMP: Process the deferred call queue in exit_trap()Andreas Kling
We were previously relying on a side effect of the critical section in smp_process_pending_messages(): when exiting that section, it would process any pending deferred calls. Instead of relying on that, make the deferred invocations explicit by calling deferred_call_execute_pending() in exit_trap(). This ensures that deferred calls get processed before entering the scheduler at the end of exit_trap(). Since thread unblocking happens via deferred calls, the threads don't have to wait until the next scheduling opportunity when they could be ready *now*. :^) This was the main reason Tom's SMP branch ran slowly in non-SMP mode.
2021-08-09Kernel/SMP: Don't process SMP messages in exit_trap() in non-SMP modeAndreas Kling
2021-08-09Kernel/SMP: Don't enable interrupts in Processor::exit_trapAndreas Kling
Enter a critical section in Processor::exit_trap so that processing SMP messages doesn't enable interrupts upon leaving. We need to delay this until the end where we call into the Scheduler if exiting the trap results in being outside of a critical section and irq handler. Co-authored-by: Tom <tomut@yahoo.com>
2021-08-09Kernel/SMP: Mark s_smp_enabled READONLY_AFTER_INITAndreas Kling
We can't enter/leave SMP mode once the kernel is up and running.
2021-08-09Kernel/SMP: Make SMP message queueing work correctlyAndreas Kling
- Use the receiver's per-CPU entry in the message, instead of the sender's. (Using the sender's entry wasn't safe for broadcast messages since the same entry ended up on multiple message queues.) - Retry the CAS until it *succeeds* instead of *fails*. This closes a race window, and also ensures a correct return value. The return value is used by the caller to decide whether to broadcast an IPI. This was the main reason smp=on was so slow. We had CPUs busy-waiting until someone else triggered an IPI and moved things along. - Add a CPU pause hint to the spin loop. :^)
2021-08-09Kernel/SMP: Fix ProcessorMessage deallocation bugAndreas Kling
Due to a boolean mistake in smp_return_to_pool(), we didn't retry pushing the message onto the freelist after a failed attempt. This caused the message pool to eventually become completely empty after enough contentious access attempts. This patch also adds a pause hint to the CPU in the failed attempt code path.
2021-08-09Kernel: Rename Processor::smp_queue_message() => smp_enqueue_message()Andreas Kling
2021-08-09Kernel: Add Processor::pause() and use it to give the CPU a restAndreas Kling
On x86, the "pause" instruction is a "spin loop hint".
2021-08-06Kernel: Rename Process::space() => Process::address_space()Andreas Kling
We commonly talk about "a process's address space" so let's nudge the code towards matching how we talk about it. :^)
2021-08-06Kernel: Move Kernel/Memory/ code into Kernel::Memory namespaceAndreas Kling
2021-08-06Kernel: Rename Kernel/VM/ to Kernel/Memory/Andreas Kling
This directory isn't just about virtual memory, it's about all kinds of memory management.
2021-08-06Kernel: Store coredump metadata properties as KStringsAndreas Kling
This patch also replaces the HashMap previously used to store coredump properties with a plain AK::Array.
2021-08-01Kernel: Remove ThreadTracer.h include from Process.h / Thread.hBrian Gianforcaro
This isn't needed for Process / Thread as they only reference it by pointer and it's already part of Kernel/Forward.h. So just include it where the implementation needs to call it.
2021-08-01Kernel: Remove unused header includesBrian Gianforcaro
2021-07-27Kernel: Remove a handful of unused member functions in ProcessorAndreas Kling
2021-07-27Kernel: Introduce ProcessorSpecific<T> for per-CPU data structuresAndreas Kling
To add a new per-CPU data structure, add an ID for it to the ProcessorSpecificDataID enum. Then call ProcessorSpecific<T>::initialize() when you are ready to construct the per-CPU data structure on the current CPU. It can then be accessed via ProcessorSpecific<T>::get(). This patch replaces the existing hard-coded mechanisms for Scheduler and MemoryManager per-CPU data structure.
2021-07-26Kernel: Remove invalid '#' format modifier for printing a faulting addrAli Mohammad Pur
This was mistakenly added in 306d898ee56c0d277d865dd4e3afba3d95eab9aa.