History

slab.h: disable completely broken overflow handling in flex allocations

Commit 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types") started using the new allocation helpers, and in the process showed that they were completely non-working. The overflow logic in overflows_flex_counter_type() is completely the wrong way around, and that broke __alloc_flex() completely. By chance, the resulting code was then such a mess that clang generated sufficiently garbage code that objtool warned about it all. Which made it somewhat quicker to narrow things down. While fixing overflows_flex_counter_type() would presumably fix this all, I'm excising the whole broken overflow logic from __alloc_flex(), because we don't want that kind of code in basic allocation functions anyway. That (no longer) broken overflows_flex_counter_type() thing needs to be inserted into the actual __set_flex_counter() logic in the unlikely case that we ever want this at all. And made conditional.

Linus Torvalds committed 8 months ago

Commit fa5c82f1 parent 89348272 files · +2 −6Browse files

Unified · Split

2 files
  1. include/linux/overflow.h +1 −1
  2. include/linux/slab.h +1 −5
include/linux/overflow.h+1−1
@@ -570,7 +570,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) · 569 unmodified lines
570 * @FAM is not annotated with __counted_by(), always returns true.570 * @FAM is not annotated with __counted_by(), always returns true.
571 */571 */
572#define overflows_flex_counter_type(TYPE, FAM, COUNT) \572#define overflows_flex_counter_type(TYPE, FAM, COUNT) \
573 (!overflows_type(COUNT, typeof_flex_counter(((TYPE *)NULL)->FAM)))573 (overflows_type(COUNT, typeof_flex_counter(((TYPE *)NULL)->FAM)))
574 574
575/**575/**
576 * __set_flex_counter() - Set the counter associated with the given flexible576 * __set_flex_counter() - Set the counter associated with the given flexible
include/linux/slab.h+1−5
@@ -1003,11 +1003,7 @@ void *kmalloc_nolock_noprof(size_t size, gfp_t gfp_flags, int node); · 1002 unmodified lines
1003({ \1003({ \
1004 const size_t __count = (COUNT); \1004 const size_t __count = (COUNT); \
1005 const size_t __obj_size = struct_size_t(TYPE, FAM, __count); \1005 const size_t __obj_size = struct_size_t(TYPE, FAM, __count); \
1006 TYPE *__obj_ptr; \1006 TYPE *__obj_ptr = KMALLOC(__obj_size, GFP); \
1007 if (WARN_ON_ONCE(overflows_flex_counter_type(TYPE, FAM, __count))) \
1008 __obj_ptr = NULL; \
1009 else \
1010 __obj_ptr = KMALLOC(__obj_size, GFP); \
1011 if (__obj_ptr) \1007 if (__obj_ptr) \
1012 __set_flex_counter(__obj_ptr->FAM, __count); \1008 __set_flex_counter(__obj_ptr->FAM, __count); \
1013 __obj_ptr; \1009 __obj_ptr; \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t