From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C191C35AC12 for ; Wed, 2 Sep 2026 04:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788323407; cv=none; b=m0XlHm18Y7okVlbY2gZ9q36S9Jxy0/MzI7CMg4FuYs72Wsa53ekXhL2FZbGBI7/APqXYZGy18tTWLYPIrRsr5s7if4b+JkndfVomq3Fud8PCwwu+jlFw43k+5Bh03iNPurHFNS2ar2WqYOCNALFLanZCsbyQUaAC9KYJNzRdAx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788323407; c=relaxed/simple; bh=mdgPcZlJL3HWscq7fjKdXipWCBSy4NPqNPPDd1WmTxo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RH6k1luP93l7/NmaQIY3XBm0olx9aSWlh9Jdgtl0e9Usl6gUgv74Kmv0VzFhFncoQZ9lxhBLr9o24ib+dQ6PhQLMtlgV5f/IV7u4jGLTpsvBcaJFIuWPBXWEPR39U5zlgxIqjuMhwAMexzHrNHOZPO7x6ExxS2zkrGmG+XghTyQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=kylzrvcP; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="kylzrvcP" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2d032846c95so6594245ad.1 for ; Tue, 01 Sep 2026 21:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1788323405; x=1788928205; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=loEECbV+1/PD6+b04t7A4hFCdkNgi7Lwbp3peMcWJ+A=; b=kylzrvcPW8My5uGhAq8czS7VAOEfT8rkcQe94tAojm3tHSRNYNryv6HN4D3qIN+WWK w6Dnb8dUN35NtcaUQy350VObn+ygPV8wP5ug6Qawvk8SLLDrQovJdAvr6mslghmzitoP rt8iSVzjiWBakSYlLVSA+P0jMLGSzHYFquAvs60MR8LNb3Xspa8orIjnD4eNNrVwXz65 Ze5oqM4LPHNL5iAWhb6kMSBrRWCsYr3qtiwnF1//7nX2ovn4rD6pWgJjatQC+kIMeCfb T7Oz2JeUucqB85AuTM2OVMJzRqWRT0IDnvoWgd+9wDQTyO8k6OAL1Kp557nikhFGJSEj NlaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788323405; x=1788928205; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=loEECbV+1/PD6+b04t7A4hFCdkNgi7Lwbp3peMcWJ+A=; b=VBkpnfkChC7aKR9LKaUoJpQXndMq4mO7WFJ6mE0tEZMcXl7qb1xK/Sa/XUMy1BFajG otwCmi9uT95ZgDlV86qR0jwzg+pK66Bwdz9kttzn9pOEnJRqF27xt7BH/yhr3QznmvmX 1BbFgJAZVOGdiCBL8p3iMmGAw9nRL5uurtiWGYV3yGMmN78c2YNnZ3mkaREz9j9fgnDK CA/9Um/ekpvosrSlyaJpbjoxVxYLeZzRJDexxxY1PN/xRwWvKV5/ijP0A2WMK2FzW8FK w1GmPOa4xH1T7z6eWcodW29SEhUn7q26qKhJsr8oQd/ZjftbEFMQFhXJOTXQs3UPPf3R 0yPw== X-Forwarded-Encrypted: i=1; AKwUvBx/7e2zHHuJHJCU2U62LsJD8subR9BHaOv/qbwi66m40+f5rzE1vMUZN16u0QEethXMYEzIDSb1fgzzopw=@vger.kernel.org X-Gm-Message-State: AFuF++lVcoqXU+9mO8HJTJ2qjpxrc7fuS7or4Q7YnF7yb3Y8VS6yqmOd epk5xRVs/oOgqHLaTEcKRsIdy8RaSDfRqORfj4ciFPVH5XatvukPMaGS36vB+6l/tXs= X-Gm-Gg: AYBFou1+HlNXQnF9WwKjeSefz9h+WWo1yIZdYo3HMJNhHl6USroFmSuM8EsHZyuqqbd CmwTN0SlNKLhAi/AWtDK5wadJX3PoMvRuf2x6elVy++z9/po4uNlh1jYV64JIVtwwahaWBrKBqs gqzEG+/HCfJO+GOfxFah+fFEg2OUagcY0iGv9bY6D95Jebfxllf6Z6ZhZ5cVeuVQLX0OB+KleiZ IhnaOkPlCK+dKbX7oFlIQT0fPUC82Ep3E+9mGob3FYjmpIviVhRnA8dN962ILC0opVhqxtesSy5 VYlzobWYwz4ml92tJR6FjGg4FJWj+f3HN0N/nmBiMbxB/CJoccdsjbmkmHelCB5lcDVvhaByB3h OURDP1FdlZosl33hLyLLKoTwichD7J6/6R9UKAS8UVxDRhdAjkMCA6uCgIZQr1+1ShlLxCRmTxJ 9/uJRK4zSw1MC8ArGJOV5/6eL2XwZ2trhCSrdAIuqM8sOj+5oMeNW65Knt3HUD0dQ= X-Received: by 2002:a17:903:1aab:b0:2da:f1b1:56c4 with SMTP id d9443c01a7336-2daf1b16445mr2465215ad.3.1788323404935; Tue, 01 Sep 2026 21:30:04 -0700 (PDT) Received: from localhost ([122.172.87.224]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-32f079c6aa4sm2617066eec.5.2026.09.01.21.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 21:30:03 -0700 (PDT) Date: Wed, 2 Sep 2026 10:00:01 +0530 From: Viresh Kumar To: Zhongqiu Han Cc: rafael@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] cpufreq: zero-initialize policy cpumask before sysfs publication Message-ID: References: <20260901143635.4106960-1-zhongqiu.han@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260901143635.4106960-1-zhongqiu.han@oss.qualcomm.com> On 01-09-26, 22:36, Zhongqiu Han wrote: > cpufreq_policy_alloc() allocates policy->cpus with alloc_cpumask_var(), > i.e. without __GFP_ZERO, unlike the sibling related_cpus and real_cpus > masks. With CONFIG_CPUMASK_OFFSTACK=y the mask is a separate > kmalloc_node() allocation, so its bitmap holds whatever the slab allocator > left behind: > > cpufreq_online() > cpufreq_policy_alloc() > alloc_cpumask_var(&policy->cpus) /* bitmap is uninitialized */ > kobject_init_and_add() /* policy%u/ appears in sysfs */ > cpufreq_policy_online() > cpumask_copy(policy->cpus, cpumask_of(cpu)) /* first valid value */ > > This leaves a window in which the sysfs attributes are already reachable > while policy->cpus is still garbage. show()/store() gate on > policy_is_inactive(), i.e. cpumask_empty(policy->cpus), so a non-zero > bitmap makes them run the attribute callbacks on a policy that is not > initialized yet. > > Fix this by using zalloc_cpumask_var() for policy->cpus. > > Fixes: 2fc3384dc75b ("cpufreq: Initialize policy->kobj while allocating policy") > Cc: stable@vger.kernel.org > Signed-off-by: Zhongqiu Han > --- > This patch is based on https://lore.kernel.org/all/83f87db8-fa13-41d0-ae52-544d22e228e6@oss.qualcomm.com/ > > drivers/cpufreq/cpufreq.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 0d0df986fa3d..3b1b2ed86cc3 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -1249,7 +1249,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) > if (!policy) > return NULL; > > - if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) > + if (!zalloc_cpumask_var(&policy->cpus, GFP_KERNEL)) > goto err_free_policy; > > if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) Acked-by: Viresh Kumar -- viresh