johnfanv2 / LenovoLegionLinux

Driver and tools for controlling Lenovo Legion laptops in Linux including fan control and power mode.
https://github.com/johnfanv2/LenovoLegionLinux
GNU General Public License v2.0
1.29k stars 49 forks source link

[BUG] crash since powerstate module got added #202

Closed gulafaran closed 2 months ago

gulafaran commented 2 months ago

Problem Description legiond service crashes after powerstate module got commited https://github.com/johnfanv2/LenovoLegionLinux/commit/3cb3c69e67e354331e85aed46ff0db9d0ae7a67c

Core was generated by `/usr/bin/legiond'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007ffff7e248ec in ?? () from /usr/lib64/libc.so.6
[Current thread is 1 (Thread 0x7ffff7c006c0 (LWP 4661))]
(gdb) bt
#0  0x00007ffff7e248ec in ?? () from /usr/lib64/libc.so.6
#1  0x00007ffff7e1a1c4 in __isoc99_fscanf () from /usr/lib64/libc.so.6
#2  0x0000555555555b8e in get_powerstate () at modules/powerstate.c:20
#3  0x0000555555555cc9 in timer_handler ()
    at /var/tmp/portage/sys-firmware/lenovolegionlinux-9999/work/lenovolegionlinux-9999/python/legion_linux/legion_linux/extra/service/legiond/legiond.c:29
#4  0x00007ffff7e5a718 in ?? () from /usr/lib64/libc.so.6
#5  0x00007ffff7e4f9c2 in ?? () from /usr/lib64/libc.so.6
#6  0x00007ffff7ec9918 in ?? () from /usr/lib64/libc.so.6

https://github.com/johnfanv2/LenovoLegionLinux/blob/3b7a69cff110dde545560019966fa9a0a92abc08/extra/service/legiond/modules/powerstate.c#L18 https://github.com/johnfanv2/LenovoLegionLinux/blob/3b7a69cff110dde545560019966fa9a0a92abc08/extra/service/legiond/modules/powerstate.c#L20

defined here https://github.com/johnfanv2/LenovoLegionLinux/blob/3b7a69cff110dde545560019966fa9a0a92abc08/extra/service/legiond/modules/powerstate.h#L18

however on this legion 7i 2023 running linux 6.8.4 that path should be /sys/firmware/acpi/pm_profile

gulafaran commented 2 months ago

hm however changing that makes it crash a bit further.

Core was generated by `/usr/bin/legiond'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007ffff7f16207 in ?? () from /usr/lib64/libc.so.6
[Current thread is 1 (Thread 0x7ffff7c006c0 (LWP 9559))]
(gdb) bt
#0  0x00007ffff7f16207 in ?? () from /usr/lib64/libc.so.6
#1  0x0000555555555d75 in set_gpu (config=0x555555559040 <config>, power_state=4294967295) at modules/setapply.c:108
#2  set_all (config=0x555555559040 <config>, power_state=4294967295) at modules/setapply.c:168
#3  timer_handler ()
    at /var/tmp/portage/sys-firmware/lenovolegionlinux-9999/work/lenovolegionlinux-9999/python/legion_linux/legion_linux/extra/service/legiond/legiond.c:29
#4  0x00007ffff7e5a718 in ?? () from /usr/lib64/libc.so.6
#5  0x00007ffff7e4f9c2 in ?? () from /usr/lib64/libc.so.6
#6  0x00007ffff7ec9918 in ?? () from /usr/lib64/libc.so.6

is my legion reporting a different kind of pm_profile?

st0nie commented 2 months ago

Thanks, but platform profile is not pm_profile We need kernel_module support to make legiond works for your machine

brainos233 commented 2 months ago

Same problem

Details

