Received: by 10.192.165.156 with SMTP id m28csp49681imm; Tue, 10 Apr 2018 16:09:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx48JfVohszphc5l7sgcbossutKZMEJ8o0gQeFaQpQ0Ky8w+e2nTFNJ2eYAs0XV48fgqPrvBL X-Received: by 10.99.95.135 with SMTP id t129mr1654508pgb.268.1523401761405; Tue, 10 Apr 2018 16:09:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523401761; cv=none; d=google.com; s=arc-20160816; b=ry7icL53c/95gbBnbQAGaEVd8Mq8Aw2cFLyKQwrOVdzmXAslc5yVF+ZKdI7Oo3DRjb 7L6N9BPs8Vuidy+NIRzkwp6U/V1tEp/Of9TYFpKEEHH041ShuSavuDiLJHROIq8nKHqL TZGqPpjRhqzqpnb3Ei7D1LNeRclRjXsJKeQE+Bkxbyc6YRTwMDqMHRDxiZF7KVOFEDzJ scrhhMP3Jf++0ODDLV6UMRff9mXeEifmpBQuBparKmKlDvEicxgv7+5qGusYKlcv84im rbSiOr28mw/GuRVrtZcWwBAF4JnpMox1jNFtVk2qaLQ7houit8yFnA5uL16OfvkA8Ua5 ueAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=fW9aZECdn2DuSp/ypUVov37yT1KU486Ka7m/F8E2Xx0=; b=xtsdkNtkg21FM+bCCrva3nPkRTestoWlrip4Rt9+CRbXOF0q0Nk/tiR15trZS8HR5i hqm+xL6heO+9CUdd6f86XTE/+cSS5VsWf/5ZqtFV7qWF0xiPe9hRWwP/Cu1rp8Fsbl34 tLijuw7xjrfUuYLTaZAt79uvB0HkiTe1YNBcMcICHPy6dx3UakVNiqhdgjK6TwyMUIxy q+7QHhzdFa3vK07cOrJzLs/QgHOSkj8KhP5AnsuPIPNVCoGNfkJupjc6n/mzV22EielX 5t580ipreNdt9qLkbJi9iCOq6QWxDgLYzg79qt5rLIzdgwunUt/i9rNnlMiXcPUj7WL1 arMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si3583967ple.629.2018.04.10.16.08.44; Tue, 10 Apr 2018 16:09:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755463AbeDJWex (ORCPT + 99 others); Tue, 10 Apr 2018 18:34:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:41880 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754371AbeDJWeu (ORCPT ); Tue, 10 Apr 2018 18:34:50 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CFDA9CDB; Tue, 10 Apr 2018 22:34:49 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yi Zeng , Zhang Rui , Sasha Levin Subject: [PATCH 4.14 008/138] thermal: power_allocator: fix one race condition issue for thermal_instances list Date: Wed, 11 Apr 2018 00:23:18 +0200 Message-Id: <20180410212903.139209142@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212902.121524696@linuxfoundation.org> References: <20180410212902.121524696@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yi Zeng [ Upstream commit a5de11d67dcd268b8d0beb73dc374de5e97f0caf ] When invoking allow_maximum_power and traverse tz->thermal_instances, we should grab thermal_zone_device->lock to avoid race condition. For example, during the system reboot, if the mali GPU device implements device shutdown callback and unregister GPU devfreq cooling device, the deleted list head may be accessed to cause panic, as the following log shows: [ 33.551070] c3 25 (kworker/3:0) Unable to handle kernel paging request at virtual address dead000000000070 [ 33.566708] c3 25 (kworker/3:0) pgd = ffffffc0ed290000 [ 33.572071] c3 25 (kworker/3:0) [dead000000000070] *pgd=00000001ed292003, *pud=00000001ed292003, *pmd=0000000000000000 [ 33.581515] c3 25 (kworker/3:0) Internal error: Oops: 96000004 [#1] PREEMPT SMP [ 33.599761] c3 25 (kworker/3:0) CPU: 3 PID: 25 Comm: kworker/3:0 Not tainted 4.4.35+ #912 [ 33.614137] c3 25 (kworker/3:0) Workqueue: events_freezable thermal_zone_device_check [ 33.620245] c3 25 (kworker/3:0) task: ffffffc0f32e4200 ti: ffffffc0f32f0000 task.ti: ffffffc0f32f0000 [ 33.629466] c3 25 (kworker/3:0) PC is at power_allocator_throttle+0x7c8/0x8a4 [ 33.636609] c3 25 (kworker/3:0) LR is at power_allocator_throttle+0x808/0x8a4 [ 33.643742] c3 25 (kworker/3:0) pc : [] lr : [] pstate: 20000145 [ 33.652874] c3 25 (kworker/3:0) sp : ffffffc0f32f3bb0 [ 34.468519] c3 25 (kworker/3:0) Process kworker/3:0 (pid: 25, stack limit = 0xffffffc0f32f0020) [ 34.477220] c3 25 (kworker/3:0) Stack: (0xffffffc0f32f3bb0 to 0xffffffc0f32f4000) [ 34.819822] c3 25 (kworker/3:0) Call trace: [ 34.824021] c3 25 (kworker/3:0) Exception stack(0xffffffc0f32f39c0 to 0xffffffc0f32f3af0) [ 34.924993] c3 25 (kworker/3:0) [] power_allocator_throttle+0x7c8/0x8a4 [ 34.933184] c3 25 (kworker/3:0) [] handle_thermal_trip.part.25+0x70/0x224 [ 34.941545] c3 25 (kworker/3:0) [] thermal_zone_device_update+0xc0/0x20c [ 34.949818] c3 25 (kworker/3:0) [] thermal_zone_device_check+0x20/0x2c [ 34.957924] c3 25 (kworker/3:0) [] process_one_work+0x168/0x458 [ 34.965414] c3 25 (kworker/3:0) [] worker_thread+0x13c/0x4b4 [ 34.972650] c3 25 (kworker/3:0) [] kthread+0xe8/0xfc [ 34.979187] c3 25 (kworker/3:0) [] ret_from_fork+0x10/0x40 [ 34.986244] c3 25 (kworker/3:0) Code: f9405e73 eb1302bf d102e273 54ffc460 (b9402a61) [ 34.994339] c3 25 (kworker/3:0) ---[ end trace 32057901e3b7e1db ]--- Signed-off-by: Yi Zeng Signed-off-by: Zhang Rui Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/thermal/power_allocator.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/thermal/power_allocator.c +++ b/drivers/thermal/power_allocator.c @@ -523,6 +523,7 @@ static void allow_maximum_power(struct t struct thermal_instance *instance; struct power_allocator_params *params = tz->governor_data; + mutex_lock(&tz->lock); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if ((instance->trip != params->trip_max_desired_temperature) || (!cdev_is_power_actor(instance->cdev))) @@ -534,6 +535,7 @@ static void allow_maximum_power(struct t mutex_unlock(&instance->cdev->lock); thermal_cdev_update(instance->cdev); } + mutex_unlock(&tz->lock); } /**