From patchwork Sat Mar 26 15:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 554516 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 5554BC433EF for ; Sat, 26 Mar 2022 15:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233693AbiCZPxg (ORCPT ); Sat, 26 Mar 2022 11:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233688AbiCZPxf (ORCPT ); Sat, 26 Mar 2022 11:53:35 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5403BFD20 for ; Sat, 26 Mar 2022 08:51:58 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id q14so13798377ljc.12 for ; Sat, 26 Mar 2022 08:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Eb8mEZgW6Pv9eJz7v3yw4vSszcng2DvogIPFiCFHPAM=; b=NvjALIk6sfpnadaKvnK/HRszwktc2fsPkhXqPhPoPE9FxQ6kmwr/My2ajrh0916EBg yJ+wJR4IW8YyzD0/cmD7EXzMzY9/Vwhom9MlXyIUddI8DrUQBY+U0qm4ZvG80pY/uWjg BkyTEc2ZKztYDAp3wHE93IjIL44N4uU1IJ+KiOJ/ZE/E7hKTM6SGJLAmf59mk04c48y6 TOPLKfemYjZMIP7YpZBJmSnxoTW7TiJAvRVSUH3J+Z3rpMgZy82t2p6Qpy3gGGXnGZQh OxD7Z4Pq8w5Z3s+LxPtGZ0ki9FvmF6feF7Os/XTZd2vvF0UNOYD7371rbSeZCi5oKhZJ L2Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Eb8mEZgW6Pv9eJz7v3yw4vSszcng2DvogIPFiCFHPAM=; b=2r+op70s1DXI4tMgtwKbli0H8kn1MZBwKipfESWRwv3J3d+5kRfCfFWjkgzU1PmNwf eSKLGpB2WqYy5Ph0Mp8YsX/MPaLx6puDWGrWiIaW10yfebkd/qk6SNcleRhtWYWWj4SC R/01UEMuPJ8PRWnBkp54yPU5C5UsDuHVSMWMV76/xTff+xRJPT1aS2xAH6FyrH1YRJVe LBgDmETqe6sJRxN4bM8PV6G9lb1bAc7paqRzpdc3Q9dHhbvDcSZsTvojF7vIuzy6rXQ7 3Ypg7RK/8wNsNAJZX5tYV1/t74N4QcRjVUp6LqFaGSX+tG7w9PY+MoYS4g4TcUwJSvI5 pj8w== X-Gm-Message-State: AOAM532AGatFvNSwG0Jcsc89l59i5O3bon4Gu0aEufTf4Lj54m0QhPyX 6d5WUuVFM78XJQa9AKaWK48c+w== X-Google-Smtp-Source: ABdhPJwW1rh24njroI9lmlYxb90fFkGfmwUYLI+IB/0xKcVjvYlcYVztsq/DLrMEj4lZC8NJhJyvgQ== X-Received: by 2002:a2e:5318:0:b0:249:8375:81ab with SMTP id h24-20020a2e5318000000b00249837581abmr12199030ljb.243.1648309916264; Sat, 26 Mar 2022 08:51:56 -0700 (PDT) Received: from eriador.lumag.spb.ru ([185.24.52.156]) by smtp.gmail.com with ESMTPSA id o17-20020a05651238b100b00443c898b598sm1097992lft.112.2022.03.26.08.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Mar 2022 08:51:55 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, Thara Gopinath , Vladimir Zapolskiy Subject: [PATCH v4 1/4] cpufreq: qcom-hw: drop affinity hint before freeing the IRQ Date: Sat, 26 Mar 2022 18:51:50 +0300 Message-Id: <20220326155153.7377-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> References: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Drop affinity hint before freeing the throttling IRQ to fix the following trace: [ 185.114773] ------------[ cut here ]------------ [ 185.119517] WARNING: CPU: 7 PID: 43 at kernel/irq/manage.c:1887 free_irq+0x3a4/0x3dc [ 185.127474] Modules linked in: [ 185.130618] CPU: 7 PID: 43 Comm: cpuhp/7 Tainted: G S W 5.17.0-rc6-00386-g67382a5b705d-dirty #690 [ 185.147125] pstate: 604000c5 (nZCv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 185.154269] pc : free_irq+0x3a4/0x3dc [ 185.158031] lr : free_irq+0x33c/0x3dc [ 185.161792] sp : ffff80000841bc90 [ 185.165195] x29: ffff80000841bc90 x28: ffffa6edc5c3d000 x27: ffff6d93729e5908 [ 185.172515] x26: 0000000000000000 x25: ffff6d910109fc00 x24: ffff6d91011490e0 [ 185.179838] x23: ffff6d9101149218 x22: 0000000000000080 x21: 0000000000000000 [ 185.187163] x20: ffff6d9101149000 x19: ffff6d910ab61500 x18: ffffffffffffffff [ 185.194487] x17: 2e35202020202020 x16: 2020202020202020 x15: ffff80008841b9a7 [ 185.201805] x14: 00000000000003c9 x13: 0000000000000001 x12: 0000000000000040 [ 185.209135] x11: ffff6d91005aab58 x10: ffff6d91005aab5a x9 : ffffc6a5ad1c5408 [ 185.216455] x8 : ffff6d91005adb88 x7 : 0000000000000000 x6 : ffffc6a5ab5a91f4 [ 185.223776] x5 : 0000000000000000 x4 : ffff6d91011490a8 x3 : ffffc6a5ad266108 [ 185.231098] x2 : 0000000013033204 x1 : ffff6d9101149000 x0 : ffff6d910a9cc000 [ 185.238421] Call trace: [ 185.240932] free_irq+0x3a4/0x3dc [ 185.244334] qcom_cpufreq_hw_cpu_exit+0x78/0xcc [ 185.248985] cpufreq_offline.isra.0+0x228/0x270 [ 185.253639] cpuhp_cpufreq_offline+0x10/0x20 [ 185.258027] cpuhp_invoke_callback+0x16c/0x2b0 [ 185.262592] cpuhp_thread_fun+0x190/0x250 [ 185.266710] smpboot_thread_fn+0x12c/0x230 [ 185.270914] kthread+0xfc/0x100 [ 185.274145] ret_from_fork+0x10/0x20 [ 185.277820] irq event stamp: 212 [ 185.281136] hardirqs last enabled at (211): [] _raw_spin_unlock_irqrestore+0x8c/0xa0 [ 185.290775] hardirqs last disabled at (212): [] __schedule+0x710/0xa10 [ 185.299081] softirqs last enabled at (0): [] copy_process+0x7d0/0x1a14 [ 185.307475] softirqs last disabled at (0): [<0000000000000000>] 0x0 Fixes: 3ed6dfbd3bb98 ("cpufreq: qcom-hw: Set CPU affinity of dcvsh interrupts") Tested-by: Vladimir Zapolskiy Reviewed-by: Vladimir Zapolskiy Reviewed-by: Bjorn Andersson Signed-off-by: Dmitry Baryshkov --- drivers/cpufreq/qcom-cpufreq-hw.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index 618e436018c0..44d46e52baea 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -427,6 +427,7 @@ static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data) mutex_unlock(&data->throttle_lock); cancel_delayed_work_sync(&data->throttle_work); + irq_set_affinity_hint(data->throttle_irq, NULL); free_irq(data->throttle_irq, data); } From patchwork Sat Mar 26 15:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 555484 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 8783CC4332F for ; Sat, 26 Mar 2022 15:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233688AbiCZPxh (ORCPT ); Sat, 26 Mar 2022 11:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233689AbiCZPxg (ORCPT ); Sat, 26 Mar 2022 11:53:36 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2950412ACE for ; Sat, 26 Mar 2022 08:51:59 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id bt26so17998319lfb.3 for ; Sat, 26 Mar 2022 08:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TGuxe1tdDb+vQ+pZhLOcPKE6MxLU7K+4INF2UgDIqr0=; b=Yqxt27hEZ4enS/Hz6DvVZIsJpD5jySXI/e+r7/MOZUXw7X2toawJ6gPkF4TsGR3Gj1 kchL8DLZ1X0/YYlmaiOXXcVYTZb7l1nNi5oqxXRa+1ZW5LdCsdGejIX053syZqtEVRkw mYAEC5yK6oXL+oTkClsIQmPEgKGxRd0oFvh1U9HJqy27CLJHAhArRROfhUE8kDYu9iRV NPIvECa9yxV7+wCsywlYIMY7a5oVkbSDgQZkVPoINNGZDkr3wLM/qpM2m/LMXOuD292G dHNxvQ1HZwUyUpITpkb69yxI6BXO7lSGN4kWWGKFh/8KhlUOQ3KeNQAfqRGezQsZflzK xtqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TGuxe1tdDb+vQ+pZhLOcPKE6MxLU7K+4INF2UgDIqr0=; b=QJP2raigIFX5c7eWnDAiymPvQgviwYgyXPCo5nxcNHiLBOnd3/sAx3q6bNn2/bpIr/ WUQttPpimoIDpNdanVXCXnPRRjUkmM+68pg/8QjwGLkvNS0pypOZxCcJS6fo+th0/tlV OkJMF3zbANsoDqwaOEF3RZTVmIMM/SxUBGK6G7AFvN/ZKdWxDdXUqVefiKHKTMSNSaou xO1cO37YP2/INkfUuQxNVWXy9fPIAmAtgit0KgA/5CzLT7U3Qe5ySTzZlpF79K1Zrz6c 0h8fr12SBav3xS9m2TPAleUl8f0qusUKMp7tx3V6cUKx64gS0A6fre6QpHcm3DTDn69P O+Tw== X-Gm-Message-State: AOAM533tI172YK2ysDSsSoS9xuLmeXtV96FRBvtOEUbi6QwKv5rr3LhD Vx/PEnUHAsurPDfYEKLwqxeThfGec2cBhg== X-Google-Smtp-Source: ABdhPJx6FgKKfA7Gsm5qoa96fp4hyxULZ36tI15uJ/iTrrlmOi/3LS+TS0iR//A1d69nPukRK8VQjw== X-Received: by 2002:ac2:5223:0:b0:448:5100:e427 with SMTP id i3-20020ac25223000000b004485100e427mr12565757lfl.87.1648309917316; Sat, 26 Mar 2022 08:51:57 -0700 (PDT) Received: from eriador.lumag.spb.ru ([185.24.52.156]) by smtp.gmail.com with ESMTPSA id o17-20020a05651238b100b00443c898b598sm1097992lft.112.2022.03.26.08.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Mar 2022 08:51:56 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, Thara Gopinath Subject: [PATCH v4 2/4] cpufreq: qcom-hw: fix the race between LMH worker and cpuhp Date: Sat, 26 Mar 2022 18:51:51 +0300 Message-Id: <20220326155153.7377-3-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> References: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The driver would disable the worker when cpu is being put offline, but it happens closer to the end of cpufreq_offline(). The function qcom_lmh_dcvs_poll() can be running in parallel with this, when policy->cpus already has been updated. Read policy->related_cpus instead. [ 37.122433] ------------[ cut here ]------------ [ 37.127225] WARNING: CPU: 0 PID: 187 at drivers/base/arch_topology.c:180 topology_update_thermal_pressure+0xec/0x100 [ 37.138098] Modules linked in: [ 37.141279] CPU: 0 PID: 187 Comm: kworker/0:3 Tainted: G S 5.17.0-rc6-00389-g37c83d0b8710-dirty #713 [ 37.158306] Workqueue: events qcom_lmh_dcvs_poll [ 37.163095] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 37.170278] pc : topology_update_thermal_pressure+0xec/0x100 [ 37.176131] lr : topology_update_thermal_pressure+0x20/0x100 [ 37.181977] sp : ffff800009b6bce0 [ 37.185402] x29: ffff800009b6bce0 x28: ffffd87abe92b000 x27: ffff04bd7292e205 [ 37.192792] x26: ffffd87abe930af8 x25: ffffd87abe94e4c8 x24: 0000000000000000 [ 37.200180] x23: ffff04bb01177018 x22: ffff04bb011770c0 x21: ffff04bb01177000 [ 37.207567] x20: ffff04bb0a419000 x19: 00000000000c4e00 x18: 0000000000000000 [ 37.214954] x17: 000000040044ffff x16: 004000b2b5503510 x15: 0000006aaa1326d2 [ 37.222333] x14: 0000000000000232 x13: 0000000000000001 x12: 0000000000000040 [ 37.229718] x11: ffff04bb00400000 x10: 968f57bd39f701c8 x9 : ffff04bb0acc8674 [ 37.237095] x8 : fefefefefefefeff x7 : 0000000000000018 x6 : ffffd87abd90092c [ 37.244478] x5 : 0000000000000016 x4 : 0000000000000000 x3 : 0000000000000100 [ 37.251852] x2 : ffff04bb0a419020 x1 : 0000000000000100 x0 : 0000000000000100 [ 37.259235] Call trace: [ 37.261771] topology_update_thermal_pressure+0xec/0x100 [ 37.267266] qcom_lmh_dcvs_poll+0xbc/0x154 [ 37.271505] process_one_work+0x288/0x69c [ 37.275654] worker_thread+0x74/0x470 [ 37.279450] kthread+0xfc/0x100 [ 37.282712] ret_from_fork+0x10/0x20 [ 37.286417] irq event stamp: 74 [ 37.289664] hardirqs last enabled at (73): [] _raw_spin_unlock_irq+0x44/0x80 [ 37.298632] hardirqs last disabled at (74): [] __schedule+0x710/0xa10 [ 37.306885] softirqs last enabled at (58): [] _stext+0x410/0x588 [ 37.314778] softirqs last disabled at (51): [] __irq_exit_rcu+0x158/0x174 [ 37.323386] ---[ end trace 0000000000000000 ]--- Fixes: 275157b367f4 ("cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support") Signed-off-by: Dmitry Baryshkov --- drivers/cpufreq/qcom-cpufreq-hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index 44d46e52baea..d39a0ef9ea45 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -290,7 +290,7 @@ static unsigned int qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data) static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data) { struct cpufreq_policy *policy = data->policy; - int cpu = cpumask_first(policy->cpus); + int cpu = cpumask_first(policy->related_cpus); struct device *dev = get_cpu_device(cpu); unsigned long freq_hz, throttled_freq; struct dev_pm_opp *opp; From patchwork Sat Mar 26 15:51:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 554515 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 79F17C4167B for ; Sat, 26 Mar 2022 15:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233689AbiCZPxh (ORCPT ); Sat, 26 Mar 2022 11:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233694AbiCZPxg (ORCPT ); Sat, 26 Mar 2022 11:53:36 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17CDE13D30 for ; Sat, 26 Mar 2022 08:52:00 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id b43so9308295ljr.10 for ; Sat, 26 Mar 2022 08:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yMc1zE/A8/QUCb1FtTjagGiCgSImVddv9mvDKYNqv0I=; b=Uz6kx32hwE8pOqayjLZLNMtOBlEijXuCQ52gWxFEl1x7BQDHpJp6pg3KnFdMVfyFu5 OMg04yG7OXL137GWYeQz4hCYd1IsNnXsTQl3rsBb9B0LPrIMYO/un8xXztAej+/JdfTm J5Y9RZ++vfIHVREBcOJptKqdDeuF5/ddsIVlq6q1GJAr6NxOMTItpmpQtJWX9shkY7G2 FZeS3RNCvo7JLg0uEvOERUSQDZb1qjFovnhoMFDGeybjjwX7o9nz7NB/63WkQV/iRX2C PPs7xv9THQlAnTLg4PNawM5tYHjHVhQ5wDHaFfQk2FBjv6dBb45JkFbgdUJww0NzLLIf 9ofg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yMc1zE/A8/QUCb1FtTjagGiCgSImVddv9mvDKYNqv0I=; b=sz533VIX/r8g35tpksuHpNvs6rFt6WgsZeNAM1pt+zYyqVIvWYzIx+S+GEbm8jNpVo Q8gosdgvyVSAfuSJawrKfrzmlC8MMHSTDfWY18AzN1v2xtOtlTs29hoZMgrn0gHUKkCw yhZ/9dB737hlzOjDrODjc4qWH4mjJ+OFOZszLcT4zRtiwILEhGNjBhRn/Y3alpKN9sdC iYUWoqB7wHUXZzvAdLy6fOaeU11y5lNGq2oT1xlcuSfB3oeTHevlW/4Us63NFdLnFyTL azkzNz+zsAvvZf8msO3JLLCvjiPO6sSR4GavHPSdprNjO5bv1yHO1bt86groXhPPPWGz xLVw== X-Gm-Message-State: AOAM530lFGugO5smEd4rAS/x9gplKQZpzZTmRUXr2pkQbbTdmEUP/Y/V S8NLrXWqKr4ehNIt7wtnmCr9Rw== X-Google-Smtp-Source: ABdhPJxri4M5kZQrnEP37Jq7Ta7kGOo0dDQTtJj350jVvnpiIScf/nEPSCAmA4g92FxTb75aep0WxA== X-Received: by 2002:a2e:9593:0:b0:249:b90d:2544 with SMTP id w19-20020a2e9593000000b00249b90d2544mr6539830ljh.6.1648309918245; Sat, 26 Mar 2022 08:51:58 -0700 (PDT) Received: from eriador.lumag.spb.ru ([185.24.52.156]) by smtp.gmail.com with ESMTPSA id o17-20020a05651238b100b00443c898b598sm1097992lft.112.2022.03.26.08.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Mar 2022 08:51:57 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, Thara Gopinath , kernel test robot , Vladimir Zapolskiy Subject: [PATCH v4 3/4] cpufreq: qcom-hw: fix the opp entries refcounting Date: Sat, 26 Mar 2022 18:51:52 +0300 Message-Id: <20220326155153.7377-4-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> References: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The qcom_lmh_dcvs_notify() will get the dev_pm_opp instance for throttling, but will not put it, ending up with leaking a reference count and the following backtrace when putting the CPU offline. Correctly put the reference count of the returned opp instance. [ 84.418025] ------------[ cut here ]------------ [ 84.422770] WARNING: CPU: 7 PID: 43 at drivers/opp/core.c:1396 _opp_table_kref_release+0x188/0x190 [ 84.431966] Modules linked in: [ 84.435106] CPU: 7 PID: 43 Comm: cpuhp/7 Tainted: G S 5.17.0-rc6-00388-g7cf3c0d89c44-dirty #721 [ 84.451631] pstate: 82400005 (Nzcv daif +PAN -UAO +TCO -DIT -SSBS BTYPE=--) [ 84.458781] pc : _opp_table_kref_release+0x188/0x190 [ 84.463878] lr : _opp_table_kref_release+0x78/0x190 [ 84.468885] sp : ffff80000841bc70 [ 84.472294] x29: ffff80000841bc70 x28: ffff6664afe3d000 x27: ffff1db6729e5908 [ 84.479621] x26: 0000000000000000 x25: 0000000000000000 x24: ffff1db6729e58e0 [ 84.486946] x23: ffff8000080a5000 x22: ffff1db40aad80e0 x21: ffff1db4002fec80 [ 84.494277] x20: ffff1db40aad8000 x19: ffffb751c3186300 x18: ffffffffffffffff [ 84.501603] x17: 5300326563697665 x16: 645f676e696c6f6f x15: 00001186c1df5448 [ 84.508928] x14: 00000000000002e9 x13: 0000000000000000 x12: 0000000000000000 [ 84.516256] x11: ffffb751c3186368 x10: ffffb751c39a2a70 x9 : 0000000000000000 [ 84.523585] x8 : ffff1db4008edf00 x7 : ffffb751c328c000 x6 : 0000000000000001 [ 84.530916] x5 : 0000000000040000 x4 : 0000000000000001 x3 : ffff1db4008edf00 [ 84.538247] x2 : 0000000000000000 x1 : ffff1db400aa6100 x0 : ffff1db40aad80d0 [ 84.545579] Call trace: [ 84.548101] _opp_table_kref_release+0x188/0x190 [ 84.552842] dev_pm_opp_remove_all_dynamic+0x8c/0xc0 [ 84.557949] qcom_cpufreq_hw_cpu_exit+0x30/0xdc [ 84.562608] cpufreq_offline.isra.0+0x1b4/0x1d8 [ 84.567270] cpuhp_cpufreq_offline+0x10/0x6c [ 84.571663] cpuhp_invoke_callback+0x16c/0x2b0 [ 84.576231] cpuhp_thread_fun+0x190/0x250 [ 84.580353] smpboot_thread_fn+0x12c/0x230 [ 84.584568] kthread+0xfc/0x100 [ 84.587810] ret_from_fork+0x10/0x20 [ 84.591490] irq event stamp: 3482 [ 84.594901] hardirqs last enabled at (3481): [] call_rcu+0x39c/0x50c [ 84.603119] hardirqs last disabled at (3482): [] el1_dbg+0x24/0x8c [ 84.611074] softirqs last enabled at (310): [] _stext+0x410/0x588 [ 84.619028] softirqs last disabled at (305): [] __irq_exit_rcu+0x158/0x174 [ 84.627691] ---[ end trace 0000000000000000 ]--- Fixes: 275157b367f4 ("cpufreq: qcom-cpufreq-hw: Add dcvs interrupt support") Reported-by: kernel test robot Tested-by: Vladimir Zapolskiy Reviewed-by: Vladimir Zapolskiy Reviewed-by: Bjorn Andersson Signed-off-by: Dmitry Baryshkov --- drivers/cpufreq/qcom-cpufreq-hw.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index d39a0ef9ea45..db67daed99a3 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -305,12 +305,18 @@ static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data) opp = dev_pm_opp_find_freq_floor(dev, &freq_hz); if (IS_ERR(opp) && PTR_ERR(opp) == -ERANGE) - dev_pm_opp_find_freq_ceil(dev, &freq_hz); + opp = dev_pm_opp_find_freq_ceil(dev, &freq_hz); - throttled_freq = freq_hz / HZ_PER_KHZ; + if (IS_ERR(opp)) { + dev_warn(dev, "Can't find the OPP for throttling: %pe!\n", opp); + } else { + throttled_freq = freq_hz / HZ_PER_KHZ; + + /* Update thermal pressure (the boost frequencies are accepted) */ + arch_update_thermal_pressure(policy->related_cpus, throttled_freq); - /* Update thermal pressure (the boost frequencies are accepted) */ - arch_update_thermal_pressure(policy->related_cpus, throttled_freq); + dev_pm_opp_put(opp); + } /* * In the unlikely case policy is unregistered do not enable From patchwork Sat Mar 26 15:51:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 555483 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 8A01FC433F5 for ; Sat, 26 Mar 2022 15:52:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233694AbiCZPxj (ORCPT ); Sat, 26 Mar 2022 11:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233700AbiCZPxi (ORCPT ); Sat, 26 Mar 2022 11:53:38 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6883FDEDD for ; Sat, 26 Mar 2022 08:52:01 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 5so18020816lfp.1 for ; Sat, 26 Mar 2022 08:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lyl1W6wKqtyKB0huqnjGmmgWTKJ3Eh0knQy19kaAlKw=; b=Li8C0VkJ04oW5QoWZMZYBwVbSX3yZOtaLyHtGbCt2USVLLJ30uhzQavxx8HXRjAvp0 hSEnh2gtwiGrr8GYQtF5pwN38IeabcU/m3i/ieOP1HbIrdHs4Wccygy6jpdNSOEzAzDL SdRpjbhf6SYpK8RPa6OxKUguxZCAwqrBhg8AMK9cjCdDOpmrVuz7W53GzOZc7itL6cw2 I4PjpQ868di8YZ6ROkGYWhQm9m63wG2g7ChHbW9n6RFAxBszfz9DzCZGMPdiX3bcW5Sj /u+fdeW5wCLYqL6iDxn5PhgSewGvWIf0SOyca2T4heWt/g0I18dm1LI90CSNzfmDf7C/ LBpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lyl1W6wKqtyKB0huqnjGmmgWTKJ3Eh0knQy19kaAlKw=; b=njk8uU8kJo0HI7CtU+PkFG/OBLdWYv9+Kj6omFZVaVf+PhokPbCbkeVtzv7qyc9kc4 j/0a0AtKPCZ4eXwSVtuP/0kCJzahGDCNA+A9N0VBlNIk4RMICoJJ8/XAW8wnOLx+61zq 6TSTCZMU7FEpDqmrB3h2Giv/NAj/ZwSnXys/gl7wXlWL8NDRagtXKosRX/fkFQvVlBw4 3x+Q7l/6KlkiqH/WNNk9Au9bJ2vichmKg6o3ehGOuiotIuO486VITGK3WaCX2ZeJCxtz 9oRmMvmfvNL+PkG8QBxVGdlOFsX5RY0Aa6rKAL+V1Zc2e9lptp0KTahm+FzMDYPkT2Hu 1r5Q== X-Gm-Message-State: AOAM531Ej4N7dx3O/69KJ3oJe3a96oT1/sDBdQ0V4eOH80sQ+hBzbPzW SDbi4DHig11eSQde4V4xGN3mLA== X-Google-Smtp-Source: ABdhPJy3U8/INt1qIpVyEF3mcSR5UdtZbEmeLz+KiiN/4y3B2cUUlyG/pW7VT7YZqCVL3zgJlrCKJQ== X-Received: by 2002:a05:6512:ea7:b0:44a:2d87:fffc with SMTP id bi39-20020a0565120ea700b0044a2d87fffcmr12224140lfb.290.1648309919549; Sat, 26 Mar 2022 08:51:59 -0700 (PDT) Received: from eriador.lumag.spb.ru ([185.24.52.156]) by smtp.gmail.com with ESMTPSA id o17-20020a05651238b100b00443c898b598sm1097992lft.112.2022.03.26.08.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Mar 2022 08:51:58 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , "Rafael J. Wysocki" , Viresh Kumar Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, Thara Gopinath , Vladimir Zapolskiy Subject: [PATCH v4 4/4] cpufreq: qcom-hw: provide online/offline operations Date: Sat, 26 Mar 2022 18:51:53 +0300 Message-Id: <20220326155153.7377-5-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> References: <20220326155153.7377-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Provide lightweight online and offline operations. This saves us from parsing and tearing down the OPP tables each time the CPU is put online or offline. Tested-by: Vladimir Zapolskiy Reviewed-by: Vladimir Zapolskiy Reviewed-by: Bjorn Andersson Signed-off-by: Dmitry Baryshkov --- drivers/cpufreq/qcom-cpufreq-hw.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c index db67daed99a3..b0282898168e 100644 --- a/drivers/cpufreq/qcom-cpufreq-hw.c +++ b/drivers/cpufreq/qcom-cpufreq-hw.c @@ -423,10 +423,26 @@ static int qcom_cpufreq_hw_lmh_init(struct cpufreq_policy *policy, int index) return 0; } -static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data) +static int qcom_cpufreq_hw_cpu_online(struct cpufreq_policy *policy) { + struct qcom_cpufreq_data *data = policy->driver_data; + struct platform_device *pdev = cpufreq_get_driver_data(); + int ret; + + ret = irq_set_affinity_hint(data->throttle_irq, policy->cpus); + if (ret) + dev_err(&pdev->dev, "Failed to set CPU affinity of %s[%d]\n", + data->irq_name, data->throttle_irq); + + return ret; +} + +static int qcom_cpufreq_hw_cpu_offline(struct cpufreq_policy *policy) +{ + struct qcom_cpufreq_data *data = policy->driver_data; + if (data->throttle_irq <= 0) - return; + return 0; mutex_lock(&data->throttle_lock); data->cancel_throttle = true; @@ -434,6 +450,12 @@ static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data) cancel_delayed_work_sync(&data->throttle_work); irq_set_affinity_hint(data->throttle_irq, NULL); + + return 0; +} + +static void qcom_cpufreq_hw_lmh_exit(struct qcom_cpufreq_data *data) +{ free_irq(data->throttle_irq, data); } @@ -590,6 +612,8 @@ static struct cpufreq_driver cpufreq_qcom_hw_driver = { .get = qcom_cpufreq_hw_get, .init = qcom_cpufreq_hw_cpu_init, .exit = qcom_cpufreq_hw_cpu_exit, + .online = qcom_cpufreq_hw_cpu_online, + .offline = qcom_cpufreq_hw_cpu_offline, .register_em = cpufreq_register_em_with_opp, .fast_switch = qcom_cpufreq_hw_fast_switch, .name = "qcom-cpufreq-hw",