From patchwork Wed Oct 26 07:40:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lv Zheng X-Patchwork-Id: 9396175 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 657CE60234 for ; Wed, 26 Oct 2016 07:40:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D8E9298DA for ; Wed, 26 Oct 2016 07:40:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2270A298DC; Wed, 26 Oct 2016 07:40:26 +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 67D8F298DA for ; Wed, 26 Oct 2016 07:40:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754338AbcJZHkU (ORCPT ); Wed, 26 Oct 2016 03:40:20 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:34733 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbcJZHkR (ORCPT ); Wed, 26 Oct 2016 03:40:17 -0400 Received: by mail-oi0-f66.google.com with SMTP id p136so10415452oic.1; Wed, 26 Oct 2016 00:40:17 -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=JjQIzKI1lMYnMnveZ68VXjJ+Bha81IJz9R0gBaEifx4=; b=f1WJRf1A8m4GHVLro4s+tpwbooqd9fhIIIXNSxMS3hdJAoZWiKK/XZad/1zOsF/Wwc gkn23MQmni0hWl9W5Mwu06ZR/f1yPMxTZOsmpR6txd4fWhGb5WGul+tKDorEjwGGV23N nKqhmI9xZuHJCf7NQNiJd18cwrENljmom2YwZHK+eKdzgX/4m+FO/RxYSr9Q2KgJO7Ap kn6OWXji+9dX46nVOJ5DWtIlUtaAGZEhUmFH6msI6um7zK7KLhxwtbUy2YKp4YaWYd+/ kDS89UC322Xs21q33CWYcUeBGtZXFkP3D9vl3z7fu86RcPN6Q0a6HbVMhNwJCDZgVbcl +pWw== 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=JjQIzKI1lMYnMnveZ68VXjJ+Bha81IJz9R0gBaEifx4=; b=Kjq4o32e7pF/6uY0s8Svgzg2Ii3kjb5e4rJd+lMsPwUYfcxQAKrGGcbTa+29EalY7E 0uSuORrVQwZJRm8GPCa4PGG+9mtyR8BJrYhVinzbLlE0v+oIZmZs3CUSiv04czM16n6f KOFiuI/dzKHMBNYue8PwrwPEiE+7hzl8lA3E9TZtS6RyU0uGfDSKXbt1tYbCCMIcK6kU HSbgU3CNHAMf2zFkch92XG5N3QtDOVGyAuLIRNxNIiyZZAFcO0fsNl7APkceULVER8j2 QSnUh/3/gtc7/d5CjLvlve2XSR45wFBn6/o5nd6IfN9JSIqizOErWrfcMzj86owDWbpD 9fGw== X-Gm-Message-State: ABUngveLVLt+aC1sYHysvgjj2JPVCDc7i8EGg+jj1GTYMp5l93TB53FQu/Z7XstrQtP1Vg== X-Received: by 10.202.190.138 with SMTP id o132mr148950oif.166.1477467616832; Wed, 26 Oct 2016 00:40:16 -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 l2sm268248otc.15.2016.10.26.00.40.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 00:40:16 -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 v2 1/3] ACPICA: Dispatcher: Fix order issue of method termination Date: Wed, 26 Oct 2016 15:40:12 +0800 Message-Id: <8e4ab5c5e724de379474aaa838648375e74e9045.1477465173.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. Fixed by Lv Zheng. Fixes: 74f51b80a0c4 ("ACPICA: Namespace: Fix dynamic table loading issues") Reported-and-tested-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 */