Endpoint Mode: Raising legacy interrupt causes BUG: Scheduling while Atomic

Endpoint: Xavier AGX on custom carrier 5.0.2/35.1
Root: generic x86 pc on linux 5.10

I’m working on a kernel module to use the endpoint functionality. I’m trying to raise a legacy interrupt on the endpoint but it runs into a BUG: scheduling while atomic.

I don’t believe I am entering atomic context within any of my code. This is a very basic “hello world” level module. I also don’t use any spinlocks/mutexes within my code. At least not directly. I know the EPC has a mutex on any ops. Not sure if that matters. Is there another source of entering atomic context that is not obvious?

I know I can modify tegra_pcie_ep_raise_irq and replace usleep_range with udelay. But I’m trying to avoid something like that.

pci_epc_raise_irq(epc, epf->func_no, PCI_EPC_IRQ_LEGACY, 0);
[  278.572774] BUG: scheduling while atomic: kworker/0:2H/597/0x00000003
[  278.573045] Modules linked in: ac_epf_test(OE) fuse lzo_rle lzo_compress zram aes_ce_ccm realtek snd_soc_tegra186_asrc iwlmvm snd_soc_tegra186_dspk snd_soc_tegra210_ope snd_soc_tegra186_arad snd_soc_tegra210_iqc mac80211 snd_soc_tegra210_mvc snd_soc_tegra210_admaif snd_soc_tegra210_afc snd_soc_tegra210_dmic snd_soc_tegra210_amx snd_soc_tegra210_adx snd_soc_tegra_pcm snd_soc_tegra210_mixer snd_soc_tegra210_i2s snd_soc_tegra210_sfc aes_ce_blk crypto_simd cryptd aes_ce_cipher ghash_ce sha2_ce sha256_arm64 sha1_ce snd_soc_spdif_tx snd_soc_tegra_machine_driver binfmt_misc max77620_thermal nct1008 snd_soc_rt5659 snd_soc_tegra210_adsp snd_soc_rl6231 snd_soc_tegra_utils snd_soc_simple_card_utils bluedroid_pm snd_soc_tegra210_ahub iwlwifi tegra_bpmp_thermal nvadsp userspace_alert tegra210_adma snd_hda_codec_hdmi cfg80211 snd_hda_tegra spi_tegra114 snd_hda_codec snd_hda_core loop ina3221 pwm_fan nvgpu nvmap ramoops reed_solomon ip_tables x_tables
[  278.574315] CPU: 0 PID: 597 Comm: kworker/0:2H Tainted: G           OE     5.10.104-tegra #1
[  278.574323] Hardware name: Unknown Jetson-AGX/Jetson-AGX, BIOS 1.0-d7fb19b 08/10/2022
[  278.574387] Workqueue: kactest ac_epf_test_cmd_handler [ac_epf_test]
[  278.574402] Call trace:
[  278.574453]  dump_backtrace+0x0/0x1d0
[  278.574465]  show_stack+0x30/0x40
[  278.574490]  dump_stack+0xd8/0x138
[  278.574510]  __schedule_bug+0x78/0x90
[  278.574530]  __schedule+0x844/0x910
[  278.574538]  schedule+0x78/0x110
[  278.574553]  schedule_hrtimeout_range_clock+0xa0/0x120
[  278.574562]  schedule_hrtimeout_range+0x3c/0x50
[  278.574570]  usleep_range+0x6c/0xa0
[  278.574600]  tegra_pcie_ep_raise_irq+0x84/0x100
[  278.574609]  dw_pcie_ep_raise_irq+0x4c/0x70
[  278.574621]  pci_epc_raise_irq+0x84/0xd0
[  278.574631]  ac_epf_test_cmd_handler+0x110/0x13c [ac_epf_test]
[  278.574654]  process_one_work+0x1c4/0x4a0
[  278.574662]  worker_thread+0x54/0x430
[  278.574692]  kthread+0x148/0x170
[  278.574702]  ret_from_fork+0x10/0x24
[  278.574813] BUG: workqueue leaked lock or atomic: kworker/0:2H/0xfffffffe/597
                    last function: ac_epf_test_cmd_handler [ac_epf_test]
[  278.575182] CPU: 0 PID: 597 Comm: kworker/0:2H Tainted: G        W  OE     5.10.104-tegra #1
[  278.575195] Hardware name: Unknown Jetson-AGX/Jetson-AGX, BIOS 1.0-d7fb19b 08/10/2022
[  278.575213] Workqueue: kactest ac_epf_test_cmd_handler [ac_epf_test]
[  278.575230] Call trace:
[  278.575242]  dump_backtrace+0x0/0x1d0
[  278.575252]  show_stack+0x30/0x40
[  278.575300]  dump_stack+0xd8/0x138
[  278.575309]  process_one_work+0x498/0x4a0
[  278.575317]  worker_thread+0x54/0x430
[  278.575324]  kthread+0x148/0x170
[  278.575332]  ret_from_fork+0x10/0x24
[  278.575346] BUG: scheduling while atomic: kworker/0:2H/597/0xffffffff
[  278.575507] Modules linked in: ac_epf_test(OE) fuse lzo_rle lzo_compress zram aes_ce_ccm realtek snd_soc_tegra186_asrc iwlmvm snd_soc_tegra186_dspk snd_soc_tegra210_ope snd_soc_tegra186_arad snd_soc_tegra210_iqc mac80211 snd_soc_tegra210_mvc snd_soc_tegra210_admaif snd_soc_tegra210_afc snd_soc_tegra210_dmic snd_soc_tegra210_amx snd_soc_tegra210_adx snd_soc_tegra_pcm snd_soc_tegra210_mixer snd_soc_tegra210_i2s snd_soc_tegra210_sfc aes_ce_blk crypto_simd cryptd aes_ce_cipher ghash_ce sha2_ce sha256_arm64 sha1_ce snd_soc_spdif_tx snd_soc_tegra_machine_driver binfmt_misc max77620_thermal nct1008 snd_soc_rt5659 snd_soc_tegra210_adsp snd_soc_rl6231 snd_soc_tegra_utils snd_soc_simple_card_utils bluedroid_pm snd_soc_tegra210_ahub iwlwifi tegra_bpmp_thermal nvadsp userspace_alert tegra210_adma snd_hda_codec_hdmi cfg80211 snd_hda_tegra spi_tegra114 snd_hda_codec snd_hda_core loop ina3221 pwm_fan nvgpu nvmap ramoops reed_solomon ip_tables x_tables
[  278.575934] CPU: 0 PID: 597 Comm: kworker/0:2H Tainted: G        W  OE     5.10.104-tegra #1
[  278.575940] Hardware name: Unknown Jetson-AGX/Jetson-AGX, BIOS 1.0-d7fb19b 08/10/2022
[  278.576087] Workqueue:  0x0 (kactest)
[  278.576103] Call trace:
[  278.576115]  dump_backtrace+0x0/0x1d0
[  278.576125]  show_stack+0x30/0x40
[  278.576132]  dump_stack+0xd8/0x138
[  278.576140]  __schedule_bug+0x78/0x90
[  278.576149]  __schedule+0x844/0x910
[  278.576156]  schedule+0x78/0x110
[  278.576164]  worker_thread+0xc0/0x430
[  278.576171]  kthread+0x148/0x170
[  278.576178]  ret_from_fork+0x10/0x24

Sorry for the late response, have you managed to get issue resolved or still need the support? Thanks

I still need support if you have any suggestions.

In the mean time I recompiled the kernel and changed the sleep to a delay within tegra_pcie_ep_raise_irq