08 Apr, 2014

40 commits

  • Currently, memcg_unregister_cache(), which deletes the cache being
    destroyed from the memcg_slab_caches list, is called after
    __kmem_cache_shutdown() (see kmem_cache_destroy()), which starts to
    destroy the cache.

    As a result, one can access a partially destroyed cache while traversing
    a memcg_slab_caches list, which can have deadly consequences (for
    instance, cache_show() called for each cache on a memcg_slab_caches list
    from mem_cgroup_slabinfo_read() will dereference pointers to already
    freed data).

    To fix this, let's move memcg_unregister_cache() before the cache
    destruction process beginning, issuing memcg_register_cache() on failure.

    Signed-off-by: Vladimir Davydov
    Cc: Michal Hocko
    Cc: Johannes Weiner
    Cc: David Rientjes
    Cc: Pekka Enberg
    Cc: Glauber Costa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     
  • Memcg-awareness turned kmem_cache_create() into a dirty interweaving of
    memcg-only and except-for-memcg calls. To clean this up, let's move the
    code responsible for memcg cache creation to a separate function.

    Signed-off-by: Vladimir Davydov
    Cc: Michal Hocko
    Cc: Johannes Weiner
    Cc: David Rientjes
    Cc: Pekka Enberg
    Cc: Glauber Costa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     
  • This patch cleans up the memcg cache creation path as follows:

    - Move memcg cache name creation to a separate function to be called
    from kmem_cache_create_memcg(). This allows us to get rid of the mutex
    protecting the temporary buffer used for the name formatting, because
    the whole cache creation path is protected by the slab_mutex.

    - Get rid of memcg_create_kmem_cache(). This function serves as a proxy
    to kmem_cache_create_memcg(). After separating the cache name creation
    path, it would be reduced to a function call, so let's inline it.

    Signed-off-by: Vladimir Davydov
    Cc: Michal Hocko
    Cc: Johannes Weiner
    Cc: David Rientjes
    Cc: Pekka Enberg
    Cc: Glauber Costa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     
  • When a kmem cache is created (kmem_cache_create_memcg()), we first try to
    find a compatible cache that already exists and can handle requests from
    the new cache, i.e. has the same object size, alignment, ctor, etc. If
    there is such a cache, we do not create any new caches, instead we simply
    increment the refcount of the cache found and return it.

    Currently we do this procedure not only when creating root caches, but
    also for memcg caches. However, there is no point in that, because, as
    every memcg cache has exactly the same parameters as its parent and cache
    merging cannot be turned off in runtime (only on boot by passing
    "slub_nomerge"), the root caches of any two potentially mergeable memcg
    caches should be merged already, i.e. it must be the same root cache, and
    therefore we couldn't even get to the memcg cache creation, because it
    already exists.

    The only exception is boot caches - they are explicitly forbidden to be
    merged by setting their refcount to -1. There are currently only two of
    them - kmem_cache and kmem_cache_node, which are used in slab internals (I
    do not count kmalloc caches as their refcount is set to 1 immediately
    after creation). Since they are prevented from merging preliminary I
    guess we should avoid to merge their children too.

    So let's remove the useless code responsible for merging memcg caches.

    Signed-off-by: Vladimir Davydov
    Cc: Michal Hocko
    Cc: Johannes Weiner
    Cc: David Rientjes
    Cc: Pekka Enberg
    Cc: Glauber Costa
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Vladimir Davydov
     
  • arch_align_stack() moved to asm/exec.h, so change the comment referring to
    asm/system.h which no longer exists.

    Signed-off-by: David Howells
    Cc: Jeff Dike
    Cc: Richard Weinberger
    Cc: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Howells
     
  • Clean asm/system.h from docs as nothing should refer to that header anymore.

    Signed-off-by: David Howells
    Cc: Ingo Molnar
    Cc: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    David Howells
     
  • To increase compiler portability there is which
    provides convenience macros for various gcc constructs. Eg: __weak for
    __attribute__((weak)). I've replaced all instances of gcc attributes
    with the right macro in the kernel subsystem.

    Signed-off-by: Gideon Israel Dsouza
    Cc: "Rafael J. Wysocki"
    Cc: Ingo Molnar
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Gideon Israel Dsouza
     
  • If the renamed symbol is defined lib/iomap.c implements ioport_map and
    ioport_unmap and currently (nearly) all platforms define the port
    accessor functions outb/inb and friend unconditionally. So
    HAS_IOPORT_MAP is the better name for this.

    Consequently NO_IOPORT is renamed to NO_IOPORT_MAP.

    The motivation for this change is to reintroduce a symbol HAS_IOPORT
    that signals if outb/int et al are available. I will address that at
    least one merge window later though to keep surprises to a minimum and
    catch new introductions of (HAS|NO)_IOPORT.

    The changes in this commit were done using:

    $ git grep -l -E '(NO|HAS)_IOPORT' | xargs perl -p -i -e 's/\b((?:CONFIG_)?(?:NO|HAS)_IOPORT)\b/$1_MAP/'

    Signed-off-by: Uwe Kleine-König
    Acked-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Uwe Kleine-König
     
  • ... since __initcall is now deprecated.

    Signed-off-by: Davidlohr Bueso
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     
  • This macro appears to have been introduced back in the 2.5 era for
    semtimedop32 backward compatibility on ia32:

    https://lkml.org/lkml/2003/4/28/78

    Nowadays, this syscall in compat just defaults back to the code found in
    sem.c, so it is no longer used and can thus be removed:

    long compat_sys_semtimedop(int semid, struct sembuf __user *tsems,
    unsigned nsops, const struct compat_timespec __user *timeout)
    {
    struct timespec __user *ts64;
    if (compat_convert_timespec(&ts64, timeout))
    return -EFAULT;
    return sys_semtimedop(semid, tsems, nsops, ts64);
    }

    Furthermore, there are no users in compat.c. After this change, kernel
    builds just fine with both CONFIG_SYSVIPC_COMPAT and CONFIG_SYSVIPC.

    Signed-off-by: Davidlohr Bueso
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     
  • This can greatly aid in narrowing down the real source of initramfs
    problems such as failures related to the compression of the in-kernel
    initramfs when an external initramfs is in use as well. Existing errors
    are ambiguous as to which initramfs is a problem and why.

    [akpm@linux-foundation.org: use pr_debug()]
    Signed-off-by: Daniel M. Weeks
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Daniel M. Weeks
     
  • /proc/self/make-it-fail is a boolean, but accepts any number, including
    negative ones. Change variable to unsigned, and cap upper bound at 1.

    [akpm@linux-foundation.org: don't make make_it_fail unsigned]
    Signed-off-by: Dave Jones
    Reviewed-by: Akinobu Mita
    Cc: David Rientjes
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dave Jones
     
  • This ensures that BUG() always has a definition that causes a trap (via
    an undefined instruction), and that the compiler still recognizes the
    code following BUG() as unreachable, avoiding warnings that would
    otherwise appear (such as on non-void functions that don't return a
    value after BUG()).

    In addition to saving a few bytes over the generic infinite-loop
    implementation, this implementation traps rather than looping, which
    potentially allows for better error-recovery behavior (such as by
    rebooting).

    Signed-off-by: Josh Triplett
    Reported-by: Arnd Bergmann
    Acked-by: Arnd Bergmann
    Cc: Ingo Molnar
    Cc: Thomas Gleixner
    Cc: "H. Peter Anvin"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • When !CONFIG_BUG and !HAVE_ARCH_BUG, define the generic BUG() as an
    infinite loop rather than a no-op. This avoids undefined behavior if
    execution ever actually reaches BUG(), and avoids warnings about code
    after BUG() (such as on non-void functions calling BUG() and then not
    returning).

    bloat-o-meter results:

    add/remove: 0/0 grow/shrink: 43/10 up/down: 235/-98 (137)
    function old new delta
    umount_collect 119 138 +19
    notify_change 306 324 +18
    xstate_enable_boot_cpu 252 269 +17
    kunmap 54 70 +16
    balloon_page_dequeue 112 126 +14
    mm_take_all_locks 223 233 +10
    list_lru_walk_node 143 152 +9
    vma_adjust 1059 1067 +8
    pcpu_setup_first_chunk 1130 1138 +8
    mm_drop_all_locks 143 151 +8
    ns_capable 55 62 +7
    anon_transport_class_unregister 8 15 +7
    srcu_init_notifier_head 35 41 +6
    shrink_dcache_for_umount 174 180 +6
    kunmap_high 99 105 +6
    end_page_writeback 43 49 +6
    do_exit 1339 1345 +6
    __kfifo_dma_out_prepare_r 86 92 +6
    __kfifo_dma_in_prepare_r 90 96 +6
    fixup_user_fault 120 125 +5
    repair_env_string 73 77 +4
    read_cache_pages_invalidate_page 56 60 +4
    isolate_lru_pages.isra 142 146 +4
    do_notify_parent_cldstop 255 259 +4
    cpu_init 370 374 +4
    utimes_common 270 272 +2
    tasklet_hi_action 91 93 +2
    tasklet_action 91 93 +2
    set_pte_vaddr 46 48 +2
    find_get_pages_tag 202 204 +2
    early_iounmap 185 187 +2
    __native_set_fixmap 36 38 +2
    __get_user_pages 822 824 +2
    __early_ioremap 299 301 +2
    yield_task_stop 1 2 +1
    tick_resume 37 38 +1
    switched_to_stop 1 2 +1
    switched_to_idle 1 2 +1
    prio_changed_stop 1 2 +1
    prio_changed_idle 1 2 +1
    pm_qos_power_read 111 112 +1
    arch_cpu_idle_dead 1 2 +1
    __insert_vmap_area 140 141 +1
    sys_renameat 614 612 -2
    mm_fault_error 297 295 -2
    SyS_renameat 614 612 -2
    sys_linkat 416 413 -3
    SyS_linkat 416 413 -3
    chmod_common 129 122 -7
    proc_cap_handler 240 225 -15
    __schedule 849 831 -18
    sys_madvise 1077 1054 -23
    SyS_madvise 1077 1054 -23

    Signed-off-by: Josh Triplett
    Reported-by: Arnd Bergmann
    Acked-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • The stub version of WARN for !CONFIG_BUG completely ignored its format
    string and subsequent arguments; make it check them instead, using
    no_printk.

    Signed-off-by: Josh Triplett
    Reported-by: Arnd Bergmann
    Acked-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • Signed-off-by: Josh Triplett
    Reported-by: Randy Dunlap
    Acked-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • When !CONFIG_BUG, WARN_ON and family become simple passthroughs of their
    condition argument; however, WARN_ON_ONCE and family still have conditions
    and a boolean to detect one-time invocation, even though the warning
    they'd emit doesn't exist. Make the existing definitions conditional on
    CONFIG_BUG, and add definitions for !CONFIG_BUG that map to the
    passthrough versions of WARN and WARN_ON.

    This saves 4.4k on a minimized configuration (smaller than allnoconfig),
    and 20.6k with defconfig plus CONFIG_BUG=n.

    Signed-off-by: Josh Triplett
    Acked-by: Arnd Bergmann
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • "make allnoconfig" exists to ease testing of minimal configurations.
    Documentation/SubmitChecklist includes a note to test with allnoconfig.
    This helps catch missing dependencies on common-but-not-required
    functionality, which might otherwise go unnoticed.

    However, allnoconfig still leaves many symbols enabled, because they're
    hidden behind CONFIG_EMBEDDED or CONFIG_EXPERT. For instance, allnoconfig
    still has CONFIG_PRINTK and CONFIG_BLOCK enabled, so drivers don't
    typically get build-tested with those disabled.

    To address this, introduce a new Kconfig option "allnoconfig_y", used on
    symbols which only exist to hide other symbols. Set it on CONFIG_EMBEDDED
    (which then selects CONFIG_EXPERT). allnoconfig will then disable all the
    symbols hidden behind those.

    Signed-off-by: Josh Triplett
    Tested-by: Paul E. McKenney
    Cc: Michal Marek
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • Fix breakage which will be exposed by the patch "kconfig: make allnoconfig
    disable options behind EMBEDDED and EXPERT".

    arch/powerpc/kernel/mce.c, compiled in for PPC_BOOK3S_64, calls
    functions only built when IRQ_WORK, so select it. Fixes the following
    build error:

    arch/powerpc/kernel/built-in.o: In function `.machine_check_queue_event':
    (.text+0x11260): undefined reference to `.irq_work_queue'

    Signed-off-by: Josh Triplett
    Reported-by: Stephen Rothwell
    Acked-by: Benjamin Herrenschmidt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • Fix breakage which will be exposed by the patch "kconfig: make allnoconfig
    disable options behind EMBEDDED and EXPERT".

    arch/ia64/kernel/unaligned.c uses tty_write_message to print an
    unaligned access exception to the TTY of the current user process.
    Enable TTY to prevent a build error.

    Minimal fix, on the basis that few people on ia64 will care deeply about
    kernel size enough to turn off TTY. Ideally, I'd instead suggest
    dropping the tty_write_message entirely, and just leaving the printk.
    Bonus: no need to sprintf first.

    Signed-off-by: Josh Triplett
    Cc: Stephen Rothwell
    Cc: "Luck, Tony"
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • Fix breakage which will be exposed by the patch "kconfig: make allnoconfig
    disable options behind EMBEDDED and EXPERT".

    Now allnoconfig started disabling CONFIG_PROC_FS:

    arch/cris/kernel/built-in.o:(.rodata+0xc): undefined reference to `show_cpuinfo'
    make: *** [vmlinux] Error 1

    Signed-off-by: Geert Uytterhoeven
    Cc: Stephen Rothwell
    Cc: Mikael Starvik
    Cc: Jesper Nilsson
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Geert Uytterhoeven
     
  • Fix breakage which will be exposed by the patch "kconfig: make allnoconfig
    disable options behind EMBEDDED and EXPERT".

    arch/cris/arch-v10/kernel/debugport.c, compiled in unconditionally with
    ETRAX_ARCH_V10, requires TTY, so select TTY to avoid a build failure.

    Signed-off-by: Josh Triplett
    Cc: Stephen Rothwell
    Cc: Mikael Starvik
    Cc: Jesper Nilsson
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Josh Triplett
     
  • "ret" is zero here so we can remove the "!ret" part of the condition.
    "uhdr" is alread a __user pointer so we can remove the cast.

    Signed-off-by: Dan Carpenter
    Acked-by: Dimitri Sivanich
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Carpenter
     
  • Currently, booting without initrd specified on 80x25 screen gives a call
    trace followed by atkbd : Spurious ACK. Original message ("VFS: Unable
    to mount root fs") is not available. Of course this could happen in
    other situations...

    This patch displays panic reason after call trace which could help lot
    of people even if it's not the very last line on screen.

    Also, convert all panic.c printk(KERN_EMERG to pr_emerg(

    [akpm@linux-foundation.org: missed a couple of pr_ conversions]
    Signed-off-by: Fabian Frederick
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • init_inodecache is only called by __init init_bfs_fs

    Signed-off-by: Fabian Frederick
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • Normal behavior for filenames exceeding specific filesystem limits is to
    refuse operation.

    AFFS standard name length being only 30 characters against 255 for usual
    Linux filesystems, original implementation does filename truncate by
    default with a define value AFFS_NO_TRUNCATE which can be enabled but
    needs module compilation.

    This patch adds 'nofilenametruncate' mount option so that user can
    easily activate that feature and avoid a lot of problems (eg overwrite
    files ...)

    Signed-off-by: Fabian Frederick
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • Commit 0edf977d2ae3 ("[readdir] convert affs") returns directly -EIO
    without unlocking dir inode and releasing dir bh when second affs_bread
    sequence fails. This patch restores initial behaviour. It also fixes
    pr_debug and affs_error to fit in 80 columns + removes reference to
    filldir (replaced by dir_emit in the commit above).

    Signed-off-by: Fabian Frederick
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • init_inodecache is only called by __init init_affs_fs

    Signed-off-by: Fabian Frederick
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • init_inodecache is only called by __init init_adfs_fs.

    Signed-off-by: Fabian Frederick
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Fabian Frederick
     
  • As sysctl_hung_task_timeout_sec is unsigned long, when this value is
    larger then LONG_MAX/HZ, the function schedule_timeout_interruptible in
    watchdog will return immediately without sleep and with print :

    schedule_timeout: wrong timeout value ffffffffffffff83

    and then the funtion watchdog will call schedule_timeout_interruptible
    again and again. The screen will be filled with

    "schedule_timeout: wrong timeout value ffffffffffffff83"

    This patch does some check and correction in sysctl, to let the function
    schedule_timeout_interruptible allways get the valid parameter.

    Signed-off-by: Liu Hua
    Tested-by: Satoru Takeuchi
    Cc: [3.4+]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Liu Hua
     
  • This patch removes an artificial RapidIO bus root device and establishes
    actual device hierarchy by providing reference to real parent devices.
    It also introduces device class for RapidIO controller devices (on-chip
    or an eternal bridge, known as "mport").

    Existing implementation was sufficient for SoC-based platforms that have
    a single RapidIO controller. With introduction of devices using
    multiple RapidIO controllers and PCIe-to-RapidIO bridges the old scheme
    is very limiting or does not work at all. The implemented changes allow
    to properly reference platform's local RapidIO mport devices and provide
    device details needed for upper layers.

    This change to RapidIO device hierarchy does not break any known
    existing kernel or user space interfaces.

    Signed-off-by: Alexandre Bounine
    Cc: Matt Porter
    Cc: Li Yang
    Cc: Kumar Gala
    Cc: Andre van Herk
    Cc: Stef van Os
    Cc: Jerry Jacobs
    Cc: Arno Tiemersma
    Cc: Rob Landley
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexandre Bounine
     
  • Combine SG entries describing single contiguous memory block into one
    Tsi721 BDMA descriptor. This reduces number of hardware descriptors
    required for large data transfers and improves performance on the PCIe
    side by reducing number of descriptor fetch requests.

    Signed-off-by: Alexandre Bounine
    Cc: Matt Porter
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexandre Bounine
     
  • Replace rcu_assign_pointer(x, NULL) with RCU_INIT_POINTER(x, NULL)

    The rcu_assign_pointer() ensures that the initialization of a structure
    is carried out before storing a pointer to that structure. And in the
    case of the NULL pointer, there is no structure to initialize.

    So, rcu_assign_pointer(p, NULL) can be safely converted to
    RCU_INIT_POINTER(p, NULL)

    Signed-off-by: Monam Agarwal
    Acked-by: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Monam Agarwal
     
  • Remove no longer used deprecated code, and make local functions
    static.

    Signed-off-by: Stephen Hemminger
    Acked-by: Jean Delvare
    Acked-by: Tejun Heo
    Cc: Jeff Layton
    Cc: Philipp Reisner
    Cc: Jens Axboe
    Cc: George Spelvin
    Cc: Randy Dunlap
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Stephen Hemminger
     
  • Currently when an empty PT_NOTE is detected, vmcore initialization
    fails. It sounds too harsh. Because PT_NOTE could be empty, for
    example, one offlined a cpu but never restarted kdump service, and after
    crash, PT_NOTE program header is there but no data contains. It's
    better to warn about the empty PT_NOTE and continue to initialise
    vmcore.

    And ultimately the multiple PT_NOTE are merged into a single one, all
    empty PT_NOTE are discarded naturally during the merge. So empty
    PT_NOTE is not visible to user space and vmcore is as good as expected.

    Signed-off-by: WANG Chao
    Cc: Vivek Goyal
    Cc: HATAYAMA Daisuke
    Cc: Greg Pearson
    Cc: Baoquan He
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    WANG Chao
     
  • Eliminate the following warning in proc/vmcore.c:

    fs/proc/vmcore.c:1088:6: warning: no previous prototype for `vmcore_cleanup' [-Wmissing-prototypes]

    [akpm@linux-foundation.org: clean up powerpc, remove unneeded EXPORT_SYMBOL]
    Signed-off-by: Rashika Kheria
    Reviewed-by: Josh Triplett
    Cc: Benjamin Herrenschmidt
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Rashika Kheria
     
  • Even if the main thread is dead the process still can stop/continue.
    However, if the leader is ptraced wait_consider_task(ptrace => false)
    always skips wait_task_stopped/wait_task_continued, so WSTOPPED or
    WCONTINUED can never work for the natural parent in this case.

    Move the "A zombie ptracee is only visible to its ptracer" check into the
    "if (!delay_group_leader(p))" block. ->notask_error is cleared by the
    "fall through" code below.

    This depends on the previous change, wait_task_stopped/continued must be
    avoided if !delay_group_leader() and the tracer is ->real_parent.
    Otherwise WSTOPPED|WEXITED could wrongly report "stopped" when the child
    is already dead (single-threaded or not). If it is traced by another task
    then the "stopped" state is fine until the debugger detaches and reveals a
    zombie state.

    Stupid test-case:

    void *tfunc(void *arg)
    {
    sleep(1); // wait for zombie leader
    raise(SIGSTOP);
    exit(0x13);
    return NULL;
    }

    int run_child(void)
    {
    pthread_t thread;

    if (!fork()) {
    int tracee = getppid();

    assert(ptrace(PTRACE_ATTACH, tracee, 0,0) == 0);
    do
    ptrace(PTRACE_CONT, tracee, 0,0);
    while (wait(NULL) > 0);

    return 0;
    }

    sleep(1); // wait for PTRACE_ATTACH
    assert(pthread_create(&thread, NULL, tfunc, NULL) == 0);
    pthread_exit(NULL);
    }

    int main(void)
    {
    int child, stat;

    child = fork();
    if (!child)
    return run_child();

    assert(child == waitpid(-1, &stat, WSTOPPED));
    assert(stat == 0x137f);

    kill(child, SIGCONT);

    assert(child == waitpid(-1, &stat, WCONTINUED));
    assert(stat == 0xffff);

    assert(child == waitpid(-1, &stat, 0));
    assert(stat == 0x1300);

    return 0;
    }

    Without this patch it hangs in waitpid(WSTOPPED), wait_task_stopped() is
    never called.

    Note: this doesn't fix all problems with a zombie delay_group_leader(),
    WCONTINUED | WEXITED check is not exactly right. debugger can't assume it
    will be notified if another thread reaps the whole thread group.

    Signed-off-by: Oleg Nesterov
    Cc: Al Viro
    Cc: Jan Kratochvil
    Cc: Lennart Poettering
    Cc: Michal Schmidt
    Cc: Roland McGrath
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • "A zombie is only visible to its ptracer" logic in wait_consider_task()
    is very wrong. Trivial test-case:

    #include
    #include
    #include
    #include

    int main(void)
    {
    int child = fork();

    if (!child) {
    assert(ptrace(PTRACE_TRACEME, 0,0,0) == 0);
    return 0x23;
    }

    assert(waitid(P_ALL, child, NULL, WEXITED | WNOWAIT) == 0);
    assert(waitid(P_ALL, 0, NULL, WSTOPPED) == -1);
    return 0;
    }

    it hangs in waitpid(WSTOPPED) despite the fact it has a single zombie
    child. This is because wait_consider_task(ptrace => 0) sees p->ptrace and
    cleares ->notask_error assuming that the debugger should detach and notify
    us.

    Change wait_consider_task(ptrace => 0) to pretend that ptrace == T if the
    child is traced by us. This really simplifies the logic and allows us to
    do more fixes, see the next changes. This also hides the unwanted group
    stop state automatically, we can remove another ptrace_reparented() check.

    Unfortunately, this adds the following behavioural changes:

    1. Before this patch wait(WEXITED | __WNOTHREAD) does not reap
    a natural child if it is traced by the caller's sub-thread.

    Hopefully nobody will ever notice this change, and I think
    that nobody should rely on this behaviour anyway.

    2. SIGNAL_STOP_CONTINUED is no longer hidden from debugger if
    it is real parent.

    While this change comes as a side effect, I think it is good
    by itself. The group continued state can not be consumed by
    another process in this case, it doesn't depend on ptrace,
    it doesn't make sense to hide it from real parent.

    Perhaps we should add the thread_group_leader() check before
    wait_task_continued()? May be, but this shouldn't depend on
    ptrace_reparented().

    Signed-off-by: Oleg Nesterov
    Cc: Al Viro
    Cc: Jan Kratochvil
    Cc: Lennart Poettering
    Cc: Michal Schmidt
    Cc: Roland McGrath
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • get_task_state() uses the most significant bit to report the state to
    user-space, this means that EXIT_ZOMBIE->EXIT_TRACE->EXIT_DEAD transition
    can be noticed via /proc as Z -> X -> Z change. Note that this was
    possible even before EXIT_TRACE was introduced.

    This is not really bad but imho it make sense to hide EXIT_TRACE from
    user-space completely. So the patch simply swaps EXIT_ZOMBIE and
    EXIT_DEAD, this way EXIT_TRACE will be seen as EXIT_ZOMBIE by user-space.

    Signed-off-by: Oleg Nesterov
    Cc: Jan Kratochvil
    Cc: Michal Schmidt
    Cc: Al Viro
    Cc: Lennart Poettering
    Cc: Roland McGrath
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov
     
  • Now that EXIT_DEAD is the terminal state it doesn't make sense to call
    eligible_child() or security_task_wait() if the task is really dead.

    Signed-off-by: Oleg Nesterov
    Tested-by: Michal Schmidt
    Cc: Jan Kratochvil
    Cc: Al Viro
    Cc: Lennart Poettering
    Cc: Roland McGrath
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Oleg Nesterov