Search Linux Wireless

Re: [PATCH net v2] net: wireless: marvell: mwifiex: fix sleep in atomic context bugs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



duoming@xxxxxxxxxx writes:

> Hello,
>
> On Fri, 20 May 2022 09:08:52 -0700 Jeff Johnson wrote:
>
>> >>>>> There are sleep in atomic context bugs when uploading device dump
>> >>>>> data on usb interface. The root cause is that the operations that
>> >>>>> may sleep are called in fw_dump_timer_fn which is a timer handler.
>> >>>>> The call tree shows the execution paths that could lead to bugs:
>> >>>>>
>> >>>>>      (Interrupt context)
>> >>>>> fw_dump_timer_fn
>> >>>>>     mwifiex_upload_device_dump
>> >>>>>       dev_coredumpv(..., GFP_KERNEL)
>> >>
>> >> just looking at this description, why isn't the simple fix just to
>> >> change this call to use GFP_ATOMIC?
>> > 
>> > Because change the parameter of dev_coredumpv() to GFP_ATOMIC could only solve
>> > partial problem. The following GFP_KERNEL parameters are in /lib/kobject.c
>> > which is not influenced by dev_coredumpv().
>> > 
>> >   kobject_set_name_vargs
>> >     kvasprintf_const(GFP_KERNEL, ...); //may sleep
>> >     kstrdup(s, GFP_KERNEL); //may sleep
>> 
>> Then it seems there is a problem with dev_coredumpm().
>> 
>> dev_coredumpm() takes a gfp param which means it expects to be called in 
>> any context, but it then calls dev_set_name() which, as you point out, 
>> cannot be called from an atomic context.
>> 
>> So if we cannot change the fact that dev_set_name() cannot be called 
>> from an atomic context, then it would seem to follow that 
>> dev_coredumpv also cannot be called from an atomic 
>> context and hence their gfp param is pointless and should presumably be 
>> removed.
>
> Thanks for your time and suggestions! I think the gfp_t parameter of dev_coredumpv and
> dev_coredumpm may not be removed, because it could be used to pass value to gfp_t
> parameter of kzalloc in dev_coredumpm. What's more, there are also many other places
> use dev_coredumpv and dev_coredumpm, if we remove the gfp_t parameter, there are too many
> places that need to modify and these places are not in interrupt
> context.

"Too many users" is not a valid reason to leave a bug in place, either
dev_coredumpv() should support GFP_ATOMIC or the gfp_t parameter should
be removed.

> There are two solutions now: one is to moves the operations that may
> sleep into a work item.

That does not fix the root cause that dev_coredumpv() claims it can be
called in atomic contexts.

> Another is to change the gfp_t parameter of dev_coredumpv from GFP_KERNEL to GFP_ATOMIC, and
> change the gfp_t parameter of kvasprintf_const and kstrdup from GFP_KERNEL to 
> "in_interrupt() ? GFP_ATOMIC : GFP_KERNEL".

in_interrupt() is deprecated and should not be used. And I don't think
it detects all atomic contexts like spinlocks.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches



[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux