Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-50732

kernel: Constant HUGETLB_FLAG_ENCODE_16GB has questionable definition in hugetlb_encode.h

    • kernel-5.14.0-521.el9
    • No
    • Low
    • Patch
    • 3
    • rhel-sst-kernel-ft
    • ssg_core_kernel
    • 2
    • 4
    • 1
    • QE ack, Dev ack
    • False
    • Hide

      None

      Show
      None
    • None
    • Red Hat Enterprise Linux
    • CK-September-2024, CK-October-2024, CK-November-2024
    • All
    • None

      The kernel-headers-5.14.0-427.26.1.el9_4.x86_64 package has this in /usr/include/asm-generic/hugetlb_encode.h:

      #define HUGETLB_FLAG_ENCODE_SHIFT       26
      #define HUGETLB_FLAG_ENCODE_16GB        (34 << HUGETLB_FLAG_ENCODE_SHIFT)
      

       This is undefined C and has later been changed in this upstream commit:

      commit 710bb68c2e3a24512e2d2bae470960d7488e97b1
      Author: Matthias Goergens <matthias.goergens@gmail.com>
      Date:   Mon Sep 5 11:19:04 2022 +0800
      
          hugetlb_encode.h: fix undefined behaviour (34 << 26)
          
          Left-shifting past the size of your datatype is undefined behaviour in C.
          The literal 34 gets the type `int`, and that one is not big enough to be
          left shifted by 26 bits.
          
          An `unsigned` is long enough (on any machine that has at least 32 bits for
          their ints.)
          
          For uniformity, we mark all the literals as unsigned.  But it's only
          really needed for HUGETLB_FLAG_ENCODE_16GB.
          
          Thanks to Randy Dunlap for an initial review and suggestion.
          
          Link: https://lkml.kernel.org/r/20220905031904.150925-1-matthias.goergens@gmail.com
          Signed-off-by: Matthias Goergens <matthias.goergens@gmail.com>
          Acked-by: Randy Dunlap <rdunlap@infradead.org>
          Cc: Mike Kravetz <mike.kravetz@oracle.com>
          Cc: Muchun Song <songmuchun@bytedance.com>
          Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
      

      Current (upstream) glibc expects this fixed definition, result in a slightly annoying glibc test suite failure.

              llong@redhat.com Waiman Long
              fweimer@redhat.com Florian Weimer
              Memory Management Maintainers Memory Management Maintainers
              Li Wang Li Wang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: