From nobody Mon Feb 9 17:25:20 2026 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