IRC channel logs
2026-01-11.log
back to list of logs
<damo22> * Code and stack selectors have already been <damo22> * checked. Others will be reset by 'iret' <azert>what about context switching, how do you deal with that? <damo22>#if defined(__x86_64__) && !defined(USER32) <damo22> wrmsr(MSR_REG_FSBASE, pcb->ims.sbs.fsbase); <damo22> wrmsr(MSR_REG_KGSBASE, pcb->ims.sbs.gsbase); <damo22>maybe i dont need to push %gs and pop %gs with PUSH_SEGMENTS and POP_SEGMENTS? <youpi>I wonder if that's really needed indeed <sobkas>Ok had to switch to vesa as qxl had some horrible memory leaks <damo22>RIP ffffffff8103df4d EFLAGS 00010006 <damo22>trapno 14: Page fault, error 00000002 <damo22>panic {cpu0} ../i386/i386/trap.c:230: kernel_trap: kernel thread accessed user s <damo22>0xffffffff8103df4d <all_intrs+65>: 0x00d504ff <azert>damo22: I suspect popping gs sets gsbase to zero <damo22>>>>>> Page fault (14) for W fffffffe61796000 at all_intrs+0x41 <<<<< <damo22>305 err = boot_script_parse_line (&bmods[i], line); <damo22>303 char *line = (char*)phystokv(bmods[i].string); ?? <youpi>yes, the multiboot information is using physical addresses <damo22>0xffffffff81087a47 206 losers = boot_script_set_variable <damo22>=> 0xffffffff81087a47 <bootstrap_create+215>: call 0xffffffff8108c9b0 <boot_script_set_variable> <damo22>is that supposed to be a function call? <youpi>it's a function and call is the instruction to make a function call, yes <damo22>it seems to change behaviour on every run <damo22>result is a page fault >>>>> Page fault (14) for W fffffffe61796000 at all_intrs+0x41 <<<<< <damo22>i think i removed a CPU_NUMBER() in all_intrs by mistake <damo22>start pci-arbiter: HANG and GS = 0 with base address 0 <damo22>%ss is always set to KERNEL_DS ? <youpi>because we set it in the master TSS <youpi>so the processor does the switch <damo22>ok i am a bit confused, if userspace sets %gs register to 0, it will wipe the gs base, so how do we stop that from killing the kernel? <damo22>well, it wipes the current value of the gsbase <youpi>which is the user gs base while in user land <damo22>ok so a kernel thread cannot run while userspace is also running? <youpi>processors run only one thing at a time <damo22>somehow FS is zero when DS is 0x10 <youpi>that's not really surprising: the kernel doesn't use fs atm <damo22>i think the problem is, a kernel thread is running "in userspace" <damo22>because the first thread is launched as a userspace thread <damo22>so there is no need to swapgs during early bringup when the first thread is running <damo22>start pci-arbiter: Kernel Page fault trap, eip 0xffffffff8103e7fa, code 0, cr2 c <damo22>thats looking better than before <damo22>it still throws the above page fault <damo22>looks like while inside a 64b syscall, it calls _Xthread_set_state <damo22>so while in a user context, it tries to call splsched() which breaks <damo22>do i swapgs at the start of every syscall64 and at the end? <damo22>do i need to wrap syscall64_call in swapgs? <etno>sobkas: Since we don't have any DRM driver, wouldn't it be desirable that mesa builds without the need for stubs ? <etno>AIUI, this is the common code for mesa drivers using DRM. Removing that part from the build may be a possibility ? <damo22>we would need to add it all back again when we write drm <etno>Yes, but mesa should be able to build for a system without any DRM support and still do sw-rendering <etno>And I think that it may actually be possible by disabling DRI support <etno>(on the other hand, I failed so far to do so; so probably talking too loud 😅) <etno>My idea was : gallium(softpipe or llvm) + DRI disabled + GLX(direct-glx) <damo22>GS =0000 ffffffff810bb000 00000000 00201300 <damo22>now the base address is correct but the selector is 0 <damo22>i think that invalidates the segment <youpi>damo22: syscall64 is a clear user-to-kernel entry, so swapgs is required, yes <azert>damo22: in long mode, gs can be zero, it shouldn't invalidate the base <youpi>azert: loading 0 into gs does invalidate the base <damo22>youpi: so i think the issue is the selector is 0 and wipes gs, but even after i restore the base address the selector remains 0 and still doesnt allow it to resolve gs:addresses <azert>youpi: that's because you load 0 into gs, indeed <azert>but if you restore the gsbase using wrgsbase, then the fact that it is zero doesn't matter in long mode <youpi>see right above damo22 saying "even after i restore the base address the selector remains 0 and still doesnt allow it to resolve gs:addresses" <damo22>let me try loading the selector as well as the base <youpi>damo22: I don't see linux restoring gs, it just leaves it as it was in user land <youpi>i.e. user land can change gs (and thus clear the gs base), the kernel doesn't care, and just uses swapgs to restore the gs base without caring about gs itself <azert>I found this at page 168 of the manual: the processor does not perform runtime checking on NULL segment selectors <damo22>well the selector brings in the access/flags bits? <damo22>GS =0000 ffffffff810bb000 00000000 00201300 <azert>if the base is correct then it doesn't break because of fs <damo22>which is loaded when i set the gs selector to the 0x68 <azert>I would leave the gs selector to zero <azert>it's just a compatibility feature <azert>really they could have just substitute gs with a couple of registers, instead they decided to keep it for compatibility with i386 <damo22>ok so i am in gdb breakpointed at syscall64 <damo22>GS =0000 ffffffff810bb000 00000000 00000000 <damo22>after the swapgs it did not change <damo22>so both msrs have the same value <azert>you need to set them in the kernel, they don't change in the userspace <azert>and I would avoid using selectors to change them <azert>first of all, because they just modify the lower 32 bit <youpi>damo22: I guess we can drop a part of your Add GS segment configuration to early gdt commit: we want the gs base part, but we don't need the boot GS part and loading $PERCPU_DS <youpi>and probably we don't need to set it up in gdt_fill either <azert>it might be needed for the USER_32 feature <azert>I think that USER_32 was a sexy concept like in 2000 when amd64 was made <azert>because software back then rarely needed more then 4gb each <youpi>it's not just sexy. It allows now to keep some hurd-i386 packages built <youpi>because they now require a lot of virtual memory <azert>after debian will drop the linux i386 distribution, I suppose hurd should do it too <Pellescours>damo22: I see that when you setup the swapgs you set the kernel value in both (gs_base & kgs_base). I hope the user value is cleared before jumping on userland otherwise I fear a security hole (kernel gs in userland so userland being able to hack something and reach kernel memory) <damo22>i dont know how to protect kernel from that, if someone knows the address <azert>damo22: of course the userspace cannot set the kernel gsbase <azert>just leave the userspace gs_base alone, you basically shouldn't care about what is there <azert>or put an absurd value there; like -1ULL <azert>that will be useful for debugging swapgs issues <damo22>GS =0000 ffffffff810bb000 000fffff 00000000 <damo22>i am going to push what ive got and leave it for tonighe <sobkas>etno: drm is needed for dri it's not used but still needs it during compilation, it was easier to add stubs than fix dependency on drm <etno>sobkas: The idea would be to disable dri itself. <sobkas>etno: without dri it build libgl so I don't liked it <etno>sobkas: any solution that works will suite me in the end. And as Damo mentioned, a stub drm.h file would be a first step towards an actual implementation. <sobkas># FIXME: haiku doesn't use dri, and xlib doesn't use dri, probably should <sobkas>I agree with this sentiment that xlib shouldn't be a special case <sobkas>as of stubs I have file full of #define _IOT_drm_buf_desc (0) and it compiles and works(need to actually check?) <gnu_srs1>And comment on what has already been done. <sobkas>I got comment to not use thatwe shouldn't use ioccom.h <sobkas>ok I'm trying other option for mesa <gnu_srs1>I have patches enabling a lot in mesa. The only remaining problem is glxgears works with ssh -Y but not in the window manager. Probably a shared memory issue. <gnu_srs1>I would appreciate help to find out the cause. Shall I send the patches to the ML? <sobkas>with some if violence I was able to compile mesa without(not 100% sure) drm <sobkas>Ok glxgears works with ssh -X/Y and on window manager <sobkas>I still have problems with code=139 <sobkas>And I'm unable to make qxl work with opengl