From patchwork Fri Nov 10 09:34:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6buE5YaN5ry+KEpveXlvdW5nIEh1YW5nKQ==?= X-Patchwork-Id: 743314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D4A1C4167D for ; Fri, 10 Nov 2023 18:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344904AbjKJS1W (ORCPT ); Fri, 10 Nov 2023 13:27:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346004AbjKJSZ5 (ORCPT ); Fri, 10 Nov 2023 13:25:57 -0500 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2085.outbound.protection.outlook.com [40.107.215.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6BD624C00; Fri, 10 Nov 2023 01:35:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Slg0cVZa1fTzWEWwO4X5Fnq3emMg70tKjDSl3sL2X6oNvogxVkfqvpqLge2PTRL1DTBPSACk6KUxdRRLgW1FhClL4olsZT2gVgOt8b3M1l0aX5Izq5Un2NqfhiMt1ov3DkGjU2o2nFA4hlW8urjoV3B0FVsUFa+hiNhpL3aqhnd7OPnx+GjkYysmZzb/C5SbDPFjuOwodTCTyMiY0vdcxG9c/gRnHfb7NZ8LSlVfpzxy5m7nUY1mHCkG4ezAK4SlcwVbuG/kSEmji/8gOivCPQ1WRZ429VUVd9QREfuOz7J3YAkYcr9BVFT7UNr3QBNr9Kl0mT5yD+00nXwsgpeYVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6rIgZQKlI39JsUvAuaI7JwqSRIZL5MrCi+ju84tLORE=; b=Olyai8WjkWDawtcJzb+mxn4LbxhG0K7u4qADDQmxbf7LiFkyxOcR8/Kf1tR6qCVfhEA89IVh83f2kLCSiDjxCOZu/U/E9w8ebI67y0mwTH9oB4CYtU4ShOLX0Kr+0JAmDe2KAoEtbhvhPMsH5JB3CHiZWkvNGFMvYU7lmf8Re8b2dc+q/A2fTNdWYJRPaZ1RugbSYF6KScRWUPfDezBSzEoZ/7e8xTovUSEpsvQK/WQeNq1VGoYPxYhnTlGL+BD2bd2tmBVKQs2aOvXrWjXS84AAvbG+yTc+5V4np1QH91mEYNWx0WpHURZOPLEZcmLqBK+uXhAOnpiin5sEgYHrHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=samsung.com smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6rIgZQKlI39JsUvAuaI7JwqSRIZL5MrCi+ju84tLORE=; b=ENhX0PavWQ8cj0LS4AmB0Wi5+fFltiK6jciHJgIl800AortmfjFPhYDOx8bW5BSiv2nUnBGMzIy1D9rhqc++8UaQTJa2PA3tmjE1l5DxibFMF3hts73fHyRHxZQ1OV3CmZlYO2CA+vLObkqe7EKDzrDfO0a0zOf9eBEBwzLYtgQ= Received: from SI1PR02CA0032.apcprd02.prod.outlook.com (2603:1096:4:1f6::12) by KL1PR02MB6661.apcprd02.prod.outlook.com (2603:1096:820:112::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.18; Fri, 10 Nov 2023 09:35:00 +0000 Received: from HK2PEPF00006FB3.apcprd02.prod.outlook.com (2603:1096:4:1f6:cafe::69) by SI1PR02CA0032.outlook.office365.com (2603:1096:4:1f6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.19 via Frontend Transport; Fri, 10 Nov 2023 09:35:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by HK2PEPF00006FB3.mail.protection.outlook.com (10.167.8.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6977.21 via Frontend Transport; Fri, 10 Nov 2023 09:35:00 +0000 Received: from PA80318969.adc.com (172.16.40.118) by mailappw30.adc.com (172.16.56.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 10 Nov 2023 17:34:59 +0800 From: huangzaiyang To: , , CC: , , huangzaiyang , ZaiYang Huang Subject: [PATCH] Performance: devfreq: avoid devfreq delay work re-init before Date: Fri, 10 Nov 2023 17:34:57 +0800 Message-ID: <20231110093457.458-1-huangzaiyang@oppo.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [172.16.40.118] X-ClientProxiedBy: mailappw31.adc.com (172.16.56.198) To mailappw30.adc.com (172.16.56.197) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK2PEPF00006FB3:EE_|KL1PR02MB6661:EE_ X-MS-Office365-Filtering-Correlation-Id: e80324bc-0160-4372-35a4-08dbe1d04f57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aABVKdLdnNncB9neC9F93WzEv1cax5/sYTUtq6tQHknS7S74VexJzePb2yRH9cVKIskO5XdKEWIFvPU2sy/wan1G+Kf8qMoY9MQy9dlQXFTA5msCgooIbQcMVlpBppT7s373IjQk2GB5+vduLgtT9T2MlwS5L7+j/LxQOD8UnXaQp1X8FRF2pZu6h2QlWn4egSRDn2f0lO/S/l47GkLlz3m1iOj5mfz0BOT8ymvFd8Dm/Wz2vDf+KLTG6tRFULrGXOIXpUoUYH3gN/Dzq1lHKrgUzUAodCSIXsjR1FmSRfGeIlYMj/NLxgURoHyna/z0v3Vbq6D+XwmArq0nvXEvbRuM3tmn6KaM1vLcEZ8zg+yWplt1Ycu20xgP8lDYIz/SJM/+obMj30wA2exyw0sTUGNLPDGTdxL+cM/462LES4gSgjwBamQY8IIBJSGSFz4WqA24cOOCY1bd0Dc5/J213bVXI8b2thmpDEqvYfc4iTd4A7bWR6SJzRsM8RelZh6QgPDkeAKruVk9KcPlR51VuubnRV8J+MOjMmVD+k0eLVTE4Fy+c0PrR5GsTI8VL0CW0/mkf2Ozdy0MqTNEydYTisDpCjDHpFync4jfWnLhQBFoVOvPYsku/JrXmRjCc2Wgr/HcDeFai8gfJKH69NhcIds0d+SXth0+PSI8kqsMrXcCXtiHOxy1kkjlC2q1SJMJhr8hTrfzusTPMz1j9yyRHQbd96UznA0KKGYA7wIQ/Bd36XrrJDE2k3AedBrz1+Mj873fb/Z1W2ul9spRV4vDMQ== X-Forefront-Antispam-Report: CIP:58.252.5.68; CTRY:CN; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.oppo.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(136003)(376002)(39860400002)(346002)(396003)(230922051799003)(451199024)(186009)(1800799009)(82310400011)(64100799003)(40470700004)(36840700001)(46966006)(2906002)(40460700003)(30864003)(5660300002)(40480700001)(36756003)(81166007)(70206006)(54906003)(86362001)(356005)(316002)(26005)(107886003)(2616005)(1076003)(82740400003)(110136005)(16526019)(478600001)(83380400001)(70586007)(47076005)(336012)(41300700001)(4326008)(8936002)(36860700001)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2023 09:35:00.1901 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e80324bc-0160-4372-35a4-08dbe1d04f57 X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6; Ip=[58.252.5.68]; Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: HK2PEPF00006FB3.apcprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR02MB6661 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: huangzaiyang There is a timer_list race condition when executing the following test shell script: ''' while true do echo "simple_ondemand" > /sys/class/devfreq/1d84000.ufshc/governor echo "performance" > /sys/class/devfreq/1d84000.ufshc/governor done ''' [13511.214366][ C3] Unable to handle kernel paging request at virtual address dead00000000012a [13511.214393][ C3] Mem abort info: [13511.214398][ C3] ESR = 0x96000044 [13511.214404][ C3] EC = 0x25: DABT (current EL), IL = 32 bits [13511.214409][ C3] SET = 0, FnV = 0 [13511.214414][ C3] EA = 0, S1PTW = 0 [13511.214417][ C3] Data abort info: [13511.214422][ C3] ISV = 0, ISS = 0x00000044 [13511.214427][ C3] CM = 0, WnR = 1 [13511.214432][ C3] [dead00000000012a] address between user and kernel address ranges [13511.214439][ C3] Internal error: Oops: 96000044 [#1] PREEMPT SMP [13511.215449][ C3] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G S W O 5.10.168-android12-9-o-g63cc297a7b34 #1 [13511.215454][ C3] Hardware name: Qualcomm Technologies, Inc. Cape MTP, Whiteswan (DT) [13511.215460][ C3] pstate: 82400085 (Nzcv daIf +PAN -UAO +TCO BTYPE=--) [13511.215472][ C3] pc : expire_timers+0x9c/0x428 [13511.215478][ C3] lr : __run_timers+0x1f0/0x328 [13511.215483][ C3] sp : ffffffc00801bdd0 [13511.215487][ C3] x29: ffffffc00801bdf0 x28: ffffffdb87b31698 [13511.215493][ C3] x27: ffffffdb87999e58 x26: ffffffdb87966008 [13511.215499][ C3] x25: 0000000000000001 x24: ffffff8001734a00 [13511.215506][ C3] x23: 00000000000000e0 x22: dead000000000122 [13511.215512][ C3] x21: 000000010032658e x20: ffffff89f7a9ae80 [13511.215518][ C3] x19: ffffffc00801be50 x18: ffffffc00801d038 [13511.215525][ C3] x17: 0000000000000240 x16: 0000000000000201 [13511.215532][ C3] x15: ffffffffffffffff x14: ffffff89f7a9aef8 [13511.215538][ C3] x13: 0000000000000240 x12: ffffff89f7a9aea8 [13511.215544][ C3] x11: 0000000000000021 x10: 000000014032658e [13511.215550][ C3] x9 : ffffffc00801be50 x8 : dead000000000122 [13511.215556][ C3] x7 : ffff71646c68735e x6 : ffffff89f7aaae58 [13511.215563][ C3] x5 : 0000000000000000 x4 : 0000000000000101 [13511.215569][ C3] x3 : ffffff89f7a9aef0 x2 : ffffff89f7a9aef0 [13511.215575][ C3] x1 : ffffffc00801be50 x0 : ffffff8045804428 [13511.215581][ C3] Call trace: [13511.215586][ C3] expire_timers+0x9c/0x428 [13511.215591][ C3] __run_timers+0x1f0/0x328 [13511.215596][ C3] run_timer_softirq+0x28/0x58 [13511.215602][ C3] efi_header_end+0x168/0x5ec [13511.215610][ C3] __irq_exit_rcu+0x108/0x124 [13511.215617][ C3] __handle_domain_irq+0x118/0x1e4 [13511.215625][ C3] gic_handle_irq.31230+0x6c/0x250 [13511.215630][ C3] el1_irq+0xe4/0x1c0 [13511.215638][ C3] cpuidle_enter_state+0x3a4/0xa04 [13511.215644][ C3] do_idle+0x308/0x574 [13511.215649][ C3] cpu_startup_entry+0x84/0x90 [13511.215656][ C3] secondary_start_kernel+0x204/0x274 [13511.215664][ C3] Code: d503201f a9402408 f9000128 b4000048 (f9000509) [13511.215670][ C3] ---[ end trace 5100bad72a35d566 ]--- [13511.215676][ C3] Kernel panic - not syncing: Oops: Fatal exception in interrupt This is because when switching the governor through the sys node, the devfreq_monitor_start function will re-initialize the delayed work task, which will cause the delay work pending flag to become invalid, and the timer pending judgment contained in the delayed work will also become invalid, and then the pending interception will be executed when the queue is executed. So we remove the delay work'initialization work to the devfreq_add_device and timer_store functions, and the delay work pending judgment is performed before the devfreq_monitor_start function performs the queue operation. Signed-off-by: ZaiYang Huang --- drivers/devfreq/devfreq.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index b3a68d5833bd..8ae6f853a21e 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -483,18 +483,7 @@ void devfreq_monitor_start(struct devfreq *devfreq) if (IS_SUPPORTED_FLAG(devfreq->governor->flags, IRQ_DRIVEN)) return; - switch (devfreq->profile->timer) { - case DEVFREQ_TIMER_DEFERRABLE: - INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); - break; - case DEVFREQ_TIMER_DELAYED: - INIT_DELAYED_WORK(&devfreq->work, devfreq_monitor); - break; - default: - return; - } - - if (devfreq->profile->polling_ms) + if (devfreq->profile->polling_ms && !delayed_work_pending(&devfreq->work)) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); } @@ -830,6 +819,17 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_dev; } + switch (devfreq->profile->timer) { + case DEVFREQ_TIMER_DEFERRABLE: + INIT_DEFERRABLE_WORK(&devfreq->work, devfreq_monitor); + break; + case DEVFREQ_TIMER_DELAYED: + INIT_DELAYED_WORK(&devfreq->work, devfreq_monitor); + break; + default: + dev_err(dev, "%s: Target devfreq(%s)'s profile timer has no settings \n", devfreq->governor_name, + __func__); + } if (!devfreq->profile->max_state || !devfreq->profile->freq_table) { mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); @@ -1860,6 +1860,18 @@ static ssize_t timer_store(struct device *dev, struct device_attribute *attr, df->profile->timer = timer; mutex_unlock(&df->lock); + switch (df->profile->timer) { + case DEVFREQ_TIMER_DEFERRABLE: + INIT_DEFERRABLE_WORK(&df->work, devfreq_monitor); + break; + case DEVFREQ_TIMER_DELAYED: + INIT_DELAYED_WORK(&df->work, devfreq_monitor); + break; + default: + dev_err(dev, "%s: Target devfreq(%s)'s profile timer has no settings \n", df->governor_name, + __func__); + } + ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL); if (ret) { dev_warn(dev, "%s: Governor %s not stopped(%d)\n",