rwlock: allow recursive read locking when already locked in write mode
authorRoger Pau Monné <roger.pau@citrix.com>
Wed, 26 Feb 2020 09:53:03 +0000 (10:53 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 26 Feb 2020 09:53:03 +0000 (10:53 +0100)
commit868a01021c6f429e4f47647edfe2e76b4a9c753d
treea9d04cd77de4d8c52f9ed169cebeb9b414f2ec3d
parent75b7411617108bdc820d337064b38ac09f794fc5
rwlock: allow recursive read locking when already locked in write mode

Allow a CPU already holding the lock in write mode to also lock it in
read mode. There's no harm in allowing read locking a rwlock that's
already owned by the caller (ie: CPU) in write mode. Allowing such
accesses is required at least for the CPU maps use-case.

In order to do this reserve 12bits of the lock, this allows to support
up to 4096 CPUs. Also reduce the write lock mask to 2 bits: one to
signal there are pending writers waiting on the lock and the other to
signal the lock is owned in write mode.

This reduces the maximum number of concurrent readers from 16777216 to
262144, I think this should still be enough, or else the lock field
can be expanded from 32 to 64bits if all architectures support atomic
operations on 64bit integers.

Fixes: 5872c83b42c608 ('smp: convert the cpu maps lock into a rw lock')
Reported-by: Jan Beulich <jbeulich@suse.com>
Reported-by: Jürgen Groß <jgross@suse.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Julien Grall <julien@xen.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/rwlock.c
xen/include/xen/rwlock.h