ipilcher / n5550

Thecus N5550 hardware support
GNU General Public License v2.0
8 stars 8 forks source link

Can't build module on kernel >=5.12 #19

Closed marc0777 closed 2 years ago

marc0777 commented 2 years ago

I was trying to get this on my N5550 currently running OpenMediaVault. However I noticed that, even after applying the patch mentioned in #17 the modules still can't compile. The error I get is this:

make[1]: Entering directory '/usr/src/linux-headers-5.15.19-2-pve'
  CC [M]  /root/n5550-master/modules/n5550_ahci_leds.o
/root/n5550-master/modules/n5550_ahci_leds.c: In function ‘enabled_store’:
/root/n5550-master/modules/n5550_ahci_leds.c:110:34: error: ‘module_mutex’ undeclared (first use in this function); did you mean ‘module_put’?
  110 |  ret = mutex_lock_interruptible(&module_mutex);
      |                                  ^~~~~~~~~~~~
      |                                  module_put
/root/n5550-master/modules/n5550_ahci_leds.c:110:34: note: each undeclared identifier is reported only once for each function it appears in
/root/n5550-master/modules/n5550_ahci_leds.c: In function ‘n5550_ahci_leds_init’:
/root/n5550-master/modules/n5550_ahci_leds.c:226:34: error: ‘module_mutex’ undeclared (first use in this function); did you mean ‘module_put’?
  226 |  ret = mutex_lock_interruptible(&module_mutex);
      |                                  ^~~~~~~~~~~~
      |                                  module_put
make[2]: *** [scripts/Makefile.build:285: /root/n5550-master/modules/n5550_ahci_leds.o] Error 1
make[1]: *** [Makefile:1880: /root/n5550-master/modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.19-2-pve'
make: *** [Makefile:6: all] Error 2

After some investigation I found torvalds/linux@922f2a7c822bf76dffb218331bd95b1eea3cf637 this commit affecting linux since version 5.12 that removed the export of module_mutex in module.h, making it not accessible for us.

How could this be made into working again without directly using that export?

marc0777 commented 2 years ago

After looking into it further I also noticed that find_module has been unexported too since kernel 5.12, as in commit https://github.com/torvalds/linux/commit/089049f6c9956c5cf1fc89fe10229c76e99f4bef, so solving the module_mutex problem would't be enough to compile this in more recent kernels.

ipilcher commented 2 years ago

Yup. I ran into this when I looked at what it would take to migrate my N5550 to something later than CentOS 7 a few months ago. As you discovered, the approach that I took with my n5550_ahci_leds module (which was always a rather horrible hack) is no longer viable.

The good news is that this provided the impetus for me to write a more generic block device LED trigger that actually does things the "right way." I've since been trying to get someone who works on the Linux LEDs subsystem to actually review the darn thing, so that it can actually be included in the kernel. Unfortunately, I've had no luck with this.

The module does, however, work just fine as an out-of-tree driver, and it does away with the requirement that the ahci driver be built as a module; it works just fine with a built-in AHCI driver. I've added a copy of the relevant files to this repo here, including documentation of the various sysfs attributes and a short overview of how the trigger works.

You'll still need the n5550_board module to actually tell the kernel about the N5550's LEDs and GPIOs, and you'll need to create udev rules or something to configure the blkdev LED trigger at boot. Once that's done, however, the disk activity LEDs should just work, and the other LEDs and GPIOs should all be configured, so that you can use them with freecusd or anything else.

Let me know how it goes.

marc0777 commented 2 years ago

I managed to compile and enable the n5550_board together with the ledtrig-blkdev module and it works very well, thanks!

I'm having problems compiling freecusd too, but I'll open a separate issue for that.

hapklaar commented 2 years ago

I managed to compile and enable the n5550_board together with the ledtrig-blkdev module and it works very well, thanks!

@marc0777 Would you be so kind to include a short step-by-step for what you did to make this work? I'm still struggling with what to do after compiling both these modules.