kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Trouble with allocating memory on platform driver
@ 2020-04-04 15:21 s.achterop
  2020-04-15  9:29 ` s.achterop
  0 siblings, 1 reply; 4+ messages in thread
From: s.achterop @ 2020-04-04 15:21 UTC (permalink / raw)
  To: kernelnewbies

Hello list,

Trying to create a device driver for a raspberry pi zero (BCM2835) to control a gpio and an spi device.
This eventually will be done in a FIQ interrupt handler.
A simplified version of this batradio-driver can be found at:
  https://github.com/SietseAchterop/Batradio/blob/master/batradio_module/alloctest.c

The problem is that modprobe-ing this driver directly yields the following in dmesg.

Apr  4 16:50:23 raspberrypi kernel: [  139.636850] batradio: loading out-of-tree module taints kernel.
Apr  4 16:50:23 raspberrypi kernel: [  139.653580] ------------[ cut here ]------------
Apr  4 16:50:23 raspberrypi kernel: [  139.653650] WARNING: CPU: 0 PID: 1208 at include/linux/dma-mapping.h:516 init_module+0x164/0x1e0 [batradio]
Apr  4 16:50:23 raspberrypi kernel: [  139.653664] Modules linked in: batradio(O+) fuse rfcomm cmac bnep hci_uart btbcm serdev bluetooth ecdh_generic 8021q garp stp llc sg uas brcmfmac brcmutil sha256_generic cfg80211 rfkill snd_bcm2835(C) raspberrypi_hwmon snd_pcm hwmon snd_timer snd 
bcm2835_v4l2(C) bcm2835_codec(C) v4l2_mem2mem bcm2835_mmal_vchiq(C) v4l2_common videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media vc_sm_cma(C) fixed uio_pdrv_genirq uio i2c_dev ip_tables x_tables ipv6
Apr  4 16:50:23 raspberrypi kernel: [  139.653835] CPU: 0 PID: 1208 Comm: modprobe Tainted: G         C O      4.19.108+ #1
Apr  4 16:50:23 raspberrypi kernel: [  139.653844] Hardware name: BCM2835
Apr  4 16:50:23 raspberrypi kernel: [  139.653897] [<c00184f8>] (unwind_backtrace) from [<c0015064>] (show_stack+0x20/0x24)
Apr  4 16:50:23 raspberrypi kernel: [  139.653931] [<c0015064>] (show_stack) from [<c0753394>] (dump_stack+0x20/0x28)
Apr  4 16:50:23 raspberrypi kernel: [  139.653970] [<c0753394>] (dump_stack) from [<c0025b58>] (__warn.part.3+0xb8/0xe0)
Apr  4 16:50:23 raspberrypi kernel: [  139.653998] [<c0025b58>] (__warn.part.3) from [<c0025cf8>] (warn_slowpath_null+0x50/0x5c)
Apr  4 16:50:23 raspberrypi kernel: [  139.654037] [<c0025cf8>] (warn_slowpath_null) from [<bf698164>] (init_module+0x164/0x1e0 [batradio])
Apr  4 16:50:23 raspberrypi kernel: [  139.654110] [<bf698164>] (init_module [batradio]) from [<c000ae8c>] (do_one_initcall+0x4c/0x234)
Apr  4 16:50:23 raspberrypi kernel: [  139.654151] [<c000ae8c>] (do_one_initcall) from [<c00a7898>] (do_init_module+0x6c/0x1f8)
Apr  4 16:50:23 raspberrypi kernel: [  139.654181] [<c00a7898>] (do_init_module) from [<c00a9cdc>] (load_module+0x21ec/0x24cc)
Apr  4 16:50:23 raspberrypi kernel: [  139.654209] [<c00a9cdc>] (load_module) from [<c00aa1f8>] (sys_finit_module+0xcc/0xec)
Apr  4 16:50:23 raspberrypi kernel: [  139.654232] [<c00aa1f8>] (sys_finit_module) from [<c0009000>] (ret_fast_syscall+0x0/0x28)
Apr  4 16:50:23 raspberrypi kernel: [  139.654244] Exception stack(0xcc037fa8 to 0xcc037ff0)
Apr  4 16:50:23 raspberrypi kernel: [  139.654261] 7fa0:                   93da3c00 00401760 00000003 0002d064 00000000 0002ec3c
Apr  4 16:50:23 raspberrypi kernel: [  139.654279] 7fc0: 93da3c00 00401760 00000000 0000017b 00402f10 00000000 00402e68 00000000
Apr  4 16:50:23 raspberrypi kernel: [  139.654294] 7fe0: bed56338 bed56328 00022cb8 b6c26af0
Apr  4 16:50:23 raspberrypi kernel: [  139.654307] ---[ end trace deb280ac68ce7734 ]---
Apr  4 16:50:23 raspberrypi kernel: [  139.654330] platform batradio__.0: coherent DMA mask is unset
Apr  4 16:50:23 raspberrypi kernel: [  139.654344] platform batradio__.0: Couldn't allocate memory!

The crash is at the very beginning of the init function of the module, here is the first part of that function:

   pdev = platform_device_register_simple("batradio__", 0, NULL, 0);
   if (IS_ERR(pdev))
     return PTR_ERR(pdev);
	
   batradio_data = devm_kzalloc(&pdev->dev,
			       sizeof(*batradio_data),
			       GFP_KERNEL);
   if (!batradio_data)
     return -ENOMEM;

   batradio_data->fiq_base = dma_zalloc_coherent(&pdev->dev,
						FIQ_BUFFER_SIZE,
						&batradio_data->dma_handle,
						GFP_KERNEL);
   if (!batradio_data->fiq_base) {
     dev_err(&pdev->dev, "Couldn't allocate memory!\n");
     return -ENOMEM;
   }

Note that the crash seems to occur because of the call to dma_zalloc_coherent.
The allocation does not work, FIQ_BUFFER_SIZE is 256*1024. and this is directly after reboot.
Also note that I start the rpizero only with the console, so no X. And login with ssh.

Why is this happening? What does "coherent DMA mask is unset" means.
I do not intend to use dma, but I understood that allocating in this way is what I should do if I want to use this data also from my FIQ handler.

Does it has to do with the use of platform_device_register_simple? Maybe the device structure isn't initialized properly for this?
I actually use this function because I don't know which compatible value I have to use when using the devicetree, everything I tried failed.

I also read the following in platform_device.h about platform_device_register_simple:
       In particular, when such drivers are built as modules, they can't be "hotplugged".
Is this relevant. is using modprobe meant by this?

   Thanks in advance,
       Sietse


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-17 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-04 15:21 Trouble with allocating memory on platform driver s.achterop
2020-04-15  9:29 ` s.achterop
2020-04-17  8:47   ` s.achterop
2020-04-17 19:30     ` Valdis Klētnieks

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).