From: Jie Zhan <zhanjie9@hisilicon.com>
To: Yaxiong Tian <tianyaxiong@kylinos.cn>, <cw00.choi@samsung.com>,
<myungjoo.ham@samsung.com>, <kyungmin.park@samsung.com>
Cc: <linux-pm@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <linuxarm@huawei.com>,
<jonathan.cameron@huawei.com>, <zhenglifeng1@huawei.com>,
<zhangpengjie2@huawei.com>, <lihuisong@huawei.com>,
<prime.zeng@hisilicon.com>
Subject: Re: [PATCH v1 00/10] devfreq: Fix NULL pointer dereference when a governor module is unloaded
Date: Tue, 31 Mar 2026 14:43:20 +0800 [thread overview]
Message-ID: <8281a0af-aa2d-496d-a826-ddbf334b248f@hisilicon.com> (raw)
In-Reply-To: <94f5b6ff-f610-44f6-90e4-2e538b4f99c9@kylinos.cn>
On 3/31/2026 9:30 AM, Yaxiong Tian wrote:
>
> 在 2026/3/30 14:29, Jie Zhan 写道:
>>
>> On 3/27/2026 10:06 AM, Yaxiong Tian wrote:
>>> 在 2026/3/26 21:14, Jie Zhan 写道:
>>>> On 3/26/2026 8:34 PM, Jie Zhan wrote:
>>>>> When compiled as a kernel module, the governor module can be dynamically
>>>>> inserted or removed. 'devfreq->governor' would become NULL if the governor
>>>>> module is removed when it's in use, and NULL pointer dereference would be
>>>>> triggered. A similar issue was also reported in [1].
>>>>>
>>>>> To address this issue:
>>>>>
>>>>> Patch 1-5 rework mutex, factor out a common governor setting function, and
>>>>> clean up some unreachable code.
>>>>>
>>>>> Patch 6-8 prevent a governor module in use from being removed (except for
>>>>> force unload) by getting/putting a refcount of the governor's module when
>>>>> switching governors.
>>>>>
>>>>> Patch 9-10 allow 'governor' and 'available_governors' to work normally even
>>>>> when a governor module in use is force unloaded.
>>>>>
>>>>> Note that this series is based on [1] or devfreq-next, otherwise code
>>> Sorry, please ignore the "remember to CC me on the patches." in my previous email.
>>>
>>> In my opinion, it would be better to prioritize the FIX first before proceeding with the lock mechanism optimizations and other work. This would make it easier to backport the patches to lower-version kernels. I noticed the patch is already in the devfreq-testing branch. I hope the FIX work can be moved forward smoothly to resolve the null pointer and other bugs. Thank you!
>> Hi Yaxiong,
>>
>> I don't think this issue is urgent because it can only possibly happen when
>> governors are built as loadable modules, which is typically used for
>> development rather than production.
> No, loading/unloading modules is also a user operational requirement, not just for development.
>
>>
>> For downstream kernels, feel free to go ahead with quick fixes. For the
>> upstream kernel, however, I'd prefer to make the devfreq core clean and
>> sensible.
>
> I don't think code cleanup should take priority over bug fixes, especially when you already know there's an issue with the functionality. In fact, the version users are running is not the upstream version, but rather individual stable releases.
The point is to do the bugfix in a different way rather than cleanups.
>
> Most users don't have the time or energy to research and fix kernel issues themselves; they rely on upstream community patches most of the time.
>
> By the way, although your patch subject says "FIX", I don't see any fix tag.
>
>>
>> Your approach is to prevent kernel panics when unloading governor modules
>> before changing governors.
>>
>> This patchset achieves that, and additionally let userspace get a friendly
>> warning when trying to remove a governor module in use, e.g.
>> "rmmod: ERROR: Module governor_performance is in use".
>> This requires using the module refcount stuff, and brings out a set of
>> cleanups and refactoring. BTW, cpufreq implements a similar mechanism like
>> this.
>>
>> I may carry your fourth patch that changes the return code of
>> governor_show() in v2 and address some Sashiko review comments along the
>> way.
>>
>> Please let me know if this works for you?
> So I don't approve of this. Maybe you should ask for others' opinions, such as Chanwoo Choi.
>
No problem. I see your point.
I'll take a closer look at your version and see if that works.
The module owner refcount related stuff can be rebased later if needed.
Thanks,
Jie
>>
>> Regards,
>> Jie
>>>
>>>
>>>> sorry, based on [2] or devfreq-next
>>>>> would conflict.
>>>>>
>>>>> [1] https://lore.kernel.org/all/20260319091409.998397-1-tianyaxiong@kylinos.cn/
>>>>> [2] https://lore.kernel.org/all/20251216031153.2242306-1-zhangpengjie2@huawei.com/
prev parent reply other threads:[~2026-03-31 6:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 12:34 [PATCH v1 00/10] devfreq: Fix NULL pointer dereference when a governor module is unloaded Jie Zhan
2026-03-26 12:34 ` [PATCH v1 01/10] devfreq: Use mutex guard in governor_store() Jie Zhan
2026-03-26 12:34 ` [PATCH v1 02/10] devfreq: Use mutex guard in devfreq_add/remove_governor() Jie Zhan
2026-03-26 12:34 ` [PATCH v1 03/10] devfreq: Add a dedicated mutex for the governor list Jie Zhan
2026-03-26 12:34 ` [PATCH v1 04/10] devfreq: Factor out devfreq_set_governor[_locked]() Jie Zhan
2026-03-26 12:34 ` [PATCH v1 05/10] devfreq: Remove dead code in devfreq_add_governor() Jie Zhan
2026-03-26 12:34 ` [PATCH v1 06/10] devfreq: Add module owner to devfreq governor Jie Zhan
2026-03-26 12:34 ` [PATCH v1 07/10] devfreq: Get and put module refcount when switching governor Jie Zhan
2026-03-26 12:34 ` [PATCH v1 08/10] devfreq: Allow find_devfreq_governor() to get module refcount Jie Zhan
2026-03-26 12:34 ` [PATCH v1 09/10] devfreq: Allow showing available_governors when device governor is NULL Jie Zhan
2026-03-26 12:34 ` [PATCH v1 10/10] devfreq: Allow setting governor " Jie Zhan
2026-03-26 13:14 ` [PATCH v1 00/10] devfreq: Fix NULL pointer dereference when a governor module is unloaded Jie Zhan
[not found] ` <1774576755240654.100.seg@mailgw.kylinos.cn>
2026-03-27 2:06 ` Yaxiong Tian
2026-03-30 6:29 ` Jie Zhan
[not found] ` <1774919144945331.7.seg@mailgw.kylinos.cn>
2026-03-31 1:30 ` Yaxiong Tian
2026-03-31 6:43 ` Jie Zhan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8281a0af-aa2d-496d-a826-ddbf334b248f@hisilicon.com \
--to=zhanjie9@hisilicon.com \
--cc=cw00.choi@samsung.com \
--cc=jonathan.cameron@huawei.com \
--cc=kyungmin.park@samsung.com \
--cc=lihuisong@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=myungjoo.ham@samsung.com \
--cc=prime.zeng@hisilicon.com \
--cc=tianyaxiong@kylinos.cn \
--cc=zhangpengjie2@huawei.com \
--cc=zhenglifeng1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox