Received: by 10.213.65.68 with SMTP id h4csp44519imn; Mon, 19 Mar 2018 19:01:08 -0700 (PDT) X-Google-Smtp-Source: AG47ELvLNaEj1DkdOwMGw8mo0oJphaw3Hsy2PbhpQ3XEKFFaFF02pWHiFU887xmBo0VAaKeeeNcm X-Received: by 2002:a17:902:9a48:: with SMTP id x8-v6mr1859667plv.135.1521511268147; Mon, 19 Mar 2018 19:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521511268; cv=none; d=google.com; s=arc-20160816; b=NXTxcI1jnv6UPzdnr43AMJntoW0lqILdZddv23RDlxn3f9pOmfnGRmVcAfwF0a/W7W QZLmkI1cHamxL0woU3Kh/mmiAvzEtB5WrOhYZmTn5IxP4nXEyqk953X24gdVL9hcRxdZ TfJtv6MdCUC123Bx+aDeszvN0HoACwV38/f7hWrC7LJqJTzrIYsA0UF8YbXwvRzrZn1x DgZ4qRXJyQ0plvSO+Czbuj5cUywhZ6y+AWAljYu8ZovGJ5X59WiVwqXcXjcAdIDhYvVc YxShrjV78+Jpm82bJtIdCKUijwfElvfAgt3UevPIzw0kT0ZC2BN7rzWLb5HmfXBZBbtq mfXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=jV0azyZxtYwJD6d9XjIUfeiEtE10wpmQpilxM3/YCiE=; b=N1vq592VjFUeeph/mqVO0JfDurVgd7sgyxa+g9tA0can0nfL/4sdlgNcjHFI04wA4W JhHKeiGT3rTuljSZ+osMv9onpJ55I2NZJpZ4QlDJiAJ8U7b2A+sIB/kzivYG17DbDNH0 Se1fUAm/qd95B/j0GYBk2gRxGYMszBpDSwUBxNfeW2BTPvKr5iFNQjYFq7w4BBMzLUrW Jf0JaOvCQYEfSpzb7KBr3Ed9nPXSaim9EZee/Y7Zkg1nMEK0fotZeaug5p+x3fDKHPDL 0LWJHVq3bB9jpNF8/LwElFmtENb+4+k3TQC+MFI6ce38pLAH3qfhSdFD0DA+7jfyGcnX ZRIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=TltfwMTS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2-v6si527964pls.497.2018.03.19.19.00.53; Mon, 19 Mar 2018 19:01:08 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=TltfwMTS; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936773AbeCSWmp (ORCPT + 99 others); Mon, 19 Mar 2018 18:42:45 -0400 Received: from mail-by2nam01on0103.outbound.protection.outlook.com ([104.47.34.103]:19764 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755993AbeCSPrK (ORCPT ); Mon, 19 Mar 2018 11:47:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jV0azyZxtYwJD6d9XjIUfeiEtE10wpmQpilxM3/YCiE=; b=TltfwMTSefYZqQHbBEx8O4c0YNe2uhLHMTY/2zA8OZnn7053l3s+9dA0fYut7mQNVBAM6e2ij5hULg1XY+FyP8HpHgzaTpsO3ka/GoF0GLqSL5NGgjv+ZZWB3P2v0LE/cTehaIBeBvV5nM08Vi2NMJtD+3aXeYEdXFWo7h4F10g= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1013.namprd21.prod.outlook.com (52.132.133.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 15:47:05 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:47:05 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Yi Zeng , Zhang Rui , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 008/124] thermal: power_allocator: fix one race condition issue for thermal_instances list Thread-Topic: [PATCH AUTOSEL for 4.15 008/124] thermal: power_allocator: fix one race condition issue for thermal_instances list Thread-Index: AQHTv5mHaTOHdzkuvkyLNSdTBsCnZg== Date: Mon, 19 Mar 2018 15:47:05 +0000 Message-ID: <20180319154645.11350-8-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1013;7:c9DxewogIfUgKDkQl9TuZZzcVkG8koMNUmx5xCbXJE0RGUthrKZEZ17CqRupOPwvkWHhO5lxsmpAbBJhYbRgGNTKMgKHpA3NEGRAiqAKtyYVwDFMvROdh8TjQlNHtqzLn/7IKfn9GdcvaF8k8/P+y2VOffsz6dUr1D4K2Qcw2sT6awv0aeaBxsTUQO06Lg2X4k4DqpOxyx3Do35ZPJISYruuzqtyZXcmLDjNy1dPIQMQaHot5v/0ZYXZuZH8/2Yv;20:vSQTeizyjL2dAHNBhXlD/IizD0VSdKt6bUP+ml7sS0IDa9FC0Y5ZFKK+ASqnycw018l4kdWze2if3LIsRtp/M4iF/Vo/L72+XKi0IAA/+Hg4Bklg/uratOaU27rxpIUUzG5l4iK68vlY6nozaIpLQOqUISF2fY8kFvkprlRHK5o= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 89fec1a2-4cad-4546-c61b-08d58db0aa40 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1013; x-ms-traffictypediagnostic: DM5PR2101MB1013: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231221)(944501300)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB1013;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1013; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(396003)(39860400002)(346002)(376002)(39380400002)(189003)(51234002)(199004)(86612001)(316002)(26005)(72206003)(4326008)(25786009)(110136005)(10290500003)(86362001)(575784001)(59450400001)(54906003)(53936002)(36756003)(107886003)(3280700002)(14454004)(22452003)(6506007)(5660300001)(68736007)(99286004)(186003)(478600001)(76176011)(2950100002)(10090500001)(102836004)(6116002)(5250100002)(2501003)(97736004)(3660700001)(106356001)(81156014)(81166006)(8676002)(8936002)(7736002)(305945005)(2900100001)(105586002)(3846002)(1076002)(66066001)(6436002)(2906002)(6512007)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1013;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: v3tfC6n2ZsVXOZV8LitCWDsiLYpMRak9Ky3KNvLDoAgACRtsnxK9e5wUb8BpxV2z/06ZRTiX6K/EZiTSRXuhb9Ii4ARt5WmkwctWo/rRF4O2JnRKIRE0v9EaL8S/OfeO7uaaBNj2sECe0DRjcXJIP5gO7LPwZNKCloW0I3ULysFZ6ovZcWpLdyIcyciqMfPUbuchOeUPdCHvah1X7bD73atSVoFa6YBazTAiu7603fBAY0PiZtmOCRSpTY6yRk1zFF2oHroeJHQQgaD57hcSlIdjRhD2rHafb1g33cQih8FlcaWbxJhkCr7U2kfYRv6HDLqNnnXVqSKxfSPWjhDo8Q== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89fec1a2-4cad-4546-c61b-08d58db0aa40 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:47:05.1234 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1013 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a= t virtual address dead000000000070 [ 33.566708] c3 25 (kworker/3:0) pgd =3D ffffffc0ed290000 [ 33.572071] c3 25 (kworker/3:0) [dead000000000070] *pgd=3D00000001ed2920= 03, *pud=3D00000001ed292003, *pmd=3D0000000000000000 [ 33.581515] c3 25 (kworker/3:0) Internal error: Oops: 96000004 [#1] PREE= MPT SMP [ 33.599761] c3 25 (kworker/3:0) CPU: 3 PID: 25 Comm: kworker/3:0 Not tai= nted 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: ffffffc0f32f0= 000 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 limi= t =3D 0xffffffc0f32f0020) [ 34.477220] c3 25 (kworker/3:0) Stack: (0xffffffc0f32f3bb0 to 0xffffffc0= f32f4000) [ 34.819822] c3 25 (kworker/3:0) Call trace: [ 34.824021] c3 25 (kworker/3:0) Exception stack(0xffffffc0f32f39c0 to 0x= ffffffc0f32f3af0) [ 34.924993] c3 25 (kworker/3:0) [] power_allocator_thr= ottle+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+0x= 168/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 54ffc46= 0 (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 --- drivers/thermal/power_allocator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/thermal/power_allocator.c b/drivers/thermal/power_allo= cator.c index b4d3116cfdaf..3055f9a12a17 100644 --- a/drivers/thermal/power_allocator.c +++ b/drivers/thermal/power_allocator.c @@ -523,6 +523,7 @@ static void allow_maximum_power(struct thermal_zone_dev= ice *tz) struct thermal_instance *instance; struct power_allocator_params *params =3D tz->governor_data; =20 + mutex_lock(&tz->lock); list_for_each_entry(instance, &tz->thermal_instances, tz_node) { if ((instance->trip !=3D params->trip_max_desired_temperature) || (!cdev_is_power_actor(instance->cdev))) @@ -534,6 +535,7 @@ static void allow_maximum_power(struct thermal_zone_dev= ice *tz) mutex_unlock(&instance->cdev->lock); thermal_cdev_update(instance->cdev); } + mutex_unlock(&tz->lock); } =20 /** --=20 2.14.1