08 Jun, 2012

1 commit

  • Commit 17cf28afea2a ("mm/fs: remove truncate_range") removed the
    truncate_range inode operation in favour of the fallocate file
    operation.

    When using SYSV IPC shared memory segments, calling madvise with the
    MADV_REMOVE advice on an area of shared memory will attempt to invoke
    the .fallocate function for the shm_file_operations, which is NULL and
    therefore returns -EOPNOTSUPP to userspace. The previous behaviour
    would inherit the inode_operations from the underlying tmpfs file and
    invoke truncate_range there.

    This patch restores the previous behaviour by wrapping the underlying
    fallocate function in shm_fallocate, as we do for fsync.

    [hughd@google.com: use -ENOTSUPP in shm_fallocate()]
    Signed-off-by: Will Deacon
    Acked-by: Hugh Dickins
    Signed-off-by: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Will Deacon
     

02 Jun, 2012

1 commit

  • Pull vfs changes from Al Viro.
    "A lot of misc stuff. The obvious groups:
    * Miklos' atomic_open series; kills the damn abuse of
    ->d_revalidate() by NFS, which was the major stumbling block for
    all work in that area.
    * ripping security_file_mmap() and dealing with deadlocks in the
    area; sanitizing the neighborhood of vm_mmap()/vm_munmap() in
    general.
    * ->encode_fh() switched to saner API; insane fake dentry in
    mm/cleancache.c gone.
    * assorted annotations in fs (endianness, __user)
    * parts of Artem's ->s_dirty work (jff2 and reiserfs parts)
    * ->update_time() work from Josef.
    * other bits and pieces all over the place.

    Normally it would've been in two or three pull requests, but
    signal.git stuff had eaten a lot of time during this cycle ;-/"

    Fix up trivial conflicts in Documentation/filesystems/vfs.txt (the
    'truncate_range' inode method was removed by the VM changes, the VFS
    update adds an 'update_time()' method), and in fs/btrfs/ulist.[ch] (due
    to sparse fix added twice, with other changes nearby).

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (95 commits)
    nfs: don't open in ->d_revalidate
    vfs: retry last component if opening stale dentry
    vfs: nameidata_to_filp(): don't throw away file on error
    vfs: nameidata_to_filp(): inline __dentry_open()
    vfs: do_dentry_open(): don't put filp
    vfs: split __dentry_open()
    vfs: do_last() common post lookup
    vfs: do_last(): add audit_inode before open
    vfs: do_last(): only return EISDIR for O_CREAT
    vfs: do_last(): check LOOKUP_DIRECTORY
    vfs: do_last(): make ENOENT exit RCU safe
    vfs: make follow_link check RCU safe
    vfs: do_last(): use inode variable
    vfs: do_last(): inline walk_component()
    vfs: do_last(): make exit RCU safe
    vfs: split do_lookup()
    Btrfs: move over to use ->update_time
    fs: introduce inode operation ->update_time
    reiserfs: get rid of resierfs_sync_super
    reiserfs: mark the superblock as dirty a bit later
    ...

    Linus Torvalds
     

01 Jun, 2012

