Re: [PATCH 2/4] sysfs: Only take active references on attributes.

From: Eric W. Biederman
Date: Mon Feb 15 2010 - 05:11:22 EST


AmÃrico Wang <xiyou.wangcong@xxxxxxxxx> writes:

> On Mon, Feb 15, 2010 at 03:27:45PM +0800, AmÃrico Wang wrote:
>>On Thu, Feb 11, 2010 at 03:20:00PM -0800, Eric W. Biederman wrote:
>>>
>>>If we exclude directories and symlinks from the set of sysfs
>>>dirents where we need active references we are left with
>>>sysfs attributes (binary or not).
>>>
>>>- Tweak sysfs_deactivate to only do something on attributes
>>>- Move lockdep initialization into sysfs_file_add_mode to
>>> limit it to just attributes.
>>
>>Why?
>>
>>If I read your patch correctly, s_active will be useless
>>for non-attributes sysfs entries? For sysfs dir, maybe,
>>since it can only be removed by sysfs_remove_dir(),
>>but not sure about sysfs symlinks...

Yes. s_active is effectively useless for non-attribute sysfs entries.

> For sysfs dir's, opening it will not get s_active,
> since it doesn't have .open member. But it does
> put s_active when removing it. This seems buggy?

s_active needs to be taken over the lifetime of every method. For
directories a file descriptor will pin the dirent which does have a
reference to the sysfs dirent, and that ensures the sysfs entry does
not disappear.

There is one common path for removing sysfs dirents and they all call
sysfs_deactivate. The job of sysfs_deactivate is to wait until there
are no methods actively running so their dirents can have any
non-generic state cleaned up.

Neither symlinks nor directories call sysfs_get/put_active, thus
sysfs_deactivate is effectively a noop for those dirents before my
patch. After my patch sysfs_deactivate is also a noop from a lockdep
perspective.

Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/