Skip to contentSkip to conversation

mmcoops with panic/oops

RFC In review Jaehoon Chung 2 participants 3 messages Nov 30, 2010 – Dec 1, 2010 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

RFC 1/1 mmcoops with panic/oops

This patch is mmcoops.

When Kernel panic or oops, write panic log to circular buffer in eMMC. then after reset, we can see the log in MMC.

So we need change mmc_wait_for_req().
because if we used schedule(), we can find atomic schedule warning. That is not our needs log. so i used delay.
i want to know how about __mmc_wait_for_req()

If any question, let me know.

Thanks,
Jaehoon Chung

---
 drivers/mmc/card/Kconfig    |    6 +
 drivers/mmc/card/Makefile   |    1 +
 drivers/mmc/card/mmc_oops.c |  270 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/core.c     |   47 +++++++-
 include/linux/mmc/core.h    |    1 +
 include/linux/mmcoops.h     |   12 ++
 6 files changed, 330 insertions(+), 7 deletions(-)
 create mode 100644 drivers/mmc/card/mmc_oops.c
 create mode 100644 include/linux/mmcoops.h
drivers/mmc/card/Kconfig +6 -0
index 57e4416..02c9256 100644
@@ -54,6 +54,12 @@ config SDIO_UART
 	help
 	  SDIO function driver for SDIO cards that implements the UART
 	  class, as well as the GPS class which appears like a UART.
+config MMC_OOPS
+	tristate "Log panic/oops to a MMC buffer"
+	help
+	  This enables panic and oops messages to be logged to a circular
+	  buffer in a MMC sectors where it can be read back at some
+	  later point.
 
 config MMC_TEST
 	tristate "MMC host test driver"
drivers/mmc/card/Makefile +1 -0
index c73b406..09ecd82 100644
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_MMC_BLOCK)		+= mmc_block.o
 mmc_block-objs			:= block.o queue.o
+obj-$(CONFIG_MMC_OOPS)		+= mmc_oops.o
 obj-$(CONFIG_MMC_TEST)		+= mmc_test.o
 
 obj-$(CONFIG_SDIO_UART)		+= sdio_uart.o
drivers/mmc/card/mmc_oops.c new file +270 -0

270 lines not on this page · raw message

drivers/mmc/core/core.c +40 -7

64 lines not on this page · raw message

include/linux/mmc/core.h +1 -0
index 64e013f..7107344 100644
@@ -131,6 +131,7 @@ struct mmc_request {
 struct mmc_host;
 struct mmc_card;
 
+extern void __mmc_wait_for_req(struct mmc_host *, struct mmc_request *, int);
 extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
 extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
 extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
include/linux/mmcoops.h new file +12 -0
new file mode 100644
index 0000000..fa356eb
@@ -0,0 +1,12 @@
+#ifndef __MMCOOPS_H
+#define __MMCOOPS_H
+
+#include <linux/platform_device.h>
+
+struct mmcoops_platform_data {
+	struct platform_device	*pdev;
+	unsigned long		start;
+	unsigned long		size;
+};
+
+#endif
#1 lore raw
Quoted 46 lines · On Tue, 30 Nov 2010 17:42:13 +0900 Jaehoon Chung <[email protected]> wrote:

This patch is mmcoops.

When Kernel panic or oops, write panic log to circular buffer in eMMC. then after reset, we can see the log in MMC.

So we need change mmc_wait_for_req().
because if we used schedule(), we can find atomic schedule warning. That is not our needs log. so i used delay.
i want to know how about __mmc_wait_for_req()

If any question, let me know.

...

/**
- * mmc_wait_for_req - start a request and wait for completion
+ * __mmc_wait_for_req - start a request and wait for completion
* @host: MMC host to start command
* @mrq: MMC request to start
+ * @panic: kernel panic/oops or not
*
* Start a new MMC custom command request for a host, and wait
* for the command to complete. Does not attempt to parse the
* response.
*/

drivers/mmc/core/core.c +15 -4
-void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
+void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
+		int panic)
 {
-	DECLARE_COMPLETION_ONSTACK(complete);
+	if (panic) {
+		DECLARE_WAITQUEUE(wait, current);
+
+		mmc_start_request(host, mrq);
+
+		spin_lock_irq(&host->wq.lock);
+		init_waitqueue_head(&host->wq);
+
+		add_wait_queue_exclusive(&host->wq, &wait);
+		set_current_state(TASK_UNINTERRUPTIBLE);
 
-	mrq->done_data = &complete;
-	mrq->done = mmc_wait_done;
+		mdelay(10);
+		spin_unlock_irq(&host->wq.lock);
+	} else {

drivers/mmc/core/core.c static void mmc_wait_done(struct mmc_request *mrq) · line 237

Quoted 10 lines
drivers/mmc/core/core.c +10 -0
+		DECLARE_COMPLETION_ONSTACK(complete);
+
+		mrq->done_data = &complete;
+		mrq->done = mmc_wait_done;
+
+		mmc_start_request(host, mrq);
+
+		wait_for_completion(&complete);
+	}
+}

This approach seems somewhat OK - it will only do the busy-wait in the "panic=1" case, so existing callers shouldn't be affected. (panic' could have had type bool', btw).

