On 6/24/26 10:41 PM, Pedro Falcato wrote:
> On Mon, Jun 15, 2026 at 08:05:56PM +0900, Harry Yoo (Oracle) wrote:
>> Since kmalloc_nolock() always fails in NMI and hardirq contexts on
>> PREEMPT_RT, slub_kunit cannot properly test _nolock() APIs.
>>
>> Register a kprobe pre-handler to invoke kmalloc_nolock() and
>> kfree_nolock() in the middle of the slab allocator. However, do not
>> register the handler on UP kernels [1].
> 
> Maybe explain in the commit message why that is?

Because it's the case is broken on UP and we decided not bother to fix.
Thought the cover letter in Link: would give enough context.

>> To attach the pre-handler while s->cpu_sheaves->lock or n->list_lock
>> is held, add a wrapper function for lockdep_assert_held() that calls
>> a no-op function slab_attach_kprobe_locked() on debug builds. The
> 
> Why lockdep?

I wanted to avoid hard-coding internal slab function names
in the test module while having a good coverage.

> Wouldn't it make more sense to add these triggers after> locking these locks?

Good point.

Perhaps it'd make more sense to let _trylock() fail occasionally,
because that what I actually want to test.

>> function is optimized away when neither CONFIG_PROVE_LOCKING nor
>> CONFIG_DEBUG_VM is selected and register_kprobe() fails.
>>
>> The function calls barrier() to prevent the compiler from optimizing
>> away its callsites. Otherwise, the compiler may consider the function
>> does not have any side effect and remove callsites.
> 
> My wider comment is the following: this looks very useful but perhaps should
> be lifted to Kunit itself? There's already function redirection (which could
> be used for this as well).

TIL kunit function redirection, thanks :)

> I don't know if that suits your purposes?

Hmm, but looking at the kunit function redirection,
apparently the function needs to have a symbol to redirect.

Not sure how feasible it is to make all those lock helpers have symbols
to use kunit function redirection.

> Choosing to say "I want to hook this random function using kprobe and give
> it custom behavior" sounds lovely for all sorts of testing.

Sounds lovely.

Actually, I was thinking it would be lovely to have fault-injection-like
feature for memcg because it's hard to trigger that in kunit...

Thanks!

-- 
Cheers,
Harry / Hyeonggon

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to