diff --git a/include/linux/list.h b/include/linux/list.h index ae537fa..bdc9bda 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -29,17 +29,8 @@ static inline void INIT_LIST_HEAD(struct list_head *list) } #ifdef CONFIG_DEBUG_LIST -extern bool __list_add_valid(struct list_head *new, - struct list_head *prev, - struct list_head *next); extern bool __list_del_entry_valid(struct list_head *entry); #else -static inline bool __list_add_valid(struct list_head *new, - struct list_head *prev, - struct list_head *next) -{ - return true; -} static inline bool __list_del_entry_valid(struct list_head *entry) { return true; @@ -52,18 +43,21 @@ static inline bool __list_del_entry_valid(struct list_head *entry) * This is only for internal list manipulation where we know * the prev/next entries already! */ +#ifndef CONFIG_DEBUG_LIST static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { - if (!__list_add_valid(new, prev, next)) - return; - next->prev = new; new->next = next; new->prev = prev; WRITE_ONCE(prev->next, new); } +#else +extern void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next); +#endif /** * list_add - add a new entry diff --git a/include/linux/rculist.h b/include/linux/rculist.h index b1fd8bf..0535b41 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -45,17 +45,19 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) * This is only for internal list manipulation where we know * the prev/next entries already! */ +#ifndef CONFIG_DEBUG_LIST static inline void __list_add_rcu(struct list_head *new, struct list_head *prev, struct list_head *next) { - if (!__list_add_valid(new, prev, next)) - return; - new->next = next; new->prev = prev; rcu_assign_pointer(list_next_rcu(prev), new); next->prev = new; } +#else +void __list_add_rcu(struct list_head *new, + struct list_head *prev, struct list_head *next); +#endif /** * list_add_rcu - add a new entry to rcu-protected list diff --git a/lib/list_debug.c b/lib/list_debug.c index a34db8d..efb12a9 100644 --- a/lib/list_debug.c +++ b/lib/list_debug.c @@ -2,7 +2,8 @@ * Copyright 2006, Red Hat, Inc., Dave Jones * Released under the General Public License (GPL). * - * This file contains the linked list validation for DEBUG_LIST. + * This file contains the linked list implementations for + * DEBUG_LIST. */ #include @@ -12,28 +13,33 @@ #include /* - * Check that the data structures for the list manipulations are reasonably - * valid. Failures here indicate memory corruption (and possibly an exploit - * attempt). + * Insert a new entry between two known consecutive entries. + * + * This is only for internal list manipulation where we know + * the prev/next entries already! */ -bool __list_add_valid(struct list_head *new, struct list_head *prev, - struct list_head *next) +void __list_add(struct list_head *new, + struct list_head *prev, + struct list_head *next) { - if (CHECK_DATA_CORRUPTION(next->prev != prev, - "list_add corruption. next->prev should be prev (%p), but was %p. (next=%p).\n", - prev, next->prev, next) || - CHECK_DATA_CORRUPTION(prev->next != next, - "list_add corruption. prev->next should be next (%p), but was %p. (prev=%p).\n", - next, prev->next, prev) || - CHECK_DATA_CORRUPTION(new == prev || new == next, - "list_add double add: new=%p, prev=%p, next=%p.\n", - new, prev, next)) - return false; - - return true; + WARN(next->prev != prev, + "list_add corruption. next->prev should be " + "prev (%p), but was %p. (next=%p).\n", + prev, next->prev, next); + WARN(prev->next != next, + "list_add corruption. prev->next should be " + "next (%p), but was %p. (prev=%p).\n", + next, prev->next, prev); + WARN(new == prev || new == next, + "list_add double add: new=%p, prev=%p, next=%p.\n", + new, prev, next); + next->prev = new; + new->next = next; + new->prev = prev; + WRITE_ONCE(prev->next, new); } -EXPORT_SYMBOL(__list_add_valid); +EXPORT_SYMBOL(__list_add); bool __list_del_entry_valid(struct list_head *entry) { @@ -60,3 +66,22 @@ bool __list_del_entry_valid(struct list_head *entry) } EXPORT_SYMBOL(__list_del_entry_valid); + +/* + * RCU variants. + */ +void __list_add_rcu(struct list_head *new, + struct list_head *prev, struct list_head *next) +{ + WARN(next->prev != prev, + "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n", + prev, next->prev, next); + WARN(prev->next != next, + "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n", + next, prev->next, prev); + new->next = next; + new->prev = prev; + rcu_assign_pointer(list_next_rcu(prev), new); + next->prev = new; +} +EXPORT_SYMBOL(__list_add_rcu);