From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350874; cv=none; d=zohomail.com; s=zohoarc; b=CN5Xz8mUu7XZ8adKgj688hmWNX9p8pCZXOqdbVAWd2Fk2OFXyQu2jfy8qBm+nXIgE4/O8Htes2V+pkpTQSM80mJEoATxS299ydKMa0qyB5T3vSI2Pcee6GitTPoMgJZF4soqEcgymt12Mtr2apt/nqNUX2cgVEEa8XOsLY3AOGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350874; h=Content-Type: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=z/bXHNWyZkTLicGysMRuS+mhbdjAEJwJyFIm3Wfcg6A=; b=cceYvA8S7bO42QPbiU7ZbUEY+jXFCq55ijxixeZzfysFlLOqKS2QuXEqlI1dnVR554qBGSG9w+3G9mfe8QtFk4szMdfCnHYkVYvVp2y77uDcuAexP9mTsh64f+mVdquFl+PgxQo2UB6E/cAL2YGLITJbVFWvz/dXazGPiMpUdxk= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350874039565.809926539507; Wed, 13 Mar 2024 10:27:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692669.1080002 (Exim 4.92) (envelope-from ) id 1rkSNx-0001p5-4b; Wed, 13 Mar 2024 17:27:25 +0000 Received: by outflank-mailman (output) from mailman id 692669.1080002; Wed, 13 Mar 2024 17:27:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSNx-0001oL-0g; Wed, 13 Mar 2024 17:27:25 +0000 Received: by outflank-mailman (input) for mailman id 692669; Wed, 13 Mar 2024 17:27:24 +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 1rkSNw-0001lR-0k for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:24 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f3206778-e15e-11ee-a1ee-f123f15fe8a2; Wed, 13 Mar 2024 18:27:21 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a466a1f9ea0so11607266b.1 for ; Wed, 13 Mar 2024 10:27:21 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:19 -0700 (PDT) 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: f3206778-e15e-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350840; x=1710955640; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z/bXHNWyZkTLicGysMRuS+mhbdjAEJwJyFIm3Wfcg6A=; b=PBaPTIjeHQfhYt3S01T0O1dQwOA9fFVtYeF7mirFDdDbl43ITmtKXPmepfXq/r5WWX Ydc3cWAEeTV8F0ItQ2GE2N6Hz3bFKKjLed9sb29Ps92ERQZiQ4fOccrg+jDT6sN55Jgv 9LHfdoX5gccWmqJFLvkrNyhWtrhhmjBDiPo4I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350840; x=1710955640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z/bXHNWyZkTLicGysMRuS+mhbdjAEJwJyFIm3Wfcg6A=; b=n9ocQOz6S+kYUcy0wRHUGawr3L9WcdAnaLXDLPdZFvmKGmCsAIUm3/TVNOXp5d00bH 0Uu5JsO5QyJRwzi4HdhiM/KUJfKeXYLCcM/2YrlceIn1fOgR2m56IQRR5VMqtjftWKOl n1lwefK7+q7A1hmAvCZ0cS6TjvQLlnZUBJ2Eku6u/PJAT7j9jLFchvWF5NqqfTV/Xhbk p/mQMf6+oe3yHvuULVO74TsK9WCzoYr7m11X7ZMc4eZ/fQiKHtXPTgb0PXTX9sZD8QA4 jyPfk/+283Ov9aC7ef1flRX7QOeFRmTRQXf/iXBNtyVP4jcGnWCsydvRx0dBlFNGMCzt fE1w== X-Gm-Message-State: AOJu0Yx+6/LKWuhOOARTlfS3v7qeRN+buJcIG3XFeQfeYnjLmMqQ1sLD G1Hl7Ybmfw6LO53rHMoI0Z/+OYHPl6QdMmb3yeSJhIVB8HBR4iNTK6e6WhEWLeK/c2AYWEhBBtn l X-Google-Smtp-Source: AGHT+IG5eOM/N8WPQ+tLKnromzM4xSu+1XcAJsvPgdf1Zalb2TQYPjNhcC8YFhYbXe6S0A8CFLD9yw== X-Received: by 2002:a17:907:a093:b0:a45:54f3:b44d with SMTP id hu19-20020a170907a09300b00a4554f3b44dmr9508916ejc.8.1710350840553; Wed, 13 Mar 2024 10:27:20 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 1/7] xen/bitops: Cleanup ahead of rearrangements Date: Wed, 13 Mar 2024 17:27:10 +0000 Message-Id: <20240313172716.2325427-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350874431100003 * Rename __attribute_pure__ to just __pure before it gains users. * Identify the areas of xen/bitops.h which are a mess. * Create common/bitops.c for compile and runtime testing. This provides a statement of the ABI, and a confirmation that arch-specific implementati= ons behave as expected. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini I expect MISRA will have something to say about the macros here, but they a= re in aid of better testing. --- xen/common/Makefile | 1 + xen/common/bitops.c | 41 ++++++++++++++++++++++++++++++++++++++ xen/include/xen/bitops.h | 13 +++++++++--- xen/include/xen/compiler.h | 3 ++- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 xen/common/bitops.c diff --git a/xen/common/Makefile b/xen/common/Makefile index e5eee19a8537..1f8ca9a2f4f8 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_ARGO) +=3D argo.o obj-y +=3D bitmap.o +obj-y +=3D bitops.o obj-$(CONFIG_GENERIC_BUG_FRAME) +=3D bug.o obj-$(CONFIG_HYPFS_CONFIG) +=3D config_data.o obj-$(CONFIG_CORE_PARKING) +=3D core_parking.o diff --git a/xen/common/bitops.c b/xen/common/bitops.c new file mode 100644 index 000000000000..4c07191b4030 --- /dev/null +++ b/xen/common/bitops.c @@ -0,0 +1,41 @@ +#include +#include +#include + +/* Hide a value from the optimiser. */ +#define HIDE(x) ({ typeof(x) _x =3D x; asm volatile ( "" : "+r" (_x) ); _x= ; }) + +/* + * Check that fn(val) can be calcuated by the compiler, and that it gives = the + * expected answer. + */ +#define COMPILE_CHECK(fn, val, res) \ + do { \ + if ( fn(val) !=3D res ) \ + asm (".error \"Compile time check '" STR(fn(val) =3D=3D res) "= ' failed\""); \ + } while ( 0 ) + +/* + * Check that Xen's runtime logic for fn(val) gives the expected answer. = This + * requires using HIDE() to prevent the optimiser from emitting the full + * calculation. + */ +#define RUNTIME_CHECK(fn, val, res) \ + do { \ + BUG_ON(fn(HIDE(val)) !=3D res); \ + } while ( 0 ) + +/* + * Perform compiletime and runtime checks for fn(val) =3D=3D res. + */ +#define CHECK(fn, val, res) \ + do { \ + COMPILE_CHECK(fn, val, res); \ + RUNTIME_CHECK(fn, val, res); \ + } while ( 0 ) + +static int __init cf_check test_bitops(void) +{ + return 0; +} +__initcall(test_bitops); diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index e3c5a4ccf321..9b40f20381a2 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -1,5 +1,7 @@ -#ifndef _LINUX_BITOPS_H -#define _LINUX_BITOPS_H +#ifndef XEN_BITOPS_H +#define XEN_BITOPS_H + +#include #include =20 /* @@ -103,8 +105,13 @@ static inline int generic_flsl(unsigned long x) * Include this here because some architectures need generic_ffs/fls in * scope */ + +/* --------------------- Please tidy above here --------------------- */ + #include =20 +/* --------------------- Please tidy below here --------------------- */ + #ifndef find_next_bit /** * find_next_bit - find the next set bit in a memory region @@ -294,4 +301,4 @@ static inline __u32 ror32(__u32 word, unsigned int shif= t) =20 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) =20 -#endif +#endif /* XEN_BITOPS_H */ diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h index 16d554f2a593..972719df55b3 100644 --- a/xen/include/xen/compiler.h +++ b/xen/include/xen/compiler.h @@ -85,7 +85,8 @@ #define inline inline __init #endif =20 -#define __attribute_pure__ __attribute__((__pure__)) +#define __pure __attribute__((__pure__)) + #define __attribute_const__ __attribute__((__const__)) #define __transparent__ __attribute__((__transparent_union__)) =20 --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350873; cv=none; d=zohomail.com; s=zohoarc; b=kP6GqzcagWVtonZt/XZrjT8+wt7Tw34qw2quwuUnuAGpDs/TX1lO3AVuoqWknG5CF2QblPyC+PzJY9fjOIKs33BvIMsEHX3euzzJ3sLpwBuv67uY6jVYbgs+gW1AKRSwP2VsxHX4tMfhUX/oZRa2/YVmFV8JClJdNuUI4TVhaZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350873; h=Content-Type: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=k2oya0isulzFAqiR2Y4bOr7KNgkZIK98TBQV1YHRgn0=; b=CHGzJDtljtM3mJMKDC1UZLWMAIquCWiNFyt04qZ6EuPRhF/TgG8N11JieCLpU7Pl0dAKVQjndPK37NrfcpiGnS7X31Bp/Mm4gOiX/U2bYmUhrmO0tetO2DNoCxlHMd9Qbs3madA6WTs9xhaU1XO5BHzg0JfvHlTnfr7RXzsj5GU= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350873050614.3928517577517; Wed, 13 Mar 2024 10:27:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692670.1080017 (Exim 4.92) (envelope-from ) id 1rkSNy-0002EH-BZ; Wed, 13 Mar 2024 17:27:26 +0000 Received: by outflank-mailman (output) from mailman id 692670.1080017; Wed, 13 Mar 2024 17:27: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 1rkSNy-0002EA-8j; Wed, 13 Mar 2024 17:27:26 +0000 Received: by outflank-mailman (input) for mailman id 692670; Wed, 13 Mar 2024 17:27:24 +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 1rkSNw-0001lR-LF for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:24 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f3d14d5f-e15e-11ee-a1ee-f123f15fe8a2; Wed, 13 Mar 2024 18:27:23 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-a450615d1c4so24687366b.0 for ; Wed, 13 Mar 2024 10:27:23 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:21 -0700 (PDT) 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: f3d14d5f-e15e-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350842; x=1710955642; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k2oya0isulzFAqiR2Y4bOr7KNgkZIK98TBQV1YHRgn0=; b=tgN3u5Rl4VBjVMYFfH665xVPT01FrfQ26DouBvPsUIp6/IEpYZHe67CTfWwzTMDDgE GKTWbszIJA+rXPqCv84CSN5rKscOiGd2vjIAx31MEdRvylichcslzc2ny5I0Lm7OXt+b 5URllXOM0AmYh6pJjYOT1uJ6opYp+xaC0zCMI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350842; x=1710955642; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k2oya0isulzFAqiR2Y4bOr7KNgkZIK98TBQV1YHRgn0=; b=bzGWniYsk53HGq4U8N94gAFlV6jLk9ltByn2ZlqXyTp+Y0fEm1JF2XwNC6Et+bOB7k /RuF1lQ8wRSfsmiFQZOv1yF8YhLw2UrONjPn82v4ELSqMHt3tondTNCufIGtrtdRyqxR LxEriIah61QRj+PqKXSorSmM7ciKRAGCdr50xjegCfI3neLnoRpJMMSh0Po9IGcSje2p Eynq5tTo88p0/P+bN4ppLSJfn+EWeOFLjkmgPEzw7hbHLAKdtBDhZflGePngZB649kNc IrMvoxNXBbw29Cr/b4WT5DL9RHevBSBN1MbaEZ8eM7VsltZ8XeRCIHYrjXe4exa0jdWO vH4g== X-Gm-Message-State: AOJu0YxTESqZqPOSklFzmgv8PAEfY5KIiA3Gqeh+xFSLvYs6ZiB0/U2q i0ZofzQC/PLPYVDHJHwyZ4ws1ZexsNzRrbfnzYxA+dUQpvfDGFRU4YMSduF8Cch9wV1YndpnvuP c X-Google-Smtp-Source: AGHT+IHOjqUYc+9/WYFvjA5tif1UP2IANWkp92gtxXAy0+hCRxUW7p1lSXmMlZsvtX+23e1kctw02A== X-Received: by 2002:a17:906:7d50:b0:a45:f1fa:a17d with SMTP id l16-20020a1709067d5000b00a45f1faa17dmr2704000ejp.25.1710350842139; Wed, 13 Mar 2024 10:27:22 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 2/7] xen/bitops: Implement ffs() in common logic Date: Wed, 13 Mar 2024 17:27:11 +0000 Message-Id: <20240313172716.2325427-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350874420100002 Allow the optimiser to elimiate the call completely, and use the compiler builtin by default. Architectures should only proide arch_ffs() if they th= ink they can do better than the compiler. Confirm the expected behaviour with compile time and boot time tests. For x86, correct the prototype, and simplify the asm() with the statement given by the Intel architects to Linux about the behaviour on processors ne= wer than the 486. For PPC, __builtin_ffs() is 1/3 of the size of size of the transform to generic_fls(). Drop the definition entirely. For ARM, simply rename ffs() to arch_ffs(). It appears that the transformation to __builtin_clz() still makes better code than __builtin_ffs(). Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/arch/arm/include/asm/bitops.h | 2 +- xen/arch/ppc/include/asm/bitops.h | 1 - xen/arch/x86/include/asm/bitops.h | 19 +++++++++++++------ xen/common/bitops.c | 10 ++++++++++ xen/include/xen/bitops.h | 15 +++++++++++++++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/include/asm/bitops.h b/xen/arch/arm/include/asm/b= itops.h index ab030b6cb032..09c6064274a7 100644 --- a/xen/arch/arm/include/asm/bitops.h +++ b/xen/arch/arm/include/asm/bitops.h @@ -157,7 +157,7 @@ static inline int fls(unsigned int x) } =20 =20 -#define ffs(x) ({ unsigned int __t =3D (x); fls(ISOLATE_LSB(__t)); }) +#define arch_ffs(x) ({ unsigned int __t =3D (x); fls(ISOLATE_LSB(__t)); }) #define ffsl(x) ({ unsigned long __t =3D (x); flsl(ISOLATE_LSB(__t)); }) =20 /** diff --git a/xen/arch/ppc/include/asm/bitops.h b/xen/arch/ppc/include/asm/b= itops.h index 5820b9ce7bb5..635a3b4e3e33 100644 --- a/xen/arch/ppc/include/asm/bitops.h +++ b/xen/arch/ppc/include/asm/bitops.h @@ -173,7 +173,6 @@ static inline int __test_and_clear_bit(int nr, volatile= void *addr) =20 #define flsl(x) generic_flsl(x) #define fls(x) generic_fls(x) -#define ffs(x) ({ unsigned int t_ =3D (x); fls(t_ & -t_); }) #define ffsl(x) ({ unsigned long t_ =3D (x); flsl(t_ & -t_); }) =20 /* Based on linux/include/asm-generic/bitops/ffz.h */ diff --git a/xen/arch/x86/include/asm/bitops.h b/xen/arch/x86/include/asm/b= itops.h index 5a71afbc89d5..2c5b103cbbd9 100644 --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -430,16 +430,23 @@ static inline int ffsl(unsigned long x) return (int)r+1; } =20 -static inline int ffs(unsigned int x) +static inline unsigned int arch_ffs(unsigned int x) { - int r; + int r =3D -1; + + /* + * The AMD manual states that BSF won't modify the destination registe= r if + * x=3D0. The Intel manual states that the result is undefined, but t= he + * architects have said that the register is written back with it's old + * value, possibly zero extended above 32 bits. + */ + asm ( "bsf %[val], %[res]" + : [res] "+r" (r) + : [val] "rm" (x) ); =20 - asm ( "bsf %1,%0\n\t" - "jnz 1f\n\t" - "mov $-1,%0\n" - "1:" : "=3Dr" (r) : "rm" (x)); return r + 1; } +#define arch_ffs arch_ffs =20 /** * fls - find last bit set diff --git a/xen/common/bitops.c b/xen/common/bitops.c index 4c07191b4030..484df68768ad 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -34,8 +34,18 @@ RUNTIME_CHECK(fn, val, res); \ } while ( 0 ) =20 +static void test_ffs(void) +{ + /* unsigned int ffs(unsigned int) */ + CHECK(ffs, 0, 0); + CHECK(ffs, 1, 1); + CHECK(ffs, 0x80000000U, 32); +} + static int __init cf_check test_bitops(void) { + test_ffs(); + return 0; } __initcall(test_bitops); diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index 9b40f20381a2..fb3645d9cf87 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -110,6 +110,21 @@ static inline int generic_flsl(unsigned long x) =20 #include =20 +/* + * Find First Set bit. Bits are labelled from 1. + */ +static always_inline __pure unsigned int ffs(unsigned int x) +{ + if ( __builtin_constant_p(x) ) + return __builtin_ffs(x); + +#ifndef arch_ffs +#define arch_ffs __builtin_ffs +#endif + + return arch_ffs(x); +} + /* --------------------- Please tidy below here --------------------- */ =20 #ifndef find_next_bit --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350867; cv=none; d=zohomail.com; s=zohoarc; b=kUilsHhbOYhEU9/haOuZPMJ0xuKAaZnOJ5VsJdxHEu6ldv1gVbaHo7+njLIVExtfGNt5c+Ch5kNrXa4z87J9QJMy2FCeioUDYTmYe6WW+eIJERGuFXi7Gl3tGCRk317LClRiz8SOzGtpxGMw/OwAMFFVvdEJgwzfHL+AbTUueF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350867; h=Content-Type: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=wlFjhhn3RPAHKYuNj8Ur+L4ReTenR22KzyO8QJjXINY=; b=DEBCazhQKQmxUXdXgMf91jRgH9E3cNIFPppGbipXNU70VC/jIynYGlBKaGGw5V7T6D/jJBplGGW6nQxDDDunqCKXGr24d049ctzg2jcFTMUNazx4kDXaWa8Tv9hBUj0mvpNebLHMikHMfDLWfwqo/3rZPVq16wQ6n536nfywcO0= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350867545244.0374330368278; Wed, 13 Mar 2024 10:27:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692671.1080025 (Exim 4.92) (envelope-from ) id 1rkSNy-0002LX-SK; Wed, 13 Mar 2024 17:27:26 +0000 Received: by outflank-mailman (output) from mailman id 692671.1080025; Wed, 13 Mar 2024 17:27: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 1rkSNy-0002JF-Mw; Wed, 13 Mar 2024 17:27:26 +0000 Received: by outflank-mailman (input) for mailman id 692671; Wed, 13 Mar 2024 17:27:25 +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 1rkSNx-00023P-SW for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:25 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f4f4daec-e15e-11ee-afdd-a90da7624cb6; Wed, 13 Mar 2024 18:27:24 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-a28a6cef709so11269366b.1 for ; Wed, 13 Mar 2024 10:27:24 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:22 -0700 (PDT) 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: f4f4daec-e15e-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350844; x=1710955644; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wlFjhhn3RPAHKYuNj8Ur+L4ReTenR22KzyO8QJjXINY=; b=GJeeMxi+KKJqEGwVMksOZSo3oH6lFTcjQL9pAIs7VESJnWBZ76YvozGPLTxn9Ainf3 vwSUWdfuXponQlsTw11Uis+6Scr0hEIhYgnKv7mwdln/JhK0K6JVluYCHjcupC+eNryd LAXYzoZhAlvkRJDWwhNrD+xgRq4FmNSWkDJtQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350844; x=1710955644; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wlFjhhn3RPAHKYuNj8Ur+L4ReTenR22KzyO8QJjXINY=; b=iqDB5oK5IJgHTDFvijlxzOnTH87QxXCnzi+BVxovy/361EvLHPhZhFFymRQYFqYa+0 xlY43Rt6i1z/QfysywIKgIf/PtsHqDrWj/fXXBH96h//lXNj+UtBx/10Z2D2HWPJW1ew whWQaJCIkNFcrJmOiXY8j706f9m6DVzhAAoX+qaJmuhvgi2yesU44q69bRSDAmf9mY+z e9lVyohUWelVPSQgED94YHsieymIz6B6zEyvqrCg/zDxk1N4L8pyL2ENhQeR6jH5MFJ7 eG7zXmyUpN3KW4A0Sa0e4iZj8mHwiMWOfaoJVCLVqMghonG8wVo0N/NN7rZ182yHeTLD GLBA== X-Gm-Message-State: AOJu0YzSh06GChDqQvEXzEZ4ugWqLebxNBRBuS8smz1VziY5f3itZZYw DUJZ0J028PS9COEPGTzjtbAQXPBrijt1njIg5W/9Dojq2Y0d6Ns//PoVgy1b8fK2QEH/rAe7gqb q X-Google-Smtp-Source: AGHT+IGyRscQkGqeocdnAjLem4S/ovvLA2xS7fr6bR6SxeaGoAp/cZ5SJUKwtSqtY3P3ypAv9a2rLA== X-Received: by 2002:a17:907:1681:b0:a46:1e16:317c with SMTP id cx1-20020a170907168100b00a461e16317cmr8639997ejd.55.1710350844192; Wed, 13 Mar 2024 10:27:24 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 3/7] xen/bitops: Implement ffsl() in common logic Date: Wed, 13 Mar 2024 17:27:12 +0000 Message-Id: <20240313172716.2325427-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350868318100001 Exactly as per ffs() in the previous patch. Express the upper bound of the testing in terms of BITS_PER_LONG as it varies between architectures. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/arch/arm/include/asm/bitops.h | 2 +- xen/arch/ppc/include/asm/bitops.h | 1 - xen/arch/x86/include/asm/bitops.h | 30 +++++++++++++----------------- xen/common/bitops.c | 7 +++++++ xen/include/xen/bitops.h | 12 ++++++++++++ 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/xen/arch/arm/include/asm/bitops.h b/xen/arch/arm/include/asm/b= itops.h index 09c6064274a7..59ae8ed150b6 100644 --- a/xen/arch/arm/include/asm/bitops.h +++ b/xen/arch/arm/include/asm/bitops.h @@ -158,7 +158,7 @@ static inline int fls(unsigned int x) =20 =20 #define arch_ffs(x) ({ unsigned int __t =3D (x); fls(ISOLATE_LSB(__t)); }) -#define ffsl(x) ({ unsigned long __t =3D (x); flsl(ISOLATE_LSB(__t)); }) +#define arch_ffsl(x) ({ unsigned long __t =3D (x); flsl(ISOLATE_LSB(__t));= }) =20 /** * find_first_set_bit - find the first set bit in @word diff --git a/xen/arch/ppc/include/asm/bitops.h b/xen/arch/ppc/include/asm/b= itops.h index 635a3b4e3e33..ecec2a826660 100644 --- a/xen/arch/ppc/include/asm/bitops.h +++ b/xen/arch/ppc/include/asm/bitops.h @@ -173,7 +173,6 @@ static inline int __test_and_clear_bit(int nr, volatile= void *addr) =20 #define flsl(x) generic_flsl(x) #define fls(x) generic_fls(x) -#define ffsl(x) ({ unsigned long t_ =3D (x); flsl(t_ & -t_); }) =20 /* Based on linux/include/asm-generic/bitops/ffz.h */ /* diff --git a/xen/arch/x86/include/asm/bitops.h b/xen/arch/x86/include/asm/b= itops.h index 2c5b103cbbd9..99342877e32f 100644 --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -413,23 +413,6 @@ static inline unsigned int find_first_set_bit(unsigned= long word) return (unsigned int)word; } =20 -/** - * ffs - find first bit set - * @x: the word to search - * - * This is defined the same way as the libc and compiler builtin ffs routi= nes. - */ -static inline int ffsl(unsigned long x) -{ - long r; - - asm ( "bsf %1,%0\n\t" - "jnz 1f\n\t" - "mov $-1,%0\n" - "1:" : "=3Dr" (r) : "rm" (x)); - return (int)r+1; -} - static inline unsigned int arch_ffs(unsigned int x) { int r =3D -1; @@ -448,6 +431,19 @@ static inline unsigned int arch_ffs(unsigned int x) } #define arch_ffs arch_ffs =20 +static inline unsigned int arch_ffsl(unsigned long x) +{ + long r =3D -1; + + /* See arch_ffs() for safety discussion. */ + asm ( "bsf %[val], %[res]" + : [res] "+r" (r) + : [val] "rm" (x) ); + + return r + 1; +} +#define arch_ffsl arch_ffsl + /** * fls - find last bit set * @x: the word to search diff --git a/xen/common/bitops.c b/xen/common/bitops.c index 484df68768ad..eceffe5029d6 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -40,6 +40,13 @@ static void test_ffs(void) CHECK(ffs, 0, 0); CHECK(ffs, 1, 1); CHECK(ffs, 0x80000000U, 32); + + /* unsigned int ffsl(unsigned long) */ + CHECK(ffsl, 0, 0); + CHECK(ffsl, 1, 1); + CHECK(ffsl, 1UL << (BITS_PER_LONG - 1), BITS_PER_LONG); + if ( BITS_PER_LONG > 32 ) + CHECK(ffsl, 1UL << 32, 33); } =20 static int __init cf_check test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index fb3645d9cf87..a37b42342bc5 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -125,6 +125,18 @@ static always_inline __pure unsigned int ffs(unsigned = int x) return arch_ffs(x); } =20 +static always_inline __pure unsigned int ffsl(unsigned long x) +{ + if ( __builtin_constant_p(x) ) + return __builtin_ffsl(x); + +#ifndef arch_ffsl +#define arch_ffsl __builtin_ffsl +#endif + + return arch_ffsl(x); +} + /* --------------------- Please tidy below here --------------------- */ =20 #ifndef find_next_bit --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350867; cv=none; d=zohomail.com; s=zohoarc; b=c60/kmr+ZNBcOwGiQM6Hz1I0vhuNOhlc4sDK5ifkhGFc8RfnJZBf19TxqUwCy8Ig9XHBmIHSzVQD+xP6eiFiRu7mSrNHAnMA2U6/TU4zFqFed3x1NsUwceFoa87fgoUL6HtDbaK/Up+5Ou0GXfbvqyycpXC8kQN1AXTTSDv9r9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350867; h=Content-Type: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=mpSUgnXdBHSAZ/JHJssOPkagB6hKViTaNFdB8Xxbxeo=; b=EduTVJ3CejkU2SO52KP5D5nYH2iLdVOZjnOkH/AUoPfnYPguFxhVpG4AEWTfB3gTOAktnWyzxo/WsN0owbIVGRaD+Cev33w1vAgsohIwC1fEsu1gEIzLRWAMb6UTa9fOhsvbwcmMbqknUdART8U+0FFnwvT8odd1R3X1ICOb7TA= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350867126983.3638284507206; Wed, 13 Mar 2024 10:27:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692672.1080038 (Exim 4.92) (envelope-from ) id 1rkSO0-0002j7-3K; Wed, 13 Mar 2024 17:27:28 +0000 Received: by outflank-mailman (output) from mailman id 692672.1080038; Wed, 13 Mar 2024 17:27:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSNz-0002j0-W1; Wed, 13 Mar 2024 17:27:27 +0000 Received: by outflank-mailman (input) for mailman id 692672; Wed, 13 Mar 2024 17:27: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 1rkSNy-00023P-LF for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:26 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f5b98a74-e15e-11ee-afdd-a90da7624cb6; Wed, 13 Mar 2024 18:27:26 +0100 (CET) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-513173e8191so163351e87.1 for ; Wed, 13 Mar 2024 10:27:26 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:24 -0700 (PDT) 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: f5b98a74-e15e-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350845; x=1710955645; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mpSUgnXdBHSAZ/JHJssOPkagB6hKViTaNFdB8Xxbxeo=; b=jup611V9n936X50ItOtQ+kutj8v0i4d45mzKYThumoTM/qDp+2SklQJOcbsTXy0fBC fbUOX05OEqllNd3bt09xr5XjygSRR/ZV8KbwbBXSjI/oaAmgj17nZOrL9ZwLQnQOKyPG hT7Hlq52yOhSRdJNt43j2SEnH9WtnhO9UxCbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350845; x=1710955645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mpSUgnXdBHSAZ/JHJssOPkagB6hKViTaNFdB8Xxbxeo=; b=jHPA9HSw2GqnxJul/U94nxdhNNVJQSaCQF0WXWPwjjpe3wp5GbZRU3OzROWJ4DrMXM fXqzqZavS6QL+5ExMHFBlZyuHVpYZ4Pk8Rxjrt0ZTM0oFIYdHLitks9UXYQPfYE9ajyS 7BX1gPc4F7eDlwI2sTAMvcThZJO+DLyjhbCNCvcOV/Wbk3j9OXDCvV6QGgRme71uIG+r 7qqUpDzqZ47mvSTasMUtDjMg1mc4JrggAWWVd55b+cUL6mNitUoWpAb3Ajo7WB4k5D3a Xe8XwtZMWVyTXooxsNAq6x0W7UfNvmbyY/5D6US7zzsg5vOgdpquf9/EjQNA3daSA5ya NTNQ== X-Gm-Message-State: AOJu0YxxteFCekwyfCbMoLNQJjNaQwUcWDijReibM2TkASBd8coADFMg OTkNgdlMF3uL16ETsWkh+tntwOYa+Ulk/Y+d7g34QvmpNc/nppkHeg28PovSH8CaBUyvoiWZQNN M X-Google-Smtp-Source: AGHT+IHHS2BbxMFp3fPdXZlAelFUvd7kXhHTdQ6kdTtsszbGnCM2NvEXDlSzwIEv0B4ltQUsCO1dZA== X-Received: by 2002:a05:6512:3e20:b0:513:acc5:47e with SMTP id i32-20020a0565123e2000b00513acc5047emr3211066lfv.22.1710350845342; Wed, 13 Mar 2024 10:27:25 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 4/7] xen/bitops: Delete generic_ffs{,l}() Date: Wed, 13 Mar 2024 17:27:13 +0000 Message-Id: <20240313172716.2325427-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350868407100003 No more users. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/include/xen/bitops.h | 41 ---------------------------------------- 1 file changed, 41 deletions(-) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index a37b42342bc5..b85b35c40781 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -14,41 +14,6 @@ #define GENMASK_ULL(h, l) \ (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LLONG - 1 - (h)))) =20 -/* - * ffs: find first bit set. This is defined the same way as - * the libc and compiler builtin ffs routines, therefore - * differs in spirit from the above ffz (man ffs). - */ - -static inline int generic_ffs(unsigned int x) -{ - int r =3D 1; - - if (!x) - return 0; - if (!(x & 0xffff)) { - x >>=3D 16; - r +=3D 16; - } - if (!(x & 0xff)) { - x >>=3D 8; - r +=3D 8; - } - if (!(x & 0xf)) { - x >>=3D 4; - r +=3D 4; - } - if (!(x & 3)) { - x >>=3D 2; - r +=3D 2; - } - if (!(x & 1)) { - x >>=3D 1; - r +=3D 1; - } - return r; -} - /* * fls: find last bit set. */ @@ -84,11 +49,6 @@ static inline int generic_fls(unsigned int x) =20 #if BITS_PER_LONG =3D=3D 64 =20 -static inline int generic_ffsl(unsigned long x) -{ - return !x || (u32)x ? generic_ffs(x) : generic_ffs(x >> 32) + 32; -} - static inline int generic_flsl(unsigned long x) { u32 h =3D x >> 32; @@ -97,7 +57,6 @@ static inline int generic_flsl(unsigned long x) } =20 #else -# define generic_ffsl generic_ffs # define generic_flsl generic_fls #endif =20 --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350873; cv=none; d=zohomail.com; s=zohoarc; b=frrxqLcBnkXSM+v+/9NXPHxwUezyZqNEeGlqAABSfXq+T3zxv2Iew5atrZgX7DJpy7VSrqPC7nyYrsXEIQzJ4wxpVqSAnwEsPm2UDL64F7xHDHMTLkNgdJ0S5NyF4/z89B56shmoHjf+60wJs5lAzOOL57c2j5fnYPRcKnXU+mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350873; h=Content-Type: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=bHB0TnvHPBNz/eBFlKRD6r+XgGXUhXiQaqNnXVkmHEM=; b=XzEVkuUouaKi82Ysv0aNuxPd0SqkZd1Tp5+7/ppBTf1S9cYrdrY1Z1WVj5uAdCTlvGcaXigyU3dCX7o08z2pEMDEorgPpQ4QoE6XH4CuT8kB1giijF2+n6D+uvSXvI/QM6/0gTHC45EN+uTNb+F9dBSDSMSVwkH5b+29i9QUs/0= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350873591239.41198576944203; Wed, 13 Mar 2024 10:27:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692673.1080048 (Exim 4.92) (envelope-from ) id 1rkSO2-00031b-Cc; Wed, 13 Mar 2024 17:27:30 +0000 Received: by outflank-mailman (output) from mailman id 692673.1080048; Wed, 13 Mar 2024 17:27:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSO2-00031M-9I; Wed, 13 Mar 2024 17:27:30 +0000 Received: by outflank-mailman (input) for mailman id 692673; Wed, 13 Mar 2024 17:27:29 +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 1rkSO1-0001lR-2a for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:29 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f68109f2-e15e-11ee-a1ee-f123f15fe8a2; Wed, 13 Mar 2024 18:27:27 +0100 (CET) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5686677bda1so2152011a12.0 for ; Wed, 13 Mar 2024 10:27:27 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:25 -0700 (PDT) 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: f68109f2-e15e-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350846; x=1710955646; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bHB0TnvHPBNz/eBFlKRD6r+XgGXUhXiQaqNnXVkmHEM=; b=HdiEIEtty4EKP+6iQXwJ7Bt+loJ55OXEBPtpvmCYFUqN3Zef/4qEwlbqVl4y+sErbQ C5d1l+r2Hlloip+TdwNAW+s7lmnLgWbuC85Mpxppq+Q3SMeECWlQ+w72D/VQUlp85RBh YxFOAn7A0or7U7VSza9aFX2gqhvX3Wj0SRnzo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350846; x=1710955646; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bHB0TnvHPBNz/eBFlKRD6r+XgGXUhXiQaqNnXVkmHEM=; b=Wm22WpHdZS+NjEkcb5Wi90FSbSDCp2Tu8h9JQzWvVkxLPiwDE+Ni11EpEDp822n/0W sPxLNq/kmtVKrATSZaCOj5IxEDXLLRnPOtVWaHcqpeo7G6do12XAdhcKisI+JMlp4o84 xWul3qLDQ7PPbXjjLHAIFeXirNHa5hXrYbTjKOxEdsg8UjcKYqWfYWD7NPzw0LwR73+b yeSJlYuMhbPnpiTHrpqT9it/0jfqlAhHuE0Ds/5CogU3RY9sHWsqdspJ3i7hzSfdqhgr tbUg1Fl4TeYA4gluIAsWtVxIkVjEJ3PZRPrmd3WeBTebKZ8MozQCJcmhKNLUj64S7pKM DoKg== X-Gm-Message-State: AOJu0YxI7yVkuGgvUNwM9/GZH0ccwjvVT/OxIv9JBGprZkpe8oTzfQht tHBQOMBP7jbsNbjVJScMVEYsU8klwSdyv3ywcvBVuFlLnEsQAvAcBtP6fdOak0uxoRVZftGBIUt S X-Google-Smtp-Source: AGHT+IGIO5zs05MQAfaMrOvXvlJvj/CQCBKQvepFuzD0oSVa3+Yg0TZEOonx3qZaJ0qsoNzwif8sQw== X-Received: by 2002:a17:906:b00f:b0:a44:806f:ad56 with SMTP id v15-20020a170906b00f00b00a44806fad56mr2736937ejy.11.1710350846637; Wed, 13 Mar 2024 10:27:26 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 5/7] xen/bitops: Implement ffs64() in common logic Date: Wed, 13 Mar 2024 17:27:14 +0000 Message-Id: <20240313172716.2325427-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350874412100001 As per ffs()/ffsl() in previous patches. Add tests for all interesting bit positions at 32bit boundaries. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/common/bitops.c | 12 ++++++++++++ xen/include/xen/bitops.h | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/common/bitops.c b/xen/common/bitops.c index eceffe5029d6..cd194fe672b7 100644 --- a/xen/common/bitops.c +++ b/xen/common/bitops.c @@ -47,6 +47,18 @@ static void test_ffs(void) CHECK(ffsl, 1UL << (BITS_PER_LONG - 1), BITS_PER_LONG); if ( BITS_PER_LONG > 32 ) CHECK(ffsl, 1UL << 32, 33); + + /* + * unsigned int ffs64(uint64_t) + * + * 32-bit builds of Xen have to split this into two adjacent operation= s, + * so test all interesting bit positions. + */ + CHECK(ffs64, 0, 0); + CHECK(ffs64, 1, 1); + CHECK(ffs64, (uint64_t)0x0000000080000000, 32); + CHECK(ffs64, (uint64_t)0x0000000100000000, 33); + CHECK(ffs64, (uint64_t)0x8000000000000000, 64); } =20 static int __init cf_check test_bitops(void) diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h index b85b35c40781..f14ad0d33aa3 100644 --- a/xen/include/xen/bitops.h +++ b/xen/include/xen/bitops.h @@ -96,6 +96,14 @@ static always_inline __pure unsigned int ffsl(unsigned l= ong x) return arch_ffsl(x); } =20 +static always_inline __pure unsigned int ffs64(uint64_t x) +{ + if ( BITS_PER_LONG =3D=3D 64 ) + return ffsl(x); + else + return !x || (uint32_t)x ? ffs(x) : ffs(x >> 32) + 32; +} + /* --------------------- Please tidy below here --------------------- */ =20 #ifndef find_next_bit @@ -148,15 +156,7 @@ extern unsigned long find_first_zero_bit(const unsigne= d long *addr, =20 #if BITS_PER_LONG =3D=3D 64 # define fls64 flsl -# define ffs64 ffsl #else -# ifndef ffs64 -static inline int generic_ffs64(__u64 x) -{ - return !x || (__u32)x ? ffs(x) : ffs(x >> 32) + 32; -} -# define ffs64 generic_ffs64 -# endif # ifndef fls64 static inline int generic_fls64(__u64 x) { --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350873; cv=none; d=zohomail.com; s=zohoarc; b=N0nIwMvD0sejXqj+q+rCUuCac7cLT8bFU+DuBL+j7mKPzI5oWbwH8Y8sJFFCiUuVadDzTG6Q26AWAj2qeHDiV8r8vCO+TenhRIg1rni6x30V4O9NDnAoNTpd2B/idSXdWhcqgVkTaULPdhamuRW89X2I3GtqT2i2iTwJlHbngIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350873; h=Content-Type: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=42OziT0p0S95gIbK7k1NI+z53JEbfaX+0bPN+VqyNws=; b=NZExAXDKy6dtAxBDbQc9SSJohIVNygAzsJrMzzCyWxqK71ISKb0p1ycePINYb9ePSz5enQuOH15obZFqqz9lSnlxI23/JJdZ0zuzV1sqbrdbpTp4JQtCA4damIJZW2XIeMtb9nMTN/VEQfZIEM9rVbOOsvppzJj8ChZNiBWDs1s= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350873318912.4614546886793; Wed, 13 Mar 2024 10:27:53 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692674.1080058 (Exim 4.92) (envelope-from ) id 1rkSO4-0003KC-NK; Wed, 13 Mar 2024 17:27:32 +0000 Received: by outflank-mailman (output) from mailman id 692674.1080058; Wed, 13 Mar 2024 17:27:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSO4-0003K3-KE; Wed, 13 Mar 2024 17:27:32 +0000 Received: by outflank-mailman (input) for mailman id 692674; Wed, 13 Mar 2024 17:27:30 +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 1rkSO2-0001lR-EE for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:30 +0000 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [2a00:1450:4864:20::636]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f738e570-e15e-11ee-a1ee-f123f15fe8a2; Wed, 13 Mar 2024 18:27:28 +0100 (CET) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a46682e71a9so9111466b.3 for ; Wed, 13 Mar 2024 10:27:28 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:27 -0700 (PDT) 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: f738e570-e15e-11ee-a1ee-f123f15fe8a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350848; x=1710955648; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=42OziT0p0S95gIbK7k1NI+z53JEbfaX+0bPN+VqyNws=; b=NLpoAP1pmRjhQeTgPHFob4IXM4K69d91fLRP41wKjX8WysAXj4kZL0vM96vnQ+z1qV RaDsM8kEfO7IVaTz9pVqkr2+1Lo7mWo2/JB6LpJjuywQQ8ZU2rruXSsjeYI7k3PnyPNc Vu5/9sGuMKo1LShOrJRfCGAB3f1YOQwjoDAIk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350848; x=1710955648; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=42OziT0p0S95gIbK7k1NI+z53JEbfaX+0bPN+VqyNws=; b=GBwY1cv47zhZ5iocf4BPCYspFyaWRP9sOY6jMJeLQUqvExqvcB1duPfURMeH9uoM/T li7WuPzTR0I9wB+PkDOXh+Awhj1ajWhqrDCzgJ1QRO/Iz5pMp1fEJw9HqMEncjM17IWE PtQCwuQmHULv6KM6rnU3yV6289hVO0j/sGF82Emu7WvCGRViYERvDSRcrHfhMRMtI0EJ LBpDe4Efb4HjWHGACGq8zxW996/jIQnPqp8Vt/xU3b5ycAhEU691odoJNpRQScXu3nyL Htgn6O71T13nbUPYzUcU/ZyDBZN5pnYJqDScrpqkDJdaUflNj9HTdfbjN5vA8IOvIlFl +HGQ== X-Gm-Message-State: AOJu0Yws3/bs8krlmaBv68J4QoTLquOrc/nKfOq1HrL92R+nTWkIC8sQ 2eXxFWXXS7cnh0yDqDuW0WxvZmSbzvWgj3yXRgnl8KuHgjzNzHgBkFZHxtUe2rm+qXpYmTT6Fha Q X-Google-Smtp-Source: AGHT+IHDA9kAwEE71Zrgue/ZSZqfSO4un1kmimxgYrjALg0+zIY9/UH8mGWH25XVKZ8g/4LSy1rdDA== X-Received: by 2002:a17:907:104b:b0:a45:bcac:c7e0 with SMTP id oy11-20020a170907104b00b00a45bcacc7e0mr8414663ejb.65.1710350847919; Wed, 13 Mar 2024 10:27:27 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 6/7] xen: Swap find_first_set_bit() for ffsl() - 1 Date: Wed, 13 Mar 2024 17:27:15 +0000 Message-Id: <20240313172716.2325427-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350874446100004 find_first_set_bit() is a Xen-ism which has undefined behaviour with a 0 input. The latter is well defined with an input of 0, and is a found outsi= de of Xen too. _init_heap_pages() is the one special case here, comparing the LSB of two different addresses. The -1 cancels off both sides of the expression. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/arch/x86/guest/xen/xen.c | 4 ++-- xen/arch/x86/hvm/dom0_build.c | 2 +- xen/arch/x86/hvm/hpet.c | 8 ++++---- xen/arch/x86/include/asm/pt-contig-markers.h | 2 +- xen/arch/x86/mm.c | 2 +- xen/arch/x86/mm/p2m-pod.c | 4 ++-- xen/common/page_alloc.c | 2 +- xen/common/softirq.c | 2 +- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/drivers/passthrough/iommu.c | 4 ++-- xen/drivers/passthrough/x86/iommu.c | 4 ++-- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/guest/xen/xen.c b/xen/arch/x86/guest/xen/xen.c index d9768cc9527d..7484b3f73ad3 100644 --- a/xen/arch/x86/guest/xen/xen.c +++ b/xen/arch/x86/guest/xen/xen.c @@ -168,14 +168,14 @@ static void cf_check xen_evtchn_upcall(void) =20 while ( pending ) { - unsigned int l1 =3D find_first_set_bit(pending); + unsigned int l1 =3D ffsl(pending) - 1; unsigned long evtchn =3D xchg(&XEN_shared_info->evtchn_pending[l1]= , 0); =20 __clear_bit(l1, &pending); evtchn &=3D ~XEN_shared_info->evtchn_mask[l1]; while ( evtchn ) { - unsigned int port =3D find_first_set_bit(evtchn); + unsigned int port =3D ffsl(evtchn) - 1; =20 __clear_bit(port, &evtchn); port +=3D l1 * BITS_PER_LONG; diff --git a/xen/arch/x86/hvm/dom0_build.c b/xen/arch/x86/hvm/dom0_build.c index bbae8a564522..7bc092675628 100644 --- a/xen/arch/x86/hvm/dom0_build.c +++ b/xen/arch/x86/hvm/dom0_build.c @@ -139,7 +139,7 @@ static int __init pvh_populate_memory_range(struct doma= in *d, order =3D get_order_from_pages(end - start + 1); order =3D min(order ? order - 1 : 0, max_order); /* The order allocated and populated must be aligned to the addres= s. */ - order =3D min(order, start ? find_first_set_bit(start) : MAX_ORDER= ); + order =3D min(order, start ? ffsl(start) - 1 : MAX_ORDER); page =3D alloc_domheap_pages(d, order, dom0_memflags | MEMF_no_scr= ub); if ( page =3D=3D NULL ) { diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c index 1db9c0b60ee0..30ec14b24110 100644 --- a/xen/arch/x86/hvm/hpet.c +++ b/xen/arch/x86/hvm/hpet.c @@ -336,7 +336,7 @@ static void timer_sanitize_int_route(HPETState *h, unsi= gned int tn) * enabled pick the first irq. */ timer_config(h, tn) |=3D - MASK_INSR(find_first_set_bit(timer_int_route_cap(h, tn)), + MASK_INSR(ffsl(timer_int_route_cap(h, tn)) - 1, HPET_TN_ROUTE); } =20 @@ -410,7 +410,7 @@ static int cf_check hpet_write( { bool active; =20 - i =3D find_first_set_bit(new_val); + i =3D ffsl(new_val) - 1; if ( i >=3D HPET_TIMER_NUM ) break; __clear_bit(i, &new_val); @@ -536,14 +536,14 @@ static int cf_check hpet_write( /* stop/start timers whos state was changed by this write. */ while (stop_timers) { - i =3D find_first_set_bit(stop_timers); + i =3D ffsl(stop_timers) - 1; __clear_bit(i, &stop_timers); hpet_stop_timer(h, i, guest_time); } =20 while (start_timers) { - i =3D find_first_set_bit(start_timers); + i =3D ffsl(start_timers) - 1; __clear_bit(i, &start_timers); hpet_set_timer(h, i, guest_time); } diff --git a/xen/arch/x86/include/asm/pt-contig-markers.h b/xen/arch/x86/in= clude/asm/pt-contig-markers.h index b3c1fe803534..e8c8157d605f 100644 --- a/xen/arch/x86/include/asm/pt-contig-markers.h +++ b/xen/arch/x86/include/asm/pt-contig-markers.h @@ -60,7 +60,7 @@ static bool pt_update_contig_markers(uint64_t *pt, unsign= ed int idx, /* Step 1: Reduce markers in lower numbered entries. */ while ( i ) { - b =3D find_first_set_bit(i); + b =3D ffsl(i) - 1; i &=3D ~(1U << b); if ( GET_MARKER(pt[i]) <=3D b ) break; diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 62f5b811bbe8..28e9a159b577 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3418,7 +3418,7 @@ static int vcpumask_to_pcpumask( { unsigned int cpu; =20 - vcpu_id =3D find_first_set_bit(vmask); + vcpu_id =3D ffsl(vmask) - 1; vmask &=3D ~(1UL << vcpu_id); vcpu_id +=3D vcpu_bias; if ( (vcpu_id >=3D d->max_vcpus) ) diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 65d31e552305..e0ad934d2e30 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -684,7 +684,7 @@ unsigned long p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int ord= er) { unsigned long left =3D 1UL << order, ret =3D 0; - unsigned int chunk_order =3D find_first_set_bit(gfn_x(gfn) | left); + unsigned int chunk_order =3D ffsl(gfn_x(gfn) | left) - 1; =20 do { ret +=3D decrease_reservation(d, gfn, chunk_order); @@ -1384,7 +1384,7 @@ guest_physmap_mark_populate_on_demand(struct domain *= d, unsigned long gfn, unsigned int order) { unsigned long left =3D 1UL << order; - unsigned int chunk_order =3D find_first_set_bit(gfn | left); + unsigned int chunk_order =3D ffsl(gfn | left) - 1; int rc; =20 if ( !paging_mode_translate(d) ) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 2ec17df9b420..812eac51ea0d 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -1817,7 +1817,7 @@ static void _init_heap_pages(const struct page_info *= pg, if ( unlikely(!avail[nid]) ) { bool use_tail =3D IS_ALIGNED(s, 1UL << MAX_ORDER) && - (find_first_set_bit(e) <=3D find_first_set_bit(s)); + (ffsl(e) <=3D ffsl(s)); unsigned long n; =20 n =3D init_node_heap(nid, s, nr_pages, &use_tail); diff --git a/xen/common/softirq.c b/xen/common/softirq.c index 321d26902d37..bee4a82009c3 100644 --- a/xen/common/softirq.c +++ b/xen/common/softirq.c @@ -48,7 +48,7 @@ static void __do_softirq(unsigned long ignore_mask) || cpu_is_offline(cpu) ) break; =20 - i =3D find_first_set_bit(pending); + i =3D ffsl(pending) - 1; clear_bit(i, &softirq_pending(cpu)); (*softirq_handlers[i])(); } diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthro= ugh/amd/iommu_map.c index e0f4fe736a8d..f1061bfc798c 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -137,7 +137,7 @@ static void set_iommu_ptes_present(unsigned long pt_mfn, ASSERT(!pde->u); =20 if ( pde > table ) - ASSERT(pde->ign0 =3D=3D find_first_set_bit(pde - table)); + ASSERT(pde->ign0 =3D=3D ffsl(pde - table) - 1); else ASSERT(pde->ign0 =3D=3D CONTIG_LEVEL_SHIFT); =20 diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iomm= u.c index 996c31be1284..67dd8e5cd9e1 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -301,7 +301,7 @@ static unsigned int mapping_order(const struct domain_i= ommu *hd, { unsigned long res =3D dfn_x(dfn) | mfn_x(mfn); unsigned long sizes =3D hd->platform_ops->page_sizes; - unsigned int bit =3D find_first_set_bit(sizes), order =3D 0; + unsigned int bit =3D ffsl(sizes) - 1, order =3D 0; =20 ASSERT(bit =3D=3D PAGE_SHIFT); =20 @@ -309,7 +309,7 @@ static unsigned int mapping_order(const struct domain_i= ommu *hd, { unsigned long mask; =20 - bit =3D find_first_set_bit(sizes); + bit =3D ffsl(sizes) - 1; mask =3D (1UL << bit) - 1; if ( nr <=3D mask || (res & mask) ) break; diff --git a/xen/drivers/passthrough/x86/iommu.c b/xen/drivers/passthrough/= x86/iommu.c index a3fa0aef7c37..d721ea27a033 100644 --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -641,7 +641,7 @@ struct page_info *iommu_alloc_pgtable(struct domain_iom= mu *hd, if ( contig_mask ) { /* See pt-contig-markers.h for a description of the marker scheme.= */ - unsigned int i, shift =3D find_first_set_bit(contig_mask); + unsigned int i, shift =3D ffsl(contig_mask) - 1; =20 ASSERT((CONTIG_LEVEL_SHIFT & (contig_mask >> shift)) =3D=3D CONTIG= _LEVEL_SHIFT); =20 @@ -652,7 +652,7 @@ struct page_info *iommu_alloc_pgtable(struct domain_iom= mu *hd, =20 for ( i =3D 4; i < PAGE_SIZE / sizeof(*p); i +=3D 4 ) { - p[i + 0] =3D (find_first_set_bit(i) + 0ULL) << shift; + p[i + 0] =3D (ffsl(i) - 1ULL) << shift; p[i + 1] =3D 0; p[i + 2] =3D 1ULL << shift; p[i + 3] =3D 0; --=20 2.30.2 From nobody Fri May 17 16:24:23 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=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1710350876; cv=none; d=zohomail.com; s=zohoarc; b=iOtQaAVFNbcPESld1LVOGdBWn3YHgPpGMctCup12UNgdxAXGlkbzoMJiFpxLU0DUqZPrYLSPHd9HMqBOqfN6x7C55B/x4hk1d1ThSF8uUCoScBQWIt5TCn2M8PaqCyg4+OT1SXd4oJVTAHhxycvSVykPrWiBJYiYSvv+bXW8sXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710350876; h=Content-Type: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=33TXDSAxPDO8bnXw5DlUbCOINftbDhFb4uNtskElrXY=; b=Y5N6eXCGTPdjkf0385CT/3RZYV34EzvZX5G/x/IV2tIZq27QAcNaEOlu9iX3JqJH8akgbY3bIQolKLIuZ8yPUZhg4NmQmQIwxct2wXH5c++Xi9LW25Z2fYNdU+vhi7omAAWN4y1V0PbvqmUQci16Nvb0NuW8i5jSeYo/QRwCRL4= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1710350876160565.4273090348189; Wed, 13 Mar 2024 10:27:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.692675.1080062 (Exim 4.92) (envelope-from ) id 1rkSO5-0003NP-1g; Wed, 13 Mar 2024 17:27:33 +0000 Received: by outflank-mailman (output) from mailman id 692675.1080062; Wed, 13 Mar 2024 17:27:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rkSO4-0003MV-Rh; Wed, 13 Mar 2024 17:27:32 +0000 Received: by outflank-mailman (input) for mailman id 692675; Wed, 13 Mar 2024 17:27:30 +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 1rkSO2-00023P-Se for xen-devel@lists.xenproject.org; Wed, 13 Mar 2024 17:27:30 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f8401d88-e15e-11ee-afdd-a90da7624cb6; Wed, 13 Mar 2024 18:27:30 +0100 (CET) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-513cc23b93aso134352e87.2 for ; Wed, 13 Mar 2024 10:27:30 -0700 (PDT) Received: from andrewcoop.citrite.net (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id f15-20020a170906048f00b00a42ee62b634sm5005732eja.106.2024.03.13.10.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:27:28 -0700 (PDT) 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: f8401d88-e15e-11ee-afdd-a90da7624cb6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1710350849; x=1710955649; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=33TXDSAxPDO8bnXw5DlUbCOINftbDhFb4uNtskElrXY=; b=GQDGzq70NgXh8q66UCQMVnMT511HyPobC7cKbWr7LRG7LUyTtuOIGe4JUrdclFzeCr HjS2wRh9DvXQZKzgNCfbAmtx1X1tfMwyFn7DKcEmkXCKjMJYfIxMFY3LMdhxSl/1tCfM qkyTiQgr447cwrJDYlCt8nj0aktwFfmcUGZTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710350849; x=1710955649; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=33TXDSAxPDO8bnXw5DlUbCOINftbDhFb4uNtskElrXY=; b=v0jz6G5XE+Fgj3mJKismko8oY4a+v7uTCtKGd7o8+bGtbS2omd09yawy/TIZwU6Zhg SrHXl65PgUS8B9pzMiXsnVLaO0SFCDdV1BjNnaBJv6/pfMSbGvA5Xp6AiRqVPLyq2rmU QNDlkXm+MKGa7Cag0g9OnQ/sxJYxDWm+T8JVBrjiRPJZrYdfgMLhb7LBEhKfyRdoykyE SQAo81vOfnLFKauNNjHbMq/4bEXTns3P6Mkl1BqF5Z5eKza7oXXBOVTLLfAOtU3wGkv6 fJrmapDvP7/OJ7IlhdRw8vRL4c8VSMy9+z9c6e2ztSyli0FImnj81h7wpBoVXR4IG1NU +HIw== X-Gm-Message-State: AOJu0YwmQrUQ25pxf008pYpjHwGnLYPdiy2UEDxofqwJ1coMxTHyWs+G xxywgzzPP74WKUjr/a0hn1CKO7cVX/UuMJqAMHu2T3VQVrm6XXuVfqic3F+NCwuIhgP3oAOlSi4 i X-Google-Smtp-Source: AGHT+IH+wJrXbeahOJLqrDjcYaBZ9zU2I/cXRNPjMfx4C/xQoBg042rLDW5ZSKpV7udLszZCL7H5+w== X-Received: by 2002:a05:6512:239f:b0:513:b8c7:7ecc with SMTP id c31-20020a056512239f00b00513b8c77eccmr3385947lfv.60.1710350849218; Wed, 13 Mar 2024 10:27:29 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Michal Orzel , Oleksii Kurochko , Shawn Anastasio , "consulting @ bugseng . com" , Simone Ballarin , Federico Serafini , Nicola Vetrini Subject: [PATCH 7/7] xen/bitops: Delete find_first_set_bit() Date: Wed, 13 Mar 2024 17:27:16 +0000 Message-Id: <20240313172716.2325427-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240313172716.2325427-1-andrew.cooper3@citrix.com> References: <20240313172716.2325427-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1710350878301100001 No more users. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk CC: Bertrand Marquis CC: Michal Orzel CC: Oleksii Kurochko CC: Shawn Anastasio CC: consulting@bugseng.com CC: Simone Ballarin CC: Federico Serafini CC: Nicola Vetrini --- xen/arch/arm/include/asm/bitops.h | 12 ------------ xen/arch/ppc/include/asm/bitops.h | 9 --------- xen/arch/x86/include/asm/bitops.h | 12 ------------ 3 files changed, 33 deletions(-) diff --git a/xen/arch/arm/include/asm/bitops.h b/xen/arch/arm/include/asm/b= itops.h index 59ae8ed150b6..5104334e4874 100644 --- a/xen/arch/arm/include/asm/bitops.h +++ b/xen/arch/arm/include/asm/bitops.h @@ -160,18 +160,6 @@ static inline int fls(unsigned int x) #define arch_ffs(x) ({ unsigned int __t =3D (x); fls(ISOLATE_LSB(__t)); }) #define arch_ffsl(x) ({ unsigned long __t =3D (x); flsl(ISOLATE_LSB(__t));= }) =20 -/** - * find_first_set_bit - find the first set bit in @word - * @word: the word to search - * - * Returns the bit-number of the first set bit (first bit being 0). - * The input must *not* be zero. - */ -static inline unsigned int find_first_set_bit(unsigned long word) -{ - return ffsl(word) - 1; -} - /** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh diff --git a/xen/arch/ppc/include/asm/bitops.h b/xen/arch/ppc/include/asm/b= itops.h index ecec2a826660..989d341a44c7 100644 --- a/xen/arch/ppc/include/asm/bitops.h +++ b/xen/arch/ppc/include/asm/bitops.h @@ -206,13 +206,4 @@ static always_inline unsigned long __ffs(unsigned long= word) return __builtin_ctzl(word); } =20 -/** - * find_first_set_bit - find the first set bit in @word - * @word: the word to search - * - * Returns the bit-number of the first set bit (first bit being 0). - * The input must *not* be zero. - */ -#define find_first_set_bit(x) (ffsl(x) - 1) - #endif /* _ASM_PPC_BITOPS_H */ diff --git a/xen/arch/x86/include/asm/bitops.h b/xen/arch/x86/include/asm/b= itops.h index 99342877e32f..2835bb6814d5 100644 --- a/xen/arch/x86/include/asm/bitops.h +++ b/xen/arch/x86/include/asm/bitops.h @@ -401,18 +401,6 @@ static always_inline unsigned int __scanbit(unsigned l= ong val, unsigned int max) r__; = \ }) =20 -/** - * find_first_set_bit - find the first set bit in @word - * @word: the word to search - *=20 - * Returns the bit-number of the first set bit. The input must *not* be ze= ro. - */ -static inline unsigned int find_first_set_bit(unsigned long word) -{ - asm ( "rep; bsf %1,%0" : "=3Dr" (word) : "rm" (word) ); - return (unsigned int)word; -} - static inline unsigned int arch_ffs(unsigned int x) { int r =3D -1; --=20 2.30.2