Re: [PATCH v3] Fix rmmod/read/write races in /proc entries

From: Andrew Morton
Date: Fri Feb 09 2007 - 04:01:38 EST


On Thu, 8 Feb 2007 16:20:12 +0300 Alexey Dobriyan <adobriyan@xxxxxxxxxx> wrote:

> +again:
> spin_lock(&proc_subdir_lock);
> for (p = &parent->subdir; *p; p=&(*p)->next ) {
> if (!proc_match(len, fn, *p))
> continue;
> de = *p;
> +
> + /*
> + * Stop accepting new readers/writers. If you're dynamically
> + * allocating ->proc_fops, save a pointer somewhere.
> + */
> + spin_lock(&de->pde_unload_lock);
> + de->proc_fops = NULL;
> + /* Wait until all readers/writers are done. */
> + if (de->pde_users > 0) {
> + spin_unlock(&de->pde_unload_lock);
> + spin_unlock(&proc_subdir_lock);
> + schedule();
> + goto again;
> + }
> + spin_unlock(&de->pde_unload_lock);

aergh. This will devolve into busy-wait-until-we-expire-our-timeslice.

Would be nicer to do this with a wait_for_completion().

I guess it doesn't happen very often - if another process happens to
be in the middle or a read or write syscall to that /proc file.
-
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/