Skip to contentSkip to conversation

Mailbox: sleeping function called from invalid context fix

PATCH Superseded Guzman Lugo, Fernando 3 participants 6 messages Feb 13, 2010 – Feb 18, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 5/6 Mailbox: sleeping function called from invalid context fix

Quoted 1 line

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00 2001

From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid context fix

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

---
 arch/arm/plat-omap/mailbox.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)
arch/arm/plat-omap/mailbox.c +15 -15
index 8136ee3..d8bfa45 100644
@@ -29,7 +29,7 @@
 #include <plat/mailbox.h>
 
 static struct omap_mbox *mboxes;
-static DEFINE_RWLOCK(mboxes_lock);
+static DECLARE_RWSEM(mboxes_sem);
 
 static int mbox_configured;
 
@@ -248,16 +248,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 	struct omap_mbox_queue *mq;
 
 	if (likely(mbox->ops->startup)) {
-		write_lock(&mboxes_lock);
+		down_write(&mboxes_sem);
 		if (!mbox_configured)
 			ret = mbox->ops->startup(mbox);
 
 		if (unlikely(ret)) {
-			write_unlock(&mboxes_lock);
+			up_write(&mboxes_sem);
 			return ret;
 		}
 		mbox_configured++;
-		write_unlock(&mboxes_lock);
+		up_write(&mboxes_sem);
 	}
 
 	ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -304,12 +304,12 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
 	mbox_queue_free(mbox->rxq);
 
 	if (unlikely(mbox->ops->shutdown)) {
-		write_lock(&mboxes_lock);
+		down_write(&mboxes_sem);
 		if (mbox_configured > 0)
 			mbox_configured--;
 		if (!mbox_configured)
 			mbox->ops->shutdown(mbox);
-		write_unlock(&mboxes_lock);
+		up_write(&mboxes_sem);
 	}
 }
 
@@ -330,14 +330,14 @@ struct omap_mbox *omap_mbox_get(const char *name)
 	struct omap_mbox *mbox;
 	int ret;
 
-	read_lock(&mboxes_lock);
+	down_read(&mboxes_sem);
 	mbox = *(find_mboxes(name));
 	if (mbox == NULL) {
-		read_unlock(&mboxes_lock);
+		up_read(&mboxes_sem);
 		return ERR_PTR(-ENOENT);
 	}
 
-	read_unlock(&mboxes_lock);
+	up_read(&mboxes_sem);
 
 	ret = omap_mbox_startup(mbox);
 	if (ret)
@@ -363,15 +363,15 @@ int omap_mbox_register(struct device *parent, struct omap_mbox *mbox)
 	if (mbox->next)
 		return -EBUSY;
 
-	write_lock(&mboxes_lock);
+	down_write(&mboxes_sem);
 	tmp = find_mboxes(mbox->name);
 	if (*tmp) {
 		ret = -EBUSY;
-		write_unlock(&mboxes_lock);
+		up_write(&mboxes_sem);
 		goto err_find;
 	}
 	*tmp = mbox;
-	write_unlock(&mboxes_lock);
+	up_write(&mboxes_sem);
 
 	return 0;
 
@@ -384,18 +384,18 @@ int omap_mbox_unregister(struct omap_mbox *mbox)
 {
 	struct omap_mbox **tmp;
 
-	write_lock(&mboxes_lock);
+	down_write(&mboxes_sem);
 	tmp = &mboxes;
 	while (*tmp) {
 		if (mbox == *tmp) {
 			*tmp = mbox->next;
 			mbox->next = NULL;
-			write_unlock(&mboxes_lock);
+			up_write(&mboxes_sem);
 			return 0;
 		}
 		tmp = &(*tmp)->next;
 	}
-	write_unlock(&mboxes_lock);
+	up_write(&mboxes_sem);
 
 	return -EINVAL;
 }
Signature · 1 line
1.6.0.4
#1 lore raw

Hi Fernando,

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Sat, 13 Feb 2010 02:42:16 +0100

Quoted 10 lines

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00 2001
From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid context fix

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

"mboxes_lock" is used to maintain the global list of mailbox instances, which belong to a single mailbox H/W module, but they are logical channels from S/W perspective. Both "->ops->startup()" and "->ops->shutdown()" are being executed against the above single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes, which are (un)registered with "omap_mbox_(un)register()". IOW, a mbox instance can be registered at anytime(before/after) H/W initialization. This H/W initialization is taken care of by "mbox_configured" variable. So I might think that the right solution is to introduce a new mutex lock __just for__ h/w configuration as below:

Modified arch/arm/plat-omap/mailbox.c

arch/arm/plat-omap/mailbox.c +6 -5
index 8e90633..19530de 100644
@@ -32,6 +32,7 @@ static struct omap_mbox *mboxes;
 static DEFINE_RWLOCK(mboxes_lock);
 
 static int mbox_configured;
