Page MenuHomeFreeBSD

mmc_sim: fix setting of the mutex name
ClosedPublic

Authored by avg on Dec 13 2021, 11:45 AM.
Tags
None
Referenced Files
F102029843: D33412.diff
Wed, Nov 6, 5:33 PM
Unknown Object (File)
Wed, Oct 23, 9:07 AM
Unknown Object (File)
Wed, Oct 16, 9:16 PM
Unknown Object (File)
Sep 16 2024, 4:25 PM
Unknown Object (File)
Sep 15 2024, 8:44 PM
Unknown Object (File)
Sep 10 2024, 10:25 PM
Unknown Object (File)
Sep 4 2024, 5:37 PM
Unknown Object (File)
Sep 2 2024, 6:26 PM
Subscribers

Details

Summary

To quote the manual:
The pointer passed in as name and type is saved rather than the data
it points to. The data pointed to must remain stable until the mutex
is destroyed.

It seems that the type is actually copied, but the name is stored as
a pointer indeed.
mmc_cam_sim_alloc used a name stored on stack.
So, a corrupt mutex name would be reported.
For example:

lock order reversal: (sleepable after non-sleepable)
1st 0xd7285b20 <8A><C0><C0>P@<C1><D0>P@<C1>^D^A (aw_mmc_sim, sleep mutex) @ /usr/devel/git/orange/sys/cam/cam_xpt.c:2804

This change moves the name to struct mmc_sim.
Also, that name is used as the sim name as well.
Unused mtx_name variable is removed too.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

avg requested review of this revision.Dec 13 2021, 11:45 AM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 13 2021, 11:52 AM
This revision was automatically updated to reflect the committed changes.
manu accepted this revision.
This revision is now accepted and ready to land.Dec 13 2021, 12:25 PM

In case you re-open it, I'd accept it. Scrolling through it looks sane. Probably wasn't worth backing it out.

I think the only question I'd have is-- do we actually need 64 characters for a mutex name and the SIM name? I think in a lot of places we used 16 for the mutex; probably also because some tools will truncate when printing?

In D33412#755309, @bz wrote:

I think the only question I'd have is-- do we actually need 64 characters for a mutex name and the SIM name? I think in a lot of places we used 16 for the mutex; probably also because some tools will truncate when printing?

Good question and I am not sure.
I kept what the original code used, but that was on the stack.
I think that 16 should be enough.
I wonder if we have any constants for conventional mutex and SIM name lengths.

This revision was automatically updated to reflect the committed changes.