From patchwork Fri Oct 18 10:58:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 176796 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp682720ill; Fri, 18 Oct 2019 03:58:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaIjUrfI2R/3mH17msd7FObS/AjKNN6a7GPS4d6/m9ygmaQ/8yYTXHTabzTZtNuWdtG8Ho X-Received: by 2002:a17:906:2cca:: with SMTP id r10mr8195309ejr.108.1571396333682; Fri, 18 Oct 2019 03:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571396333; cv=none; d=google.com; s=arc-20160816; b=ehWHGLwqvgMIGjPzjVXW1JWKdVxs7V5jPoO4dhVloEKr+lhwlHQH9QyAwMVJaQJn2T xkqzhvox0te0IztkVRU6r8mF8ERqKumtQOSUR+arDCxAr4BRHZ9RPD6FujOxYHk2GYGz 9YtNAIU2oR6BlkbcSoQSUd8vhvXev0n8NBpYzSNn4bUzWe2Zv4IhSuthrLeqPvhWYfFe ZADpFwWnY+rAClKWopubq06g5YBmcAonXpYOoXKzStqCcDl2clLIZsmXJCnk+3gHUlsT l376rqOBtxs4e4KPmZsN8FpZaIZB3ji0WeDabAXe7ipzSKrT4qGkHCAqVubrEq/EQcwP Djcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=ETs25mcb3T00IzFAZfGyXmf8ZHoaZHJ3T2xdB2YHq8k=; b=cQ/bDTLsjdLvZOMHJkxv0ygSfwbtM8+bSLtu46O31se/30Q0MppWCxlrbgJEQBtjSP qfcBiYefV2szNZ04MO8pqfeVcqhzzPIKogLHqOKh2k+cz74jOx8/X8RCpn7cjXwgvQrF RqiHtTcwpZ2ijO8AAJTCDFYDw2dKrpCUV1TKIlzpJxiTUDMiqnH7kKSBZJYLZ8BWMNmQ 7qyIP7BQgeSYPgwz0k0hfwbt21xCJyov0+R4tQ8L88Pyrhdv33iaFzA1YVYZBLxD8SpG Jr/gowDPMHsCJSr0Hh8Bt7Lrp0Mii9IJKJhI5Gh/8JhLUBsbVo5NnzquPEjdul5BN5oP kPrQ== 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 d19si3117023ejy.353.2019.10.18.03.58.53; Fri, 18 Oct 2019 03:58:53 -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 S2439154AbfJRK6u (ORCPT + 26 others); Fri, 18 Oct 2019 06:58:50 -0400 Received: from [217.140.110.172] ([217.140.110.172]:34856 "EHLO foss.arm.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1728576AbfJRK6t (ORCPT ); Fri, 18 Oct 2019 06:58:49 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F1EB6AB6; Fri, 18 Oct 2019 03:58:25 -0700 (PDT) Received: from usa.arm.com (e107155-lin.cambridge.arm.com [10.1.196.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2E8C33F6C4; Fri, 18 Oct 2019 03:58:25 -0700 (PDT) From: Sudeep Holla To: Viresh Kumar , "Rafael J . Wysocki" Cc: Sudeep Holla , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] cpufreq: cancel any pending policy update work scheduled before freeing Date: Fri, 18 Oct 2019 11:58:15 +0100 Message-Id: <20191018105815.5714-1-sudeep.holla@arm.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Schedules policy update work may end up racing with the freeing of the policy and unregistering the driver. One possible race is as below where the cpufreq_driver is unregistered but the scheduled work gets executed at later stage when cpufreq_driver is NULL(i.e. after freeing the policy and driver) Unable to handle kernel NULL pointer dereference at virtual address 0000001c pgd = (ptrval) [0000001c] *pgd=80000080204003, *pmd=00000000 Internal error: Oops: 206 [#1] SMP THUMB2 Modules linked in: CPU: 0 PID: 34 Comm: kworker/0:1 Not tainted 5.4.0-rc3-00006-g67f5a8081a4b #86 Hardware name: ARM-Versatile Express Workqueue: events handle_update PC is at cpufreq_set_policy+0x58/0x228 LR is at dev_pm_qos_read_value+0x77/0xac Control: 70c5387d Table: 80203000 DAC: fffffffd Process kworker/0:1 (pid: 34, stack limit = 0x(ptrval)) (cpufreq_set_policy) from (refresh_frequency_limits.part.24+0x37/0x48) (refresh_frequency_limits.part.24) from (handle_update+0x2f/0x38) (handle_update) from (process_one_work+0x16d/0x3cc) (process_one_work) from (worker_thread+0xff/0x414) (worker_thread) from (kthread+0xff/0x100) (kthread) from (ret_from_fork+0x11/0x28) Cc: "Rafael J. Wysocki" Cc: Viresh Kumar Signed-off-by: Sudeep Holla --- drivers/cpufreq/cpufreq.c | 2 ++ 1 file changed, 2 insertions(+) v1->v2: - Dropped check for work_pending as it can still be racy - Changed from flush_work to cancel_work_sync -- 2.17.1 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e93cba29fbb2..8ad9c2859841 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1279,6 +1279,8 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) } dev_pm_qos_remove_request(policy->min_freq_req); + /* cancel any pending policy->update work before freeing the policy */ + cancel_work_sync(&policy->update); kfree(policy->min_freq_req); cpufreq_policy_put_kobj(policy);