Skip to contentSkip to conversation

gpss: core: no waiters left behind on deregister

PATCH In review Oliver Neukum 3 participants 6 messages Jun 24, 2019 – Jul 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpss: core: no waiters left behind on deregister

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
 drivers/gnss/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gnss/core.c +1 -1
index e6f94501cb28..0d13bd2cefd5 100644
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
 	down_write(&gdev->rwsem);
 	gdev->disconnected = true;
 	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);
 		gdev->ops->close(gdev);
 	}
 	up_write(&gdev->rwsem);
Signature · 1 line
2.16.4
maintainer
#1 lore raw
Quoted 13 lines · Oliver Neukum

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
 drivers/gnss/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gnss/core.c +0 -0
index e6f94501cb28..0d13bd2cefd5 100644

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 306

Quoted 5 lines
drivers/gnss/core.c +1 -1
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
 	down_write(&gdev->rwsem);
 	gdev->disconnected = true;
 	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);

GNSS core doesn't have any exclusive waiters, so no need to use use the exclusive wake-up (all) interface.

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 309

Quoted 3 lines
drivers/gnss/core.c +0 -0
 		gdev->ops->close(gdev);
 	}
 	up_write(&gdev->rwsem);

Thanks,
Johan

#2 lore raw

Am Dienstag, den 25.06.2019, 09:04 +0200 schrieb Johan Hovold:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
 drivers/gnss/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 306

Quoted 10 lines
drivers/gnss/core.c +1 -1
index e6f94501cb28..0d13bd2cefd5 100644
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
 	down_write(&gdev->rwsem);
 	gdev->disconnected = true;
 	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);

GNSS core doesn't have any exclusive waiters, so no need to use use the exclusive wake-up (all) interface.

Well, yes, but that is the problem. In gnss_read() you drop the lock:

        mutex_lock(&gdev->read_mutex);

        while (kfifo_is_empty(&gdev->read_fifo)) {
                mutex_unlock(&gdev->read_mutex);

                if (gdev->disconnected)
                        return 0;

                if (file->f_flags & O_NONBLOCK)
                        return -EAGAIN;

That means that an arbitrary number of tasks can get here.

                ret = wait_event_interruptible(gdev->read_queue,
                                gdev->disconnected ||
                                !kfifo_is_empty(&gdev->read_fifo));

Meaning that an arbitrary number can be sleeping here. Yet in gnss_deregister_device() you use a simple wake_up:

void gnss_deregister_device(struct gnss_device *gdev)

{

        down_write(&gdev->rwsem);
        gdev->disconnected = true;
        if (gdev->count) {
                wake_up_interruptible(&gdev->read_queue);

wake_up_interruptible() will wake up one waiting task. But after that the device is gone. There will be no further events. The other tasks will sleep forever.

Regards
Oliver

maintainer
#3 lore raw
Quoted 26 lines · Oliver Neukum

Am Dienstag, den 25.06.2019, 09:04 +0200 schrieb Johan Hovold:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
 drivers/gnss/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 306

Quoted 10 lines
drivers/gnss/core.c +1 -1
index e6f94501cb28..0d13bd2cefd5 100644
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
 	down_write(&gdev->rwsem);
 	gdev->disconnected = true;
 	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);

GNSS core doesn't have any exclusive waiters, so no need to use use the exclusive wake-up (all) interface.

Well, yes, but that is the problem. In gnss_read() you drop the lock:

Quoted 7 lines

That means that an arbitrary number of tasks can get here.

                ret = wait_event_interruptible(gdev->read_queue,
                                gdev->disconnected ||
                                !kfifo_is_empty(&gdev->read_fifo));

Meaning that an arbitrary number can be sleeping here.

I understand wait you're getting at, but I think your mistaken regarding exclusive wait. Note that wait_event_interruptible() uses nonexclusive wait.

Quoted 12 lines

Yet in gnss_deregister_device() you use a simple wake_up:

void gnss_deregister_device(struct gnss_device *gdev)

{

        down_write(&gdev->rwsem);
        gdev->disconnected = true;
        if (gdev->count) {
                wake_up_interruptible(&gdev->read_queue);
Quoted 3 lines

wake_up_interruptible() will wake up one waiting task. But after that the device is gone. There will be no further events. The other tasks will sleep forever.

No, wake_up_interruptible() will wake up all nonexclusive waiters, which is all we care about here.

Johan

#4 lore raw

Am Mittwoch, den 26.06.2019, 13:41 +0200 schrieb Johan Hovold:

Quoted 50 lines · Oliver Neukum
Quoted 24 lines

Am Dienstag, den 25.06.2019, 09:04 +0200 schrieb Johan Hovold:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
 drivers/gnss/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 306

Quoted 10 lines
drivers/gnss/core.c +1 -1
index e6f94501cb28..0d13bd2cefd5 100644
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
 	down_write(&gdev->rwsem);
 	gdev->disconnected = true;
 	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);

GNSS core doesn't have any exclusive waiters, so no need to use use the exclusive wake-up (all) interface.

Quoted 8 lines

Well, yes, but that is the problem. In gnss_read() you drop the lock:
That means that an arbitrary number of tasks can get here.

                ret = wait_event_interruptible(gdev->read_queue,
                                gdev->disconnected ||
                                !kfifo_is_empty(&gdev->read_fifo));

Meaning that an arbitrary number can be sleeping here.

I understand wait you're getting at, but I think your mistaken regarding exclusive wait. Note that wait_event_interruptible() uses nonexclusive wait.

Quoted 12 lines

Yet in gnss_deregister_device() you use a simple wake_up:

void gnss_deregister_device(struct gnss_device *gdev)

{

        down_write(&gdev->rwsem);
        gdev->disconnected = true;
        if (gdev->count) {
                wake_up_interruptible(&gdev->read_queue);
Quoted 6 lines
Quoted 3 lines

wake_up_interruptible() will wake up one waiting task. But after that the device is gone. There will be no further events. The other tasks will sleep forever.

No, wake_up_interruptible() will wake up all nonexclusive waiters, which is all we care about here.

You are right and tracing this is hard.

Regards & Sorry
Oliver

#5 lore raw
In reply to Oliver Neukum

Hello!

The subject has gpss ISO gnss. You hardly meant the General Purpose
System Simulation. :-)

Quoted 13 lines · Oliver Neukum

If you deregister a device you need to wake up all waiters as there will be no further wakeups.

---
  drivers/gnss/core.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gnss/core.c +0 -0
index e6f94501cb28..0d13bd2cefd5 100644

drivers/gnss/core.c void gnss_deregister_device(struct gnss_device *gdev) · line 309

Quoted 8 lines
drivers/gnss/core.c +1 -1
@@ -303,7 +303,7 @@ void gnss_deregister_device(struct gnss_device *gdev)
  	down_write(&gdev->rwsem);
  	gdev->disconnected = true;
  	if (gdev->count) {
-		wake_up_interruptible(&gdev->read_queue);
+		wake_up_interruptible_all(&gdev->read_queue);
  		gdev->ops->close(gdev);
  	}
  	up_write(&gdev->rwsem);

MBR, Sergei