#Elysium (Cronus)

1 messages Β· Page 2 of 1

honest echo
#

I mean it looks correct but also that is probably the longest line in my kernel

vocal jackal
#

can u add logging to vm_map_direct to see what it actually ends up mapping

honest echo
#

yeah fs

vocal jackal
#

is it a concious decision to not use the direct map btw?

honest echo
#

it is

#

I am trying to eliminate it wherever I can

vocal jackal
#

why is that?

honest echo
#

because I'd like to have the option to disable it

vocal jackal
#

hm

honest echo
#

its not necessarily rational

#

just something that I decided on

#

either way it should not impede this

#

lgtm

#

I'm gonna dump the mapped region

#

and see whats there

vocal jackal
#

what did u print there

#

that physical address looks misaligned

honest echo
#

how so

vocal jackal
#

the one in < >

honest echo
#

thats just the region uacpi requested

vocal jackal
#

i kinda wanted to see what it is u actually end up mapping

honest echo
#

well I can trace the ptm too

#

hold on

#

well

#

even better

#

hm

#

from info tlb

vocal jackal
#

you're using your own bootloader right

honest echo
#

yes

vocal jackal
#

how do u fetch the rsdp

honest echo
#

I did consider the RSDP might be wrong

#

it looked slightly different but now it looks very similar to limine trl

#

just rewrote it

#

incase

#

I mean the previous version worked fine when I was parsing it myself

vocal jackal
#

can u just dump that address from gdb

honest echo
#

yeah

#

that was my plan

vocal jackal
#

i mean its very easy to check also if u just replace your mapping function with HHDM, if that doesnt work also that must be either wrong address or you overwrote it

honest echo
#

thats fair

#

ill try that rn

#

apparently I cannot set a breakpoint when booting from uefi

#

like at least not before efi has handed off or whatever

vocal jackal
#

u should be able to if u disable KVM

honest echo
#

idk

#

ahhh

#

im dumb

#

thanks

#

ill try the HHDM rq anyhow

vocal jackal
#

its possible that ur forgetting to flush the tlb properly as well

#

because your mapping is global

honest echo
#

I am not

#

I am super liberal with my tlb shootdowns atm

#

they are insanely bad for perf

#

lmao

#

but at least I am not missing anything atm

vocal jackal
#

oh well

honest echo
#

I mean its always possible

#

but unlikely

#

same thing with HHDM

vocal jackal
#

what does GDB say

honest echo
#

yeah doing that

vocal jackal
#

maybe cast it to acpi_rsdp* so its easy to read

#

p *(struct acpi_rsdp*)addr or whatever

honest echo
#

yeah its all zeroes

#

I wonder if I am overwriting the actual memory at some point

vocal jackal
#

it's stored in uefi boot memory so if you're reusing that then that would explain it

#

u would expect runtimeservices but no

honest echo
#

I should not be touching that

vocal jackal
#

maybe print the pointer and contents u get at the time of retrieval

honest echo
#

time to investigate

vocal jackal
#

in your bootloader

honest echo
#

yeah

#

the pointer is printed and is correct

#

but the contents I havent

#

I am going to check a couple things

vocal jackal
#

yaeh

honest echo
#

yeah the phys memory is zeroed so the mapping is correct but the memory is fucked

vocal jackal
honest echo
#

should be in EfiACPIReclaimMemory probably?

vocal jackal
#

like i said no

#

Its in EfiBootServicesData

honest echo
#

oh

#

either way

#

not touching that

#

yet

#

good to know

honest echo
#

erroneously though

vocal jackal
#

put a watchpoint on it in gdb

#

and see who zeroes it

honest echo
#

πŸ˜„

#

will do

vocal jackal
#

oh and also hexdump it in the bootloader

#

could be zeroed there who knows

honest echo
#

πŸ˜„

vocal jackal
#

yea...

honest echo
#

idk how I would really set a watchpoint on it

#

since at the beginning its a physaddr

#

then its technically present in the hhdm

vocal jackal
#

set at both?

honest echo
#

I suppose

#

actually let me see if the mem is fine at the very beginning of the kernel

#

that would help narrow the scope

vocal jackal
#

yeah

honest echo
#

yeah its fine at the beginning

#

well there we go

#

I have found the perpetrator

vocal jackal
#

lol

#

u said u never allocate it no?

honest echo
#

well

#

not intentionally

#

it should not be passed into the pmm

