08 Apr, 2022

2 commits

  • [ Upstream commit 5a06fcb15b43d1f7bf740c672950122331cb5655 ]

    test_kernel_ptr() uses access_ok() to figure out if a given address
    points to user space instead of kernel space. However on architectures
    that set CONFIG_ALTERNATE_USER_ADDRESS_SPACE, a pointer can be valid
    for both, and the check always fails because access_ok() returns true.

    Make the check for user space pointers conditional on the type of
    address space layout.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Sasha Levin

    Arnd Bergmann
     
  • [ Upstream commit 23fc539e81295b14b50c6ccc5baeb4f3d59d822d ]

    On some architectures, access_ok() does not do any argument type
    checking, so replacing the definition with a generic one causes
    a few warnings for harmless issues that were never caught before.

    Fix the ones that I found either through my own test builds or
    that were reported by the 0-day bot.

    Reported-by: kernel test robot
    Reviewed-by: Christoph Hellwig
    Acked-by: Dinh Nguyen
    Signed-off-by: Arnd Bergmann
    Signed-off-by: Sasha Levin

    Arnd Bergmann
     

18 Aug, 2021

2 commits

  • The inner parts of certain locks (mutex, rwlocks) changed due to a rework for
    RT and non RT code. Most users remain unaffected, but those who fiddle around
    in the inner parts need to be updated.

    Match the struct names to the new layout.

    Signed-off-by: Sebastian Andrzej Siewior
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lore.kernel.org/r/20210815211305.137982730@linutronix.de

    Sebastian Andrzej Siewior
     
  • The wait_lock of mutex is really a low level lock. Convert it to a
    raw_spinlock like the wait_lock of rtmutex.

    [ mingo: backmerged the test_lockup.c build fix by bigeasy. ]

    Co-developed-by: Sebastian Andrzej Siewior
    Signed-off-by: Sebastian Andrzej Siewior
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lore.kernel.org/r/20210815211304.166863404@linutronix.de

    Thomas Gleixner
     

16 Dec, 2020

1 commit

  • On PREEMPT_RT the locks are quite different so they can't be tested as it
    is done below. The alternative is to test for the waitlock within
    rtmutex.

    This is the bare minimun to get it compiled. Problems which exist on
    PREEMP_RT:

    - none of the locks (spinlock_t, rwlock_t, mutex_t, rw_semaphore) may
    be acquired with disabled preemption or interrupts.

    If I read the code correct the it is possible to acquire a mutex_t
    with disabled interrupts.

    I don't know how to obtain a lock pointer. Technically they are not
    exported to userland.

    - memory can not be allocated with disabled preemption or interrupts
    even with GFP_ATOMIC.

    Link: https://lkml.kernel.org/r/20201028181041.xyeothhkouc3p4md@linutronix.de
    Signed-off-by: Sebastian Andrzej Siewior
    Cc: Konstantin Khlebnikov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sebastian Andrzej Siewior
     

13 Aug, 2020

2 commits

  • Since filp_open() returns an error pointer, we should use IS_ERR() to
    check the return value and then return PTR_ERR() if failed to get the
    actual return value instead of always -EINVAL.

    E.g. without this patch:

    [root@localhost loongson]# ls no_such_file
    ls: cannot access no_such_file: No such file or directory
    [root@localhost loongson]# modprobe test_lockup file_path=no_such_file lock_sb_umount time_secs=60 state=S
    modprobe: ERROR: could not insert 'test_lockup': Invalid argument
    [root@localhost loongson]# dmesg | tail -1
    [ 126.100596] test_lockup: cannot find file_path

    With this patch:

    [root@localhost loongson]# ls no_such_file
    ls: cannot access no_such_file: No such file or directory
    [root@localhost loongson]# modprobe test_lockup file_path=no_such_file lock_sb_umount time_secs=60 state=S
    modprobe: ERROR: could not insert 'test_lockup': Unknown symbol in module, or unknown parameter (see dmesg)
    [root@localhost loongson]# dmesg | tail -1
    [ 95.134362] test_lockup: failed to open no_such_file: -2

    Fixes: aecd42df6d39 ("lib/test_lockup.c: add parameters for locking generic vfs locks")
    Signed-off-by: Tiezhu Yang
    Signed-off-by: Andrew Morton
    Reviewed-by: Guenter Roeck
    Cc: Konstantin Khlebnikov
    Cc: Kees Cook
    Link: http://lkml.kernel.org/r/1595555407-29875-2-git-send-email-yangtiezhu@loongson.cn
    Signed-off-by: Linus Torvalds

    Tiezhu Yang
     
  • Fix sparse build warning:

    lib/test_lockup.c:403:1: warning:
    symbol '__pcpu_scope_test_works' was not declared. Should it be static?

    Reported-by: Hulk Robot
    Signed-off-by: Wei Yongjun
    Signed-off-by: Andrew Morton
    Link: http://lkml.kernel.org/r/20200707112252.9047-1-weiyongjun1@huawei.com
    Signed-off-by: Linus Torvalds

    Wei Yongjun
     

