[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/2] xen: Change parameter of generic_{fls,ffs}() to unsigned int


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Tue, 5 Sep 2023 09:31:35 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7ttBx/RLfvS/dpP2YFQ9lhSCOmO9pCv8GBtM7hOK5HY=; b=TdQ7GGnQpL2+aRwiKuVazqoQi0N8R/BSndhvjvPCaP9jNf0Z+PMmF3UvIfo6Yth7XjZOpYFnBaKeAdf/QuPVsBnwgnexN0Z/i6KYWiYIavzqq6Fvxlqm4ggTh/LQp8C1ZyFJilAdd1TNn5IXQFPVuCcPQRu6kYevFOILXc1nWb3gs2WmQTnWP6wtYqE2/Kli9hnMRESPcEQkLVK9q/Xmb9TAW51AVq3Pp7tmCIo/LrhyxCDuuKBLfBFvFsnqsFGWgFOPe/pOuslehwAgpG8rdC/xg8dWraqB4aP8IGxWXoHb4js20t0gmStNhvviP9W11S7idGs4p3n7nxYmq3HUgw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eaUmqwAvbS0bq6t6s2ZB5/xGhmszoBwoG9dbVmFgl6dMO1cSnjZd0e3QnhXKYHVWtjj2u6PHMtOcSWpwKnMFX++hQ26QBmC+LTKpiM7bNlB+HH0+ueU0oHzncCiRo3rni2R8y221nzPeoEdrddEuqAWWsmGM/jfz+f/2HgMprgu4P/L8A0tcwk26OZdFoukuKvLQlVSAUeWcY/HcjCEiQR/fv5cB3Yf33vGApxdpYyaH2LZRiK+KJLRaVJxJd9Bujnxf16q237kIBQ9MJ1KshfdmoSfbVIiN98sx44yPdtDiLnV07sLzwVnTJYmqiR+i/oLvcMByAPW6R1MAiErMxw==
  • Cc: Michal Orzel <michal.orzel@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, "Jan Beulich" <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, <Henry.Wang@xxxxxxx>
  • Delivery-date: Tue, 05 Sep 2023 07:32:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When running with SMMUv3 and UBSAN enabled on arm64, there are a lot of
warnings printed related to shifting into sign bit in generic_fls()
as it takes parameter of type int.

Example:
(XEN) UBSAN: Undefined behaviour in ./include/xen/bitops.h:69:11
(XEN) left shift of 134217728 by 4 places cannot be represented in type 'int'

It does not make a lot of sense to ask for the last set bit of a negative
value. We don't have a direct user of this helper and all the wrappers
pass value of type unsigned {int,long}.

Linux did the same as part of commit:
3fc2579e6f16 ("fls: change parameter to unsigned int")

To keep consistency between the helpers, take the opportunity to:
 - replace __inline__ with inline,
 - modify generic_ffs() to take parameter of type unsigned int as well
   (currently no user and the only wrapper generic_ffsl() passes unsigned
   long).

Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
---
Changes in v2:
 - as requested by Jan, s/__inline__/inline/ and modify generic_ffs()
   for consistency

It looks like generic_fls() is only used by Arm and invoked only if
the arguement passed is a compile time constant. This is true for SMMUv3
which makes use of ffs64() in FIELD_{PREP,GET} macros. generic_ffs() has no
user at the moment.

Note for the future:
The return type could be unsigned as well. However, looking at all variations
of the helpers to find first set/clear in the codebase, returning int is the
de-facto standard. Changing the return type of the title helpers would result
in inconsistency or require to do modifications in other places which is not
something I want to do at this stage of release.
---
 xen/include/xen/bitops.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/xen/bitops.h b/xen/include/xen/bitops.h
index 654f525fb437..edd6817d5356 100644
--- a/xen/include/xen/bitops.h
+++ b/xen/include/xen/bitops.h
@@ -18,7 +18,7 @@
  * differs in spirit from the above ffz (man ffs).
  */
 
-static inline int generic_ffs(int x)
+static inline int generic_ffs(unsigned int x)
 {
     int r = 1;
 
@@ -51,7 +51,7 @@ static inline int generic_ffs(int x)
  * fls: find last bit set.
  */
 
-static __inline__ int generic_fls(int x)
+static inline int generic_fls(unsigned int x)
 {
     int r = 32;
 
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.