vocal jackal
#

god bless watchpoints

honest echo
#

at all

#

real

#

ok fixed it

#

that was actually a very good find

#

at init I was merging buddies that were not free into ones that were free

#

because at init I find the "max order" of every block

#

and apparently I was just setting order to that

#

god

#

how has this not caused other issues lmao

vocal jackal
#

lol

honest echo
#

thanks for the help ❀️

#

I would have not thought of a watchpoint and would have probably spent hours more on this

vocal jackal
#

npnp

honest echo
#

beep boop

frosty oasis
#

πŸ‘ΎπŸ€–

honest echo
#

I am once again sitting on like 1000-2000 lines of delta without a commit

#

why do I do this to myself

honest echo
#

dont execute me for this

vocal jackal
#

wait what

#

how did u do this

honest echo
#

log packets over serial

#

lmao

#

I am going to make it so I can filter by "tag" and log level

#

which is going to be genuinely useful

vocal jackal
#

how did u make it into a server?

honest echo
#

dead simple go app that just reads the logs from tcp and then servers them as server-sent events

vocal jackal
#

ohh

vocal jackal
honest echo
#

lmao

#

yeah...

vocal jackal
#

reminds me of early nyaux

honest echo
#

I think I know why its happening

#

just havent gotten around to fixing that stuff yet

vocal jackal
#

usually its because of some sort of an allocator bug always doing a slow path

honest echo
#

no its uhh

#

my cpu local accesses for the most part disable interrupts

#

I am very much going to change that

#

just that atm its the only way to do it safely

vocal jackal
#

cli/sti should run pretty fast i think

honest echo
#

well

#

fuck

#

who knows

vocal jackal
#

well if you're curious u could profile it

honest echo
#

yeah I have

vocal jackal
#

its not that hard so thats good

honest echo
#

anyway

#

I have other more important stuff to do first

#

ill get around to that later

vocal jackal
#

fair

honest echo
#

lol

simple sinew
#

lmao, thats fun

vocal jackal
#

i dont gdt but i have CFI backtraces

#

my priorities are straight

honest echo
#

lol

honest echo
#

ok that took an embarassingly long time

#

but I am doing this in plain html/js so its a pain to fucking do anything

#

lol

vocal jackal
#

would probably be easier to dump in a file and have dmesg read it KEKW

#

as in just convert to kmsg format

honest echo
#

idk why I am doing this atp

#

grep totally doesnt exist

honest echo
#

ok

#

but now im cooking

#

like

vocal jackal
#

how do u do symbols and stack traces?

lime vortex
vocal jackal
#

yeah i saw the release log

lime vortex
#

now the symbols resolve fine on non-x86 too, instead of having a bunch of junk symbols

vocal jackal
#

thats cool

honest echo
#

then I just walk stack frames

sharp surge
#

why load them as a module instead of putting them into a loadable segment

vocal jackal
honest echo
#

I just generate a format I can parse at runtime in-kernel

#

well actually

#

not parse

#

just use

vocal jackal
#

Yeah its definitely easier to ship separately

#

3 relinks to make it work with lto

honest echo
#

yeah I mean it'd be neat

#

but like

#

bootloader module works just fine

#

and my kernel can run without the symbols too

#

tho u wont be able to load kernel modules lol

sharp surge
#

like with the regular symtab I somewhat understand because you have to do some unconventional linker script stuff to get it loaded, and especially with a custom format symtab, but dynsym is already in memory without any extra tricks

honest echo
#

yeah I just use the normal symtab

#

atm

#

well

#

not really

#

I dump symbols with nm

#

I dont really use kernel modules

#

and I need to rework them

#

anyway

vocal jackal
sharp surge
#

dynsym is exported symbols

#

and it's what's used by e.g. ld.so

#

symtab is just debug info

vocal jackal
sharp surge
#

global symbols with default or protected visibility

vocal jackal
#

Ah

sharp surge
#

the symbols that dependent objects can use

#

you can get it in an executable with -rdynamic or some similar flag

vocal jackal
sharp surge
#

Yep

#

And then modules would be normal shared objects instead of relocatable objects like linux modules

vocal jackal
#

Can't u have that property for objects also?

sharp surge
#

Meaning you only have to deal with a few very simple relocation types

#

And none of the relocations will be in read only segments (unless explicitly requested during linking)

sharp surge
vocal jackal
#

can u have dynsym in objects?

sharp surge
#

