1. 12 Jan, 2023 7 commits
    • Linus Torvalds's avatar
      Merge tag 'sched-urgent-2023-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · ea66bf86
      Linus Torvalds authored
      Pull scheduler fixes from Ingo Molnar:
      
       - Fix scheduler frequency invariance bug related to overly long
         tickless periods triggering an integer overflow and disabling the
         feature.
      
       - Fix use-after-free bug in dup_user_cpus_ptr().
      
       - Fix do_set_cpus_allowed() deadlock scenarios related to calling
         kfree() with the pi_lock held. NOTE: the rcu_free() is the 'lazy'
         solution here - we looked at patches to free the structure after the
         pi_lock got dropped, but that looked quite a bit messier - and none
         of this is truly performance critical. We can revisit this if it's
         too lazy of a solution ...
      
      * tag 'sched-urgent-2023-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        sched/core: Use kfree_rcu() in do_set_cpus_allowed()
        sched/core: Fix use-after-free bug in dup_user_cpus_ptr()
        sched/core: Fix arch_scale_freq_tick() on tickless systems
      ea66bf86
    • Linus Torvalds's avatar
      Merge tag 'core-urgent-2023-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip · cf4d5be8
      Linus Torvalds authored
      Pull objtool fix from Ingo Molnar:
      
       - Fix objtool to be more permissive with hand-written assembly that
         uses non-function symbols in executable sections.
      
      * tag 'core-urgent-2023-01-12' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
        objtool: Tolerate STT_NOTYPE symbols at end of section
      cf4d5be8
    • Linus Torvalds's avatar
      Merge tag 'urgent-nolibc.2023.01.09a' of... · f129b616
      Linus Torvalds authored
      Merge tag 'urgent-nolibc.2023.01.09a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
      
      Pull nolibc fixes from Paul McKenney:
      
       - The fd_set structure was incorrectly defined as arrays of u32 instead
         of long, which breaks BE64. Fix courtesy of Sven Schnelle.
      
       - S_ISxxx macros were incorrectly testing the bits after applying them
         instead of bitwise ANDing S_FMT with the value. Fix from Warner Losh.
      
       - The mips code was randomly broken due to an unprotected "noreorder"
         directive in the _start code that could prevent the assembler from
         filling delayed slots. This in turn resulted in random other
         instructions being placed into those slots. Fix courtesy of Willy
         Tarreau.
      
       - The current nolibc header layout refrains from including files that
         are not explicitly included by the code using nolibc. Unfortunately,
         this causes build failures when such files contain definitions that
         are used (for example) by libgcc. Example definitions include raise()
         and memset(), which are called by some architectures, but only at
         certain optimization levels. Fix courtesy of Willy Tarreau.
      
       - gcc 11.3 in ARM thumb2 mode at -O2 recognized a memset() construction
         inside the memset() definition. The compiler replaced this
         construction with a call to... memset(). Userland cannot be forced to
         build with -ffreestanding, so an empty asm() statement was introduced
         into the loop the loop in order to prevent the compiler from making
         this unproductive transformation. Fix courtesy of Willy Tarreau.
      
       - Most of the O_* macros were wrong on RISCV because their octal values
         were coded as hexadecimal. This resulted in the getdents64() selftest
         failing. Fix courtesy of Willy Tarreau.
      
      This was tested on x86_64, i386, armv5, armv7, thumb1, thumb2, mips and
      riscv, all at -O0, -Os and -O3.
      
      * tag 'urgent-nolibc.2023.01.09a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu:
        tools/nolibc: fix the O_* fcntl/open macro definitions for riscv
        tools/nolibc: prevent gcc from making memset() loop over itself
        tools/nolibc: fix missing includes causing build issues at -O0
        tools/nolibc: restore mips branch ordering in the _start block
        tools/nolibc: Fix S_ISxxx macros
        nolibc: fix fd_set type
      f129b616
    • Linus Torvalds's avatar
      Merge tag 'spi-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi · c757fc92
      Linus Torvalds authored
      Pull spi fixes from Mark Brown:
      
       - Fixes for long standing issues with accesses to spidev->spi during
         teardown in the spidev userspace driver.
      
       - Rename the newly added spi-cs-setup-ns DT property to be more in line
         with our other delay properties before it becomes ABI.
      
       - A few driver specific fixes.
      
      * tag 'spi-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi:
        spi: spidev: remove debug messages that access spidev->spi without locking
        spi: spidev: fix a race condition when accessing spidev->spi
        spi: Rename spi-cs-setup-ns property to spi-cs-setup-delay-ns
        spi: dt-bindings: Rename spi-cs-setup-ns to spi-cs-setup-delay-ns
        spi: cadence: Fix busy cycles calculation
        spi: mediatek: Enable irq before the spi registration
      c757fc92
    • Linus Torvalds's avatar
      Merge tag 'regulator-fix-v6.2-rc3' of... · cf9668a2
      Linus Torvalds authored
      Merge tag 'regulator-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
      
      Pull regulator fixes from Mark Brown:
       "A couple of small driver specific fixes, one of which I queued for 6.1
        but didn't actually send out so has had *plenty* of testing in -next"
      
      * tag 'regulator-fix-v6.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator:
        regulator: qcom-rpmh: PM8550 ldo11 regulator is an nldo
        regulator: da9211: Use irq handler when ready
      cf9668a2
    • Linus Torvalds's avatar
      Merge tag 'mtd/fixes-for-6.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux · e58f087e
      Linus Torvalds authored
      Pull MTD fixes from Miquel Raynal:
      
       - cfi: Allow building spi-intel standalone to avoid build issues
      
       - parsers: scpart: Fix __udivdi3 undefined on mips
      
       - parsers: tplink_safeloader: Fix potential memory leak during parsing
      
       - Update email of Tudor Ambarus
      
      * tag 'mtd/fixes-for-6.2-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux:
        MAINTAINERS: Update email of Tudor Ambarus
        mtd: cfi: allow building spi-intel standalone
        mtd: parsers: scpart: fix __udivdi3 undefined on mips
        mtd: parsers: Fix potential memory leak in mtd_parser_tplink_safeloader_parse()
      e58f087e
    • Linus Torvalds's avatar
      Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi · 23025cbc
      Linus Torvalds authored
      Pull SCSI fixes from James Bottomley:
       "Ten small fixes (less the one that cleaned up a reverted removal),
        nine in drivers of which the ufs one is the most critical.
      
        The single core patch is a minor speedup to error handling"
      
      * tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi:
        scsi: libsas: Grab the ATA port lock in sas_ata_device_link_abort()
        scsi: hisi_sas: Fix tag freeing for reserved tags
        scsi: ufs: core: WLUN suspend SSU/enter hibern8 fail recovery
        scsi: scsi_debug: Delete unreachable code in inquiry_vpd_b0()
        scsi: mpi3mr: Refer CONFIG_SCSI_MPI3MR in Makefile
        scsi: core: scsi_error: Do not queue pointless abort workqueue functions
        scsi: storvsc: Fix swiotlb bounce buffer leak in confidential VM
        scsi: iscsi: Fix multiple iSCSI session unbind events sent to userspace
        scsi: mpi3mr: Remove usage of dma_get_required_mask() API
        scsi: mpt3sas: Remove usage of dma_get_required_mask() API
      23025cbc
  2. 11 Jan, 2023 5 commits
    • Linus Torvalds's avatar
      Merge tag 'perf-tools-fixes-for-v6.2-2-2023-01-11' of... · e8f60cd7
      Linus Torvalds authored
      Merge tag 'perf-tools-fixes-for-v6.2-2-2023-01-11' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
      
      Pull perf tools fixes from Arnaldo Carvalho de Melo:
      
       - Make 'perf kmem' cope with the removal of some
         kmem:kmem_cache_alloc_node and kmem:kmalloc_node in the
         11e9734b ("mm/slab_common: unify NUMA and UMA version of
         tracepoints") commit, making sure it works with Linux >= 6.2 as well
         as with older kernels where those tracepoints are present.
      
       - Also make it handle the new "node" kmem:kmalloc and
         kmem:kmem_cache_alloc tracepoint field introduced in that same
         commit.
      
       - Fix hardware tracing PMU address filter duplicate symbol selection,
         that was preventing to match with static functions with the same name
         present in different object files.
      
       - Fix regression on what linux/types.h file gets used to build the "BPF
         prologue" 'perf test' entry, the system one lacks the fmode_t
         definition used in this test, so provide that type in the test
         itself.
      
       - Avoid build breakage with libbpf < 0.8.0 + LIBBPF_DYNAMIC=1. If the
         user asks for linking with the libbpf package provided by the distro,
         then it has to be >= 0.8.0. Using the libbpf supplied with the kernel
         would be a fallback in that case.
      
       - Fix the build when libbpf isn't available or explicitly disabled via
         NO_LIBBPF=1.
      
       - Don't try to install libtraceevent plugins as its not anymore in the
         kernel sources and will thus always fail.
      
      * tag 'perf-tools-fixes-for-v6.2-2-2023-01-11' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux:
        perf auxtrace: Fix address filter duplicate symbol selection
        perf bpf: Avoid build breakage with libbpf < 0.8.0 + LIBBPF_DYNAMIC=1
        perf build: Fix build error when NO_LIBBPF=1
        perf tools: Don't install libtraceevent plugins as its not anymore in the kernel sources
        perf kmem: Support field "node" in evsel__process_alloc_event() coping with recent tracepoint restructuring
        perf kmem: Support legacy tracepoints
        perf build: Properly guard libbpf includes
        perf tests bpf prologue: Fix bpf-script-test-prologue test compile issue with clang
      e8f60cd7
    • Adrian Hunter's avatar
      perf auxtrace: Fix address filter duplicate symbol selection · cf129830
      Adrian Hunter authored
      When a match has been made to the nth duplicate symbol, return
      success not error.
      
      Example:
      
        Before:
      
          $ cat file.c
          cat: file.c: No such file or directory
          $ cat file1.c
          #include <stdio.h>
      
          static void func(void)
          {
                  printf("First func\n");
          }
      
          void other(void);
      
          int main()
          {
                  func();
                  other();
                  return 0;
          }
          $ cat file2.c
          #include <stdio.h>
      
          static void func(void)
          {
                  printf("Second func\n");
          }
      
          void other(void)
          {
                  func();
          }
      
          $ gcc -Wall -Wextra -o test file1.c file2.c
          $ perf record -e intel_pt//u --filter 'filter func @ ./test' -- ./test
          Multiple symbols with name 'func'
          #1      0x1149  l       func
                          which is near           main
          #2      0x1179  l       func
                          which is near           other
          Disambiguate symbol name by inserting #n after the name e.g. func #2
          Or select a global symbol by inserting #0 or #g or #G
          Failed to parse address filter: 'filter func @ ./test'
          Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
          Where multiple filters are separated by space or comma.
          $ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test
          Failed to parse address filter: 'filter func #2 @ ./test'
          Filter format is: filter|start|stop|tracestop <start symbol or address> [/ <end symbol or size>] [@<file name>]
          Where multiple filters are separated by space or comma.
      
        After:
      
          $ perf record -e intel_pt//u --filter 'filter func #2 @ ./test' -- ./test
          First func
          Second func
          [ perf record: Woken up 1 times to write data ]
          [ perf record: Captured and wrote 0.016 MB perf.data ]
          $ perf script --itrace=b -Ftime,flags,ip,sym,addr --ns
          1231062.526977619:   tr strt                               0 [unknown] =>     558495708179 func
          1231062.526977619:   tr end  call               558495708188 func =>     558495708050 _init
          1231062.526979286:   tr strt                               0 [unknown] =>     55849570818d func
          1231062.526979286:   tr end  return             55849570818f func =>     55849570819d other
      
      Fixes: 1b36c03e ("perf record: Add support for using symbols in address filters")
      Reported-by: default avatarDmitrii Dolgov <9erthalion6@gmail.com>
      Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
      Tested-by: default avatarDmitry Dolgov <9erthalion6@gmail.com>
      Cc: Adrian Hunter <adrian.hunter@intel.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20230110185659.15979-1-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      cf129830
    • Mark Brown's avatar
      spi: Merge rename of spi-cs-setup-ns DT property · b442990d
      Mark Brown authored
      The newly added spi-cs-setup-ns doesn't really fit with the existing
      property names for delays, rename it so that it does before it makes it
      into a release and becomes ABI.
      b442990d
    • Bartosz Golaszewski's avatar
      spi: spidev: remove debug messages that access spidev->spi without locking · 6b35b173
      Bartosz Golaszewski authored
      The two debug messages in spidev_open() dereference spidev->spi without
      taking the lock and without checking if it's not null. This can lead to
      a crash. Drop the messages as they're not needed - the user-space will
      get informed about ENOMEM with the syscall return value.
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Link: https://lore.kernel.org/r/20230106100719.196243-2-brgl@bgdev.plSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      6b35b173
    • Bartosz Golaszewski's avatar
      spi: spidev: fix a race condition when accessing spidev->spi · a720416d
      Bartosz Golaszewski authored
      There's a spinlock in place that is taken in file_operations callbacks
      whenever we check if spidev->spi is still alive (not null). It's also
      taken when spidev->spi is set to NULL in remove().
      
      This however doesn't protect the code against driver unbind event while
      one of the syscalls is still in progress. To that end we need a lock taken
      continuously as long as we may still access spidev->spi. As both the file
      ops and the remove callback are never called from interrupt context, we
      can replace the spinlock with a mutex.
      Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
      Link: https://lore.kernel.org/r/20230106100719.196243-1-brgl@bgdev.plSigned-off-by: default avatarMark Brown <broonie@kernel.org>
      a720416d
  3. 10 Jan, 2023 10 commits
  4. 09 Jan, 2023 11 commits
    • Linus Torvalds's avatar
      gcc: disable -Warray-bounds for gcc-11 too · 5a41237a
      Linus Torvalds authored
      We had already disabled this warning for gcc-12 due to bugs in the value
      range analysis, but it turns out we end up having some similar problems
      with gcc-11.3 too, so let's disable it there too.
      
      Older gcc versions end up being increasingly less relevant, and
      hopefully clang and newer version of gcc (ie gcc-13) end up working
      reliably enough that we still get the build coverage even when we
      disable this for some versions.
      
      Link: https://lore.kernel.org/all/20221227002941.GA2691687@roeck-us.net/
      Link: https://lore.kernel.org/all/D8BDBF66-E44C-45D4-9758-BAAA4F0C1998@kernel.org/
      Cc: Kees Cook <kees@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Guenter Roeck <linux@roeck-us.net>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      5a41237a
    • Willy Tarreau's avatar
      tools/nolibc: fix the O_* fcntl/open macro definitions for riscv · 00b18da4
      Willy Tarreau authored
      When RISCV port was imported in 5.2, the O_* macros were taken with
      their octal value and written as-is in hex, resulting in the getdents64()
      to fail in nolibc-test.
      
      Fixes: 582e84f7 ("tool headers nolibc: add RISCV support") #5.2
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      00b18da4
    • Willy Tarreau's avatar
      tools/nolibc: prevent gcc from making memset() loop over itself · 1bfbe1f3
      Willy Tarreau authored
      When building on ARM in thumb mode with gcc-11.3 at -O2 or -O3,
      nolibc-test segfaults during the select() tests. It turns out that at
      this level, gcc recognizes an opportunity for using memset() to zero
      the fd_set, but it miscompiles it because it also recognizes a memset
      pattern as well, and decides to call memset() from the memset() code:
      
        000122bc <memset>:
           122bc:       b510            push    {r4, lr}
           122be:       0004            movs    r4, r0
           122c0:       2a00            cmp     r2, #0
           122c2:       d003            beq.n   122cc <memset+0x10>
           122c4:       23ff            movs    r3, #255        ; 0xff
           122c6:       4019            ands    r1, r3
           122c8:       f7ff fff8       bl      122bc <memset>
           122cc:       0020            movs    r0, r4
           122ce:       bd10            pop     {r4, pc}
      
      Simply placing an empty asm() statement inside the loop suffices to
      avoid this.
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      1bfbe1f3
    • Willy Tarreau's avatar
      tools/nolibc: fix missing includes causing build issues at -O0 · 55abdd1f
      Willy Tarreau authored
      After the nolibc includes were split to facilitate portability from
      standard libcs, programs that include only what they need may miss
      some symbols which are needed by libgcc. This is the case for raise()
      which is needed by the divide by zero code in some architectures for
      example.
      
      Regardless, being able to include only the apparently needed files is
      convenient.
      
      Instead of trying to move all exported definitions to a single file,
      since this can change over time, this patch takes another approach
      consisting in including the nolibc header at the end of all standard
      include files. This way their types and functions are already known
      at the moment of inclusion, and including any single one of them is
      sufficient to bring all the required ones.
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      55abdd1f
    • Willy Tarreau's avatar
      tools/nolibc: restore mips branch ordering in the _start block · 184177c3
      Willy Tarreau authored
      Depending on the compiler used and the optimization options, the sbrk()
      test was crashing, both on real hardware (mips-24kc) and in qemu. One
      such example is kernel.org toolchain in version 11.3 optimizing at -Os.
      
      Inspecting the sys_brk() call shows the following code:
      
        0040047c <sys_brk>:
          40047c:       24020fcd        li      v0,4045
          400480:       27bdffe0        addiu   sp,sp,-32
          400484:       0000000c        syscall
          400488:       27bd0020        addiu   sp,sp,32
          40048c:       10e00001        beqz    a3,400494 <sys_brk+0x18>
          400490:       00021023        negu    v0,v0
          400494:       03e00008        jr      ra
      
      It is obviously wrong, the "negu" instruction is placed in beqz's
      delayed slot, and worse, there's no nop nor instruction after the
      return, so the next function's first instruction (addiu sip,sip,-32)
      will also be executed as part of the delayed slot that follows the
      return.
      
      This is caused by the ".set noreorder" directive in the _start block,
      that applies to the whole program. The compiler emits code without the
      delayed slots and relies on the compiler to swap instructions when this
      option is not set. Removing the option would require to change the
      startup code in a way that wouldn't make it look like the resulting
      code, which would not be easy to debug. Instead let's just save the
      default ordering before changing it, and restore it at the end of the
      _start block. Now the code is correct:
      
        0040047c <sys_brk>:
          40047c:       24020fcd        li      v0,4045
          400480:       27bdffe0        addiu   sp,sp,-32
          400484:       0000000c        syscall
          400488:       10e00002        beqz    a3,400494 <sys_brk+0x18>
          40048c:       27bd0020        addiu   sp,sp,32
          400490:       00021023        negu    v0,v0
          400494:       03e00008        jr      ra
          400498:       00000000        nop
      
      Fixes: 66b6f755 ("rcutorture: Import a copy of nolibc") #5.0
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      184177c3
    • Warner Losh's avatar
      tools/nolibc: Fix S_ISxxx macros · 16f5cea7
      Warner Losh authored
      The mode field has the type encoded as an value in a field, not as a bit
      mask. Mask the mode with S_IFMT instead of each type to test. Otherwise,
      false positives are possible: eg S_ISDIR will return true for block
      devices because S_IFDIR = 0040000 and S_IFBLK = 0060000 since mode is
      masked with S_IFDIR instead of S_IFMT. These macros now match the
      similar definitions in tools/include/uapi/linux/stat.h.
      Signed-off-by: default avatarWarner Losh <imp@bsdimp.com>
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      16f5cea7
    • Sven Schnelle's avatar
      nolibc: fix fd_set type · feaf7565
      Sven Schnelle authored
      The kernel uses unsigned long for the fd_set bitmap,
      but nolibc use u32. This works fine on little endian
      machines, but fails on big endian. Convert to unsigned
      long to fix this.
      Signed-off-by: default avatarSven Schnelle <svens@linux.ibm.com>
      Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
      Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
      feaf7565
    • Nicholas Piggin's avatar
      objtool: Tolerate STT_NOTYPE symbols at end of section · cad90e53
      Nicholas Piggin authored
      Hand-written asm often contains non-function symbols in executable
      sections. _end symbols for finding the size of instruction blocks
      for runtime processing is one such usage.
      
      optprobe_template_end is one example that causes the warning:
      
        objtool: optprobe_template_end(): can't find starting instruction
      
      This is because the symbol happens to be at the end of the file (and
      therefore end of a section in the object file).
      
      So ignore end-of-section STT_NOTYPE symbols instead of bailing out
      because an instruction can't be found. While we're here, add a more
      descriptive warning for STT_FUNC symbols found at the end of a
      section.
      
      [ This also solves a PowerPC regression reported by Sathvika Vasireddy. ]
      Reported-by: default avatarNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
      Reported-by: default avatarSathvika Vasireddy <sv@linux.ibm.com>
      Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Acked-by: default avatarSathvika Vasireddy <sv@linux.ibm.com>
      Link: https://lore.kernel.org/r/20221220101323.3119939-1-npiggin@gmail.com
      cad90e53
    • Athira Rajeev's avatar
      perf tests bpf prologue: Fix bpf-script-test-prologue test compile issue with clang · 6f9aba7f
      Athira Rajeev authored
      While running 'perf test' for bpf, observed that "BPF prologue
      generation" test case fails to compile with clang. Logs below from
      powerpc:
      
        <stdin>:33:2: error: use of undeclared identifier 'fmode_t'
                fmode_t f_mode = (fmode_t)_f_mode;
                ^
        <stdin>:37:6: error: use of undeclared identifier 'f_mode'; did you mean '_f_mode'?
                if (f_mode & FMODE_WRITE)
                    ^~~~~~
                    _f_mode
        <stdin>:30:60: note: '_f_mode' declared here
        int bpf_func__null_lseek(void *ctx, int err, unsigned long _f_mode,
                                                                   ^
        2 errors generated.
      
      The test code tests/bpf-script-test-prologue.c uses fmode_t.  And the
      error above is for "fmode_t" which is defined in include/linux/types.h
      as part of kernel build directory: "/lib/modules/<kernel_version>/build"
      that comes from kernel devel [ soft link to /usr/src/<kernel_version> ].
      
      Clang picks this header file from "-working-directory" build option that
      specifies this build folder.
      
      But the commit 14e4b9f4 ("perf trace: Raw augmented syscalls fix
      libbpf 1.0+ compatibility") changed the include directory to use:
      "/usr/include".
      
      Post this change, types.h from /usr/include/ is getting picked upwhich
      doesn’t contain definition of "fmode_t" and hence fails to compile.
      
      Compilation command before this commit:
      
        /usr/bin/clang -D__KERNEL__ -D__NR_CPUS__=72 -DLINUX_VERSION_CODE=0x50e00 -xc  -I/root/lib/perf/include/bpf -nostdinc -I./arch/powerpc/include -I./arch/powerpc/include/generated  -I./include -I./arch/powerpc/include/uapi -I./arch/powerpc/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h  -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/<ver>/build -c - -target bpf  -g -O2 -o -
      
      Compilation command after this commit:
      
        /usr/bin/clang -D__KERNEL__ -D__NR_CPUS__=72 -DLINUX_VERSION_CODE=0x50e00 -xc  -I/usr/include/ -nostdinc -I./arch/powerpc/include -I./arch/powerpc/include/generated  -I./include -I./arch/powerpc/include/uapi -I./arch/powerpc/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h  -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/<ver>/build -c - -target bpf  -g -O2 -o -
      
      The difference is addition of -I/usr/include/  in the first line which
      is causing the error. Fix this by adding typedef for "fmode_t" in the
      testcase to solve the compile issue.
      
      Fixes: 14e4b9f4 ("perf trace: Raw augmented syscalls fix libbpf 1.0+ compatibility")
      Signed-off-by: default avatarAthira Jajeev <atrajeev@linux.vnet.ibm.com>
      Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Disha Goel <disgoel@linux.ibm.com>
      Cc: Ian Rogers <irogers@google.com>
      Cc: James Clark <james.clark@arm.com>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Kajol Jain <kjain@linux.ibm.com>
      Cc: linuxppc-dev@lists.ozlabs.org
      Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Nageswara R Sastry <rnsastry@linux.ibm.com>
      Cc: Namhyung Kim <namhyung@kernel.org>
      Link: https://lore.kernel.org/linux-perf-users/20230105120436.92051-1-atrajeev@linux.vnet.ibm.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
      6f9aba7f
    • Waiman Long's avatar
      sched/core: Use kfree_rcu() in do_set_cpus_allowed() · 9a5418bc
      Waiman Long authored
      Commit 851a723e ("sched: Always clear user_cpus_ptr in
      do_set_cpus_allowed()") may call kfree() if user_cpus_ptr was previously
      set. Unfortunately, some of the callers of do_set_cpus_allowed()
      may have pi_lock held when calling it. So the following splats may be
      printed especially when running with a PREEMPT_RT kernel:
      
         WARNING: possible circular locking dependency detected
         BUG: sleeping function called from invalid context
      
      To avoid these problems, kfree_rcu() is used instead. An internal
      cpumask_rcuhead union is created for the sole purpose of facilitating
      the use of kfree_rcu() to free the cpumask.
      
      Since user_cpus_ptr is not being used in non-SMP configs, the newly
      introduced alloc_user_cpus_ptr() helper will return NULL in this case
      and sched_setaffinity() is modified to handle this special case.
      
      Fixes: 851a723e ("sched: Always clear user_cpus_ptr in do_set_cpus_allowed()")
      Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarWaiman Long <longman@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20221231041120.440785-3-longman@redhat.com
      9a5418bc
    • Waiman Long's avatar
      sched/core: Fix use-after-free bug in dup_user_cpus_ptr() · 87ca4f9e
      Waiman Long authored
      Since commit 07ec77a1 ("sched: Allow task CPU affinity to be
      restricted on asymmetric systems"), the setting and clearing of
      user_cpus_ptr are done under pi_lock for arm64 architecture. However,
      dup_user_cpus_ptr() accesses user_cpus_ptr without any lock
      protection. Since sched_setaffinity() can be invoked from another
      process, the process being modified may be undergoing fork() at
      the same time.  When racing with the clearing of user_cpus_ptr in
      __set_cpus_allowed_ptr_locked(), it can lead to user-after-free and
      possibly double-free in arm64 kernel.
      
      Commit 8f9ea86f ("sched: Always preserve the user requested
      cpumask") fixes this problem as user_cpus_ptr, once set, will never
      be cleared in a task's lifetime. However, this bug was re-introduced
      in commit 851a723e ("sched: Always clear user_cpus_ptr in
      do_set_cpus_allowed()") which allows the clearing of user_cpus_ptr in
      do_set_cpus_allowed(). This time, it will affect all arches.
      
      Fix this bug by always clearing the user_cpus_ptr of the newly
      cloned/forked task before the copying process starts and check the
      user_cpus_ptr state of the source task under pi_lock.
      
      Note to stable, this patch won't be applicable to stable releases.
      Just copy the new dup_user_cpus_ptr() function over.
      
      Fixes: 07ec77a1 ("sched: Allow task CPU affinity to be restricted on asymmetric systems")
      Fixes: 851a723e ("sched: Always clear user_cpus_ptr in do_set_cpus_allowed()")
      Reported-by: default avatarDavid Wang 王标 <wangbiao3@xiaomi.com>
      Signed-off-by: default avatarWaiman Long <longman@redhat.com>
      Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
      Reviewed-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Cc: stable@vger.kernel.org
      Link: https://lore.kernel.org/r/20221231041120.440785-2-longman@redhat.com
      87ca4f9e
  5. 08 Jan, 2023 4 commits
  6. 07 Jan, 2023 3 commits