iMX SEMA4 Linux driver improvements and fixes patch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iMX SEMA4 Linux driver improvements and fixes patch

1,323 Views
savaj
Contributor II

Hi,

 

I am not sure whether the pull-request mechanism for linux-imx on github works, so I am posting the patch here. If required, I can also open a PR on github.

 

For our purposes we tried using the SEMA4 driver found in linux-imx, but the driver was not serving our needs, and I believe it was essentially broken, both by design and by implementation.

Identified problems:

- if a remote core was holding a gate, and the driver attempted to lock the gate (and of course failed), there would be no ISR when the remote processor releases the gate. This bug is a consequence of OR-ing the SEMA4_Gaten register instead of a direct value write: driver would try to write 0b11 instead, which is treated as a "no-op".

- Using a spinlock in imx_sema4_mutex_lock can lead to a kernel bug if a caller is not aware that this call is basically converting the context into an atomic one. It also doesn't make sense to lock a global flag when a single gate is being locked.

- The lock/unlock dance in IRQ, followed by a wake_up call, is hard to follow. By the time the caller is woken up and has taken control there are no guarantees we have the gate locked. While this may be okay, I don't think it is a good design to have the caller do trylock or lock again when woken up. Instead, the mutex driver should behave as a standard mutex driver.

 

This patch ensures that only one user can hold a gate, and it improves IRQ handling from SEMA4 module. There is only a simple lock in the ISR,  The code is simplified and made more robust.

 

Please let me know whether the change is acceptable and whether I need to submit it as a pull request on your github repo.

 

Cheers,

Sava

Labels (2)
0 Kudos
Reply
6 Replies

1,103 Views
savaj
Contributor II

Hi @Manuel_Salas ,

 

Are there any updates on this issue, should I turn to github and open a PR there?

 

Thanks,

Sava

0 Kudos
Reply

1,082 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @savaj 

I hope you are doing very well.

 

I just received an update from the team:

 

Please confirm which branch the patch was based on and send the patch to nxp imx maintainer team to review. The email is as below.

NXP Linux Team <linux-imx@nxp.com> (reviewer:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE)

 

Best regards,

Salas.

0 Kudos
Reply

929 Views
savaj
Contributor II

Hi @Manuel_Salas ,

 

Hope you're doing well.

I sent the patch to the specified email address couple of weeks ago, but got no feedback since then.

Is it expected for the process to take a bit longer or did the email somehow got missed?

 

Thanks,

Sava

0 Kudos
Reply

589 Views
savaj
Contributor II

Hi @Manuel_Salas ,

 

I am sorry to having to bug you, but at this point I'm a bit confused with the complete lack of response by NXP, and total silence that I'm experiencing for weeks now. I'm wondering what's the reason for this silence.

Of course, I tried escalating the issue using the built-in feature of this forum, sending an inquiry to the provided email address of the NXP Linux team... 

 

If you could at least share that, I'd appreciate it.

Thank you and best regards,

Sava

0 Kudos
Reply

1,025 Views
savaj
Contributor II

Hello @Manuel_Salas 

 

Sorry for a bit of the delay. 

The kernel branch is lf-6.12.y (yocto walnascar).

I'll send the patch to the specified address.

 

Thanks,

Sava

1,280 Views
Manuel_Salas
NXP TechSupport
NXP TechSupport

Hello @savaj 

I hope you are doing very well.

Thank you very much for your contribution.

 

I asked internally about the process to follow for review the patch. I will let you know any update.

 

Best regards,

