Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2240340ybl; Sun, 19 Jan 2020 22:31:14 -0800 (PST) X-Google-Smtp-Source: APXvYqzSmlqFFP5tEv+wY8PTTYZHykrAkda0l/bCML6YBAz6e0wvHfej+sg6iJwOiaDN5q9W36Xq X-Received: by 2002:aca:de06:: with SMTP id v6mr11663712oig.168.1579501874426; Sun, 19 Jan 2020 22:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579501874; cv=none; d=google.com; s=arc-20160816; b=RlfttCc1nkjJedstaxIiLpG88E4I1YatSqlc/XI/MnTqUVpwTuxtTMfzyCp/I8/v/f 3XmvB3mQd+27ZT8v9Mm+9KX6c35ZucDuehSCGu8VDtdPfBS59Fq5z3XHNeIahKGvtkA8 r7cgntHd++UNLLHwQqqmCs4Duv4+Hcc9C7ibaybW2v08pHk/IxCWgSKdmlGsuiKVcRYi 9SXeR4DBjx67WnCtBzNdvya1DqE35kvX2ornSgrmLB3YRCNGLG/amRAQr4IEVLpBg++5 f7hUgobU9vK2a39udaDFw7+AmI7Bw/umv2QO+4zDRwm+ofw6w610wO/ZUeIJRhGcxhmt 1F9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xf1QiuMf0hHigZRu4/cbzAY/tfWYTII9JMzw/Trme34=; b=wYf6zAL39G1wjoqf5sqcRx0f7BLDmnznE2LGhWmjxM225mk5uxohUbFhte+9hAzlhg NakkA2ZeAVDmyGhd3qmGa5Tt9hIrxCBrGJ9TZ2IAI6LIXQmvaloq54KiRvy2zfTEUHFm XECXeDZcl+IoTVpVWngN7csLpI5dUEruNSNdvYJwr585V+hoKdNl2PRV/Q+hWp72tfS7 c7TFrz9Jd73jPxnuosElgJKTupleKHzCpgzUrQn8C7e4M8B9eNH6fK8OWq89HykyhN0l ppPWW+dFh4EGLLNisuIS48c2UwPSszF247ghD3AHlxb7JCqFxnNo6W1vH9+2n17MDQNz BvXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a4KwANnE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8si19625956otk.283.2020.01.19.22.31.01; Sun, 19 Jan 2020 22:31:14 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=a4KwANnE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726089AbgATGaI (ORCPT + 99 others); Mon, 20 Jan 2020 01:30:08 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42124 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbgATGaI (ORCPT ); Mon, 20 Jan 2020 01:30:08 -0500 Received: by mail-pg1-f196.google.com with SMTP id s64so15009918pgb.9 for ; Sun, 19 Jan 2020 22:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xf1QiuMf0hHigZRu4/cbzAY/tfWYTII9JMzw/Trme34=; b=a4KwANnE2EZL0qHoQ+SpxO0bZOErxLwdUS0tR0s7vjU16+pCr7d4tI9/7tAX0OGxeR 3Ujo0XFEL87E+PdvBn2VRM+jsvPd2lMNk8IRvMi4wKEtsaUefWlemKt1vgyXmV/khhne K/u694w8gbMQGifnS1TPubDWXRqBFmXyP0iFa8VZc7u6r/pTclt0FYbOSuJzsuzWmQjX mO8hh8Qiy7JFvaE/M8uOtRoHwFt2PaVWVg3QOIP4XQjFZd9AwxSvxo6IRFm7rDzXbTrV JZl4NXasmhTp9ep6O0CWO2J2Lakjya3kwlqcOy/eJZfLYJiUkb3R3rE3xLq87vazhNi7 wANA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xf1QiuMf0hHigZRu4/cbzAY/tfWYTII9JMzw/Trme34=; b=oprBPqWIARbviElVZXkmjnp/yYHfS/4bvIzIGR8g0FTj4Zm8jfNvPEAVHVRtNoBare 5T7cvDT6vem0/46kNh73nd5gdNY8Pg4fgFdSH+fJgJyaVLmt9WuWZqUy8QFz+W20mO1S aYv92ddXmxrD2f8esSvos9h7NcTZFji1znhZYo03o+Lk7q62Dnu903Rwu+MGIV2sWe76 hrCrCynYGafBTBAoxt6iTIFRRJtV2DIniVv5+cX0Qj9s0KByWXNknnyL886vo1cAAOL6 ZLxw0uyzYVzX2CAj20VpnyVij5vpuQgpJhxXO0mPtJ+AZ76x+PIoquUoZ7+/Zwq58ebj 5ENg== X-Gm-Message-State: APjAAAV5EsJhJqU6ZGwqHRYMovHTfVPDIIHoxjynC/n4pD20/vJt5wnq 1FPqST/YVUBe4VfumfIdz62ZFA== X-Received: by 2002:a62:1889:: with SMTP id 131mr15707948pfy.250.1579501807380; Sun, 19 Jan 2020 22:30:07 -0800 (PST) Received: from localhost ([122.172.71.156]) by smtp.gmail.com with ESMTPSA id g9sm38268658pfm.150.2020.01.19.22.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Jan 2020 22:30:06 -0800 (PST) Date: Mon, 20 Jan 2020 12:00:04 +0530 From: Viresh Kumar To: chenqiwu Cc: mmayer@broadcom.com, rjw@rjwysocki.net, f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, chenqiwu Subject: Re: [PATCH v3] cpufreq: brcmstb-avs: fix imbalance of cpufreq policy refcount Message-ID: <20200120063004.zzhep35vfl3urndd@vireshk-i7> References: <1579417750-21984-1-git-send-email-qiwuchen55@gmail.com> <20200120053250.igkwofqfzvmqb3c3@vireshk-i7> <20200120055822.GB5185@cqw-OptiPlex-7050> <20200120060134.izotrbzjvzk327zx@vireshk-i7> <20200120061356.GA5605@cqw-OptiPlex-7050> <20200120062126.nmxaqhcpqcojuihr@vireshk-i7> <20200120062756.GA5802@cqw-OptiPlex-7050> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200120062756.GA5802@cqw-OptiPlex-7050> User-Agent: NeoMutt/20180716-391-311a52 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20-01-20, 14:27, chenqiwu wrote: > On Mon, Jan 20, 2020 at 11:51:26AM +0530, Viresh Kumar wrote: > > On 20-01-20, 14:13, chenqiwu wrote: > > > On Mon, Jan 20, 2020 at 11:31:34AM +0530, Viresh Kumar wrote: > > > > On 20-01-20, 13:58, chenqiwu wrote: > > > > > On Mon, Jan 20, 2020 at 11:02:50AM +0530, Viresh Kumar wrote: > > > > > > On 19-01-20, 15:09, qiwuchen55@gmail.com wrote: > > > > > > > From: chenqiwu > > > > > > > > > > > > > > brcm_avs_cpufreq_get() calls cpufreq_cpu_get() to get the cpufreq policy, > > > > > > > meanwhile, it also increments the kobject reference count to mark it busy. > > > > > > > However, a corresponding call of cpufreq_cpu_put() is ignored to decrement > > > > > > > the kobject reference count back, which may lead to a potential stuck risk > > > > > > > that the cpuhp thread deadly waits for dropping of kobject refcount when > > > > > > > cpufreq policy free. > > > > > > > > > > > > > > For fixing this bug, cpufreq_get_policy() is referenced to do a proper > > > > > > > cpufreq_cpu_get()/cpufreq_cpu_put() and fill a policy copy for the user. > > > > > > > If the policy return NULL, we just return 0 to hit the code path of > > > > > > > cpufreq_driver->get. > > > > > > > > > > > > > > Signed-off-by: chenqiwu > > > > > > > --- > > > > > > > drivers/cpufreq/brcmstb-avs-cpufreq.c | 12 ++++++++++-- > > > > > > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > index 77b0e5d..ee0d404 100644 > > > > > > > --- a/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > +++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c > > > > > > > @@ -452,8 +452,16 @@ static bool brcm_avs_is_firmware_loaded(struct private_data *priv) > > > > > > > > > > > > > > static unsigned int brcm_avs_cpufreq_get(unsigned int cpu) > > > > > > > { > > > > > > > - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); > > > > > > > > > > > > Why can't we just add a corresponding cpufreq_cpu_put() instead of all this ? > > > > > > > > > > > > > > > > cpufreq_get_policy() does a proper cpufreq_cpu_get()/cpufreq_cpu_put(), > > > > > meanwhile fills a policy copy for the user. It equals to using > > > > > cpufreq_cpu_get() and a corresponding cpufreq_cpu_put() around access > > > > > to the policy pointer. I think both methods are fine here. > > > > > What do you think? > > > > > > > > cpufreq_get_policy() does an extra memcpy as well, which isn't required at all > > > > in your case. > > > > > > > > -- > > > > viresh > > > > > > Huha..Do you worry about the race conditon with cpufreq policy free path? > > > > No. I just worry about an unnecessary memcpy, nothing else. > > > Is there any question about this extra memcpy? What do you mean by that? The whole point I am trying to make is that for your specific case, doing an explicit cpufreq_cpu_get() and cpufreq_cpu_put() is far more efficient than calling cpufreq_get_policy() which has a different purpose and usecase. -- viresh