Skip to content

Commit 8f35fef

Browse files
tititiou36Neeraj Upadhyay
authored andcommitted
refscale: Constify struct ref_scale_ops
'struct ref_scale_ops' are not modified in these drivers. Constifying this structure moves some data to a read-only section, so increase overall security. On a x86_64, with allmodconfig: Before: ====== text data bss dec hex filename 34231 4167 736 39134 98de kernel/rcu/refscale.o After: ===== text data bss dec hex filename 35175 3239 736 39150 98ee kernel/rcu/refscale.o Signed-off-by: Christophe JAILLET <[email protected]> Tested-by: "Paul E. McKenney" <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]>
1 parent f1fd0e0 commit 8f35fef

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

kernel/rcu/refscale.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct ref_scale_ops {
135135
const char *name;
136136
};
137137

138-
static struct ref_scale_ops *cur_ops;
138+
static const struct ref_scale_ops *cur_ops;
139139

140140
static void un_delay(const int udl, const int ndl)
141141
{
@@ -171,7 +171,7 @@ static bool rcu_sync_scale_init(void)
171171
return true;
172172
}
173173

174-
static struct ref_scale_ops rcu_ops = {
174+
static const struct ref_scale_ops rcu_ops = {
175175
.init = rcu_sync_scale_init,
176176
.readsection = ref_rcu_read_section,
177177
.delaysection = ref_rcu_delay_section,
@@ -205,7 +205,7 @@ static void srcu_ref_scale_delay_section(const int nloops, const int udl, const
205205
}
206206
}
207207

208-
static struct ref_scale_ops srcu_ops = {
208+
static const struct ref_scale_ops srcu_ops = {
209209
.init = rcu_sync_scale_init,
210210
.readsection = srcu_ref_scale_read_section,
211211
.delaysection = srcu_ref_scale_delay_section,
@@ -232,7 +232,7 @@ static void rcu_tasks_ref_scale_delay_section(const int nloops, const int udl, c
232232
un_delay(udl, ndl);
233233
}
234234

235-
static struct ref_scale_ops rcu_tasks_ops = {
235+
static const struct ref_scale_ops rcu_tasks_ops = {
236236
.init = rcu_sync_scale_init,
237237
.readsection = rcu_tasks_ref_scale_read_section,
238238
.delaysection = rcu_tasks_ref_scale_delay_section,
@@ -271,7 +271,7 @@ static void rcu_trace_ref_scale_delay_section(const int nloops, const int udl, c
271271
}
272272
}
273273

274-
static struct ref_scale_ops rcu_trace_ops = {
274+
static const struct ref_scale_ops rcu_trace_ops = {
275275
.init = rcu_sync_scale_init,
276276
.readsection = rcu_trace_ref_scale_read_section,
277277
.delaysection = rcu_trace_ref_scale_delay_section,
@@ -310,7 +310,7 @@ static void ref_refcnt_delay_section(const int nloops, const int udl, const int
310310
}
311311
}
312312

313-
static struct ref_scale_ops refcnt_ops = {
313+
static const struct ref_scale_ops refcnt_ops = {
314314
.init = rcu_sync_scale_init,
315315
.readsection = ref_refcnt_section,
316316
.delaysection = ref_refcnt_delay_section,
@@ -347,7 +347,7 @@ static void ref_rwlock_delay_section(const int nloops, const int udl, const int
347347
}
348348
}
349349

350-
static struct ref_scale_ops rwlock_ops = {
350+
static const struct ref_scale_ops rwlock_ops = {
351351
.init = ref_rwlock_init,
352352
.readsection = ref_rwlock_section,
353353
.delaysection = ref_rwlock_delay_section,
@@ -384,7 +384,7 @@ static void ref_rwsem_delay_section(const int nloops, const int udl, const int n
384384
}
385385
}
386386

387-
static struct ref_scale_ops rwsem_ops = {
387+
static const struct ref_scale_ops rwsem_ops = {
388388
.init = ref_rwsem_init,
389389
.readsection = ref_rwsem_section,
390390
.delaysection = ref_rwsem_delay_section,
@@ -419,7 +419,7 @@ static void ref_lock_delay_section(const int nloops, const int udl, const int nd
419419
preempt_enable();
420420
}
421421

422-
static struct ref_scale_ops lock_ops = {
422+
static const struct ref_scale_ops lock_ops = {
423423
.readsection = ref_lock_section,
424424
.delaysection = ref_lock_delay_section,
425425
.name = "lock"
@@ -454,7 +454,7 @@ static void ref_lock_irq_delay_section(const int nloops, const int udl, const in
454454
preempt_enable();
455455
}
456456

457-
static struct ref_scale_ops lock_irq_ops = {
457+
static const struct ref_scale_ops lock_irq_ops = {
458458
.readsection = ref_lock_irq_section,
459459
.delaysection = ref_lock_irq_delay_section,
460460
.name = "lock-irq"
@@ -490,7 +490,7 @@ static void ref_acqrel_delay_section(const int nloops, const int udl, const int
490490
preempt_enable();
491491
}
492492

493-
static struct ref_scale_ops acqrel_ops = {
493+
static const struct ref_scale_ops acqrel_ops = {
494494
.readsection = ref_acqrel_section,
495495
.delaysection = ref_acqrel_delay_section,
496496
.name = "acqrel"
@@ -524,7 +524,7 @@ static void ref_clock_delay_section(const int nloops, const int udl, const int n
524524
stopopts = x;
525525
}
526526

527-
static struct ref_scale_ops clock_ops = {
527+
static const struct ref_scale_ops clock_ops = {
528528
.readsection = ref_clock_section,
529529
.delaysection = ref_clock_delay_section,
530530
.name = "clock"
@@ -556,7 +556,7 @@ static void ref_jiffies_delay_section(const int nloops, const int udl, const int
556556
stopopts = x;
557557
}
558558

559-
static struct ref_scale_ops jiffies_ops = {
559+
static const struct ref_scale_ops jiffies_ops = {
560560
.readsection = ref_jiffies_section,
561561
.delaysection = ref_jiffies_delay_section,
562562
.name = "jiffies"
@@ -706,9 +706,9 @@ static void refscale_typesafe_ctor(void *rtsp_in)
706706
preempt_enable();
707707
}
708708

709-
static struct ref_scale_ops typesafe_ref_ops;
710-
static struct ref_scale_ops typesafe_lock_ops;
711-
static struct ref_scale_ops typesafe_seqlock_ops;
709+
static const struct ref_scale_ops typesafe_ref_ops;
710+
static const struct ref_scale_ops typesafe_lock_ops;
711+
static const struct ref_scale_ops typesafe_seqlock_ops;
712712

713713
// Initialize for a typesafe test.
714714
static bool typesafe_init(void)
@@ -769,23 +769,23 @@ static void typesafe_cleanup(void)
769769
}
770770

771771
// The typesafe_init() function distinguishes these structures by address.
772-
static struct ref_scale_ops typesafe_ref_ops = {
772+
static const struct ref_scale_ops typesafe_ref_ops = {
773773
.init = typesafe_init,
774774
.cleanup = typesafe_cleanup,
775775
.readsection = typesafe_read_section,
776776
.delaysection = typesafe_delay_section,
777777
.name = "typesafe_ref"
778778
};
779779

780-
static struct ref_scale_ops typesafe_lock_ops = {
780+
static const struct ref_scale_ops typesafe_lock_ops = {
781781
.init = typesafe_init,
782782
.cleanup = typesafe_cleanup,
783783
.readsection = typesafe_read_section,
784784
.delaysection = typesafe_delay_section,
785785
.name = "typesafe_lock"
786786
};
787787

788-
static struct ref_scale_ops typesafe_seqlock_ops = {
788+
static const struct ref_scale_ops typesafe_seqlock_ops = {
789789
.init = typesafe_init,
790790
.cleanup = typesafe_cleanup,
791791
.readsection = typesafe_read_section,
@@ -1026,7 +1026,7 @@ static int main_func(void *arg)
10261026
}
10271027

10281028
static void
1029-
ref_scale_print_module_parms(struct ref_scale_ops *cur_ops, const char *tag)
1029+
ref_scale_print_module_parms(const struct ref_scale_ops *cur_ops, const char *tag)
10301030
{
10311031
pr_alert("%s" SCALE_FLAG
10321032
"--- %s: verbose=%d verbose_batched=%d shutdown=%d holdoff=%d lookup_instances=%ld loops=%ld nreaders=%d nruns=%d readdelay=%d\n", scale_type, tag,
@@ -1081,7 +1081,7 @@ ref_scale_init(void)
10811081
{
10821082
long i;
10831083
int firsterr = 0;
1084-
static struct ref_scale_ops *scale_ops[] = {
1084+
static const struct ref_scale_ops *scale_ops[] = {
10851085
&rcu_ops, &srcu_ops, RCU_TRACE_OPS RCU_TASKS_OPS &refcnt_ops, &rwlock_ops,
10861086
&rwsem_ops, &lock_ops, &lock_irq_ops, &acqrel_ops, &clock_ops, &jiffies_ops,
10871087
&typesafe_ref_ops, &typesafe_lock_ops, &typesafe_seqlock_ops,

0 commit comments

Comments
 (0)