12 commits

  • after all, 0 bytes and 0 pages is the same thing...

    Signed-off-by: Al Viro

    Al Viro
     
  • Signed-off-by: Al Viro

    Al Viro
     
  • When I wrote the first patch that added the rbtree support for message
    queue insertion, it sped up the case where the queue was very full
    drastically from the original code. It, however, slowed down the case
    where the queue was empty (not drastically though).

    This patch caches the last freed rbtree node struct so we can quickly
    reuse it when we get a new message. This is the common path for any queue
    that very frequently goes from 0 to 1 then back to 0 messages in queue.

    Andrew Morton didn't like that we were doing a GFP_ATOMIC allocation in
    msg_insert, so this patch attempts to speculatively allocate a new node
    struct outside of the spin lock when we know we need it, but will still
    fall back to a GFP_ATOMIC allocation if it has to.

    Once I added the caching, the necessary various ret = ; spin_unlock
    gyrations in mq_timedsend were getting pretty ugly, so this also slightly
    refactors that function to streamline the flow of the code and the
    function exit.

    Finally, while working on getting performance back I made sure that all of
    the node structs were always fully initialized when they were first used,
    rendering the use of kzalloc unnecessary and a waste of CPU cycles.

    The net result of all of this is:

    1) We will avoid a GFP_ATOMIC allocation when possible, but fall back
    on it when necessary.

    2) We will speculatively allocate a node struct using GFP_KERNEL if our
    cache is empty (and save the struct to our cache if it's still empty
    after we have obtained the spin lock).

    3) The performance of the common queue empty case has significantly
    improved and is now much more in line with the older performance for
    this case.

    The performance changes are:

    Old mqueue new mqueue new mqueue + caching
    queue empty
    send/recv 305/288ns 349/318ns 310/322ns

    I don't think we'll ever be able to get the recv performance back, but
    that's because the old recv performance was a direct result and
    consequence of the old methods abysmal send performance. The recv path
    simply must do more so that the send path does not incur such a penalty
    under higher queue depths.

    As it turns out, the new caching code also sped up the various queue full
    cases relative to my last patch. That could be because of the difference
    between the syscall path in 3.3.4-rc5 and 3.3.4-rc6, or because of the
    change in code flow in the mq_timedsend routine. Regardless, I'll take
    it. It wasn't huge, and I *would* say it was within the margin for error,
    but after many repeated runs what I'm seeing is that the old numbers trend
    slightly higher (about 10 to 20ns depending on which test is the one
    running).

    [akpm@linux-foundation.org: checkpatch fixes]
    Signed-off-by: Doug Ledford
    Cc: Frederic Weisbecker
    Cc: Manfred Spraul
    Cc: Stephen Rothwell
    Cc: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • We already check the mq attr struct if it's passed in, but now that the
    admin can set system wide defaults separate from maximums, it's actually
    possible to set the defaults to something that would overflow. So, if
    there is no attr struct passed in to the open call, check the default
    values.

    While we are at it, simplify mq_attr_ok() by making it return 0 or an
    error condition, so that way if we add more tests to it later, we have the
    option of what error should be returned instead of the calling location
    having to pick a possibly inaccurate error code.

    [akpm@linux-foundation.org: s/ENOMEM/EOVERFLOW/]
    Signed-off-by: Doug Ledford
    Cc: Stephen Rothwell
    Cc: Manfred Spraul
    Acked-by: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • While working on the other parts of the mqueue stuff, I noticed that the
    calculation for overflow in mq_attr_ok didn't actually match reality (this
    is especially true since my last patch which changed how we account memory
    slightly).

    In particular, we used to test for overflow using:
    msgs * msgsize + msgs * sizeof(struct msg_msg *)

    That was never really correct because each message we allocate via
    load_msg() is actually a struct msg_msg followed by the data for the
    message (and if struct msg_msg + data exceeds PAGE_SIZE we end up
    allocating struct msg_msgseg structs too, but accounting for them would
    get really tedious, so let's ignore those...they're only a pointer in size
    anyway). This patch updates the calculation to be more accurate in
    regards to maximum possible memory consumption by the mqueue.

    [akpm@linux-foundation.org: add a local to simplify overflow-checking expression]
    Signed-off-by: Doug Ledford
    Cc: Stephen Rothwell
    Cc: Manfred Spraul
    Acked-by: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • The existing implementation of the POSIX message queue send and recv
    functions is, well, abysmal. Even worse than abysmal. I submitted a
    patch to increase the maximum POSIX message queue limit to 65536 due to
    customer needs, however, upon looking over the send/recv implementation, I
    realized that my customer needs help with that too even if they don't know
    it. The basic problem is that, given the fairly typical use case scenario
    for a large queue of queueing lots of messages all at the same priority (I
    verified with my customer that this is indeed what their app does), the
    msg_insert routine is basically a frikkin' bubble sort. I mean, whoa,
    that's *so* middle school.

    OK, OK, to not slam the original author too much, I'm sure they didn't
    envision a queue depth of 50,000+ messages. No one would think that
    moving elements in an array, one at a time, and dereferencing each pointer
    in that array to check priority of the message being pointed too, again
    one at a time, for 50,000+ times would be good. So let's assume that, as
    is typical, the users have found a way to break our code simply by using
    it in a way we didn't envision. Fair enough.

    "So, just how broken is it?", you ask. I wondered the same thing, so I
    wrote an app to let me know. It's my next patch. It gave me some
    interesting results. Here's what it tested:

    Interference with other apps - In continuous mode, the app just sits there
    and hits a message queue forever, while you go do something productive on
    another terminal using other CPUs. You then measure how long it takes you
    to do that something productive. Then you restart the app in fake
    continuous mode, and it sits in a tight loop on a CPU while you repeat
    your tests. The whole point of this is to keep one CPU tied up (so it
    can't be used in your other work) but in one case tied up hitting the
    mqueue code so we can see the effect of walking that 65,528 element array
    one pointer at a time on the global CPU cache. If it's bad, then it will
    slow down your app on the other CPUs just by polluting cache mercilessly.
    In the fake case, it will be in a tight loop, but not polluting cache.
    Testing the mqueue subsystem directly - Here we just run a number of tests
    to see how the mqueue subsystem performs under different conditions. A
    couple conditions are known to be worst case for the old system, and some
    routines, so this tests all of them.

    So, on to the results already:

    Subsystem/Test Old New

    Time to compile linux
    kernel (make -j12 on a
    6 core CPU)
    Running mqueue test user 49m10.744s user 45m26.294s
    sys 5m51.924s sys 4m59.894s
    total 55m02.668s total 50m26.188s

    Running fake test user 45m32.686s user 45m18.552s
    sys 5m12.465s sys 4m56.468s
    total 50m45.151s total 50m15.020s

    % slowdown from mqueue
    cache thrashing ~8% ~.5%

    Avg time to send/recv (in nanoseconds per message)
    when queue empty 305/288 349/318
    when queue full (65528 messages)
    constant priority 526589/823 362/314
    increasing priority 403105/916 495/445
    decreasing priority 73420/594 482/409
    random priority 280147/920 546/436

    Time to fill/drain queue (65528 messages, in seconds)
    constant priority 17.37/.12 .13/.12
    increasing priority 4.14/.14 .21/.18
    decreasing priority 12.93/.13 .21/.18
    random priority 8.88/.16 .22/.17

    So, I think the results speak for themselves. It's possible this
    implementation could be improved by cacheing at least one priority level
    in the node tree (that would bring the queue empty performance more in
    line with the old implementation), but this works and is *so* much better
    than what we had, especially for the common case of a single priority in
    use, that further refinements can be in follow on patches.

    [akpm@linux-foundation.org: fix typo in comment, remove stray semicolon]
    [levinsasha928@gmail.com: use correct gfp flags in msg_insert]
    Signed-off-by: Doug Ledford
    Cc: Stephen Rothwell
    Cc: Manfred Spraul
    Acked-by: KOSAKI Motohiro
    Signed-off-by: Sasha Levin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • Commit b231cca4381e ("message queues: increase range limits") changed
    mqueue default value when attr parameter is specified NULL from hard
    coded value to fs.mqueue.{msg,msgsize}_max sysctl value.

    This made large side effect. When user need to use two mqueue
    applications 1) using !NULL attr parameter and it require big message
    size and 2) using NULL attr parameter and only need small size message,
    app (1) require to raise fs.mqueue.msgsize_max and app (2) consume large
    memory size even though it doesn't need.

    Doug Ledford propsed to switch back it to static hard coded value.
    However it also has a compatibility problem. Some applications might
    started depend on the default value is tunable.

    The solution is to separate default value from maximum value.

    Signed-off-by: KOSAKI Motohiro
    Signed-off-by: Doug Ledford
    Acked-by: Doug Ledford
    Acked-by: Joe Korty
    Cc: Amerigo Wang
    Acked-by: Serge E. Hallyn
    Cc: Jiri Slaby
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    KOSAKI Motohiro
     
  • KMALLOC_MAX_SIZE is not a good threshold. It is extremely high and
    problematic. Unfortunately, some silly drivers depend on this and we
    can't change it. But any new code needn't use such extreme ugly high
    order allocations. It brings us awful fragmentation issues and system
    slowdown.

    Signed-off-by: KOSAKI Motohiro
    Acked-by: Doug Ledford
    Acked-by: Joe Korty
    Cc: Amerigo Wang
    Cc: Serge E. Hallyn
    Cc: Jiri Slaby
    Cc: Joe Korty
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    KOSAKI Motohiro
     
  • Commit b231cca4381e ("message queues: increase range limits") changed the
    maximum size of a message in a message queue from INT_MAX to 8192*128.
    Unfortunately, we had customers that relied on a size much larger than
    8192*128 on their production systems. After reviewing POSIX, we found
    that it is silent on the maximum message size. We did find a couple other
    areas in which it was not silent. Fix up the mqueue maximums so that the
    customer's system can continue to work, and document both the POSIX and
    real world requirements in ipc_namespace.h so that we don't have this
    issue crop back up.

    Also, commit 9cf18e1dd74cd0 ("ipc: HARD_MSGMAX should be higher not lower
    on 64bit") fiddled with HARD_MSGMAX without realizing that the number was
    intentionally in place to limit the msg queue depth to one that was small
    enough to kmalloc an array of pointers (hence why we divided 128k by
    sizeof(long)). If we wish to meet POSIX requirements, we have no choice
    but to change our allocation to a vmalloc instead (at least for the large
    queue size case). With that, it's possible to increase our allowed
    maximum to the POSIX requirements (or more if we choose).

    [sfr@canb.auug.org.au: using vmalloc requires including vmalloc.h]
    Signed-off-by: Doug Ledford
    Cc: Serge E. Hallyn
    Cc: Amerigo Wang
    Cc: Joe Korty
    Cc: Jiri Slaby
    Acked-by: KOSAKI Motohiro
    Cc: Manfred Spraul
    Signed-off-by: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • In two places we don't enforce the hard limits for CAP_SYS_RESOURCE apps.
    In preparation for making more reasonable hard limits, start enforcing
    them even on CAP_SYS_RESOURCE.

    Signed-off-by: Doug Ledford
    Cc: Serge E. Hallyn
    Cc: Amerigo Wang
    Cc: Joe Korty
    Cc: Jiri Slaby
    Acked-by: KOSAKI Motohiro
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • Commit b231cca4381e ("message queues: increase range limits") changed
    how we create a queue that does not include an attr struct passed to
    open so that it creates the queue with whatever the maximum values are.
    However, if the admin has set the maximums to allow flexibility in
    creating a queue (aka, both a large size and large queue are allowed,
    but combined they create a queue too large for the RLIMIT_MSGQUEUE of
    the user), then attempts to create a queue without an attr struct will
    fail. Switch back to using acceptable defaults regardless of what the
    maximums are.

    Note: so far, we only know of a few applications that rely on this
    behavior (specifically, set the maximums in /proc, then run the
    application which calls mq_open() without passing in an attr struct, and
    the application expects the newly created message queue to have the
    maximum sizes that were set in /proc used on the mq_open() call, and all
    of those applications that we know of are actually part of regression
    test suites that were coded to do something like this:

    for size in 4096 65536 $((1024 * 1024)) $((16 * 1024 * 1024)); do
    echo $size > /proc/sys/fs/mqueue/msgsize_max
    mq_open || echo "Error opening mq with size $size"
    done

    These test suites that depend on any behavior like this are broken. The
    concept that programs should rely upon the system wide maximum in order
    to get their desired results instead of simply using a attr struct to
    specify what they want is fundamentally unfriendly programming practice
    for any multi-tasking OS.

    Fixing this will break those few apps that we know of (and those app
    authors recognize the brokenness of their code and the need to fix it).
    However, the following patch "mqueue: separate mqueue default value"
    allows a workaround in the form of new knobs for the default msg queue
    creation parameters for any software out there that we don't already
    know about that might rely on this behavior at the moment.

    Signed-off-by: Doug Ledford
    Cc: Serge E. Hallyn
    Cc: Amerigo Wang
    Cc: Joe Korty
    Cc: Jiri Slaby
    Acked-by: KOSAKI Motohiro
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     
  • Since commit b231cca4381e ("message queues: increase range limits") on
    Oct 18, 2008, calls to mq_open() that did not pass in an attribute
    struct and expected to get default values for the size of the queue and
    the max message size now get the system wide maximums instead of
    hardwired defaults like they used to get.

    This was uncovered when one of the earlier patches in this patch set
    increased the default system wide maximums at the same time it increased
    the hard ceiling on the system wide maximums (a customer specifically
    needed the hard ceiling brought back up, the new ceiling that commit
    b231cca4381e introduced was too low for their production systems). By
    increasing the default maximums and not realising they were tied to any
    attempt to create a message queue without an attribute struct, I had
    inadvertently made it such that all message queue creation attempts
    without an attribute struct were failing because the new default
    maximums would create a queue that exceeded the default rlimit for
    message queue bytes.

    As a result, the system wide defaults were brought back down to their
    previous levels, and the system wide ceilings on the maximums were
    raised to meet the customer's needs. However, the fact that the no
    attribute struct behavior of mq_open() could be broken by changing the
    system wide maximums for message queues was seen as fundamentally broken
    itself. So we hardwired the no attribute case back like it used to be.
    But, then we realized that on the very off chance that some piece of
    software in the wild depended on that behavior, we could work around
    that issue by adding two new knobs to /proc that allowed setting the
    defaults for message queues created without an attr struct separately
    from the system wide maximums.

    What is not an option IMO is to leave the current behavior in place. No
    piece of software should ever rely on setting the system wide maximums
    in order to get a desired message queue. Such a reliance would be so
    fundamentally multitasking OS unfriendly as to not really be tolerable.
    Fortunately, we don't know of any software in the wild that uses this
    except for a regression test program that caught the issue in the first
    place. If there is though, we have made accommodations with the two new
    /proc knobs (and that's all the accommodations such fundamentally broken
    software can be allowed)..

    This patch:

    The various defines for minimums and maximums of the sysctl controllable
    mqueue values are scattered amongst different files and named
    inconsistently. Move them all into ipc_namespace.h and make them have
    consistent names. Additionally, make the number of queues per namespace
    also have a minimum and maximum and use the same sysctl function as the
    other two settable variables.

    Signed-off-by: Doug Ledford
    Acked-by: Serge E. Hallyn
    Cc: Amerigo Wang
    Cc: Joe Korty
    Cc: Jiri Slaby
    Acked-by: KOSAKI Motohiro
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Doug Ledford
     

29 May, 2012

1 commit

  • Pull writeback tree from Wu Fengguang:
    "Mainly from Jan Kara to avoid iput() in the flusher threads."

    * tag 'writeback' of git://git.kernel.org/pub/scm/linux/kernel/git/wfg/linux:
    writeback: Avoid iput() from flusher thread
    vfs: Rename end_writeback() to clear_inode()
    vfs: Move waiting for inode writeback from end_writeback() to evict_inode()
    writeback: Refactor writeback_single_inode()
    writeback: Remove wb->list_lock from writeback_single_inode()
    writeback: Separate inode requeueing after writeback
    writeback: Move I_DIRTY_PAGES handling
    writeback: Move requeueing when I_SYNC set to writeback_sb_inodes()
    writeback: Move clearing of I_SYNC into inode_sync_complete()
    writeback: initialize global_dirty_limit
    fs: remove 8 bytes of padding from struct writeback_control on 64 bit builds
    mm: page-writeback.c: local functions should not be exposed globally

    Linus Torvalds
     

06 May, 2012

1 commit

  • After we moved inode_sync_wait() from end_writeback() it doesn't make sense
    to call the function end_writeback() anymore. Rename it to clear_inode()
    which well says what the function really does - set I_CLEAR flag.

    Signed-off-by: Jan Kara
    Signed-off-by: Fengguang Wu

    Jan Kara
     

03 May, 2012

1 commit


08 Apr, 2012

2 commits


30 Mar, 2012

1 commit


23 Mar, 2012

1 commit

  • Merge first batch of patches from Andrew Morton:
    "A few misc things and all the MM queue"

    * emailed from Andrew Morton : (92 commits)
    memcg: avoid THP split in task migration
    thp: add HPAGE_PMD_* definitions for !CONFIG_TRANSPARENT_HUGEPAGE
    memcg: clean up existing move charge code
    mm/memcontrol.c: remove unnecessary 'break' in mem_cgroup_read()
    mm/memcontrol.c: remove redundant BUG_ON() in mem_cgroup_usage_unregister_event()
    mm/memcontrol.c: s/stealed/stolen/
    memcg: fix performance of mem_cgroup_begin_update_page_stat()
    memcg: remove PCG_FILE_MAPPED
    memcg: use new logic for page stat accounting
    memcg: remove PCG_MOVE_LOCK flag from page_cgroup
    memcg: simplify move_account() check
    memcg: remove EXPORT_SYMBOL(mem_cgroup_update_page_stat)
    memcg: kill dead prev_priority stubs
    memcg: remove PCG_CACHE page_cgroup flag
    memcg: let css_get_next() rely upon rcu_read_lock()
    cgroup: revert ss_id_lock to spinlock
    idr: make idr_get_next() good for rcu_read_lock()
    memcg: remove unnecessary thp check in page stat accounting
    memcg: remove redundant returns
    memcg: enum lru_list lru
    ...

    Linus Torvalds
     

22 Mar, 2012

2 commits

  • When calling shmget() with SHM_HUGETLB, shmget aligns the request size to
    PAGE_SIZE, but this is not sufficient.

    Modify hugetlb_file_setup() to align requests to the huge page size, and
    to accept an address argument so that all alignment checks can be
    performed in hugetlb_file_setup(), rather than in its callers. Change
    newseg() and mmap_pgoff() to match the new prototype and eliminate a now
    redundant alignment check.

    [akpm@linux-foundation.org: fix build]
    Signed-off-by: Steven Truelove
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Steven Truelove
     
  • Pull vfs pile 1 from Al Viro:
    "This is _not_ all; in particular, Miklos' and Jan's stuff is not there
    yet."

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (64 commits)
    ext4: initialization of ext4_li_mtx needs to be done earlier
    debugfs-related mode_t whack-a-mole
    hfsplus: add an ioctl to bless files
    hfsplus: change finder_info to u32
    hfsplus: initialise userflags
    qnx4: new helper - try_extent()
    qnx4: get rid of qnx4_bread/qnx4_getblk
    take removal of PF_FORKNOEXEC to flush_old_exec()
    trim includes in inode.c
    um: uml_dup_mmap() relies on ->mmap_sem being held, but activate_mm() doesn't hold it
    um: embed ->stub_pages[] into mmu_context
    gadgetfs: list_for_each_safe() misuse
    ocfs2: fix leaks on failure exits in module_init
    ecryptfs: make register_filesystem() the last potential failure exit
    ntfs: forgets to unregister sysctls on register_filesystem() failure
    logfs: missing cleanup on register_filesystem() failure
    jfs: mising cleanup on register_filesystem() failure
    make configfs_pin_fs() return root dentry on success
    configfs: configfs_create_dir() has parent dentry in dentry->d_parent
    configfs: sanitize configfs_create()
    ...

    Linus Torvalds
     

21 Mar, 2012

1 commit


16 Mar, 2012

1 commit

  • When using the "compat" APIs, architectures will generally want to
    be able to make direct syscalls to msgsnd(), shmctl(), etc., and
    in the kernel we would want them to be handled directly by
    compat_sys_xxx() functions, as is true for other compat syscalls.

    However, for historical reasons, several of the existing compat IPC
    syscalls do not do this. semctl() expects a pointer to the fourth
    argument, instead of the fourth argument itself. msgsnd(), msgrcv()
    and shmat() expect arguments in different order.

    This change adds an ARCH_WANT_OLD_COMPAT_IPC config option that can be
    set to preserve this behavior for ports that use it (x86, sparc, powerpc,
    s390, and mips). No actual semantics are changed for those architectures,
    and there is only a minimal amount of code refactoring in ipc/compat.c.

    Newer architectures like tile (and perhaps future architectures such
    as arm64 and unicore64) should not select this option, and thus can
    avoid having any IPC-specific code at all in their architecture-specific
    compat layer. In the same vein, if this option is not selected, IPC_64
    mode is assumed, since that's what the headers expect.

    The workaround code in "tile" for msgsnd() and msgrcv() is removed
    with this change; it also fixes the bug that shmat() and semctl() were
    not being properly handled.

    Reviewed-by: Arnd Bergmann
    Signed-off-by: Chris Metcalf

    Chris Metcalf
     

14 Feb, 2012

1 commit


24 Jan, 2012

3 commits

  • Commit cc39c6a9bbde ("mm: account skipped entries to avoid looping in
    find_get_pages") correctly fixed an infinite loop; but left a problem
    that find_get_pages() on shmem would return 0 (appearing to callers to
    mean end of tree) when it meets a run of nr_pages swap entries.

    The only uses of find_get_pages() on shmem are via pagevec_lookup(),
    called from invalidate_mapping_pages(), and from shmctl SHM_UNLOCK's
    scan_mapping_unevictable_pages(). The first is already commented, and
    not worth worrying about; but the second can leave pages on the
    Unevictable list after an unusual sequence of swapping and locking.

    Fix that by using shmem_find_get_pages_and_swap() (then ignoring the
    swap) instead of pagevec_lookup().

    But I don't want to contaminate vmscan.c with shmem internals, nor
    shmem.c with LRU locking. So move scan_mapping_unevictable_pages() into
    shmem.c, renaming it shmem_unlock_mapping(); and rename
    check_move_unevictable_page() to check_move_unevictable_pages(), looping
    down an array of pages, oftentimes under the same lock.

    Leave out the "rotate unevictable list" block: that's a leftover from
    when this was used for /proc/sys/vm/scan_unevictable_pages, whose flawed
    handling involved looking at pages at tail of LRU.

    Was there significance to the sequence first ClearPageUnevictable, then
    test page_evictable, then SetPageUnevictable here? I think not, we're
    under LRU lock, and have no barriers between those.

    Signed-off-by: Hugh Dickins
    Reviewed-by: KOSAKI Motohiro
    Cc: Minchan Kim
    Cc: Rik van Riel
    Cc: Shaohua Li
    Cc: Eric Dumazet
    Cc: Johannes Weiner
    Cc: Michel Lespinasse
    Cc: [back to 3.1 but will need respins]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hugh Dickins
     
  • scan_mapping_unevictable_pages() is used to make SysV SHM_LOCKed pages
    evictable again once the shared memory is unlocked. It does this with
    pagevec_lookup()s across the whole object (which might occupy most of
    memory), and takes 300ms to unlock 7GB here. A cond_resched() every
    PAGEVEC_SIZE pages would be good.

    However, KOSAKI-san points out that this is called under shmem.c's
    info->lock, and it's also under shm.c's shm_lock(), both spinlocks.
    There is no strong reason for that: we need to take these pages off the
    unevictable list soonish, but those locks are not required for it.

    So move the call to scan_mapping_unevictable_pages() from shmem.c's
    unlock handling up to shm.c's unlock handling. Remove the recently
    added barrier, not needed now we have spin_unlock() before the scan.

    Use get_file(), with subsequent fput(), to make sure we have a reference
    to mapping throughout scan_mapping_unevictable_pages(): that's something
    that was previously guaranteed by the shm_lock().

    Remove shmctl's lru_add_drain_all(): we don't fault in pages at SHM_LOCK
    time, and we lazily discover them to be Unevictable later, so it serves
    no purpose for SHM_LOCK; and serves no purpose for SHM_UNLOCK, since
    pages still on pagevec are not marked Unevictable.

    The original code avoided redundant rescans by checking VM_LOCKED flag
    at its level: now avoid them by checking shp's SHM_LOCKED.

    The original code called scan_mapping_unevictable_pages() on a locked
    area at shm_destroy() time: perhaps we once had accounting cross-checks
    which required that, but not now, so skip the overhead and just let
    inode eviction deal with them.

    Put check_move_unevictable_page() and scan_mapping_unevictable_pages()
    under CONFIG_SHMEM (with stub for the TINY case when ramfs is used),
    more as comment than to save space; comment them used for SHM_UNLOCK.

    Signed-off-by: Hugh Dickins
    Reviewed-by: KOSAKI Motohiro
    Cc: Minchan Kim
    Cc: Rik van Riel
    Cc: Shaohua Li
    Cc: Eric Dumazet
    Cc: Johannes Weiner
    Cc: Michel Lespinasse
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Hugh Dickins
     
  • Because the current task is being used to get the limit, we can simply
    use rlimit() instead of task_rlimit().

    Signed-off-by: Davidlohr Bueso
    Acked-by: KOSAKI Motohiro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Davidlohr Bueso
     

11 Jan, 2012

1 commit

  • ipc/mqueue.c: for __SI_MESQ, convert the uid being sent to recipient's
    user namespace. (new, thanks Oleg)

    __send_signal: convert current's uid to the recipient's user namespace
    for any siginfo which is not SI_FROMKERNEL (patch from Oleg, thanks
    again :)

    do_notify_parent and do_notify_parent_cldstop: map task's uid to parent's
    user namespace

    ptrace_signal maps parent's uid into current's user namespace before
    including in signal to current. IIUC Oleg has argued that this shouldn't
    matter as the debugger will play with it, but it seems like not converting
    the value currently being set is misleading.

    Changelog:
    Sep 20: Inspired by Oleg's suggestion, define map_cred_ns() helper to
    simplify callers and help make clear what we are translating
    (which uid into which namespace). Passing the target task would
    make callers even easier to read, but we pass in user_ns because
    current_user_ns() != task_cred_xxx(current, user_ns).
    Sep 20: As recommended by Oleg, also put task_pid_vnr() under rcu_read_lock
    in ptrace_signal().
    Sep 23: In send_signal(), detect when (user) signal is coming from an
    ancestor or unrelated user namespace. Pass that on to __send_signal,
    which sets si_uid to 0 or overflowuid if needed.
    Oct 12: Base on Oleg's fixup_uid() patch. On top of that, handle all
    SI_FROMKERNEL cases at callers, because we can't assume sender is
    current in those cases.
    Nov 10: (mhelsley) rename fixup_uid to more meaningful usern_fixup_signal_uid
    Nov 10: (akpm) make the !CONFIG_USER_NS case clearer

    Signed-off-by: Serge Hallyn
    Cc: Oleg Nesterov
    Cc: Matt Helsley
    Cc: "Eric W. Biederman"
    From: Serge Hallyn
    Subject: __send_signal: pass q->info, not info, to userns_fixup_signal_uid (v2)

    Eric Biederman pointed out that passing info is a bug and could lead to a
    NULL pointer deref to boot.

    A collection of signal, securebits, filecaps, cap_bounds, and a few other
    ltp tests passed with this kernel.

    Changelog:
    Nov 18: previous patch missed a leading '&'

    Signed-off-by: Serge Hallyn
    Cc: "Eric W. Biederman"
    From: Dan Carpenter
    Subject: ipc/mqueue: lock() => unlock() typo

    There was a double lock typo introduced in b085f4bd6b21 "user namespace:
    make signal.c respect user namespaces"

    Signed-off-by: Dan Carpenter
    Cc: Oleg Nesterov
    Cc: Matt Helsley
    Cc: "Eric W. Biederman"
    Acked-by: Serge Hallyn
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Serge E. Hallyn
     

04 Jan, 2012

4 commits


09 Dec, 2011

1 commit


03 Nov, 2011

3 commits

  • include/linux/sem.h contains several structures that are only used within
    ipc/sem.c.

    The patch moves them into ipc/sem.c - there is no need to expose the
    structures to the whole kernel.

    No functional changes, only whitespace cleanups and 80-char per line
    fixes.

    Signed-off-by: Manfred Spraul
    Acked-by: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Mike Galbraith
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Manfred Spraul
     
  • semtimedop() does not handle spurious wakeups, it returns -EINTR to user
    space. Most other schedule() users would just loop and not return to user
    space. The patch adds such a loop to semtimedop()

    Signed-off-by: Manfred Spraul
    Reported-by: Peter Zijlstra
    Acked-by: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Mike Galbraith
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Manfred Spraul
     
  • sys_semtimedop() may return -EIDRM although the semaphore operation
    completed successfully:

    thread 1: thread 2:
    semtimedop(), sleeps
    semop():
    * acquires sem_lock()
    semtimedop() woken up due to timeout
    sem_lock() loops
    * notices that thread 2 could be completed.
    * performs the operations that thread 2 is sleeping on.
    * marks the semaphore operation as IN_WAKEUP
    * drops sem_lock(), does wakeup, sets return code to 0
    * thread delayed due to interrupt, whatever
    * returns to user space
    * thread still delayed
    semctl(IPC_RMID)
    * acquires sem_lock()
    * ipc_rmid(), ipcp->deleted=1
    * drops sem_lock()
    * thread finally continues - but seem_lock()
    now fails due to ipcp->deleted == 1
    * returns -EIDRM instead of 0

    The fix is trivial: Always use the return code in queue.status.

    In real world, the race probably doesn't matter:
    If the semaphore array is destroyed, the app is probably not interested
    if the last operation succeeded or was already cancelled.

    Signed-off-by: Manfred Spraul
    Cc: Thomas Gleixner
    Cc: Mike Galbraith
    Acked-by: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Manfred Spraul
     

01 Nov, 2011

1 commit

  • Fix the wrong use of schedule_hrtimeout_range_clock() in wq_sleep(),
    although it is harmless for the syscall mq_timed* now. It was introduced
    by 9ca7d8e ("mqueue: Convert message queue timeout to use hrtimers").

    Signed-off-by: Wanlong Gao
    Cc: Carsten Emde
    Cc: Thomas Gleixner
    Cc: Manfred Spraul
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Wanlong Gao
     

05 Aug, 2011

1 commit

  • This isn't really critical any more, since other patches (commit
    298507d4d2cf: "shm: optimize exit_shm()") have caused us to not actually
    need to touch the rw_mutex unless there are actual shm segments
    associated with the namespace, but we really should do tne shm_init_ns()
    earlier than we do now.

    This, together with commit 288d5abec831 ("Boot up with usermodehelper
    disabled") will mean that we really do initialize the initial ipc
    namespace data structure before we run any tasks.

    Tested-by: Marc Zyngier
    Signed-off-by: Linus Torvalds

    Linus Torvalds