Skip to contentSkip to conversation

[2.4.13] [devfs 0.119 (20011009)] base.c: devfsd_ioctl

PATCH Kari Hurtta 2 participants 2 messages Oct 28, 2001 – Oct 29, 2001

lore
Share & tools
lore
#0 lore raw

Can you say where I have wrong?

Code on devfsd_ioctl() [base.c]:

        if (fs_info->devfsd_task == NULL)
        {
            if ( !spin_trylock (&lock) ) return -EBUSY;
            fs_info->devfsd_task = current;
            spin_unlock (&lock);

To me that spinlock looks like it is useless.
Either

	1) If it is mean that lock protects two CPUs settting
            fs_info->devfsd_task when another is set it,
	    then test about fs_info->devfsd_task == NULL
	    should be inside of locked code
or     2) this is protected with some other lock as comment
          perhaps indicates:

        /*  Ensure only one reader has access to the queue. This scheme will
            work even if the global kernel lock were to be removed, because it
            doesn't matter who gets in first, as long as only one gets it
        */
        if (fs_info->devfsd_task == NULL)
        {
            if ( !spin_trylock (&lock) ) return -EBUSY;

Should this be:

devfs/base.c renamed from devfs/base.c.old +5 -0
@@ -3227,6 +3227,11 @@
 	if (fs_info->devfsd_task == NULL)
 	{
 	    if ( !spin_trylock (&lock) ) return -EBUSY;
+	    if (fs_info->devfsd_task != NULL) {
+	         /* We lost race ... */
+	         spin_unlock (&lock);
+		 return -EBUSY;
+	    }
 	    fs_info->devfsd_task = current;
 	    spin_unlock (&lock);
 	    fs_info->devfsd_file = file;
Signature · 4 lines
          /"\                           |  Kari 
          \ /     ASCII Ribbon Campaign |    Hurtta
           X      Against HTML Mail     |
          / \                           |
#1 lore raw
Quoted 35 lines · Kari Hurtta

Can you say where I have wrong?

Code on devfsd_ioctl() [base.c]:

        if (fs_info->devfsd_task == NULL)
        {
            if ( !spin_trylock (&lock) ) return -EBUSY;
            fs_info->devfsd_task = current;
            spin_unlock (&lock);

To me that spinlock looks like it is useless.
Either

	1) If it is mean that lock protects two CPUs settting
            fs_info->devfsd_task when another is set it,
	    then test about fs_info->devfsd_task == NULL
	    should be inside of locked code
or     2) this is protected with some other lock as comment
          perhaps indicates:

        /*  Ensure only one reader has access to the queue. This scheme will
            work even if the global kernel lock were to be removed, because it
            doesn't matter who gets in first, as long as only one gets it
        */
        if (fs_info->devfsd_task == NULL)
        {
            if ( !spin_trylock (&lock) ) return -EBUSY;

Should this be:

devfs/base.c renamed from devfs/base.c.old +0 -0
@@ -3227,6 +3227,11 @@
 	if (fs_info->devfsd_task == NULL)

devfs/base.c line 3237

Quoted 10 lines
devfs/base.c renamed from devfs/base.c.old +5 -0
 	{
 	    if ( !spin_trylock (&lock) ) return -EBUSY;
+	    if (fs_info->devfsd_task != NULL) {
+	         /* We lost race ... */
+	         spin_unlock (&lock);
+		 return -EBUSY;
+	    }
 	    fs_info->devfsd_task = current;
 	    spin_unlock (&lock);
 	    fs_info->devfsd_file = file;

Damn! You're right. I broke that when I simplified the anti-race code back in June and replaced the #ifdef CONFIG_SMP bits with plain spinlocks. Unfortunately I didn't put back in a critcal line. Cut-and-paste error without the paste :-(

OK, I've updated my both my trees. I'll feed this to Linus in my next release.

				Regards,

					Richard....
Permanent: [email protected]
Current:   [email protected]