Skip to content

Commit b14ff27

Browse files
committed
slab, rcu: move TINY_RCU variant of kvfree_rcu() to SLAB
Following the move of TREE_RCU implementation, let's move also the TINY_RCU one for consistency and subsequent refactoring. For simplicity, remove the separate inline __kvfree_call_rcu() as TINY_RCU is not meant for high-performance hardware anyway. Declare kvfree_call_rcu() in rcupdate.h to avoid header dependency issues. Also move the kvfree_rcu_barrier() declaration to slab.h Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Tested-by: Paul E. McKenney <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 2014c95 commit b14ff27

File tree

6 files changed

+38
-50
lines changed

6 files changed

+38
-50
lines changed

include/linux/rcupdate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,11 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
10821082
#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
10831083
#define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
10841084

1085+
/*
1086+
* In mm/slab_common.c, no suitable header to include here.
1087+
*/
1088+
void kvfree_call_rcu(struct rcu_head *head, void *ptr);
1089+
10851090
#define kvfree_rcu_arg_2(ptr, rhf) \
10861091
do { \
10871092
typeof (ptr) ___p = (ptr); \

include/linux/rcutiny.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -90,41 +90,6 @@ static inline void synchronize_rcu_expedited(void)
9090
synchronize_rcu();
9191
}
9292

93-
/*
94-
* Add one more declaration of kvfree() here. It is
95-
* not so straight forward to just include <linux/mm.h>
96-
* where it is defined due to getting many compile
97-
* errors caused by that include.
98-
*/
99-
extern void kvfree(const void *addr);
100-
101-
static inline void __kvfree_call_rcu(struct rcu_head *head, void *ptr)
102-
{
103-
if (head) {
104-
call_rcu(head, (rcu_callback_t) ((void *) head - ptr));
105-
return;
106-
}
107-
108-
// kvfree_rcu(one_arg) call.
109-
might_sleep();
110-
synchronize_rcu();
111-
kvfree(ptr);
112-
}
113-
114-
static inline void kvfree_rcu_barrier(void)
115-
{
116-
rcu_barrier();
117-
}
118-
119-
#ifdef CONFIG_KASAN_GENERIC
120-
void kvfree_call_rcu(struct rcu_head *head, void *ptr);
121-
#else
122-
static inline void kvfree_call_rcu(struct rcu_head *head, void *ptr)
123-
{
124-
__kvfree_call_rcu(head, ptr);
125-
}
126-
#endif
127-
12893
void rcu_qs(void);
12994

13095
static inline void rcu_softirq_qs(void)
@@ -164,7 +129,6 @@ static inline void rcu_end_inkernel_boot(void) { }
164129
static inline bool rcu_inkernel_boot_has_ended(void) { return true; }
165130
static inline bool rcu_is_watching(void) { return true; }
166131
static inline void rcu_momentary_eqs(void) { }
167-
static inline void kfree_rcu_scheduler_running(void) { }
168132

169133
/* Avoid RCU read-side critical sections leaking across. */
170134
static inline void rcu_all_qs(void) { barrier(); }

include/linux/rcutree.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ static inline void rcu_virt_note_context_switch(void)
3434
}
3535

3636
void synchronize_rcu_expedited(void);
37-
void kvfree_call_rcu(struct rcu_head *head, void *ptr);
38-
void kvfree_rcu_barrier(void);
3937

4038
void rcu_barrier(void);
4139
void rcu_momentary_eqs(void);
42-
void kfree_rcu_scheduler_running(void);
4340

4441
struct rcu_gp_oldstate {
4542
unsigned long rgos_norm;

include/linux/slab.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/gfp.h>
1717
#include <linux/overflow.h>
1818
#include <linux/types.h>
19+
#include <linux/rcupdate.h>
1920
#include <linux/workqueue.h>
2021
#include <linux/percpu-refcount.h>
2122
#include <linux/cleanup.h>
@@ -1082,6 +1083,19 @@ extern void kvfree_sensitive(const void *addr, size_t len);
10821083

10831084
unsigned int kmem_cache_size(struct kmem_cache *s);
10841085

1086+
#ifdef CONFIG_TINY_RCU
1087+
static inline void kvfree_rcu_barrier(void)
1088+
{
1089+
rcu_barrier();
1090+
}
1091+
1092+
static inline void kfree_rcu_scheduler_running(void) { }
1093+
#else
1094+
void kvfree_rcu_barrier(void);
1095+
1096+
void kfree_rcu_scheduler_running(void);
1097+
#endif
1098+
10851099
/**
10861100
* kmalloc_size_roundup - Report allocation bucket size for the given size
10871101
*

kernel/rcu/tiny.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,6 @@ bool poll_state_synchronize_rcu(unsigned long oldstate)
246246
}
247247
EXPORT_SYMBOL_GPL(poll_state_synchronize_rcu);
248248

249-
#ifdef CONFIG_KASAN_GENERIC
250-
void kvfree_call_rcu(struct rcu_head *head, void *ptr)
251-
{
252-
if (head)
253-
kasan_record_aux_stack(ptr);
254-
255-
__kvfree_call_rcu(head, ptr);
256-
}
257-
EXPORT_SYMBOL_GPL(kvfree_call_rcu);
258-
#endif
259-
260249
void __init rcu_init(void)
261250
{
262251
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);

mm/slab_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,25 @@ EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
12841284
EXPORT_TRACEPOINT_SYMBOL(kfree);
12851285
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);
12861286

1287+
#ifdef CONFIG_TINY_RCU
1288+
1289+
void kvfree_call_rcu(struct rcu_head *head, void *ptr)
1290+
{
1291+
if (head) {
1292+
kasan_record_aux_stack(ptr);
1293+
call_rcu(head, (rcu_callback_t) ((void *) head - ptr));
1294+
return;
1295+
}
1296+
1297+
// kvfree_rcu(one_arg) call.
1298+
might_sleep();
1299+
synchronize_rcu();
1300+
kvfree(ptr);
1301+
}
1302+
EXPORT_SYMBOL_GPL(kvfree_call_rcu);
1303+
1304+
#endif
1305+
12871306
/*
12881307
* This rcu parameter is runtime-read-only. It reflects
12891308
* a minimum allowed number of objects which can be cached

0 commit comments

Comments
 (0)