xen/spinlock: make recursive spinlocks a dedicated type
v5 cover xen/spinlock: make recursive spinlocks a dedicated type
Instead of being able to use normal spinlocks as recursive ones, too, make recursive spinlocks a special lock type.
This will make the spinlock structure smaller in production builds and add type-safety.
This allows to increase the maximum number of physical cpus from 4095 to 65535 without increasing the size of the lock structure in production builds (the size of recursive spinlocks in debug builds will grow to 12 bytes due to that change).
Note that rwlock handling is still limiting the number of cpus to 4095, this is being taken care off in patch 12, which raises the rwlock limit to 16384 cpus.
Iommu code imposes a limit of 16383 cpus.
Changes in V2:
- addressed comments by Jan Beulich
- lots of additional cleanups
- reorganized complete series
Changes in V3:
- addressed comments by Jan Beulich
Changes in V4:
- former patch 1 has already been applied
- fixed a coding style issue in patch 1
Changes in V5:
- new patches 1 + 10 + 12 + 13
- due to the recent Ghost-race patches the macro layer for calling spinlock functions is kept
- addressed comments
Juergen Gross (13):
xen/spinlock: remove misra rule 21.1 violations xen/spinlock: introduce new type for recursive spinlocks xen/spinlock: rename recursive lock functions xen/spinlock: add rspin_[un]lock_irq[save|restore]() xen/spinlock: make struct lock_profile rspinlock_t aware xen/spinlock: add explicit non-recursive locking functions xen/spinlock: add another function level xen/spinlock: add missing rspin_is_locked() and rspin_barrier() xen/spinlock: split recursive spinlocks from normal ones xen/spinlock: let all is_locked and trylock variants return bool xen/spinlock: support higher number of cpus xen/rwlock: raise the number of possible cpus
xen: allow up to 16383 cpus
xen/arch/Kconfig | 2 +- xen/arch/arm/domain.c | 4 +- xen/arch/arm/mm.c | 4 +- xen/arch/x86/domain.c | 20 +-- xen/arch/x86/include/asm/mm.h | 2 +- xen/arch/x86/mm.c | 12 +- xen/arch/x86/mm/mem_sharing.c | 16 +-- xen/arch/x86/mm/mm-locks.h | 6 +- xen/arch/x86/mm/p2m-pod.c | 6 +- xen/arch/x86/mm/p2m.c | 4 +- xen/arch/x86/tboot.c | 4 +- xen/common/domain.c | 6 +- xen/common/domctl.c | 4 +- xen/common/grant_table.c | 10 +- xen/common/ioreq.c | 54 ++++---- xen/common/memory.c | 4 +- xen/common/numa.c | 4 +- xen/common/page_alloc.c | 30 ++--- xen/common/spinlock.c | 235 +++++++++++++++++++++++++--------- xen/drivers/char/console.c | 38 +++--- xen/drivers/passthrough/pci.c | 8 +- xen/include/xen/rwlock.h | 18 +-- xen/include/xen/sched.h | 10 +- xen/include/xen/spinlock.h | 174 ++++++++++++++++++------- 24 files changed, 440 insertions(+), 235 deletions(-)
Signature · 1 line
2.35.3
PATCH v5 1/13 xen/spinlock: remove misra rule 21.1 violations
In xen spinlock code there are several violations of MISRA rule 21.1 (identifiers starting with "__" or "_[A-Z]").
Fix them by using trailing underscores instead.
---
V5:
- new patch (Julien Grall)
--- xen/include/xen/spinlock.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
xen/include/xen/spinlock.h +14 -14
@@ -22,7 +22,7 @@ union lock_debug { bool unseen:1; }; }; -#define _LOCK_DEBUG { .val = LOCK_DEBUG_INITVAL } +#define LOCK_DEBUG_ { .val = LOCK_DEBUG_INITVAL }void check_lock (union lock_debug *debug,bool try);void lock_enter (const union lock_debug *debug);void lock_exit (const union lock_debug *debug);
@@ -30,7 +30,7 @@ void spin_debug_enable(void);void spin_debug_disable (void );#else union lock_debug { }; -#define _LOCK_DEBUG { } +#define LOCK_DEBUG_ { }#define check_lock (l, t) ((void)0)#define lock_enter (l) ((void)0)#define lock_exit (l) ((void)0)
@@ -95,27 +95,27 @@ struct lock_profile_qhead {int32_t idx;/* index for printout */ }; -#define _LOCK_PROFILE (lockname) { .name = #lockname, .lock = &(lockname), } -#define _LOCK_PROFILE_PTR (name) \ - static struct lock_profile * const __lock_profile_##name \ +#define LOCK_PROFILE_ (lockname) { .name = #lockname, .lock = &(lockname), } +#define LOCK_PROFILE_PTR_ (name) \ + static struct lock_profile * const lock_profile__##name \ __used_section(".lockprofile.data") = \ - &__lock_profile_data_##name -#define _SPIN_LOCK_UNLOCKED (x) { \ + &lock_profile_data__##name +#define SPIN_LOCK_UNLOCKED_ (x) { \ .recurse_cpu = SPINLOCK_NO_CPU, \ - .debug =_LOCK_DEBUG, \ + .debug = LOCK_DEBUG_, \ .profile = x, \ } -#define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) +#define SPIN_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED_(NULL)#define DEFINE_SPINLOCK (l) \ - spinlock_t l = _SPIN_LOCK_UNLOCKED(NULL); \ - static struct lock_profile __lock_profile_data_##l = _LOCK_PROFILE(l); \ - _LOCK_PROFILE_PTR(l) + spinlock_t l = SPIN_LOCK_UNLOCKED_(NULL); \ + static struct lock_profile lock_profile_data__##l = LOCK_PROFILE_(l); \ + LOCK_PROFILE_PTR_(l)#define spin_lock_init_prof (s, l) \ do { \ struct lock_profile *prof; \ prof = xzalloc(struct lock_profile); \ - (s)->l = (spinlock_t)_SPIN_LOCK_UNLOCKED(prof); \ + (s)->l = (spinlock_t)SPIN_LOCK_UNLOCKED_(prof); \ if ( !prof ) \ { \ printk(XENLOG_WARNING \
@@ -149,7 +149,7 @@ struct lock_profile_qhead { };#define SPIN_LOCK_UNLOCKED { \ .recurse_cpu = SPINLOCK_NO_CPU, \ - .debug =_LOCK_DEBUG, \ + .debug = LOCK_DEBUG_, \ }#define DEFINE_SPINLOCK (l) spinlock_t l = SPIN_LOCK_UNLOCKED
Signature · 1 line
2.35.3
Re: [PATCH v5 01/13] xen/spinlock: remove misra rule 21.1 violations
Quoted 6 lines · Juergen Gross
In xen spinlock code there are several violations of MISRA rule 21.1 (identifiers starting with "__" or "_[A-Z]").
Fix them by using trailing underscores instead.
Signed-off-by Juergen Gross <[email protected]>
I can live with the changes as they are, but before giving an ack, I'd still like to ask if the moved underscores are really useful / necessary in all cases. E.g.
xen/include/xen/spinlock.h union lock_debug { · line 25
Quoted 8 lines
xen/include/xen/spinlock.h +1
-1@@ -22,7 +22,7 @@ union lock_debug { bool unseen:1; }; }; -#define _LOCK_DEBUG { .val = LOCK_DEBUG_INITVAL } +#define LOCK_DEBUG_ { .val = LOCK_DEBUG_INITVAL }
... for an internal helper macro it may indeed be better to have a trailing one here, but ...
xen/include/xen/spinlock.h struct lock_profile_qhead { · line 100
Quoted 10 lines
xen/include/xen/spinlock.h +3
-3@@ -95,27 +95,27 @@ struct lock_profile_qhead {int32_t idx;/* index for printout */ }; -#define _LOCK_PROFILE (lockname) { .name = #lockname, .lock = &(lockname), } -#define _LOCK_PROFILE_PTR (name) \ - static struct lock_profile * const __lock_profile_##name \ +#define LOCK_PROFILE_ (lockname) { .name = #lockname, .lock = &(lockname), } +#define LOCK_PROFILE_PTR_ (name) \ + static struct lock_profile * const lock_profile__##name \
... I'm not entirely convinced of the need for the double infix ones here ...
xen/include/xen/spinlock.h struct lock_profile_qhead { · line 111
Quoted 8 lines
xen/include/xen/spinlock.h +3
-4-#define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) +#define SPIN_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED_(NULL)#define DEFINE_SPINLOCK (l) \ - spinlock_t l = _SPIN_LOCK_UNLOCKED(NULL); \ - static struct lock_profile __lock_profile_data_##l = _LOCK_PROFILE(l); \ - _LOCK_PROFILE_PTR(l) + spinlock_t l = SPIN_LOCK_UNLOCKED_(NULL); \ + static struct lock_profile lock_profile_data__##l = LOCK_PROFILE_(l); \
.... and here.
Jan
Re: [PATCH v5 01/13] xen/spinlock: remove misra rule 21.1 violations
Quoted 28 lines · Jan Beulich
Quoted 6 lines · Juergen Gross
In xen spinlock code there are several violations of MISRA rule 21.1 (identifiers starting with "__" or "_[A-Z]").
Fix them by using trailing underscores instead.
Signed-off-by Juergen Gross <[email protected]>I can live with the changes as they are, but before giving an ack, I'd still like to ask if the moved underscores are really useful / necessary in all cases. E.g.
xen/include/xen/spinlock.h union lock_debug { · line 25
Quoted 8 lines
xen/include/xen/spinlock.h +1
-1@@ -22,7 +22,7 @@ union lock_debug { bool unseen:1; }; }; -#define _LOCK_DEBUG { .val = LOCK_DEBUG_INITVAL } +#define LOCK_DEBUG_ { .val = LOCK_DEBUG_INITVAL }... for an internal helper macro it may indeed be better to have a trailing one here, but ...
Quoted 4 lines
xen/include/xen/spinlock.h +0
-0@@ -95,27 +95,27 @@ struct lock_profile_qhead {int32_t idx;/* index for printout */ };
Quoted 9 lines
xen/include/xen/spinlock.h struct lock_profile_qhead { · line 100
Quoted 6 lines
xen/include/xen/spinlock.h +3
-3-#define _LOCK_PROFILE (lockname) { .name = #lockname, .lock = &(lockname), } -#define _LOCK_PROFILE_PTR (name) \ - static struct lock_profile * const __lock_profile_##name \ +#define LOCK_PROFILE_ (lockname) { .name = #lockname, .lock = &(lockname), } +#define LOCK_PROFILE_PTR_ (name) \ + static struct lock_profile * const lock_profile__##name \... I'm not entirely convinced of the need for the double infix ones here ...
This reduces the chance of name clashes with other lock profiling variables or functions (e.g. lock_profile_lock). In case you think this can be neglected, I'm fine with dropping the extra underscores.
Juergen
PATCH v5 2/13 xen/spinlock: introduce new type for recursive spinlocks
In reply to Juergen GrossIntroduce a new type "rspinlock_t" to be used for recursive spinlocks.
For now it is only an alias of spinlock_t, so both types can still be used for recursive spinlocks. This will be changed later, though.
Switch all recursive spinlocks to the new type.
Define the initializer helpers and use them where appropriate.
---
V2:
- carved out from V1 patch
V5:
- avoid MISRA violation (Julien Grall)
--- xen/arch/x86/include/asm/mm.h | 2 +- xen/arch/x86/mm/mm-locks.h | 2 +- xen/common/domain.c | 4 ++-- xen/common/ioreq.c | 2 +- xen/drivers/char/console.c | 4 ++-- xen/drivers/passthrough/pci.c | 2 +- xen/include/xen/sched.h | 6 +++--- xen/include/xen/spinlock.h | 19 +++++++++++++++---- 8 files changed, 26 insertions(+), 15 deletions(-)
xen/arch/x86/include/asm/mm.h +1 -1
@@ -597,7 +597,7 @@ unsigned long domain_get_maximum_gpfn(struct domain *d);/* Definition of an mm lock: spinlock with extra fields for debugging */ typedef struct mm_lock { - spinlock_t lock; + rspinlock_t lock; int unlock_level; int locker; /* processor which holds the lock */ const char *locker_function; /* func that took it */
xen/arch/x86/mm/mm-locks.h +1 -1
@@ -20,7 +20,7 @@ DECLARE_PERCPU_RWLOCK_GLOBAL(p2m_percpu_rwlock);static inline void mm_lock_init (mm_lock_t *l) { -spin_lock_init (&l->lock); +rspin_lock_init (&l->lock); l->locker =-1 ; l->locker_function ="nobody" ; l->unlock_level =0 ;
xen/common/domain.c +2 -2
@@ -627,8 +627,8 @@ struct domain *domain_create(domid_t domid,atomic_set (&d->refcnt,1 );RCU_READ_LOCK_INIT (&d->rcu_lock); -spin_lock_init_prof (d, domain_lock); -spin_lock_init_prof (d, page_alloc_lock); +rspin_lock_init_prof (d, domain_lock); +rspin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->hypercall_deadlock_mutex);INIT_PAGE_LIST_HEAD (&d->page_list);INIT_PAGE_LIST_HEAD (&d->extra_page_list);
xen/common/ioreq.c +1 -1
@@ -1331,7 +1331,7 @@ unsigned int ioreq_broadcast(ioreq_t *p, bool buffered)void ioreq_domain_init (struct domain *d) { -spin_lock_init (&d->ioreq_server.lock); +rspin_lock_init (&d->ioreq_server.lock);arch_ioreq_domain_init (d); }
xen/drivers/char/console.c +2 -2
@@ -119,7 +119,7 @@ static int __read_mostly sercon_handle = -1;int8_t __read_mostly opt_console_xen;/* console=xen */ #endif -static DEFINE_SPINLOCK (console_lock); +static DEFINE_RSPINLOCK (console_lock);/* * To control the amount of printing, thresholds are added.
@@ -1177,7 +1177,7 @@ void console_force_unlock(void) {watchdog_disable ();spin_debug_disable (); -spin_lock_init (&console_lock); +rspin_lock_init (&console_lock);serial_force_unlock (sercon_handle); console_locks_busted =1 ;console_start_sync ();
xen/drivers/passthrough/pci.c +1 -1
@@ -50,7 +50,7 @@ struct pci_seg { } bus2bridge[MAX_BUSES ]; }; -static spinlock_t _pcidevs_lock =SPIN_LOCK_UNLOCKED ; +static DEFINE_RSPINLOCK (_pcidevs_lock);/* Do not use, as it has no speculation barrier, use pcidevs_lock() instead. */ void pcidevs_lock_unsafe (void )
xen/include/xen/sched.h +3 -3
@@ -376,9 +376,9 @@ struct domainrcu_read_lock_t rcu_lock; -spinlock_t domain_lock; +rspinlock_t domain_lock; -spinlock_t page_alloc_lock;/* protects all the following fields */ +rspinlock_t page_alloc_lock;/* protects all the following fields */ struct page_list_head page_list;/* linked list */ struct page_list_head extra_page_list;/* linked list (size extra_pages) */ struct page_list_head xenpage_list;/* linked list (size xenheap_pages) */
@@ -620,7 +620,7 @@ struct domain#ifdef CONFIG_IOREQ_SERVER /* Lock protects all other values in the sub-struct */ struct { -spinlock_t lock; +rspinlock_t lock;struct ioreq_server *server[MAX_NR_IOREQ_SERVERS ]; } ioreq_server;#endif
xen/include/xen/spinlock.h +15 -4
@@ -46,7 +46,7 @@ union lock_debug { }; lock profiling on: Global locks which should be subject to profiling must be declared via - DEFINE_SPINLOCK. + DEFINE_[R]SPINLOCK. For locks in structures further measures are necessary: - the structure definition must include a profile_head with exactly this
@@ -57,7 +57,7 @@ union lock_debug { }; - the single locks which are subject to profiling have to be initialized via -spin_lock_init_prof (ptr ,lock ); + [r]spin_lock_init_prof(ptr, lock); with ptr being the main structure pointer and lock the spinlock field
@@ -110,12 +110,16 @@ struct lock_profile_qhead {spinlock_t l =SPIN_LOCK_UNLOCKED_ (NULL ); \ static struct lock_profile lock_profile_data__##l = LOCK_PROFILE_(l); \ LOCK_PROFILE_PTR_(l) +#define DEFINE_RSPINLOCK (l) \ + rspinlock_t l = SPIN_LOCK_UNLOCKED_(NULL); \ + static struct lock_profile lock_profile_data__##l = LOCK_PROFILE_(l); \ + LOCK_PROFILE_PTR_(l) -#define spin_lock_init_prof (s, l) \ +#define spin_lock_init_prof__ (s, l, locktype) \ do { \ struct lock_profile *prof; \ prof = xzalloc(struct lock_profile); \ - (s)->l = (spinlock_t)SPIN_LOCK_UNLOCKED_(prof); \ + (s)->l = (locktype)SPIN_LOCK_UNLOCKED_(prof); \ if ( !prof ) \ { \ printk(XENLOG_WARNING \
@@ -129,6 +133,9 @@ struct lock_profile_qhead { (s)->profile_head.elem_q = prof; \ } while( 0 ) +#define spin_lock_init_prof (s, l) spin_lock_init_prof__(s, l, spinlock_t) +#define rspin_lock_init_prof (s, l) spin_lock_init_prof__(s, l, rspinlock_t) +void _lock_profile_register_struct (int32_t type,struct lock_profile_qhead *qhead,int32_t idx); void _lock_profile_deregister_struct(int32_t type,
@@ -152,8 +159,10 @@ struct lock_profile_qhead { }; .debug = LOCK_DEBUG_, \ }#define DEFINE_SPINLOCK (l) spinlock_t l = SPIN_LOCK_UNLOCKED +#define DEFINE_RSPINLOCK (l) rspinlock_t l = SPIN_LOCK_UNLOCKED#define spin_lock_init_prof (s, l) spin_lock_init(&((s)->l)) +#define rspin_lock_init_prof (s, l) rspin_lock_init(&((s)->l))#define lock_profile_register_struct (type, ptr, idx)#define lock_profile_deregister_struct (type, ptr)#define spinlock_profile_printall (key)
@@ -183,8 +192,10 @@ typedef struct spinlock {#endif } spinlock_t; +typedef spinlock_t rspinlock_t ;#define spin_lock_init (l) (*(l) = (spinlock_t)SPIN_LOCK_UNLOCKED) +#define rspin_lock_init (l) (*(l) = (rspinlock_t)SPIN_LOCK_UNLOCKED)void _spin_lock (spinlock_t *lock);void _spin_lock_cb (spinlock_t *lock,void (*cb)(void *data),void *data);
Signature · 1 line
2.35.3
Re: [PATCH v5 02/13] xen/spinlock: introduce new type for recursive spinlocks
Quoted 11 lines · Juergen Gross
Introduce a new type "
rspinlock_t" to be used for recursive spinlocks.For now it is only an alias of
spinlock_t, so both types can still be used for recursive spinlocks. This will be changed later, though.Switch all recursive spinlocks to the new type.
Define the initializer helpers and use them where appropriate.
Signed-off-by Juergen Gross <[email protected]>Acked-by Julien Grall <[email protected]>
PATCH v5 3/13 xen/spinlock: rename recursive lock functions
In reply to Juergen GrossRename the recursive spin_lock() functions by replacing the trailing "_recursive" with a leading "r".
Switch the parameter to be a pointer to rspinlock_t.
---
V2:
- new patch
V5:
- let rspin_trylock() return bool (Jan Beulich)
- keep inline/macro layer
--- xen/arch/arm/domain.c | 4 +-- xen/arch/x86/domain.c | 8 +++--- xen/arch/x86/mm/mem_sharing.c | 8 +++--- xen/arch/x86/mm/mm-locks.h | 4 +-- xen/common/ioreq.c | 52 +++++++++++++++++------------------ xen/common/page_alloc.c | 12 ++++---- xen/common/spinlock.c | 12 ++++---- xen/drivers/char/console.c | 12 ++++---- xen/drivers/passthrough/pci.c | 4 +-- xen/include/xen/sched.h | 4 +-- xen/include/xen/spinlock.h | 18 ++++++------ 11 files changed, 68 insertions(+), 70 deletions(-)
xen/arch/arm/domain.c +2 -2
@@ -987,7 +987,7 @@ static int relinquish_memory(struct domain *d, struct page_list_head *list)int ret =0 ;/* Use a recursive lock, as we may enter 'free_domheap_page'. */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);page_list_for_each_safe ( page, tmp, list ) {
@@ -1014,7 +1014,7 @@ static int relinquish_memory(struct domain *d, struct page_list_head *list) } out: -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);return ret; }
xen/arch/x86/domain.c +4 -4
@@ -1323,7 +1323,7 @@ int arch_set_info_guest( {bool done = false; -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);for ( i =0 ; ; ) {
@@ -1344,7 +1344,7 @@ int arch_set_info_guest(break ; } -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);if ( !done )return -ERESTART ;
@@ -2183,7 +2183,7 @@ static int relinquish_memory(int ret =0 ;/* Use a recursive lock, as we may enter 'free_domheap_page'. */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);while ( (page =page_list_remove_head (list)) ) {
@@ -2324,7 +2324,7 @@ static int relinquish_memory(page_list_move (list, &d->arch.relmem_list); out: -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);return ret; }
xen/arch/x86/mm/mem_sharing.c +4 -4
@@ -682,7 +682,7 @@ static int page_make_sharable(struct domain *d,int rc =0 ;bool drop_dom_ref = false; -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);if ( d->is_dying ) {
@@ -725,7 +725,7 @@ static int page_make_sharable(struct domain *d, } out: -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);if ( drop_dom_ref )put_domain (d);
@@ -1936,7 +1936,7 @@ int mem_sharing_fork_reset(struct domain *d, bool reset_state, goto state;/* need recursive lock because we will free pages */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);page_list_for_each_safe (page, tmp, &d->page_list) {shr_handle_t sh;
@@ -1965,7 +1965,7 @@ int mem_sharing_fork_reset(struct domain *d, bool reset_state,put_page_alloc_ref (page);put_page_and_type (page); } -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock); state:if ( reset_state )
xen/arch/x86/mm/mm-locks.h +2 -2
@@ -79,7 +79,7 @@ static always_inline void _mm_lock(const struct domain *d, mm_lock_t *l, {if ( !((mm_locked_by_me (l)) && rec) )_check_lock_level (d, level); -spin_lock_recursive (&l->lock); +rspin_lock (&l->lock);if ( l->lock.recurse_cnt ==1 ) { l->locker_function = func;
@@ -202,7 +202,7 @@ static inline void mm_unlock(mm_lock_t *l) l->locker_function ="nobody" ;_set_lock_level (l->unlock_level); } -spin_unlock_recursive (&l->lock); +rspin_unlock (&l->lock); } static inline void mm_enforce_order_unlock(int unlock_level,
xen/common/ioreq.c +26 -26
205 lines not on this page · raw message
xen/common/page_alloc.c +6 -6
@@ -2500,7 +2500,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)if (unlikely (is_xen_heap_page (pg)) ) {/* NB. May recursively lock from relinquish_memory(). */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);for ( i =0 ; i < (1 << order); i++ )arch_free_heap_page (d, &pg[i]);
@@ -2508,7 +2508,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) d->xenheap_pages -=1 << order; drop_dom_ref = (d->xenheap_pages ==0 ); -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock); }else {
@@ -2517,7 +2517,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)if (likely (d) &&likely (d != dom_cow) ) {/* NB. May recursively lock from relinquish_memory(). */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);for ( i =0 ; i < (1 << order); i++ ) {
@@ -2540,7 +2540,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) drop_dom_ref = !domain_adjust_tot_pages (d, -(1 << order)); -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);/* * Normally we expect a domain to clear pages before freeing them,
@@ -2756,7 +2756,7 @@ void free_domstatic_page(struct page_info *page)ASSERT_ALLOC_CONTEXT ();/* NB. May recursively lock from relinquish_memory(). */ -spin_lock_recursive (&d->page_alloc_lock); +rspin_lock (&d->page_alloc_lock);arch_free_heap_page (d, page);
@@ -2767,7 +2767,7 @@ void free_domstatic_page(struct page_info *page)/* Add page on the resv_page_list *after* it has been freed. */ page_list_add_tail (page, &d->resv_page_list); -spin_unlock_recursive (&d->page_alloc_lock); +rspin_unlock (&d->page_alloc_lock);if ( drop_dom_ref )put_domain (d);
xen/common/spinlock.c +6 -6
@@ -436,7 +436,7 @@ void _spin_barrier(spinlock_t *lock)smp_mb (); } -int _spin_trylock_recursive (spinlock_t *lock) +bool _rspin_trylock (rspinlock_t *lock) {unsigned int cpu =smp_processor_id ();
@@ -448,8 +448,8 @@ int _spin_trylock_recursive(spinlock_t *lock)if (likely (lock->recurse_cpu != cpu) ) { -if ( !spin_trylock (lock) ) -return 0 ; +if ( !_spin_trylock (lock) ) +return false; lock->recurse_cpu = cpu; }
@@ -457,10 +457,10 @@ int _spin_trylock_recursive(spinlock_t *lock)ASSERT (lock->recurse_cnt <SPINLOCK_MAX_RECURSE ); lock->recurse_cnt++; -return 1 ; +return true; } -void _spin_lock_recursive (spinlock_t *lock) +void _rspin_lock (rspinlock_t *lock) {unsigned int cpu =smp_processor_id ();
@@ -475,7 +475,7 @@ void _spin_lock_recursive(spinlock_t *lock) lock->recurse_cnt++; } -void _spin_unlock_recursive (spinlock_t *lock) +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) ) {
xen/drivers/char/console.c +6 -6
@@ -919,7 +919,7 @@ static void vprintk_common(const char *prefix, const char *fmt, va_list args)/* console_lock can be acquired recursively from __printk_ratelimit(). */ local_irq_save (flags); -spin_lock_recursive (&console_lock); +rspin_lock (&console_lock); state = &this_cpu (state); (void )vsnprintf (buf,sizeof (buf), fmt, args);
@@ -955,7 +955,7 @@ static void vprintk_common(const char *prefix, const char *fmt, va_list args) state->continued =1 ; } -spin_unlock_recursive (&console_lock); +rspin_unlock (&console_lock);local_irq_restore (flags); }
@@ -1162,14 +1162,14 @@ unsigned long console_lock_recursive_irqsave(void)unsigned long flags;local_irq_save (flags); -spin_lock_recursive (&console_lock); +rspin_lock (&console_lock);return flags; }void console_unlock_recursive_irqrestore (unsigned long flags) { -spin_unlock_recursive (&console_lock); +rspin_unlock (&console_lock);local_irq_restore (flags); }
@@ -1230,12 +1230,12 @@ int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst)char lost_str[8 ];snprintf (lost_str,sizeof (lost_str),"%d" , lost);/* console_lock may already be acquired by printk(). */ -spin_lock_recursive (&console_lock); +rspin_lock (&console_lock);printk_start_of_line ("(XEN) " );__putstr ("printk: " );__putstr (lost_str);__putstr (" messages suppressed.\n" ); -spin_unlock_recursive (&console_lock); +rspin_unlock (&console_lock); }local_irq_restore (flags);return 1 ;
xen/drivers/passthrough/pci.c +2 -2
@@ -55,12 +55,12 @@ static DEFINE_RSPINLOCK(_pcidevs_lock);/* Do not use, as it has no speculation barrier, use pcidevs_lock() instead. */ void pcidevs_lock_unsafe (void ) { -_spin_lock_recursive (&_pcidevs_lock); +_rspin_lock (&_pcidevs_lock); }void pcidevs_unlock (void ) { -spin_unlock_recursive (&_pcidevs_lock); +rspin_unlock (&_pcidevs_lock); }bool pcidevs_locked (void )
xen/include/xen/sched.h +2 -2
@@ -358,8 +358,8 @@ struct sched_unit { (v) = (v)->next_in_list )/* Per-domain lock can be recursively acquired in fault handlers. */ -#define domain_lock (d) spin_lock_recursive(&(d)->domain_lock) -#define domain_unlock (d) spin_unlock_recursive(&(d)->domain_lock) +#define domain_lock (d) rspin_lock(&(d)->domain_lock) +#define domain_unlock (d) rspin_unlock(&(d)->domain_lock)struct evtchn_port_ops ;
xen/include/xen/spinlock.h +8 -10
@@ -210,10 +210,6 @@ int _spin_is_locked(const spinlock_t *lock);int _spin_trylock (spinlock_t *lock);void _spin_barrier (spinlock_t *lock); -int _spin_trylock_recursive (spinlock_t *lock); -void _spin_lock_recursive (spinlock_t *lock); -void _spin_unlock_recursive (spinlock_t *lock); - static always_inline void spin_lock(spinlock_t *l) {_spin_lock (l);
@@ -268,21 +264,23 @@ static always_inline void spin_lock_if(bool condition, spinlock_t *l)#define spin_barrier (l) _spin_barrier(l)/* -* spin_[un]lock_recursive(): Use these forms when the lock can (safely!) be +* rspin_[un]lock(): Use these forms when the lock can (safely!) be * reentered recursively on the same CPU. All critical regions that may form * part of a recursively-nested set must be protected by these forms. If there * are any critical regions that cannot form part of such a set, they can use * standard spin_[un]lock(). */ -#define spin_trylock_recursive (l) \ - lock_evaluate_nospec(_spin_trylock_recursive(l)) +bool _rspin_trylock (rspinlock_t *lock); +void _rspin_lock (rspinlock_t *lock); +void _rspin_unlock (rspinlock_t *lock); -static always_inline void spin_lock_recursive(spinlock_t *l) +static always_inline void rspin_lock(rspinlock_t *lock) { -_spin_lock_recursive (l); +_rspin_lock (lock);block_lock_speculation (); } -#define spin_unlock_recursive (l) _spin_unlock_recursive(l) +#define rspin_trylock (l) lock_evaluate_nospec(_rspin_trylock(l)) +#define rspin_unlock (l) _rspin_unlock(l)#endif /* __SPINLOCK_H__ */
Signature · 1 line
2.35.3
PATCH v5 4/13 xen/spinlock: add rspin_[un]lock_irq[save|restore]()
In reply to Juergen GrossInstead of special casing rspin_lock_irqsave() and rspin_unlock_irqrestore() for the console lock, add those functions to spinlock handling and use them where needed.
---
V2:
- new patch
V5:
- avoid MISRA violation (Julien Grall)
- keep wrapper functions (Jan Beulich)
--- xen/common/spinlock.c | 18 +++++++++++++++++- xen/drivers/char/console.c | 6 ++---- xen/include/xen/spinlock.h | 9 +++++++++ 3 files changed, 28 insertions(+), 5 deletions(-)
xen/common/spinlock.c +17 -1
@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); + +return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) ) { lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock); } } +void _rspin_unlock_irqrestore (rspinlock_t *lock,unsigned long flags) +{ +_rspin_unlock (lock); +local_irq_restore (flags); +} +#ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile_anc {
xen/drivers/char/console.c +2 -4
@@ -1161,16 +1161,14 @@ unsigned long console_lock_recursive_irqsave(void) {unsigned long flags; -local_irq_save (flags); -rspin_lock (&console_lock); +rspin_lock_irqsave (&console_lock, flags);return flags; }void console_unlock_recursive_irqrestore (unsigned long flags) { -rspin_unlock (&console_lock); -local_irq_restore (flags); +rspin_unlock_irqrestore (&console_lock, flags); }void console_force_unlock (void )
xen/include/xen/spinlock.h +9 -0
@@ -272,7 +272,15 @@ static always_inline void spin_lock_if(bool condition, spinlock_t *l)*/ bool _rspin_trylock (rspinlock_t *lock);void _rspin_lock (rspinlock_t *lock); +#define rspin_lock_irqsave (l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _rspin_lock_irqsave(l)); \ + block_lock_speculation(); \ + }) +unsigned long _rspin_lock_irqsave (rspinlock_t *lock);void _rspin_unlock (rspinlock_t *lock); +void _rspin_unlock_irqrestore (rspinlock_t *lock,unsigned long flags); static always_inline void rspin_lock(rspinlock_t *lock) {
@@ -282,5 +290,6 @@ static always_inline void rspin_lock(rspinlock_t *lock)#define rspin_trylock (l) lock_evaluate_nospec(_rspin_trylock(l))#define rspin_unlock (l) _rspin_unlock(l) +#define rspin_unlock_irqrestore (l, f) _rspin_unlock_irqrestore(l, f)#endif /* __SPINLOCK_H__ */
Signature · 1 line
2.35.3
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>
with two remarks:
Quoted 13 lines
xen/common/spinlock.c +7
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); +
xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 10 lines
xen/common/spinlock.c +4
-1+return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) ) { lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);
This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
xen/include/xen/spinlock.h static always_inline void spin_lock_if(bool condition, spinlock_t *l) · line 278
Quoted 10 lines
xen/include/xen/spinlock.h +4
-0@@ -272,7 +272,15 @@ static always_inline void spin_lock_if(bool condition, spinlock_t *l)*/ bool _rspin_trylock (rspinlock_t *lock);void _rspin_lock (rspinlock_t *lock); +#define rspin_lock_irqsave (l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _rspin_lock_irqsave(l)); \
Perhaps in the context of another patch in the series I think I had pointed out that the outer pair of parentheses is unnecessary in constructs like this. I'd be fine adjusting this while committing, as long as for the other item above you'd provide some text to add.
Jan
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 29 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
Quoted 19 lines
xen/common/spinlock.c +10
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); + +return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) )
Quoted 8 lines
xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 4 lines
xen/common/spinlock.c +1
-1{ lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
I think it would be better to move that change to patch 3.
Quoted 15 lines
xen/include/xen/spinlock.h static always_inline void spin_lock_if(bool condition, spinlock_t *l) · line 278
Quoted 11 lines
xen/include/xen/spinlock.h +4
-0@@ -272,7 +272,15 @@ static always_inline void spin_lock_if(bool condition, spinlock_t *l)*/ bool _rspin_trylock (rspinlock_t *lock);void _rspin_lock (rspinlock_t *lock); +#define rspin_lock_irqsave (l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long)); \ + ((f) = _rspin_lock_irqsave(l)); \Perhaps in the context of another patch in the series I think I had pointed out that the outer pair of parentheses is unnecessary in constructs like this.
Oh, this one slipped through, sorry for that.
Will fix it in the next iteration.
Juergen
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 39 lines · Jürgen Groß
Quoted 29 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
Quoted 19 lines
xen/common/spinlock.c +10
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); + +return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) )Quoted 8 lines
xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 4 lines
xen/common/spinlock.c +1
-1{ lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
Quoted 1 line
I think it would be better to move that change to patch 3.
Hmm, it would be a secondary change there, too. I was actually meaning to commit patches 2-5, but if things want moving around I guess I better wait with doing so?
Jan
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Jürgen Groß
Quoted 37 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
Quoted 13 lines
xen/common/spinlock.c +7
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); +xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 10 lines
xen/common/spinlock.c +4
-1+return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) ) { lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
Quoted 5 lines
Quoted 1 line
I think it would be better to move that change to patch 3.
Hmm, it would be a secondary change there, too. I was actually meaning to commit patches 2-5, but if things want moving around I guess I better wait with doing so?
Hmm, maybe just drop this hunk and let patch 7 handle it?
Juergen
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 41 lines · Jürgen Groß
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Jürgen Groß
Quoted 37 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
Quoted 13 lines
xen/common/spinlock.c +7
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); +xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 10 lines
xen/common/spinlock.c +4
-1+return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) ) { lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
I think it would be better to move that change to patch 3.
Hmm, it would be a secondary change there, too. I was actually meaning to commit patches 2-5, but if things want moving around I guess I better wait with doing so?
Hmm, maybe just drop this hunk and let patch 7 handle it?
Ah yes, that seem more logical to me. I take it you don't mean "hunk" though, but really just this one line change.
Jan
Re: [PATCH v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]()
Quoted 44 lines · Jan Beulich
Quoted 43 lines · Jürgen Groß
Quoted 42 lines · Jan Beulich
Quoted 40 lines · Jürgen Groß
Quoted 29 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
Instead of special casing
rspin_lock_irqsave()andrspin_unlock_irqrestore()for the console lock, add those functions to spinlock handling and use them where needed.Signed-off-by Juergen Gross <[email protected]>Reviewed-by Jan Beulich <[email protected]>with two remarks:
Quoted 19 lines
xen/common/spinlock.c +10
-0@@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } +unsigned long _rspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_rspin_lock (lock); + +return flags; +} +void _rspin_unlock (rspinlock_t *lock) {if (likely (--lock->recurse_cnt ==0 ) )Quoted 8 lines
xen/common/spinlock.c void _rspin_lock(rspinlock_t *lock) · line 493
Quoted 4 lines
xen/common/spinlock.c +1
-1{ lock->recurse_cpu =SPINLOCK_NO_CPU ; -spin_unlock (lock); +_spin_unlock (lock);This looks like an unrelated change. I think I can guess the purpose, but it would be nice if such along-the-way changes could be mentioned in the description.
I think it would be better to move that change to patch 3.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Hmm, it would be a secondary change there, too. I was actually meaning to commit patches 2-5, but if things want moving around I guess I better wait with doing so?
Hmm, maybe just drop this hunk and let patch 7 handle it?
Ah yes, that seem more logical to me. I take it you don't mean "hunk" though, but really just this one line change.
Oh yes, of course.
Juergen
PATCH v5 5/13 xen/spinlock: make struct lock_profile rspinlock_t aware
In reply to Juergen GrossStruct lock_profile contains a pointer to the spinlock it is associated with. Prepare support of differing spinlock_t and rspinlock_t types by adding a type indicator of the pointer. Use the highest bit of the block_cnt member for this indicator in order to not grow the struct while hurting only the slow path with slightly less performant code. Note that this requires a cast when printing the value in order to be format compliant.
---
V2:
- new patch
V5:
- use bool for is_rlock (Julien Grall)
- use unsigned int for lockval in spinlock_profile_print_elem() (Jan Beulich)
- don't use anonymous union (Jan Beulich)
--- xen/common/spinlock.c | 28 ++++++++++++++++++++-------- xen/include/xen/spinlock.h | 14 ++++++++++---- 2 files changed, 30 insertions(+), 12 deletions(-)
xen/common/spinlock.c +20 -8
@@ -538,19 +538,31 @@ static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par) static void cf_check spinlock_profile_print_elem(struct lock_profile *data,int32_t type,int32_t idx,void *par) { -struct spinlock *lock = data->lock; +unsigned int cpu; +unsigned int lockval; + +if ( data->is_rlock ) + { + cpu = data->ptr.rlock->debug.cpu; + lockval = data->ptr.rlock->tickets.head_tail; + } +else + { + cpu = data->ptr.lock->debug.cpu; + lockval = data->ptr.lock->tickets.head_tail; + }printk ("%s " , lock_profile_ancs[type].name);if ( type !=LOCKPROF_TYPE_GLOBAL )printk ("%d " , idx); -printk ("%s: addr=%p, lockval=%08x, " , data->name, lock, - lock->tickets.head_tail); -if ( lock->debug.cpu ==SPINLOCK_NO_CPU ) +printk ("%s: addr=%p, lockval=%08x, " , data->name, data->ptr.lock, lockval); +if ( cpu ==SPINLOCK_NO_CPU )printk ("not locked\n" );else -printk ("cpu=%d\n" , lock->debug.cpu); -printk (" lock:%" PRId64"(%" PRI_stime"), block:%" PRId64"(%" PRI_stime")\n" , - data->lock_cnt, data->time_hold, data->block_cnt, data->time_block); +printk ("cpu=%u\n" , cpu); +printk (" lock:%" PRIu64"(%" PRI_stime"), block:%" PRIu64"(%" PRI_stime")\n" , + data->lock_cnt, data->time_hold, (uint64_t )data->block_cnt, + data->time_block); } void cf_check spinlock_profile_printall(unsigned char key)
@@ -680,7 +692,7 @@ static int __init cf_check lock_prof_init(void) { (*q)->next = lock_profile_glb_q.elem_q; lock_profile_glb_q.elem_q = *q; - (*q)->lock->profile = *q; + (*q)->ptr.lock->profile = *q; } _lock_profile_register_struct(LOCKPROF_TYPE_GLOBAL,
xen/include/xen/spinlock.h +10 -4
@@ -77,13 +77,19 @@ union lock_debug { };*/ struct spinlock ; +/* Temporary hack until a dedicated struct rspinlock is existing. */ +#define rspinlock spinlockstruct lock_profile {struct lock_profile *next;/* forward link */ const char *name;/* lock name */ -struct spinlock *lock;/* the lock itself */ +union { +struct spinlock *lock;/* the lock itself */ +struct rspinlock *rlock;/* the recursive lock itself */ + } ptr;uint64_t lock_cnt;/* # of complete locking ops */ -uint64_t block_cnt;/* # of complete wait for lock */ +uint64_t block_cnt:63 ;/* # of complete wait for lock */ +bool is_rlock:1 ;/* use rlock pointer */ s_time_t time_hold;/* cumulated lock time */ s_time_t time_block;/* cumulated wait time */ s_time_t time_locked;/* system time of last locking */
@@ -95,7 +101,7 @@ struct lock_profile_qhead {int32_t idx;/* index for printout */ }; -#define LOCK_PROFILE_ (lockname) { .name = #lockname, .lock = &(lockname), } +#define LOCK_PROFILE_ (lockname) { .name = #lockname, .ptr.lock = &(lockname), }#define LOCK_PROFILE_PTR_ (name) \ static struct lock_profile * const lock_profile__##name \ __used_section(".lockprofile.data") = \
@@ -128,7 +134,7 @@ struct lock_profile_qhead {break ; \ } \ prof->name = #l; \ - prof->lock = &(s)->l; \ + prof->ptr.lock = &(s)->l; \ prof->next = (s)->profile_head.elem_q; \ (s)->profile_head.elem_q = prof; \ }while (0 )
Signature · 1 line
2.35.3
PATCH v5 6/13 xen/spinlock: add explicit non-recursive locking functions
In reply to Juergen GrossIn order to prepare a type-safe recursive spinlock structure, add explicitly non-recursive locking functions to be used for non-recursive locking of spinlocks, which are used recursively, too.
---
V2:
- rename functions (Jan Beulich)
- get rid of !! in pcidevs_locked() (Jan Beulich)
V5:
- remove spurious change (Julien Grall)
- add nrspin_lock() description (Julien Grall)
--- xen/arch/arm/mm.c | 4 ++-- xen/arch/x86/domain.c | 12 ++++++------ xen/arch/x86/mm.c | 12 ++++++------ xen/arch/x86/mm/mem_sharing.c | 8 ++++---- xen/arch/x86/mm/p2m-pod.c | 4 ++-- xen/arch/x86/mm/p2m.c | 4 ++-- xen/arch/x86/tboot.c | 4 ++-- xen/common/domctl.c | 4 ++-- xen/common/grant_table.c | 10 +++++----- xen/common/memory.c | 4 ++-- xen/common/numa.c | 4 ++-- xen/common/page_alloc.c | 16 ++++++++-------- xen/drivers/char/console.c | 16 ++++++++-------- xen/include/xen/spinlock.h | 29 +++++++++++++++++++++++------ 14 files changed, 74 insertions(+), 57 deletions(-)
xen/arch/arm/mm.c +2 -2
@@ -105,7 +105,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,if (page_get_owner (page) == d )return ; -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);/* * The incremented type count pins as writable or read-only.
@@ -136,7 +136,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,page_list_add_tail (page, &d->xenpage_list); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); } int xenmem_add_to_physmap_one(
xen/arch/x86/domain.c +6 -6
@@ -212,7 +212,7 @@ void dump_pageframe_info(struct domain *d) {unsigned long total[MASK_EXTR (PGT_type_mask, PGT_type_mask) +1 ] = {}; -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { unsigned int index = MASK_EXTR(page->u.inuse.type_info,
@@ -231,13 +231,13 @@ void dump_pageframe_info(struct domain *d)_p (mfn_x (page_to_mfn (page))), page->count_info, page->u.inuse.type_info); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); }if (is_hvm_domain (d) )p2m_pod_dump_data (d); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); page_list_for_each ( page, &d->xenpage_list ) {
@@ -253,7 +253,7 @@ void dump_pageframe_info(struct domain *d) page->count_info, page->u.inuse.type_info); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); } void update_guest_memory_policy(struct vcpu *v,
@@ -2448,10 +2448,10 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask =0 ; } -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);page_list_splice (&d->arch.relmem_list, &d->page_list);INIT_PAGE_LIST_HEAD (&d->arch.relmem_list); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); PROGRESS(xen):
xen/arch/x86/mm.c +6 -6
@@ -482,7 +482,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,set_gpfn_from_mfn (mfn_x (page_to_mfn (page)),INVALID_M2P_ENTRY ); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);/* The incremented type count pins as writable or read-only. */ page->u.inuse.type_info =
@@ -502,7 +502,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,page_list_add_tail (page, &d->xenpage_list); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); }void make_cr3 (struct vcpu *v,mfn_t mfn)
@@ -3597,11 +3597,11 @@ long do_mmuext_op( {bool drop_ref; -spin_lock (&pg_owner->page_alloc_lock); +nrspin_lock (&pg_owner->page_alloc_lock); drop_ref = (pg_owner->is_dying &&test_and_clear_bit (_PGT_pinned, &page->u.inuse.type_info)); -spin_unlock (&pg_owner->page_alloc_lock); +nrspin_unlock (&pg_owner->page_alloc_lock);if ( drop_ref ) { pin_drop:
@@ -4424,7 +4424,7 @@ int steal_page(* that it might be upon return from alloc_domheap_pages with * MEMF_no_owner set. */ -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);BUG_ON (page->u.inuse.type_info & (PGT_count_mask | PGT_locked | PGT_pinned));
@@ -4436,7 +4436,7 @@ int steal_page(if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages (d,-1 ) ) drop_dom_ref = true; -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);if (unlikely (drop_dom_ref) )put_domain (d);
xen/arch/x86/mm/mem_sharing.c +4 -4
@@ -740,11 +740,11 @@ static int page_make_private(struct domain *d, struct page_info *page)if ( !get_page (page, dom_cow) )return -EINVAL ; -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);if ( d->is_dying ) { -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);put_page (page);return -EBUSY ; }
@@ -752,7 +752,7 @@ static int page_make_private(struct domain *d, struct page_info *page) expected_type = (PGT_shared_page | PGT_validated | PGT_locked |2 );if ( page->u.inuse.type_info != expected_type ) { -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);put_page (page);return -EEXIST ; }
@@ -769,7 +769,7 @@ static int page_make_private(struct domain *d, struct page_info *page)if (domain_adjust_tot_pages (d,1 ) ==1 )get_knownalive_domain (d);page_list_add_tail (page, &d->page_list); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);put_page (page);
xen/arch/x86/mm/p2m-pod.c +2 -2
@@ -27,7 +27,7 @@ static always_inline void lock_page_alloc(struct p2m_domain *p2m) {page_alloc_mm_pre_lock (p2m->domain); -spin_lock (&(p2m->domain->page_alloc_lock)); +nrspin_lock (&(p2m->domain->page_alloc_lock));page_alloc_mm_post_lock (p2m->domain, p2m->domain->arch.page_alloc_unlock_level); }
@@ -35,7 +35,7 @@ static always_inline void lock_page_alloc(struct p2m_domain *p2m)static inline void unlock_page_alloc (struct p2m_domain *p2m) {page_alloc_mm_unlock (p2m->domain->arch.page_alloc_unlock_level); -spin_unlock (&(p2m->domain->page_alloc_lock)); +nrspin_unlock (&(p2m->domain->page_alloc_lock)); }/*
xen/arch/x86/mm/p2m.c +2 -2
@@ -2228,7 +2228,7 @@ void audit_p2m(struct domain *d,/* Audit part two: walk the domain's page allocation list, checking * the m2p entries. */ -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { mfn =mfn_x (page_to_mfn (page));
@@ -2280,7 +2280,7 @@ void audit_p2m(struct domain *d,P2M_PRINTK ("OK: mfn=%#lx, gfn=%#lx, p2mfn=%#lx\n" , mfn, gfn,mfn_x (p2mfn)); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);pod_unlock (p2m);p2m_unlock (p2m);
xen/arch/x86/tboot.c +2 -2
@@ -205,14 +205,14 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE],continue ;printk ("MACing Domain %u\n" , d->domain_id); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);page_list_for_each (page, &d->page_list) {void *pg =__map_domain_page (page);vmac_update (pg,PAGE_SIZE , &ctx);unmap_domain_page (pg); } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);if (is_iommu_enabled (d) && is_vtd ) {
xen/common/domctl.c +2 -2
@@ -621,14 +621,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) {uint64_t new_max = op->u.max_mem.max_memkb >> (PAGE_SHIFT -10 ); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);/* * NB. We removed a check that new_max >= current tot_pages; this means * that the domain will now be allowed to "ratchet" down to new_max. In * the meantime, while tot > max, all new allocations are disallowed. */ d->max_pages =min (new_max, (uint64_t )(typeof (d->max_pages))-1 ); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);break ; }
xen/common/grant_table.c +5 -5
@@ -2376,7 +2376,7 @@ gnttab_transfer( mfn =page_to_mfn (page); } -spin_lock (&e->page_alloc_lock); +nrspin_lock (&e->page_alloc_lock);/* * Check that 'e' will accept the page and has reservation
@@ -2387,7 +2387,7 @@ gnttab_transfer( unlikely(domain_tot_pages(e) >= e->max_pages) || unlikely(!(e->tot_pages + 1)) ) { -spin_unlock (&e->page_alloc_lock); +nrspin_unlock (&e->page_alloc_lock);if ( e->is_dying ) gdprintk(XENLOG_INFO, "Transferee d%d is dying\n",
@@ -2411,7 +2411,7 @@ gnttab_transfer(* safely drop the lock and re-aquire it later to add page to the * pagelist. */ -spin_unlock (&e->page_alloc_lock); +nrspin_unlock (&e->page_alloc_lock); okay =gnttab_prepare_for_transfer (e, d, gop.ref);/*
@@ -2427,9 +2427,9 @@ gnttab_transfer(* Need to grab this again to safely free our "reserved" * page in the page total */ -spin_lock (&e->page_alloc_lock); +nrspin_lock (&e->page_alloc_lock); drop_dom_ref = !domain_adjust_tot_pages (e,-1 ); -spin_unlock (&e->page_alloc_lock); +nrspin_unlock (&e->page_alloc_lock);if ( okay/* i.e. e->is_dying due to the surrounding if() */ ) gdprintk(XENLOG_INFO, "Transferee d%d is now dying\n",
xen/common/memory.c +2 -2
@@ -770,10 +770,10 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) (1UL << in_chunk_order)) - (j * (1UL << exch.out.extent_order))); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); drop_dom_ref = (dec_count && !domain_adjust_tot_pages (d, -dec_count)); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);if ( drop_dom_ref )put_domain (d);
xen/common/numa.c +2 -2
@@ -719,13 +719,13 @@ static void cf_check dump_numa(unsigned char key)memset (page_num_node,0 ,sizeof (page_num_node)); -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { i =page_to_nid (page); page_num_node[i]++; } -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); for_each_online_node ( i ) printk(" Node %u: %u\n", i, page_num_node[i]);
xen/common/page_alloc.c +8 -8
@@ -514,7 +514,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages)* must always take the global heap_lock rather than only in the much * rarer case that d->outstanding_pages is non-zero */ -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);spin_lock (&heap_lock);/* pages==0 means "unset" the claim. */
@@ -560,7 +560,7 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages) out:spin_unlock (&heap_lock); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);return ret; }
@@ -2346,7 +2346,7 @@ int assign_pages(int rc =0 ;unsigned int i; -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);if (unlikely (d->is_dying) ) {
@@ -2428,7 +2428,7 @@ int assign_pages( } out: -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);return rc; }
@@ -2907,9 +2907,9 @@ mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags)ASSERT_ALLOC_CONTEXT ();/* Acquire a page from reserved page list(resv_page_list). */ -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock); page =page_list_remove_head (&d->resv_page_list); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock);if (unlikely (!page) )return INVALID_MFN ;
@@ -2928,9 +2928,9 @@ mfn_t acquire_reserved_page(struct domain *d, unsigned int memflags)*/ unprepare_staticmem_pages (page,1 , false); fail: -spin_lock (&d->page_alloc_lock); +nrspin_lock (&d->page_alloc_lock);page_list_add_tail (page, &d->resv_page_list); -spin_unlock (&d->page_alloc_lock); +nrspin_unlock (&d->page_alloc_lock); return INVALID_MFN; }#endif
xen/drivers/char/console.c +8 -8
@@ -368,9 +368,9 @@ long read_console_ring(struct xen_sysctl_readconsole *op)if ( op->clear ) { -spin_lock_irq (&console_lock); +nrspin_lock_irq (&console_lock); conringc = p - c > conring_size ? p - conring_size : c; -spin_unlock_irq (&console_lock); +nrspin_unlock_irq (&console_lock); } op->count = sofar;
@@ -638,7 +638,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,if (is_hardware_domain (cd) ) {/* Use direct console output as it could be interactive */ -spin_lock_irq (&console_lock); +nrspin_lock_irq (&console_lock);console_serial_puts (kbuf, kcount);video_puts (kbuf, kcount);
@@ -659,7 +659,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,tasklet_schedule (¬ify_dom0_con_ring_tasklet); } -spin_unlock_irq (&console_lock); +nrspin_unlock_irq (&console_lock); }else {
@@ -1026,9 +1026,9 @@ void __init console_init_preirq(void)pv_console_set_rx_handler (serial_rx);/* HELLO WORLD --- start-of-day banner text. */ -spin_lock (&console_lock); +nrspin_lock (&console_lock);__putstr (xen_banner ()); -spin_unlock (&console_lock); +nrspin_unlock (&console_lock); printk("Xen version %d.%d%s (%s@%s) (%s) %s %s\n", xen_major_version(), xen_minor_version(), xen_extra_version(), xen_compile_by(), xen_compile_domain(), xen_compiler(),
@@ -1065,13 +1065,13 @@ void __init console_init_ring(void) } opt_conring_size =PAGE_SIZE << order; -spin_lock_irqsave (&console_lock, flags); +nrspin_lock_irqsave (&console_lock, flags);for ( i = conringc ; i != conringp; i++ ) ring[i & (opt_conring_size -1 )] = conring[i & (conring_size -1 )]; conring = ring;smp_wmb ();/* Allow users of console_force_unlock() to see larger buffer. */ conring_size = opt_conring_size; -spin_unlock_irqrestore (&console_lock, flags); +nrspin_unlock_irqrestore (&console_lock, flags);printk ("Allocated console ring of %u KiB.\n" , opt_conring_size >>10 ); }
xen/include/xen/spinlock.h +23 -6
@@ -102,6 +102,9 @@ struct lock_profile_qhead { };#define LOCK_PROFILE_ (lockname) { .name = #lockname, .ptr.lock = &(lockname), } +#define RLOCK_PROFILE_ (lockname) { .name = #lockname, \ + .ptr.rlock = &(lockname), \ + .is_rlock = true, }#define LOCK_PROFILE_PTR_ (name) \ static struct lock_profile * const lock_profile__##name \ __used_section(".lockprofile.data") = \
@@ -118,10 +121,10 @@ struct lock_profile_qhead { LOCK_PROFILE_PTR_(l)#define DEFINE_RSPINLOCK (l) \ rspinlock_t l = SPIN_LOCK_UNLOCKED_(NULL); \ - static struct lock_profile lock_profile_data__##l = LOCK_PROFILE_(l); \ + static struct lock_profile lock_profile_data__##l = RLOCK_PROFILE_(l); \ LOCK_PROFILE_PTR_(l) -#define spin_lock_init_prof__ (s, l, locktype) \ +#define spin_lock_init_prof__ (s, l, lockptr, locktype, isr) \ do { \ struct lock_profile *prof; \ prof = xzalloc(struct lock_profile); \
@@ -134,13 +137,16 @@ struct lock_profile_qhead {break ; \ } \ prof->name = #l; \ - prof->ptr.lock = &(s)->l; \ + prof->ptr.lockptr = &(s)->l; \ + prof->is_rlock = isr; \ prof->next = (s)->profile_head.elem_q; \ (s)->profile_head.elem_q = prof; \ } while( 0 ) -#define spin_lock_init_prof (s, l) spin_lock_init_prof__(s, l, spinlock_t) -#define rspin_lock_init_prof (s, l) spin_lock_init_prof__(s, l, rspinlock_t) +#define spin_lock_init_prof (s, l) \ + spin_lock_init_prof__(s, l, lock, spinlock_t, false) +#define rspin_lock_init_prof (s, l) \ + spin_lock_init_prof__(s, l, rlock, rspinlock_t, true)void _lock_profile_register_struct (int32_t type,struct lock_profile_qhead *qhead,int32_t idx);
@@ -274,7 +280,10 @@ static always_inline void spin_lock_if(bool condition, spinlock_t *l)* reentered recursively on the same CPU. All critical regions that may form * part of a recursively-nested set must be protected by these forms. If there * are any critical regions that cannot form part of such a set, they can use -* standard spin_[un]lock(). +* nrspin_[un]lock(). +* The nrspin_[un]lock() forms act the same way as normal spin_[un]lock() +* calls, but operate on rspinlock_t locks. nrspin_lock() and rspin_lock() +* calls are blocking to each other for a specific lock even on the same cpu. */ bool _rspin_trylock (rspinlock_t *lock);void _rspin_lock (rspinlock_t *lock);
@@ -298,4 +307,12 @@ static always_inline void rspin_lock(rspinlock_t *lock)#define rspin_unlock (l) _rspin_unlock(l)#define rspin_unlock_irqrestore (l, f) _rspin_unlock_irqrestore(l, f) +#define nrspin_trylock (l) spin_trylock(l) +#define nrspin_lock (l) spin_lock(l) +#define nrspin_unlock (l) spin_unlock(l) +#define nrspin_lock_irq (l) spin_lock_irq(l) +#define nrspin_unlock_irq (l) spin_unlock_irq(l) +#define nrspin_lock_irqsave (l, f) spin_lock_irqsave(l, f) +#define nrspin_unlock_irqrestore (l, f) spin_unlock_irqrestore(l, f) +#endif /* __SPINLOCK_H__ */
Signature · 1 line
2.35.3
PATCH v5 7/13 xen/spinlock: add another function level
In reply to Juergen GrossAdd another function level in spinlock.c hiding the spinlock_t layout from the low level locking code.
This is done in preparation of introducing rspinlock_t for recursive locks without having to duplicate all of the locking code.
---
V2:
- new patch
V5:
- don't regress spin_is_locked() for rspin-lock (Jan Beulich)
- use bool as return type of spin_is_locked_common() and spin_trylock_common() (Jan Beulich)
--- xen/common/spinlock.c | 103 ++++++++++++++++++++++++------------- xen/include/xen/spinlock.h | 1 + 2 files changed, 68 insertions(+), 36 deletions(-)
xen/common/spinlock.c +67 -36
@@ -261,29 +261,31 @@ void spin_debug_disable(void)#ifdef CONFIG_DEBUG_LOCK_PROFILE +#define LOCK_PROFILE_PAR lock->profile#define LOCK_PROFILE_REL \ - if ( lock->profile ) \ + if ( profile ) \ { \ - lock->profile->time_hold += NOW() - lock->profile->time_locked; \ - lock->profile->lock_cnt++; \ + profile->time_hold += NOW() - profile->time_locked; \ + profile->lock_cnt++; \ }#define LOCK_PROFILE_VAR (var, val) s_time_t var = (val)#define LOCK_PROFILE_BLOCK (var) var = var ? : NOW()#define LOCK_PROFILE_BLKACC (tst, val) \ if ( tst ) \ { \ - lock->profile->time_block += lock->profile->time_locked - (val); \ - lock->profile->block_cnt++; \ + profile->time_block += profile->time_locked - (val); \ + profile->block_cnt++; \ }#define LOCK_PROFILE_GOT (val) \ - if ( lock->profile ) \ + if ( profile ) \ { \ - lock->profile->time_locked = NOW(); \ + profile->time_locked = NOW(); \ LOCK_PROFILE_BLKACC(val, val); \ }#else +#define LOCK_PROFILE_PAR NULL#define LOCK_PROFILE_REL #define LOCK_PROFILE_VAR (var, val)#define LOCK_PROFILE_BLOCK (var)
@@ -307,17 +309,18 @@ static always_inline uint16_t observe_head(const spinlock_tickets_t *t)return read_atomic (&t->head); } -static void always_inline spin_lock_common(spinlock_t *lock, +static void always_inline spin_lock_common(spinlock_tickets_t *t, +union lock_debug *debug, +struct lock_profile *profile,void (*cb)(void *data),void *data) {spinlock_tickets_t tickets =SPINLOCK_TICKET_INC ;LOCK_PROFILE_VAR (block,0 ); -check_lock (&lock->debug, false); +check_lock (debug, false);preempt_disable (); - tickets.head_tail =arch_fetch_and_add (&lock->tickets.head_tail, - tickets.head_tail); -while ( tickets.tail !=observe_head (&lock->tickets) ) + tickets.head_tail =arch_fetch_and_add (&t->head_tail, tickets.head_tail); +while ( tickets.tail !=observe_head (t) ) {LOCK_PROFILE_BLOCK (block);if ( cb )
@@ -325,18 +328,19 @@ static void always_inline spin_lock_common(spinlock_t *lock,arch_lock_relax (); }arch_lock_acquire_barrier (); -got_lock (&lock->debug); +got_lock (debug);LOCK_PROFILE_GOT (block); }void _spin_lock (spinlock_t *lock) { -spin_lock_common (lock,NULL ,NULL ); +spin_lock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ,NULL , +NULL ); }void _spin_lock_cb (spinlock_t *lock,void (*cb)(void *data),void *data) { -spin_lock_common (lock, cb, data); +spin_lock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR , cb, data); }void _spin_lock_irq (spinlock_t *lock)
@@ -355,16 +359,23 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock)return flags; } -void _spin_unlock (spinlock_t *lock) +static void always_inline spin_unlock_common(spinlock_tickets_t *t, +union lock_debug *debug, +struct lock_profile *profile) {LOCK_PROFILE_REL ; -rel_lock (&lock->debug); +rel_lock (debug);arch_lock_release_barrier (); -add_sized (&lock->tickets.head,1 ); +add_sized (&t->head,1 );arch_lock_signal ();preempt_enable (); } +void _spin_unlock (spinlock_t *lock) +{ +spin_unlock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} +void _spin_unlock_irq (spinlock_t *lock) {_spin_unlock (lock);
@@ -377,6 +388,11 @@ void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)local_irq_restore (flags); } +static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t) +{ +return t->head != t->tail; +} +int _spin_is_locked (const spinlock_t *lock) {/*
@@ -385,57 +401,70 @@ int _spin_is_locked(const spinlock_t *lock)* ASSERT()s and alike. */ return lock->recurse_cpu ==SPINLOCK_NO_CPU - ? lock->tickets.head != lock->tickets.tail + ?spin_is_locked_common (&lock->tickets) : lock->recurse_cpu ==smp_processor_id (); } -int _spin_trylock (spinlock_t *lock) +static bool always_inline spin_trylock_common(spinlock_tickets_t *t, +union lock_debug *debug, +struct lock_profile *profile) {spinlock_tickets_t old, new;preempt_disable (); -check_lock (&lock->debug, true); - old =observe_lock (&lock->tickets); +check_lock (debug, true); + old =observe_lock (t);if ( old.head != old.tail ) {preempt_enable (); -return 0 ; +return false; } new = old; new.tail++; -if (cmpxchg (&lock->tickets.head_tail, - old.head_tail, new.head_tail) != old.head_tail ) +if (cmpxchg (&t->head_tail, old.head_tail, new.head_tail) != old.head_tail ) {preempt_enable (); -return 0 ; +return false; }/* * cmpxchg() is a full barrier so no need for an * arch_lock_acquire_barrier(). */ -got_lock (&lock->debug); +got_lock (debug);LOCK_PROFILE_GOT (0 ); -return 1 ; +return true; } -void _spin_barrier (spinlock_t *lock) +int _spin_trylock (spinlock_t *lock) +{ +return spin_trylock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} + +static void always_inline spin_barrier_common(spinlock_tickets_t *t, +union lock_debug *debug, +struct lock_profile *profile) {spinlock_tickets_t sample;LOCK_PROFILE_VAR (block,NOW ()); -check_barrier (&lock->debug); +check_barrier (debug);smp_mb (); - sample =observe_lock (&lock->tickets); + sample =observe_lock (t);if ( sample.head != sample.tail ) { -while (observe_head (&lock->tickets) == sample.head ) +while (observe_head (t) == sample.head )arch_lock_relax (); -LOCK_PROFILE_BLKACC (lock->profile, block); +LOCK_PROFILE_BLKACC (profile, block); }smp_mb (); } +void _spin_barrier (spinlock_t *lock) +{ +spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} +bool _rspin_trylock (rspinlock_t *lock) {unsigned int cpu =smp_processor_id ();
@@ -448,7 +477,8 @@ bool _rspin_trylock(rspinlock_t *lock)if (likely (lock->recurse_cpu != cpu) ) { -if ( !_spin_trylock (lock) ) +if ( !spin_trylock_common (&lock->tickets, &lock->debug, +LOCK_PROFILE_PAR ) )return false; lock->recurse_cpu = cpu; }
@@ -466,7 +496,8 @@ void _rspin_lock(rspinlock_t *lock)if (likely (lock->recurse_cpu != cpu) ) { -_spin_lock (lock); +spin_lock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ,NULL , +NULL ); lock->recurse_cpu = cpu; }
@@ -490,7 +521,7 @@ void _rspin_unlock(rspinlock_t *lock)if (likely (--lock->recurse_cnt ==0 ) ) { lock->recurse_cpu =SPINLOCK_NO_CPU ; -_spin_unlock (lock); +spin_unlock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); } }
xen/include/xen/spinlock.h +1 -0
@@ -165,6 +165,7 @@ extern void cf_check spinlock_profile_reset(unsigned char key);#else struct lock_profile_qhead { }; +struct lock_profile { };#define SPIN_LOCK_UNLOCKED { \ .recurse_cpu = SPINLOCK_NO_CPU, \
Signature · 1 line
2.35.3
Re: [PATCH v5 07/13] xen/spinlock: add another function level
Quoted 7 lines · Juergen Gross
Add another function level in
spinlock.chiding thespinlock_tlayout from the low level locking code.This is done in preparation of introducing
rspinlock_tfor recursive locks without having to duplicate all of the locking code.Signed-off-by Juergen Gross <[email protected]>
PATCH v5 8/13 xen/spinlock: add missing rspin_is_locked() and rspin_barrier()
In reply to Juergen GrossAdd rspin_is_locked() and rspin_barrier() in order to prepare differing spinlock_t and rspinlock_t types.
---
V2:
- partially carved out from V1 patch, partially new V5:
- let rspin_is_locked() return bool (Jan Beulich)
--- xen/arch/x86/mm/p2m-pod.c | 2 +- xen/common/domain.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/spinlock.c | 26 ++++++++++++++++++-------- xen/drivers/char/console.c | 4 ++-- xen/drivers/passthrough/pci.c | 2 +- xen/include/xen/spinlock.h | 4 ++++ 7 files changed, 28 insertions(+), 14 deletions(-)
xen/arch/x86/mm/p2m-pod.c +1 -1
@@ -374,7 +374,7 @@ int p2m_pod_empty_cache(struct domain *d)/* After this barrier no new PoD activities can happen. */ BUG_ON (!d->is_dying); -spin_barrier (&p2m->pod.lock.lock); +rspin_barrier (&p2m->pod.lock.lock);lock_page_alloc (p2m);
xen/common/domain.c +1 -1
@@ -983,7 +983,7 @@ int domain_kill(struct domain *d)case DOMDYING_alive:domain_pause (d); d->is_dying = DOMDYING_dying; -spin_barrier (&d->domain_lock); +rspin_barrier (&d->domain_lock);argo_destroy (d);vnuma_destroy (d->vnuma);domain_set_outstanding_pages (d,0 );
xen/common/page_alloc.c +1 -1
@@ -475,7 +475,7 @@ unsigned long domain_adjust_tot_pages(struct domain *d, long pages) {long dom_before, dom_after, dom_claimed, sys_before, sys_after; -ASSERT (spin_is_locked (&d->page_alloc_lock)); +ASSERT (rspin_is_locked (&d->page_alloc_lock)); d->tot_pages += pages;/*
xen/common/spinlock.c +18 -8
@@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)int _spin_is_locked (const spinlock_t *lock) { -/* -* Recursive locks may be locked by another CPU, yet we return -* "false" here, making this function suitable only for use in -* ASSERT()s and alike. -*/ -return lock->recurse_cpu ==SPINLOCK_NO_CPU - ?spin_is_locked_common (&lock->tickets) - : lock->recurse_cpu ==smp_processor_id (); +return spin_is_locked_common (&lock->tickets); } static bool always_inline spin_trylock_common(spinlock_tickets_t *t,
@@ -465,6 +458,23 @@ void _spin_barrier(spinlock_t *lock)spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); } +bool _rspin_is_locked (const rspinlock_t *lock) +{ +/* +* Recursive locks may be locked by another CPU, yet we return +* "false" here, making this function suitable only for use in +* ASSERT()s and alike. +*/ +return lock->recurse_cpu ==SPINLOCK_NO_CPU + ?spin_is_locked_common (&lock->tickets) + : lock->recurse_cpu ==smp_processor_id (); +} + +void _rspin_barrier (rspinlock_t *lock) +{ +spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} +bool _rspin_trylock (rspinlock_t *lock) {unsigned int cpu =smp_processor_id ();
xen/drivers/char/console.c +2 -2
@@ -327,7 +327,7 @@ static void cf_check do_dec_thresh(unsigned char key, bool unused)static void conring_puts (const char *str,size_t len) { -ASSERT (spin_is_locked (&console_lock)); +ASSERT (rspin_is_locked (&console_lock));while ( len-- ) conring[CONRING_IDX_MASK (conringp++)] = *str++;
@@ -765,7 +765,7 @@ static void __putstr(const char *str) {size_t len =strlen (str); -ASSERT (spin_is_locked (&console_lock)); +ASSERT (rspin_is_locked (&console_lock));console_serial_puts (str, len);video_puts (str, len);
xen/drivers/passthrough/pci.c +1 -1
@@ -65,7 +65,7 @@ void pcidevs_unlock(void)bool pcidevs_locked (void ) { -return !!spin_is_locked (&_pcidevs_lock); +return rspin_is_locked (&_pcidevs_lock); }static struct radix_tree_root pci_segments;
xen/include/xen/spinlock.h +4 -0
@@ -297,6 +297,8 @@ void _rspin_lock(rspinlock_t *lock);unsigned long _rspin_lock_irqsave (rspinlock_t *lock);void _rspin_unlock (rspinlock_t *lock);void _rspin_unlock_irqrestore (rspinlock_t *lock,unsigned long flags); +bool _rspin_is_locked (const rspinlock_t *lock); +void _rspin_barrier (rspinlock_t *lock); static always_inline void rspin_lock(rspinlock_t *lock) {
@@ -307,6 +309,8 @@ static always_inline void rspin_lock(rspinlock_t *lock)#define rspin_trylock (l) lock_evaluate_nospec(_rspin_trylock(l))#define rspin_unlock (l) _rspin_unlock(l)#define rspin_unlock_irqrestore (l, f) _rspin_unlock_irqrestore(l, f) +#define rspin_barrier (l) _rspin_barrier(l) +#define rspin_is_locked (l) _rspin_is_locked(l)#define nrspin_trylock (l) spin_trylock(l)#define nrspin_lock (l) spin_lock(l)
Signature · 1 line
2.35.3
Re: [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier()
Quoted 6 lines · Juergen Gross
xen/common/spinlock.c +0
-0@@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)int _spin_is_locked (const spinlock_t *lock) {
xen/common/spinlock.c static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t) · line 399
Quoted 10 lines
xen/common/spinlock.c +1
-8-/* -* Recursive locks may be locked by another CPU, yet we return -* "false" here, making this function suitable only for use in -* ASSERT()s and alike. -*/ -return lock->recurse_cpu ==SPINLOCK_NO_CPU - ?spin_is_locked_common (&lock->tickets) - : lock->recurse_cpu ==smp_processor_id (); +return spin_is_locked_common (&lock->tickets); }
The "only suitable for ASSERT()s and alike" part of the comment wants to survive here, I think.
Quoted 5 lines
xen/common/spinlock.c +1
-0@@ -465,6 +458,23 @@ void _spin_barrier(spinlock_t *lock)spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); } +bool _rspin_is_locked (const rspinlock_t *lock)
xen/common/spinlock.c void _spin_barrier(spinlock_t *lock) · line 471
Quoted 10 lines
xen/common/spinlock.c +10
-0+{ +/* +* Recursive locks may be locked by another CPU, yet we return +* "false" here, making this function suitable only for use in +* ASSERT()s and alike. +*/ +return lock->recurse_cpu ==SPINLOCK_NO_CPU + ?spin_is_locked_common (&lock->tickets) + : lock->recurse_cpu ==smp_processor_id (); +}
Here otoh I wonder if both the comment and the spin_is_locked_common() part of the condition are actually correct. Oh, the latter needs retaining as long as we have nrspin_*() functions, I suppose. But the comment could surely do with improving a little - at the very least "yet we return "false"" isn't quite right; minimally there's a "may" missing.
In principle, without any nrspin_*() functions, the result here ought to be usable generally, not just for ASSERT()s. Whether having its and _spin_is_locked()'s behavior differ would be a good idea is a separate question, of course.
Jan
Re: [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier()
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/common/spinlock.c +0
-0@@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)
Quoted 15 lines
xen/common/spinlock.c static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t) · line 399
Quoted 12 lines
xen/common/spinlock.c +1
-8int _spin_is_locked (const spinlock_t *lock) { -/* -* Recursive locks may be locked by another CPU, yet we return -* "false" here, making this function suitable only for use in -* ASSERT()s and alike. -*/ -return lock->recurse_cpu ==SPINLOCK_NO_CPU - ?spin_is_locked_common (&lock->tickets) - : lock->recurse_cpu ==smp_processor_id (); +return spin_is_locked_common (&lock->tickets); }The "only suitable for ASSERT()s and alike" part of the comment wants to survive here, I think.
Why?
I could understand you asking for putting such a comment to spinlock.h mentioning that any *_is_locked() variant isn't safe, but with _spin_is_locked() no longer covering recursive locks the comment's reasoning is no longer true.
Quoted 15 lines
Quoted 15 lines
xen/common/spinlock.c +10
-0@@ -465,6 +458,23 @@ void _spin_barrier(spinlock_t *lock)spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); } +bool _rspin_is_locked (const rspinlock_t *lock) +{ +/* +* Recursive locks may be locked by another CPU, yet we return +* "false" here, making this function suitable only for use in +* ASSERT()s and alike. +*/ +return lock->recurse_cpu ==SPINLOCK_NO_CPU + ?spin_is_locked_common (&lock->tickets) + : lock->recurse_cpu ==smp_processor_id ();
Quoted 8 lines
xen/common/spinlock.c void _spin_barrier(spinlock_t *lock) · line 471
Quoted 1 line
xen/common/spinlock.c +1
-0+}Here otoh I wonder if both the comment and the
spin_is_locked_common()part of the condition are actually correct. Oh, the latter needs retaining as long as we have nrspin_*() functions, I suppose. But the comment could surely do with improving a little - at the very least "yet we return "false"" isn't quite right; minimally there's a "may" missing.
If anything I guess the comment shouldn't gain a "may", but rather say "Recursive locks may be locked by another CPU via rspin_lock() ..."
Juergen
Re: [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier()
Quoted 22 lines · Jürgen Groß
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/common/spinlock.c +0
-0@@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)Quoted 15 lines
xen/common/spinlock.c static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t) · line 399
Quoted 12 lines
xen/common/spinlock.c +1
-8int _spin_is_locked (const spinlock_t *lock) { -/* -* Recursive locks may be locked by another CPU, yet we return -* "false" here, making this function suitable only for use in -* ASSERT()s and alike. -*/ -return lock->recurse_cpu ==SPINLOCK_NO_CPU - ?spin_is_locked_common (&lock->tickets) - : lock->recurse_cpu ==smp_processor_id (); +return spin_is_locked_common (&lock->tickets); }The "only suitable for ASSERT()s and alike" part of the comment wants to survive here, I think.
Quoted 6 lines
Why?
I could understand you asking for putting such a comment to
spinlock.hmentioning that any*_is_locked()variant isn't safe, but with_spin_is_locked()no longer covering recursive locks the comment's reasoning is no longer true.
Hmm. I guess there is a difference in expectations. To me, these functions in principle ought to report whether the lock is "owned", not just "locked by some CPU". They don't, hence why they may not be used for other than ASSERT()s.
As to the reasoning no longer being applicable here: That's why I asked to only retain the "only ASSERT()s" part of the comment. Yes, such a comment may also be suitable to have in spinlock.h. What I'd like to avoid is for it to be lost altogether.
Jan
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines
xen/common/spinlock.c +10
-0@@ -465,6 +458,23 @@ void _spin_barrier(spinlock_t *lock)spin_barrier_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); } +bool _rspin_is_locked (const rspinlock_t *lock) +{ +/* +* Recursive locks may be locked by another CPU, yet we return +* "false" here, making this function suitable only for use in +* ASSERT()s and alike. +*/ +return lock->recurse_cpu ==SPINLOCK_NO_CPU + ?spin_is_locked_common (&lock->tickets) + : lock->recurse_cpu ==smp_processor_id ();Quoted 8 lines
xen/common/spinlock.c void _spin_barrier(spinlock_t *lock) · line 471
Quoted 1 line
xen/common/spinlock.c +1
-0+}Here otoh I wonder if both the comment and the
spin_is_locked_common()part of the condition are actually correct. Oh, the latter needs retaining as long as we have nrspin_*() functions, I suppose. But the comment could surely do with improving a little - at the very least "yet we return "false"" isn't quite right; minimally there's a "may" missing.If anything I guess the comment shouldn't gain a "may", but rather say "Recursive locks may be locked by another CPU via
rspin_lock()..."Juergen
Re: [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier()
Quoted 30 lines · Jan Beulich
Quoted 22 lines · Jürgen Groß
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Juergen Gross
xen/common/spinlock.c +0
-0@@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)Quoted 15 lines
xen/common/spinlock.c static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t) · line 399
Quoted 12 lines
xen/common/spinlock.c +1
-8int _spin_is_locked (const spinlock_t *lock) { -/* -* Recursive locks may be locked by another CPU, yet we return -* "false" here, making this function suitable only for use in -* ASSERT()s and alike. -*/ -return lock->recurse_cpu ==SPINLOCK_NO_CPU - ?spin_is_locked_common (&lock->tickets) - : lock->recurse_cpu ==smp_processor_id (); +return spin_is_locked_common (&lock->tickets); }The "only suitable for ASSERT()s and alike" part of the comment wants to survive here, I think.
Quoted 6 lines
Why?
I could understand you asking for putting such a comment to
spinlock.hmentioning that any*_is_locked()variant isn't safe, but with_spin_is_locked()no longer covering recursive locks the comment's reasoning is no longer true.
Quoted 4 lines
Hmm. I guess there is a difference in expectations. To me, these functions in principle ought to report whether the lock is "owned", not just "locked by some CPU". They don't, hence why they may not be used for other than ASSERT()s.
Okay, thanks for clarification. I'll change the comment accordingly.
Juergen
PATCH v5 9/13 xen/spinlock: split recursive spinlocks from normal ones
In reply to Juergen GrossRecursive and normal spinlocks are sharing the same data structure for representation of the lock. This has two major disadvantages:
- it is not clear from the definition of a lock, whether it is intended to be used recursive or not, while a mixture of both usage variants needs to be
- in production builds (builds without CONFIG_DEBUG_LOCKS) the needed data size of an ordinary spinlock is 8 bytes instead of 4, due to the additional recursion data needed (associated with that the rwlock data is using 12 instead of only 8 bytes)
Fix that by introducing a struct spinlock_recursive for recursive spinlocks only, and switch recursive spinlock functions to require pointers to this new struct.
This allows to check the correct usage at build time.
---
V2:
- use shorter names (Jan Beulich)
- don't embed spinlock_t in rspinlock_t (Jan Beulich) V5:
- some style fixes (Jan Beulich)
- bool instead of int (Jan Beulich)
--- xen/common/spinlock.c | 50 ++++++++++++++++++++++++++ xen/include/xen/spinlock.h | 72 +++++++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 17 deletions(-)
xen/common/spinlock.c +50 -0
@@ -541,6 +541,56 @@ void _rspin_unlock_irqrestore(rspinlock_t *lock, unsigned long flags)local_irq_restore (flags); } +bool _nrspin_trylock (rspinlock_t *lock) +{ +check_lock (&lock->debug, true); + +if (unlikely (lock->recurse_cpu !=SPINLOCK_NO_CPU ) ) +return false; + +return spin_trylock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} + +void _nrspin_lock (rspinlock_t *lock) +{ +spin_lock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ,NULL , +NULL ); +} + +void _nrspin_unlock (rspinlock_t *lock) +{ +spin_unlock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); +} + +void _nrspin_lock_irq (rspinlock_t *lock) +{ +ASSERT (local_irq_is_enabled ()); +local_irq_disable (); +_nrspin_lock (lock); +} + +void _nrspin_unlock_irq (rspinlock_t *lock) +{ +_nrspin_unlock (lock); +local_irq_enable (); +} + +unsigned long _nrspin_lock_irqsave (rspinlock_t *lock) +{ +unsigned long flags; + +local_irq_save (flags); +_nrspin_lock (lock); + +return flags; +} + +void _nrspin_unlock_irqrestore (rspinlock_t *lock,unsigned long flags) +{ +_nrspin_unlock (lock); +local_irq_restore (flags); +} +#ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile_anc {
xen/include/xen/spinlock.h +55 -17
126 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v5 09/13] xen/spinlock: split recursive spinlocks from normal ones
Quoted 12 lines · Juergen Gross
Recursive and normal spinlocks are sharing the same data structure for representation of the lock. This has two major disadvantages:
- it is not clear from the definition of a lock, whether it is intended to be used recursive or not, while a mixture of both usage variants needs to be
- in production builds (builds without
CONFIG_DEBUG_LOCKS) the needed data size of an ordinary spinlock is 8 bytes instead of 4, due to the additional recursion data needed (associated with that the rwlock data is using 12 instead of only 8 bytes)
Quoted 7 lines
Fix that by introducing a struct
spinlock_recursivefor recursive spinlocks only, and switch recursive spinlock functions to require pointers to this new struct.This allows to check the correct usage at build time.
Signed-off-by Juergen Gross <[email protected]>
PATCH v5 10/13 xen/spinlock: let all is_locked and trylock variants return bool
In reply to Juergen GrossSwitch the remaining trylock and is_locked variants to return bool.
---
V5:
- new patch (Jan Beulich)
--- xen/common/spinlock.c | 4 ++-- xen/include/xen/spinlock.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
xen/common/spinlock.c +2 -2
@@ -393,7 +393,7 @@ static bool always_inline spin_is_locked_common(const spinlock_tickets_t *t)return t->head != t->tail; } -int _spin_is_locked (const spinlock_t *lock) +bool _spin_is_locked (const spinlock_t *lock) {return spin_is_locked_common (&lock->tickets); }
@@ -429,7 +429,7 @@ static bool always_inline spin_trylock_common(spinlock_tickets_t *t,return true; } -int _spin_trylock (spinlock_t *lock) +bool _spin_trylock (spinlock_t *lock) {return spin_trylock_common (&lock->tickets, &lock->debug,LOCK_PROFILE_PAR ); }
xen/include/xen/spinlock.h +2 -2
@@ -234,8 +234,8 @@ void _spin_unlock(spinlock_t *lock);void _spin_unlock_irq (spinlock_t *lock);void _spin_unlock_irqrestore (spinlock_t *lock,unsigned long flags); -int _spin_is_locked (const spinlock_t *lock); -int _spin_trylock (spinlock_t *lock); +bool _spin_is_locked (const spinlock_t *lock); +bool _spin_trylock (spinlock_t *lock);void _spin_barrier (spinlock_t *lock); static always_inline void spin_lock(spinlock_t *l)
Signature · 1 line
2.35.3
Re: [PATCH v5 10/13] xen/spinlock: let all is_locked and trylock variants return bool
Quoted 3 lines · Juergen Gross
Switch the remaining trylock and
is_lockedvariants to return bool.Signed-off-by Juergen Gross <[email protected]>
PATCH v5 11/13 xen/spinlock: support higher number of cpus
In reply to Juergen GrossAllow 16 bits per cpu number, which is the limit imposed by spinlock_tickets_t.
This will allow up to 65535 cpus, while increasing only the size of recursive spinlocks in debug builds from 8 to 12 bytes.
The current Xen limit of 4095 cpus is imposed by SPINLOCK_CPU_BITS being 12. There are machines available with more cpus than the current Xen limit, so it makes sense to have the possibility to use more cpus.
---
V5:
- keep previous recursion limit (Julien Grall)
--- xen/common/spinlock.c | 2 ++ xen/include/xen/spinlock.h | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-)
xen/common/spinlock.c +2 -0
@@ -481,7 +481,9 @@ bool _rspin_trylock(rspinlock_t *lock)/* Don't allow overflow of recurse_cpu field. */ BUILD_BUG_ON (NR_CPUS >SPINLOCK_NO_CPU ); +BUILD_BUG_ON (SPINLOCK_CPU_BITS >sizeof (lock->recurse_cpu) *8 );BUILD_BUG_ON (SPINLOCK_RECURSE_BITS <3 ); +BUILD_BUG_ON (SPINLOCK_MAX_RECURSE > ((1u <<SPINLOCK_RECURSE_BITS ) -1 ));check_lock (&lock->debug, true);
xen/include/xen/spinlock.h +10 -10
@@ -8,16 +8,16 @@#include <asm/system.h> #include <asm/spinlock.h> -#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_CPU_BITS 16 #ifdef CONFIG_DEBUG_LOCKS union lock_debug { - uint16_t val; -#define LOCK_DEBUG_INITVAL 0xffff + uint32_t val; +#define LOCK_DEBUG_INITVAL 0xffffffff struct { - uint16_t cpu:SPINLOCK_CPU_BITS; -#define LOCK_DEBUG_PAD_BITS (14 - SPINLOCK_CPU_BITS) - uint16_t :LOCK_DEBUG_PAD_BITS; + uint32_t cpu:SPINLOCK_CPU_BITS; +#define LOCK_DEBUG_PAD_BITS (30 - SPINLOCK_CPU_BITS) + uint32_t :LOCK_DEBUG_PAD_BITS; bool irq_safe:1; bool unseen:1; };
@@ -211,11 +211,11 @@ typedef struct spinlock { typedef struct rspinlock { spinlock_tickets_t tickets; - uint16_t recurse_cpu:SPINLOCK_CPU_BITS; + uint16_t recurse_cpu; #define SPINLOCK_NO_CPU ((1u << SPINLOCK_CPU_BITS) - 1) -#define SPINLOCK_RECURSE_BITS (16 - SPINLOCK_CPU_BITS) - uint16_t recurse_cnt:SPINLOCK_RECURSE_BITS; -#define SPINLOCK_MAX_RECURSE ((1u << SPINLOCK_RECURSE_BITS) - 1) +#define SPINLOCK_RECURSE_BITS 8 + uint8_t recurse_cnt; +#define SPINLOCK_MAX_RECURSE 15 union lock_debug debug; #ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile *profile;
Signature · 1 line
2.35.3
Re: [PATCH v5 11/13] xen/spinlock: support higher number of cpus
Quoted 5 lines · Juergen Gross
xen/include/xen/spinlock.h +0
-0@@ -8,16 +8,16 @@#include <asm/system.h> #include <asm/spinlock.h>
xen/include/xen/spinlock.h line 16
Quoted 10 lines
xen/include/xen/spinlock.h +3
-3-#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_CPU_BITS 16 #ifdef CONFIG_DEBUG_LOCKS union lock_debug { - uint16_t val; -#define LOCK_DEBUG_INITVAL 0xffff + uint32_t val; +#define LOCK_DEBUG_INITVAL 0xffffffff
With this #define I can see the desire for using a fixed width type for "val". However, ...
xen/include/xen/spinlock.h line 20
Quoted 7 lines
xen/include/xen/spinlock.h +3
-3struct { -uint16_t cpu:SPINLOCK_CPU_BITS ; -#define LOCK_DEBUG_PAD_BITS (14 - SPINLOCK_CPU_BITS) - uint16_t :LOCK_DEBUG_PAD_BITS; +uint32_t cpu:SPINLOCK_CPU_BITS ; +#define LOCK_DEBUG_PAD_BITS (30 - SPINLOCK_CPU_BITS) + uint32_t :LOCK_DEBUG_PAD_BITS;
.. "unsigned int" ought to be fine for both of these.
Jan
Re: [PATCH v5 11/13] xen/spinlock: support higher number of cpus
Quoted 20 lines · Jan Beulich
Quoted 5 lines · Juergen Gross
xen/include/xen/spinlock.h +0
-0@@ -8,16 +8,16 @@#include <asm/system.h> #include <asm/spinlock.h> xen/include/xen/spinlock.h line 16
Quoted 10 lines
xen/include/xen/spinlock.h +3
-3-#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_CPU_BITS 16 #ifdef CONFIG_DEBUG_LOCKS union lock_debug { - uint16_t val; -#define LOCK_DEBUG_INITVAL 0xffff + uint32_t val; +#define LOCK_DEBUG_INITVAL 0xffffffffWith this #define I can see the desire for using a fixed width type for "val". However, ...
Quoted 9 lines
xen/include/xen/spinlock.h line 20
Quoted 7 lines
xen/include/xen/spinlock.h +3
-3struct { -uint16_t cpu:SPINLOCK_CPU_BITS ; -#define LOCK_DEBUG_PAD_BITS (14 - SPINLOCK_CPU_BITS) - uint16_t :LOCK_DEBUG_PAD_BITS; +uint32_t cpu:SPINLOCK_CPU_BITS ; +#define LOCK_DEBUG_PAD_BITS (30 - SPINLOCK_CPU_BITS) + uint32_t :LOCK_DEBUG_PAD_BITS;.. "unsigned int" ought to be fine for both of these.
Fine with me.
Juergen
PATCH v5 12/13 xen/rwlock: raise the number of possible cpus
In reply to Juergen GrossThe rwlock handling is limiting the number of cpus to 4095 today. The main reason is the use of the atomic_t data type for the main lock handling, which needs 2 bits for the locking state (writer waiting or write locked), 12 bits for the id of a possible writer, and a 12 bit counter for readers. The limit isn't 4096 due to an off by one sanity check.
The atomic_t data type is 32 bits wide, so in theory 15 bits for the writer's cpu id and 15 bits for the reader count seem to be fine, but via read_trylock() more readers than cpus are possible.
This means that it is possible to raise the number of cpus to 16384 without changing the rwlock_t data structure. In order to avoid the reader count wrapping to zero, don't let read_trylock() succeed in case the highest bit of the reader's count is set already. This leaves enough headroom for non-recursive readers to enter without risking a wrap.
While at it calculate _QW_CPUMASK and _QR_SHIFT from _QW_SHIFT and add a sanity check for not overflowing the atomic_t data type.
---
V5:
- new patch
--- xen/include/xen/rwlock.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
xen/include/xen/rwlock.h +10 -8
@@ -23,12 +23,12 @@ typedef struct {#define rwlock_init (l) (*(l) = (rwlock_t)RW_LOCK_UNLOCKED)/* Writer states & reader shift and bias. */ -#define _QW_CPUMASK 0xfffU/* Writer CPU mask */ -#define _QW_SHIFT 12/* Writer flags shift */ -#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */ -#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ -#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */ -#define _QR_SHIFT 14/* Reader count shift */ +#define _QW_SHIFT 14/* Writer flags shift */ +#define _QW_CPUMASK ((1U << _QW_SHIFT) - 1)/* Writer CPU mask */ +#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */ +#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ +#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */ +#define _QR_SHIFT (_QW_SHIFT + 2)/* Reader count shift */ #define _QR_BIAS (1U << _QR_SHIFT)void queue_read_lock_slowpath (rwlock_t *lock);
@@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock);static inline bool _is_write_locked_by_me (unsigned int cnts) { -BUILD_BUG_ON (_QW_CPUMASK <NR_CPUS ); +BUILD_BUG_ON ((_QW_CPUMASK +1 ) <NR_CPUS ); +BUILD_BUG_ON (NR_CPUS * _QR_BIAS >INT_MAX );return (cnts & _QW_WMASK) == _QW_LOCKED && (cnts & _QW_CPUMASK) ==smp_processor_id (); }static inline bool _can_read_lock (unsigned int cnts) { -return !(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts); +return cnts <=INT_MAX && + (!(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts)); }/*
Signature · 1 line
2.35.3
Re: [PATCH v5 12/13] xen/rwlock: raise the number of possible cpus
Quoted 10 lines · Juergen Gross
The rwlock handling is limiting the number of cpus to 4095 today. The main reason is the use of the
atomic_tdata type for the main lock handling, which needs 2 bits for the locking state (writer waiting or write locked), 12 bits for the id of a possible writer, and a 12 bit counter for readers. The limit isn't 4096 due to an off by one sanity check.The
atomic_tdata type is 32 bits wide, so in theory 15 bits for the writer's cpu id and 15 bits for the reader count seem to be fine, but viaread_trylock()more readers than cpus are possible.
As a result, afaict you choose to use just 14 bits for the CPU, but still 15 bits (with the 16th to deal with overflow) for the reader count. That could do with making explicit here, as a question is whether we deem as sufficient that there is just one extra bit for the reader count.
Quoted 9 lines
xen/include/xen/rwlock.h +0
-3@@ -23,12 +23,12 @@ typedef struct {#define rwlock_init (l) (*(l) = (rwlock_t)RW_LOCK_UNLOCKED)/* Writer states & reader shift and bias. */ -#define _QW_CPUMASK 0xfffU/* Writer CPU mask */ -#define _QW_SHIFT 12/* Writer flags shift */ -#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */
xen/include/xen/rwlock.h typedef struct { · line 32
Quoted 10 lines
xen/include/xen/rwlock.h +6
-3-#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ -#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */ -#define _QR_SHIFT 14/* Reader count shift */ +#define _QW_SHIFT 14/* Writer flags shift */ +#define _QW_CPUMASK ((1U << _QW_SHIFT) - 1)/* Writer CPU mask */ +#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */ +#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ +#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */ +#define _QR_SHIFT (_QW_SHIFT + 2)/* Reader count shift */ #define _QR_BIAS (1U << _QR_SHIFT)
Btw, seeing all the uppercase U suffixes here, I think you had some lowercase ones earlier in the series. While Misra doesn't demand uppercase for U, it does for L and iirc we decided to use all uppercase suffixes as a result. Would be nice if what goes in could have this correct right away.
Quoted 7 lines
xen/include/xen/rwlock.h +2
-1@@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock);static inline bool _is_write_locked_by_me (unsigned int cnts) { -BUILD_BUG_ON (_QW_CPUMASK <NR_CPUS ); +BUILD_BUG_ON ((_QW_CPUMASK +1 ) <NR_CPUS ); +BUILD_BUG_ON (NR_CPUS * _QR_BIAS >INT_MAX );
xen/include/xen/rwlock.h void queue_write_lock_slowpath(rwlock_t *lock); · line 49
Quoted 10 lines
xen/include/xen/rwlock.h +2
-1return (cnts & _QW_WMASK) == _QW_LOCKED && (cnts & _QW_CPUMASK) ==smp_processor_id (); }static inline bool _can_read_lock (unsigned int cnts) { -return !(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts); +return cnts <=INT_MAX && + (!(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts)); }
I view this as problematic: Code knowing that a write lock is being held may invoke a function using read_trylock() and expect the lock to be available there.
Jan
Re: [PATCH v5 12/13] xen/rwlock: raise the number of possible cpus
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
The rwlock handling is limiting the number of cpus to 4095 today. The main reason is the use of the
atomic_tdata type for the main lock handling, which needs 2 bits for the locking state (writer waiting or write locked), 12 bits for the id of a possible writer, and a 12 bit counter for readers. The limit isn't 4096 due to an off by one sanity check.The
atomic_tdata type is 32 bits wide, so in theory 15 bits for the writer's cpu id and 15 bits for the reader count seem to be fine, but viaread_trylock()more readers than cpus are possible.
Quoted 5 lines
As a result, afaict you choose to use just 14 bits for the CPU, but still 15 bits (with the 16th to deal with overflow) for the reader count. That could do with making explicit here, as a question is whether we deem as sufficient that there is just one extra bit for the reader count.
Okay, I'll add a sentence to the commit message.
Quoted 18 lines
Quoted 18 lines
xen/include/xen/rwlock.h +5
-6@@ -23,12 +23,12 @@ typedef struct {#define rwlock_init (l) (*(l) = (rwlock_t)RW_LOCK_UNLOCKED)/* Writer states & reader shift and bias. */ -#define _QW_CPUMASK 0xfffU/* Writer CPU mask */ -#define _QW_SHIFT 12/* Writer flags shift */ -#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */ -#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ -#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */ -#define _QR_SHIFT 14/* Reader count shift */ +#define _QW_SHIFT 14/* Writer flags shift */ +#define _QW_CPUMASK ((1U << _QW_SHIFT) - 1)/* Writer CPU mask */ +#define _QW_WAITING (1U << _QW_SHIFT)/* A writer is waiting */ +#define _QW_LOCKED (3U << _QW_SHIFT)/* A writer holds the lock */ +#define _QW_WMASK (3U << _QW_SHIFT)/* Writer mask */
Quoted 8 lines
xen/include/xen/rwlock.h typedef struct { · line 32
Quoted 2 lines
xen/include/xen/rwlock.h +1
-0+#define _QR_SHIFT (_QW_SHIFT + 2)/* Reader count shift */ #define _QR_BIAS (1U << _QR_SHIFT)Btw, seeing all the uppercase U suffixes here, I think you had some lowercase ones earlier in the series. While Misra doesn't demand uppercase for U, it does for L and iirc we decided to use all uppercase suffixes as a result. Would be nice if what goes in could have this correct right away.
I'll rescan all the patches and change them accordingly.
Quoted 12 lines
Quoted 12 lines
xen/include/xen/rwlock.h +2
-1@@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock);static inline bool _is_write_locked_by_me (unsigned int cnts) { -BUILD_BUG_ON (_QW_CPUMASK <NR_CPUS ); +BUILD_BUG_ON ((_QW_CPUMASK +1 ) <NR_CPUS ); +BUILD_BUG_ON (NR_CPUS * _QR_BIAS >INT_MAX );return (cnts & _QW_WMASK) == _QW_LOCKED && (cnts & _QW_CPUMASK) ==smp_processor_id (); }
Quoted 10 lines
xen/include/xen/rwlock.h void queue_write_lock_slowpath(rwlock_t *lock); · line 49
Quoted 6 lines
xen/include/xen/rwlock.h +2
-1static inline bool _can_read_lock (unsigned int cnts) { -return !(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts); +return cnts <=INT_MAX && + (!(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts)); }I view this as problematic: Code knowing that a write lock is being held may invoke a function using
read_trylock()and expect the lock to be available there.
So you expect it to be fine that someone is using read_trylock() 32768 times recursively while holding a lock as a writer? Sure, I can change the condition, but OTOH ...
Juergen
Re: [PATCH v5 12/13] xen/rwlock: raise the number of possible cpus
Quoted 24 lines · Jürgen Groß
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Juergen Gross
xen/include/xen/rwlock.h +2
-1@@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock);static inline bool _is_write_locked_by_me (unsigned int cnts) { -BUILD_BUG_ON (_QW_CPUMASK <NR_CPUS ); +BUILD_BUG_ON ((_QW_CPUMASK +1 ) <NR_CPUS ); +BUILD_BUG_ON (NR_CPUS * _QR_BIAS >INT_MAX );return (cnts & _QW_WMASK) == _QW_LOCKED && (cnts & _QW_CPUMASK) ==smp_processor_id (); }Quoted 10 lines
xen/include/xen/rwlock.h void queue_write_lock_slowpath(rwlock_t *lock); · line 49
Quoted 6 lines
xen/include/xen/rwlock.h +2
-1static inline bool _can_read_lock (unsigned int cnts) { -return !(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts); +return cnts <=INT_MAX && + (!(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts)); }I view this as problematic: Code knowing that a write lock is being held may invoke a function using
read_trylock()and expect the lock to be available there.
Quoted 3 lines
So you expect it to be fine that someone is using
read_trylock()32768 times recursively while holding a lock as a writer? Sure, I can change the condition, but OTOH ...
Hmm, yes, the reader count (leaving aside nested read_trylock()) is zero when the lock is held for writing. So yes, I agree the condition is fine, but may I ask for a brief comment to this effect, for blind people like me?
Jan
Re: [PATCH v5 12/13] xen/rwlock: raise the number of possible cpus
Quoted 25 lines · Jan Beulich
Quoted 24 lines · Jürgen Groß
Quoted 22 lines · Jan Beulich
Quoted 7 lines · Juergen Gross
xen/include/xen/rwlock.h +2
-1@@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock);static inline bool _is_write_locked_by_me (unsigned int cnts) { -BUILD_BUG_ON (_QW_CPUMASK <NR_CPUS ); +BUILD_BUG_ON ((_QW_CPUMASK +1 ) <NR_CPUS ); +BUILD_BUG_ON (NR_CPUS * _QR_BIAS >INT_MAX );xen/include/xen/rwlock.h void queue_write_lock_slowpath(rwlock_t *lock); · line 49
Quoted 10 lines
xen/include/xen/rwlock.h +2
-1return (cnts & _QW_WMASK) == _QW_LOCKED && (cnts & _QW_CPUMASK) ==smp_processor_id (); }static inline bool _can_read_lock (unsigned int cnts) { -return !(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts); +return cnts <=INT_MAX && + (!(cnts & _QW_WMASK) ||_is_write_locked_by_me (cnts)); }I view this as problematic: Code knowing that a write lock is being held may invoke a function using
read_trylock()and expect the lock to be available there.
Quoted 8 lines
Quoted 3 lines
So you expect it to be fine that someone is using
read_trylock()32768 times recursively while holding a lock as a writer? Sure, I can change the condition, but OTOH ...Hmm, yes, the reader count (leaving aside nested
read_trylock()) is zero when the lock is held for writing. So yes, I agree the condition is fine, but may I ask for a brief comment to this effect, for blind people like me?
Yeah, fine with me. :-)
Juergen
PATCH v5 13/13 xen: allow up to 16383 cpus
In reply to Juergen GrossWith lock handling now allowing up to 16384 cpus (spinlocks can handle 65535 cpus, rwlocks can handle 16384 cpus), raise the allowed limit for the number of cpus to be configured to 16383.
The new limit is imposed by IOMMU_CMD_BUFFER_MAX_ENTRIES and QINVAL_MAX_ENTRY_NR required to be larger than 2 * CONFIG_NR_CPUS.
---
V5:
- new patch (Jan Beulich)
--- xen/arch/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/Kconfig +1 -1
@@ -6,7 +6,7 @@ config PHYS_ADDR_T_32 config NR_CPUS int "Maximum number of CPUs" - range 1 4095 + range 1 16383 default "256" if X86 default "8" if ARM && RCAR3 default "4" if ARM && QEMU
Signature · 1 line
2.35.3
Re: [PATCH v5 13/13] xen: allow up to 16383 cpus
Quoted 6 lines · Juergen Gross
With lock handling now allowing up to 16384 cpus (spinlocks can handle 65535 cpus, rwlocks can handle 16384 cpus), raise the allowed limit for the number of cpus to be configured to 16383.
The new limit is imposed by
IOMMU_CMD_BUFFER_MAX_ENTRIESandQINVAL_MAX_ENTRY_NRrequired to be larger than 2 *CONFIG_NR_CPUS.
That's quite sad - I was really hoping we'd finally end up with a power-of-2 upper bound.
Jan
Re: [PATCH v5 13/13] xen: allow up to 16383 cpus
Quoted 10 lines · Jan Beulich
Quoted 6 lines · Juergen Gross
With lock handling now allowing up to 16384 cpus (spinlocks can handle 65535 cpus, rwlocks can handle 16384 cpus), raise the allowed limit for the number of cpus to be configured to 16383.
The new limit is imposed by
IOMMU_CMD_BUFFER_MAX_ENTRIESandQINVAL_MAX_ENTRY_NRrequired to be larger than 2 *CONFIG_NR_CPUS.That's quite sad - I was really hoping we'd finally end up with a power-of-2 upper bound.
Yes, me too.
Juergen