Page MenuHomeFreeBSD

uma: Make an effort to defer reuse of items when KASAN is enabled
AcceptedPublic

Authored by markj on Wed, Jul 15, 8:57 PM.
Tags
None
Referenced Files
F162810602: D58269.diff
Fri, Jul 17, 3:29 AM
Unknown Object (File)
Thu, Jul 16, 3:37 PM
Subscribers

Details

Reviewers
alc
rlibby
Summary

When KASAN is configured, make uma_zfree_arg() free items to the per-CPU
free bucket, rather than to the alloc bucket. This means that the item
won't be recycled immediately the next time a thread goes to allocate an
item from that zone on the same CPU. In other words, the item will stay
in a quarantine state longer, which helps make KASAN's use-after-free
detection more reliable.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 74884
Build 71767: arc lint + arc unit

Event Timeline

markj requested review of this revision.Wed, Jul 15, 8:57 PM

Looks fine modulo the uz_flags comment and style and history nits.

I'm now wondering if we should just have an __always_inline cache_free_item(..., bool defer) and rely on constant propagation, since it seems the only intended difference is whether to attempt to use the alloc bucket. But maybe it is better to keep the smr/defer path distinct to be more resilient against future accidental changes or dumb compilers.

sys/vm/uma_core.c
4618–4629

So this moved there and back again. Did it need to move at all in the first patch?

4623–4625

Style suggestion, would not be vertically longer:

if (...) {
    /* We will free... */
}
#ifdef KASAN
else if (...

Or alternately, I didn't find the original goto construct unclear.

4627

You want to use the uz_flags copy, so that we don't have to touch zone yet, otherwise this breaks that optimization with KASAN compiled in.

(I haven't checked that UMA_ZONE_NOKASAN makes it into the copy, do check that.)

markj added inline comments.
sys/vm/uma_core.c
4618–4629

I suppose not, will fix.

markj marked an inline comment as done.

Address review feedback

This revision is now accepted and ready to land.Fri, Jul 17, 4:19 PM