From owner-acpi-jp@jp.freebsd.org  Thu Dec  6 01:15:35 2001
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id BAA58939;
	Thu, 6 Dec 2001 01:15:35 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from thalia.fm.intel.com (fmfdns02.fm.intel.com [132.233.247.11])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id BAA58933;
	Thu, 6 Dec 2001 01:15:32 +0900 (JST)
	(envelope-from robert.moore@intel.com)
Received: from fmsmsxvs043.fm.intel.com (fmsmsxvs043.fm.intel.com [132.233.42.129])
	by thalia.fm.intel.com (8.9.1a+p1/8.9.1/d: relay.m4,v 1.46 2001/10/25 21:02:55 root Exp $) with SMTP id QAA23827;
	Wed, 5 Dec 2001 16:15:26 GMT
Received: from FMSMSX017.fm.intel.com ([132.233.42.196])
 by fmsmsxvs043.fm.intel.com (NAVGW 2.5.1.6) with SMTP id M2001120508143824374
 ; Wed, 05 Dec 2001 08:14:38 -0800
Received: by fmsmsx017.fm.intel.com with Internet Mail Service (5.5.2653.19)
	id <X7DK1XVH>; Wed, 5 Dec 2001 08:15:27 -0800
Message-ID: <B9ECACBD6885D5119ADC00508B68C1EA2FE081@orsmsx107.jf.intel.com>
From: "Moore, Robert" <robert.moore@intel.com>
To: "'Mitsuru IWASAKI'" <iwasaki@jp.FreeBSD.org>,
        "Grover, Andrew"<andrew.grover@intel.com>,
        "Moore, Robert" <robert.moore@intel.com>
Cc: acpi-jp@jp.FreeBSD.org
Date: Wed, 5 Dec 2001 08:15:25 -0800 
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain;
	charset="iso-8859-1"
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+010328
X-Sequence: acpi-jp 1516
Subject: [acpi-jp 1516] RE: problem in AcpiExSystemWaitSemaphore()
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: robert.moore@intel.com


This is a *very* degenerate case, and I'm not convinced that it's worth
adding any additional code to try and "cleanup" on a failure from
AcpiExEnterInterpreter.

If the interpreter cannot be locked again, something is very, very seriously
wrong.  At the minimum, the currently running method must be aborted, but
chances are that the entire ACPI subsystem is corrupted, and perhaps even
the kernel itself is crashed.

In any case, if we are successful in aborting the executing method, the
semaphore will probably be deleted anyway, so it won't make any difference
whether or not we don't release it.  Even if the semaphore is global and not
deleted, we can't ever enter the interpreter again to access it.

In other words, I'm saying that a failure from AcpiExEnterInterpeter is
fatal, so there's little point in trying to cleanup.

Bob


-----Original Message-----
From: Mitsuru IWASAKI [mailto:iwasaki@jp.FreeBSD.org]
Sent: Tuesday, December 04, 2001 11:22 PM
To: andrew.grover@intel.com; robert.moore@intel.com
Cc: acpi-jp@jp.FreeBSD.org
Subject: problem in AcpiExSystemWaitSemaphore()


Hi, Intel folks.
I've found there is a problem in AcpiExSystemWaitSemaphore().

----
    Status = AcpiOsWaitSemaphore (Semaphore, 1, 0);
    if (ACPI_SUCCESS (Status))
    {
        return_ACPI_STATUS (Status);
    }

    if (Status == AE_TIME)
    {
        /* We must wait, so unlock the interpreter */

        AcpiExExitInterpreter ();

        Status = AcpiOsWaitSemaphore (Semaphore, 1, Timeout);

        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "*** Thread awake after blocking,
%s\n",
            AcpiFormatException (Status)));

        /* Reacquire the interpreter */

        Status = AcpiExEnterInterpreter ();
        if (ACPI_SUCCESS (Status))
        {
            /* Restore the timeout exception */

            Status = AE_TIME;
        }
    }
----

If we get AE_TIME from the first AcpiOsWaitSemaphore() then
get AE_OK from the second one, we'll obtain a semaphore.
The problem is that obtained semaphore never be released
forever unless AcpiExEnterInterpreter() returns not AE_OK
(yes, this is very rare case).
As the result, any operations related with the mutex won't work
properly after this.

I think that correct logic in this case would be
 1. if AcpiExEnterInterpreter() failed, we need to release the
    semaphore (if we obtained successfully), then restore the timeout
    exception.
 2. if AcpiExEnterInterpreter() was successful, we can just return
    the status from AcpiOsWaitSemaphore() to the caller.

Here is a quick hack for this problem.  I hope to have this reviewed.

Thanks

Index: exsystem.c
===================================================================
RCS file: /home/ncvs/src/sys/contrib/dev/acpica/exsystem.c,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 exsystem.c
--- exsystem.c	7 Sep 2001 01:22:24 -0000	1.1.1.7
+++ exsystem.c	4 Dec 2001 17:17:26 -0000
@@ -172,10 +172,13 @@
 
         /* Reacquire the interpreter */
 
-        Status = AcpiExEnterInterpreter ();
-        if (ACPI_SUCCESS (Status))
+        if (ACPI_FAILURE(AcpiExEnterInterpreter ()))
         {
             /* Restore the timeout exception */
+            if (ACPI_SUCCESS (Status))
+            {
+		AcpiOsSignalSemaphore (Semaphore, 1);
+            }
 
             Status = AE_TIME;
         }