+static DEFINE_MUTEX(mbox_configured_lock);
 
 /* Mailbox FIFO handle functions */
 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@@ -247,16 +248,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 	struct omap_mbox_queue *mq;
 
 	if (likely(mbox->ops->startup)) {
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (!mbox_configured)
 			ret = mbox->ops->startup(mbox);
 
 		if (unlikely(ret)) {
-			write_unlock(&mboxes_lock);
+			mutex_unlock(&mbox_configured_lock);
 			return ret;
 		}
 		mbox_configured++;
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 
 	ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -302,12 +303,12 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
 	free_irq(mbox->irq, mbox);
 
 	if (unlikely(mbox->ops->shutdown)) {
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (mbox_configured > 0)
 			mbox_configured--;
 		if (!mbox_configured)
 			mbox->ops->shutdown(mbox);
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 }
#2 lore raw

Hi,

Quoted 27 lines

-----Original Message-----
From: Hiroshi DOYU [mailto:[email protected]]
Sent: Monday, February 15, 2010 7:49 AM
To: Guzman Lugo, Fernando
Cc: [email protected]
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix

Hi Fernando,

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Sat, 13 Feb 2010 02:42:16 +0100

Quoted 4 lines

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00 2001
From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid context

fix

Quoted 6 lines

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

Quoted 6 lines

"mboxes_lock" is used to maintain the global list of mailbox instances, which belong to a single mailbox H/W module, but they are logical channels from S/W perspective. Both "->ops->startup()" and "->ops->shutdown()" are being executed against the above single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes, which are (un)registered with

Yes, they are independent of each other, and can be executed at the same time. I am agreed with your patch; that should be the right solution, so you can drop my patch.

Thanks and regards,
Fernando.

Quoted 53 lines

"omap_mbox_(un)register()". IOW, a mbox instance can be registered at anytime(before/after) H/W initialization. This H/W initialization is taken care of by "mbox_configured" variable. So I might think that the right solution is to introduce a new mutex lock __just for__ h/w configuration as below:

Modified arch/arm/plat-omap/mailbox.c

arch/arm/plat-omap/mailbox.c +6 -5
index 8e90633..19530de 100644
@@ -32,6 +32,7 @@ static struct omap_mbox *mboxes;
 static DEFINE_RWLOCK(mboxes_lock);
 
 static int mbox_configured;
+static DEFINE_MUTEX(mbox_configured_lock);
 
 /* Mailbox FIFO handle functions */
 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@@ -247,16 +248,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 	struct omap_mbox_queue *mq;
 
 	if (likely(mbox->ops->startup)) {
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (!mbox_configured)
 			ret = mbox->ops->startup(mbox);
 
 		if (unlikely(ret)) {
-			write_unlock(&mboxes_lock);
+			mutex_unlock(&mbox_configured_lock);
 			return ret;
 		}
 		mbox_configured++;
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 
 	ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -302,12 +303,12 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
 	free_irq(mbox->irq, mbox);
 
 	if (unlikely(mbox->ops->shutdown)) {
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (mbox_configured > 0)
 			mbox_configured--;
 		if (!mbox_configured)
 			mbox->ops->shutdown(mbox);
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 }
#3 lore raw
Quoted 30 lines · Guzman Lugo, Fernando

Hi,

Quoted 27 lines

-----Original Message-----
From: Hiroshi DOYU [mailto:[email protected]]
Sent: Monday, February 15, 2010 7:49 AM
To: Guzman Lugo, Fernando
Cc: [email protected]
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix

Hi Fernando,

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Sat, 13 Feb 2010 02:42:16 +0100

Quoted 4 lines

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00 2001
From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid context

fix

Quoted 6 lines

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

Quoted 8 lines
Quoted 6 lines

"mboxes_lock" is used to maintain the global list of mailbox instances, which belong to a single mailbox H/W module, but they are logical channels from S/W perspective. Both "->ops->startup()" and "->ops->shutdown()" are being executed against the above single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes, which are (un)registered with

Yes, they are independent of each other, and can be executed at the same time. I am agreed with your patch; that should be the right solution, so you can drop my patch.

Hiroshi & Fernando, if you want me to merge this series, please post it one more time with right patches and ack's from Hiroshi. Please Cc also linux-arm-kernel so it gets reviewed there. The merge window is about to open, so we're running out of time..

Regards,

Tony

Quoted 60 lines

Thanks and regards,
Fernando.

Quoted 43 lines

"omap_mbox_(un)register()". IOW, a mbox instance can be registered at anytime(before/after) H/W initialization. This H/W initialization is taken care of by "mbox_configured" variable. So I might think that the right solution is to introduce a new mutex lock __just for__ h/w configuration as below:

Modified arch/arm/plat-omap/mailbox.c

arch/arm/plat-omap/mailbox.c +4 -3
index 8e90633..19530de 100644
@@ -32,6 +32,7 @@ static struct omap_mbox *mboxes;
 static DEFINE_RWLOCK(mboxes_lock);
 
 static int mbox_configured;
+static DEFINE_MUTEX(mbox_configured_lock);
 
 /* Mailbox FIFO handle functions */
 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@@ -247,16 +248,16 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
 	struct omap_mbox_queue *mq;
 
 	if (likely(mbox->ops->startup)) {
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (!mbox_configured)
 			ret = mbox->ops->startup(mbox);
 
 		if (unlikely(ret)) {
-			write_unlock(&mboxes_lock);
+			mutex_unlock(&mbox_configured_lock);
 			return ret;
 		}
 		mbox_configured++;
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 
 	ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
@@ -302,12 +303,12 @@ static void omap_mbox_fini(struct omap_mbox *mbox)
 	free_irq(mbox->irq, mbox);
 
 	if (unlikely(mbox->ops->shutdown)) {

arch/arm/plat-omap/mailbox.c static void omap_mbox_fini(struct omap_mbox *mbox) · line 313

Quoted 10 lines
arch/arm/plat-omap/mailbox.c +2 -2
-		write_lock(&mboxes_lock);
+		mutex_lock(&mbox_configured_lock);
 		if (mbox_configured > 0)
 			mbox_configured--;
 		if (!mbox_configured)
 			mbox->ops->shutdown(mbox);
-		write_unlock(&mboxes_lock);
+		mutex_unlock(&mbox_configured_lock);
 	}
 }

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

From: ext Tony Lindgren <[email protected]>
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Thu, 18 Feb 2010 02:05:10 +0100

Quoted 38 lines · Guzman Lugo, Fernando
Quoted 37 lines

Hi,

Quoted 33 lines

-----Original Message-----
From: Hiroshi DOYU [mailto:[email protected]]
Sent: Monday, February 15, 2010 7:49 AM
To: Guzman Lugo, Fernando
Cc: [email protected]
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix

Hi Fernando,

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Sat, 13 Feb 2010 02:42:16 +0100

Quoted 4 lines

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00 2001
From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid context

fix

Quoted 6 lines

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

"mboxes_lock" is used to maintain the global list of mailbox instances, which belong to a single mailbox H/W module, but they are logical channels from S/W perspective. Both "->ops->startup()" and "->ops->shutdown()" are being executed against the above single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes, which are (un)registered with

Quoted 6 lines
Quoted 1 line

Yes, they are independent of each other, and can be executed at the same time. I am agreed with your patch; that should be the right solution, so you can drop my patch.

Hiroshi & Fernando, if you want me to merge this series, please post it one more time with right patches and ack's from Hiroshi. Please Cc also linux-arm-kernel so it gets reviewed there. The merge window is about to open, so we're running out of time..

Ok, I'll take care of them.

#5 lore raw

Hi,

Quoted 58 lines

-----Original Message-----
From: Hiroshi DOYU [mailto:[email protected]]
Sent: Wednesday, February 17, 2010 11:11 PM
To: [email protected]
Cc: Guzman Lugo, Fernando; [email protected]
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix

From: ext Tony Lindgren <[email protected]>
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix
Date: Thu, 18 Feb 2010 02:05:10 +0100

Quoted 12 lines · Guzman Lugo, Fernando
Quoted 11 lines

Hi,

Quoted 8 lines

-----Original Message-----
From: Hiroshi DOYU [mailto:[email protected]]
Sent: Monday, February 15, 2010 7:49 AM
To: Guzman Lugo, Fernando
Cc: [email protected]
Subject: Re: [PATCH 5/6] Mailbox: sleeping function called from invalid context fix

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Fernando,

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: [PATCH 5/6] Mailbox: sleeping function called from invalid

context

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

fix
Date: Sat, 13 Feb 2010 02:42:16 +0100

Quoted 1 line

From e06b2716824f225747c4dc83ed2623d0160ae132 Mon Sep 17 00:00:00

2001

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

From: Fernando Guzman Lugo <[email protected]>
Date: Fri, 29 Jan 2010 17:12:24 -0600
Subject: [PATCH] Mailbox: sleeping function called from invalid

context

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fix

Quoted 6 lines

This patch fixes this bug:

BUG: sleeping function called from invalid context

Inside omap2_mbox_startup is called clk_get_sys that can sleep, therefore omap2_mbox_startup can sleep but it is call in an atomic context . So the spinlock is change for a semaphore.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

"mboxes_lock" is used to maintain the global list of mailbox instances, which belong to a single mailbox H/W module, but they are logical channels from S/W perspective. Both "->ops->startup()" and "->ops->shutdown()" are being executed against the above single H/W module, and a mailbox H/W module is totally __independent__ of the registration of logical mailboxes, which are (un)registered with

Yes, they are independent of each other, and can be executed at the same

time. I am agreed with your patch; that should be the right solution, so you can drop my patch.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

Hiroshi & Fernando, if you want me to merge this series, please post it one more time with right patches and ack's from Hiroshi. Please Cc also linux-arm-kernel so it gets reviewed there. The merge window is about to open, so we're running out of time..

Ok, I'll take care of them.

Let me send the set of patches again.

Regards,
Fernando.