Skip to content

Commit 37a1dec

Browse files
paulmckrcuFrederic Weisbecker
authored andcommitted
rcutorture: Expand RCUTORTURE_RDR_MASK_[12] to eight bits
This commit prepares for testing of multiple SRCU reader flavors by expanding RCUTORTURE_RDR_MASK_1 and RCUTORTURE_RDR_MASK_2 from a single bit to eight bits, allowing them to accommodate the return values from multiple calls to srcu_read_lock*(). This will in turn permit better testing coverage for these SRCU reader flavors, including testing of the diagnostics for inproper use of mixed reader flavors. Signed-off-by: Paul E. McKenney <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: <[email protected]> Reviewed-by: Neeraj Upadhyay <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent bb94b12 commit 37a1dec

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

kernel/rcu/rcutorture.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ MODULE_AUTHOR("Paul E. McKenney <[email protected]> and Josh Triplett <josh@
5757

5858
/* Bits for ->extendables field, extendables param, and related definitions. */
5959
#define RCUTORTURE_RDR_SHIFT_1 8 /* Put SRCU index in upper bits. */
60-
#define RCUTORTURE_RDR_MASK_1 (1 << RCUTORTURE_RDR_SHIFT_1)
61-
#define RCUTORTURE_RDR_SHIFT_2 9 /* Put SRCU index in upper bits. */
62-
#define RCUTORTURE_RDR_MASK_2 (1 << RCUTORTURE_RDR_SHIFT_2)
60+
#define RCUTORTURE_RDR_MASK_1 (0xff << RCUTORTURE_RDR_SHIFT_1)
61+
#define RCUTORTURE_RDR_SHIFT_2 16 /* Put SRCU index in upper bits. */
62+
#define RCUTORTURE_RDR_MASK_2 (0xff << RCUTORTURE_RDR_SHIFT_2)
6363
#define RCUTORTURE_RDR_BH 0x01 /* Extend readers by disabling bh. */
6464
#define RCUTORTURE_RDR_IRQ 0x02 /* ... disabling interrupts. */
6565
#define RCUTORTURE_RDR_PREEMPT 0x04 /* ... disabling preemption. */
@@ -71,6 +71,9 @@ MODULE_AUTHOR("Paul E. McKenney <[email protected]> and Josh Triplett <josh@
7171
#define RCUTORTURE_MAX_EXTEND \
7272
(RCUTORTURE_RDR_BH | RCUTORTURE_RDR_IRQ | RCUTORTURE_RDR_PREEMPT | \
7373
RCUTORTURE_RDR_RBH | RCUTORTURE_RDR_SCHED)
74+
#define RCUTORTURE_RDR_ALLBITS \
75+
(RCUTORTURE_MAX_EXTEND | RCUTORTURE_RDR_RCU_1 | RCUTORTURE_RDR_RCU_2 | \
76+
RCUTORTURE_RDR_MASK_1 | RCUTORTURE_RDR_MASK_2)
7477
#define RCUTORTURE_RDR_MAX_LOOPS 0x7 /* Maximum reader extensions. */
7578
/* Must be power of two minus one. */
7679
#define RCUTORTURE_RDR_MAX_SEGS (RCUTORTURE_RDR_MAX_LOOPS + 3)
@@ -1820,7 +1823,7 @@ static void rcutorture_one_extend(int *readstate, int newstate,
18201823
int statesold = *readstate & ~newstate;
18211824

18221825
WARN_ON_ONCE(idxold2 < 0);
1823-
WARN_ON_ONCE((idxold2 >> RCUTORTURE_RDR_SHIFT_2) > 1);
1826+
WARN_ON_ONCE(idxold2 & ~RCUTORTURE_RDR_ALLBITS);
18241827
rtrsp->rt_readstate = newstate;
18251828

18261829
/* First, put new protection in place to avoid critical-section gap. */
@@ -1835,9 +1838,9 @@ static void rcutorture_one_extend(int *readstate, int newstate,
18351838
if (statesnew & RCUTORTURE_RDR_SCHED)
18361839
rcu_read_lock_sched();
18371840
if (statesnew & RCUTORTURE_RDR_RCU_1)
1838-
idxnew1 = (cur_ops->readlock() & 0x1) << RCUTORTURE_RDR_SHIFT_1;
1841+
idxnew1 = (cur_ops->readlock() << RCUTORTURE_RDR_SHIFT_1) & RCUTORTURE_RDR_MASK_1;
18391842
if (statesnew & RCUTORTURE_RDR_RCU_2)
1840-
idxnew2 = (cur_ops->readlock() & 0x1) << RCUTORTURE_RDR_SHIFT_2;
1843+
idxnew2 = (cur_ops->readlock() << RCUTORTURE_RDR_SHIFT_2) & RCUTORTURE_RDR_MASK_2;
18411844

18421845
/*
18431846
* Next, remove old protection, in decreasing order of strength
@@ -1857,7 +1860,7 @@ static void rcutorture_one_extend(int *readstate, int newstate,
18571860
if (statesold & RCUTORTURE_RDR_RBH)
18581861
rcu_read_unlock_bh();
18591862
if (statesold & RCUTORTURE_RDR_RCU_2) {
1860-
cur_ops->readunlock((idxold2 >> RCUTORTURE_RDR_SHIFT_2) & 0x1);
1863+
cur_ops->readunlock((idxold2 & RCUTORTURE_RDR_MASK_2) >> RCUTORTURE_RDR_SHIFT_2);
18611864
WARN_ON_ONCE(idxnew2 != -1);
18621865
idxold2 = 0;
18631866
}
@@ -1867,7 +1870,7 @@ static void rcutorture_one_extend(int *readstate, int newstate,
18671870
lockit = !cur_ops->no_pi_lock && !statesnew && !(torture_random(trsp) & 0xffff);
18681871
if (lockit)
18691872
raw_spin_lock_irqsave(&current->pi_lock, flags);
1870-
cur_ops->readunlock((idxold1 >> RCUTORTURE_RDR_SHIFT_1) & 0x1);
1873+
cur_ops->readunlock((idxold1 & RCUTORTURE_RDR_MASK_1) >> RCUTORTURE_RDR_SHIFT_1);
18711874
WARN_ON_ONCE(idxnew1 != -1);
18721875
idxold1 = 0;
18731876
if (lockit)
@@ -1882,16 +1885,13 @@ static void rcutorture_one_extend(int *readstate, int newstate,
18821885
if (idxnew1 == -1)
18831886
idxnew1 = idxold1 & RCUTORTURE_RDR_MASK_1;
18841887
WARN_ON_ONCE(idxnew1 < 0);
1885-
if (WARN_ON_ONCE((idxnew1 >> RCUTORTURE_RDR_SHIFT_1) > 1))
1886-
pr_info("Unexpected idxnew1 value of %#x\n", idxnew1);
18871888
if (idxnew2 == -1)
18881889
idxnew2 = idxold2 & RCUTORTURE_RDR_MASK_2;
18891890
WARN_ON_ONCE(idxnew2 < 0);
1890-
WARN_ON_ONCE((idxnew2 >> RCUTORTURE_RDR_SHIFT_2) > 1);
18911891
*readstate = idxnew1 | idxnew2 | newstate;
18921892
WARN_ON_ONCE(*readstate < 0);
1893-
if (WARN_ON_ONCE((*readstate >> RCUTORTURE_RDR_SHIFT_2) > 1))
1894-
pr_info("Unexpected idxnew2 value of %#x\n", idxnew2);
1893+
if (WARN_ON_ONCE(*readstate & ~RCUTORTURE_RDR_ALLBITS))
1894+
pr_info("Unexpected readstate value of %#x\n", *readstate);
18951895
}
18961896

18971897
/* Return the biggest extendables mask given current RCU and boot parameters. */
@@ -1916,7 +1916,7 @@ rcutorture_extend_mask(int oldmask, struct torture_random_state *trsp)
19161916
unsigned long preempts_irq = preempts | RCUTORTURE_RDR_IRQ;
19171917
unsigned long bhs = RCUTORTURE_RDR_BH | RCUTORTURE_RDR_RBH;
19181918

1919-
WARN_ON_ONCE(mask >> RCUTORTURE_RDR_SHIFT_1);
1919+
WARN_ON_ONCE(mask >> RCUTORTURE_RDR_SHIFT_1); // Can't have reader idx bits.
19201920
/* Mostly only one bit (need preemption!), sometimes lots of bits. */
19211921
if (!(randmask1 & 0x7))
19221922
mask = mask & randmask2;

0 commit comments

Comments
 (0)