From nobody Wed May 22 02:03:31 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=1710400858; cv=none; d=zohomail.com; s=zohoarc; b=E4lF3SnBNtRFNK5EvC+V/OIQ+nb2c4edQ0+HQNEXJOgg5WBCE18mqBm0xXYE6zTWlzBxCo3Ap3NotRrKY9aNTchzo3nxKfor3mNPANDnOz+cxmSKZ2YiCqRHC6eY04EZGV0jZoyvs2NAe/e8VXHmwyQeTF115u1ZITirP8yr/Wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400858; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X3wK2bnFDRfOZpwTuXtrdzOv2dz+Aoq7ilBYLmKlrOE=; b=j913ZdkPNBuAxG5MRA5oAt8BTov9iwkIM5cyX4ILdyOg6zDNx2r9Vv/V4KP8LAVG8WgHLPhwLuSlqu4iIWnVFoN9z1qANwQ0XrBQgLQhaSg6KOd0HJ4ISAUfdLWm1DM0EEF7yaHvnp3H1439eVXGMXXcrIlTrWfiSNNwYp/501g= 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 1710400858225397.09720282577155; Thu, 14 Mar 2024 00:20:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692892.1080529 (Exim 4.92) (envelope-from ) id 1rkfOL-0005rw-64; Thu, 14 Mar 2024 07:20:41 +0000 Received: by outflank-mailman (output) from mailman id 692892.1080529; Thu, 14 Mar 2024 07:20:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOL-0005rn-30; Thu, 14 Mar 2024 07:20:41 +0000 Received: by outflank-mailman (input) for mailman id 692892; Thu, 14 Mar 2024 07:20:40 +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 1rkfOK-0005rB-A4 for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:20:40 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5b4f105f-e1d3-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 08:20:38 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C04EB21CF1; Thu, 14 Mar 2024 07:20:37 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7C81F13977; Thu, 14 Mar 2024 07:20:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id UhLnHEWl8mU9DgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:20:37 +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: 5b4f105f-e1d3-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400837; 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=X3wK2bnFDRfOZpwTuXtrdzOv2dz+Aoq7ilBYLmKlrOE=; b=XtEVciV9XSAXvu2Ftt1+X3UG5p21zNQSUHdmIzP+sWEnRFuJ1G6mR2eE0/t473+PkyA25j XqTgtWkod6gbedfJlR9XQQ2vMSKGiSIxld5Kemrw6yTApNUKqr60B0paxCi0vZnP6j5O4X adH0J5hyzmO3FanzLPuyZPZOWSePXPk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400837; 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=X3wK2bnFDRfOZpwTuXtrdzOv2dz+Aoq7ilBYLmKlrOE=; b=XtEVciV9XSAXvu2Ftt1+X3UG5p21zNQSUHdmIzP+sWEnRFuJ1G6mR2eE0/t473+PkyA25j XqTgtWkod6gbedfJlR9XQQ2vMSKGiSIxld5Kemrw6yTApNUKqr60B0paxCi0vZnP6j5O4X adH0J5hyzmO3FanzLPuyZPZOWSePXPk= 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 v5 01/13] xen/spinlock: remove misra rule 21.1 violations Date: Thu, 14 Mar 2024 08:20:17 +0100 Message-Id: <20240314072029.16937-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: + Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=XtEVciV9 X-Spamd-Result: default: False [1.19 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.00)[13.89%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; URIBL_BLOCKED(0.00)[suse.com:email,suse.com:dkim]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_MED(-2.00)[suse.com:dkim]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 1.19 X-Spam-Level: * X-Rspamd-Queue-Id: C04EB21CF1 X-Spam-Flag: NO X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400858658100001 Content-Type: text/plain; charset="utf-8" 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 --- V5: - new patch (Julien Grall) --- xen/include/xen/spinlock.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index e351fc9995..8a443efc19 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -22,7 +22,7 @@ union lock_debug { bool unseen:1; }; }; -#define _LOCK_DEBUG { .val =3D LOCK_DEBUG_INITVAL } +#define LOCK_DEBUG_ { .val =3D 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 */ }; =20 -#define _LOCK_PROFILE(lockname) { .name =3D #lockname, .lock =3D &(locknam= e), } -#define _LOCK_PROFILE_PTR(name) = \ - static struct lock_profile * const __lock_profile_##name = \ +#define LOCK_PROFILE_(lockname) { .name =3D #lockname, .lock =3D &(locknam= e), } +#define LOCK_PROFILE_PTR_(name) = \ + static struct lock_profile * const lock_profile__##name = \ __used_section(".lockprofile.data") =3D = \ - &__lock_profile_data_##name -#define _SPIN_LOCK_UNLOCKED(x) { = \ + &lock_profile_data__##name +#define SPIN_LOCK_UNLOCKED_(x) { = \ .recurse_cpu =3D SPINLOCK_NO_CPU, = \ - .debug =3D_LOCK_DEBUG, = \ + .debug =3D LOCK_DEBUG_, = \ .profile =3D x, = \ } -#define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) +#define SPIN_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED_(NULL) #define DEFINE_SPINLOCK(l) = \ - spinlock_t l =3D _SPIN_LOCK_UNLOCKED(NULL); = \ - static struct lock_profile __lock_profile_data_##l =3D _LOCK_PROFILE(l= ); \ - _LOCK_PROFILE_PTR(l) + spinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ + static struct lock_profile lock_profile_data__##l =3D LOCK_PROFILE_(l)= ; \ + LOCK_PROFILE_PTR_(l) =20 #define spin_lock_init_prof(s, l) = \ do { = \ struct lock_profile *prof; = \ prof =3D xzalloc(struct lock_profile); = \ - (s)->l =3D (spinlock_t)_SPIN_LOCK_UNLOCKED(prof); = \ + (s)->l =3D (spinlock_t)SPIN_LOCK_UNLOCKED_(prof); = \ if ( !prof ) = \ { = \ printk(XENLOG_WARNING = \ @@ -149,7 +149,7 @@ struct lock_profile_qhead { }; =20 #define SPIN_LOCK_UNLOCKED { = \ .recurse_cpu =3D SPINLOCK_NO_CPU, = \ - .debug =3D_LOCK_DEBUG, = \ + .debug =3D LOCK_DEBUG_, = \ } #define DEFINE_SPINLOCK(l) spinlock_t l =3D SPIN_LOCK_UNLOCKED =20 --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400859; cv=none; d=zohomail.com; s=zohoarc; b=b7qcJS/bIBHnrb0OLukDbxAq9TMDmQOh4HX1tsw5S10eB67Uv3pfi5b/AQ/EaWyV+tp+QjF1m4CG9+IMycfWiaXPsafUuJ0TQDeT/zH16d93lH+9U2aL+9d+4IErRSxl8Dp8JHDL+RpKh2V+/BzFJ2lcPUHwfK+qvb9q33BUHqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400859; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8SoHtTqibFLRHMVIneFYHEvHJn0+Pf8akCVrfANI5Kk=; b=fCGZrSbfTqDocoe8ZeM0GN3zoq9NctH7nUFuIolM/7s8PpO/9QMt9BpyHjNoUiy86dnJthL8KIJLJ6czw8JaoIvEx1/cMiXonFwfb5h23F+FK94f99356jXp9WppOmMj00Bk5Hjnf2b0mphVcssZ2HCJkP2tVxoQU3TKEBAymLU= 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 1710400859965892.1706330726818; Thu, 14 Mar 2024 00:20:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692893.1080539 (Exim 4.92) (envelope-from ) id 1rkfOQ-0006A3-FV; Thu, 14 Mar 2024 07:20:46 +0000 Received: by outflank-mailman (output) from mailman id 692893.1080539; Thu, 14 Mar 2024 07:20: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 1rkfOQ-00069u-BN; Thu, 14 Mar 2024 07:20:46 +0000 Received: by outflank-mailman (input) for mailman id 692893; Thu, 14 Mar 2024 07:20: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 1rkfOO-0005cd-JJ for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:20:44 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5ea5b875-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:20:43 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 849331F79B; Thu, 14 Mar 2024 07:20:43 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C51A13977; Thu, 14 Mar 2024 07:20:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 23g9CUul8mVEDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:20:43 +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: 5ea5b875-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400843; 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=8SoHtTqibFLRHMVIneFYHEvHJn0+Pf8akCVrfANI5Kk=; b=UtjjGmvlEZgzkf0ajpqMhzvRwrdgeNDNME2mUCv+CJMiXhz3as7rV/7nj/7fiVFa0hsXix uWwNXwxF8MhGnXogt3ROWFqc4KsqhGqQAE0dYclbYLDV1ERRVQcjcsneH4fzA7F/53Bxck RNryG3rbnPYxLr2WLz1x3cnU7k1G7as= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400843; 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=8SoHtTqibFLRHMVIneFYHEvHJn0+Pf8akCVrfANI5Kk=; b=UtjjGmvlEZgzkf0ajpqMhzvRwrdgeNDNME2mUCv+CJMiXhz3as7rV/7nj/7fiVFa0hsXix uWwNXwxF8MhGnXogt3ROWFqc4KsqhGqQAE0dYclbYLDV1ERRVQcjcsneH4fzA7F/53Bxck RNryG3rbnPYxLr2WLz1x3cnU7k1G7as= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini , Paul Durrant , Julien Grall Subject: [PATCH v5 02/13] xen/spinlock: introduce new type for recursive spinlocks Date: Thu, 14 Mar 2024 08:20:18 +0100 Message-Id: <20240314072029.16937-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[11]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400860632100003 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Julien Grall Acked-by: Jan Beulich --- 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(-) diff --git a/xen/arch/x86/include/asm/mm.h b/xen/arch/x86/include/asm/mm.h index 65d209d5ff..98b66edaca 100644 --- a/xen/arch/x86/include/asm/mm.h +++ b/xen/arch/x86/include/asm/mm.h @@ -597,7 +597,7 @@ unsigned long domain_get_maximum_gpfn(struct domain *d); =20 /* 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 */ diff --git a/xen/arch/x86/mm/mm-locks.h b/xen/arch/x86/mm/mm-locks.h index 2eae73ac68..c25261b4c0 100644 --- a/xen/arch/x86/mm/mm-locks.h +++ b/xen/arch/x86/mm/mm-locks.h @@ -20,7 +20,7 @@ DECLARE_PERCPU_RWLOCK_GLOBAL(p2m_percpu_rwlock); =20 static inline void mm_lock_init(mm_lock_t *l) { - spin_lock_init(&l->lock); + rspin_lock_init(&l->lock); l->locker =3D -1; l->locker_function =3D "nobody"; l->unlock_level =3D 0; diff --git a/xen/common/domain.c b/xen/common/domain.c index f6f5574996..8e0109c590 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -627,8 +627,8 @@ struct domain *domain_create(domid_t domid, =20 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); diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 62b907f4c4..652c18a9b5 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -1331,7 +1331,7 @@ unsigned int ioreq_broadcast(ioreq_t *p, bool buffere= d) =20 void ioreq_domain_init(struct domain *d) { - spin_lock_init(&d->ioreq_server.lock); + rspin_lock_init(&d->ioreq_server.lock); =20 arch_ioreq_domain_init(d); } diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index d2cb0530b2..6a88a0b32c 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -119,7 +119,7 @@ static int __read_mostly sercon_handle =3D -1; int8_t __read_mostly opt_console_xen; /* console=3Dxen */ #endif =20 -static DEFINE_SPINLOCK(console_lock); +static DEFINE_RSPINLOCK(console_lock); =20 /* * 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 =3D 1; console_start_sync(); diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 6a1eda675d..b6b2196ab0 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -50,7 +50,7 @@ struct pci_seg { } bus2bridge[MAX_BUSES]; }; =20 -static spinlock_t _pcidevs_lock =3D SPIN_LOCK_UNLOCKED; +static DEFINE_RSPINLOCK(_pcidevs_lock); =20 /* Do not use, as it has no speculation barrier, use pcidevs_lock() instea= d. */ void pcidevs_lock_unsafe(void) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 37f5922f32..bc320f4e55 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -376,9 +376,9 @@ struct domain =20 rcu_read_lock_t rcu_lock; =20 - spinlock_t domain_lock; + rspinlock_t domain_lock; =20 - 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_page= s) */ 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 diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 8a443efc19..bbf12b93c4 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -46,7 +46,7 @@ union lock_debug { }; lock profiling on: =20 Global locks which should be subject to profiling must be declared via - DEFINE_SPINLOCK. + DEFINE_[R]SPINLOCK. =20 For locks in structures further measures are necessary: - the structure definition must include a profile_head with exactly th= is @@ -57,7 +57,7 @@ union lock_debug { }; - the single locks which are subject to profiling have to be initializ= ed via =20 - spin_lock_init_prof(ptr, lock); + [r]spin_lock_init_prof(ptr, lock); =20 with ptr being the main structure pointer and lock the spinlock field =20 @@ -110,12 +110,16 @@ struct lock_profile_qhead { spinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ static struct lock_profile lock_profile_data__##l =3D LOCK_PROFILE_(l)= ; \ LOCK_PROFILE_PTR_(l) +#define DEFINE_RSPINLOCK(l) = \ + rspinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ + static struct lock_profile lock_profile_data__##l =3D LOCK_PROFILE_(l)= ; \ + LOCK_PROFILE_PTR_(l) =20 -#define spin_lock_init_prof(s, l) = \ +#define spin_lock_init_prof__(s, l, locktype) = \ do { = \ struct lock_profile *prof; = \ prof =3D xzalloc(struct lock_profile); = \ - (s)->l =3D (spinlock_t)SPIN_LOCK_UNLOCKED_(prof); = \ + (s)->l =3D (locktype)SPIN_LOCK_UNLOCKED_(prof); = \ if ( !prof ) = \ { = \ printk(XENLOG_WARNING = \ @@ -129,6 +133,9 @@ struct lock_profile_qhead { (s)->profile_head.elem_q =3D prof; = \ } while( 0 ) =20 +#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 =3D LOCK_DEBUG_, = \ } #define DEFINE_SPINLOCK(l) spinlock_t l =3D SPIN_LOCK_UNLOCKED +#define DEFINE_RSPINLOCK(l) rspinlock_t l =3D SPIN_LOCK_UNLOCKED =20 #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; =20 +typedef spinlock_t rspinlock_t; =20 #define spin_lock_init(l) (*(l) =3D (spinlock_t)SPIN_LOCK_UNLOCKED) +#define rspin_lock_init(l) (*(l) =3D (rspinlock_t)SPIN_LOCK_UNLOCKED) =20 void _spin_lock(spinlock_t *lock); void _spin_lock_cb(spinlock_t *lock, void (*cb)(void *data), void *data); --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400869; cv=none; d=zohomail.com; s=zohoarc; b=i9t196OZBnTMuvjQTqiHo0ALb8prjgunnh+H4JGNbkuR/kgVNP7c35XOy3s648nBm1X7dfS+hfU0pdxDBe7SOlEACfHmbKOYjGQaNogKPv7RliO1sihpLOLHHbB0EHCxj/vBK45Qe5iz3mQF7zcb3mbTJsI/BYuHSTBWH52+uso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400869; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FVq2Hhj4vgnKxymRlgvuDk+/88ycU3FDdi3C03ffSSU=; b=gLQjB23ukAar4gBUAoeRYbWx4gsLgaWgsGPTKpJpZ93Ji4ZPoI521obMdjaqZNPZH8UcwtwuozRFGc2Dq9qzmtpEIO6g1GEapK7pRA00bzfLsSaoBl5zF5S+G7N6GA5GhkAl+keV5mZer5u08MPEqWLMMTJhVt9sLJC+241Nslc= 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 1710400869586654.105589220889; Thu, 14 Mar 2024 00:21:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692894.1080548 (Exim 4.92) (envelope-from ) id 1rkfOW-0006YG-Ma; Thu, 14 Mar 2024 07:20:52 +0000 Received: by outflank-mailman (output) from mailman id 692894.1080548; Thu, 14 Mar 2024 07:20:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOW-0006Y9-Jo; Thu, 14 Mar 2024 07:20:52 +0000 Received: by outflank-mailman (input) for mailman id 692894; Thu, 14 Mar 2024 07:20:51 +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 1rkfOU-0005cd-WE for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:20:51 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 623eb253-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:20:50 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6480F1F801; Thu, 14 Mar 2024 07:20:49 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E7ECB13977; Thu, 14 Mar 2024 07:20:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id nmnrNlCl8mVIDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:20:48 +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: 623eb253-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400849; 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=FVq2Hhj4vgnKxymRlgvuDk+/88ycU3FDdi3C03ffSSU=; b=LSj85bTVer0Yyv4TshSUyjWTfE2y5k/eAAEuirfoBmlJ8JkQt9Nq9d2XFIuYPWbUOWnpd8 wLUqj/svIK5VFADn7nOP3h5T48gWU3zM8JDh0KyIxx2Ah8MZZ5+3MkWm2Cs5+g6lWqVD0w vWCJs0tLIOX2UDoGxaViRCBfMFJQEh0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400849; 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=FVq2Hhj4vgnKxymRlgvuDk+/88ycU3FDdi3C03ffSSU=; b=LSj85bTVer0Yyv4TshSUyjWTfE2y5k/eAAEuirfoBmlJ8JkQt9Nq9d2XFIuYPWbUOWnpd8 wLUqj/svIK5VFADn7nOP3h5T48gWU3zM8JDh0KyIxx2Ah8MZZ5+3MkWm2Cs5+g6lWqVD0w vWCJs0tLIOX2UDoGxaViRCBfMFJQEh0= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Tamas K Lengyel , Paul Durrant , Julien Grall Subject: [PATCH v5 03/13] xen/spinlock: rename recursive lock functions Date: Thu, 14 Mar 2024 08:20:19 +0100 Message-Id: <20240314072029.16937-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=LSj85bTV X-Spamd-Result: default: False [-1.81 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; URIBL_BLOCKED(0.00)[suse.com:email,suse.com:dkim]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_MED(-2.00)[suse.com:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[15]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -1.81 X-Rspamd-Queue-Id: 6480F1F801 X-Spam-Flag: NO X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400870763100002 Content-Type: text/plain; charset="utf-8" Rename the recursive spin_lock() functions by replacing the trailing "_recursive" with a leading "r". Switch the parameter to be a pointer to rspinlock_t. Suggested-by: Jan Beulich Signed-off-by: Juergen Gross Acked-by: Julien Grall Acked-by: Jan Beulich --- 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(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 5e7a7f3e7e..f38cb5e04c 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -987,7 +987,7 @@ static int relinquish_memory(struct domain *d, struct p= age_list_head *list) int ret =3D 0; =20 /* Use a recursive lock, as we may enter 'free_domheap_page'. */ - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 page_list_for_each_safe( page, tmp, list ) { @@ -1014,7 +1014,7 @@ static int relinquish_memory(struct domain *d, struct= page_list_head *list) } =20 out: - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); return ret; } =20 diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bda853e3c9..a11c55f921 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1323,7 +1323,7 @@ int arch_set_info_guest( { bool done =3D false; =20 - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 for ( i =3D 0; ; ) { @@ -1344,7 +1344,7 @@ int arch_set_info_guest( break; } =20 - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); =20 if ( !done ) return -ERESTART; @@ -2183,7 +2183,7 @@ static int relinquish_memory( int ret =3D 0; =20 /* Use a recursive lock, as we may enter 'free_domheap_page'. */ - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 while ( (page =3D page_list_remove_head(list)) ) { @@ -2324,7 +2324,7 @@ static int relinquish_memory( page_list_move(list, &d->arch.relmem_list); =20 out: - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); return ret; } =20 diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index fe299a2bf9..f58576c702 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -682,7 +682,7 @@ static int page_make_sharable(struct domain *d, int rc =3D 0; bool drop_dom_ref =3D false; =20 - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 if ( d->is_dying ) { @@ -725,7 +725,7 @@ static int page_make_sharable(struct domain *d, } =20 out: - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); =20 if ( drop_dom_ref ) put_domain(d); @@ -1936,7 +1936,7 @@ int mem_sharing_fork_reset(struct domain *d, bool res= et_state, goto state; =20 /* 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 res= et_state, put_page_alloc_ref(page); put_page_and_type(page); } - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); =20 state: if ( reset_state ) diff --git a/xen/arch/x86/mm/mm-locks.h b/xen/arch/x86/mm/mm-locks.h index c25261b4c0..669969c6ee 100644 --- a/xen/arch/x86/mm/mm-locks.h +++ b/xen/arch/x86/mm/mm-locks.h @@ -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 =3D=3D 1 ) { l->locker_function =3D func; @@ -202,7 +202,7 @@ static inline void mm_unlock(mm_lock_t *l) l->locker_function =3D "nobody"; _set_lock_level(l->unlock_level); } - spin_unlock_recursive(&l->lock); + rspin_unlock(&l->lock); } =20 static inline void mm_enforce_order_unlock(int unlock_level, diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 652c18a9b5..1257a3d972 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -329,7 +329,7 @@ bool is_ioreq_server_page(struct domain *d, const struc= t page_info *page) unsigned int id; bool found =3D false; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 FOR_EACH_IOREQ_SERVER(d, id, s) { @@ -340,7 +340,7 @@ bool is_ioreq_server_page(struct domain *d, const struc= t page_info *page) } } =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return found; } @@ -658,7 +658,7 @@ static int ioreq_server_create(struct domain *d, int bu= fioreq_handling, return -ENOMEM; =20 domain_pause(d); - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 for ( i =3D 0; i < MAX_NR_IOREQ_SERVERS; i++ ) { @@ -686,13 +686,13 @@ static int ioreq_server_create(struct domain *d, int = bufioreq_handling, if ( id ) *id =3D i; =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); domain_unpause(d); =20 return 0; =20 fail: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); domain_unpause(d); =20 xfree(s); @@ -704,7 +704,7 @@ static int ioreq_server_destroy(struct domain *d, ioser= vid_t id) struct ioreq_server *s; int rc; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -736,7 +736,7 @@ static int ioreq_server_destroy(struct domain *d, ioser= vid_t id) rc =3D 0; =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -749,7 +749,7 @@ static int ioreq_server_get_info(struct domain *d, iose= rvid_t id, struct ioreq_server *s; int rc; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -783,7 +783,7 @@ static int ioreq_server_get_info(struct domain *d, iose= rvid_t id, rc =3D 0; =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -796,7 +796,7 @@ int ioreq_server_get_frame(struct domain *d, ioservid_t= id, =20 ASSERT(is_hvm_domain(d)); =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -834,7 +834,7 @@ int ioreq_server_get_frame(struct domain *d, ioservid_t= id, } =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -850,7 +850,7 @@ static int ioreq_server_map_io_range(struct domain *d, = ioservid_t id, if ( start > end ) return -EINVAL; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -886,7 +886,7 @@ static int ioreq_server_map_io_range(struct domain *d, = ioservid_t id, rc =3D rangeset_add_range(r, start, end); =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -902,7 +902,7 @@ static int ioreq_server_unmap_io_range(struct domain *d= , ioservid_t id, if ( start > end ) return -EINVAL; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -938,7 +938,7 @@ static int ioreq_server_unmap_io_range(struct domain *d= , ioservid_t id, rc =3D rangeset_remove_range(r, start, end); =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -963,7 +963,7 @@ int ioreq_server_map_mem_type(struct domain *d, ioservi= d_t id, if ( flags & ~XEN_DMOP_IOREQ_MEM_ACCESS_WRITE ) return -EINVAL; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -978,7 +978,7 @@ int ioreq_server_map_mem_type(struct domain *d, ioservi= d_t id, rc =3D arch_ioreq_server_map_mem_type(d, s, flags); =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 if ( rc =3D=3D 0 ) arch_ioreq_server_map_mem_type_completed(d, s, flags); @@ -992,7 +992,7 @@ static int ioreq_server_set_state(struct domain *d, ios= ervid_t id, struct ioreq_server *s; int rc; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 s =3D get_ioreq_server(d, id); =20 @@ -1016,7 +1016,7 @@ static int ioreq_server_set_state(struct domain *d, i= oservid_t id, rc =3D 0; =20 out: - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); return rc; } =20 @@ -1026,7 +1026,7 @@ int ioreq_server_add_vcpu_all(struct domain *d, struc= t vcpu *v) unsigned int id; int rc; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 FOR_EACH_IOREQ_SERVER(d, id, s) { @@ -1035,7 +1035,7 @@ int ioreq_server_add_vcpu_all(struct domain *d, struc= t vcpu *v) goto fail; } =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return 0; =20 @@ -1050,7 +1050,7 @@ int ioreq_server_add_vcpu_all(struct domain *d, struc= t vcpu *v) ioreq_server_remove_vcpu(s, v); } =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); =20 return rc; } @@ -1060,12 +1060,12 @@ void ioreq_server_remove_vcpu_all(struct domain *d,= struct vcpu *v) struct ioreq_server *s; unsigned int id; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 FOR_EACH_IOREQ_SERVER(d, id, s) ioreq_server_remove_vcpu(s, v); =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); } =20 void ioreq_server_destroy_all(struct domain *d) @@ -1076,7 +1076,7 @@ void ioreq_server_destroy_all(struct domain *d) if ( !arch_ioreq_server_destroy_all(d) ) return; =20 - spin_lock_recursive(&d->ioreq_server.lock); + rspin_lock(&d->ioreq_server.lock); =20 /* No need to domain_pause() as the domain is being torn down */ =20 @@ -1094,7 +1094,7 @@ void ioreq_server_destroy_all(struct domain *d) xfree(s); } =20 - spin_unlock_recursive(&d->ioreq_server.lock); + rspin_unlock(&d->ioreq_server.lock); } =20 struct ioreq_server *ioreq_server_select(struct domain *d, diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 2ec17df9b4..b4e0ef3a4c 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2500,7 +2500,7 @@ void free_domheap_pages(struct page_info *pg, unsigne= d 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); =20 for ( i =3D 0; i < (1 << order); i++ ) arch_free_heap_page(d, &pg[i]); @@ -2508,7 +2508,7 @@ void free_domheap_pages(struct page_info *pg, unsigne= d int order) d->xenheap_pages -=3D 1 << order; drop_dom_ref =3D (d->xenheap_pages =3D=3D 0); =20 - 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, unsigne= d int order) if ( likely(d) && likely(d !=3D dom_cow) ) { /* NB. May recursively lock from relinquish_memory(). */ - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 for ( i =3D 0; i < (1 << order); i++ ) { @@ -2540,7 +2540,7 @@ void free_domheap_pages(struct page_info *pg, unsigne= d int order) =20 drop_dom_ref =3D !domain_adjust_tot_pages(d, -(1 << order)); =20 - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); =20 /* * Normally we expect a domain to clear pages before freeing t= hem, @@ -2756,7 +2756,7 @@ void free_domstatic_page(struct page_info *page) ASSERT_ALLOC_CONTEXT(); =20 /* NB. May recursively lock from relinquish_memory(). */ - spin_lock_recursive(&d->page_alloc_lock); + rspin_lock(&d->page_alloc_lock); =20 arch_free_heap_page(d, page); =20 @@ -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); =20 - spin_unlock_recursive(&d->page_alloc_lock); + rspin_unlock(&d->page_alloc_lock); =20 if ( drop_dom_ref ) put_domain(d); diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 09028af864..11e13e1259 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -436,7 +436,7 @@ void _spin_barrier(spinlock_t *lock) smp_mb(); } =20 -int _spin_trylock_recursive(spinlock_t *lock) +bool _rspin_trylock(rspinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); =20 @@ -448,8 +448,8 @@ int _spin_trylock_recursive(spinlock_t *lock) =20 if ( likely(lock->recurse_cpu !=3D cpu) ) { - if ( !spin_trylock(lock) ) - return 0; + if ( !_spin_trylock(lock) ) + return false; lock->recurse_cpu =3D cpu; } =20 @@ -457,10 +457,10 @@ int _spin_trylock_recursive(spinlock_t *lock) ASSERT(lock->recurse_cnt < SPINLOCK_MAX_RECURSE); lock->recurse_cnt++; =20 - return 1; + return true; } =20 -void _spin_lock_recursive(spinlock_t *lock) +void _rspin_lock(rspinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); =20 @@ -475,7 +475,7 @@ void _spin_lock_recursive(spinlock_t *lock) lock->recurse_cnt++; } =20 -void _spin_unlock_recursive(spinlock_t *lock) +void _rspin_unlock(rspinlock_t *lock) { if ( likely(--lock->recurse_cnt =3D=3D 0) ) { diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 6a88a0b32c..eca17b55b4 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -919,7 +919,7 @@ static void vprintk_common(const char *prefix, const ch= ar *fmt, va_list args) =20 /* console_lock can be acquired recursively from __printk_ratelimit().= */ local_irq_save(flags); - spin_lock_recursive(&console_lock); + rspin_lock(&console_lock); state =3D &this_cpu(state); =20 (void)vsnprintf(buf, sizeof(buf), fmt, args); @@ -955,7 +955,7 @@ static void vprintk_common(const char *prefix, const ch= ar *fmt, va_list args) state->continued =3D 1; } =20 - spin_unlock_recursive(&console_lock); + rspin_unlock(&console_lock); local_irq_restore(flags); } =20 @@ -1162,14 +1162,14 @@ unsigned long console_lock_recursive_irqsave(void) unsigned long flags; =20 local_irq_save(flags); - spin_lock_recursive(&console_lock); + rspin_lock(&console_lock); =20 return flags; } =20 void console_unlock_recursive_irqrestore(unsigned long flags) { - spin_unlock_recursive(&console_lock); + rspin_unlock(&console_lock); local_irq_restore(flags); } =20 @@ -1230,12 +1230,12 @@ int __printk_ratelimit(int ratelimit_ms, int rateli= mit_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; diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index b6b2196ab0..4fcc7e2cde 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -55,12 +55,12 @@ static DEFINE_RSPINLOCK(_pcidevs_lock); /* Do not use, as it has no speculation barrier, use pcidevs_lock() instea= d. */ void pcidevs_lock_unsafe(void) { - _spin_lock_recursive(&_pcidevs_lock); + _rspin_lock(&_pcidevs_lock); } =20 void pcidevs_unlock(void) { - spin_unlock_recursive(&_pcidevs_lock); + rspin_unlock(&_pcidevs_lock); } =20 bool pcidevs_locked(void) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index bc320f4e55..85d44a16f5 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -358,8 +358,8 @@ struct sched_unit { (v) =3D (v)->next_in_list ) =20 /* 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) =20 struct evtchn_port_ops; =20 diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index bbf12b93c4..50f6580f52 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -210,10 +210,6 @@ int _spin_is_locked(const spinlock_t *lock); int _spin_trylock(spinlock_t *lock); void _spin_barrier(spinlock_t *lock); =20 -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) =20 /* - * 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 fo= rm * part of a recursively-nested set must be protected by these forms. If t= here * 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); =20 -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(); } =20 -#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) =20 #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400869; cv=none; d=zohomail.com; s=zohoarc; b=hS22JwpifuUkdxqxtaVFmqbO17Mbj/ap9VS5T6TgTrBW0h3m+yQgzAJFkz28J+ce20yunP5CE+SKuTNiHHFSOhRgfdqQtXgjcOILWrMjDbJr7h3uINqBL5pd/opC4S2z2M9ZxLesLjsFJTgl9S7gSnBjHeF+iOjO3uO7TLo7WRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400869; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CZJrib1UGrzmVSpmgprY0xMWihJMCjOR39gpkTSzqsU=; b=hSoQY5aJUR9O+cfUVEEv8ivS0pdj4RTD/PikPUzwHlKoh/DMf4XH97u57HXYxC5BVtk5KIMLp9e9sMSj1cdnV/nUr8DO2KO95O9hnXtsWBDTqryK3elsZzWESXORV4JpCWgYaicDAv2HqBgRK1++nf9Yil02Apil5nBOIA6vl6c= 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 1710400869577942.6001139927939; Thu, 14 Mar 2024 00:21:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692897.1080559 (Exim 4.92) (envelope-from ) id 1rkfOc-00070P-30; Thu, 14 Mar 2024 07:20:58 +0000 Received: by outflank-mailman (output) from mailman id 692897.1080559; Thu, 14 Mar 2024 07:20:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOc-0006za-0E; Thu, 14 Mar 2024 07:20:58 +0000 Received: by outflank-mailman (input) for mailman id 692897; Thu, 14 Mar 2024 07:20:57 +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 1rkfOa-0005cd-VK for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:20:56 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 658ef96a-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:20:55 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 271C01F801; Thu, 14 Mar 2024 07:20:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CDFCD13977; Thu, 14 Mar 2024 07:20:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id EhKxMFal8mVTDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:20:54 +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: 658ef96a-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400855; 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=CZJrib1UGrzmVSpmgprY0xMWihJMCjOR39gpkTSzqsU=; b=dpaeFiBTyGzUg2S/xFMG3QJSOPMci0iY/s+TfqbBPwwlVDibOvhTJGjQ20x81ka4Lual9x 2ZKVnSUWUZbHkmwDP9JoDyIMYXrUJrxq3nrM6DhdvY6XJClNGfRz4mf3gYcgpTj0LfQ1xg oPaUuYHRt5oACbrPijI/NYCpHY0ev/U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400855; 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=CZJrib1UGrzmVSpmgprY0xMWihJMCjOR39gpkTSzqsU=; b=dpaeFiBTyGzUg2S/xFMG3QJSOPMci0iY/s+TfqbBPwwlVDibOvhTJGjQ20x81ka4Lual9x 2ZKVnSUWUZbHkmwDP9JoDyIMYXrUJrxq3nrM6DhdvY6XJClNGfRz4mf3gYcgpTj0LfQ1xg oPaUuYHRt5oACbrPijI/NYCpHY0ev/U= 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 v5 04/13] xen/spinlock: add rspin_[un]lock_irq[save|restore]() Date: Thu, 14 Mar 2024 08:20:20 +0100 Message-Id: <20240314072029.16937-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: * Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400870725100001 Content-Type: text/plain; charset="utf-8" Instead 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. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- 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(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 11e13e1259..5ef0ac7f89 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -475,15 +475,31 @@ void _rspin_lock(rspinlock_t *lock) lock->recurse_cnt++; } =20 +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 =3D=3D 0) ) { lock->recurse_cpu =3D SPINLOCK_NO_CPU; - spin_unlock(lock); + _spin_unlock(lock); } } =20 +void _rspin_unlock_irqrestore(rspinlock_t *lock, unsigned long flags) +{ + _rspin_unlock(lock); + local_irq_restore(flags); +} + #ifdef CONFIG_DEBUG_LOCK_PROFILE =20 struct lock_profile_anc { diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index eca17b55b4..ccd5f8cc14 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1161,16 +1161,14 @@ unsigned long console_lock_recursive_irqsave(void) { unsigned long flags; =20 - local_irq_save(flags); - rspin_lock(&console_lock); + rspin_lock_irqsave(&console_lock, flags); =20 return flags; } =20 void console_unlock_recursive_irqrestore(unsigned long flags) { - rspin_unlock(&console_lock); - local_irq_restore(flags); + rspin_unlock_irqrestore(&console_lock, flags); } =20 void console_force_unlock(void) diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 50f6580f52..afa24c8e29 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -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) !=3D sizeof(unsigned long)); \ + ((f) =3D _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); =20 static always_inline void rspin_lock(rspinlock_t *lock) { @@ -282,5 +290,6 @@ static always_inline void rspin_lock(rspinlock_t *lock) =20 #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) =20 #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400878; cv=none; d=zohomail.com; s=zohoarc; b=hq6LTjirpb1mE68doRnLWcbJldusU6nUu3SzLMo/gdnbxGGDpvqD0qholLYOHfWVCilfZIG3ExtZdVVwMZJ59SphByEhOYy4d3qD7SVohwq3zNMz6tnkplgBZ+WdnUpDHishpBWYQ0hAV05iRASiQjikcT0HAQHSzAOROOgaXeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400878; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a3Lzu5w3Sdvw06E/H34sX80jbLTV1UigAHpKpIJhJHE=; b=dTxDs4cVSOa1rMNkpOh9v9KN4DwOpqKWDP+OfDWd3o6AxwuA19xmK8kicExo67DlNxCOiVUFcqvN0O7BfNLE5gYxSMCOxYhh3znasLypG6EImBwrldS78YWYRfbE8DJfNbR0QgXQ12ADlW4zb1J1nU52vNdCjIRRNcw2Rl9tsvM= 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 1710400878219643.8345714852229; Thu, 14 Mar 2024 00:21:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692899.1080569 (Exim 4.92) (envelope-from ) id 1rkfOi-0007US-BX; Thu, 14 Mar 2024 07:21:04 +0000 Received: by outflank-mailman (output) from mailman id 692899.1080569; Thu, 14 Mar 2024 07:21:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOi-0007UI-7r; Thu, 14 Mar 2024 07:21:04 +0000 Received: by outflank-mailman (input) for mailman id 692899; Thu, 14 Mar 2024 07:21:02 +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 1rkfOg-0005rB-SA for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:02 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 69000f81-e1d3-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 08:21:01 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CACBB1F79B; Thu, 14 Mar 2024 07:21:00 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7BC6813977; Thu, 14 Mar 2024 07:21:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 69SvHFyl8mVWDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:00 +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: 69000f81-e1d3-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400860; 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=a3Lzu5w3Sdvw06E/H34sX80jbLTV1UigAHpKpIJhJHE=; b=NJPhIVfe32Lkx0q3Y/1oQNem7v+szp2DChpY95VPQJ3hiKRJIlLgwLhRJecuw4TxPk9WfB vE2/JDXx/D3FSMJjDlWHMWaxdl3DM6pRn6hWCuR29OavCQzxQVlZn81x0Yv52Qe7izL1ht piKji4mpTMzF80KV1DJ02X8MoI75exM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400860; 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=a3Lzu5w3Sdvw06E/H34sX80jbLTV1UigAHpKpIJhJHE=; b=NJPhIVfe32Lkx0q3Y/1oQNem7v+szp2DChpY95VPQJ3hiKRJIlLgwLhRJecuw4TxPk9WfB vE2/JDXx/D3FSMJjDlWHMWaxdl3DM6pRn6hWCuR29OavCQzxQVlZn81x0Yv52Qe7izL1ht piKji4mpTMzF80KV1DJ02X8MoI75exM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Alejandro Vallejo , Julien Grall Subject: [PATCH v5 05/13] xen/spinlock: make struct lock_profile rspinlock_t aware Date: Thu, 14 Mar 2024 08:20:21 +0100 Message-Id: <20240314072029.16937-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400878681100001 Content-Type: text/plain; charset="utf-8" Struct 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. Signed-off-by: Juergen Gross Acked-by: Alejandro Vallejo Acked-by: Julien Grall --- 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(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 5ef0ac7f89..0e8b525cec 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -538,19 +538,31 @@ static void spinlock_profile_iterate(lock_profile_sub= func *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 =3D data->lock; + unsigned int cpu; + unsigned int lockval; + + if ( data->is_rlock ) + { + cpu =3D data->ptr.rlock->debug.cpu; + lockval =3D data->ptr.rlock->tickets.head_tail; + } + else + { + cpu =3D data->ptr.lock->debug.cpu; + lockval =3D data->ptr.lock->tickets.head_tail; + } =20 printk("%s ", lock_profile_ancs[type].name); if ( type !=3D LOCKPROF_TYPE_GLOBAL ) printk("%d ", idx); - printk("%s: addr=3D%p, lockval=3D%08x, ", data->name, lock, - lock->tickets.head_tail); - if ( lock->debug.cpu =3D=3D SPINLOCK_NO_CPU ) + printk("%s: addr=3D%p, lockval=3D%08x, ", data->name, data->ptr.lock, = lockval); + if ( cpu =3D=3D SPINLOCK_NO_CPU ) printk("not locked\n"); else - printk("cpu=3D%d\n", lock->debug.cpu); - printk(" lock:%" PRId64 "(%" PRI_stime "), block:%" PRId64 "(%" PRI_s= time ")\n", - data->lock_cnt, data->time_hold, data->block_cnt, data->time_bl= ock); + printk("cpu=3D%u\n", cpu); + printk(" lock:%" PRIu64 "(%" PRI_stime "), block:%" PRIu64 "(%" PRI_s= time ")\n", + data->lock_cnt, data->time_hold, (uint64_t)data->block_cnt, + data->time_block); } =20 void cf_check spinlock_profile_printall(unsigned char key) @@ -680,7 +692,7 @@ static int __init cf_check lock_prof_init(void) { (*q)->next =3D lock_profile_glb_q.elem_q; lock_profile_glb_q.elem_q =3D *q; - (*q)->lock->profile =3D *q; + (*q)->ptr.lock->profile =3D *q; } =20 _lock_profile_register_struct(LOCKPROF_TYPE_GLOBAL, diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index afa24c8e29..49c5115f52 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -77,13 +77,19 @@ union lock_debug { }; */ =20 struct spinlock; +/* Temporary hack until a dedicated struct rspinlock is existing. */ +#define rspinlock spinlock =20 struct 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 */ }; =20 -#define LOCK_PROFILE_(lockname) { .name =3D #lockname, .lock =3D &(locknam= e), } +#define LOCK_PROFILE_(lockname) { .name =3D #lockname, .ptr.lock =3D &(loc= kname), } #define LOCK_PROFILE_PTR_(name) = \ static struct lock_profile * const lock_profile__##name = \ __used_section(".lockprofile.data") =3D = \ @@ -128,7 +134,7 @@ struct lock_profile_qhead { break; = \ } = \ prof->name =3D #l; = \ - prof->lock =3D &(s)->l; = \ + prof->ptr.lock =3D &(s)->l; = \ prof->next =3D (s)->profile_head.elem_q; = \ (s)->profile_head.elem_q =3D prof; = \ } while( 0 ) --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400885; cv=none; d=zohomail.com; s=zohoarc; b=H+fwpPVUh26IHLV37fZppFvwLUtwftRgBf9uRuUmuAmG2pNw9kjGWzu6yFxW+hOYwEPN1kESgqjbaz8PdXsF03ZhsnrgePxFaJXO4B30Agz/X4R/+F3Wp0H7jEqlXYUJChK2CYQAHZzlc2O7oHBo57pcXHmSHLyyagzFXvkhTrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400885; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rNOyQPsbL1VDg7jKcqQA3YKjVDmW24LPmpHEEveFp9k=; b=FW/WdLdpXKa8a1FqiIN98jNkCV+WWjyPksqWtdWM1sDljsFH8ubIYCAsr2KWXyZPuDQyt0wtOSzfiPhU8SpRDPRkbufQfvTordYcsU16R5RYyWHMjYIYMdhcHZg/iWQypAp5LuYVn09ZbiM0Xlq69OTXY5ecRauVoezM0KawyuA= 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 1710400885529791.4226031248703; Thu, 14 Mar 2024 00:21:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692902.1080579 (Exim 4.92) (envelope-from ) id 1rkfOp-00081o-L6; Thu, 14 Mar 2024 07:21:11 +0000 Received: by outflank-mailman (output) from mailman id 692902.1080579; Thu, 14 Mar 2024 07:21:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOp-00081A-Hj; Thu, 14 Mar 2024 07:21:11 +0000 Received: by outflank-mailman (input) for mailman id 692902; Thu, 14 Mar 2024 07:21:10 +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 1rkfOo-0005rB-9L for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:10 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6d163f8c-e1d3-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 08:21:08 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AA3C021D08; Thu, 14 Mar 2024 07:21:06 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 351BF13977; Thu, 14 Mar 2024 07:21:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0aSMC2Kl8mVhDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:06 +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: 6d163f8c-e1d3-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400867; 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=rNOyQPsbL1VDg7jKcqQA3YKjVDmW24LPmpHEEveFp9k=; b=lzItKastQ++H1Y9cq6iQBm3AXgqCEJhJCX5+3qAdjdqCspEjCnfcY+qzD5rz7ecsufvA35 ZuKvP5wN5tQ5ckwJT+8dzc5lvF/8/Aac41Cm6FywPAyLPJIVUic05Usnm1kxEXDjtG0cvv 9zHmDlLZNsLDc59G2Sqri33awkN6K5Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400866; 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=rNOyQPsbL1VDg7jKcqQA3YKjVDmW24LPmpHEEveFp9k=; b=k/EY3VtRlUk3A7O4wluCUPmen2sw5VPKWWQpMlTWzmIlJOelZi65U2n+/utO4o6cYcvVn8 PWapTz2U3JBJWArNLrKnz6vfDmoIQ+SAObtRsfv4XHCtOMY/W6q2EoK2bqACaBIUvuc2RD QojCNCYV/+f4Uk0/EcOuLNjzUTG296I= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Tamas K Lengyel , Lukasz Hawrylko , "Daniel P. Smith" , =?UTF-8?q?Mateusz=20M=C3=B3wka?= Subject: [PATCH v5 06/13] xen/spinlock: add explicit non-recursive locking functions Date: Thu, 14 Mar 2024 08:20:22 +0100 Message-Id: <20240314072029.16937-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="k/EY3VtR" X-Spamd-Result: default: False [-1.81 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; URIBL_BLOCKED(0.00)[suse.com:email,suse.com:dkim]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_MED(-2.00)[suse.com:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[99.98%] X-Spam-Score: -1.81 X-Rspamd-Queue-Id: AA3C021D08 X-Spam-Flag: NO X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1710400886754100001 Content-Type: text/plain; charset="utf-8" In 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. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- 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(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index b15a18a494..def939172c 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -105,7 +105,7 @@ void share_xen_page_with_guest(struct page_info *page, = struct domain *d, if ( page_get_owner(page) =3D=3D d ) return; =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); =20 /* * 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); } =20 - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); } =20 int xenmem_add_to_physmap_one( diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index a11c55f921..33a2830d9d 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -212,7 +212,7 @@ void dump_pageframe_info(struct domain *d) { unsigned long total[MASK_EXTR(PGT_type_mask, PGT_type_mask) + 1] = =3D {}; =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { unsigned int index =3D 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); } =20 if ( is_hvm_domain(d) ) p2m_pod_dump_data(d); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); =20 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); } =20 - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); } =20 void update_guest_memory_policy(struct vcpu *v, @@ -2448,10 +2448,10 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask =3D 0; } =20 - 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); =20 PROGRESS(xen): =20 diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 62f5b811bb..b4d125db39 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -482,7 +482,7 @@ void share_xen_page_with_guest(struct page_info *page, = struct domain *d, =20 set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); =20 /* The incremented type count pins as writable or read-only. */ page->u.inuse.type_info =3D @@ -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); } =20 - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); } =20 void make_cr3(struct vcpu *v, mfn_t mfn) @@ -3597,11 +3597,11 @@ long do_mmuext_op( { bool drop_ref; =20 - spin_lock(&pg_owner->page_alloc_lock); + nrspin_lock(&pg_owner->page_alloc_lock); drop_ref =3D (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); =20 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 =3D true; =20 - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); =20 if ( unlikely(drop_dom_ref) ) put_domain(d); diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index f58576c702..da28266ef0 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -740,11 +740,11 @@ static int page_make_private(struct domain *d, struct= page_info *page) if ( !get_page(page, dom_cow) ) return -EINVAL; =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); =20 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 p= age_info *page) expected_type =3D (PGT_shared_page | PGT_validated | PGT_locked | 2); if ( page->u.inuse.type_info !=3D 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 p= age_info *page) if ( domain_adjust_tot_pages(d, 1) =3D=3D 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); =20 put_page(page); =20 diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 65d31e5523..515a8c98a5 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -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_doma= in *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)); } =20 /* diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index ca24cd4a67..6bdff9aee9 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2228,7 +2228,7 @@ void audit_p2m(struct domain *d, =20 /* 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 =3D mfn_x(page_to_mfn(page)); @@ -2280,7 +2280,7 @@ void audit_p2m(struct domain *d, P2M_PRINTK("OK: mfn=3D%#lx, gfn=3D%#lx, p2mfn=3D%#lx\n", mfn, gfn, mfn_x(p2mfn)); } - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); =20 pod_unlock(p2m); p2m_unlock(p2m); diff --git a/xen/arch/x86/tboot.c b/xen/arch/x86/tboot.c index 4c254b4e34..ba0700d2d5 100644 --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -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); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); page_list_for_each(page, &d->page_list) { void *pg =3D __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); =20 if ( is_iommu_enabled(d) && is_vtd ) { diff --git a/xen/common/domctl.c b/xen/common/domctl.c index f5a71ee5f7..cb62b18a9d 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -621,14 +621,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) { uint64_t new_max =3D op->u.max_mem.max_memkb >> (PAGE_SHIFT - 10); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); /* * NB. We removed a check that new_max >=3D current tot_pages; thi= s means * that the domain will now be allowed to "ratchet" down to new_ma= x. In * the meantime, while tot > max, all new allocations are disallow= ed. */ d->max_pages =3D min(new_max, (uint64_t)(typeof(d->max_pages))-1); - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); break; } =20 diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 7708930882..e98e9da520 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2376,7 +2376,7 @@ gnttab_transfer( mfn =3D page_to_mfn(page); } =20 - spin_lock(&e->page_alloc_lock); + nrspin_lock(&e->page_alloc_lock); =20 /* * Check that 'e' will accept the page and has reservation @@ -2387,7 +2387,7 @@ gnttab_transfer( unlikely(domain_tot_pages(e) >=3D e->max_pages) || unlikely(!(e->tot_pages + 1)) ) { - spin_unlock(&e->page_alloc_lock); + nrspin_unlock(&e->page_alloc_lock); =20 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 =3D gnttab_prepare_for_transfer(e, d, gop.ref); =20 /* @@ -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 =3D !domain_adjust_tot_pages(e, -1); - spin_unlock(&e->page_alloc_lock); + nrspin_unlock(&e->page_alloc_lock); =20 if ( okay /* i.e. e->is_dying due to the surrounding if() */ ) gdprintk(XENLOG_INFO, "Transferee d%d is now dying\n", diff --git a/xen/common/memory.c b/xen/common/memory.c index b3b05c2ec0..b4593f5f45 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -770,10 +770,10 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xe= n_memory_exchange_t) arg) (1UL << in_chunk_order)) - (j * (1UL << exch.out.extent_order))); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); drop_dom_ref =3D (dec_count && !domain_adjust_tot_pages(d, -dec_count)); - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); =20 if ( drop_dom_ref ) put_domain(d); diff --git a/xen/common/numa.c b/xen/common/numa.c index 6374ba1721..28a09766fa 100644 --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -719,13 +719,13 @@ static void cf_check dump_numa(unsigned char key) =20 memset(page_num_node, 0, sizeof(page_num_node)); =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); page_list_for_each ( page, &d->page_list ) { i =3D page_to_nid(page); page_num_node[i]++; } - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); =20 for_each_online_node ( i ) printk(" Node %u: %u\n", i, page_num_node[i]); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index b4e0ef3a4c..20238015ed 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -514,7 +514,7 @@ int domain_set_outstanding_pages(struct domain *d, unsi= gned 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); =20 /* pages=3D=3D0 means "unset" the claim. */ @@ -560,7 +560,7 @@ int domain_set_outstanding_pages(struct domain *d, unsi= gned long pages) =20 out: spin_unlock(&heap_lock); - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); return ret; } =20 @@ -2346,7 +2346,7 @@ int assign_pages( int rc =3D 0; unsigned int i; =20 - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); =20 if ( unlikely(d->is_dying) ) { @@ -2428,7 +2428,7 @@ int assign_pages( } =20 out: - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); return rc; } =20 @@ -2907,9 +2907,9 @@ mfn_t acquire_reserved_page(struct domain *d, unsigne= d int memflags) ASSERT_ALLOC_CONTEXT(); =20 /* Acquire a page from reserved page list(resv_page_list). */ - spin_lock(&d->page_alloc_lock); + nrspin_lock(&d->page_alloc_lock); page =3D 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; =20 @@ -2928,9 +2928,9 @@ mfn_t acquire_reserved_page(struct domain *d, unsigne= d 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 diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index ccd5f8cc14..22f50fc617 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -368,9 +368,9 @@ long read_console_ring(struct xen_sysctl_readconsole *o= p) =20 if ( op->clear ) { - spin_lock_irq(&console_lock); + nrspin_lock_irq(&console_lock); conringc =3D p - c > conring_size ? p - conring_size : c; - spin_unlock_irq(&console_lock); + nrspin_unlock_irq(&console_lock); } =20 op->count =3D 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); =20 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); } =20 - 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); =20 /* 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 =3D PAGE_SIZE << order; =20 - spin_lock_irqsave(&console_lock, flags); + nrspin_lock_irqsave(&console_lock, flags); for ( i =3D conringc ; i !=3D conringp; i++ ) ring[i & (opt_conring_size - 1)] =3D conring[i & (conring_size - 1= )]; conring =3D ring; smp_wmb(); /* Allow users of console_force_unlock() to see larger buff= er. */ conring_size =3D opt_conring_size; - spin_unlock_irqrestore(&console_lock, flags); + nrspin_unlock_irqrestore(&console_lock, flags); =20 printk("Allocated console ring of %u KiB.\n", opt_conring_size >> 10); } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 49c5115f52..f912fa968c 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -102,6 +102,9 @@ struct lock_profile_qhead { }; =20 #define LOCK_PROFILE_(lockname) { .name =3D #lockname, .ptr.lock =3D &(loc= kname), } +#define RLOCK_PROFILE_(lockname) { .name =3D #lockname, = \ + .ptr.rlock =3D &(lockname), = \ + .is_rlock =3D true, } #define LOCK_PROFILE_PTR_(name) = \ static struct lock_profile * const lock_profile__##name = \ __used_section(".lockprofile.data") =3D = \ @@ -118,10 +121,10 @@ struct lock_profile_qhead { LOCK_PROFILE_PTR_(l) #define DEFINE_RSPINLOCK(l) = \ rspinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ - static struct lock_profile lock_profile_data__##l =3D LOCK_PROFILE_(l)= ; \ + static struct lock_profile lock_profile_data__##l =3D RLOCK_PROFILE_(l= ); \ LOCK_PROFILE_PTR_(l) =20 -#define spin_lock_init_prof__(s, l, locktype) = \ +#define spin_lock_init_prof__(s, l, lockptr, locktype, isr) = \ do { = \ struct lock_profile *prof; = \ prof =3D xzalloc(struct lock_profile); = \ @@ -134,13 +137,16 @@ struct lock_profile_qhead { break; = \ } = \ prof->name =3D #l; = \ - prof->ptr.lock =3D &(s)->l; = \ + prof->ptr.lockptr =3D &(s)->l; = \ + prof->is_rlock =3D isr; = \ prof->next =3D (s)->profile_head.elem_q; = \ (s)->profile_head.elem_q =3D prof; = \ } while( 0 ) =20 -#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) =20 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 fo= rm * part of a recursively-nested set must be protected by these forms. If t= here * 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 c= pu. */ 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) =20 +#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__ */ --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400888; cv=none; d=zohomail.com; s=zohoarc; b=HWU6E9hiWeaGQy2QXc8GOBokzrpVt9d2Owud2V6Tondfmw5s50sN/qrMMghkj/sR+RlWY9RC7XQzXbGnEOSUxVyokjmhAmb9M4bsE3zH6X1na42KxTVQSwK6g2Q8tRxqAOTq54M+fYBXWo9lzNig+5xoheMW2tRXt+E2rrDeBOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400888; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=azHliw2rnZkSZFAFqf4pqY8Nf/40zwEm0vTijoAtrF8=; b=T23JHX8nzGGBiPqHcWj3fPCimjUm4PaMY+UY1LTDuC36bPG7JEV5uinffRpd+6cfVCHLt5GFAqtYVEJb4kupbxmSWM9zfLZ4F2viUPYCjEtfICam8tJcAmeqodifsFUOiOnhmYsuc+SnywZJbAl1xgMPqCeyUvl28L7hTg/cV/U= 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 1710400888082703.7280264677704; Thu, 14 Mar 2024 00:21:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692905.1080589 (Exim 4.92) (envelope-from ) id 1rkfOt-0008SW-3I; Thu, 14 Mar 2024 07:21:15 +0000 Received: by outflank-mailman (output) from mailman id 692905.1080589; Thu, 14 Mar 2024 07:21:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOs-0008Rv-VK; Thu, 14 Mar 2024 07:21:14 +0000 Received: by outflank-mailman (input) for mailman id 692905; Thu, 14 Mar 2024 07:21:13 +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 1rkfOr-0005cd-F2 for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:13 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [2a07:de40:b251:101:10:150:64:2]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6fd588df-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:21:12 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5FE081F801; Thu, 14 Mar 2024 07:21:12 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1D26F13977; Thu, 14 Mar 2024 07:21:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id B1msBWil8mVpDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:12 +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: 6fd588df-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400872; 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=azHliw2rnZkSZFAFqf4pqY8Nf/40zwEm0vTijoAtrF8=; b=bLfXCDM6/ugPfJHYGhkYNXmUNuQhqN1fcoBqGpRZQtiRDa7Qcrm1cUWlwtidOlh+4z5QF5 JJ4JEdduNM51KUNlqVzr/lVwdlkI6qEfUDeNWCT959WduonddW/9MYoMjs4OWY8TPH7gF+ qiP1lfVxD0me8cAG9LY3+SimxaYny8A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400872; 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=azHliw2rnZkSZFAFqf4pqY8Nf/40zwEm0vTijoAtrF8=; b=bLfXCDM6/ugPfJHYGhkYNXmUNuQhqN1fcoBqGpRZQtiRDa7Qcrm1cUWlwtidOlh+4z5QF5 JJ4JEdduNM51KUNlqVzr/lVwdlkI6qEfUDeNWCT959WduonddW/9MYoMjs4OWY8TPH7gF+ qiP1lfVxD0me8cAG9LY3+SimxaYny8A= 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 v5 07/13] xen/spinlock: add another function level Date: Thu, 14 Mar 2024 08:20:23 +0100 Message-Id: <20240314072029.16937-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: * Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; URIBL_BLOCKED(0.00)[suse.com:email]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400888692100003 Content-Type: text/plain; charset="utf-8" Add 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. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- 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(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 0e8b525cec..648393d95f 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -261,29 +261,31 @@ void spin_debug_disable(void) =20 #ifdef CONFIG_DEBUG_LOCK_PROFILE =20 +#define LOCK_PROFILE_PAR lock->profile #define LOCK_PROFILE_REL = \ - if ( lock->profile ) = \ + if ( profile ) = \ { = \ - lock->profile->time_hold +=3D NOW() - lock->profile->time_locked; = \ - lock->profile->lock_cnt++; = \ + profile->time_hold +=3D NOW() - profile->time_locked; = \ + profile->lock_cnt++; = \ } #define LOCK_PROFILE_VAR(var, val) s_time_t var =3D (val) #define LOCK_PROFILE_BLOCK(var) var =3D var ? : NOW() #define LOCK_PROFILE_BLKACC(tst, val) = \ if ( tst ) = \ { = \ - lock->profile->time_block +=3D lock->profile->time_locked - (val);= \ - lock->profile->block_cnt++; = \ + profile->time_block +=3D profile->time_locked - (val); = \ + profile->block_cnt++; = \ } #define LOCK_PROFILE_GOT(val) = \ - if ( lock->profile ) = \ + if ( profile ) = \ { = \ - lock->profile->time_locked =3D NOW(); = \ + profile->time_locked =3D NOW(); = \ LOCK_PROFILE_BLKACC(val, val); = \ } =20 #else =20 +#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 spin= lock_tickets_t *t) return read_atomic(&t->head); } =20 -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 *d= ata) { spinlock_tickets_t tickets =3D SPINLOCK_TICKET_INC; LOCK_PROFILE_VAR(block, 0); =20 - check_lock(&lock->debug, false); + check_lock(debug, false); 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) ) + tickets.head_tail =3D arch_fetch_and_add(&t->head_tail, tickets.head_t= ail); + while ( tickets.tail !=3D 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); } =20 void _spin_lock(spinlock_t *lock) { - spin_lock_common(lock, NULL, NULL); + spin_lock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR, NULL, + NULL); } =20 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, d= ata); } =20 void _spin_lock_irq(spinlock_t *lock) @@ -355,16 +359,23 @@ unsigned long _spin_lock_irqsave(spinlock_t *lock) return flags; } =20 -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(); } =20 +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, unsigne= d long flags) local_irq_restore(flags); } =20 +static bool always_inline spin_is_locked_common(const spinlock_tickets_t *= t) +{ + return t->head !=3D 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 =3D=3D SPINLOCK_NO_CPU - ? lock->tickets.head !=3D lock->tickets.tail + ? spin_is_locked_common(&lock->tickets) : lock->recurse_cpu =3D=3D smp_processor_id(); } =20 -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; =20 preempt_disable(); - check_lock(&lock->debug, true); - old =3D observe_lock(&lock->tickets); + check_lock(debug, true); + old =3D observe_lock(t); if ( old.head !=3D old.tail ) { preempt_enable(); - return 0; + return false; } new =3D old; new.tail++; - if ( cmpxchg(&lock->tickets.head_tail, - old.head_tail, new.head_tail) !=3D old.head_tail ) + if ( cmpxchg(&t->head_tail, old.head_tail, new.head_tail) !=3D old.hea= d_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); =20 - return 1; + return true; } =20 -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()); =20 - check_barrier(&lock->debug); + check_barrier(debug); smp_mb(); - sample =3D observe_lock(&lock->tickets); + sample =3D observe_lock(t); if ( sample.head !=3D sample.tail ) { - while ( observe_head(&lock->tickets) =3D=3D sample.head ) + while ( observe_head(t) =3D=3D sample.head ) arch_lock_relax(); - LOCK_PROFILE_BLKACC(lock->profile, block); + LOCK_PROFILE_BLKACC(profile, block); } smp_mb(); } =20 +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 =3D smp_processor_id(); @@ -448,7 +477,8 @@ bool _rspin_trylock(rspinlock_t *lock) =20 if ( likely(lock->recurse_cpu !=3D cpu) ) { - if ( !_spin_trylock(lock) ) + if ( !spin_trylock_common(&lock->tickets, &lock->debug, + LOCK_PROFILE_PAR) ) return false; lock->recurse_cpu =3D cpu; } @@ -466,7 +496,8 @@ void _rspin_lock(rspinlock_t *lock) =20 if ( likely(lock->recurse_cpu !=3D cpu) ) { - _spin_lock(lock); + spin_lock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR, N= ULL, + NULL); lock->recurse_cpu =3D cpu; } =20 @@ -490,7 +521,7 @@ void _rspin_unlock(rspinlock_t *lock) if ( likely(--lock->recurse_cnt =3D=3D 0) ) { lock->recurse_cpu =3D SPINLOCK_NO_CPU; - _spin_unlock(lock); + spin_unlock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR); } } =20 diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index f912fa968c..5b20b11db6 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -165,6 +165,7 @@ extern void cf_check spinlock_profile_reset(unsigned ch= ar key); #else =20 struct lock_profile_qhead { }; +struct lock_profile { }; =20 #define SPIN_LOCK_UNLOCKED { = \ .recurse_cpu =3D SPINLOCK_NO_CPU, = \ --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400893; cv=none; d=zohomail.com; s=zohoarc; b=l7lPyRTlExdFh5FsXUC3mes0budiftxDKTjAuZuV1eZ+jO7tvaM1OjVivj2MU72W3vaboJ0RqINwyjz5zixQ3DyXnR3nW7IA+bo/UdMfZIPDh3AXkfwfkc2/BSx5fPIAtWkyi0voMU3byFN7i2GKde//BpKIH7o0vk0iDxPWSaM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400893; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RyZIS9vv4iGwmrp5sN5jilaqDKgUnxECEpqJeS43geA=; b=XzjMI7SVZQmW+OgEUhb+A+H/CWf+mTUvzHpH9BnKqQjt4SqoMfgexn9NpD06VpWsNVLXueFqW1Q7mxDhe7gavehzKGjvglRvGsH3arYJ/yopLu118ADTXO+6rmwUDPZdPVOIJA111AW/yBHdlDO/sdskIW8Rk9RtCt8mFBwx3ec= 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 1710400893000935.6101290243646; Thu, 14 Mar 2024 00:21:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692906.1080599 (Exim 4.92) (envelope-from ) id 1rkfOz-0000WL-CK; Thu, 14 Mar 2024 07:21:21 +0000 Received: by outflank-mailman (output) from mailman id 692906.1080599; Thu, 14 Mar 2024 07:21:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfOz-0000WC-8O; Thu, 14 Mar 2024 07:21:21 +0000 Received: by outflank-mailman (input) for mailman id 692906; Thu, 14 Mar 2024 07:21:20 +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 1rkfOy-0005rB-8A for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:20 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 734e3892-e1d3-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 08:21:18 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2476C21CCF; Thu, 14 Mar 2024 07:21:18 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C8A2913977; Thu, 14 Mar 2024 07:21:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2JR4L22l8mVvDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:17 +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: 734e3892-e1d3-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400878; 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=RyZIS9vv4iGwmrp5sN5jilaqDKgUnxECEpqJeS43geA=; b=eFNSh6Vj+J1kybS3kei57Vr1fHut95++7ADIWA23bgHGVVPcmsc3eYzRgBgOWZwWiCUhSQ 28fMMQh3jvUeQY/iUoS5SP5KvHaUfpE4wW1n7fYR/zlSBkfSGqjN66hY5/Q5tLB0SINp3A C9nV+ap17jwMvMWmZ6lEDuIrkZbBgMQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400878; 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=RyZIS9vv4iGwmrp5sN5jilaqDKgUnxECEpqJeS43geA=; b=eFNSh6Vj+J1kybS3kei57Vr1fHut95++7ADIWA23bgHGVVPcmsc3eYzRgBgOWZwWiCUhSQ 28fMMQh3jvUeQY/iUoS5SP5KvHaUfpE4wW1n7fYR/zlSBkfSGqjN66hY5/Q5tLB0SINp3A C9nV+ap17jwMvMWmZ6lEDuIrkZbBgMQ= 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 , Paul Durrant Subject: [PATCH v5 08/13] xen/spinlock: add missing rspin_is_locked() and rspin_barrier() Date: Thu, 14 Mar 2024 08:20:24 +0100 Message-Id: <20240314072029.16937-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=eFNSh6Vj X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_MED(-2.00)[suse.com:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -3.01 X-Rspamd-Queue-Id: 2476C21CCF X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400894694100001 Content-Type: text/plain; charset="utf-8" Add rspin_is_locked() and rspin_barrier() in order to prepare differing spinlock_t and rspinlock_t types. Signed-off-by: Juergen Gross --- 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(-) diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 515a8c98a5..ae5dcb1870 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -374,7 +374,7 @@ int p2m_pod_empty_cache(struct domain *d) =20 /* 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); =20 lock_page_alloc(p2m); =20 diff --git a/xen/common/domain.c b/xen/common/domain.c index 8e0109c590..2d7c69e6d2 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -983,7 +983,7 @@ int domain_kill(struct domain *d) case DOMDYING_alive: domain_pause(d); d->is_dying =3D 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); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 20238015ed..83d1715e25 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -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; =20 - ASSERT(spin_is_locked(&d->page_alloc_lock)); + ASSERT(rspin_is_locked(&d->page_alloc_lock)); d->tot_pages +=3D pages; =20 /* diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 648393d95f..c3f2f9b209 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -395,14 +395,7 @@ static bool always_inline spin_is_locked_common(const = spinlock_tickets_t *t) =20 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 =3D=3D SPINLOCK_NO_CPU - ? spin_is_locked_common(&lock->tickets) - : lock->recurse_cpu =3D=3D smp_processor_id(); + return spin_is_locked_common(&lock->tickets); } =20 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); } =20 +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 =3D=3D SPINLOCK_NO_CPU + ? spin_is_locked_common(&lock->tickets) + : lock->recurse_cpu =3D=3D 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 =3D smp_processor_id(); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 22f50fc617..d5e6aacc27 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -327,7 +327,7 @@ static void cf_check do_dec_thresh(unsigned char key, b= ool unused) =20 static void conring_puts(const char *str, size_t len) { - ASSERT(spin_is_locked(&console_lock)); + ASSERT(rspin_is_locked(&console_lock)); =20 while ( len-- ) conring[CONRING_IDX_MASK(conringp++)] =3D *str++; @@ -765,7 +765,7 @@ static void __putstr(const char *str) { size_t len =3D strlen(str); =20 - ASSERT(spin_is_locked(&console_lock)); + ASSERT(rspin_is_locked(&console_lock)); =20 console_serial_puts(str, len); video_puts(str, len); diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 4fcc7e2cde..5a446d3dce 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -65,7 +65,7 @@ void pcidevs_unlock(void) =20 bool pcidevs_locked(void) { - return !!spin_is_locked(&_pcidevs_lock); + return rspin_is_locked(&_pcidevs_lock); } =20 static struct radix_tree_root pci_segments; diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 5b20b11db6..7dd11faab3 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -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); =20 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) =20 #define nrspin_trylock(l) spin_trylock(l) #define nrspin_lock(l) spin_lock(l) --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710401551; cv=none; d=zohomail.com; s=zohoarc; b=Bc2fAqx4N2eeKYaSYIMzJw32+Pye/lHZpGCHUGgHLKOxUnoUYuU+oZFs9sSOLGOiUzFCAgYAW6I+XFYAagawhFWla0q0L5rHxdw9fIwkZcR4YMafgwkoc8FKm3li1fvJJn9LGsvkWOv9ckOARv0SzI6mP26QcbZcKeeRbLYMq6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710401551; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=19/vfjk9VoFmZDJkVOwl2hl/O+FfTEfUdeHMhW/BgRM=; b=HEwp9LtW7rCRs74J7GJMv/dsQ59fqCHVjvOaTFDB532RLltM3UrxOc/Bhphr658mzwGuD/AEe3XNf2gOTP9IKK0M4Kw3Y7nNX+0qZOfOEXmXA06wXGzSj++0dGB34Nb38pmLZjruIIx49ALiahVxJvRaLofAbfO9ImsZ2mQhAGg= 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 1710401551337240.2207688816028; Thu, 14 Mar 2024 00:32:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692931.1080660 (Exim 4.92) (envelope-from ) id 1rkfZW-0006PM-H7; Thu, 14 Mar 2024 07:32:14 +0000 Received: by outflank-mailman (output) from mailman id 692931.1080660; Thu, 14 Mar 2024 07:32:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfZW-0006PD-Cp; Thu, 14 Mar 2024 07:32:14 +0000 Received: by outflank-mailman (input) for mailman id 692931; Thu, 14 Mar 2024 07:32:13 +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 1rkfP3-0005cd-1V for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:25 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 76a7a4a1-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:21:24 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C880A1F801; Thu, 14 Mar 2024 07:21:23 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8724C13977; Thu, 14 Mar 2024 07:21:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id vU2WH3Ol8mVzDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:23 +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: 76a7a4a1-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400883; 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=19/vfjk9VoFmZDJkVOwl2hl/O+FfTEfUdeHMhW/BgRM=; b=QXh4cxQRBmzMmecuhxANgyiBTHg1HsMWZR2Je574rEAJVNbvXDDeTAHlwEnKOk4O/bPC8m sYZpeRECDXox8+UgmzyvnPBOkz7I27JjMPLCieAotX7ffHhJzIZ7wBaSuyXeHfZEs66smf TPkhsY2T5ScwttZUsL7kAxsm3Xnu6RY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400883; 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=19/vfjk9VoFmZDJkVOwl2hl/O+FfTEfUdeHMhW/BgRM=; b=QXh4cxQRBmzMmecuhxANgyiBTHg1HsMWZR2Je574rEAJVNbvXDDeTAHlwEnKOk4O/bPC8m sYZpeRECDXox8+UgmzyvnPBOkz7I27JjMPLCieAotX7ffHhJzIZ7wBaSuyXeHfZEs66smf TPkhsY2T5ScwttZUsL7kAxsm3Xnu6RY= 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 v5 09/13] xen/spinlock: split recursive spinlocks from normal ones Date: Thu, 14 Mar 2024 08:20:25 +0100 Message-Id: <20240314072029.16937-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: * Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710401552697100001 Content-Type: text/plain; charset="utf-8" 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) 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. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- 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(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index c3f2f9b209..a88ad9b93c 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -541,6 +541,56 @@ void _rspin_unlock_irqrestore(rspinlock_t *lock, unsig= ned long flags) local_irq_restore(flags); } =20 +bool _nrspin_trylock(rspinlock_t *lock) +{ + check_lock(&lock->debug, true); + + if ( unlikely(lock->recurse_cpu !=3D 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 =20 struct lock_profile_anc { diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 7dd11faab3..181e5c7d35 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -77,8 +77,6 @@ union lock_debug { }; */ =20 struct spinlock; -/* Temporary hack until a dedicated struct rspinlock is existing. */ -#define rspinlock spinlock =20 struct lock_profile { struct lock_profile *next; /* forward link */ @@ -110,6 +108,10 @@ struct lock_profile_qhead { __used_section(".lockprofile.data") =3D = \ &lock_profile_data__##name #define SPIN_LOCK_UNLOCKED_(x) { = \ + .debug =3D LOCK_DEBUG_, = \ + .profile =3D x, = \ +} +#define RSPIN_LOCK_UNLOCKED_(x) { = \ .recurse_cpu =3D SPINLOCK_NO_CPU, = \ .debug =3D LOCK_DEBUG_, = \ .profile =3D x, = \ @@ -119,8 +121,9 @@ struct lock_profile_qhead { spinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ static struct lock_profile lock_profile_data__##l =3D LOCK_PROFILE_(l)= ; \ LOCK_PROFILE_PTR_(l) +#define RSPIN_LOCK_UNLOCKED RSPIN_LOCK_UNLOCKED_(NULL) #define DEFINE_RSPINLOCK(l) = \ - rspinlock_t l =3D SPIN_LOCK_UNLOCKED_(NULL); = \ + rspinlock_t l =3D RSPIN_LOCK_UNLOCKED_(NULL); = \ static struct lock_profile lock_profile_data__##l =3D RLOCK_PROFILE_(l= ); \ LOCK_PROFILE_PTR_(l) =20 @@ -145,8 +148,11 @@ struct lock_profile_qhead { =20 #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) +#define rspin_lock_init_prof(s, l) do { = \ + spin_lock_init_prof__(s, l, rlock, rspinlock_t, true); = \ + (s)->l.recurse_cpu =3D SPINLOCK_NO_CPU; = \ + (s)->l.recurse_cnt =3D 0; = \ + } while (0) =20 void _lock_profile_register_struct( int32_t type, struct lock_profile_qhead *qhead, int32_t idx); @@ -168,11 +174,14 @@ struct lock_profile_qhead { }; struct lock_profile { }; =20 #define SPIN_LOCK_UNLOCKED { = \ + .debug =3D LOCK_DEBUG_, = \ +} +#define RSPIN_LOCK_UNLOCKED { = \ .recurse_cpu =3D SPINLOCK_NO_CPU, = \ .debug =3D LOCK_DEBUG_, = \ } #define DEFINE_SPINLOCK(l) spinlock_t l =3D SPIN_LOCK_UNLOCKED -#define DEFINE_RSPINLOCK(l) rspinlock_t l =3D SPIN_LOCK_UNLOCKED +#define DEFINE_RSPINLOCK(l) rspinlock_t l =3D RSPIN_LOCK_UNLOCKED =20 #define spin_lock_init_prof(s, l) spin_lock_init(&((s)->l)) #define rspin_lock_init_prof(s, l) rspin_lock_init(&((s)->l)) @@ -193,6 +202,14 @@ typedef union { #define SPINLOCK_TICKET_INC { .head_tail =3D 0x10000, } =20 typedef struct spinlock { + spinlock_tickets_t tickets; + union lock_debug debug; +#ifdef CONFIG_DEBUG_LOCK_PROFILE + struct lock_profile *profile; +#endif +} spinlock_t; + +typedef struct rspinlock { spinlock_tickets_t tickets; uint16_t recurse_cpu:SPINLOCK_CPU_BITS; #define SPINLOCK_NO_CPU ((1u << SPINLOCK_CPU_BITS) - 1) @@ -203,12 +220,10 @@ typedef struct spinlock { #ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile *profile; #endif -} spinlock_t; - -typedef spinlock_t rspinlock_t; +} rspinlock_t; =20 #define spin_lock_init(l) (*(l) =3D (spinlock_t)SPIN_LOCK_UNLOCKED) -#define rspin_lock_init(l) (*(l) =3D (rspinlock_t)SPIN_LOCK_UNLOCKED) +#define rspin_lock_init(l) (*(l) =3D (rspinlock_t)RSPIN_LOCK_UNLOCKED) =20 void _spin_lock(spinlock_t *lock); void _spin_lock_cb(spinlock_t *lock, void (*cb)(void *data), void *data); @@ -312,12 +327,35 @@ static always_inline void rspin_lock(rspinlock_t *loc= k) #define rspin_barrier(l) _rspin_barrier(l) #define rspin_is_locked(l) _rspin_is_locked(l) =20 -#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) +bool _nrspin_trylock(rspinlock_t *lock); +void _nrspin_lock(rspinlock_t *lock); +#define nrspin_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) !=3D sizeof(unsigned long)); \ + (f) =3D _nrspin_lock_irqsave(l); \ + block_lock_speculation(); \ + }) +unsigned long _nrspin_lock_irqsave(rspinlock_t *lock); +void _nrspin_unlock(rspinlock_t *lock); +void _nrspin_lock_irq(rspinlock_t *lock); +void _nrspin_unlock_irq(rspinlock_t *lock); +void _nrspin_unlock_irqrestore(rspinlock_t *lock, unsigned long flags); + +static always_inline void nrspin_lock(rspinlock_t *lock) +{ + _nrspin_lock(lock); + block_lock_speculation(); +} + +static always_inline void nrspin_lock_irq(rspinlock_t *l) +{ + _nrspin_lock_irq(l); + block_lock_speculation(); +} + +#define nrspin_trylock(l) lock_evaluate_nospec(_nrspin_tryloc= k(l)) +#define nrspin_unlock(l) _nrspin_unlock(l) +#define nrspin_unlock_irqrestore(l, f) _nrspin_unlock_irqrestore(l, f) +#define nrspin_unlock_irq(l) _nrspin_unlock_irq(l) =20 #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710401562; cv=none; d=zohomail.com; s=zohoarc; b=RNRdF2p4jzRmjlkWM8+TxzMMKIiwF+TshKdaaZm0a79GnhamLzFaAHK969+2v1ZSqaHb2f+WxVCuz5RHNMYG87rkWZR5fGy7w3y3C1N+MaZort2W1vpKbEHr8jNPN+98augyPLx4uUydu38hru7UuTICyEn/zYCz0DCO+KmBbQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710401562; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lmSzZbPq+fuy/WPTZvVH6l4HYZ5NaZICGCs9qLuY+8E=; b=bnSUtxzvipVb8R9LNHioFN+7/B2T8UPJMvTm/JvJCwZBIi/aTI5Nef7kG2OBtfFw83ZEamg2/DZ45FfeSDnrUKYqrAbx9x9WKd6SV0w/g77uYYiHDh/r/leUqDTnmlrd3UVqkx6bgAK/66lm98e60I7Is6qamERESLQNu0xuCfw= 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 1710401562927924.1363084903026; Thu, 14 Mar 2024 00:32:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692937.1080680 (Exim 4.92) (envelope-from ) id 1rkfZh-00078o-4F; Thu, 14 Mar 2024 07:32:25 +0000 Received: by outflank-mailman (output) from mailman id 692937.1080680; Thu, 14 Mar 2024 07:32:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfZg-00078f-VT; Thu, 14 Mar 2024 07:32:24 +0000 Received: by outflank-mailman (input) for mailman id 692937; Thu, 14 Mar 2024 07:32:23 +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 1rkfP8-0005cd-IZ for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:30 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7a07dfa7-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:21:29 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7881E21CCF; Thu, 14 Mar 2024 07:21:29 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2C5B413977; Thu, 14 Mar 2024 07:21:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id pRJvCXml8mV4DgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:29 +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: 7a07dfa7-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400889; 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=lmSzZbPq+fuy/WPTZvVH6l4HYZ5NaZICGCs9qLuY+8E=; b=QtyrVSiL8myusCEnPXafNPhTR2V+wduG3G6xGsJX/oqnOWhS+maITNelnRsSaBaFjqi6bC M73SkcYctb9Vd+z0bT3jeNCpUEVs3K4x5b/GkYNsoFIG1MFztH1ux88W166noW6hNbXGmC JfnKCIfnn/XLqxSdbs+sEikhsZUAiBg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400889; 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=lmSzZbPq+fuy/WPTZvVH6l4HYZ5NaZICGCs9qLuY+8E=; b=QtyrVSiL8myusCEnPXafNPhTR2V+wduG3G6xGsJX/oqnOWhS+maITNelnRsSaBaFjqi6bC M73SkcYctb9Vd+z0bT3jeNCpUEVs3K4x5b/GkYNsoFIG1MFztH1ux88W166noW6hNbXGmC JfnKCIfnn/XLqxSdbs+sEikhsZUAiBg= 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 v5 10/13] xen/spinlock: let all is_locked and trylock variants return bool Date: Thu, 14 Mar 2024 08:20:26 +0100 Message-Id: <20240314072029.16937-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: + Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=QtyrVSiL X-Spamd-Result: default: False [1.19 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; RCVD_DKIM_ARC_DNSWL_HI(-1.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; DWL_DNSWL_MED(-2.00)[suse.com:dkim]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_IN_DNSWL_HI(-0.50)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[28.51%] X-Spam-Score: 1.19 X-Spam-Level: * X-Rspamd-Queue-Id: 7881E21CCF X-Spam-Flag: NO X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710401564586100001 Content-Type: text/plain; charset="utf-8" Switch the remaining trylock and is_locked variants to return bool. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V5: - new patch (Jan Beulich) --- xen/common/spinlock.c | 4 ++-- xen/include/xen/spinlock.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index a88ad9b93c..b28239f74d 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -393,7 +393,7 @@ static bool always_inline spin_is_locked_common(const s= pinlock_tickets_t *t) return t->head !=3D t->tail; } =20 -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; } =20 -int _spin_trylock(spinlock_t *lock) +bool _spin_trylock(spinlock_t *lock) { return spin_trylock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_= PAR); } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 181e5c7d35..1b50a7e6a0 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -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); =20 -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); =20 static always_inline void spin_lock(spinlock_t *l) --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710400912; cv=none; d=zohomail.com; s=zohoarc; b=fctMHcqeN2wLQk3E0iljXwX3h8s6enxS1h4o1Kvz0YcmAtLz5RxuZhduyv4YG4zdJvXn3rAav0I2zjZ0IeGrNGuNnwIwpOw5AUFYJNdFX6XOb1Q/rSjAz5f7bQVuAT5B9Vd2GKouuSQk8CEeR/2sWFgMZvRTYNeUNdj9q9q9fMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710400912; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lVUg9sUvshZn0hcfy+zcEBYHChto2sM8ej1C5kH/2gA=; b=VRLFqFhGcS7ZlzW41+TlhLs8q4SfG+PIdGAxHtJsD0/R8X5x7wkQe0xkzXXvSaQorr1tHc8i2BSNyk/WsgZR9i9sIPHr29WKRm1giRsyi0qhRzCz1Tx8zHcSVc58zEXxiovqt2nH0iTN0chX8kg0tIN0PX98EJcvNEGqFvY1PUY= 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 1710400912054182.67036820727924; Thu, 14 Mar 2024 00:21:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692910.1080609 (Exim 4.92) (envelope-from ) id 1rkfPG-0001VV-JI; Thu, 14 Mar 2024 07:21:38 +0000 Received: by outflank-mailman (output) from mailman id 692910.1080609; Thu, 14 Mar 2024 07:21:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfPG-0001VO-GF; Thu, 14 Mar 2024 07:21:38 +0000 Received: by outflank-mailman (input) for mailman id 692910; Thu, 14 Mar 2024 07:21:37 +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 1rkfPF-0005rB-08 for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:37 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7d5675c0-e1d3-11ee-a1ee-f123f15fe8a2; Thu, 14 Mar 2024 08:21:35 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 101F41F79B; Thu, 14 Mar 2024 07:21:35 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C38D513977; Thu, 14 Mar 2024 07:21:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id L25ELn6l8mV/DgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:34 +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: 7d5675c0-e1d3-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400895; 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=lVUg9sUvshZn0hcfy+zcEBYHChto2sM8ej1C5kH/2gA=; b=bCTeyhrUUqc9JD5BDVIVsaj3drWovyp3NBzB06q9GTGxzwLgDmX2VQaefJXGE/31hJSHo4 poM0XP+Ato6d3pg2Tn6TFGmEEYiO5fewWFNDLf5jkjfaiublYF5jZ89DSzqrU9ynQAkyY/ kDVyy2aKqlzsey9cnGYU0o0T1QkP/rQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400895; 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=lVUg9sUvshZn0hcfy+zcEBYHChto2sM8ej1C5kH/2gA=; b=bCTeyhrUUqc9JD5BDVIVsaj3drWovyp3NBzB06q9GTGxzwLgDmX2VQaefJXGE/31hJSHo4 poM0XP+Ato6d3pg2Tn6TFGmEEYiO5fewWFNDLf5jkjfaiublYF5jZ89DSzqrU9ynQAkyY/ kDVyy2aKqlzsey9cnGYU0o0T1QkP/rQ= 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 v5 11/13] xen/spinlock: support higher number of cpus Date: Thu, 14 Mar 2024 08:20:27 +0100 Message-Id: <20240314072029.16937-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: * Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710400912743100001 Content-Type: text/plain; charset="utf-8" Allow 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. Signed-off-by: Juergen Gross --- 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(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index b28239f74d..5be48be082 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -481,7 +481,9 @@ bool _rspin_trylock(rspinlock_t *lock) =20 /* 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= )); =20 check_lock(&lock->debug, true); =20 diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 1b50a7e6a0..984da6d4c9 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -8,16 +8,16 @@ #include #include =20 -#define SPINLOCK_CPU_BITS 12 +#define SPINLOCK_CPU_BITS 16 =20 #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 { =20 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; --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710401540; cv=none; d=zohomail.com; s=zohoarc; b=jtQAXJlE7e5L/pUtWd3ej8DAx7EBhnB4rILLy7WdzvJn3MYZVNlfiDFasqgoOZBW87u4zUbziq2dCr20sGj4EX7o2GpyyxwqwInQBJvdw0/a3aqPrbuL0f7+zOTAkFJlhEy4+SHmx3+2PyfvHFQb/NfciPNvDChzR3Q1EtN1314= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710401540; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DBLksahmXlvC7yfjAllNqgbhTHyvKKzQktudFgw2Foo=; b=EPux4m7KNxlyupL522xqLGh+988XuvZjPmAyE9UnGbvz0IfyfEuPqF3aD5YZkO8844rTHmU5h9kqW1HcYvNnNNYGhhYM6wt87avLIRZeTR5cG3qn6fhiy3bcUA6xMcli/ncOgFf0s1SGUelg7pna3TSKdwzExmC+kfxWhQ5HMxE= 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 1710401540233351.02744435843397; Thu, 14 Mar 2024 00:32:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692930.1080648 (Exim 4.92) (envelope-from ) id 1rkfZK-00065b-8H; Thu, 14 Mar 2024 07:32:02 +0000 Received: by outflank-mailman (output) from mailman id 692930.1080648; Thu, 14 Mar 2024 07:32:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfZK-00065U-5l; Thu, 14 Mar 2024 07:32:02 +0000 Received: by outflank-mailman (input) for mailman id 692930; Thu, 14 Mar 2024 07:32:01 +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 1rkfPJ-0005cd-Of for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:41 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 80bf598c-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:21:41 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B808D21CF1; Thu, 14 Mar 2024 07:21:40 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 74A4713977; Thu, 14 Mar 2024 07:21:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id rPftGoSl8mWSDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:40 +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: 80bf598c-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400900; 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=DBLksahmXlvC7yfjAllNqgbhTHyvKKzQktudFgw2Foo=; b=kWqNAVP3JS7sjxQkIwZt1BroxwjcH64mEb2qLaXG2yWdT6SUyShr2k5C0fhULY5SHAQyDL 27e/Xl3xDpcLXVIrGcioT/W5GthopOOYd4IdRNewui2wM30Wj2Myq6U4SoVxMJF3EjnC04 gqSbGmQ78luNfFIUgkKVSfgwsiKz4Gw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400900; 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=DBLksahmXlvC7yfjAllNqgbhTHyvKKzQktudFgw2Foo=; b=kWqNAVP3JS7sjxQkIwZt1BroxwjcH64mEb2qLaXG2yWdT6SUyShr2k5C0fhULY5SHAQyDL 27e/Xl3xDpcLXVIrGcioT/W5GthopOOYd4IdRNewui2wM30Wj2Myq6U4SoVxMJF3EjnC04 gqSbGmQ78luNfFIUgkKVSfgwsiKz4Gw= 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 v5 12/13] xen/rwlock: raise the number of possible cpus Date: Thu, 14 Mar 2024 08:20:28 +0100 Message-Id: <20240314072029.16937-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: **** Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [4.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; URIBL_BLOCKED(0.00)[suse.com:email]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 4.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710401540574100001 Content-Type: text/plain; charset="utf-8" The 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. Signed-off-by: Juergen Gross --- V5: - new patch --- xen/include/xen/rwlock.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/xen/include/xen/rwlock.h b/xen/include/xen/rwlock.h index 65d88b0ef4..afd57659bd 100644 --- a/xen/include/xen/rwlock.h +++ b/xen/include/xen/rwlock.h @@ -23,12 +23,12 @@ typedef struct { #define rwlock_init(l) (*(l) =3D (rwlock_t)RW_LOCK_UNLOCKED) =20 /* 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) =20 void queue_read_lock_slowpath(rwlock_t *lock); @@ -36,14 +36,16 @@ void queue_write_lock_slowpath(rwlock_t *lock); =20 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) =3D=3D _QW_LOCKED && (cnts & _QW_CPUMASK) =3D=3D smp_processor_id(); } =20 static inline bool _can_read_lock(unsigned int cnts) { - return !(cnts & _QW_WMASK) || _is_write_locked_by_me(cnts); + return cnts <=3D INT_MAX && + (!(cnts & _QW_WMASK) || _is_write_locked_by_me(cnts)); } =20 /* --=20 2.35.3 From nobody Wed May 22 02:03:31 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=1710401340; cv=none; d=zohomail.com; s=zohoarc; b=Ne2myp/bfcO7GeZ+KCVisPTQ2Cr+gKehT7eoJixbBwXSvL2wXo8qI0guFr0WY7gZl4DmhdWQbB3WdiBepzDqCLks2Y6/7j6SPbwGuWhvheavZ/8hGKGIqcWaF/7dobMTOB4hl2zFp2QcltDDscuCzsnqj7Le7BxOxq2lhrLgsyQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710401340; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=svDhVGjKFzIPpcWjFYARn/2rWUfeidU+xfRiYlSjnX4=; b=I8JbgVY2jVAYZkT1Tiul1QyH/dp+/DF4iFRik7bO7mnh+bDvg+tw7OcVW6sMQUth6C8VFVFu4ERwrb1ID9Gns3rCKp/CP4SISZrSqKW1AkThvjlZ9VgNeMB7yTtxwrMSArPlqjPkljrdaAlJ+dFp3TcrYhucqpgM/GDBCGppDoQ= 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 1710401340949125.46939044690862; Thu, 14 Mar 2024 00:29:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692919.1080638 (Exim 4.92) (envelope-from ) id 1rkfWC-0003qV-QR; Thu, 14 Mar 2024 07:28:48 +0000 Received: by outflank-mailman (output) from mailman id 692919.1080638; Thu, 14 Mar 2024 07:28:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkfWC-0003qO-Nv; Thu, 14 Mar 2024 07:28:48 +0000 Received: by outflank-mailman (input) for mailman id 692919; Thu, 14 Mar 2024 07:28:48 +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 1rkfPP-0005cd-8l for xen-devel@lists.xenproject.org; Thu, 14 Mar 2024 07:21:47 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 84170f40-e1d3-11ee-afdd-a90da7624cb6; Thu, 14 Mar 2024 08:21:46 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 623A91F79B; Thu, 14 Mar 2024 07:21:46 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1F2EE13977; Thu, 14 Mar 2024 07:21:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6SIlBoql8mWXDgAAD6G6ig (envelope-from ); Thu, 14 Mar 2024 07:21:46 +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: 84170f40-e1d3-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400906; 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=svDhVGjKFzIPpcWjFYARn/2rWUfeidU+xfRiYlSjnX4=; b=EkBnLKOBMPSiT+mLfvH5diIs5oNZa3ZYrVL2mqE0YS3a3slf6xVaQ1xNZbcKaPWCXxlsId saQdPEEfqZF0QIsteoa/J3SfuX2vLdA99ZEWn4uun0ngYCOJjlesSCZY3akhpEmeiPfPqf CBS9SfE5xRbTmX3zGkjFY4/M9SIZ0JY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1710400906; 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=svDhVGjKFzIPpcWjFYARn/2rWUfeidU+xfRiYlSjnX4=; b=EkBnLKOBMPSiT+mLfvH5diIs5oNZa3ZYrVL2mqE0YS3a3slf6xVaQ1xNZbcKaPWCXxlsId saQdPEEfqZF0QIsteoa/J3SfuX2vLdA99ZEWn4uun0ngYCOJjlesSCZY3akhpEmeiPfPqf CBS9SfE5xRbTmX3zGkjFY4/M9SIZ0JY= 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 v5 13/13] xen: allow up to 16383 cpus Date: Thu, 14 Mar 2024 08:20:29 +0100 Message-Id: <20240314072029.16937-14-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240314072029.16937-1-jgross@suse.com> References: <20240314072029.16937-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: **** Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [4.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; URIBL_BLOCKED(0.00)[suse.com:email]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 4.90 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1710401342114100001 Content-Type: text/plain; charset="utf-8" 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_ENTRIES and QINVAL_MAX_ENTRY_NR required to be larger than 2 * CONFIG_NR_CPUS. Signed-off-by: Juergen Gross --- V5: - new patch (Jan Beulich) --- xen/arch/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index 67ba38f32f..308ce129a8 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -6,7 +6,7 @@ config PHYS_ADDR_T_32 =20 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 --=20 2.35.3