From patchwork Mon May 6 10:15:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13655245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27C44C10F16 for ; Mon, 6 May 2024 10:15:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.717434.1119667 (Exim 4.92) (envelope-from ) id 1s3vNf-0002Rl-V6; Mon, 06 May 2024 10:15:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 717434.1119667; Mon, 06 May 2024 10:15:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1s3vNf-0002Qn-NY; Mon, 06 May 2024 10:15:35 +0000 Received: by outflank-mailman (input) for mailman id 717434; Mon, 06 May 2024 10:15:33 +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 1s3vNd-0001cU-PX for xen-devel@lists.xenproject.org; Mon, 06 May 2024 10:15:33 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 92a33655-0b91-11ef-909c-e314d9c70b13; Mon, 06 May 2024 12:15:33 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a59b49162aeso318484966b.3 for ; Mon, 06 May 2024 03:15:33 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id h8-20020a17090634c800b00a59b8e16ac7sm2160242ejb.36.2024.05.06.03.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 03:15:32 -0700 (PDT) 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: 92a33655-0b91-11ef-909c-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714990532; x=1715595332; 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=HJ4ONEZyJqQciNKYxaBQg/mppiyTg6XZa2ET+ksHj5Y=; b=dbZekPFR769FL1tAFtTjP0EW7I19ctISNgUPasRG3A75WbM+k7ud9WOahfQtifQjxy atnyXfZqr/WVUsOREhxc72VL0S2jany/TiFlr2lnZAo2BRspJd/Blo2PfQuHsyVtaKCo VOHDDoNLRBl+/km6ghRtLRQnCpRMNCP/C4Dt9lwrYeckCifi1xMs8F82VNy9m+P1SfWj tpT/4A4JyNO3hQ2oepxPm0ZDKcepxUxfjAEIT3pVFl4yBNNQgSmlI5xfVMDImQB2d1Jo afKHMLrTjqwYLkHsLr+MqeniEll7RDsT6MUITDLz/FS5T1yoJ6btWlpTpZmlCK421gB2 iirA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714990532; x=1715595332; 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=HJ4ONEZyJqQciNKYxaBQg/mppiyTg6XZa2ET+ksHj5Y=; b=XO/f5DrkyJGqEfcIG6CebQfnsvGRoMUDyxjpvla5EGHCgpPPEvg/kCzOlWF06pYE/i buRPgMqOc2WtYuZd6pMWzkQiFYMdOBQvL6JmGCa1R+QR/bSaWx+hg1LziJYsyfmuMWlZ CSGmMT3vZB9CiljBlz7M6GXkU8YGgC4DVovbPCJ/ktriq6ZVbAQaCQOkoXo37A4ZOOFX CCww0Z2xxl2vGo+xkpynOxeJzyDpMRR060Bc6GbIZKUym6ZSXMNBIU8SLfsYVE/bloiC tqoCs/TzvXXU/NphkyUBwvaiYb/fIWXVdLsrFy4nnhNmavp7wwrc/dtF8X7xKEzl1lRt D+cg== X-Gm-Message-State: AOJu0YyWrFO7iaPRi4qp706HkemiC6D7MrgA6D+e+FKCB53em4+48RPf 9G2Nhh3BXrAgVAXc6m2kkpYF6w7dG9cj7qk+5ZD/XcUVrAnxZ00t1VrDYA== X-Google-Smtp-Source: AGHT+IEyiSX0ZrAYQlbQ+yXOPTKDOcWShyOAiEUWqGNjgpbNhCquuXTWMg5liaftvBSjkrVr5aOkOA== X-Received: by 2002:a17:907:9493:b0:a59:bacc:b086 with SMTP id dm19-20020a170907949300b00a59baccb086mr3381844ejc.50.1714990532394; Mon, 06 May 2024 03:15:32 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Shawn Anastasio , Rahul Singh Subject: [PATCH v9 04/15] xen/bitops: put __ffs() into linux compatible header Date: Mon, 6 May 2024 12:15:13 +0200 Message-ID: <4ef575389520479cee0a79fccfc20e6891594d61.1714988096.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: References: MIME-Version: 1.0 The mentioned macros exist only because of Linux compatible purpose. The patch defines __ffs() in terms of Xen bitops and it is safe to define in this way ( as __ffs() - 1 ) as considering that __ffs() was defined as __builtin_ctzl(x), which has undefined behavior when x=0, so it is assumed that such cases are not encountered in the current code. To not include to Xen library files __ffs() and __ffz() were defined locally in find-next-bit.c. Except __ffs() usage in find-next-bit.c only one usage of __ffs() leave in smmu-v3.c. It seems that it __ffs can be changed to ffsl(x)-1 in this file, but to keep smmu-v3.c looks close to linux it was deciced just to define __ffs() in xen/linux-compat.h and include it in smmu-v3.c Signed-off-by: Oleksii Kurochko Acked-by: Shawn Anastasio Reviewed-by: Jan Beulich Acked-by: Michal Orzel Acked-by: Rahul Singh --- Changes in V9: - update the defintion of __ffs in xen/linux-compat.h. - add Reviewed-by: Jan Beulich - add Acked-by: Shawn Anastasio for PPC part which I missed to add in the previous patch version. --- Changes in V8: - drop ffz() for PPC as there is no any usage of it and it seems to me that it was introduced only because Arm has it, and Arm uses it only in find-next-bit.c where ffz() was moved to. - add Acked-by: Shawn Anastasio for PPC part. --- Changes in V7: - introduce ffz(),__ffs() locally in find-next-bit.c - drop inclusion of in find-next-bit.c. - update the commit message. --- Changes in V6: - new patch for the patch series. --- xen/arch/arm/include/asm/arm64/bitops.h | 21 --------------------- xen/arch/ppc/include/asm/bitops.h | 21 --------------------- xen/drivers/passthrough/arm/smmu-v3.c | 2 ++ xen/include/xen/linux-compat.h | 2 ++ xen/lib/find-next-bit.c | 3 +++ 5 files changed, 7 insertions(+), 42 deletions(-) diff --git a/xen/arch/arm/include/asm/arm64/bitops.h b/xen/arch/arm/include/asm/arm64/bitops.h index 5f5d97faa0..2deb134388 100644 --- a/xen/arch/arm/include/asm/arm64/bitops.h +++ b/xen/arch/arm/include/asm/arm64/bitops.h @@ -1,27 +1,6 @@ #ifndef _ARM_ARM64_BITOPS_H #define _ARM_ARM64_BITOPS_H -/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */ -/** - * __ffs - find first bit in word. - * @word: The word to search - * - * Undefined if no bit exists, so code should check against 0 first. - */ -static /*__*/always_inline unsigned long __ffs(unsigned long word) -{ - return __builtin_ctzl(word); -} - -/* Based on linux/include/asm-generic/bitops/ffz.h */ -/* - * ffz - find first zero in word. - * @word: The word to search - * - * Undefined if no zero exists, so code should check against ~0UL first. - */ -#define ffz(x) __ffs(~(x)) - static inline int arch_flsl(unsigned long x) { uint64_t ret; diff --git a/xen/arch/ppc/include/asm/bitops.h b/xen/arch/ppc/include/asm/bitops.h index ca308fd62b..2237b9f8f4 100644 --- a/xen/arch/ppc/include/asm/bitops.h +++ b/xen/arch/ppc/include/asm/bitops.h @@ -119,15 +119,6 @@ static inline int test_and_set_bit(unsigned int nr, volatile void *addr) (volatile unsigned int *)addr + BITOP_WORD(nr)) != 0; } -/* Based on linux/include/asm-generic/bitops/ffz.h */ -/* - * ffz - find first zero in word. - * @word: The word to search - * - * Undefined if no zero exists, so code should check against ~0UL first. - */ -#define ffz(x) __ffs(~(x)) - /** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh @@ -139,16 +130,4 @@ static inline int test_and_set_bit(unsigned int nr, volatile void *addr) #define hweight16(x) __builtin_popcount((uint16_t)(x)) #define hweight8(x) __builtin_popcount((uint8_t)(x)) -/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */ -/** - * __ffs - find first bit in word. - * @word: The word to search - * - * Undefined if no bit exists, so code should check against 0 first. - */ -static always_inline unsigned long __ffs(unsigned long word) -{ - return __builtin_ctzl(word); -} - #endif /* _ASM_PPC_BITOPS_H */ diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c index b1c40c2c0a..6904962467 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -72,12 +72,14 @@ */ #include +#include #include #include #include #include #include #include +#include #include #include #include diff --git a/xen/include/xen/linux-compat.h b/xen/include/xen/linux-compat.h index 62ba71485c..b289dfd894 100644 --- a/xen/include/xen/linux-compat.h +++ b/xen/include/xen/linux-compat.h @@ -19,4 +19,6 @@ typedef int64_t __s64; typedef paddr_t phys_addr_t; +#define __ffs(x) (ffsl(x) - 1UL) + #endif /* __XEN_LINUX_COMPAT_H__ */ diff --git a/xen/lib/find-next-bit.c b/xen/lib/find-next-bit.c index ca6f82277e..761b027398 100644 --- a/xen/lib/find-next-bit.c +++ b/xen/lib/find-next-bit.c @@ -12,6 +12,9 @@ #include +#define __ffs(x) (ffsl(x) - 1) +#define ffz(x) __ffs(~(x)) + #ifndef find_next_bit /* * Find the next set bit in a memory region.