Atomic operations deadlock

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Julius
Posts: 2
Joined: Sun Jun 26, 2022 10:23 pm

Atomic operations deadlock

Post by Julius »

Heya,

I'm currently writing an 86_64 bare metal kernel.

After a successful boot into my kernel using EDK2 as a bootloader (calling ExitBootServices) I now want to use spinlocks for synchronization (f.e. a synchronized logger and global allocator).
I'm using rust, which in turn gets compiled down to llvm code, so my spinlock implementation uses llvm atomics under the hood for the x86_64-unknown-none-elf target. Currently interrupts are disabled.

This works perfectly in qemu! But when booting on real hardware (either through grub or plain uefi) the locks appear to be always locked.

Now my question:
Does anything need to be activated/set to enable atomics as stated in this post?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Atomic operations deadlock

Post by Octocontrabass »

Julius wrote:Does anything need to be activated/set to enable atomics as stated in this post?
Probably not. The default memory cache settings are correct in most cases. (Occasionally you might find a PC with broken firmware that doesn't set the MTRRs correctly, but that's pretty unusual.)

It sounds like some kind of memory corruption. Maybe your loader isn't zeroing .bss, or maybe your stack isn't where it should be, or maybe it's some other problem.
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: Atomic operations deadlock

Post by Ethin »

You don't need to enable anything to perform atomic operations. I use them all the time in embedded code and OSDev and have never needed to set a bit or anything like that to get them to work -- they just work. I strongly suspect that this is a different issue altogether.
User avatar
Julius
Posts: 2
Joined: Sun Jun 26, 2022 10:23 pm

Re: Atomic operations deadlock

Post by Julius »

Octocontrabass wrote:It sounds like some kind of memory corruption. Maybe your loader isn't zeroing .bss [...]
Well guess what was commented out in my bootloader..... I thank you so much for your time and keeping up with this.. Sorry and have a good day!
Post Reply