From nobody Sun May 19 07:16:25 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=1702374470; cv=none; d=zohomail.com; s=zohoarc; b=l2/0vILeR7GfZKf0L8AIDLZW6bIjqFlB8dcrYEnQsR0gxvKhx7t54EOEACcJMU3MpGbYBwRp8q4T2llJYGLpKx1FUuNvWR9lY9zQdsinjrGfV2Yi2jjIfo1fBVYkMsJnrb2FHpUNbDLLg1ScIIF8f57J/bepYnQ7gmU3XJ5+gFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374470; 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=05RrYMir4dujTWuikdK7at9dlF2CXR4dNylFaQEqncE=; b=m5gn68gCoSks+Jv/b2rezMekyU7zPtPBREL+r7ccJeM81o3L46NaVynOsA/IFY5Z9F4KM/5BxtMzzBRpWZ+/gxExRQ3wSZ4wldt5FWwWiSWFSzl6bmR0puXIBa1F4QA+ofAKGm83fLm89BwEMvSfuP5FoPVOYSQV8YJCcGPbcOY= 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 1702374470586560.2969713330571; Tue, 12 Dec 2023 01:47:50 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652844.1018897 (Exim 4.92) (envelope-from ) id 1rCzMX-0006zJ-PN; Tue, 12 Dec 2023 09:47:37 +0000 Received: by outflank-mailman (output) from mailman id 652844.1018897; Tue, 12 Dec 2023 09:47:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzMX-0006zC-Mj; Tue, 12 Dec 2023 09:47:37 +0000 Received: by outflank-mailman (input) for mailman id 652844; Tue, 12 Dec 2023 09:47:36 +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 1rCzMW-0006i7-2M for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:47:36 +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 79a74d82-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:47:34 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 DA0CD224B1; Tue, 12 Dec 2023 09:47:33 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 9B9D7139E9; Tue, 12 Dec 2023 09:47:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id T+u/JDUseGWqfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:47:33 +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: 79a74d82-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374454; 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=05RrYMir4dujTWuikdK7at9dlF2CXR4dNylFaQEqncE=; b=Z/Oh8sjoUCM+8LRc8Dz3gUmr/TTBPaIRau3PfRqWgYATUg++NkN3Hhe9fo7EYWgnDpgCiZ 3bdmEwcJDALmZGPLgk5OdZhwHfFm61MpBkwSE/j5C4skVytVKBNBbY0qVtWou4Hud8JBDS 4rnbwgL+Kr+pJPA0xlR4NL9+DCscMDA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374453; 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=05RrYMir4dujTWuikdK7at9dlF2CXR4dNylFaQEqncE=; b=Z5evBUhm1k8ym4FmZnajKtUQVssPQvL1NyssaSen+JthhgCQX4chO4KU+jZ2RsgZkvP4Qe t8p96/3q00v6+/12nkUgHZGNB6rEGQGkk5sETYrn8cCLyaEC4Pb7vhqpKvNkkaQb1oEOFB VI0JGhwLTMcYXtezGYrx53qKCIfUiCc= 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 Subject: [PATCH v4 01/12] xen/spinlock: reduce lock profile ifdefs Date: Tue, 12 Dec 2023 10:47:14 +0100 Message-Id: <20231212094725.22184-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 3.70 X-Spam-Flag: NO X-Spam-Level: **** X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [4.90 / 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]; RCPT_COUNT_SEVEN(0.00)[9]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 4.90 X-ZohoMail-DKIM: pass (identity @suse.com) (identity @suse.com) X-ZM-MESSAGEID: 1702374472277100003 Content-Type: text/plain; charset="utf-8" With some small adjustments to the LOCK_PROFILE_* macros some #ifdefs can be dropped from spinlock.c. Signed-off-by: Juergen Gross Reviewed-by: Alejandro Vallejo Acked-by: Julien Grall --- V2: - new patch V3: - add variable name to macros parameter (Jan Beulich) V4: - fix coding style issue (Alejandro Vallejo) --- xen/common/spinlock.c | 49 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index d5fa400b78..09028af864 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -267,25 +267,28 @@ void spin_debug_disable(void) lock->profile->time_hold +=3D NOW() - lock->profile->time_locked; = \ lock->profile->lock_cnt++; = \ } -#define LOCK_PROFILE_VAR s_time_t block =3D 0 -#define LOCK_PROFILE_BLOCK block =3D block ? : NOW(); -#define LOCK_PROFILE_GOT = \ +#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++; = \ + } +#define LOCK_PROFILE_GOT(val) = \ if ( lock->profile ) = \ { = \ lock->profile->time_locked =3D NOW(); = \ - if ( block ) = \ - { = \ - lock->profile->time_block +=3D lock->profile->time_locked - bl= ock; \ - lock->profile->block_cnt++; = \ - } = \ + LOCK_PROFILE_BLKACC(val, val); = \ } =20 #else =20 #define LOCK_PROFILE_REL -#define LOCK_PROFILE_VAR -#define LOCK_PROFILE_BLOCK -#define LOCK_PROFILE_GOT +#define LOCK_PROFILE_VAR(var, val) +#define LOCK_PROFILE_BLOCK(var) +#define LOCK_PROFILE_BLKACC(tst, val) +#define LOCK_PROFILE_GOT(val) =20 #endif =20 @@ -308,7 +311,7 @@ static void always_inline spin_lock_common(spinlock_t *= lock, void (*cb)(void *data), void *d= ata) { spinlock_tickets_t tickets =3D SPINLOCK_TICKET_INC; - LOCK_PROFILE_VAR; + LOCK_PROFILE_VAR(block, 0); =20 check_lock(&lock->debug, false); preempt_disable(); @@ -316,14 +319,14 @@ static void always_inline spin_lock_common(spinlock_t= *lock, tickets.head_tail); while ( tickets.tail !=3D observe_head(&lock->tickets) ) { - LOCK_PROFILE_BLOCK; + LOCK_PROFILE_BLOCK(block); if ( cb ) cb(data); arch_lock_relax(); } arch_lock_acquire_barrier(); got_lock(&lock->debug); - LOCK_PROFILE_GOT; + LOCK_PROFILE_GOT(block); } =20 void _spin_lock(spinlock_t *lock) @@ -411,19 +414,15 @@ int _spin_trylock(spinlock_t *lock) * arch_lock_acquire_barrier(). */ got_lock(&lock->debug); -#ifdef CONFIG_DEBUG_LOCK_PROFILE - if ( lock->profile ) - lock->profile->time_locked =3D NOW(); -#endif + LOCK_PROFILE_GOT(0); + return 1; } =20 void _spin_barrier(spinlock_t *lock) { spinlock_tickets_t sample; -#ifdef CONFIG_DEBUG_LOCK_PROFILE - s_time_t block =3D NOW(); -#endif + LOCK_PROFILE_VAR(block, NOW()); =20 check_barrier(&lock->debug); smp_mb(); @@ -432,13 +431,7 @@ void _spin_barrier(spinlock_t *lock) { while ( observe_head(&lock->tickets) =3D=3D sample.head ) arch_lock_relax(); -#ifdef CONFIG_DEBUG_LOCK_PROFILE - if ( lock->profile ) - { - lock->profile->time_block +=3D NOW() - block; - lock->profile->block_cnt++; - } -#endif + LOCK_PROFILE_BLKACC(lock->profile, block); } smp_mb(); } --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374479; cv=none; d=zohomail.com; s=zohoarc; b=SXEQR//W8wfg9hmqe6TVEGoiN8x9Rjiak3YsmROx8LazkHMLWHoOKjHJZStu592iSIDr79pXnNqgq+CPbA5T9Qi7Gobx8DFd/UZco8WHeNag1zo2oQoJaUM++IvjKikiGe1nbbHA30psjKzpLAFs0vCqKaON9/4TzrpeoV8FzXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374479; 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=doNpwSeReZ+USBSQcgU+UndKZ1tREobYqeEPZw9GeWA=; b=QYtbUenC4jTxPyidBNfJIIYCoB1rRygB2n5X9McphsNHwOTh36TA23m98CWHdoV17noB8XRzlS+vBE5HG5pO6F5Rpc4HVW0pvk1gREdgLNBudZ7tfCJLTwGAWxFM8Ye0XSOiIOmkpiGNtyz2mzywxJHmCelsc7LR7p8ecVWMfzI= 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 1702374479577977.134993370404; Tue, 12 Dec 2023 01:47:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652845.1018907 (Exim 4.92) (envelope-from ) id 1rCzMd-0007J2-1t; Tue, 12 Dec 2023 09:47:43 +0000 Received: by outflank-mailman (output) from mailman id 652845.1018907; Tue, 12 Dec 2023 09:47:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzMc-0007It-V8; Tue, 12 Dec 2023 09:47:42 +0000 Received: by outflank-mailman (input) for mailman id 652845; Tue, 12 Dec 2023 09:47:40 +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 1rCzMa-0007Gv-U7 for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:47:40 +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 7d061412-98d3-11ee-98e8-6d05b1d4d9a1; Tue, 12 Dec 2023 10:47:40 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 74EE5224B7; Tue, 12 Dec 2023 09:47:39 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 3BE6E139E9; Tue, 12 Dec 2023 09:47:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id C59eDTsseGWwfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:47:39 +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: 7d061412-98d3-11ee-98e8-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374459; 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=doNpwSeReZ+USBSQcgU+UndKZ1tREobYqeEPZw9GeWA=; b=PNX5+Ub7qOIAHZAg3mwdjS51i1StvDwvNPx66nLRRjnlMAGV71xGdpFBAKLUegx2yVcQMO 6PzMf9HqRheNMcxewW2D7KE6S6J701EC31h19BB0/BcKzGvHcfGc5CJtqrGMTc5xO+g8lR bh4UzrnJmW+Cw3F7rDsZjxT5XWIa3gg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374459; 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=doNpwSeReZ+USBSQcgU+UndKZ1tREobYqeEPZw9GeWA=; b=PNX5+Ub7qOIAHZAg3mwdjS51i1StvDwvNPx66nLRRjnlMAGV71xGdpFBAKLUegx2yVcQMO 6PzMf9HqRheNMcxewW2D7KE6S6J701EC31h19BB0/BcKzGvHcfGc5CJtqrGMTc5xO+g8lR bh4UzrnJmW+Cw3F7rDsZjxT5XWIa3gg= 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 v4 02/12] xen/spinlock: make spinlock initializers more readable Date: Tue, 12 Dec 2023 10:47:15 +0100 Message-Id: <20231212094725.22184-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: *************** X-Spam-Flag: YES X-Spam-Score: 15.00 X-Spam-Level: X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [-0.81 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 74EE5224B7 X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=PNX5+Ub7; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out1.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Spamd-Bar: / X-Spam-Score: -0.81 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374480681100001 Content-Type: text/plain; charset="utf-8" Use named member initializers instead of positional ones for the macros used to initialize structures. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- V2: - new patch --- xen/include/xen/spinlock.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index c44e7d4929..1cd9120eac 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -21,7 +21,7 @@ union lock_debug { bool unseen:1; }; }; -#define _LOCK_DEBUG { 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); @@ -94,12 +94,16 @@ struct lock_profile_qhead { int32_t idx; /* index for printout */ }; =20 -#define _LOCK_PROFILE(name) { NULL, #name, &name, 0, 0, 0, 0, 0 } +#define _LOCK_PROFILE(lockname) { .name =3D #lockname, .lock =3D &lockname= , } #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) { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG, x= } +#define _SPIN_LOCK_UNLOCKED(x) { = \ + .recurse_cpu =3D SPINLOCK_NO_CPU, = \ + .debug =3D_LOCK_DEBUG, = \ + .profile =3D x, = \ +} #define SPIN_LOCK_UNLOCKED _SPIN_LOCK_UNLOCKED(NULL) #define DEFINE_SPINLOCK(l) = \ spinlock_t l =3D _SPIN_LOCK_UNLOCKED(NULL); = \ @@ -142,7 +146,10 @@ extern void cf_check spinlock_profile_reset(unsigned c= har key); =20 struct lock_profile_qhead { }; =20 -#define SPIN_LOCK_UNLOCKED { { 0 }, SPINLOCK_NO_CPU, 0, _LOCK_DEBUG } +#define SPIN_LOCK_UNLOCKED { = \ + .recurse_cpu =3D SPINLOCK_NO_CPU, = \ + .debug =3D_LOCK_DEBUG, = \ +} #define DEFINE_SPINLOCK(l) spinlock_t l =3D SPIN_LOCK_UNLOCKED =20 #define spin_lock_init_prof(s, l) spin_lock_init(&((s)->l)) --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374483; cv=none; d=zohomail.com; s=zohoarc; b=czALnZK4AvsdUi0FuSq23C8QtWh4ML+EZaW84EkFngYw5PN+pSKtKg69v1VGoqhybgI9NjP0ioeA6bzMiVChGRdS9PvngXN8jMTNsvGenbnV8J9Z9MUDD07mIDNBQ8HhUmYbAiw0tni4I30KgYID9k60Tdx07C6CcRm7TaGLNSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374483; 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=88B7I1n8s6sxOU5LedyrvvowvYQQmSv/h/8w0LslwMs=; b=HpVELNr4x+svZSzOS8nTkwNIRdk67iqWCbMJ33+yD81jDLDd7bws7H7a2qjAOvO/mXfVjL8RX+Gjcr5vluORteWjPJ08RQpfL1FvC8RT5OoSav1pghe+if4nIq4Km3JxvbbmEhjUzxJuqttGBRtEGrE2xYhOV1m4wSGfnR9aW2E= 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 1702374483197525.2769420309662; Tue, 12 Dec 2023 01:48:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652846.1018917 (Exim 4.92) (envelope-from ) id 1rCzMi-0007fC-Dw; Tue, 12 Dec 2023 09:47:48 +0000 Received: by outflank-mailman (output) from mailman id 652846.1018917; Tue, 12 Dec 2023 09:47: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 1rCzMi-0007es-AA; Tue, 12 Dec 2023 09:47:48 +0000 Received: by outflank-mailman (input) for mailman id 652846; Tue, 12 Dec 2023 09:47:47 +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 1rCzMh-0006i7-AG for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:47:47 +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 8044bd86-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:47:45 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 1551D224B1; Tue, 12 Dec 2023 09:47:45 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id C6023139E9; Tue, 12 Dec 2023 09:47:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 3fssL0AseGW6fgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:47:44 +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: 8044bd86-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374465; 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=88B7I1n8s6sxOU5LedyrvvowvYQQmSv/h/8w0LslwMs=; b=TbpSLwIc4crKkQi6n4Ieom6HjlLzThLBD+jPsECSsjt1E49fSLLQBFFhskOREKkm9QsNaR rcaLYvS4/s1u/rIV0Cv2Jdu2aH/cA44zfU9FSu/ggawZ5VO2Jb12bRdpb4464W2SWjy/wD 8tZ8jofRPM+7pkjG/si/ETQrQdyZyu4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374465; 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=88B7I1n8s6sxOU5LedyrvvowvYQQmSv/h/8w0LslwMs=; b=TbpSLwIc4crKkQi6n4Ieom6HjlLzThLBD+jPsECSsjt1E49fSLLQBFFhskOREKkm9QsNaR rcaLYvS4/s1u/rIV0Cv2Jdu2aH/cA44zfU9FSu/ggawZ5VO2Jb12bRdpb4464W2SWjy/wD 8tZ8jofRPM+7pkjG/si/ETQrQdyZyu4= 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 Subject: [PATCH v4 03/12] xen/spinlock: introduce new type for recursive spinlocks Date: Tue, 12 Dec 2023 10:47:16 +0100 Message-Id: <20231212094725.22184-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Flag: NO X-Spam-Score: 10.00 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[10]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374484518100001 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 --- V2: - carved out from V1 patch --- 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 05dfe35502..8a6e0c283f 100644 --- a/xen/arch/x86/include/asm/mm.h +++ b/xen/arch/x86/include/asm/mm.h @@ -596,7 +596,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 00b1bc402d..b05cad1752 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 c5954cdb1a..dc97755391 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 0666564ec9..76e455bacd 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -120,7 +120,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. @@ -1178,7 +1178,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 28ed8ea817..d604ed5634 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 void pcidevs_lock(void) { diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 3609ef88c4..c6604aef78 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= ) */ @@ -597,7 +597,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 1cd9120eac..20d15f34dd 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -45,7 +45,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 @@ -56,7 +56,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 @@ -109,12 +109,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 = \ @@ -128,6 +132,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, @@ -151,8 +158,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) @@ -182,8 +191,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 Sun May 19 07:16:25 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=1702374490; cv=none; d=zohomail.com; s=zohoarc; b=mMhH68HiwQYeRLdFKKX6tNIJ5bF6NVRlM5EgPqOStSDVDHZGqfZo8yp3NC4FLoTtz1w9K5SFLQFD1SoiOTGzE55AQOjxZslgdXb9Ua8Gqbycl67NRUbJ3tGiWI9sOxIYjBS87uaFfo/e1PK6AsEGtB1LcnetzwyXoWIaCep75kE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374490; 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=fdRSEytmHvGpI/Z2j7dS5CoHPsmRTFiZAI41T9Vl7PE=; b=dW62t2z1ZVsgy6qc/K58sKWkpp+stMqUfhKXwVx3Ri30MVfIapJQcgOUE4NJLv5sN9OdqP/sPa8GTwCx2Tc3tZWFbBmAD2PLbmK3O6yrTRlS+qCV8UqqF45ZEgGzpV2MyfLQRo1qxryAsn19qeyjAzBFC+wuunH5VWt/0xj4KyA= 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 1702374490200356.26833263064395; Tue, 12 Dec 2023 01:48:10 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652849.1018927 (Exim 4.92) (envelope-from ) id 1rCzMn-00084s-Nn; Tue, 12 Dec 2023 09:47:53 +0000 Received: by outflank-mailman (output) from mailman id 652849.1018927; Tue, 12 Dec 2023 09:47:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzMn-00084j-Jq; Tue, 12 Dec 2023 09:47:53 +0000 Received: by outflank-mailman (input) for mailman id 652849; Tue, 12 Dec 2023 09:47:52 +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 1rCzMm-0007Gv-Cs for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:47:52 +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 83b929aa-98d3-11ee-98e8-6d05b1d4d9a1; Tue, 12 Dec 2023 10:47:51 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 C9D441F74C; Tue, 12 Dec 2023 09:47:50 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 68C57139E9; Tue, 12 Dec 2023 09:47:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id F6JoGEYseGXEfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:47:50 +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: 83b929aa-98d3-11ee-98e8-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374470; 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=fdRSEytmHvGpI/Z2j7dS5CoHPsmRTFiZAI41T9Vl7PE=; b=n/D7lrSIoQ++/5E4gz1W0B59W5XN1BfQcTyh2y1yo4XpVhdzYxEnreJPIA0FgqiOs3iiuU S+GxJpD56enSeKua3cujj/ttc4m+zCB0dypwvFGphoCEmEad1tLNllmwnM14W730kD1FY0 H/I3AtDLyjSORra1rbg4zcGe1CGcJYI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374470; 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=fdRSEytmHvGpI/Z2j7dS5CoHPsmRTFiZAI41T9Vl7PE=; b=n/D7lrSIoQ++/5E4gz1W0B59W5XN1BfQcTyh2y1yo4XpVhdzYxEnreJPIA0FgqiOs3iiuU S+GxJpD56enSeKua3cujj/ttc4m+zCB0dypwvFGphoCEmEad1tLNllmwnM14W730kD1FY0 H/I3AtDLyjSORra1rbg4zcGe1CGcJYI= 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 Subject: [PATCH v4 04/12] xen/spinlock: rename recursive lock functions Date: Tue, 12 Dec 2023 10:47:17 +0100 Message-Id: <20231212094725.22184-5-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 18.90 X-Spam-Flag: YES X-Spam-Level: ******* X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [7.29 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; RCPT_COUNT_TWELVE(0.00)[14]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: C9D441F74C X-Spam-Flag: NO Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="n/D7lrSI"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out2.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Spamd-Bar: +++++++ X-Spam-Score: 7.29 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374490693100001 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. Remove the indirection through a macro, as it is adding only complexity without any gain. Suggested-by: Jan Beulich Signed-off-by: Juergen Gross Acked-by: Jan Beulich Acked-by: Julien Grall --- V2: - new patch --- 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 | 6 ++-- xen/drivers/char/console.c | 12 ++++---- xen/drivers/passthrough/pci.c | 4 +-- xen/include/xen/sched.h | 4 +-- xen/include/xen/spinlock.h | 24 +++++++--------- 11 files changed, 67 insertions(+), 71 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 3712e36df9..69ce1fd5cf 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1321,7 +1321,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; ; ) { @@ -1342,7 +1342,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; @@ -2181,7 +2181,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)) ) { @@ -2322,7 +2322,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 4f810706a3..1720079fd9 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -688,7 +688,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 ) { @@ -731,7 +731,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); @@ -1942,7 +1942,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; @@ -1971,7 +1971,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 b05cad1752..c867ad7d53 100644 --- a/xen/arch/x86/mm/mm-locks.h +++ b/xen/arch/x86/mm/mm-locks.h @@ -79,7 +79,7 @@ static inline void _mm_lock(const struct domain *d, mm_lo= ck_t *l, { if ( !((mm_locked_by_me(l)) && rec) ) _check_lock_level(d, level); - spin_lock_recursive(&l->lock); + rspin_lock(&l->lock); if ( l->lock.recurse_cnt =3D=3D 1 ) { l->locker_function =3D func; @@ -200,7 +200,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 9b5df74fdd..8c6a3d9274 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -2497,7 +2497,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]); @@ -2505,7 +2505,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 { @@ -2514,7 +2514,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++ ) { @@ -2537,7 +2537,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, @@ -2753,7 +2753,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 @@ -2764,7 +2764,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..422a7fb1db 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) +int rspin_trylock(rspinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); =20 @@ -460,7 +460,7 @@ int _spin_trylock_recursive(spinlock_t *lock) return 1; } =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 76e455bacd..f6f61dc5a1 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -920,7 +920,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); @@ -956,7 +956,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 @@ -1163,14 +1163,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 @@ -1231,12 +1231,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 d604ed5634..41444f8e2e 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -54,12 +54,12 @@ static DEFINE_RSPINLOCK(_pcidevs_lock); =20 void pcidevs_lock(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 c6604aef78..8cf751ad0c 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 20d15f34dd..ee536c302c 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -209,9 +209,16 @@ 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); +/* + * 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(). + */ +int rspin_trylock(rspinlock_t *lock); +void rspin_lock(rspinlock_t *lock); +void rspin_unlock(rspinlock_t *lock); =20 #define spin_lock(l) _spin_lock(l) #define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) @@ -241,15 +248,4 @@ void _spin_unlock_recursive(spinlock_t *lock); /* Ensure a lock is quiescent between two critical operations. */ #define spin_barrier(l) _spin_barrier(l) =20 -/* - * spin_[un]lock_recursive(): 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) _spin_trylock_recursive(l) -#define spin_lock_recursive(l) _spin_lock_recursive(l) -#define spin_unlock_recursive(l) _spin_unlock_recursive(l) - #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374493; cv=none; d=zohomail.com; s=zohoarc; b=AAzXE2mkRlDXtiqu61+2+ufn/lW6Z/lT6WZYK/gex0NEeYrZ4osL79ywik1+x44wTBPOvY7or/IKrwU69oVobJ7/9JZSnrqZK629OVwDBxS95SND39T8eMTB1iwS/XZ/BxEdJ4yIFDMC66LJ4UVOIkTtJL+1AZMFFtuQnYPpNKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374493; 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=GvkQ+1+sIR2iv06NXkv6xKF/IP+0QdiM6YcayZ0slMo=; b=MfgaZA8cKlm5buo3E+7qm65BLFmDF5gMgEAAKasIdQgjIgmj3zA1LzN4HuGGZ9RmhC7SzEbPsfGmiZU094KKrLH4pgo/KlmSPhALzCRw+w0ZVVGMZmrjM9PvItT7FbItUsIgUBsIjZD9GQaddadVJVLV8leA2tTAlyiINXv76tk= 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 1702374493796114.16349880142752; Tue, 12 Dec 2023 01:48:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652850.1018937 (Exim 4.92) (envelope-from ) id 1rCzMu-0000FC-4j; Tue, 12 Dec 2023 09:48:00 +0000 Received: by outflank-mailman (output) from mailman id 652850.1018937; Tue, 12 Dec 2023 09:48:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzMu-0000F5-1e; Tue, 12 Dec 2023 09:48:00 +0000 Received: by outflank-mailman (input) for mailman id 652850; Tue, 12 Dec 2023 09:47:58 +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 1rCzMs-0006i7-HX for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:47:58 +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 87085716-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:47:56 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 61B1E224B1; Tue, 12 Dec 2023 09:47:56 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 23376139E9; Tue, 12 Dec 2023 09:47:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id /fxYB0wseGXQfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:47:56 +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: 87085716-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374476; 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=GvkQ+1+sIR2iv06NXkv6xKF/IP+0QdiM6YcayZ0slMo=; b=nVwSG+sNZUZIocD1eWzm7CMBxEElSnhxaVyrV7Y2bz/5OfUJdegD2HkVhXBsQT8r5jtbUl 93TS1a9n6qg7Qk1htapA0uaRQaFeVfTBps5x4VzbMApTw8AExrhWJvk0XpTPHPgD0ndE6J /6aw1YiRtcthPl4s39ZAgTtQxFU7mmw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374476; 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=GvkQ+1+sIR2iv06NXkv6xKF/IP+0QdiM6YcayZ0slMo=; b=nVwSG+sNZUZIocD1eWzm7CMBxEElSnhxaVyrV7Y2bz/5OfUJdegD2HkVhXBsQT8r5jtbUl 93TS1a9n6qg7Qk1htapA0uaRQaFeVfTBps5x4VzbMApTw8AExrhWJvk0XpTPHPgD0ndE6J /6aw1YiRtcthPl4s39ZAgTtQxFU7mmw= 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 Subject: [PATCH v4 05/12] xen/spinlock: add rspin_[un]lock_irq[save|restore]() Date: Tue, 12 Dec 2023 10:47:18 +0100 Message-Id: <20231212094725.22184-6-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 18.90 X-Spam-Flag: YES X-Spam-Level: ******* X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [7.29 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; 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)[9]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 61B1E224B1 X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=nVwSG+sN; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out1.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Spamd-Bar: +++++++ X-Spam-Score: 7.29 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374494823100001 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 --- V2: - new patch --- xen/arch/x86/traps.c | 14 ++++++++------ xen/common/spinlock.c | 16 ++++++++++++++++ xen/drivers/char/console.c | 18 +----------------- xen/include/xen/console.h | 5 +++-- xen/include/xen/spinlock.h | 7 +++++++ 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 7724306116..21227877b3 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -647,13 +647,15 @@ void show_stack_overflow(unsigned int cpu, const stru= ct cpu_user_regs *regs) void show_execution_state(const struct cpu_user_regs *regs) { /* Prevent interleaving of output. */ - unsigned long flags =3D console_lock_recursive_irqsave(); + unsigned long flags; + + rspin_lock_irqsave(&console_lock, flags); =20 show_registers(regs); show_code(regs); show_stack(regs); =20 - console_unlock_recursive_irqrestore(flags); + rspin_unlock_irqrestore(&console_lock, flags); } =20 void cf_check show_execution_state_nonconst(struct cpu_user_regs *regs) @@ -663,7 +665,7 @@ void cf_check show_execution_state_nonconst(struct cpu_= user_regs *regs) =20 void vcpu_show_execution_state(struct vcpu *v) { - unsigned long flags =3D 0; + unsigned long flags; =20 if ( test_bit(_VPF_down, &v->pause_flags) ) { @@ -698,7 +700,7 @@ void vcpu_show_execution_state(struct vcpu *v) #endif =20 /* Prevent interleaving of output. */ - flags =3D console_lock_recursive_irqsave(); + rspin_lock_irqsave(&console_lock, flags); =20 vcpu_show_registers(v); =20 @@ -708,7 +710,7 @@ void vcpu_show_execution_state(struct vcpu *v) * Stop interleaving prevention: The necessary P2M lookups involve * locking, which has to occur with IRQs enabled. */ - console_unlock_recursive_irqrestore(flags); + rspin_unlock_irqrestore(&console_lock, flags); =20 show_hvm_stack(v, &v->arch.user_regs); } @@ -717,7 +719,7 @@ void vcpu_show_execution_state(struct vcpu *v) if ( guest_kernel_mode(v, &v->arch.user_regs) ) show_guest_stack(v, &v->arch.user_regs); =20 - console_unlock_recursive_irqrestore(flags); + rspin_unlock_irqrestore(&console_lock, flags); } =20 #ifdef CONFIG_HVM diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 422a7fb1db..c1a9ba1304 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -475,6 +475,16 @@ 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) ) @@ -484,6 +494,12 @@ void rspin_unlock(rspinlock_t *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 f6f61dc5a1..1db2bbdb6a 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -120,7 +120,7 @@ static int __read_mostly sercon_handle =3D -1; int8_t __read_mostly opt_console_xen; /* console=3Dxen */ #endif =20 -static DEFINE_RSPINLOCK(console_lock); +DEFINE_RSPINLOCK(console_lock); =20 /* * To control the amount of printing, thresholds are added. @@ -1158,22 +1158,6 @@ void console_end_log_everything(void) atomic_dec(&print_everything); } =20 -unsigned long console_lock_recursive_irqsave(void) -{ - unsigned long flags; - - local_irq_save(flags); - rspin_lock(&console_lock); - - return flags; -} - -void console_unlock_recursive_irqrestore(unsigned long flags) -{ - rspin_unlock(&console_lock); - local_irq_restore(flags); -} - void console_force_unlock(void) { watchdog_disable(); diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 68759862e8..583c38f064 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -8,8 +8,11 @@ #define __CONSOLE_H__ =20 #include +#include #include =20 +extern rspinlock_t console_lock; + struct xen_sysctl_readconsole; long read_console_ring(struct xen_sysctl_readconsole *op); =20 @@ -20,8 +23,6 @@ void console_init_postirq(void); void console_endboot(void); int console_has(const char *device); =20 -unsigned long console_lock_recursive_irqsave(void); -void console_unlock_recursive_irqrestore(unsigned long flags); void console_force_unlock(void); =20 void console_start_sync(void); diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index ee536c302c..05b97c1e03 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -218,7 +218,14 @@ void _spin_barrier(spinlock_t *lock); */ int 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)); \ + }) +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 #define spin_lock(l) _spin_lock(l) #define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374502; cv=none; d=zohomail.com; s=zohoarc; b=ATow+DxL7KCovnx+wPq9+Vx2bhYAjdJPmjyddUqJ8L50IYfIrQHW7vSbFTybh653JkUXooMPEz5LSqo8z3xTrmV/Ob2btv1pDNn72pPrmm2eB+9mBpj5+9qhOsAZCNhnPSHtrQSnuS4YJCgMi1itzS24sX6cX1QLNwyjKBUkpwU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374502; 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=ImgxXwya7OlVCWVkU9MisuGH03hg4qJ0KBDJY6FOy/8=; b=Wrj2A8B/jXd392av55kgprvJTApR9/KrygSB7m9LIay/x27fAH9/SDqE9QbuVn68dXUCDsvL/DbADrVyroOwNMR107bZjF8f9aN3iOzvHu7yGN1VSfsboEITnrqhFRRdjYV8E+q3NY6JFVRLAChdIm6zK80xXRD97M7zneqmM50= 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 1702374502254699.6004987214354; Tue, 12 Dec 2023 01:48:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652854.1018946 (Exim 4.92) (envelope-from ) id 1rCzMz-0000lk-Es; Tue, 12 Dec 2023 09:48:05 +0000 Received: by outflank-mailman (output) from mailman id 652854.1018946; Tue, 12 Dec 2023 09:48:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzMz-0000lX-Ar; Tue, 12 Dec 2023 09:48:05 +0000 Received: by outflank-mailman (input) for mailman id 652854; Tue, 12 Dec 2023 09:48:04 +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 1rCzMx-0006i7-VO for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:03 +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 8a5709ba-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:48:02 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 F229E1F74C; Tue, 12 Dec 2023 09:48:01 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B58C8139E9; Tue, 12 Dec 2023 09:48:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id DcYlK1EseGXSfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:01 +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: 8a5709ba-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374482; 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=ImgxXwya7OlVCWVkU9MisuGH03hg4qJ0KBDJY6FOy/8=; b=egqNoIMtSq3uUlnt7OwPH2OSCEPrReq3lJDG0WY8H8IIlp3ftCWMOwz5zGGQK7qUUz2Wg/ e5ZlVA1M/bd8vHbQRuM7vKgxOcVpwwo4nt33c7fyvU78uIppYm1WfEQj3SBmXnVKBqQxde KR9cvPuPUQiZGDDEuOldP7QE6bOnNUg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374482; 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=ImgxXwya7OlVCWVkU9MisuGH03hg4qJ0KBDJY6FOy/8=; b=egqNoIMtSq3uUlnt7OwPH2OSCEPrReq3lJDG0WY8H8IIlp3ftCWMOwz5zGGQK7qUUz2Wg/ e5ZlVA1M/bd8vHbQRuM7vKgxOcVpwwo4nt33c7fyvU78uIppYm1WfEQj3SBmXnVKBqQxde KR9cvPuPUQiZGDDEuOldP7QE6bOnNUg= 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 Subject: [PATCH v4 06/12] xen/spinlock: make struct lock_profile rspinlock_t aware Date: Tue, 12 Dec 2023 10:47:19 +0100 Message-Id: <20231212094725.22184-7-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 8.80 X-Spam-Flag: NO Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[99.99%]; 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)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374502979100001 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. Signed-off-by: Juergen Gross Acked-by: Alejandro Vallejo Acked-by: Julien Grall --- V2: - new patch --- xen/common/spinlock.c | 26 +++++++++++++++++++------- xen/include/xen/spinlock.h | 10 ++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index c1a9ba1304..7d611d3d7d 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; + uint32_t lockval; + + if ( data->is_rlock ) + { + cpu =3D data->rlock->debug.cpu; + lockval =3D data->rlock->tickets.head_tail; + } + else + { + cpu =3D data->lock->debug.cpu; + lockval =3D data->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->lock, lock= val); + 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) diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 05b97c1e03..ac3bef267a 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -76,13 +76,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 */ + }; 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 */ + uint64_t 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 */ --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374512; cv=none; d=zohomail.com; s=zohoarc; b=VgsZ/Vkghec4sf7OlOsRj1mrGxZaGwRKrrfjMnI6mBl50PwnKAm6VqazoS+Gt5ebqzZXsn2CUcncttxbsZLs6CYeEgiQRvELtfSfbfFLKuM1zoX8JWPInwSTnjcAa7ptV8M/y9/Mx0LLqembStaDqiQXDCwCF3ZaHuIWQl7odxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374512; 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=fuJajbW3/YYf0ZwXbPmGfzAVaQMwEgrS+mxOKjY7JuM=; b=hc1754f8bwiw7cxL6by4rpf7/Y+3PRepwMIAS5rqkTup51rMMuuJSVM+U69I0MUxeQCrwWnwrRWwIhorYrsqFr7RxgQusLdzTHBRDtasRF6qJGDJ5oSFmT/y/ta8Afic3nGRJUZfM3P14SaD98cBedpPX7pOji5VztWO2W+wxiM= 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 1702374512487359.23318685826223; Tue, 12 Dec 2023 01:48:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652855.1018957 (Exim 4.92) (envelope-from ) id 1rCzN4-0001DJ-Ni; Tue, 12 Dec 2023 09:48:10 +0000 Received: by outflank-mailman (output) from mailman id 652855.1018957; Tue, 12 Dec 2023 09:48:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzN4-0001DA-Kh; Tue, 12 Dec 2023 09:48:10 +0000 Received: by outflank-mailman (input) for mailman id 652855; Tue, 12 Dec 2023 09:48:09 +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 1rCzN3-0007Gv-8n for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:09 +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 8dd442f4-98d3-11ee-98e8-6d05b1d4d9a1; Tue, 12 Dec 2023 10:48:08 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 C2043224B1; Tue, 12 Dec 2023 09:48:07 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 58BD2139E9; Tue, 12 Dec 2023 09:48:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id NAJtFFcseGXXfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:07 +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: 8dd442f4-98d3-11ee-98e8-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374487; 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=fuJajbW3/YYf0ZwXbPmGfzAVaQMwEgrS+mxOKjY7JuM=; b=I//7pvG9dUu5sVhpJO82/Y8e3y3JxDVHBkG7EqHvpH/sISE2vyx6KBnEzb1kCFZw/jB9y6 r9IhKDRf/hf7XHt/noqg0QxGzlDOw5Oh7788PsVXcw7TQ62U06hSHRnP1up+qWsW9ZGhcM FJUwbegaGNEfb9lVibgJ238F9EAuB98= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374487; 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=fuJajbW3/YYf0ZwXbPmGfzAVaQMwEgrS+mxOKjY7JuM=; b=I//7pvG9dUu5sVhpJO82/Y8e3y3JxDVHBkG7EqHvpH/sISE2vyx6KBnEzb1kCFZw/jB9y6 r9IhKDRf/hf7XHt/noqg0QxGzlDOw5Oh7788PsVXcw7TQ62U06hSHRnP1up+qWsW9ZGhcM FJUwbegaGNEfb9lVibgJ238F9EAuB98= 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 v4 07/12] xen/spinlock: add explicit non-recursive locking functions Date: Tue, 12 Dec 2023 10:47:20 +0100 Message-Id: <20231212094725.22184-8-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Flag: NO X-Spam-Score: 10.00 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.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_TWELVE(0.00)[16]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374513180100001 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) --- 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 | 24 +++++++++++++++++++----- 14 files changed, 70 insertions(+), 56 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index eeb65ca6bb..7466d12b0c 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 69ce1fd5cf..998cb53a58 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, @@ -2446,10 +2446,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 0a66db10b9..c35a68fbd5 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) @@ -3584,11 +3584,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: @@ -4411,7 +4411,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)); @@ -4423,7 +4423,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 1720079fd9..fa4e56a4df 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -746,11 +746,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; } @@ -758,7 +758,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; } @@ -775,7 +775,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 9e5ad68df2..61a91f5a94 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -27,7 +27,7 @@ static 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 inline void lock_page_alloc(struct p2m_domain *p2m) static inline void unlock_page_alloc(struct p2m_domain *p2m) { page_alloc_mm_unlock(p2m->domain->arch.page_alloc_unlock_level); - spin_unlock(&(p2m->domain->page_alloc_lock)); + nrspin_unlock(&(p2m->domain->page_alloc_lock)); } =20 /* diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 6eb446e437..f188f09b8e 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2226,7 +2226,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)); @@ -2278,7 +2278,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 86c4c22cac..5b33a1bf9d 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 5721eab225..54163d51ea 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 f454c4d894..47b1d0b5a8 100644 --- a/xen/common/numa.c +++ b/xen/common/numa.c @@ -718,13 +718,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 8c6a3d9274..a25c00a7d4 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -515,7 +515,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. */ @@ -561,7 +561,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 @@ -2343,7 +2343,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) ) { @@ -2425,7 +2425,7 @@ int assign_pages( } =20 out: - spin_unlock(&d->page_alloc_lock); + nrspin_unlock(&d->page_alloc_lock); return rc; } =20 @@ -2906,9 +2906,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 @@ -2927,9 +2927,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 1db2bbdb6a..8d05c57f69 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -369,9 +369,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; @@ -639,7 +639,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); @@ -660,7 +660,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 { @@ -1027,9 +1027,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(), @@ -1066,13 +1066,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 ac3bef267a..82ef99d3b6 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -101,6 +101,8 @@ struct lock_profile_qhead { }; =20 #define _LOCK_PROFILE(lockname) { .name =3D #lockname, .lock =3D &lockname= , } +#define _RLOCK_PROFILE(lockname) { .name =3D #lockname, .rlock =3D &lockna= me, \ + .is_rlock =3D 1, } #define _LOCK_PROFILE_PTR(name) = \ static struct lock_profile * const __lock_profile_##name = \ __used_section(".lockprofile.data") =3D = \ @@ -117,10 +119,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); = \ @@ -133,13 +135,16 @@ struct lock_profile_qhead { break; = \ } = \ prof->name =3D #l; = \ - prof->lock =3D &(s)->l; = \ + prof->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, 0) +#define rspin_lock_init_prof(s, l) = \ + __spin_lock_init_prof(s, l, rlock, rspinlock_t, 1) =20 void _lock_profile_register_struct( int32_t type, struct lock_profile_qhead *qhead, int32_t idx); @@ -174,6 +179,7 @@ struct lock_profile_qhead { }; =20 #endif =20 + typedef union { uint32_t head_tail; struct { @@ -261,4 +267,12 @@ void rspin_unlock_irqrestore(rspinlock_t *lock, unsign= ed long flags); /* Ensure a lock is quiescent between two critical operations. */ #define spin_barrier(l) _spin_barrier(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) + #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374517; cv=none; d=zohomail.com; s=zohoarc; b=WPws73r3sKv6CEa1h96xnqHbAmD3sc2XaBheE9iIwEKsrBSdhvTlJwBO2mT7JpRT5H5AFA2AkvQgGbtOkUXTsdxSKbeVQV+gUZFeSB1tmdjXscFy2+tHi5QQ0Z3Bb7WMh+3t8QqNVGs4VcighYfXcqqNZgTS0Fl+IQG3UbyjIqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374517; 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=JqufYzI2VSdAkZ5M5j8hnnU6lqQ01enR77XYZZhm6gU=; b=duQflon4f+FAeOTN2i2HMliVKJ0vXnZEzNHnRVOLB17upz0vnyWZc0X9TUrUrhIu1ouVtjDdM45mx7A1eu0JpjJiUyCqjrnY2UjvEAytFT60gvWMgBWUfG0/Flj3kU01nQ84GqcVBhN19RRpUOfiRrK9qvfyAKuFremFNrFyOok= 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 1702374517261765.5014728277699; Tue, 12 Dec 2023 01:48:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652858.1018967 (Exim 4.92) (envelope-from ) id 1rCzNA-0001lI-8Z; Tue, 12 Dec 2023 09:48:16 +0000 Received: by outflank-mailman (output) from mailman id 652858.1018967; Tue, 12 Dec 2023 09:48:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzNA-0001kz-5M; Tue, 12 Dec 2023 09:48:16 +0000 Received: by outflank-mailman (input) for mailman id 652858; Tue, 12 Dec 2023 09:48:14 +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 1rCzN8-0007Gv-Lx for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:14 +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 9132306b-98d3-11ee-98e8-6d05b1d4d9a1; Tue, 12 Dec 2023 10:48:13 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 5EE4D1F8AF; Tue, 12 Dec 2023 09:48:13 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 25CBD139E9; Tue, 12 Dec 2023 09:48:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id NfAGCF0seGXifgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:13 +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: 9132306b-98d3-11ee-98e8-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374493; 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=JqufYzI2VSdAkZ5M5j8hnnU6lqQ01enR77XYZZhm6gU=; b=RS0mBIQIWvWD3yz04dS6i8xt3FH+xEsh06cP6VAMODVwwM0A4buG9E7aP1qiXJoN1HU4Vh Bgq4m3asfdOoKtk6krfmEdmvaf9YtTElB3baiW9CckHIm70JRFDKNGA7/UUTPF7/YKRF5G R1oPE4RzeogH0pnPLtPMpsYC6EevDs8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374493; 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=JqufYzI2VSdAkZ5M5j8hnnU6lqQ01enR77XYZZhm6gU=; b=RS0mBIQIWvWD3yz04dS6i8xt3FH+xEsh06cP6VAMODVwwM0A4buG9E7aP1qiXJoN1HU4Vh Bgq4m3asfdOoKtk6krfmEdmvaf9YtTElB3baiW9CckHIm70JRFDKNGA7/UUTPF7/YKRF5G R1oPE4RzeogH0pnPLtPMpsYC6EevDs8= 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 v4 08/12] xen/spinlock: add another function level Date: Tue, 12 Dec 2023 10:47:21 +0100 Message-Id: <20231212094725.22184-9-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 18.90 X-Spam-Flag: YES X-Spam-Level: ****** X-Spamd-Bar: ++++++ Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=RS0mBIQI; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out2.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [6.09 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[99.99%]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; 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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 6.09 X-Rspamd-Queue-Id: 5EE4D1F8AF X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374519366100001 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 --- V2: - new patch --- xen/common/spinlock.c | 104 +++++++++++++++++++++++-------------- xen/include/xen/spinlock.h | 1 + 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 7d611d3d7d..31d12b1006 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,25 +388,25 @@ void _spin_unlock_irqrestore(spinlock_t *lock, unsign= ed long flags) local_irq_restore(flags); } =20 +static int 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) { - /* - * 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 - ? lock->tickets.head !=3D lock->tickets.tail - : lock->recurse_cpu =3D=3D smp_processor_id(); + return spin_is_locked_common(&lock->tickets); } =20 -int _spin_trylock(spinlock_t *lock) +static int 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(); @@ -403,8 +414,7 @@ int _spin_trylock(spinlock_t *lock) } 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; @@ -413,29 +423,41 @@ int _spin_trylock(spinlock_t *lock) * cmpxchg() is a full barrier so no need for an * arch_lock_acquire_barrier(). */ - got_lock(&lock->debug); + got_lock(debug); LOCK_PROFILE_GOT(0); =20 return 1; } =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); +} + int rspin_trylock(rspinlock_t *lock) { unsigned int cpu =3D smp_processor_id(); @@ -448,7 +470,8 @@ int 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 0; lock->recurse_cpu =3D cpu; } @@ -466,7 +489,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 +514,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 82ef99d3b6..d6f4b66613 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -163,6 +163,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 Sun May 19 07:16:25 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=1702374521; cv=none; d=zohomail.com; s=zohoarc; b=EYeT4cqaKFK6IBZfrvI5hdTIFZFFzRuhsLLPTantTpnfJIRDerKXls5Q3rFlQztzcivZTnfXcMohNM2LaBqfcQ2mTpn/VU2MU7uXyY8sU7mlvLSr3dtrf1tXQC56yiR7VEAd2D+isIc10kNKEJfIaIHvSnZIVjo30T+rOSS1fZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374521; 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=GeHSgUQmT5Ki5ph3MFsQ59wc1zBmxDp8n3ZyP6ZPgHs=; b=ZVQ9QeLA56bEAVmlKppayn/mbgZ08bnuuz9VptHootxjeGYDLin2kwivaT42gImQU8qxrbtQTiNr6RNTAd//cWhkI3Nf/NPNy1QCFYfrDbsu5muab7pzjsRxj8xygHEp5M2EJ7+4kSO2EkliPGfmn1+mDQvq/bDOh9Vm3MPIhGk= 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 1702374521213248.08143372369943; Tue, 12 Dec 2023 01:48:41 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652860.1018977 (Exim 4.92) (envelope-from ) id 1rCzNH-0002Qz-HJ; Tue, 12 Dec 2023 09:48:23 +0000 Received: by outflank-mailman (output) from mailman id 652860.1018977; Tue, 12 Dec 2023 09:48:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzNH-0002Qs-Dj; Tue, 12 Dec 2023 09:48:23 +0000 Received: by outflank-mailman (input) for mailman id 652860; Tue, 12 Dec 2023 09:48:21 +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 1rCzNF-0006i7-DE for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:21 +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 948b53c6-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:48:19 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 06E76224B1; Tue, 12 Dec 2023 09:48:19 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B6EEE139E9; Tue, 12 Dec 2023 09:48:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 4pZtK2IseGXqfgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:18 +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: 948b53c6-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374499; 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=GeHSgUQmT5Ki5ph3MFsQ59wc1zBmxDp8n3ZyP6ZPgHs=; b=Cmfoz7I/V4oW5S7TltXIHoolTK9kmfZrWSj1gNeUqmiJhRSeYYD4q9XbZ8mn4MGXwSaR75 5hOTo8mahHvw7kcZO+SNWB7LdjR2W7lYbEJpMH0YtxQ9Y3gv6X8vMJD0Jwzoqwcc+gj/u5 ExsNZ9HYTM8mKNGN2aIvxV1Ia1VHv1Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374499; 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=GeHSgUQmT5Ki5ph3MFsQ59wc1zBmxDp8n3ZyP6ZPgHs=; b=Cmfoz7I/V4oW5S7TltXIHoolTK9kmfZrWSj1gNeUqmiJhRSeYYD4q9XbZ8mn4MGXwSaR75 5hOTo8mahHvw7kcZO+SNWB7LdjR2W7lYbEJpMH0YtxQ9Y3gv6X8vMJD0Jwzoqwcc+gj/u5 ExsNZ9HYTM8mKNGN2aIvxV1Ia1VHv1Q= 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 v4 09/12] xen/spinlock: add missing rspin_is_locked() and rspin_barrier() Date: Tue, 12 Dec 2023 10:47:22 +0100 Message-Id: <20231212094725.22184-10-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 18.90 X-Spam-Flag: YES X-Spam-Level: ****** X-Spamd-Bar: ++++++ Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="Cmfoz7I/"; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out1.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [6.09 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; 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)[10]; NEURAL_HAM_SHORT(-0.20)[-1.000]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 6.09 X-Rspamd-Queue-Id: 06E76224B1 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374523514100001 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 --- xen/arch/x86/mm/p2m-pod.c | 2 +- xen/common/domain.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/spinlock.c | 17 +++++++++++++++++ xen/drivers/char/console.c | 4 ++-- xen/drivers/passthrough/pci.c | 2 +- xen/include/xen/spinlock.h | 2 ++ 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 61a91f5a94..40d3b25d25 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -385,7 +385,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 dc97755391..198cb36878 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -982,7 +982,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 a25c00a7d4..14010b6fa5 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -476,7 +476,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 31d12b1006..91e325f3fe 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -458,6 +458,23 @@ void _spin_barrier(spinlock_t *lock) spin_barrier_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR); } =20 +int 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); +} + int 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 8d05c57f69..e6502641eb 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -328,7 +328,7 @@ static void cf_check do_dec_thresh(unsigned char key, s= truct cpu_user_regs *regs =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++; @@ -766,7 +766,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 41444f8e2e..94f52b7acc 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -64,7 +64,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 d6f4b66613..e63db4eb4c 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -239,6 +239,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); +int rspin_is_locked(const rspinlock_t *lock); +void rspin_barrier(rspinlock_t *lock); =20 #define spin_lock(l) _spin_lock(l) #define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374524; cv=none; d=zohomail.com; s=zohoarc; b=gk2C8JTsXE+5iTzEETDwgVQre8TYN4JR01ONUuTzUaeTsF+yii1YRIoC9BnREi6nAoVhOJC1crS/VJ//Xjy6PdlL5oDGgEIBACvyhz/VBsiS5xCaxNa6O5WjHaAWaX6S3RqMsHz19nmrlwsJeSPtnH9mIhllaEhmw/4pcFNWTCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374524; 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=BklndjCL4Uz1x9x3WS3WiTgdhj80m92SjU/6dJo8OCQ=; b=jjkBYUfVgZiBSYjsBZfGXzePVMzTvE1OSNf0KrAiWNrz72bkMXgkgsU9iv7KqscKSn4/5xV4QsILPcyk/1ShzOPpSQvnLUhjAn6McU59lNsYJZmahNr20TxDVXnRyV9cjM9A5cAQB76P6y/xWwJC+ayNwr22asPXdALwzGxpeGY= 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 1702374524332704.0936279617797; Tue, 12 Dec 2023 01:48:44 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652862.1018987 (Exim 4.92) (envelope-from ) id 1rCzNK-0002pl-PZ; Tue, 12 Dec 2023 09:48:26 +0000 Received: by outflank-mailman (output) from mailman id 652862.1018987; Tue, 12 Dec 2023 09:48:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzNK-0002pX-Mh; Tue, 12 Dec 2023 09:48:26 +0000 Received: by outflank-mailman (input) for mailman id 652862; Tue, 12 Dec 2023 09:48:26 +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 1rCzNK-0007Gv-A9 for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:26 +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 97da7a10-98d3-11ee-98e8-6d05b1d4d9a1; Tue, 12 Dec 2023 10:48:25 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 96282224B7; Tue, 12 Dec 2023 09:48:24 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 5C7A3139E9; Tue, 12 Dec 2023 09:48:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id 2X9YFWgseGX1fgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:24 +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: 97da7a10-98d3-11ee-98e8-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374504; 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=BklndjCL4Uz1x9x3WS3WiTgdhj80m92SjU/6dJo8OCQ=; b=VhO+QMOAA1MSIMe5kcASh6vyJs81aCpKNXCiEN64r6Ip+WsduMUegl4RaG/MUD4aWfuiAn L+enWUnDzxDMVn2+839l3mO9H5WGtISAvwbzsQCAvLxAv4B+8QC242+j8B0sbZZprJS3OI tapeKTxXZmMCU++ih6mvOXHKYQ22VxY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374504; 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=BklndjCL4Uz1x9x3WS3WiTgdhj80m92SjU/6dJo8OCQ=; b=VhO+QMOAA1MSIMe5kcASh6vyJs81aCpKNXCiEN64r6Ip+WsduMUegl4RaG/MUD4aWfuiAn L+enWUnDzxDMVn2+839l3mO9H5WGtISAvwbzsQCAvLxAv4B+8QC242+j8B0sbZZprJS3OI tapeKTxXZmMCU++ih6mvOXHKYQ22VxY= 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 v4 10/12] xen/spinlock: split recursive spinlocks from normal ones Date: Tue, 12 Dec 2023 10:47:23 +0100 Message-Id: <20231212094725.22184-11-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 8.80 X-Spam-Flag: NO X-Spam-Level: ********** X-Spam-Flag: NO Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [10.00 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.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)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 10.00 X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374525509100003 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 --- V2: - use shorter names (Jan Beulich) - don't embed spinlock_t in rspinlock_t (Jan Beulich) --- xen/common/spinlock.c | 49 ++++++++++++++++++++++++++++++++ xen/include/xen/spinlock.h | 58 +++++++++++++++++++++++++------------- 2 files changed, 88 insertions(+), 19 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 91e325f3fe..d0f8393504 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -541,6 +541,55 @@ void rspin_unlock_irqrestore(rspinlock_t *lock, unsign= ed long flags) local_irq_restore(flags); } =20 +int nrspin_trylock(rspinlock_t *lock) +{ + check_lock(&lock->debug, true); + + if ( unlikely(lock->recurse_cpu !=3D SPINLOCK_NO_CPU) ) + return 0; + + 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 e63db4eb4c..ca18b9250a 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -76,8 +76,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 */ @@ -108,6 +106,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, = \ @@ -117,8 +119,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 @@ -143,8 +146,11 @@ struct lock_profile_qhead { =20 #define spin_lock_init_prof(s, l) = \ __spin_lock_init_prof(s, l, lock, spinlock_t, 0) -#define rspin_lock_init_prof(s, l) = \ - __spin_lock_init_prof(s, l, rlock, rspinlock_t, 1) +#define rspin_lock_init_prof(s, l) do { = \ + __spin_lock_init_prof(s, l, rlock, rspinlock_t, 1); = \ + (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); @@ -166,11 +172,15 @@ struct lock_profile_qhead { }; struct lock_profile { }; =20 #define SPIN_LOCK_UNLOCKED { = \ + .debug =3D_LOCK_DEBUG, = \ +} +#define RSPIN_LOCK_UNLOCKED { = \ + .debug =3D_LOCK_DEBUG, = \ .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)) @@ -180,7 +190,6 @@ struct lock_profile { }; =20 #endif =20 - typedef union { uint32_t head_tail; struct { @@ -192,6 +201,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) @@ -202,12 +219,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); @@ -242,6 +257,19 @@ void rspin_unlock_irqrestore(rspinlock_t *lock, unsign= ed long flags); int rspin_is_locked(const rspinlock_t *lock); void rspin_barrier(rspinlock_t *lock); =20 +int nrspin_trylock(rspinlock_t *lock); +void nrspin_lock(rspinlock_t *lock); +void nrspin_unlock(rspinlock_t *lock); +void nrspin_lock_irq(rspinlock_t *lock); +void nrspin_unlock_irq(rspinlock_t *lock); +#define nrspin_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) !=3D sizeof(unsigned long)); \ + ((f) =3D __nrspin_lock_irqsave(l)); \ + }) +unsigned long __nrspin_lock_irqsave(rspinlock_t *lock); +void nrspin_unlock_irqrestore(rspinlock_t *lock, unsigned long flags); + #define spin_lock(l) _spin_lock(l) #define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) #define spin_lock_irq(l) _spin_lock_irq(l) @@ -270,12 +298,4 @@ void rspin_barrier(rspinlock_t *lock); /* Ensure a lock is quiescent between two critical operations. */ #define spin_barrier(l) _spin_barrier(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) - #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374868; cv=none; d=zohomail.com; s=zohoarc; b=JlpYjNGy6WWGW1Sge5mqISOM6FykcFMUtBkSoihlohCRdLXikC9Q80WjjbyxszlOwnv0eIzzkFvCkPQVOKDHfhnAgUY/RdIJm/HOrz4+4tpX7qpTIxEzU5qLcCRuNEFN79qK5zfzDoKRnn6uBIN43KgREv+HZ4mregXBRUunff0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374868; 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=X9mtlOEEzRw0edEwEif+vRv2D1U88AlwXf4iThb3cgE=; b=m85MQPCindc5vm49Ykicz+tCaseW5EoY0e3daCHdiUAviODNoyxosEHwf6E0kYVfGZ0iBSKK3XmgCZ0MdH6vEs73hih/hfUwp5Q6aWHdTfKBVOBbIkNfOdNfpMngprw/7O8Sh85vgz8ZlZleWxyEYEPvmorBH1XicJf0+5DkqfQ= 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 1702374868229705.6327844569724; Tue, 12 Dec 2023 01:54:28 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652891.1019027 (Exim 4.92) (envelope-from ) id 1rCzSu-0008CI-9f; Tue, 12 Dec 2023 09:54:12 +0000 Received: by outflank-mailman (output) from mailman id 652891.1019027; Tue, 12 Dec 2023 09:54:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzSu-0008CB-5e; Tue, 12 Dec 2023 09:54:12 +0000 Received: by outflank-mailman (input) for mailman id 652891; Tue, 12 Dec 2023 09:54:11 +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 1rCzNQ-0006i7-9p for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:32 +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 9b26cd42-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:48:30 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 2B6511F74C; Tue, 12 Dec 2023 09:48:30 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id E5F36139E9; Tue, 12 Dec 2023 09:48:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id GlrjNm0seGX+fgAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48: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: 9b26cd42-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374510; 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=X9mtlOEEzRw0edEwEif+vRv2D1U88AlwXf4iThb3cgE=; b=j16YnGSd8HmcxmMNaY9AbaLdu2gwwGtPOeiAo3vlqhr2TN6EJVeWVMfG6CfxOooQ47VS1a 1/37ZRLk5Hi/YZxZO2ykAAE9sOTX8JXldRsMBiaqeMXpGO4ldLURJQTqXkpFGtoPFIHa5n 5g5tfAHahqu+Ig6LjgfAQ2Ukb+uyVoQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374510; 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=X9mtlOEEzRw0edEwEif+vRv2D1U88AlwXf4iThb3cgE=; b=j16YnGSd8HmcxmMNaY9AbaLdu2gwwGtPOeiAo3vlqhr2TN6EJVeWVMfG6CfxOooQ47VS1a 1/37ZRLk5Hi/YZxZO2ykAAE9sOTX8JXldRsMBiaqeMXpGO4ldLURJQTqXkpFGtoPFIHa5n 5g5tfAHahqu+Ig6LjgfAQ2Ukb+uyVoQ= 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 v4 11/12] xen/spinlock: remove indirection through macros for spin_*() functions Date: Tue, 12 Dec 2023 10:47:24 +0100 Message-Id: <20231212094725.22184-12-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Flag: NO X-Spam-Score: 10.00 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: ******** X-Spam-Score: 8.80 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.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)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374870397100001 Content-Type: text/plain; charset="utf-8" In reality all spin_*() functions are macros which are defined to just call a related real function. Remove this macro layer, as it is adding complexity without any gain. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- V2: - new patch --- xen/common/spinlock.c | 28 +++++++++--------- xen/include/xen/spinlock.h | 58 +++++++++++++++----------------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index d0f8393504..296bcf33e6 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -332,30 +332,30 @@ static void always_inline spin_lock_common(spinlock_t= ickets_t *t, LOCK_PROFILE_GOT(block); } =20 -void _spin_lock(spinlock_t *lock) +void spin_lock(spinlock_t *lock) { 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) +void spin_lock_cb(spinlock_t *lock, void (*cb)(void *data), void *data) { spin_lock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR, cb, d= ata); } =20 -void _spin_lock_irq(spinlock_t *lock) +void spin_lock_irq(spinlock_t *lock) { ASSERT(local_irq_is_enabled()); local_irq_disable(); - _spin_lock(lock); + spin_lock(lock); } =20 -unsigned long _spin_lock_irqsave(spinlock_t *lock) +unsigned long __spin_lock_irqsave(spinlock_t *lock) { unsigned long flags; =20 local_irq_save(flags); - _spin_lock(lock); + spin_lock(lock); return flags; } =20 @@ -371,20 +371,20 @@ static void always_inline spin_unlock_common(spinlock= _tickets_t *t, preempt_enable(); } =20 -void _spin_unlock(spinlock_t *lock) +void spin_unlock(spinlock_t *lock) { spin_unlock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR); } =20 -void _spin_unlock_irq(spinlock_t *lock) +void spin_unlock_irq(spinlock_t *lock) { - _spin_unlock(lock); + spin_unlock(lock); local_irq_enable(); } =20 -void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) +void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags) { - _spin_unlock(lock); + spin_unlock(lock); local_irq_restore(flags); } =20 @@ -393,7 +393,7 @@ static int always_inline spin_is_locked_common(const sp= inlock_tickets_t *t) return t->head !=3D t->tail; } =20 -int _spin_is_locked(const spinlock_t *lock) +int spin_is_locked(const spinlock_t *lock) { return spin_is_locked_common(&lock->tickets); } @@ -429,7 +429,7 @@ static int always_inline spin_trylock_common(spinlock_t= ickets_t *t, return 1; } =20 -int _spin_trylock(spinlock_t *lock) +int spin_trylock(spinlock_t *lock) { return spin_trylock_common(&lock->tickets, &lock->debug, LOCK_PROFILE_= PAR); } @@ -453,7 +453,7 @@ static void always_inline spin_barrier_common(spinlock_= tickets_t *t, smp_mb(); } =20 -void _spin_barrier(spinlock_t *lock) +void spin_barrier(spinlock_t *lock) { spin_barrier_common(&lock->tickets, &lock->debug, LOCK_PROFILE_PAR); } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index ca18b9250a..87946965b2 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -224,18 +224,30 @@ typedef struct rspinlock { #define spin_lock_init(l) (*(l) =3D (spinlock_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); -void _spin_lock_irq(spinlock_t *lock); -unsigned long _spin_lock_irqsave(spinlock_t *lock); +void spin_lock(spinlock_t *lock); +void spin_lock_cb(spinlock_t *lock, void (*cb)(void *data), void *data); +void spin_lock_irq(spinlock_t *lock); +#define spin_lock_irqsave(l, f) \ + ({ \ + BUILD_BUG_ON(sizeof(f) !=3D sizeof(unsigned long)); \ + ((f) =3D __spin_lock_irqsave(l)); \ + }) +unsigned long __spin_lock_irqsave(spinlock_t *lock); =20 -void _spin_unlock(spinlock_t *lock); -void _spin_unlock_irq(spinlock_t *lock); -void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags); +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); -void _spin_barrier(spinlock_t *lock); +int spin_is_locked(const spinlock_t *lock); +int spin_trylock(spinlock_t *lock); +#define spin_trylock_irqsave(lock, flags) \ +({ \ + local_irq_save(flags); \ + spin_trylock(lock) ? \ + 1 : ({ local_irq_restore(flags); 0; }); \ +}) +/* Ensure a lock is quiescent between two critical operations. */ +void spin_barrier(spinlock_t *lock); =20 /* * rspin_[un]lock(): Use these forms when the lock can (safely!) be @@ -270,32 +282,6 @@ void nrspin_unlock_irq(rspinlock_t *lock); unsigned long __nrspin_lock_irqsave(rspinlock_t *lock); void nrspin_unlock_irqrestore(rspinlock_t *lock, unsigned long flags); =20 -#define spin_lock(l) _spin_lock(l) -#define spin_lock_cb(l, c, d) _spin_lock_cb(l, c, d) -#define spin_lock_irq(l) _spin_lock_irq(l) -#define spin_lock_irqsave(l, f) \ - ({ \ - BUILD_BUG_ON(sizeof(f) !=3D sizeof(unsigned long)); \ - ((f) =3D _spin_lock_irqsave(l)); \ - }) - -#define spin_unlock(l) _spin_unlock(l) -#define spin_unlock_irq(l) _spin_unlock_irq(l) -#define spin_unlock_irqrestore(l, f) _spin_unlock_irqrestore(l, f) - -#define spin_is_locked(l) _spin_is_locked(l) -#define spin_trylock(l) _spin_trylock(l) - -#define spin_trylock_irqsave(lock, flags) \ -({ \ - local_irq_save(flags); \ - spin_trylock(lock) ? \ - 1 : ({ local_irq_restore(flags); 0; }); \ -}) - #define spin_lock_kick(l) arch_lock_signal_wmb() =20 -/* Ensure a lock is quiescent between two critical operations. */ -#define spin_barrier(l) _spin_barrier(l) - #endif /* __SPINLOCK_H__ */ --=20 2.35.3 From nobody Sun May 19 07:16:25 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=1702374675; cv=none; d=zohomail.com; s=zohoarc; b=N68z+8geeyJE4yDGnQV/dcyhuW22u7NPRFMI5h29oW/nlzdS1MvdC+WIfqeI9eYN2OV7xCyRIzj/1bFyIdLEA6GKqa4ARE00L41F3slz8Aow5lw3/fUzR82+O9+wISjjEOXRqwmk0wGT1luPXwhKldzw0M4UCgHsOPLRbi7GcoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702374675; 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=o0uw0mmQZTxGdRt6ID2VqCT2e47nRjokh0HeNjme8pc=; b=FbsmZCkhow3u71+qDNCBfOHs9NEOTZXbsQ3unIUCmH2Td4UAEBmqTY1BjbyM+pGaUx249q3i50smet0XaKQBOkWtNnTKh/R5uf3IlDJTmyhGjbpdT/4kOBnLYZH+DNdOG5t94PAAKBMVK1nyAbvvhIVkR7ZxkCOqYB4eG12kEVM= 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 1702374675572610.1668673520386; Tue, 12 Dec 2023 01:51:15 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.652875.1018996 (Exim 4.92) (envelope-from ) id 1rCzPf-0005jz-Ce; Tue, 12 Dec 2023 09:50:51 +0000 Received: by outflank-mailman (output) from mailman id 652875.1018996; Tue, 12 Dec 2023 09:50:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCzPf-0005js-A0; Tue, 12 Dec 2023 09:50:51 +0000 Received: by outflank-mailman (input) for mailman id 652875; Tue, 12 Dec 2023 09:50:49 +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 1rCzNV-0006i7-SG for xen-devel@lists.xenproject.org; Tue, 12 Dec 2023 09:48:37 +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 9e84002a-98d3-11ee-9b0f-b553b5be7939; Tue, 12 Dec 2023 10:48:36 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (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 BE2EB1F74C; Tue, 12 Dec 2023 09:48:35 +0000 (UTC) Received: from imap2.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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 83F73139E9; Tue, 12 Dec 2023 09:48:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id gFz5HnMseGUAfwAAn2gu4w (envelope-from ); Tue, 12 Dec 2023 09:48:35 +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: 9e84002a-98d3-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374515; 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=o0uw0mmQZTxGdRt6ID2VqCT2e47nRjokh0HeNjme8pc=; b=GpYCzSlzf8uUWHp752gL4WHDqkywen/2Pq2rJqzgYiipkl4dTnvAsaSDdEVjDuCqWYYy1q kW5XhUATQEYwlYlnXiAYeEKuPjY1tuLtavOZ1L6rSBht0XhK4NgBRn9AfnKMf0aYk61XY/ vHGIjVYXyUTBZGiCXC/zDnG9GWdWoyo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702374515; 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=o0uw0mmQZTxGdRt6ID2VqCT2e47nRjokh0HeNjme8pc=; b=GpYCzSlzf8uUWHp752gL4WHDqkywen/2Pq2rJqzgYiipkl4dTnvAsaSDdEVjDuCqWYYy1q kW5XhUATQEYwlYlnXiAYeEKuPjY1tuLtavOZ1L6rSBht0XhK4NgBRn9AfnKMf0aYk61XY/ vHGIjVYXyUTBZGiCXC/zDnG9GWdWoyo= 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 v4 12/12] xen/spinlock: support higher number of cpus Date: Tue, 12 Dec 2023 10:47:25 +0100 Message-Id: <20231212094725.22184-13-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231212094725.22184-1-jgross@suse.com> References: <20231212094725.22184-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: *************** X-Spam-Flag: YES X-Spam-Score: 15.00 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=GpYCzSlz; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out2.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [0.99 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; 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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 0.99 X-Rspamd-Queue-Id: BE2EB1F74C X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1702374676623100001 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. Signed-off-by: Juergen Gross --- xen/common/spinlock.c | 1 + xen/include/xen/spinlock.h | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 296bcf33e6..ae7c7c2086 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -481,6 +481,7 @@ int 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); =20 check_lock(&lock->debug, true); diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 87946965b2..d720778cc1 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -7,16 +7,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; }; @@ -210,10 +210,10 @@ 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_RECURSE_BITS 8 + uint8_t recurse_cnt; #define SPINLOCK_MAX_RECURSE ((1u << SPINLOCK_RECURSE_BITS) - 1) union lock_debug debug; #ifdef CONFIG_DEBUG_LOCK_PROFILE --=20 2.35.3