Skip to content

Don't use BIT() macro in UAPI headers

Joe Richey kvm linux-arm-kernel linux-media lkml 2 versions – Applied

Status from this message: The following commit has been merged into the x86/misc branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest7 patches 4 repliesApplied
  2. v16 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- Use _BITUL() macro instead of open-coding
- Fixup HWCAP2_RING3MWAIT as well
- Shorten commits and added "Fixes" per reviewer comments
- checkpatch: Broaden UAPI regex
- checkpatch: Reccomend _BITULL()/_BITUL() for UAPI headers

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/7x86/elf: Use _BITUL() macro in UAPI headersarch/x86/include/uapi/asm/hwcap2.h+4 -20 replies
2/7KVM: X86: Use _BITUL() macro in UAPI headersinclude/uapi/linux/kvm.h tools/include/uapi/linux/kvm.h+6 -41 reply
3/7drivers: firmware: psci: Use _BITUL() macro in UAPI headersinclude/uapi/linux/psci.h+3 -11 reply
4/7uacce: Use _BITUL() macro in UAPI headersinclude/uapi/misc/uacce/uacce.h+2 -11 reply
5/7media: vicodec: Use _BITUL() macro in UAPI headersinclude/uapi/linux/v4l2-controls.h+12 -110 replies
6/7tools headers UAPI: Sync pkt_sched.h with the kernel sourcestools/include/uapi/linux/pkt_sched.h+112 -100 replies
7/7checkpatch: suggest _BITULL() and _BITUL() for UAPI headersscripts/checkpatch.pl+9 -71 reply

Reviews trailers per patch

2 of 7 patches have a Reviewed-by or Acked-by.

PatchMark RutlandZhangfei Gao
1/7
2/7
3/7A-b
4/7A-b
5/7
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/7] Don't use BIT() macro in UAPI headers

From: Joe Richey <[email protected]>

The BIT(n) macro is used in the kernel as an alias for (1 << n). However, it is not defined in the UAPI headers, they should instead use the _BITUL(n) macro. This patch chages all existing usages in UAPI headers and updates ./scripts/checkpatch.pl to properly reccomend the correct macro depending on context.

Running the below commands shows no more incorrect macro usages:

    rg "BIT\(" **/uapi/**
    rg "BIT_ULL\(" **/uapi/**

Tested by building a basic kernel. Changes are trivial.

I encountered this issue when compiling the following program:

    #include <sys/auxv.h>
    #include <asm/hwcap2.h>
    // Detect if FSGSBASE instructions are enabled
    int main() {
        unsigned long val = getauxval(AT_HWCAP2);
        return !(val & HWCAP2_FSGSBASE);
    }

Resulting in the following likner error:
/usr/bin/ld: /tmp/cceFpAdR.o: in function `main':
gs.c:(.text+0x21): undefined reference to `BIT'

Changes from V1 to V2:
- Use _BITUL() macro instead of open-coding
- Fixup HWCAP2_RING3MWAIT as well
- Shorten commits and added "Fixes" per reviewer comments
- checkpatch: Broaden UAPI regex
- checkpatch: Reccomend _BITULL()/_BITUL() for UAPI headers

Joe Richey (7):
x86/elf: Use _BITUL() macro in UAPI headers
KVM: X86: Use _BITUL() macro in UAPI headers
drivers: firmware: psci: Use _BITUL() macro in UAPI headers
uacce: Use _BITUL() macro in UAPI headers
media: vicodec: Use _BITUL() macro in UAPI headers tools headers UAPI: Sync pkt_sched.h with the kernel sources
checkpatch: suggest _BITULL() and _BITUL() for UAPI headers

 arch/x86/include/uapi/asm/hwcap2.h   |   6 +-
 include/uapi/linux/kvm.h             |   5 +-
 include/uapi/linux/psci.h            |   4 +-
 include/uapi/linux/v4l2-controls.h   |  23 ++---
 include/uapi/misc/uacce/uacce.h      |   3 +-
 scripts/checkpatch.pl                |  16 ++--
 tools/include/uapi/linux/kvm.h       |   5 +-
 tools/include/uapi/linux/pkt_sched.h | 122 ++++++++++++++++++++++++---
 8 files changed, 148 insertions(+), 36 deletions(-)
Signature · 1 line
2.31.1