That being said, the code is odd/wrong.

void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
int panic)

{
	if (panic) {
		DECLARE_WAITQUEUE(wait, current);

		mmc_start_request(host, mrq);

		spin_lock_irq(&host->wq.lock);
		init_waitqueue_head(&host->wq);

		add_wait_queue_exclusive(&host->wq, &wait);
		set_current_state(TASK_UNINTERRUPTIBLE);

		mdelay(10);
		spin_unlock_irq(&host->wq.lock);
	} else {

Surely the waitqueue is unneeded and the missing remove_wait_queue() is a bug and the set_current_state() is a bug and the spin_lock_irq() appears to be unneeded. afaict you want this:

void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
int panic)

{
	if (panic) {
		mmc_start_request(host, mrq);
		mdelay(10);
	} else {

However it is pretty bad to just delay 10 milliseconds and then assume that the request has completed. Would it not be better to poll for the IRQ completion, or to poll some hardware flag?

(We can't poll for IRQ completion if the caller has disabled IRQs, but if the caller has disabled IRQs then the use of spin_lock_irq() instead of spin_lock_irqsave() is yet another bug!)

#2 lore raw

Hi Andrew.

Quoted 84 lines · Andrew Morton
Quoted 46 lines · On Tue, 30 Nov 2010 17:42:13 +0900 Jaehoon Chung <[email protected]> wrote:

This patch is mmcoops.

When Kernel panic or oops, write panic log to circular buffer in eMMC. then after reset, we can see the log in MMC.

So we need change mmc_wait_for_req().
because if we used schedule(), we can find atomic schedule warning. That is not our needs log. so i used delay.
i want to know how about __mmc_wait_for_req()

If any question, let me know.

...

/**
- * mmc_wait_for_req - start a request and wait for completion
+ * __mmc_wait_for_req - start a request and wait for completion
* @host: MMC host to start command
* @mrq: MMC request to start
+ * @panic: kernel panic/oops or not
*
* Start a new MMC custom command request for a host, and wait
* for the command to complete. Does not attempt to parse the
* response.
*/

drivers/mmc/core/core.c +15 -4
-void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
+void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
+		int panic)
 {
-	DECLARE_COMPLETION_ONSTACK(complete);
+	if (panic) {
+		DECLARE_WAITQUEUE(wait, current);
+
+		mmc_start_request(host, mrq);
+
+		spin_lock_irq(&host->wq.lock);
+		init_waitqueue_head(&host->wq);
+
+		add_wait_queue_exclusive(&host->wq, &wait);
+		set_current_state(TASK_UNINTERRUPTIBLE);
 
-	mrq->done_data = &complete;
-	mrq->done = mmc_wait_done;
+		mdelay(10);
+		spin_unlock_irq(&host->wq.lock);
+	} else {

drivers/mmc/core/core.c static void mmc_wait_done(struct mmc_request *mrq) · line 237

Quoted 10 lines
drivers/mmc/core/core.c +10 -0
+		DECLARE_COMPLETION_ONSTACK(complete);
+
+		mrq->done_data = &complete;
+		mrq->done = mmc_wait_done;
+
+		mmc_start_request(host, mrq);
+
+		wait_for_completion(&complete);
+	}
+}

This approach seems somewhat OK - it will only do the busy-wait in the "panic=1" case, so existing callers shouldn't be affected. (panic' could have had type bool', btw).

That being said, the code is odd/wrong.

void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
int panic)

{
	if (panic) {
		DECLARE_WAITQUEUE(wait, current);

		mmc_start_request(host, mrq);

		spin_lock_irq(&host->wq.lock);
		init_waitqueue_head(&host->wq);

		add_wait_queue_exclusive(&host->wq, &wait);
		set_current_state(TASK_UNINTERRUPTIBLE);

		mdelay(10);
		spin_unlock_irq(&host->wq.lock);
	} else {
Quoted 4 lines

Surely the waitqueue is unneeded and the missing remove_wait_queue() is a bug and the set_current_state() is a bug and the spin_lock_irq() appears to be unneeded. afaict you want this:

Sorry, Missing remove_wait_queue()...
Yes, actually i want below code. but that is not working well.. You said we need to know request completed.
But it is difficult to know correct delay time..

And when we try to write log, if happen other panic/oops log.. maybe that try to write that log..then happen write crash.. So i used waitqueue.

i changed spin_lock_irqsave() instead of spin_lock_irq()

Quoted 9 lines

void __mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq,
int panic)

{
	if (panic) {
		mmc_start_request(host, mrq);
		mdelay(10);
	} else {
Quoted 3 lines

However it is pretty bad to just delay 10 milliseconds and then assume that the request has completed. Would it not be better to poll for the IRQ completion, or to poll some hardware flag?

right, 10 milliseconds is assumed..i'm also testing how much delay need.. If need, i will change that time.

Quoted 9 lines

(We can't poll for IRQ completion if the caller has disabled IRQs, but if the caller has disabled IRQs then the use of spin_lock_irq() instead of spin_lock_irqsave() is yet another bug!)
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Thank you...

Regards,
Jaehoon Chung