[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] Question about sharing spinlock_t among VMs in Xen



On 13/06/2016 18:43, Meng Xu wrote:
> Hi,
>
> I have a quick question about using the Linux spin_lock() in Xen
> environment to protect some host-wide shared (memory) resource among
> VMs.
>
> *** The question is as follows ***
> Suppose I have two Linux VMs sharing the same spinlock_t lock (through
> the sharing memory) on the same host. Suppose we have one process in
> each VM. Each process uses the linux function spin_lock(&lock) [1] to
> grab & release the lock.
> Will these two processes in the two VMs have race on the shared lock?

"Race" is debatable.  (After all, the point of a lock is to have
serialise multiple accessors).  But yes, this will be the same lock.

The underlying cache coherency fabric will perform atomic locked
operations on the same physical piece of RAM.

The important question is whether the two difference VMs have an
identical idea of what a spinlock_t is.  If not, this will definitely fail.

> My speculation is that it should have the race on the shard lock when
> the spin_lock() function in *two VMs* operate on the same lock.
>
> We did some quick experiment on this and we found one VM sometimes see
> the soft lockup on the lock. But we want to make sure our
> understanding is correct.
>
> We are exploring if we can use the spin_lock to protect the shared
> resources among VMs, instead of using the PV drivers. If the
> spin_lock() in linux can provide the host-wide atomicity (which will
> surprise me, though), that will be great. Otherwise, we probably have
> to expose the spin_lock in Xen to the Linux?

What are you attempting to protect like this?

Anything which a guest can spin on like this is a recipe for disaster,
as you observe, as the guest which holds the lock will get scheduled out
in favour of the guest attempting to take the lock.  Alternatively, two
different guests with a different idea of how to manage the memory
backing a spinlock_t.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.