``` Thread 3 (Thread 0x7ffff7c006c0 (LWP 213858) "legiond"): #0 0x00007ffff7f0686b in ?? () from /usr/lib/libc.so.6 No symbol table info available. #1 0x0000555555555dc3 in set_gpu (power_state=P_AC_P, config=0x555555559060 ) at modules/setapply.c:110 cmd = "\300e\370\367\377\177\000\000\250f\370\367\377\177\000\000P@\370\367\377\177\000\000)\370\342\367\377\177\000\000\300e\370\367\377\177\000\000c\375\342\367\377\177\000\000\020\000\000\000\000\000\000\000\335pUUUU\000\000\300e\370\367\377\177\000\000jX\342\367\377\177\000\000\006\000\000\000\000\000\000\000\220\376\277\367\377\177\000\000\006\000\000" result = #2 0x0000555555555ff8 in set_all (config=0x555555559060 , power_state=P_AC_P) at modules/setapply.c:168 No locals. #3 timer_handler () at /usr/src/debug/lenovolegionlinux-git/lenovolegionlinux/extra/service/legiond/legiond.c:29 No locals. #4 0x00007ffff7e4410d in ?? () from /usr/lib/libc.so.6 No symbol table info available. #5 0x00007ffff7e3855a in ?? () from /usr/lib/libc.so.6 No symbol table info available. #6 0x00007ffff7eb5a5c in ?? () from /usr/lib/libc.so.6 No symbol table info available. Thread 2 (Thread 0x7ffff7fc0740 (LWP 213857) "legiond"): Quit Not confirmed. [Inferior 1 (process 213854) killed] Thread 3 (Thread 0x7ffff7c006c0 (LWP 229779) "legiond"): #0 0x00007ffff7f0686b in ?? () from /usr/lib/libc.so.6 No symbol table info available. #1 0x0000555555555dc3 in set_gpu (power_state=P_AC_P, config=0x555555559060 ) at modules/setapply.c:110 cmd = "\300e\370\367\377\177\000\000\250f\370\367\377\177\000\000P@\370\367\377\177\000\000)\370\342\367\377\177\000\000\300e\370\367\377\177\000\000c\375\342\367\377\177\000\000\020\000\000\000\000\000\000\000\335pUUUU\000\000\300e\370\367\377\177\000\000jX\342\367\377\177\000\000\006\000\000\000\000\000\000\000\220\376\277\367\377\177\000\000\006\000\000" result = #2 0x0000555555555ff8 in set_all (config=0x555555559060 , power_state=P_AC_P) at modules/setapply.c:168 No locals. #3 timer_handler () at /usr/src/debug/lenovolegionlinux-git/lenovolegionlinux/extra/service/legiond/legiond.c:29 No locals. #4 0x00007ffff7e4410d in ?? () from /usr/lib/libc.so.6 No symbol table info available. #5 0x00007ffff7e3855a in ?? () from /usr/lib/libc.so.6 No symbol table info available. #6 0x00007ffff7eb5a5c in ?? () from /usr/lib/libc.so.6 No symbol table info available. Thread 2 (Thread 0x7ffff7fc0740 (LWP 229778) "legiond"): #0 0x00007ffff7dea42a in sigtimedwait () from /usr/lib/libc.so.6 No symbol table info available. #1 0x00007ffff7e4404b in ?? () from /usr/lib/libc.so.6 No symbol table info available. #2 0x00007ffff7e3855a in ?? () from /usr/lib/libc.so.6 No symbol table info available. #3 0x00007ffff7eb5a5c in ?? () from /usr/lib/libc.so.6 No symbol table info available. Thread 1 (Thread 0x7ffff7daa740 (LWP 229775) "legiond"): #0 0x00007ffff7eb763f in accept () from /usr/lib/libc.so.6 No symbol table info available. #1 0x0000555555555208 in main () at /usr/src/debug/lenovolegionlinux-git/lenovolegionlinux/extra/service/legiond/legiond.c:97 clientfd = ret = "\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000" delay = delay_s = 1 delay_ns = 500000000 timerid = 0x80002aaaaaaad528 its = {it_interval = {tv_sec = 0, tv_nsec = 0}, it_value = {tv_sec = 1, tv_nsec = 0}} sev = {sigev_value = {sival_int = -5992, sival_ptr = 0x7fffffffe898}, sigev_signo = 0, sigev_notify = 2, _sigev_un = {_pad = {1431658432, 21845, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, _tid = 1431658432, _sigev_thread = {_function = 0x555555555fc0 , _attribute = 0x0}}} addr = {sun_family = 1, sun_path = "/run/legiond.socket", '\000' , "\377\373\213\027\000\000\000\000W\366\036\031\000\000\000\000`\353\377\377\377\177\000\0000\353\377\377\377\177", '\000' , "\200\374\367\377\177\000\000\300\002\000\000\000\000\000\000!\357\375\367\377\177\000\000(\352\377\377\377\177\000\000\000\000\000\001\000"} action = {__sigaction_handler = {sa_handler = 0x5555555554f0 , sa_sigaction = 0x5555555554f0 }, sa_mask = {__val = {0 }}, sa_flags = 0, sa_restorer = 0x0} [Inferior 1 (process 229775) killed] Thread 3 (Thread 0x7ffff7c006c0 (LWP 27439) "legiond"): #0 0x00007ffff7f0686b in ?? () from /usr/lib/libc.so.6 No symbol table info available. #1 0x0000555555555cf8 in set_gpu (config=0x555555559040 , power_state=P_AC_P) at modules/setapply.c:108 cmd = "\000\000@\367\377\177\000\0000\000\000\350\377\177\000\000\000\000\000\000\000\000\000\000\210\377\377\377\377\377\377\377\000\000\000\000\000\000\000\000\240\374\373\367\377\177\000\000\000\000@\367\377\177\000\000\341\200\344\367\377\177\000\000\210\377\377\377\377\377\377\377\000\000\000\000\000\000\000\000\210\377\377\377\377\377\377\377\223\216\344\367\377\177\000\000p\v", result = cmd = result = #2 set_all (config=0x555555559040 , power_state=P_AC_P) at modules/setapply.c:168 No locals. #3 timer_handler () at /usr/src/debug/lenovolegionlinux-git/lenovolegionlinux/python/legion_linux/legion_linux/extra/service/legiond/legiond.c:29 No locals. #4 0x00007ffff7e4410d in ?? () from /usr/lib/libc.so.6 No symbol table info available. #5 0x00007ffff7e3855a in ?? () from /usr/lib/libc.so.6 No symbol table info available. #6 0x00007ffff7eb5a5c in ?? () from /usr/lib/libc.so.6 No symbol table info available. Quit Not confirmed. [Inferior 1 (process 27435) killed] ```

st0nie commented 2 months ago

Can you give the output of the powerprofilesctl command?

powerprofilesctl
gulafaran commented 2 months ago
┌┤tom-legion->tom ~
└➤ powerprofilesctl 
  performance:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile
    Degraded:   no

* balanced:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile

  power-saver:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile
st0nie commented 2 months ago

Can fn+q change the mode of powerprofilesctl? if so I would consider using powerprofilesctl to get the power mode when that path is not available

Also I would like to know if fn+q can trigger acpi events on your machine. You can test this with acpi_listen

gulafaran commented 2 months ago

this is with the led turning red,

┌┤tom-legion->tom ~
└➤ powerprofilesctl 
* performance:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile
    Degraded:   no

  balanced:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile

  power-saver:
    CpuDriver:  intel_pstate
    PlatformDriver: platform_profile

so yeah looks so here atleast

gulafaran commented 2 months ago

as for acpi_listen it seems so


┌┤tom-legion->tom:130 ~
└➤ acpi_listen
 D320289E-8FEA- 000000e7 00000000
 D320289E-8FEA- 000000e3 00000000
 95D1DF76-D6C0- 000000d0 00000000
 D320289E-8FEA- 000000e7 00000000
 D320289E-8FEA- 000000e3 00000000
 95D1DF76-D6C0- 000000d0 00000000
 D320289E-8FEA- 000000e7 00000000
 D320289E-8FEA- 000000e3 00000000

this is me cycling between the three modes

st0nie commented 2 months ago

https://github.com/johnfanv2/LenovoLegionLinux/commit/a0c9495b6acf161c5f6f93343671dc5d5811d1e9

@gulafaran Does this fix it? I tested it with my laptop and it works

gulafaran commented 2 months ago

a0c9495

@gulafaran Does this fix it? I tested it with my laptop and it works

yeah, i havent setup the config since it crashed before but,

┌┤tom-legion->tom ~
└➤ systemctl status legiond
● legiond.service - legiond daemon
     Loaded: loaded (/usr/lib/systemd/system/legiond.service; disabled; preset: disabled)
     Active: active (running) since Fri 2024-04-26 13:25:51 CEST; 3s ago
   Main PID: 36464 (legiond)
      Tasks: 2 (limit: 115398)
     Memory: 240.0K (peak: 720.0K)
        CPU: 2ms
     CGroup: /system.slice/legiond.service
             └─36464 /usr/bin/legiond

the service is up and running now :)

st0nie commented 2 months ago

I think it should be fine.