From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AF2DECDE5F for ; Mon, 23 Jul 2018 19:28:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6DF220856 for ; Mon, 23 Jul 2018 19:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6DF220856 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388078AbeGWUai (ORCPT ); Mon, 23 Jul 2018 16:30:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40132 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388022AbeGWUai (ORCPT ); Mon, 23 Jul 2018 16:30:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EBBB4059FF8; Mon, 23 Jul 2018 19:27:57 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-175.bos.redhat.com [10.18.17.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id E60352166BA0; Mon, 23 Jul 2018 19:27:56 +0000 (UTC) Subject: Re: [PATCH 2/2] cpufreq: Fix a circular lock dependency problem To: Peter Zijlstra Cc: "Rafael J. Wysocki" , Viresh Kumar , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, "Paul E. McKenney" , Greg Kroah-Hartman , Konrad Rzeszutek Wilk References: <1532368179-15263-1-git-send-email-longman@redhat.com> <1532368179-15263-3-git-send-email-longman@redhat.com> <20180723191627.GJ2494@hirez.programming.kicks-ass.net> From: Waiman Long Organization: Red Hat Message-ID: <0306d1b7-85d2-5e50-2b7c-466f0e978afa@redhat.com> Date: Mon, 23 Jul 2018 15:27:56 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180723191627.GJ2494@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Jul 2018 19:27:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 23 Jul 2018 19:27:57 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'longman@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/23/2018 03:16 PM, Peter Zijlstra wrote: > On Mon, Jul 23, 2018 at 01:49:39PM -0400, Waiman Long wrote: >> drivers/cpufreq/cpufreq.c | 16 +++++++++++++++- >> 1 file changed, 15 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c >> index b0dfd32..9cf02d7 100644 >> --- a/drivers/cpufreq/cpufreq.c >> +++ b/drivers/cpufreq/cpufreq.c >> @@ -922,8 +922,22 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr, >> struct cpufreq_policy *policy = to_policy(kobj); >> struct freq_attr *fattr = to_attr(attr); >> ssize_t ret = -EINVAL; >> + int retries = 3; >> >> - cpus_read_lock(); >> + /* >> + * cpus_read_trylock() is used here to work around a circular lock >> + * dependency problem with respect to the cpufreq_register_driver(). >> + * With a simple retry loop, the chance of not able to get the >> + * read lock is extremely small. >> + */ >> + while (!cpus_read_trylock()) { >> + if (retries-- <= 0) >> + return -EBUSY; >> + /* >> + * Sleep for about 50ms and retry again. >> + */ >> + msleep(50); >> + } > That's atrocious. > > I had thought about just returning an error if the trylock fails as CPU hotplug rarely happened. I can revert to that simple case if others have no objection. Cheers, Longman