[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH for-4.19 3/9] xen/cpu: ensure get_cpu_maps() returns false if CPU operations are underway
Due to the current rwlock logic, if the CPU calling get_cpu_maps() does so from a cpu_hotplug_{begin,done}() region the function will still return success, because a CPU taking the rwlock in read mode after having taken it in write mode is allowed. Such behavior however defeats the purpose of get_cpu_maps(), as it should always return false when called with a CPU hot{,un}plug operation is in progress. Otherwise the logic in send_IPI_mask() for example is wrong, as it could decide to use the shorthand even when a CPU operation is in progress. Adjust the logic in get_cpu_maps() to return false when the CPUs lock is already hold in write mode by the current CPU, as read_trylock() would otherwise return true. Fixes: 868a01021c6f ('rwlock: allow recursive read locking when already locked in write mode') Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- xen/common/cpu.c | 3 ++- xen/include/xen/rwlock.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/common/cpu.c b/xen/common/cpu.c index 6173220e771b..d76f80fe2e99 100644 --- a/xen/common/cpu.c +++ b/xen/common/cpu.c @@ -49,7 +49,8 @@ static DEFINE_RWLOCK(cpu_add_remove_lock); bool get_cpu_maps(void) { - return read_trylock(&cpu_add_remove_lock); + return !rw_is_write_locked_by_me(&cpu_add_remove_lock) && + read_trylock(&cpu_add_remove_lock); } void put_cpu_maps(void) diff --git a/xen/include/xen/rwlock.h b/xen/include/xen/rwlock.h index a2e98cad343e..4e7802821859 100644 --- a/xen/include/xen/rwlock.h +++ b/xen/include/xen/rwlock.h @@ -316,6 +316,8 @@ static always_inline void write_lock_irq(rwlock_t *l) #define rw_is_locked(l) _rw_is_locked(l) #define rw_is_write_locked(l) _rw_is_write_locked(l) +#define rw_is_write_locked_by_me(l) \ + lock_evaluate_nospec(_is_write_locked_by_me(atomic_read(&(l)->cnts))) typedef struct percpu_rwlock percpu_rwlock_t; -- 2.44.0
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |