Skip to contentSkip to conversation

dn_route.c momentarily exiting RCU read-side critical section

DISCUSSION Paul E. McKenney 3 participants 6 messages Oct 29, 2007 – Nov 5, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello!

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
	struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);

	rt = rt->u.dst.dn_next;
	while(!rt) {
		rcu_read_unlock_bh();
		if (--s->bucket < 0)
			break;

... But what happens if seq->private is freed up right here? ... Or what prevents this from happening?

		rcu_read_lock_bh();
		rt = dn_rt_hash_table[s->bucket].chain;
	}
	return rt;
}

Similar code is in rt_cache_get_next().

So, what am I missing here?

Thanx, Paul

maintainer
#1 lore raw

From: "Paul E. McKenney" <[email protected]>
Date: Mon, 29 Oct 2007 14:15:40 -0700

Quoted 14 lines

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
	struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);

	rt = rt->u.dst.dn_next;
	while(!rt) {
		rcu_read_unlock_bh();
		if (--s->bucket < 0)
			break;

... But what happens if seq->private is freed up right here? ... Or what prevents this from happening?

...

Quoted 3 lines

Similar code is in rt_cache_get_next().

So, what am I missing here?

seq->private is allocated on file open (here via seq_open_private()), and freed up on file close (via seq_release_private).

So it cannot be freed up in the middle of an iteration.

#2 lore raw
Quoted 18 lines · David Miller

From: "Paul E. McKenney" <[email protected]>
Date: Mon, 29 Oct 2007 14:15:40 -0700

Quoted 14 lines

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
	struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);

	rt = rt->u.dst.dn_next;
	while(!rt) {
		rcu_read_unlock_bh();
		if (--s->bucket < 0)
			break;

... But what happens if seq->private is freed up right here? ... Or what prevents this from happening?

...

Quoted 8 lines
Quoted 3 lines

Similar code is in rt_cache_get_next().

So, what am I missing here?

seq->private is allocated on file open (here via seq_open_private()), and freed up on file close (via seq_release_private).

So it cannot be freed up in the middle of an iteration.

Thank you for the info!!!

OK, for my next stupid question: why is the rcu_dereference(seq->private) required, as opposed to simply seq->private?

Thanx, Paul

#3 lore raw
Quoted 7 lines · Paul E. McKenney
Quoted 7 lines
Quoted 7 lines

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
    struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
    rt = rt->u.dst.dn_next;
    while(!rt) {
            rcu_read_unlock_bh();
            if (--s->bucket < 0)
                    break;

OK, for my next stupid question: why is the rcu_dereference(seq->private) required, as opposed to simply seq->private?

It was put there by someone who went through the code converting all occurances of smp_read_barrier_depends to rcu_dereference. In this instance the rcu_dereference conversion doesn't make much sense so we should probably just revert it.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw
Quoted 14 lines · Herbert Xu
Quoted 13 lines · Paul E. McKenney
Quoted 12 lines
Quoted 12 lines

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
    struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);

    rt = rt->u.dst.dn_next;
    while(!rt) {
            rcu_read_unlock_bh();
            if (--s->bucket < 0)
                    break;
Quoted 7 lines
Quoted 2 lines

OK, for my next stupid question: why is the rcu_dereference(seq->private) required, as opposed to simply seq->private?

It was put there by someone who went through the code converting all occurances of smp_read_barrier_depends to rcu_dereference. In this instance the rcu_dereference conversion doesn't make much sense so we should probably just revert it.

Thank you for the info! Stupid question #3: what sequence of events would the smp_read_barrier_depends() be defending against?

Thanx, Paul

#5 lore raw
Quoted 7 lines · Paul E. McKenney
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

net/decnet/dn_route.c in dn_rt_cache_get_next() is as follows:

static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)

{
    struct dn_rt_cache_iter_state *s = rcu_dereference(seq->private);
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
    rt = rt->u.dst.dn_next;
    while(!rt) {
            rcu_read_unlock_bh();
            if (--s->bucket < 0)
                    break;

Thank you for the info! Stupid question #3: what sequence of events would the smp_read_barrier_depends() be defending against?

The reading of rt from the hash bucket and the dereferencing above. We need to make sure that we see the initialised rt.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt