From owner-acpi-jp@jp.freebsd.org  Wed Dec  5 16:22:06 2001
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id QAA27781;
	Wed, 5 Dec 2001 16:22:06 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (root@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id QAA27776
	for <acpi-jp@jp.freebsd.org>; Wed, 5 Dec 2001 16:22:06 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (root@localhost [127.0.0.1])
	(authenticated as iwa with CRAM-MD5)
	by tasogare.imasy.or.jp (8.11.6+3.4W/8.11.6/tasogare) with ESMTP/inet id fB57LwP30372;
	Wed, 5 Dec 2001 16:21:59 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Date: Wed, 05 Dec 2001 16:21:39 +0900 (JST)
Message-Id: <20011205.162139.118635082.iwasaki@jp.FreeBSD.org>
To: andrew.grover@intel.com, robert.moore@intel.com
Cc: acpi-jp@jp.freebsd.org
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Mailer: Mew version 2.0 on Emacs 20.7 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+010328
X-Sequence: acpi-jp 1513
Subject: [acpi-jp 1513] problem in AcpiExSystemWaitSemaphore()
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

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;
         }


