From nobody Fri May 17 08:24:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1645700108; cv=none; d=zohomail.com; s=zohoarc; b=FMwzn/M5VT8cYHDf9/hdHRc7kjdMnH7BPDG0iVh+/nugfXNBHDSMjD+eRJryr2QBJuAp6oTXspJPQuVLmZsxoOtA9afLkZlBTbEnjLkSwOqWyOlg2NRJoGOLi40aSgirv0q2+ee2J03J/ugsa6pDqykg4ZkFqbdEde+VMUpKMSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645700108; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ojjdlGbMc95KyfFklDt/mHMPcKnQ5SgYlPEfROv8euA=; b=U10js+wTztfmWrl9cNhGDabI1s3eEGAzRiOmCfmrfCHvGWLXgyyS9SfC3otq6OkyJ1oblEM4XcacoDeZOl2fM3Uf09w763o3TcJKnYLXiw788YTSU44/M692FgbJeiJXFjCr2CE3qhiLS+/T6Ee/8vqqeQSvaLkBPWHGPJHJYJs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1645700108264323.5839101628102; Thu, 24 Feb 2022 02:55:08 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.278152.475304 (Exim 4.92) (envelope-from ) id 1nNBlm-0000wS-LI; Thu, 24 Feb 2022 10:54:46 +0000 Received: by outflank-mailman (output) from mailman id 278152.475304; Thu, 24 Feb 2022 10:54:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nNBlm-0000wL-I3; Thu, 24 Feb 2022 10:54:46 +0000 Received: by outflank-mailman (input) for mailman id 278152; Thu, 24 Feb 2022 10:54:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nNBlk-0000gJ-Pv for xen-devel@lists.xenproject.org; Thu, 24 Feb 2022 10:54:44 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2bebc759-9560-11ec-8eb8-a37418f5ba1a; Thu, 24 Feb 2022 11:54:43 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A1A5121136; Thu, 24 Feb 2022 10:54:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 68F2713A79; Thu, 24 Feb 2022 10:54:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CI5gGPJjF2L2SQAAMHmgww (envelope-from ); Thu, 24 Feb 2022 10:54:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2bebc759-9560-11ec-8eb8-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645700082; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ojjdlGbMc95KyfFklDt/mHMPcKnQ5SgYlPEfROv8euA=; b=FZ3VVQKQ9N5KZGY3CNBPoQN1p/zbYprrswdaoV6yeJORXSDKet60wfyv/NQpmwX8+bE9Np FeX9q0eH6FZN39XM9nDMkzizWXCYN7kr/xxMr0KmfHZ4mSu3tt5nvZT2sNXslubpJrO11N jKpjcXsuem5DcyfXfNoKB5FOTEvCMEo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH 1/2] xen/spinlock: use lock address for lock debug functions Date: Thu, 24 Feb 2022 11:54:35 +0100 Message-Id: <20220224105436.1480-2-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224105436.1480-1-jgross@suse.com> References: <20220224105436.1480-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1645700110426100001 Content-Type: text/plain; charset="utf-8" Instead of only passing the lock_debug address to check_lock() et al use the address of the spinlock. Signed-off-by: Juergen Gross --- xen/common/spinlock.c | 34 +++++++++++++++++----------------- xen/include/xen/rwlock.h | 10 +++++----- xen/include/xen/spinlock.h | 10 ++++++++-- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 62c83aaa6a..53d6ab6853 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -13,7 +13,7 @@ =20 static atomic_t spin_debug __read_mostly =3D ATOMIC_INIT(0); =20 -void check_lock(union lock_debug *debug, bool try) +void check_lock(spinlock_t *lock, bool try) { bool irq_safe =3D !local_irq_is_enabled(); =20 @@ -49,12 +49,12 @@ void check_lock(union lock_debug *debug, bool try) if ( try && irq_safe ) return; =20 - if ( unlikely(debug->irq_safe !=3D irq_safe) ) + if ( unlikely(lock->debug.irq_safe !=3D irq_safe) ) { union lock_debug seen, new =3D { 0 }; =20 new.irq_safe =3D irq_safe; - seen.val =3D cmpxchg(&debug->val, LOCK_DEBUG_INITVAL, new.val); + seen.val =3D cmpxchg(&lock->debug.val, LOCK_DEBUG_INITVAL, new.val= ); =20 if ( !seen.unseen && seen.irq_safe =3D=3D !irq_safe ) { @@ -65,7 +65,7 @@ void check_lock(union lock_debug *debug, bool try) } } =20 -static void check_barrier(union lock_debug *debug) +static void check_barrier(spinlock_t *lock) { if ( unlikely(atomic_read(&spin_debug) <=3D 0) ) return; @@ -81,19 +81,19 @@ static void check_barrier(union lock_debug *debug) * However, if we spin on an IRQ-unsafe lock with IRQs disabled then t= hat * is clearly wrong, for the same reason outlined in check_lock() abov= e. */ - BUG_ON(!local_irq_is_enabled() && !debug->irq_safe); + BUG_ON(!local_irq_is_enabled() && !lock->debug.irq_safe); } =20 -static void got_lock(union lock_debug *debug) +static void got_lock(spinlock_t *lock) { - debug->cpu =3D smp_processor_id(); + lock->debug.cpu =3D smp_processor_id(); } =20 -static void rel_lock(union lock_debug *debug) +static void rel_lock(spinlock_t *lock) { if ( atomic_read(&spin_debug) > 0 ) - BUG_ON(debug->cpu !=3D smp_processor_id()); - debug->cpu =3D SPINLOCK_NO_CPU; + BUG_ON(lock->debug.cpu !=3D smp_processor_id()); + lock->debug.cpu =3D SPINLOCK_NO_CPU; } =20 void spin_debug_enable(void) @@ -164,7 +164,7 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(= void *), void *data) spinlock_tickets_t tickets =3D SPINLOCK_TICKET_INC; LOCK_PROFILE_VAR; =20 - check_lock(&lock->debug, false); + check_lock(lock, false); preempt_disable(); tickets.head_tail =3D arch_fetch_and_add(&lock->tickets.head_tail, tickets.head_tail); @@ -176,7 +176,7 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(= void *), void *data) arch_lock_relax(); } arch_lock_acquire_barrier(); - got_lock(&lock->debug); + got_lock(lock); LOCK_PROFILE_GOT; } =20 @@ -204,7 +204,7 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock) void _spin_unlock(spinlock_t *lock) { LOCK_PROFILE_REL; - rel_lock(&lock->debug); + rel_lock(lock); arch_lock_release_barrier(); add_sized(&lock->tickets.head, 1); arch_lock_signal(); @@ -240,7 +240,7 @@ int _spin_trylock(spinlock_t *lock) spinlock_tickets_t old, new; =20 preempt_disable(); - check_lock(&lock->debug, true); + check_lock(lock, true); old =3D observe_lock(&lock->tickets); if ( old.head !=3D old.tail ) { @@ -259,7 +259,7 @@ int _spin_trylock(spinlock_t *lock) * cmpxchg() is a full barrier so no need for an * arch_lock_acquire_barrier(). */ - got_lock(&lock->debug); + got_lock(lock); #ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked =3D NOW(); @@ -274,7 +274,7 @@ void _spin_barrier(spinlock_t *lock) s_time_t block =3D NOW(); #endif =20 - check_barrier(&lock->debug); + check_barrier(lock); smp_mb(); sample =3D observe_lock(&lock->tickets); if ( sample.head !=3D sample.tail ) @@ -300,7 +300,7 @@ int _spin_trylock_recursive(spinlock_t *lock) BUILD_BUG_ON(NR_CPUS > SPINLOCK_NO_CPU); BUILD_BUG_ON(SPINLOCK_RECURSE_BITS < 3); =20 - check_lock(&lock->debug, true); + check_lock(lock, true); =20 if ( likely(lock->recurse_cpu !=3D cpu) ) { diff --git a/xen/include/xen/rwlock.h b/xen/include/xen/rwlock.h index 0cc9167715..188fc809dc 100644 --- a/xen/include/xen/rwlock.h +++ b/xen/include/xen/rwlock.h @@ -56,7 +56,7 @@ static inline int _read_trylock(rwlock_t *lock) u32 cnts; =20 preempt_disable(); - check_lock(&lock->lock.debug, true); + check_lock(&lock->lock, true); cnts =3D atomic_read(&lock->cnts); if ( likely(_can_read_lock(cnts)) ) { @@ -90,7 +90,7 @@ static inline void _read_lock(rwlock_t *lock) if ( likely(_can_read_lock(cnts)) ) { /* The slow path calls check_lock() via spin_lock(). */ - check_lock(&lock->lock.debug, false); + check_lock(&lock->lock, false); return; } =20 @@ -169,7 +169,7 @@ static inline void _write_lock(rwlock_t *lock) if ( atomic_cmpxchg(&lock->cnts, 0, _write_lock_val()) =3D=3D 0 ) { /* The slow path calls check_lock() via spin_lock(). */ - check_lock(&lock->lock.debug, false); + check_lock(&lock->lock, false); return; } =20 @@ -206,7 +206,7 @@ static inline int _write_trylock(rwlock_t *lock) u32 cnts; =20 preempt_disable(); - check_lock(&lock->lock.debug, true); + check_lock(&lock->lock, true); cnts =3D atomic_read(&lock->cnts); if ( unlikely(cnts) || unlikely(atomic_cmpxchg(&lock->cnts, 0, _write_lock_val()) !=3D 0= ) ) @@ -341,7 +341,7 @@ static inline void _percpu_read_lock(percpu_rwlock_t **= per_cpudata, else { /* All other paths have implicit check_lock() calls via read_lock(= ). */ - check_lock(&percpu_rwlock->rwlock.lock.debug, false); + check_lock(&percpu_rwlock->rwlock.lock, false); } } =20 diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 961891bea4..5b6b73732f 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -21,13 +21,11 @@ union lock_debug { }; }; #define _LOCK_DEBUG { LOCK_DEBUG_INITVAL } -void check_lock(union lock_debug *debug, bool try); void spin_debug_enable(void); void spin_debug_disable(void); #else union lock_debug { }; #define _LOCK_DEBUG { } -#define check_lock(l, t) ((void)0) #define spin_debug_enable() ((void)0) #define spin_debug_disable() ((void)0) #endif @@ -189,6 +187,14 @@ int _spin_trylock_recursive(spinlock_t *lock); void _spin_lock_recursive(spinlock_t *lock); void _spin_unlock_recursive(spinlock_t *lock); =20 +#ifdef CONFIG_DEBUG_LOCKS +void check_lock(spinlock_t *lock, bool try); +#else +static inline void check_lock(spinlock_t *lock, bool try) +{ +} +#endif + #define spin_lock(l) _spin_lock(l) #define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) #define spin_lock_irq(l) _spin_lock_irq(l) --=20 2.34.1 From nobody Fri May 17 08:24:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1645700109; cv=none; d=zohomail.com; s=zohoarc; b=ccjCJ09qXjTA1Yii5ZmfXDNBBEf8YtTZCuHm0E3j/IEp+3COAlv6HOvVZBL/Qq6jlcql66P3vkZ609tRuZ9b8UCPHBo1froeGG9tQrGrl9PTBOhKLzpzhMAGqJBlq5TzWt0VR9mLFX9BuGjOvQOk3SOH1mC4M3dU7yjgdKakBI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645700109; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=URIjccjwM+WJARLadPEaWbGGRJrYXRvtFlWn552mtiI=; b=bj+DpA/ztAZTmdpLd4tN0jfdblFTF9M9yPcorBJYQIDPUV3GQx5MsJ/U2Sug3ywP31LspGolzpepGisDoSOApqS21+a3rGrFpMXcwIGWyS+dCrOuGgq2ILGCc4p0o01ZBD1sS+SMBKHwXjWyKZWYxUkW9iGALI/TtYFU25NiJFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1645700109696140.35934866340438; Thu, 24 Feb 2022 02:55:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.278153.475310 (Exim 4.92) (envelope-from ) id 1nNBlm-0000yT-UZ; Thu, 24 Feb 2022 10:54:46 +0000 Received: by outflank-mailman (output) from mailman id 278153.475310; Thu, 24 Feb 2022 10:54:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nNBlm-0000yB-Pe; Thu, 24 Feb 2022 10:54:46 +0000 Received: by outflank-mailman (input) for mailman id 278153; Thu, 24 Feb 2022 10:54:45 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nNBll-0000gP-1N for xen-devel@lists.xenproject.org; Thu, 24 Feb 2022 10:54:45 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2c0ab764-9560-11ec-8539-5f4723681683; Thu, 24 Feb 2022 11:54:43 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E7D8A212B6; Thu, 24 Feb 2022 10:54:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A85BA13A79; Thu, 24 Feb 2022 10:54:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uPbOJ/JjF2L2SQAAMHmgww (envelope-from ); Thu, 24 Feb 2022 10:54:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2c0ab764-9560-11ec-8539-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1645700082; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=URIjccjwM+WJARLadPEaWbGGRJrYXRvtFlWn552mtiI=; b=fLIXfWbRb3zjBOqhts86DZqCB04UL0o2z9JifLcWZ6kaGZy/vV/jBOjbJ53bCqxq2o6eIm n/Zk19ePskoyZNPKLmVdL6fMrGRySTYHM96AZ1k6f1zmFx1CgXykOA1xMQwJ9i4xlFbT2Y wmUlgkBcSspxhYVOKBW7mD+eAvMNghQ= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Jan Beulich , Andrew Cooper , George Dunlap , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Julien Grall , Stefano Stabellini Subject: [PATCH 2/2] xen/spinlock: merge recurse_cpu and debug.cpu fields in struct spinlock Date: Thu, 24 Feb 2022 11:54:36 +0100 Message-Id: <20220224105436.1480-3-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224105436.1480-1-jgross@suse.com> References: <20220224105436.1480-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1645700112218100004 Content-Type: text/plain; charset="utf-8" Instead of having two fields in struct spinlock holding a cpu number, just merge them. For this purpose get rid of union lock_debug and use a 32 bit sized union for cpu, recurse_cnt and the two debug booleans. Signed-off-by: Juergen Gross --- xen/arch/x86/mm/mm-locks.h | 6 ++--- xen/common/spinlock.c | 48 +++++++++++++++++++++----------------- xen/include/xen/spinlock.h | 43 ++++++++++++++++++---------------- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/xen/arch/x86/mm/mm-locks.h b/xen/arch/x86/mm/mm-locks.h index fcfd4706ba..01cf3a820d 100644 --- a/xen/arch/x86/mm/mm-locks.h +++ b/xen/arch/x86/mm/mm-locks.h @@ -42,7 +42,7 @@ static inline void mm_lock_init(mm_lock_t *l) =20 static inline bool mm_locked_by_me(const mm_lock_t *l) { - return (l->lock.recurse_cpu =3D=3D current->processor); + return (l->lock.data.cpu =3D=3D current->processor); } =20 static inline int _get_lock_level(void) @@ -94,7 +94,7 @@ static inline void _mm_lock(const struct domain *d, mm_lo= ck_t *l, if ( !((mm_locked_by_me(l)) && rec) ) _check_lock_level(d, level); spin_lock_recursive(&l->lock); - if ( l->lock.recurse_cnt =3D=3D 1 ) + if ( l->lock.data.recurse_cnt =3D=3D 1 ) { l->locker_function =3D func; l->unlock_level =3D _get_lock_level(); @@ -209,7 +209,7 @@ static inline void mm_read_unlock(mm_rwlock_t *l) =20 static inline void mm_unlock(mm_lock_t *l) { - if ( l->lock.recurse_cnt =3D=3D 1 ) + if ( l->lock.data.recurse_cnt =3D=3D 1 ) { l->locker_function =3D "nobody"; _set_lock_level(l->unlock_level); diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 53d6ab6853..33e6aaab1c 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -17,8 +17,6 @@ void check_lock(spinlock_t *lock, bool try) { bool irq_safe =3D !local_irq_is_enabled(); =20 - BUILD_BUG_ON(LOCK_DEBUG_PAD_BITS <=3D 0); - if ( unlikely(atomic_read(&spin_debug) <=3D 0) ) return; =20 @@ -49,12 +47,12 @@ void check_lock(spinlock_t *lock, bool try) if ( try && irq_safe ) return; =20 - if ( unlikely(lock->debug.irq_safe !=3D irq_safe) ) + if ( unlikely(lock->data.irq_safe !=3D irq_safe) ) { - union lock_debug seen, new =3D { 0 }; + spinlock_data_t seen, new =3D { 0 }; =20 new.irq_safe =3D irq_safe; - seen.val =3D cmpxchg(&lock->debug.val, LOCK_DEBUG_INITVAL, new.val= ); + seen.val =3D cmpxchg(&lock->data.val, SPINLOCK_DATA_INITVAL, new.v= al); =20 if ( !seen.unseen && seen.irq_safe =3D=3D !irq_safe ) { @@ -81,19 +79,19 @@ static void check_barrier(spinlock_t *lock) * However, if we spin on an IRQ-unsafe lock with IRQs disabled then t= hat * is clearly wrong, for the same reason outlined in check_lock() abov= e. */ - BUG_ON(!local_irq_is_enabled() && !lock->debug.irq_safe); + BUG_ON(!local_irq_is_enabled() && !lock->data.irq_safe); } =20 static void got_lock(spinlock_t *lock) { - lock->debug.cpu =3D smp_processor_id(); + lock->data.cpu =3D smp_processor_id(); } =20 static void rel_lock(spinlock_t *lock) { if ( atomic_read(&spin_debug) > 0 ) - BUG_ON(lock->debug.cpu !=3D smp_processor_id()); - lock->debug.cpu =3D SPINLOCK_NO_CPU; + BUG_ON(lock->data.cpu !=3D smp_processor_id()); + lock->data.cpu =3D SPINLOCK_NO_CPU; } =20 void spin_debug_enable(void) @@ -230,9 +228,9 @@ int _spin_is_locked(spinlock_t *lock) * "false" here, making this function suitable only for use in * ASSERT()s and alike. */ - return lock->recurse_cpu =3D=3D SPINLOCK_NO_CPU + return lock->data.cpu =3D=3D SPINLOCK_NO_CPU ? lock->tickets.head !=3D lock->tickets.tail - : lock->recurse_cpu =3D=3D smp_processor_id(); + : lock->data.cpu =3D=3D smp_processor_id(); } =20 int _spin_trylock(spinlock_t *lock) @@ -296,22 +294,24 @@ int _spin_trylock_recursive(spinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); =20 - /* Don't allow overflow of recurse_cpu field. */ + /* Don't allow overflow of cpu field. */ BUILD_BUG_ON(NR_CPUS > SPINLOCK_NO_CPU); BUILD_BUG_ON(SPINLOCK_RECURSE_BITS < 3); =20 check_lock(lock, true); =20 - if ( likely(lock->recurse_cpu !=3D cpu) ) + if ( likely(lock->data.cpu !=3D cpu) ) { if ( !spin_trylock(lock) ) return 0; - lock->recurse_cpu =3D cpu; +#ifndef CONFIG_DEBUG_LOCKS + lock->data.cpu =3D cpu; +#endif } =20 /* We support only fairly shallow recursion, else the counter overflow= s. */ - ASSERT(lock->recurse_cnt < SPINLOCK_MAX_RECURSE); - lock->recurse_cnt++; + ASSERT(lock->data.recurse_cnt < SPINLOCK_MAX_RECURSE); + lock->data.recurse_cnt++; =20 return 1; } @@ -320,22 +320,26 @@ void _spin_lock_recursive(spinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); =20 - if ( likely(lock->recurse_cpu !=3D cpu) ) + if ( likely(lock->data.cpu !=3D cpu) ) { _spin_lock(lock); - lock->recurse_cpu =3D cpu; +#ifndef CONFIG_DEBUG_LOCKS + lock->data.cpu =3D cpu; +#endif } =20 /* We support only fairly shallow recursion, else the counter overflow= s. */ - ASSERT(lock->recurse_cnt < SPINLOCK_MAX_RECURSE); - lock->recurse_cnt++; + ASSERT(lock->data.recurse_cnt < SPINLOCK_MAX_RECURSE); + lock->data.recurse_cnt++; } =20 void _spin_unlock_recursive(spinlock_t *lock) { - if ( likely(--lock->recurse_cnt =3D=3D 0) ) + if ( likely(--lock->data.recurse_cnt =3D=3D 0) ) { - lock->recurse_cpu =3D SPINLOCK_NO_CPU; +#ifndef CONFIG_DEBUG_LOCKS + lock->data.cpu =3D SPINLOCK_NO_CPU; +#endif spin_unlock(lock); } } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 5b6b73732f..61731b5d29 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -6,26 +6,34 @@ #include #include =20 -#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_NO_CPU ((1u << SPINLOCK_CPU_BITS) - 1) +#define SPINLOCK_RECURSE_BITS (16 - SPINLOCK_CPU_BITS) +#define SPINLOCK_MAX_RECURSE ((1u << SPINLOCK_RECURSE_BITS) - 1) +#define SPINLOCK_PAD_BITS (30 - SPINLOCK_CPU_BITS - SPINLOCK_RECURSE_= BITS) =20 -#ifdef CONFIG_DEBUG_LOCKS -union lock_debug { - uint16_t val; -#define LOCK_DEBUG_INITVAL 0xffff +typedef union { + u32 val; struct { - uint16_t cpu:SPINLOCK_CPU_BITS; -#define LOCK_DEBUG_PAD_BITS (14 - SPINLOCK_CPU_BITS) - uint16_t :LOCK_DEBUG_PAD_BITS; + u32 cpu:SPINLOCK_CPU_BITS; + u32 recurse_cnt:SPINLOCK_RECURSE_BITS; + u32 pad:SPINLOCK_PAD_BITS; +#ifdef CONFIG_DEBUG_LOCKS bool irq_safe:1; bool unseen:1; +#define SPINLOCK_DEBUG_INITVAL 0xc0000000 +#else + u32 debug_pad:2; +#define SPINLOCK_DEBUG_INITVAL 0x00000000 +#endif }; -}; -#define _LOCK_DEBUG { LOCK_DEBUG_INITVAL } +} spinlock_data_t; +#define SPINLOCK_DATA_INITVAL (SPINLOCK_NO_CPU | SPINLOCK_DEBUG_INITVAL) + +#ifdef CONFIG_DEBUG_LOCKS void spin_debug_enable(void); void spin_debug_disable(void); #else -union lock_debug { }; -#define _LOCK_DEBUG { } #define spin_debug_enable() ((void)0) #define spin_debug_disable() ((void)0) #endif @@ -92,7 +100,7 @@ struct lock_profile_qhead { static struct lock_profile * const __lock_profile_##name = \ __used_section(".lockprofile.data") =3D = \ &__lock_profile_data_##name -#define _SPIN_LOCK_UNLOCKED(x) { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG, x= } +#define _SPIN_LOCK_UNLOCKED(x) { { 0 }, { SPINLOCK_DATA_INITVAL }, x } #define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) #define DEFINE_SPINLOCK(l) = \ spinlock_t l =3D _SPIN_LOCK_UNLOCKED(NULL); = \ @@ -134,7 +142,7 @@ extern void cf_check spinlock_profile_reset(unsigned ch= ar key); =20 struct lock_profile_qhead { }; =20 -#define SPIN_LOCK_UNLOCKED { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG } +#define SPIN_LOCK_UNLOCKED { { 0 }, { SPINLOCK_DATA_INITVAL } } #define DEFINE_SPINLOCK(l) spinlock_t l =3D SPIN_LOCK_UNLOCKED =20 #define spin_lock_init_prof(s, l) spin_lock_init(&((s)->l)) @@ -156,12 +164,7 @@ typedef union { =20 typedef struct spinlock { spinlock_tickets_t tickets; - u16 recurse_cpu:SPINLOCK_CPU_BITS; -#define SPINLOCK_NO_CPU ((1u << SPINLOCK_CPU_BITS) - 1) -#define SPINLOCK_RECURSE_BITS (16 - SPINLOCK_CPU_BITS) - u16 recurse_cnt:SPINLOCK_RECURSE_BITS; -#define SPINLOCK_MAX_RECURSE ((1u << SPINLOCK_RECURSE_BITS) - 1) - union lock_debug debug; + spinlock_data_t data; #ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile *profile; #endif --=20 2.34.1