Re: [PATCH] sysfs: move assignment to be under lock insysfs_remove_dir()

From: Tejun Heo
Date: Wed Oct 30 2013 - 09:28:40 EST


Hello,

On Tue, Oct 29, 2013 at 10:29:43PM -0700, Eric W. Biederman wrote:
> I never actually looked deeply into it, and I was working from several
> year old memory and a quick skim of the patch when I asked the question.
>
> The protection we have previous to this patch is that syfs_remove_dir is
> only sane to call once.
>
> Which makes the code that does:
> if (!dir_sd)
> return;
> in __sysfs_remove_dir very suspicious. I expect we want a
> WARN_ON(!dir_sd);

It was always like that, probably in the same spirit as kfree() taking
NULL so that it can be easier, for example, in init failure paths.

> But the entire directory removal process and working on sysfs stopped
> being fun before I managed to get that cleaned up. And unless I missed
> something go by Tejun is going to go generalize this thing before this
> bit gets cleaned up. Sigh.

I kept the same behavior for kernfs_remove(). I don't think it's
something we explicitly want to clean up tho? It's an acceptable
behavior.

> On an equally bizarre note. I don't understand why we have a separate
> spinlock there. Looks... Sigh. We use a different lock from
> everything as a premature optimization so that sysfs_remove_dir could be
> modified to just take a sysfs_dirent, and all of the kobject handling
> could be removed.
>
> Sigh. It was never in my way and while I was working on the code that
> there was a good locking reason for doing that silly thing.

Umm... you got it completely wrong. It's there to address a race
condition between removal and symlinking and has nothing to do with
optimization.

The current odd looking locking on removal side serves a purpose in
making it clear that it isn't synchronizing concurrent removal calls.
Maybe we should rename the lock to sysfs_symlink_target_lock and add
fat comments on both sides? Or we can make it a mutex and exclude the
entire removal and symlinking, which would probably easier to follow.

Thanks.

--
tejun
--
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/