mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "anon... anon.al" <anon.asdf@gmail.com>
To: albert.neu@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile
Date: Tue, 4 Sep 2007 18:45:23 +0200	[thread overview]
Message-ID: <379fb4870709040945ve834f9djf4772ec6166bb7ff@mail.gmail.com> (raw)
In-Reply-To: <379fb4870709040939m2430be6ci57fd73f1f9abc6ef@mail.gmail.com>

On 9/4/07, anon... anon.al <anon.asdf@gmail.com> wrote:
<snip>
> If yes: which mechanism can be used?

I was thinking about using an atomic counter in procfile_write

  proc_f = create_proc_entry(PROC_FILE_NAME, 0644, NULL);
  //...
  proc_f->write_proc = procfile_write;

int procfile_write(struct file *filp, const char *buffer, \
		   unsigned long len, void *data)
{
  //"StackXXX"
  atomic_inc(&cnt_procfile_users);

  printk(KERN_ALERT "Hi there!\n");

  atomic_dec(&cnt_procfile_users);
  wake_up_interruptible(&queue);
  return len;
}

and then in cleanup_module using:

wait_event_interruptible(queue,           \
(                                         \
 spin_lock_irqsave(&lock, flags),	  \
 cnt = atomic_read(&cnt_procfile_users),  \
 ((cnt == 0)                              \
  ? 1					  \
  : (spin_unlock_irqrestore(&lock, flags), 0))\
));
remove_proc_entry(PROC_FILE_NAME, &proc_root);
spin_unlock_irqrestore(&lock, flags);

But:
x1)
Could it happen that code is already in function procfile_write at "StackXXX"
(before atomic_inc(&cnt_procfile_users)) when the scheduler switches
to another task??
((Or is the "entering into a function, up to the function's first
statement" atomic??))

x2)
Could it happen that the scheduler switches, after
atomic_dev(&cnt_procfile_users) but before
return len??

If so, then it could happen that we're in spin_lock_irqsave, while
someone else is still using the procfile; and then this code still
fails miserably.
?

Regards -Albert

  reply	other threads:[~2007-09-04 16:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-04 16:39 anon... anon.al
2007-09-04 16:45 ` anon... anon.al [this message]
2007-09-04 16:56 ` Alexey Dobriyan
2007-09-04 17:35   ` anon... anon.al

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=379fb4870709040945ve834f9djf4772ec6166bb7ff@mail.gmail.com \
    --to=anon.asdf@gmail.com \
    --cc=albert.neu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®