17 Jul, 2020

1 commit

  • Using uninitialized_var() is dangerous as it papers over real bugs[1]
    (or can in the future), and suppresses unrelated compiler warnings
    (e.g. "unused variable"). If the compiler thinks it is uninitialized,
    either simply initialize the variable or make compiler changes.

    In preparation for removing[2] the[3] macro[4], remove all remaining
    needless uses with the following script:

    git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
    xargs perl -pi -e \
    's/\buninitialized_var\(([^\)]+)\)/\1/g;
    s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'

    drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
    pathological white-space.

    No outstanding warnings were found building allmodconfig with GCC 9.3.0
    for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
    alpha, and m68k.

    [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
    [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
    [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
    [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/

    Reviewed-by: Leon Romanovsky # drivers/infiniband and mlx4/mlx5
    Acked-by: Jason Gunthorpe # IB
    Acked-by: Kalle Valo # wireless drivers
    Reviewed-by: Chao Yu # erofs
    Signed-off-by: Kees Cook

    Kees Cook
     

19 Jun, 2020

1 commit


10 Jun, 2020

2 commits

  • Convert comments that reference mmap_sem to reference mmap_lock instead.

    [akpm@linux-foundation.org: fix up linux-next leftovers]
    [akpm@linux-foundation.org: s/lockaphore/lock/, per Vlastimil]
    [akpm@linux-foundation.org: more linux-next fixups, per Michel]

    Signed-off-by: Michel Lespinasse
    Signed-off-by: Andrew Morton
    Reviewed-by: Vlastimil Babka
    Reviewed-by: Daniel Jordan
    Cc: Davidlohr Bueso
    Cc: David Rientjes
    Cc: Hugh Dickins
    Cc: Jason Gunthorpe
    Cc: Jerome Glisse
    Cc: John Hubbard
    Cc: Laurent Dufour
    Cc: Liam Howlett
    Cc: Matthew Wilcox
    Cc: Peter Zijlstra
    Cc: Ying Han
    Link: http://lkml.kernel.org/r/20200520052908.204642-13-walken@google.com
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     
  • This change converts the existing mmap_sem rwsem calls to use the new mmap
    locking API instead.

    The change is generated using coccinelle with the following rule:

    // spatch --sp-file mmap_lock_api.cocci --in-place --include-headers --dir .

    @@
    expression mm;
    @@
    (
    -init_rwsem
    +mmap_init_lock
    |
    -down_write
    +mmap_write_lock
    |
    -down_write_killable
    +mmap_write_lock_killable
    |
    -down_write_trylock
    +mmap_write_trylock
    |
    -up_write
    +mmap_write_unlock
    |
    -downgrade_write
    +mmap_write_downgrade
    |
    -down_read
    +mmap_read_lock
    |
    -down_read_killable
    +mmap_read_lock_killable
    |
    -down_read_trylock
    +mmap_read_trylock
    |
    -up_read
    +mmap_read_unlock
    )
    -(&mm->mmap_sem)
    +(mm)

    Signed-off-by: Michel Lespinasse
    Signed-off-by: Andrew Morton
    Reviewed-by: Daniel Jordan
    Reviewed-by: Laurent Dufour
    Reviewed-by: Vlastimil Babka
    Cc: Davidlohr Bueso
    Cc: David Rientjes
    Cc: Hugh Dickins
    Cc: Jason Gunthorpe
    Cc: Jerome Glisse
    Cc: John Hubbard
    Cc: Liam Howlett
    Cc: Matthew Wilcox
    Cc: Peter Zijlstra
    Cc: Ying Han
    Link: http://lkml.kernel.org/r/20200520052908.204642-5-walken@google.com
    Signed-off-by: Linus Torvalds

    Michel Lespinasse
     

05 Jun, 2020

1 commit

  • Fix the following sparse warning:

    lib/test_lockup.c:145:14: warning: symbol 'test_inode' was not declared.
    Should it be static?

    Reported-by: Hulk Robot
    Signed-off-by: Jason Yan
    Signed-off-by: Andrew Morton
    Link: http://lkml.kernel.org/r/20200417074021.46411-1-yanaijie@huawei.com
    Signed-off-by: Linus Torvalds

    Jason Yan
     

08 Apr, 2020

3 commits

  • file_path= defines file or directory to open
    lock_inode=Y set lock_rwsem_ptr to inode->i_rwsem
    lock_mapping=Y set lock_rwsem_ptr to mapping->i_mmap_rwsem
    lock_sb_umount=Y set lock_rwsem_ptr to sb->s_umount

    This gives safe and simple way to see how system reacts to contention of
    common vfs locks and how syscalls depend on them directly or indirectly.

    For example to block s_umount for 60 seconds:
    # modprobe test_lockup file_path=. lock_sb_umount time_secs=60 state=S

    This is useful for checking/testing scalability issues like this:
    https://lore.kernel.org/lkml/158497590858.7371.9311902565121473436.stgit@buzz/

    Signed-off-by: Konstantin Khlebnikov
    Signed-off-by: Andrew Morton
    Cc: Colin Ian King
    Cc: Greg Kroah-Hartman
    Cc: Guenter Roeck
    Cc: Kees Cook
    Cc: Peter Zijlstra
    Cc: Petr Mladek
    Cc: Sasha Levin
    Cc: Sergey Senozhatsky
    Cc: Steven Rostedt
    Link: http://lkml.kernel.org/r/158498153964.5621.83061779039255681.stgit@buzz
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov
     
  • There is a spelling mistake in a pr_notice message. Fix it.

    Signed-off-by: Colin Ian King
    Signed-off-by: Andrew Morton
    Cc: Greg Kroah-Hartman
    Cc: Guenter Roeck
    Cc: Kees Cook
    Cc: Konstantin Khlebnikov
    Cc: Peter Zijlstra
    Cc: Petr Mladek
    Cc: Sasha Levin
    Cc: Sergey Senozhatsky
    Cc: Steven Rostedt
    Link: http://lkml.kernel.org/r/20200221155145.79522-1-colin.king@canonical.com
    Signed-off-by: Linus Torvalds

    Colin Ian King
     
  • CONFIG_TEST_LOCKUP=m adds module "test_lockup" that helps to make sure
    that watchdogs and lockup detectors are working properly.

    Depending on module parameters test_lockup could emulate soft or hard
    lockup, "hung task", hold arbitrary lock, allocate bunch of pages.

    Also it could generate series of lockups with cooling-down periods, in
    this way it could be used as "ping" for locks or page allocator. Loop
    checks signals between iteration thus could be stopped by ^C.

    # modinfo test_lockup
    ...
    parm: time_secs:lockup time in seconds, default 0 (uint)
    parm: time_nsecs:nanoseconds part of lockup time, default 0 (uint)
    parm: cooldown_secs:cooldown time between iterations in seconds, default 0 (uint)
    parm: cooldown_nsecs:nanoseconds part of cooldown, default 0 (uint)
    parm: iterations:lockup iterations, default 1 (uint)
    parm: all_cpus:trigger lockup at all cpus at once (bool)
    parm: state:wait in 'R' running (default), 'D' uninterruptible, 'K' killable, 'S' interruptible state (charp)
    parm: use_hrtimer:use high-resolution timer for sleeping (bool)
    parm: iowait:account sleep time as iowait (bool)
    parm: lock_read:lock read-write locks for read (bool)
    parm: lock_single:acquire locks only at one cpu (bool)
    parm: reacquire_locks:release and reacquire locks/irq/preempt between iterations (bool)
    parm: touch_softlockup:touch soft-lockup watchdog between iterations (bool)
    parm: touch_hardlockup:touch hard-lockup watchdog between iterations (bool)
    parm: call_cond_resched:call cond_resched() between iterations (bool)
    parm: measure_lock_wait:measure lock wait time (bool)
    parm: lock_wait_threshold:print lock wait time longer than this in nanoseconds, default off (ulong)
    parm: disable_irq:disable interrupts: generate hard-lockups (bool)
    parm: disable_softirq:disable bottom-half irq handlers (bool)
    parm: disable_preempt:disable preemption: generate soft-lockups (bool)
    parm: lock_rcu:grab rcu_read_lock: generate rcu stalls (bool)
    parm: lock_mmap_sem:lock mm->mmap_sem: block procfs interfaces (bool)
    parm: lock_rwsem_ptr:lock rw_semaphore at address (ulong)
    parm: lock_mutex_ptr:lock mutex at address (ulong)
    parm: lock_spinlock_ptr:lock spinlock at address (ulong)
    parm: lock_rwlock_ptr:lock rwlock at address (ulong)
    parm: alloc_pages_nr:allocate and free pages under locks (uint)
    parm: alloc_pages_order:page order to allocate (uint)
    parm: alloc_pages_gfp:allocate pages with this gfp_mask, default GFP_KERNEL (uint)
    parm: alloc_pages_atomic:allocate pages with GFP_ATOMIC (bool)
    parm: reallocate_pages:free and allocate pages between iterations (bool)

    Parameters for locking by address are unsafe and taints kernel. With
    CONFIG_DEBUG_SPINLOCK=y they at least check magics for embedded spinlocks.

    Examples:

    task hang in D-state:
    modprobe test_lockup time_secs=1 iterations=60 state=D

    task hang in io-wait D-state:
    modprobe test_lockup time_secs=1 iterations=60 state=D iowait

    softlockup:
    modprobe test_lockup time_secs=1 iterations=60 state=R

    hardlockup:
    modprobe test_lockup time_secs=1 iterations=60 state=R disable_irq

    system-wide hardlockup:
    modprobe test_lockup time_secs=1 iterations=60 state=R \
    disable_irq all_cpus

    rcu stall:
    modprobe test_lockup time_secs=1 iterations=60 state=R \
    lock_rcu touch_softlockup

    lock mmap_sem / block procfs interfaces:
    modprobe test_lockup time_secs=1 iterations=60 state=S lock_mmap_sem

    lock tasklist_lock for read / block forks:
    TASKLIST_LOCK=$(awk '$3 == "tasklist_lock" {print "0x"$1}' /proc/kallsyms)
    modprobe test_lockup time_secs=1 iterations=60 state=R \
    disable_irq lock_read lock_rwlock_ptr=$TASKLIST_LOCK

    lock namespace_sem / block vfs mount operations:
    NAMESPACE_SEM=$(awk '$3 == "namespace_sem" {print "0x"$1}' /proc/kallsyms)
    modprobe test_lockup time_secs=1 iterations=60 state=S \
    lock_rwsem_ptr=$NAMESPACE_SEM

    lock cgroup mutex / block cgroup operations:
    CGROUP_MUTEX=$(awk '$3 == "cgroup_mutex" {print "0x"$1}' /proc/kallsyms)
    modprobe test_lockup time_secs=1 iterations=60 state=S \
    lock_mutex_ptr=$CGROUP_MUTEX

    ping cgroup_mutex every second and measure maximum lock wait time:
    modprobe test_lockup cooldown_secs=1 iterations=60 state=S \
    lock_mutex_ptr=$CGROUP_MUTEX reacquire_locks measure_lock_wait

    [linux@roeck-us.net: rename disable_irq to fix build error]
    Link: http://lkml.kernel.org/r/20200317133614.23152-1-linux@roeck-us.net
    Signed-off-by: Konstantin Khlebnikov
    Signed-off-by: Guenter Roeck
    Signed-off-by: Andrew Morton
    Cc: Sasha Levin
    Cc: Petr Mladek
    Cc: Kees Cook
    Cc: Peter Zijlstra
    Cc: Greg Kroah-Hartman
    Cc: Steven Rostedt
    Cc: Sergey Senozhatsky
    Cc: Dmitry Monakhov
    Cc: Guenter Roeck
    Link: http://lkml.kernel.org/r/158132859146.2797.525923171323227836.stgit@buzz
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov