Re: [PATCH for-next v3 2/9] mm/slab, slub_kunit: register kprobe to trigger _nolock APIs

Harry Yoo <[email protected]>
Newsgroups org.kernel.vger.rcu,dev.linux.lists.linux-rt-devel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <[email protected]>

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
OpenPGP_signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEARYKAB0WIQQQ1ub6gR5ogjaKRmOGXBN6rc5S1gUCakIf/wAKCRCGXBN6rc5S
1k2zAP0WFF+pvp88rmpHr5+CTNLJsoe3HtwPQMCjNUTN1Wuj6AD/TWU08aQXbB1M
c2AKbPtfWlxkJ3yFMUn/T9WJ1h0e9AQ=
=M28/
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.