public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, avi@redhat.com
Subject: array of pointers with rcu
Date: Sun, 28 Jun 2009 16:22:24 +0300	[thread overview]
Message-ID: <20090628132223.GA11856@redhat.com> (raw)

Paul,
I'd like to implement a static array of pointers with rcu.
(Note that Documentation/RCU/arrayRCU.txt addresses only the case of
static arrays where the data (rather than a pointer to the data) is
located in each array element).
The array is implemented today in kvm as follows:

struct kvm_io_bus {
        int                   dev_count;
#define NR_IOBUS_DEVS 6
        struct kvm_io_device *devs[NR_IOBUS_DEVS];
};

It's easy to use rcu_assign_pointer and
rcu_dereference to access each value in the array,
so that's fine.

However, I also have the dev_count value to handle.
This value is usually used in loops like this

for (i = 0; i < bus->dev_count; ++i) {
	... uses bus->devs[i] ...
}

I can assign the dev_count value with rcu_assign_pointer and even though
it is not a pointer I think it should work fine.  However, to access
dev_count I think that rcu_dereference will not do what I want:

#define rcu_dereference(p)     ({ \
                                typeof(p) _________p1 = ACCESS_ONCE(p);
\
                                smp_read_barrier_depends(); \
                                (_________p1); \
                                })


The use of dev_count is not through a dependency so
smp_read_barrier_depends will not be enough on most architectures.

So it seems that what I really need is something like:
#define rcu_read_value(p)     ({ \
                                typeof(p) _________p1 = ACCESS_ONCE(p);
\
                                smp_rmb(); \
                                (_________p1); \
                                })

And maybe
#define rcu_assign_value rcu_assign_pointer
for symmetry.

Comments?

-- 
MST

             reply	other threads:[~2009-06-28 13:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-28 13:22 Michael S. Tsirkin [this message]
2009-06-28 16:14 ` array of pointers with rcu Paul E. McKenney
2009-06-28 19:06   ` Michael S. Tsirkin
2009-06-28 21:10     ` Paul E. McKenney
2009-06-29  9:27       ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090628132223.GA11856@redhat.com \
    --to=mst@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox