Takashi Iwai 2a5c5e
From 0fada277147ffc6d694aa32162f51198d4f10d94 Mon Sep 17 00:00:00 2001
Takashi Iwai 2a5c5e
From: Jamie Iles <jamie@nuviainc.com>
Takashi Iwai 2a5c5e
Date: Mon, 12 Oct 2020 14:04:46 +0100
Takashi Iwai 2a5c5e
Subject: [PATCH] ACPI: debug: don't allow debugging when ACPI is disabled
Takashi Iwai 2a5c5e
Git-commit: 0fada277147ffc6d694aa32162f51198d4f10d94
Takashi Iwai 2a5c5e
Patch-mainline: v5.10-rc1
Takashi Iwai 2a5c5e
References: git-fixes
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
If ACPI is disabled then loading the acpi_dbg module will result in the
Takashi Iwai 2a5c5e
following splat when lock debugging is enabled.
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
  DEBUG_LOCKS_WARN_ON(lock->magic != lock)
Takashi Iwai 2a5c5e
  WARNING: CPU: 0 PID: 1 at kernel/locking/mutex.c:938 __mutex_lock+0xa10/0x1290
Takashi Iwai 2a5c5e
  Kernel panic - not syncing: panic_on_warn set ...
Takashi Iwai 2a5c5e
  CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.9.0-rc8+ #103
Takashi Iwai 2a5c5e
  Hardware name: linux,dummy-virt (DT)
Takashi Iwai 2a5c5e
  Call trace:
Takashi Iwai 2a5c5e
   dump_backtrace+0x0/0x4d8
Takashi Iwai 2a5c5e
   show_stack+0x34/0x48
Takashi Iwai 2a5c5e
   dump_stack+0x174/0x1f8
Takashi Iwai 2a5c5e
   panic+0x360/0x7a0
Takashi Iwai 2a5c5e
   __warn+0x244/0x2ec
Takashi Iwai 2a5c5e
   report_bug+0x240/0x398
Takashi Iwai 2a5c5e
   bug_handler+0x50/0xc0
Takashi Iwai 2a5c5e
   call_break_hook+0x160/0x1d8
Takashi Iwai 2a5c5e
   brk_handler+0x30/0xc0
Takashi Iwai 2a5c5e
   do_debug_exception+0x184/0x340
Takashi Iwai 2a5c5e
   el1_dbg+0x48/0xb0
Takashi Iwai 2a5c5e
   el1_sync_handler+0x170/0x1c8
Takashi Iwai 2a5c5e
   el1_sync+0x80/0x100
Takashi Iwai 2a5c5e
   __mutex_lock+0xa10/0x1290
Takashi Iwai 2a5c5e
   mutex_lock_nested+0x6c/0xc0
Takashi Iwai 2a5c5e
   acpi_register_debugger+0x40/0x88
Takashi Iwai 2a5c5e
   acpi_aml_init+0xc4/0x114
Takashi Iwai 2a5c5e
   do_one_initcall+0x24c/0xb10
Takashi Iwai 2a5c5e
   kernel_init_freeable+0x690/0x728
Takashi Iwai 2a5c5e
   kernel_init+0x20/0x1e8
Takashi Iwai 2a5c5e
   ret_from_fork+0x10/0x18
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
This is because acpi_debugger.lock has not been initialized as
Takashi Iwai 2a5c5e
acpi_debugger_init() is not called when ACPI is disabled.  Fail module
Takashi Iwai 2a5c5e
loading to avoid this and any subsequent problems that might arise by
Takashi Iwai 2a5c5e
trying to debug AML when ACPI is disabled.
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
Fixes: 8cfb0cdf07e2 ("ACPI / debugger: Add IO interface to access debugger functionalities")
Takashi Iwai 2a5c5e
Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Takashi Iwai 2a5c5e
Signed-off-by: Jamie Iles <jamie@nuviainc.com>
Takashi Iwai 2a5c5e
Cc: 4.10+ <stable@vger.kernel.org> # 4.10+
Takashi Iwai 2a5c5e
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Takashi Iwai 2a5c5e
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
---
Takashi Iwai 2a5c5e
 drivers/acpi/acpi_dbg.c |    3 +++
Takashi Iwai 2a5c5e
 1 file changed, 3 insertions(+)
Takashi Iwai 2a5c5e
Takashi Iwai 2a5c5e
--- a/drivers/acpi/acpi_dbg.c
Takashi Iwai 2a5c5e
+++ b/drivers/acpi/acpi_dbg.c
Takashi Iwai 2a5c5e
@@ -757,6 +757,9 @@ int __init acpi_aml_init(void)
Takashi Iwai 2a5c5e
 		goto err_exit;
Takashi Iwai 2a5c5e
 	}
Takashi Iwai 2a5c5e
 
Takashi Iwai 2a5c5e
+	if (acpi_disabled)
Takashi Iwai 2a5c5e
+		return -ENODEV;
Takashi Iwai 2a5c5e
+
Takashi Iwai 2a5c5e
 	/* Initialize AML IO interface */
Takashi Iwai 2a5c5e
 	mutex_init(&acpi_aml_io.lock);
Takashi Iwai 2a5c5e
 	init_waitqueue_head(&acpi_aml_io.wait);