Commit 9a08942f authored by Frederic Weisbecker's avatar Frederic Weisbecker
Browse files

Merge branch 'rcu/misc' into next

- In order to prepare the layout for nohz_full work deferral to
  user exit, the context tracking state must shrink the counter
  of transitions to/from RCU not watching. The only possible hazard
  is to trigger wrap-around more easily, delaying a bit grace periods
  when that happens. This should be a rare event though. Yet add
  debugging and torture code to test that assumption.

- Fix memory leak on locktorture module

- Annotate accesses in rculist_nulls.h to prevent from KCSAN warnings.
  On recent discussions, we also concluded that all those WRITE_ONCE()
  and READ_ONCE() on list APIs deserve appropriate comments. Something
  to be expected for the next cycle.

- Provide a script to apply several configs to several commits with torture.

- Allow torture to reuse a build directory in order to save needless
  rebuild time.

- Various cleanups.
parents a5041384 82a22449
Loading
Loading
Loading
Loading
+37 −7
Original line number Diff line number Diff line
@@ -18,12 +18,6 @@ enum ctx_state {
	CT_STATE_MAX		= 4,
};

/* Odd value for watching, else even. */
#define CT_RCU_WATCHING CT_STATE_MAX

#define CT_STATE_MASK (CT_STATE_MAX - 1)
#define CT_RCU_WATCHING_MASK (~CT_STATE_MASK)

struct context_tracking {
#ifdef CONFIG_CONTEXT_TRACKING_USER
	/*
@@ -44,9 +38,45 @@ struct context_tracking {
#endif
};

/*
 * We cram two different things within the same atomic variable:
 *
 *                     CT_RCU_WATCHING_START  CT_STATE_START
 *                                |                |
 *                                v                v
 *     MSB [ RCU watching counter ][ context_state ] LSB
 *         ^                       ^
 *         |                       |
 * CT_RCU_WATCHING_END        CT_STATE_END
 *
 * Bits are used from the LSB upwards, so unused bits (if any) will always be in
 * upper bits of the variable.
 */
#ifdef CONFIG_CONTEXT_TRACKING
#define CT_SIZE (sizeof(((struct context_tracking *)0)->state) * BITS_PER_BYTE)

#define CT_STATE_WIDTH bits_per(CT_STATE_MAX - 1)
#define CT_STATE_START 0
#define CT_STATE_END   (CT_STATE_START + CT_STATE_WIDTH - 1)

#define CT_RCU_WATCHING_MAX_WIDTH (CT_SIZE - CT_STATE_WIDTH)
#define CT_RCU_WATCHING_WIDTH     (IS_ENABLED(CONFIG_RCU_DYNTICKS_TORTURE) ? 2 : CT_RCU_WATCHING_MAX_WIDTH)
#define CT_RCU_WATCHING_START     (CT_STATE_END + 1)
#define CT_RCU_WATCHING_END       (CT_RCU_WATCHING_START + CT_RCU_WATCHING_WIDTH - 1)
#define CT_RCU_WATCHING           BIT(CT_RCU_WATCHING_START)

#define CT_STATE_MASK        GENMASK(CT_STATE_END,        CT_STATE_START)
#define CT_RCU_WATCHING_MASK GENMASK(CT_RCU_WATCHING_END, CT_RCU_WATCHING_START)

#define CT_UNUSED_WIDTH (CT_RCU_WATCHING_MAX_WIDTH - CT_RCU_WATCHING_WIDTH)

static_assert(CT_STATE_WIDTH        +
	      CT_RCU_WATCHING_WIDTH +
	      CT_UNUSED_WIDTH       ==
	      CT_SIZE);

DECLARE_PER_CPU(struct context_tracking, context_tracking);
#endif
#endif	/* CONFIG_CONTEXT_TRACKING */

#ifdef CONFIG_CONTEXT_TRACKING_USER
static __always_inline int __ct_state(void)
+3 −3
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,

	if (last) {
		WRITE_ONCE(n->next, last->next);
		n->pprev = &last->next;
		WRITE_ONCE(n->pprev, &last->next);
		rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
	} else {
		hlist_nulls_add_head_rcu(n, h);
@@ -148,8 +148,8 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
/* after that hlist_nulls_del will work */
static inline void hlist_nulls_add_fake(struct hlist_nulls_node *n)
{
	n->pprev = &n->next;
	n->next = (struct hlist_nulls_node *)NULLS_MARKER(NULL);
	WRITE_ONCE(n->pprev, &n->next);
	WRITE_ONCE(n->next, (struct hlist_nulls_node *)NULLS_MARKER(NULL));
}

/**
+6 −2
Original line number Diff line number Diff line
@@ -103,8 +103,8 @@ static const struct kernel_param_ops lt_bind_ops = {
	.get = param_get_cpumask,
};

module_param_cb(bind_readers, &lt_bind_ops, &bind_readers, 0644);
module_param_cb(bind_writers, &lt_bind_ops, &bind_writers, 0644);
module_param_cb(bind_readers, &lt_bind_ops, &bind_readers, 0444);
module_param_cb(bind_writers, &lt_bind_ops, &bind_writers, 0444);

long torture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask, bool dowarn);

@@ -1211,6 +1211,10 @@ static void lock_torture_cleanup(void)
			cxt.cur_ops->exit();
		cxt.init_called = false;
	}

	free_cpumask_var(bind_readers);
	free_cpumask_var(bind_writers);

	torture_cleanup_end();
}

+15 −0
Original line number Diff line number Diff line
@@ -213,4 +213,19 @@ config RCU_STRICT_GRACE_PERIOD
	  when looking for certain types of RCU usage bugs, for example,
	  too-short RCU read-side critical sections.


config RCU_DYNTICKS_TORTURE
	bool "Minimize RCU dynticks counter size"
	depends on RCU_EXPERT && !COMPILE_TEST
	default n
	help
	  This option sets the width of the dynticks counter to its
	  minimum usable value.  This minimum width greatly increases
	  the probability of flushing out bugs involving counter wrap,
	  but it also increases the probability of extending grace period
	  durations.  This Kconfig option should therefore be avoided in
	  production due to the consequent increased probability of OOMs.

	  This has no value for production and is only for testing.

endmenu # "RCU Debugging"
+1 −3
Original line number Diff line number Diff line
@@ -2438,10 +2438,8 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
	newstate = rcutorture_extend_mask(rtors.readstate, trsp);
	WARN_ON_ONCE(newstate & RCUTORTURE_RDR_UPDOWN);
	rcutorture_one_extend(&rtors.readstate, newstate, trsp, rtors.rtrsp++);
	if (!rcu_torture_one_read_start(&rtors, trsp, myid)) {
		rcutorture_one_extend(&rtors.readstate, 0, trsp, rtors.rtrsp);
	if (!rcu_torture_one_read_start(&rtors, trsp, myid))
		return false;
	}
	rtors.rtrsp = rcutorture_loop_extend(&rtors.readstate, trsp, rtors.rtrsp);
	rcu_torture_one_read_end(&rtors, trsp);
	return true;
Loading