Not really

vocal jackal
#

sucks

sharp surge
#

Dynsym is linker output and it only exists for shared objects and executables linked with rdynamic

#

Objects only have symtab

vocal jackal
#

i see

#

thats probably why they have so many crappy scripts for module symbol export

sharp surge
#

Yeah idk why they still do it like that when the object format they use now is perfectly capable of actual shared libraries

#

Like I get the historical reasons but that hasn't been a factor for a very long time

vocal jackal
#

the only reason i dont like them is because you're forced to use the got stuff

#

and u cant just have symbols referenced directly

simple sinew
vocal jackal
#

which is have each module specify its namespace

#

and have other modules import namespaces

#

so only the respective namespace is looked at for global symbols

vocal jackal
#

__attribute__((visibility("default")) or whatever

honest echo
#

ah fair

#

yeah I need to rework kernel modules

#

I dont really use em for shit

#

anyway

simple sinew
honest echo
#

just realized I qemu can output serial over websockets

#

lol

#

well time to do that

#

this is braindamage but also I need a break from debugging

#

genuinely why the fuck can it even do that

#

like its cool and I am about to abuse it

#

but

vocal jackal
#

Qemu can do literally anything

honest echo
#

real

honest echo
#

I made it so there is no need for a middleman

#

the website just attempts to connect to the websocket port constantly and so when qemu starts it connects and woop woop

honest echo
#

lmao

#

(all just a website, there is no backend but qemu directly)

#

kinda funny

vocal jackal
#

lmfao

#

how did u add a vnc viewer

honest echo
#

qemu can do vnc over websocket

#

lmaooo

vocal jackal
#

damn

mystic basalt
honest echo
#

aight after working on some side projecst I seem to have fixed all the bugs in elysium

honest echo
dusty hawk
#

charon rewrite when πŸ˜‰ πŸ’€

honest echo
#

been doing that

#

lol

#

but I need to break to do thesis and other shit

honest echo
#

sike I aint doing that (charon, unfortunately thesis work is unavoidable)

#

lol

#

going to continue osdev

simple sinew
#

lol

honest echo
honest echo
#

did one for tartarus too

honest echo
#

so I did something cursed

#

if anyone has a better way of doing this plez lmk

vocal jackal
#

well what does linux do

honest echo
#

no clue

#

jesus christ

#

linux's is like

#

somehow more macro aids

#

they also do a runtime check for the sizes

#

although that might be optimized out

honest echo
#

turns out

#

I got trolled

#

apparently the assembler can just determine the size of the operation based on the register size of one of the operands just like for mov

#

so I can just do this

honest echo
#

magic command that turns my laptop into a hot brick for an hour

honest echo
#

I love it when I do a couple random innocent changes and now I pagefault in earlyboot

#

on an instruction fetch

#

good times

#

is tartarus still fucking borked somehow

honest echo
#

so kinda cool

#

found out clangd has doxygen support in pre-release versions

honest echo
#

well

#

I have been working on an init system

#

and so naturally I do the thing I do

#

and put way too much effort into the dumbest things lmao

#

but anyway

#

it now auto generates an interactive init graph

#

and highlights impossible dependencies

#

(blue/red here is kind of missleading, they are all okay, only the edges that are dashed are impossible)

#

I think I might have super overcomplicated things ngl

simple sinew
#

That's cool, nice

#

Was this inspired by managarm's initgraph?

honest echo
#

I did not know they had one πŸ˜„

#

I had seen a couple init system type things

#

and implemented a similar thing

#

and it became so hard to track what was going on

#

so I spent a day making an overcomplicated python script to make this

#

and it sorta helps

#

one thing I need to do is have a couple big targets that I can depend on instead of depending on every minute thing

honest echo
#

so gave up on taht

#

it became such a fucking mess it was unmaintainable

#

I reverted back to having init stages and still allowing targets to depend on other targets within a stage

#

its a bit scuffed but works well enough for now

#

one thing I did inherit from that mess is that I now have a custom lsp that provides completion and diagnostics for target dependencies

#

which is like

#

πŸ’€

simple sinew
#

hey thats pretty cool

honest echo
#

aight I implemented hooks that shouldnt be terrible for performance. I emit the function pointers in a unique section per hook. I also made a python script that automatically generates a linker script that defines start/end symbols because I dont wanna rely on the gnu __start/end ones.

#

the only thing is that my build process is becoming more complex day by day

#

lmao

#

basically no overhead compared to a function pointer call

#

direct function call would still be more performant but hooks lets me register multiple handlers per hook

#

extended the lsp to do hooks too

#

this is actually kinda neat

honest echo
#

pretty happy with this though

#

initializing a slab cache for example becomes as simple as this

#

the hook gets executed from the slab init function

honest echo
#

did a lot of work on organizing the init stuff

#

now I am faulting on a nullptr πŸ™‚

#

fun times

honest echo
#

I have spent like

#

15 hours in the last two days

#

debugging these random faults I get

#

I cant reproduce them 100% of the time

#

ther's like 4 different faults ive identified that happens

#

it only happens using kvm which makes things so fucking shit to debug

#

its definitely concurrency related

#

I seem to have fixed them with this

#

this is in my interrupt handler

#

though I dont see how this directly fixes the issues I have been having

#

I definitely see how some issues might arise by allowing soft irqs to nest

#

but I dont see how it leads to the faults I have been dealing with

#

😭

#

so now I am sitting here terrified I havent fixed the root cause

simple sinew
#

what are the random faults?

honest echo
#

mostly completely nonsensical page faults

#

there is one really fun one that kept happening in userspace when mlibc tried to access a kernel space address

#

and yes I am 1000000% sure it was never passed to userspace via syscalls or anything of that sort

simple sinew
#

hmm

#

could it be a segment register?

honest echo
#

thats what came to mind

#

but fs is intact

#

gs was zeroed

#

ds, es are zeroed on every return to userspace

simple sinew
#

and I imagine you're not touching floating point and vector registers in the kernel?

honest echo
#

yep

#

well beyond saving/restoring them

honest echo
#

wait no

#

yeah idk why this would cause any of that

simple sinew
#

what is dw_status btw?

honest echo
#

deferred work

#

like

#

soft irq

simple sinew
#

I can only see it as dont worry stattus

#

ah ok lol

honest echo
#

basically I was allowing deferred work to be handled within nested interrupts

#

which is probably not ideal at the very least

#

but I dont see why it'd be fatal like this

#

and since the issue seems to be very timing related im just worried this changed the timings enough to "fix" it

simple sinew
#

wrt to the leaked kernel address, I'm wondering if its a page being used twice somewhere (thats not supposed to be).

honest echo
#

yeah I mean memory corruption is the thing I assumed is the issue

#

like one thing I found out is if I allocate some memory before some other it "fixes" the issue

#

which is nonsensical

#

but god if I know where the memory corruption might be happening

#

one thing that does come to mind is that if I allow deferred work to be handled in nested interrupts. the likelyhood for them to keep nesting goes way up and I might overrun the stack

#

that might be the most logical explanation

#

I really should setup canary pages around the stack

simple sinew
#

they're worth having

honest echo
#

actually for now a quick and dirty check is to assert if I am almost off the stack in the handler

#

and see if that gets triggered

simple sinew
#

I assume you've tried disabling freeing for various allocators and seeing if the faults still pop up?

honest echo
#

slab/heap. disabling free for the pmm turned out to be slightly problematic

#

since it gets populated via free

simple sinew
#

ah lol

honest echo
#

I should do that though

#

I am going to try the assert first tho

#

if it is this I would be so happy

simple sinew
#

you can also scribble over pages as they're being freed, sometimes that catches things

#

yeah that would be nice

honest echo
#

well the assert doesnt trigger

#

but if I increase the kernel stack size I also dont get the faults

#

but again that could be because of the difference in allocation

#

hmm also allocating them with the VM instead of PMM + HHDM seems to fix the thing

#

though that could be because they are now overwriting other shit, not shit in the HHDM

#

im going to try some poor mans guard pages

#

lol

simple sinew
#

what if you allocate the stack with guard pages on both sides?

honest echo
#

yeah

#

I dont have a good impl to do so

#

but im just going to allocate them somewhere far off in memory far apart

simple sinew
#

hardcode it in meme

honest echo
#

πŸ™‚

#

bruh my vm is refusing to map things where I want them

#

what

honest echo
#

wow

#

that is

#

so I made a static var

#

just like before the kernel ish

#

and then I just add some to it for every stack

#

very scuffed

#

it..... ends up trying to map this address

#

what the fuck

#

well memory corruption it is

#

oh YES! it happens in tcg

#

I can watchpoint it

#

oh

#

FUCK IM STUPID

#

it was in decimal

#

well thats annoying

#

ig

#

it works

#

I suppose that means they are not overunning their stacks

honest echo
#

you are right tho about poisoning memory

#

that led to another fault

#

though STILL it will not happen with tcg on

#

god this is frustrating

#

fuck

#

if I add an assert checking the memory on alloc it apparently causes enough time drift to make the bug not happen

#

at least it hints towards the pmm at least being intact

honest echo
#

almost at 20 hours of debugging the same thing

#

fuck yeah

#

this totally doesnt suck

#

I couldve re-written my entire kernel in that time probably

#

the main thing is I cannot seem to pinpoint what even goes wrong

#

I know the symptoms but I cannot for the life of me trace any of them back to what actually went wrong

#

like this one for example

#

I presume the data in the xsave area got borked at some point

#

but how to trace it to what did it or even confirm that is what is happening idk

#

because I cannot run it with tcg so I have super limited means of debugging

honest echo
#

i dont even remember what I changed

#

but I think I fixed some tiny bugs

#

and now its this one that mainly comes up

honest echo
#

yeah atp I think I am just going to do the thing I have been wanting to do and rewrite the kernel

honest echo
#

nah nah not yet

#

I can do this

simple sinew
simple sinew
#

a bit of an extreme measure but you could do a userspace port of your kernel if its portable. Then you have all your usual tools available to you.

#

depending on how good your git hygeine is too, you could try git bisect.

honest echo
honest echo
simple sinew
#

Fair enough, anything in particular?

honest echo
#

mostly just the way I do like different contexts

#

like I am not very confident that I manage where I can do different things 100% correct

#

like in terms of interrupts / deferred work

#

I need to think it through further before implementing

#

also the entire kernel was written with a different arch abstraction so its a bit borked atm

honest echo
#

well spent all of yesterday and the day before rewriting my build system in rust

#

lol

#

but its slightly less borked now

honest echo
#

alright today I will start rewriting cronus

honest echo
#

cyke

plush mirage
#

greetings from #showing-off

honest echo
#

lol welcome

#

this thread is dead asf tho

plush mirage
#

this matters not

honest echo
#

though I should start working on cronus soon tho πŸ™‚

plush mirage
#

work at thy owne pace

honest echo
#

plan currently is to start over and write a microkernel

plush mirage
honest echo
#

but im finishing some tooling first and need to finish aarch64 support for my bootloader

honest echo
#

im planning on prolly writing the kernel in C and writing servers & drivers in rust

plush mirage
#

oh interesting

#

most OSes I see here use one language for all of it

honest echo
#

yeah prolly

#

I write a good amount of rust for normal applications

#

did a little bit of systems stuff with it

#

but only dont kernel development in C really

#

so feels like a decent way to go about it

plush mirage
#

Then you can surely compile your kernel using #1306765166007816363 trl

honest echo
#

haha, yeah unfortunately clang only πŸ™‚

#

I abuse the hell out of clang tooling

#

re: clang-tidy checks for enforcing atomics

plush mirage
#

clang-tidy is just CI checks, you don't use it for actual compilation

honest echo
#

will check it out forsure πŸ™‚

plush mirage
honest echo
plush mirage
#

Sounds like it takes a WHILE

honest echo
#

well I run a very small subset

#

mainly my custom checks

#

I use clangs annotate attribute to annotate vars/members that are atomic and then enforce specific functions for accessing them

plush mirage
#

cool

honest echo
#

idk its cursed, part of the reason I am interested in using rust

#

feels like if I need to stretch the language this far maybe I should use something else

plush mirage
#

That of C is particularly lenient for a strongly-typed language.

#

I personally use Rust primarily for the borrow checker

honest echo
#

well naturally that is another benefit

#

there's little about rust I dont like

plush mirage
#

Actually since we're both just starting this is a golden opportunity to potentially work together?

#

Perhaps we could do something like have the same ABI (which is easier because microkernels have less ABI to make in the first place) so we can share work?

honest echo
#

Sure, we could definitely come up with something πŸ™‚

plush mirage
#

I don't have any of that designed at the moment.

honest echo
#

though my kernel dev stuff is prolly a week or two out atm

#

Well maybe just a week

honest echo
plush mirage
#

I do find the idea of Managarm's highly asynchronous I/O appealing

honest echo
#

I honestly know very little about Managarms internals

plush mirage
#

So do I