From nobody Fri Apr 26 19:52:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584110366; cv=none; d=zohomail.com; s=zohoarc; b=QEDVyG6/MMmrXlDwpVAa6E8LtEvd1au48IZfnr3VcowxsgtlX+gG5L7JXqJNsoNz3ksbvWmfMjw48XQaTdB+tXtbx90BMc7w3dawOehDdonJr+eqcxzgQmNs09QiMay4pvQuYONKcBc89o/7pBL6UhSgUCc/txXdmPoKzgrNNA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110366; h=Content-Type: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=RJxmY5PCZrhQj1ZPOkjrx/+DqhpmL/WFjluGJqVfb5A=; b=P67gu7nMX86i/hPh0kSjAAV6Ad2acWU9BwjV6fvK78jmxzSIqSLKP4Xb5T5UhnpD5+1BLcHOAaMaH/0ggDLaFQbRmY2crx/+t1RKytaYkmvCsVy4Kvu67CVOpAAUGPU3xNUuEsjdoBzIkJJYMWP8NZugaE8hKH/rr/B+wdgQqQ4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1584110366461822.1085374247955; Fri, 13 Mar 2020 07:39:26 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jClRq-0000b0-FZ; Fri, 13 Mar 2020 14:38:02 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jClRo-0000am-WF for xen-devel@lists.xenproject.org; Fri, 13 Mar 2020 14:38:01 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3c5dfbcc-6538-11ea-b31a-12813bfff9fa; Fri, 13 Mar 2020 14:37:59 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B6794ACD0; Fri, 13 Mar 2020 14:37:58 +0000 (UTC) X-Inumbo-ID: 3c5dfbcc-6538-11ea-b31a-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 13 Mar 2020 15:37:54 +0100 Message-Id: <20200313143755.31870-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200313143755.31870-1-jgross@suse.com> References: <20200313143755.31870-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v2 1/2] xen/rwlocks: call preempt_disable() when taking a rwlock X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Similar to spinlocks preemption should be disabled while holding a rwlock. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - move preempt_disable()/enable() calls (Jan Beulich, Julien Grall) --- xen/include/xen/rwlock.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/xen/include/xen/rwlock.h b/xen/include/xen/rwlock.h index 1c221dd0d9..4d1b48c722 100644 --- a/xen/include/xen/rwlock.h +++ b/xen/include/xen/rwlock.h @@ -2,6 +2,7 @@ #define __RWLOCK_H__ =20 #include +#include #include #include =20 @@ -54,6 +55,7 @@ static inline int _read_trylock(rwlock_t *lock) { u32 cnts; =20 + preempt_disable(); cnts =3D atomic_read(&lock->cnts); if ( likely(_can_read_lock(cnts)) ) { @@ -62,6 +64,7 @@ static inline int _read_trylock(rwlock_t *lock) return 1; atomic_sub(_QR_BIAS, &lock->cnts); } + preempt_enable(); return 0; } =20 @@ -73,6 +76,7 @@ static inline void _read_lock(rwlock_t *lock) { u32 cnts; =20 + preempt_disable(); cnts =3D atomic_add_return(_QR_BIAS, &lock->cnts); if ( likely(_can_read_lock(cnts)) ) return; @@ -106,6 +110,7 @@ static inline void _read_unlock(rwlock_t *lock) * Atomically decrement the reader count */ atomic_sub(_QR_BIAS, &lock->cnts); + preempt_enable(); } =20 static inline void _read_unlock_irq(rwlock_t *lock) @@ -137,6 +142,7 @@ static inline unsigned int _write_lock_val(void) static inline void _write_lock(rwlock_t *lock) { /* Optimize for the unfair lock case where the fair flag is 0. */ + preempt_disable(); if ( atomic_cmpxchg(&lock->cnts, 0, _write_lock_val()) =3D=3D 0 ) return; =20 @@ -168,17 +174,23 @@ static inline int _write_trylock(rwlock_t *lock) { u32 cnts; =20 + preempt_disable(); cnts =3D atomic_read(&lock->cnts); - if ( unlikely(cnts) ) + if ( unlikely(cnts) || + unlikely(atomic_cmpxchg(&lock->cnts, 0, _write_lock_val()) !=3D 0= ) ) + { + preempt_enable(); return 0; + } =20 - return likely(atomic_cmpxchg(&lock->cnts, 0, _write_lock_val()) =3D=3D= 0); + return 1; } =20 static inline void _write_unlock(rwlock_t *lock) { ASSERT(_is_write_locked_by_me(atomic_read(&lock->cnts))); atomic_and(~(_QW_CPUMASK | _QW_WMASK), &lock->cnts); + preempt_enable(); } =20 static inline void _write_unlock_irq(rwlock_t *lock) @@ -274,6 +286,7 @@ static inline void _percpu_read_lock(percpu_rwlock_t **= per_cpudata, } =20 /* Indicate this cpu is reading. */ + preempt_disable(); this_cpu_ptr(per_cpudata) =3D percpu_rwlock; smp_mb(); /* Check if a writer is waiting. */ @@ -309,6 +322,7 @@ static inline void _percpu_read_unlock(percpu_rwlock_t = **per_cpudata, } this_cpu_ptr(per_cpudata) =3D NULL; smp_wmb(); + preempt_enable(); } =20 /* Don't inline percpu write lock as it's a complex function. */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Fri Apr 26 19:52:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584110368; cv=none; d=zohomail.com; s=zohoarc; b=EPnjv6KeZIB2VBd/TqU6VwQn9MKlhI1t/DEBEjWLnNvVQHZtevFRE2VQvB/hIb/fJheEvmWzSwXvvu6GcY0wx8JehyHaUx7RJbCVuc31AlYBLZXzyInjaEjgD9jcQxGrpketZRqXQQLd7H03pMMQE/ZY59r/Jv7v5WYqz2AJuhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110368; h=Content-Type: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=1dNZm0hzWg+eEsEbnOjgH9RrUeKhJ2DfFrbsCmR4g+g=; b=fNa7mS6oy4AmPZyBYsHrcYs4RCRHq2+UWjrrQW+iwqlTDOOsVDYLv8GvNpB8aY86NkS8IJ3oSX2rBDg0ySvxKZffDjDcgEtiNqVg9VI7BH0SRFUd178gjE5EFiCLtFefzqQIAB5b5oKWQ89rm92rLXFPJyzfoNGnl8mrZkp9uO0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1584110368164224.6677539059433; Fri, 13 Mar 2020 07:39:28 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jClRp-0000au-6o; Fri, 13 Mar 2020 14:38:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jClRo-0000ak-Po for xen-devel@lists.xenproject.org; Fri, 13 Mar 2020 14:38:00 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3c5eb198-6538-11ea-92cf-bc764e2007e4; Fri, 13 Mar 2020 14:38:00 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B6971AD03; Fri, 13 Mar 2020 14:37:58 +0000 (UTC) X-Inumbo-ID: 3c5eb198-6538-11ea-92cf-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 13 Mar 2020 15:37:55 +0100 Message-Id: <20200313143755.31870-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200313143755.31870-1-jgross@suse.com> References: <20200313143755.31870-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v2 2/2] xen/spinlocks: fix placement of preempt_[dis|en]able() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In case Xen ever gains preemption support the spinlock coding's placement of preempt_disable() and preempt_enable() should be outside of the locked section. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - move preempt_enable() to the very end of _spin_unlock() (Jan Beulich) --- xen/common/spinlock.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 344981c54a..6c8b62beb0 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -160,6 +160,7 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(= void *), void *data) LOCK_PROFILE_VAR; =20 check_lock(&lock->debug); + preempt_disable(); tickets.head_tail =3D arch_fetch_and_add(&lock->tickets.head_tail, tickets.head_tail); while ( tickets.tail !=3D observe_head(&lock->tickets) ) @@ -171,7 +172,6 @@ void inline _spin_lock_cb(spinlock_t *lock, void (*cb)(= void *), void *data) } got_lock(&lock->debug); LOCK_PROFILE_GOT; - preempt_disable(); arch_lock_acquire_barrier(); } =20 @@ -199,11 +199,11 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock) void _spin_unlock(spinlock_t *lock) { arch_lock_release_barrier(); - preempt_enable(); LOCK_PROFILE_REL; rel_lock(&lock->debug); add_sized(&lock->tickets.head, 1); arch_lock_signal(); + preempt_enable(); } =20 void _spin_unlock_irq(spinlock_t *lock) @@ -242,15 +242,18 @@ int _spin_trylock(spinlock_t *lock) return 0; new =3D old; new.tail++; + preempt_disable(); if ( cmpxchg(&lock->tickets.head_tail, old.head_tail, new.head_tail) !=3D old.head_tail ) + { + preempt_enable(); return 0; + } got_lock(&lock->debug); #ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked =3D NOW(); #endif - preempt_disable(); /* * cmpxchg() is a full barrier so no need for an * arch_lock_acquire_barrier(). --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel