From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Alexey Starikovskiy <astarikovskiy@suse.de>,
Len Brown <lenb@kernel.org>,
pm list <linux-pm@lists.linux-foundation.org>,
Thomas Renninger <trenn@suse.de>,
Matthew Garrett <mjg59@srcf.ucam.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction
Date: Sun, 31 Jan 2010 23:31:50 +0100 [thread overview]
Message-ID: <201001312331.50321.rjw@sisk.pl> (raw)
In-Reply-To: <201001312209.21212.rjw@sisk.pl>
On Sunday 31 January 2010, Rafael J. Wysocki wrote:
> On Sunday 31 January 2010, Maxim Levitsky wrote:
> > On Sun, 2010-01-31 at 00:29 +0100, Rafael J. Wysocki wrote:
> ...
> > >
> > > static int acpi_ec_resume(struct acpi_device *device)
> > > {
> > > struct acpi_ec *ec = acpi_driver_data(device);
> > > +
> > > + mutex_lock(&ec->lock);
> > > /* Enable use of GPE back */
> > > acpi_enable_gpe(NULL, ec->gpe);
> > > + /* Allow transactions to happen again */
> > > + set_bit(EC_FLAGS_SUSPENDED, &ec->flags);
> > ^^^^^^^^^^^^
> > Thats why it doesn't work here....
> > Will retest now.
>
> Ouch, sorry.
Fixed version is appended, for the record.
Rafael
---
From: Rafael J. Wysocki <rjw@sisk.pl>
Subject: ACPI / EC: Add protection from suspending in the middle of EC transaction
There is a race between the suspend process and the EC driver that
may result in suspending in the middle of an EC transaction in
progress, which may lead to unpredictable behavior of the platform.
To remove that race condition, make acpi_ec_suspend() and
acpi_ec_resume() acquire ec->lock and introduce a new EC flag,
EC_FLAGS_SUSPENDED, set in acpi_ec_suspend() and cleared in
acpi_ec_resume(), that will cause acpi_ec_transaction() to return
error code (-EBUSY) if set.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
drivers/acpi/ec.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
Index: linux-2.6/drivers/acpi/ec.c
===================================================================
--- linux-2.6.orig/drivers/acpi/ec.c
+++ linux-2.6/drivers/acpi/ec.c
@@ -76,8 +76,9 @@ enum ec_command {
enum {
EC_FLAGS_QUERY_PENDING, /* Query is pending */
EC_FLAGS_GPE_STORM, /* GPE storm detected */
- EC_FLAGS_HANDLERS_INSTALLED /* Handlers for GPE and
+ EC_FLAGS_HANDLERS_INSTALLED, /* Handlers for GPE and
* OpReg are installed */
+ EC_FLAGS_SUSPENDED, /* Driver is suspended */
};
/* If we find an EC via the ECDT, we need to keep a ptr to its context */
@@ -291,6 +292,10 @@ static int acpi_ec_transaction(struct ac
if (t->rdata)
memset(t->rdata, 0, t->rlen);
mutex_lock(&ec->lock);
+ if (test_bit(EC_FLAGS_SUSPENDED, &ec->flags)) {
+ status = -EBUSY;
+ goto unlock;
+ }
if (ec->global_lock) {
status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
if (ACPI_FAILURE(status)) {
@@ -1059,16 +1064,26 @@ error:
static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
{
struct acpi_ec *ec = acpi_driver_data(device);
+
+ mutex_lock(&ec->lock);
+ /* Prevent transactions from happening while suspended */
+ set_bit(EC_FLAGS_SUSPENDED, &ec->flags);
/* Stop using GPE */
acpi_disable_gpe(NULL, ec->gpe);
+ mutex_unlock(&ec->lock);
return 0;
}
static int acpi_ec_resume(struct acpi_device *device)
{
struct acpi_ec *ec = acpi_driver_data(device);
+
+ mutex_lock(&ec->lock);
/* Enable use of GPE back */
acpi_enable_gpe(NULL, ec->gpe);
+ /* Allow transactions to happen again */
+ clear_bit(EC_FLAGS_SUSPENDED, &ec->flags);
+ mutex_unlock(&ec->lock);
return 0;
}
next prev parent reply other threads:[~2010-01-31 22:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-30 23:29 [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction Rafael J. Wysocki
2010-01-31 14:11 ` Alan Jenkins
2010-01-31 17:09 ` Maxim Levitsky
2010-02-01 9:46 ` Henrique de Moraes Holschuh
2010-02-01 10:22 ` Alexey Starikovskiy
2010-02-01 22:42 ` Rafael J. Wysocki
2010-02-02 20:23 ` [PATCH] ACPI / EC: Remover race between EC driver and suspend process (was: Re: [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction) Rafael J. Wysocki
2010-01-31 20:41 ` [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction Maxim Levitsky
2010-01-31 21:09 ` Rafael J. Wysocki
2010-01-31 22:31 ` Rafael J. Wysocki [this message]
2010-02-03 0:32 ` [PATCH] ACPI / EC: Remove race between EC driver and suspend process (rev. 2) (was: Re: [RFC][RFT][PATCH] ACPI: Protection from suspending in the middle of EC transaction) Rafael J. Wysocki
2010-02-04 0:33 ` [PATCH] ACPI / EC: Remove race between EC driver and suspend process (rev. 3) Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201001312331.50321.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=astarikovskiy@suse.de \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=maximlevitsky@gmail.com \
--cc=mjg59@srcf.ucam.org \
--cc=trenn@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox