Skip to content

Commit e1191bd

Browse files
Lv Zhengrafaeljw
authored andcommitted
ACPI / EC: Work around method reentrancy limit in ACPICA for _Qxx
A regression is caused by the following commit: Commit: 02b771b Subject: ACPI / EC: Fix an issue caused by the serialized _Qxx evaluations In this commit, using system workqueue causes that the maximum parallel executions of _Qxx can exceed 255. This violates the method reentrancy limit in ACPICA and generates the following error log: ACPI Error: Method reached maximum reentrancy limit (255) (20150818/dsmethod-341) This patch creates a seperate workqueue and limits the number of parallel _Qxx evaluations down to a configurable value (can be tuned against number of online CPUs). Since EC events are handled after driver probe, we can create the workqueue in acpi_ec_init(). Fixes: 02b771b (ACPI / EC: Fix an issue caused by the serialized _Qxx evaluations) Link: https://bugzilla.kernel.org/show_bug.cgi?id=135691 Cc: 4.3+ <stable@vger.kernel.org> # 4.3+ Reported-and-tested-by: Helen Buus <ubuntu@hbuus.com> Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent bc53956 commit e1191bd

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

drivers/acpi/ec.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ enum ec_command {
101101
#define ACPI_EC_UDELAY_POLL 550 /* Wait 1ms for EC transaction polling */
102102
#define ACPI_EC_CLEAR_MAX 100 /* Maximum number of events to query
103103
* when trying to clear the EC */
104+
#define ACPI_EC_MAX_QUERIES 16 /* Maximum number of parallel queries */
104105

105106
enum {
106107
EC_FLAGS_QUERY_PENDING, /* Query is pending */
@@ -121,6 +122,10 @@ static unsigned int ec_delay __read_mostly = ACPI_EC_DELAY;
121122
module_param(ec_delay, uint, 0644);
122123
MODULE_PARM_DESC(ec_delay, "Timeout(ms) waited until an EC command completes");
123124

125+
static unsigned int ec_max_queries __read_mostly = ACPI_EC_MAX_QUERIES;
126+
module_param(ec_max_queries, uint, 0644);
127+
MODULE_PARM_DESC(ec_max_queries, "Maximum parallel _Qxx evaluations");
128+
124129
static bool ec_busy_polling __read_mostly;
125130
module_param(ec_busy_polling, bool, 0644);
126131
MODULE_PARM_DESC(ec_busy_polling, "Use busy polling to advance EC transaction");
@@ -174,6 +179,7 @@ static void acpi_ec_event_processor(struct work_struct *work);
174179

175180
struct acpi_ec *boot_ec, *first_ec;
176181
EXPORT_SYMBOL(first_ec);
182+
static struct workqueue_struct *ec_query_wq;
177183

178184
static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
179185
static int EC_FLAGS_QUERY_HANDSHAKE; /* Needs QR_EC issued when SCI_EVT set */
@@ -1098,7 +1104,7 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 *data)
10981104
* work queue execution.
10991105
*/
11001106
ec_dbg_evt("Query(0x%02x) scheduled", value);
1101-
if (!schedule_work(&q->work)) {
1107+
if (!queue_work(ec_query_wq, &q->work)) {
11021108
ec_dbg_evt("Query(0x%02x) overlapped", value);
11031109
result = -EBUSY;
11041110
}
@@ -1649,15 +1655,41 @@ static struct acpi_driver acpi_ec_driver = {
16491655
},
16501656
};
16511657

1658+
static inline int acpi_ec_query_init(void)
1659+
{
1660+
if (!ec_query_wq) {
1661+
ec_query_wq = alloc_workqueue("kec_query", 0,
1662+
ec_max_queries);
1663+
if (!ec_query_wq)
1664+
return -ENODEV;
1665+
}
1666+
return 0;
1667+
}
1668+
1669+
static inline void acpi_ec_query_exit(void)
1670+
{
1671+
if (ec_query_wq) {
1672+
destroy_workqueue(ec_query_wq);
1673+
ec_query_wq = NULL;
1674+
}
1675+
}
1676+
16521677
int __init acpi_ec_init(void)
16531678
{
1654-
int result = 0;
1679+
int result;
16551680

1681+
/* register workqueue for _Qxx evaluations */
1682+
result = acpi_ec_query_init();
1683+
if (result)
1684+
goto err_exit;
16561685
/* Now register the driver for the EC */
16571686
result = acpi_bus_register_driver(&acpi_ec_driver);
1658-
if (result < 0)
1659-
return -ENODEV;
1687+
if (result)
1688+
goto err_exit;
16601689

1690+
err_exit:
1691+
if (result)
1692+
acpi_ec_query_exit();
16611693
return result;
16621694
}
16631695

@@ -1667,5 +1699,6 @@ static void __exit acpi_ec_exit(void)
16671699
{
16681700

16691701
acpi_bus_unregister_driver(&acpi_ec_driver);
1702+
acpi_ec_query_exit();
16701703
}
16711704
#endif /* 0 */

0 commit comments

Comments
 (0)