From patchwork Tue Oct 25 05:21:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9393991 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 285A960231 for ; Tue, 25 Oct 2016 05:22:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D05D28D94 for ; Tue, 25 Oct 2016 05:22:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F6DB28EB0; Tue, 25 Oct 2016 05:22:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F6DF28D94 for ; Tue, 25 Oct 2016 05:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755332AbcJYFWC (ORCPT ); Tue, 25 Oct 2016 01:22:02 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35090 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133AbcJYFWA (ORCPT ); Tue, 25 Oct 2016 01:22:00 -0400 Received: by mail-oi0-f68.google.com with SMTP id n202so1756250oig.2; Mon, 24 Oct 2016 22:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=upMaa5v2gnnqG1YqLaMUKwpaL4UoN0ht9Zj0WdTt9cQ=; b=YoYgqLbTJQaSWVgy3F3+UDCtpQoEQ9KinUdxFQ5kMLx4x3+/CBm7HEbEpBg0/ADONd oa09eZlM1yUzsY+u/1nKTIqopRxf06nITyE9sO59D4qJGkf7t0Ik/6eTBkPQX7c32MDp c7Pd+Eeqwv7FWfardPVLXuov50uhRgy5YpYnt314Efpbd4l+ZLbp5k7tNgt8Kcvfh4ld F15HA9jhcpzb7NpETRQg7B5fHf165SAsN8S98jb1ws3VjFzt45gLbqWGXvCKDuaLgSCQ fp7gHX3zmtHzJ2aEeDP/1hoig6LwHGdjhkMkGQDIw38LgLEip4Q8nRedpwfo3J2dcBpN JQMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=upMaa5v2gnnqG1YqLaMUKwpaL4UoN0ht9Zj0WdTt9cQ=; b=An90EoSF981GrHY1hhG7lPPGFkL8pmtUoOekyg9KqkZp6rU5qYW+YEGSwOpQlJZkwI OTp13gv2tbpNwpClKd7IorYeImXEURGP2vgUoLJOHsrB+Nbx+xbkAd2NLbaKdJYqdGCi JkeZzlxj2yluNJQkQ5VJgYajiGgKOO4h7qd4CGKTe7ELuAXYDCUCzMqi9RNTcf4aTxCY l8KZm4cujoZIISlBeK2jLCX+zXgs6q6FvIRJc21/4buIempogMF5bIP5y9An0obTTmZk 3hPg6wZUOb/4r0nG+PYgIfKCDx0LU2mtHwzRW1eE7US5ZrJRbSl9p3K0GfxmQ2yHpKGf v6/A== X-Gm-Message-State: AA6/9Rm/zdj4uBAhjfds4LVphH+fXPWE7CMCi7qoosGowgHyxOLSJ0jMi124dnXCzE+cyQ== X-Received: by 10.202.182.87 with SMTP id g84mr21206942oif.107.1477372873099; Mon, 24 Oct 2016 22:21:13 -0700 (PDT) Received: from localhost.localdomain (h3.246.129.40.static.ip.windstream.net. [40.129.246.3]) by smtp.gmail.com with ESMTPSA id m67sm6298619otc.32.2016.10.24.22.21.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Oct 2016 22:21:12 -0700 (PDT) From: Lv Zheng X-Google-Original-From: Lv Zheng To: "Rafael J . Wysocki" , "Rafael J . Wysocki" , Len Brown Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Lv Zheng Subject: [PATCH 1/6] ACPICA: Dispatcher: Fix order issue of method termination Date: Tue, 25 Oct 2016 13:21:09 +0800 Message-Id: <0114a27d924164974733acd655c1f433d4ede4fe.1477372449.git.lv.zheng@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The last step of the method termination should be the end of the method serialization. Otherwise, the steps happening after it will face the race issues that cannot be protected by the method serialization mechanism. This patch fixes this issue by moving the per-method-object deletion code prior than the end of the method serialization. Otherwise, the possible race issues may result in AE_ALREADY_EXISTS error in a parallel environment. Reported-by: Imre Deak Signed-off-by: Lv Zheng --- drivers/acpi/acpica/dsmethod.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c index 32e9ddc..c4028a8 100644 --- a/drivers/acpi/acpica/dsmethod.c +++ b/drivers/acpi/acpica/dsmethod.c @@ -731,26 +731,6 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, acpi_ds_method_data_delete_all(walk_state); /* - * If method is serialized, release the mutex and restore the - * current sync level for this thread - */ - if (method_desc->method.mutex) { - - /* Acquisition Depth handles recursive calls */ - - method_desc->method.mutex->mutex.acquisition_depth--; - if (!method_desc->method.mutex->mutex.acquisition_depth) { - walk_state->thread->current_sync_level = - method_desc->method.mutex->mutex. - original_sync_level; - - acpi_os_release_mutex(method_desc->method. - mutex->mutex.os_mutex); - method_desc->method.mutex->mutex.thread_id = 0; - } - } - - /* * Delete any namespace objects created anywhere within the * namespace by the execution of this method. Unless: * 1) This method is a module-level executable code method, in which @@ -786,6 +766,26 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, ~ACPI_METHOD_MODIFIED_NAMESPACE; } } + + /* + * If method is serialized, release the mutex and restore the + * current sync level for this thread + */ + if (method_desc->method.mutex) { + + /* Acquisition Depth handles recursive calls */ + + method_desc->method.mutex->mutex.acquisition_depth--; + if (!method_desc->method.mutex->mutex.acquisition_depth) { + walk_state->thread->current_sync_level = + method_desc->method.mutex->mutex. + original_sync_level; + + acpi_os_release_mutex(method_desc->method. + mutex->mutex.os_mutex); + method_desc->method.mutex->mutex.thread_id = 0; + } + } } /* Decrement the thread count on the method */