From nobody Thu Apr 30 09:43:27 2026 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 1FF85C433F5 for ; Thu, 26 May 2022 11:51:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238588AbiEZLvg (ORCPT ); Thu, 26 May 2022 07:51:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232236AbiEZLvb (ORCPT ); Thu, 26 May 2022 07:51:31 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE1F02CDF9 for ; Thu, 26 May 2022 04:51:30 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id d129so1132897pgc.9 for ; Thu, 26 May 2022 04:51:30 -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=b6k3SV/2S1GAZa9ElYwCPu3QFpy6+7ouZdodLYF77Eg=; b=legUHLb2Ee0bshJ1QbJG8LcjSMIqtKRbixMePTPiZEcUDPkkQFN267HpCA1jFH2J7i rGS0iYDVjK1GC0GvSFOiqQLKen+vc+VtZ8EOXdLo/qPxcFmymLIexh6kgJumiN7mYFj+ J6rKWsicVRH3v9GpAakUPk4AfDJntjsKM5FLceeHrpnToV+987nv/FzLNy3S4+K3FZ2F rUV23pJ0j80ZpHT6uoNmAWM4IrQSfpzcR66leo/NeCjGXGFkvm28a/h8bynAShdfBsGL 45+k1NsfTemXBUIlqh9sUL4pzdUAroSSOqM4749wgnNV1SQRFxgG6KXvm19oZ0GjzMsN f4xw== 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=b6k3SV/2S1GAZa9ElYwCPu3QFpy6+7ouZdodLYF77Eg=; b=Lmxqg6nhvl9wL0SbNbepU4MpCO0I7NU3qmORBGHOPompzvwsjwhkn/mfT+Mfy2Okj9 B2ZftvoO9KTwixZrGEjY/ijvjaH8amGO/CL96+JP73G1OdN6o8nN6c1egmV+I5JaVv+u rSpaaehrbOjRKMISkP4wZzGMOYLVH7LJ9LL+dgYvbJbxV049YxcAXrZ6QxdDvrU/hCLA fCmIKVDHmAGazejw2DkKsOEVVtNp9EDkb4u5k7h/PUepg7zZ7+3qESQT97xwBbfOGxX0 xNuNbs8bj31N6t2MqD+RskfroDTREl3ygxBiwobTKmgupW5s2jE2G4nm9u840y1FG4P/ ++7w== X-Gm-Message-State: AOAM531OmlPx0ZAksLk+BwqFJJBJjK8jmh/S6Eo2z3dIS5IyR46ciQBV nBLc2uMCYq6mG5U1fJyS6T4Pf4wvqOJ2Jg== X-Google-Smtp-Source: ABdhPJwZOiTJevyRe6XAQM2vVij0hiPhs8czMbGSWZxAAmYgERefN9RdPvVJGaeJvUfNt/FVir8xcA== X-Received: by 2002:a63:5cb:0:b0:3f6:3a45:a479 with SMTP id 194-20020a6305cb000000b003f63a45a479mr31263406pgf.242.1653565890428; Thu, 26 May 2022 04:51:30 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id f7-20020a170902ab8700b0015e8d4eb272sm1295713plr.188.2022.05.26.04.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:51:30 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] cpufreq: Optimize cpufreq_show_cpus() Date: Thu, 26 May 2022 17:21:19 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of specially adding a space for each CPU, except the first one, lets add space for each of them and remove it at the end. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2cad42774164..e24aa5d4bca5 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -843,12 +843,14 @@ ssize_t cpufreq_show_cpus(const struct cpumask *mask,= char *buf) unsigned int cpu; =20 for_each_cpu(cpu, mask) { - if (i) - i +=3D scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); - i +=3D scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); + i +=3D scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); if (i >=3D (PAGE_SIZE - 5)) break; } + + /* Remove the extra space at the end */ + i--; + i +=3D sprintf(&buf[i], "\n"); return i; } --=20 2.31.1.272.g89b43f80a514 From nobody Thu Apr 30 09:43:27 2026 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 03A38C433EF for ; Thu, 26 May 2022 11:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239280AbiEZLvo (ORCPT ); Thu, 26 May 2022 07:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234299AbiEZLvg (ORCPT ); Thu, 26 May 2022 07:51:36 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C37D0288 for ; Thu, 26 May 2022 04:51:33 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id q18so1220508pln.12 for ; Thu, 26 May 2022 04:51:33 -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=gkz2dsQcdq8VoLgJuf+4xRTABrCVsHR/qCSkvr7/nrc=; b=W+zIJqWIAnNtDMXC64J9UUubmqB8QkQBkUYBIXLOKj311EPmc1jgvchw5SJZWrKHfp jHMyZxiX82kcbklSeJF7qm7Tknb6jf2yxBeCYVI+DFe+asQgOpFPaLGPJdhSuT3pUk+A yiMl5V3f36aPFAh3dL88wpJ3V5Xk6isXruwJ8OEyVptVArVh35qkRUDY1pBPjcxW82NG veFXYcZrPBgKbfVM2oxjiJtsIS2Y5K0MZx5YHmm6BWm/aKWHKMUTRIFSAn/PEEnGro6v aZH/U8lGxkBvdVW2a7z36xRAJhB7qdwSXtBYBFZ4GeLMAzE3/MxYiU5acayCwKbSfPBi elyQ== 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=gkz2dsQcdq8VoLgJuf+4xRTABrCVsHR/qCSkvr7/nrc=; b=3MYz6T4RIm2tw2OVPq8dQV60tc9coCGTwpUpJU+LIB1+bbvYBJVy/R6um8v0i5wsuq vINb8zJo5jSTDXnIBhRRBE+uO1RGi74FaTDQ+h2stUyIU9Hd/uY1woVzmZaG/DYEhoZR 7QoNFB4owd8Liv92UoD+4vxxnaOiHEvpQ0qSJb5eiCez+xmxjtUWMTOyTJuM71FhY9n4 26iokT7sz2JrlHZL6uY109IBo0m6tVLJHbQInfhaOKIQcPF/KwlrpCXt6O8747d3i3tt 9HHM7RBNrLWWAv1920fII3eCGISTbj4wqlLdq/Mnd4lNkG0tk5zsUNdUj1ikFa6FZ0av 2HlQ== X-Gm-Message-State: AOAM532Pd23a7xmXf/NOaa5LJnzyq9MYGR+O176m9apvh1XD0irx39kH QPYdZZK/vQrMoawTam8gcZGjKg== X-Google-Smtp-Source: ABdhPJx0Sxdx2kcAKXhchnTBeCUspjgJvQRJF9QJZzR4OnEVwhPRyUbOBpDtZEvUec2jXPVOApFUKg== X-Received: by 2002:a17:902:dac3:b0:161:a5b5:c8c0 with SMTP id q3-20020a170902dac300b00161a5b5c8c0mr37146046plx.61.1653565893094; Thu, 26 May 2022 04:51:33 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id q17-20020a170902b11100b0015e8d4eb297sm1308401plr.225.2022.05.26.04.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:51:32 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] cpufreq: Panic if policy is active in cpufreq_policy_free() Date: Thu, 26 May 2022 17:21:20 +0530 Message-Id: <8c3d50faf8811e86136fb3f9c459e43fc3c50bc0.1653565641.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With the new design in place, show/store callbacks check if the policy is active or not before proceeding further and cpufreq_policy_free() must be called after emptying policy->cpus mask, i.e. inactive policy. Lets make sure we don't get a bug around this later and catch this early by putting a BUG_ON() within cpufreq_policy_free(). Signed-off-by: Viresh Kumar Reported-by: kernel test robot --- drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index e24aa5d4bca5..53d163a84e06 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1284,6 +1284,12 @@ static void cpufreq_policy_free(struct cpufreq_polic= y *policy) unsigned long flags; int cpu; =20 + /* + * The callers must ensure the policy is inactive by now, to avoid any + * races with show()/store() callbacks. + */ + BUG_ON(!policy_is_inactive(policy)); + /* Remove policy from list */ write_lock_irqsave(&cpufreq_driver_lock, flags); list_del(&policy->policy_list); --=20 2.31.1.272.g89b43f80a514 From nobody Thu Apr 30 09:43:27 2026 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 D7D5DC433F5 for ; Thu, 26 May 2022 11:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239704AbiEZLwA (ORCPT ); Thu, 26 May 2022 07:52:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242594AbiEZLvk (ORCPT ); Thu, 26 May 2022 07:51:40 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84DF1D028E for ; Thu, 26 May 2022 04:51:36 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id c14so1519713pfn.2 for ; Thu, 26 May 2022 04:51:36 -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=SuD+IeYmhbuPPKbQaLeWJifIw5WrOViKtE4MNYTGhEc=; b=MJJd8mcwXvIYK+3ZoefV3P1LDFLFmU/DxrSHxJ8Vka7Kv6sxUV8BnlK+0vXwRxHixY tNBrQt9GXuWP8kXRPSHXCv6ojYuE8EV0NU05t4AK2TH0Xj/6/zPOR9OfDlX/5uP5ANB2 RmtnwdCPsKZAPGd0uY8O+QTFOYriS/QSf+0EUW2rAxuJzYcRx+DmKDSXggFk4puyrJ+s JHcylp38zsVwVlNXaARQe6evH15qH0AkCuKcBLyFVlw1oowL4MePCxaxQIoC1NbcNeRd aZUNGKNpirsCqabwjXStlm53jUOOI0DTTtG8Ewl9YaUlHMXCyGXE9T6i3en2Vufvac4w 4KjQ== 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=SuD+IeYmhbuPPKbQaLeWJifIw5WrOViKtE4MNYTGhEc=; b=l+it0zY3uDpWc00z0kyLwEZ4awaoo4lT+GSUL7CeJ3IUdE6ZTCJELj8FSr02CU2tCI DkDmemrlMFwfbYE9d9vzcyvtu085R5bqKxhMmgPpbIzYH2Lf9Q0sZgt45vgFg2Lt/oPk Y8hbMDSfVDvY5bs9L+EW/IVYEEpL2YwkVzjF+TsAN+fvDh2sfrDHNN/vGvz0hmXhZhAo 4h7UfLkkOeXyEuCKlcmL//brelnFojph7IgFREzXqJQNWnwGhwrBV20BXcRFJSQ4mCML kZQzE0ANyblx5QkCQmUSdMgoSSPWO4LQoEc9+cHhHrOXv469VPZydhxHJkQX6tOi97e1 bCRQ== X-Gm-Message-State: AOAM5331u7Z3LiCGQ0KQnhBjRqEaZ/RyvlDNJVNhYfrnpC5iGJz9A/NP SkCsPC/Eea0knJ2A4V/PtS7cdg== X-Google-Smtp-Source: ABdhPJy+86/Oq5RBDJQwemDyFUTj+4rVrb8/nToo3syC1YcNDL0LwghNJ1zctJtPfY9rpOGF2aVx1g== X-Received: by 2002:a63:8ac1:0:b0:3fa:d86b:c76d with SMTP id y184-20020a638ac1000000b003fad86bc76dmr7334098pgd.418.1653565895674; Thu, 26 May 2022 04:51:35 -0700 (PDT) Received: from localhost ([122.162.234.2]) by smtp.gmail.com with ESMTPSA id b11-20020aa7810b000000b0050dc762814bsm1317345pfi.37.2022.05.26.04.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 May 2022 04:51:35 -0700 (PDT) From: Viresh Kumar To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] cpufreq: Drop unnecessary cpus locking from store() Date: Thu, 26 May 2022 17:21:21 +0530 Message-Id: <0a6620ff5a330126b21d00244d4fad62cff4f230.1653565641.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This change was introduced long back by: commit 4f750c930822 ("cpufreq: Synchronize the cpufreq store_*() routines w= ith CPU hotplug") Since then, both cpufreq and hotplug core have been reworked and have much better locking in place. The race mentioned in commit 4f750c930822 isn't possible anymore. Drop the unnecessary locking. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 53d163a84e06..bb237d1ce5e7 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -973,21 +973,10 @@ static ssize_t store(struct kobject *kobj, struct att= ribute *attr, if (!fattr->store) return -EIO; =20 - /* - * cpus_read_trylock() is used here to work around a circular lock - * dependency problem with respect to the cpufreq_register_driver(). - */ - if (!cpus_read_trylock()) - return -EBUSY; - - if (cpu_online(policy->cpu)) { - down_write(&policy->rwsem); - if (likely(!policy_is_inactive(policy))) - ret =3D fattr->store(policy, buf, count); - up_write(&policy->rwsem); - } - - cpus_read_unlock(); + down_write(&policy->rwsem); + if (likely(!policy_is_inactive(policy))) + ret =3D fattr->store(policy, buf, count); + up_write(&policy->rwsem); =20 return ret; } --=20 2.31.1.272.g89b43f80a514