Salas.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2296704%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EiMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2296704%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EI%20am%20not%20sure%20whether%20the%20pull-request%20mechanism%20for%20linux-imx%20on%20github%20works%2C%20so%20I%20am%20posting%20the%20patch%20here.%20If%20required%2C%20I%20can%20also%20open%20a%20PR%20on%20github.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EFor%20our%20purposes%20we%20tried%20using%20the%20SEMA4%20driver%20found%20in%20linux-imx%2C%20but%20the%20driver%20was%20not%20serving%20our%20needs%2C%20and%20I%20believe%20it%20was%20essentially%20broken%2C%20both%20by%20design%20and%20by%20implementation.%3C%2FP%3E%3CP%3EIdentified%20problems%3A%3C%2FP%3E%3CP%3E-%20if%20a%20remote%20core%20was%20holding%20a%20gate%2C%20and%20the%20driver%20attempted%20to%20lock%20the%20gate%20(and%20of%20course%20failed)%2C%20there%20would%20be%20no%20ISR%20when%20the%20remote%20processor%20releases%20the%20gate.%20This%20bug%20is%20a%20consequence%20of%20OR-ing%20the%20SEMA4_Gaten%20register%20instead%20of%20a%20direct%20value%20write%3A%20driver%20would%20try%20to%20write%200b11%20instead%2C%20which%20is%20treated%20as%20a%20%22no-op%22.%3C%2FP%3E%3CP%3E-%20Using%20a%20spinlock%20in%20imx_sema4_mutex_lock%20can%20lead%20to%20a%20kernel%20bug%20if%20a%20caller%20is%20not%20aware%20that%20this%20call%20is%20basically%20converting%20the%20context%20into%20an%20atomic%20one.%20It%20also%20doesn't%20make%20sense%20to%20lock%20a%20global%20flag%20when%20a%20single%20gate%20is%20being%20locked.%3C%2FP%3E%3CP%3E-%20The%20lock%2Funlock%20dance%20in%20IRQ%2C%20followed%20by%20a%20wake_up%20call%2C%20is%20hard%20to%20follow.%20By%20the%20time%20the%20caller%20is%20woken%20up%20and%20has%20taken%20control%20there%20are%20no%20guarantees%20we%20have%20the%20gate%20locked.%20While%20this%20may%20be%20okay%2C%20I%20don't%20think%20it%20is%20a%20good%20design%20to%20have%20the%20caller%20do%20trylock%20or%20lock%20again%20when%20woken%20up.%20Instead%2C%20the%20mutex%20driver%20should%20behave%20as%20a%20standard%20mutex%20driver.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThis%20patch%20ensures%20that%20only%20one%20user%20can%20hold%20a%20gate%2C%20and%20it%20improves%20IRQ%20handling%20from%20SEMA4%20module.%20There%20is%20only%20a%20simple%20lock%20in%20the%20ISR%2C%26nbsp%3B%20The%20code%20is%20simplified%20and%20made%20more%20robust.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EPlease%20let%20me%20know%20whether%20the%20change%20is%20acceptable%20and%20whether%20I%20need%20to%20submit%20it%20as%20a%20pull%20request%20on%20your%20github%20repo.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ECheers%2C%3C%2FP%3E%3CP%3ESava%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2296704%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESuspected%20Software%20Defect%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2296821%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2296821%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F225700%22%20target%3D%22_blank%22%3E%40savaj%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20you%20are%20doing%20very%20well.%3C%2FP%3E%0A%3CP%3EThank%20you%20very%20much%20for%20your%20contribution.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EI%20asked%20internally%20about%20the%20process%20to%20follow%20for%20review%20the%20patch.%20I%20will%20let%20you%20know%20any%20update.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBest%20regards%2C%3C%2FP%3E%0A%3CP%3ESalas.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2302176%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2302176%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F203368%22%20target%3D%22_blank%22%3E%40Manuel_Salas%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EAre%20there%20any%20updates%20on%20this%20issue%2C%20should%20I%20turn%20to%20github%20and%20open%20a%20PR%20there%3F%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3ESava%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2303167%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2303167%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F225700%22%20target%3D%22_blank%22%3E%40savaj%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20hope%20you%20are%20doing%20very%20well.%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EI%20just%20received%20an%20update%20from%20the%20team%3A%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EPlease%20confirm%20which%20branch%20the%20patch%20was%20based%20on%20and%20send%20the%20patch%20to%20nxp%20imx%20maintainer%20team%20to%20review.%20The%20email%20is%20as%20below.%3C%2FP%3E%0A%3CP%3ENXP%20Linux%20Team%20%3CLINUX-IMX%3E%20(reviewer%3AARM%2FFREESCALE%20IMX%20%2F%20MXC%20ARM%20ARCHITECTURE)%3C%2FLINUX-IMX%3E%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EBest%20regards%2C%3C%2FP%3E%0A%3CP%3ESalas.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2314209%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2314209%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F203368%22%20target%3D%22_blank%22%3E%40Manuel_Salas%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESorry%20for%20a%20bit%20of%20the%20delay.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20kernel%20branch%20is%26nbsp%3Blf-6.12.y%20(yocto%20walnascar).%3C%2FP%3E%3CP%3EI'll%20send%20the%20patch%20to%20the%20specified%20address.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3ESava%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2321027%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2321027%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F203368%22%20target%3D%22_blank%22%3E%40Manuel_Salas%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EHope%20you're%20doing%20well.%3C%2FP%3E%3CP%3EI%20sent%20the%20patch%20to%20the%20specified%20email%20address%20couple%20of%20weeks%20ago%2C%20but%20got%20no%20feedback%20since%20then.%3C%2FP%3E%3CP%3EIs%20it%20expected%20for%20the%20process%20to%20take%20a%20bit%20longer%20or%20did%20the%20email%20somehow%20got%20missed%3F%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3ESava%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2342613%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20iMX%20SEMA4%20Linux%20driver%20improvements%20and%20fixes%20patch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2342613%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F203368%22%20target%3D%22_blank%22%3E%40Manuel_Salas%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EI%20am%20sorry%20to%20having%20to%20bug%20you%2C%20but%20at%20this%20point%20I'm%20a%20bit%20confused%20with%20the%20complete%20lack%20of%20response%20by%20NXP%2C%20and%20total%20silence%20that%20I'm%20experiencing%20for%20weeks%20now.%20I'm%20wondering%20what's%20the%20reason%20for%20this%20silence.%3C%2FP%3E%3CP%3EOf%20course%2C%20I%20tried%20escalating%20the%20issue%20using%20the%20built-in%20feature%20of%20this%20forum%2C%20sending%20an%20inquiry%20to%20the%20provided%20email%20address%20of%20the%20NXP%20Linux%20team...%26nbsp%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20could%20at%20least%20share%20that%2C%20I'd%20appreciate%20it.%3C%2FP%3E%3CP%3EThank%20you%20and%20best%20regards%2C%3C%2FP%3E%3CP%3ESava%3C%2FP%3E%3C%2FLINGO-BODY%3E