Merge branch 'stable-3.2' into pandora-3.2
authorGrazvydas Ignotas <notasas@gmail.com>
Sun, 23 Oct 2016 19:10:54 +0000 (22:10 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 23 Oct 2016 19:10:54 +0000 (22:10 +0300)
1  2 
arch/arm/kernel/ptrace.c
drivers/mmc/core/mmc.c
drivers/mtd/ubi/eba.c
fs/ubifs/file.c
include/linux/mm.h
kernel/exit.c
kernel/sched.c
mm/memory.c

diff --combined arch/arm/kernel/ptrace.c
@@@ -726,8 -726,8 +726,8 @@@ static int vfp_set(struct task_struct *
        if (ret)
                return ret;
  
-       vfp_flush_hwstate(thread);
        thread->vfpstate.hard = new_vfp;
+       vfp_flush_hwstate(thread);
  
        return 0;
  }
@@@ -842,7 -842,7 +842,7 @@@ long arch_ptrace(struct task_struct *ch
  #endif
  
                case PTRACE_GET_THREAD_AREA:
 -                      ret = put_user(task_thread_info(child)->tp_value,
 +                      ret = put_user(task_thread_info(child)->tp_value[0],
                                       datap);
                        break;
  
diff --combined drivers/mmc/core/mmc.c
@@@ -235,6 -235,9 +235,9 @@@ static int mmc_get_ext_csd(struct mmc_c
        return err;
  }
  
+ /* Minimum partition switch timeout in milliseconds */
+ #define MMC_MIN_PART_SWITCH_TIME      300
  /*
   * Decode extended CSD.
   */
@@@ -325,6 -328,10 +328,10 @@@ static int mmc_read_ext_csd(struct mmc_
  
                /* EXT_CSD value is in units of 10ms, but we store in ms */
                card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME];
+               /* Some eMMC set the value too low so set a minimum */
+               if (card->ext_csd.part_time &&
+                   card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME)
+                       card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME;
  
                /* Sleep / awake timeout in 100ns units */
                if (sa_shift > 0 && sa_shift <= 0x17)
@@@ -1104,14 -1111,6 +1111,14 @@@ static void mmc_remove(struct mmc_host 
        host->card = NULL;
  }
  
 +/*
 + * Card detection - card is alive.
 + */
 +static int mmc_alive(struct mmc_host *host)
 +{
 +      return mmc_send_status(host->card, NULL);
 +}
 +
  /*
   * Card detection callback from host.
   */
@@@ -1127,7 -1126,7 +1134,7 @@@ static void mmc_detect(struct mmc_host 
        /*
         * Just check if our card has been removed.
         */
 -      err = mmc_send_status(host->card, NULL);
 +      err = _mmc_detect_card_removed(host);
  
        mmc_release_host(host);
  
@@@ -1232,7 -1231,6 +1239,7 @@@ static const struct mmc_bus_ops mmc_op
        .suspend = NULL,
        .resume = NULL,
        .power_restore = mmc_power_restore,
 +      .alive = mmc_alive,
  };
  
  static const struct mmc_bus_ops mmc_ops_unsafe = {
        .suspend = mmc_suspend,
        .resume = mmc_resume,
        .power_restore = mmc_power_restore,
 +      .alive = mmc_alive,
  };
  
  static void mmc_attach_bus_ops(struct mmc_host *host)
diff --combined drivers/mtd/ubi/eba.c
@@@ -341,7 -341,7 +341,7 @@@ int ubi_eba_unmap_leb(struct ubi_devic
        dbg_eba("erase LEB %d:%d, PEB %d", vol_id, lnum, pnum);
  
        vol->eba_tbl[lnum] = UBI_LEB_UNMAPPED;
 -      err = ubi_wl_put_peb(ubi, pnum, 0);
 +      err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 0);
  
  out_unlock:
        leb_write_unlock(ubi, vol_id, lnum);
@@@ -420,8 -420,9 +420,8 @@@ retry
                                 */
                                if (err == UBI_IO_BAD_HDR_EBADMSG ||
                                    err == UBI_IO_BAD_HDR) {
 -                                      ubi_warn("corrupted VID header at PEB "
 -                                               "%d, LEB %d:%d", pnum, vol_id,
 -                                               lnum);
 +                                      ubi_warn("corrupted VID header at PEB %d, LEB %d:%d",
 +                                               pnum, vol_id, lnum);
                                        err = -EBADMSG;
                                } else
                                        ubi_ro_mode(ubi);
@@@ -500,13 -501,14 +500,14 @@@ static int recover_peb(struct ubi_devic
        int err, idx = vol_id2idx(ubi, vol_id), new_pnum, data_size, tries = 0;
        struct ubi_volume *vol = ubi->volumes[idx];
        struct ubi_vid_hdr *vid_hdr;
+       uint32_t crc;
  
        vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
        if (!vid_hdr)
                return -ENOMEM;
  
  retry:
 -      new_pnum = ubi_wl_get_peb(ubi, UBI_UNKNOWN);
 +      new_pnum = ubi_wl_get_peb(ubi);
        if (new_pnum < 0) {
                ubi_free_vid_hdr(ubi, vid_hdr);
                return new_pnum;
                goto out_put;
        }
  
-       vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
-       err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr);
-       if (err)
-               goto write_error;
+       ubi_assert(vid_hdr->vol_type == UBI_VID_DYNAMIC);
  
-       data_size = offset + len;
        mutex_lock(&ubi->buf_mutex);
 -      memset(ubi->peb_buf1 + offset, 0xFF, len);
 +      memset(ubi->peb_buf + offset, 0xFF, len);
  
        /* Read everything before the area where the write failure happened */
        if (offset > 0) {
 -              err = ubi_io_read_data(ubi, ubi->peb_buf1, pnum, 0, offset);
 +              err = ubi_io_read_data(ubi, ubi->peb_buf, pnum, 0, offset);
                if (err && err != UBI_IO_BITFLIPS)
                        goto out_unlock;
        }
  
 -      memcpy(ubi->peb_buf1 + offset, buf, len);
 +      memcpy(ubi->peb_buf + offset, buf, len);
  
 -      crc = crc32(UBI_CRC32_INIT, ubi->peb_buf1, data_size);
+       data_size = offset + len;
 -      err = ubi_io_write_data(ubi, ubi->peb_buf1, new_pnum, 0, data_size);
++      crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size);
+       vid_hdr->sqnum = cpu_to_be64(next_sqnum(ubi));
+       vid_hdr->copy_flag = 1;
+       vid_hdr->data_size = cpu_to_be32(data_size);
+       vid_hdr->data_crc = cpu_to_be32(crc);
+       err = ubi_io_write_vid_hdr(ubi, new_pnum, vid_hdr);
+       if (err) {
+               mutex_unlock(&ubi->buf_mutex);
+               goto write_error;
+       }
 +      err = ubi_io_write_data(ubi, ubi->peb_buf, new_pnum, 0, data_size);
        if (err) {
                mutex_unlock(&ubi->buf_mutex);
                goto write_error;
        ubi_free_vid_hdr(ubi, vid_hdr);
  
        vol->eba_tbl[lnum] = new_pnum;
 -      ubi_wl_put_peb(ubi, pnum, 1);
 +      ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
  
        ubi_msg("data was successfully recovered");
        return 0;
  out_unlock:
        mutex_unlock(&ubi->buf_mutex);
  out_put:
 -      ubi_wl_put_peb(ubi, new_pnum, 1);
 +      ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1);
        ubi_free_vid_hdr(ubi, vid_hdr);
        return err;
  
@@@ -567,7 -577,7 +576,7 @@@ write_error
         * get another one.
         */
        ubi_warn("failed to write to PEB %d", new_pnum);
 -      ubi_wl_put_peb(ubi, new_pnum, 1);
 +      ubi_wl_put_peb(ubi, vol_id, lnum, new_pnum, 1);
        if (++tries > UBI_IO_RETRIES) {
                ubi_free_vid_hdr(ubi, vid_hdr);
                return err;
   * @buf: the data to write
   * @offset: offset within the logical eraseblock where to write
   * @len: how many bytes to write
 - * @dtype: data type
   *
   * This function writes data to logical eraseblock @lnum of a dynamic volume
   * @vol. Returns zero in case of success and a negative error code in case
   * written to the flash media, but may be some garbage.
   */
  int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
 -                    const void *buf, int offset, int len, int dtype)
 +                    const void *buf, int offset, int len)
  {
        int err, pnum, tries = 0, vol_id = vol->vol_id;
        struct ubi_vid_hdr *vid_hdr;
        vid_hdr->data_pad = cpu_to_be32(vol->data_pad);
  
  retry:
 -      pnum = ubi_wl_get_peb(ubi, dtype);
 +      pnum = ubi_wl_get_peb(ubi);
        if (pnum < 0) {
                ubi_free_vid_hdr(ubi, vid_hdr);
                leb_write_unlock(ubi, vol_id, lnum);
        if (len) {
                err = ubi_io_write_data(ubi, buf, pnum, offset, len);
                if (err) {
 -                      ubi_warn("failed to write %d bytes at offset %d of "
 -                               "LEB %d:%d, PEB %d", len, offset, vol_id,
 -                               lnum, pnum);
 +                      ubi_warn("failed to write %d bytes at offset %d of LEB %d:%d, PEB %d",
 +                               len, offset, vol_id, lnum, pnum);
                        goto write_error;
                }
        }
@@@ -684,7 -696,7 +693,7 @@@ write_error
         * eraseblock, so just put it and request a new one. We assume that if
         * this physical eraseblock went bad, the erase code will handle that.
         */
 -      err = ubi_wl_put_peb(ubi, pnum, 1);
 +      err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
        if (err || ++tries > UBI_IO_RETRIES) {
                ubi_ro_mode(ubi);
                leb_write_unlock(ubi, vol_id, lnum);
   * @lnum: logical eraseblock number
   * @buf: data to write
   * @len: how many bytes to write
 - * @dtype: data type
   * @used_ebs: how many logical eraseblocks will this volume contain
   *
   * This function writes data to logical eraseblock @lnum of static volume
   * code in case of failure.
   */
  int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
 -                       int lnum, const void *buf, int len, int dtype,
 -                       int used_ebs)
 +                       int lnum, const void *buf, int len, int used_ebs)
  {
        int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id;
        struct ubi_vid_hdr *vid_hdr;
        vid_hdr->data_crc = cpu_to_be32(crc);
  
  retry:
 -      pnum = ubi_wl_get_peb(ubi, dtype);
 +      pnum = ubi_wl_get_peb(ubi);
        if (pnum < 0) {
                ubi_free_vid_hdr(ubi, vid_hdr);
                leb_write_unlock(ubi, vol_id, lnum);
@@@ -802,7 -816,7 +811,7 @@@ write_error
                return err;
        }
  
 -      err = ubi_wl_put_peb(ubi, pnum, 1);
 +      err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
        if (err || ++tries > UBI_IO_RETRIES) {
                ubi_ro_mode(ubi);
                leb_write_unlock(ubi, vol_id, lnum);
   * @lnum: logical eraseblock number
   * @buf: data to write
   * @len: how many bytes to write
 - * @dtype: data type
   *
   * This function changes the contents of a logical eraseblock atomically. @buf
   * has to contain new logical eraseblock data, and @len - the length of the
   * LEB change may be done at a time. This is ensured by @ubi->alc_mutex.
   */
  int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
 -                            int lnum, const void *buf, int len, int dtype)
 +                            int lnum, const void *buf, int len)
  {
        int err, pnum, tries = 0, vol_id = vol->vol_id;
        struct ubi_vid_hdr *vid_hdr;
                err = ubi_eba_unmap_leb(ubi, vol, lnum);
                if (err)
                        return err;
 -              return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype);
 +              return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0);
        }
  
        vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
        vid_hdr->data_crc = cpu_to_be32(crc);
  
  retry:
 -      pnum = ubi_wl_get_peb(ubi, dtype);
 +      pnum = ubi_wl_get_peb(ubi);
        if (pnum < 0) {
                err = pnum;
                goto out_leb_unlock;
        }
  
        if (vol->eba_tbl[lnum] >= 0) {
 -              err = ubi_wl_put_peb(ubi, vol->eba_tbl[lnum], 0);
 +              err = ubi_wl_put_peb(ubi, vol_id, lnum, vol->eba_tbl[lnum], 0);
                if (err)
                        goto out_leb_unlock;
        }
@@@ -924,7 -939,7 +933,7 @@@ write_error
                goto out_leb_unlock;
        }
  
 -      err = ubi_wl_put_peb(ubi, pnum, 1);
 +      err = ubi_wl_put_peb(ubi, vol_id, lnum, pnum, 1);
        if (err || ++tries > UBI_IO_RETRIES) {
                ubi_ro_mode(ubi);
                goto out_leb_unlock;
@@@ -973,7 -988,7 +982,7 @@@ static int is_error_sane(int err
   * physical eraseblock @to. The @vid_hdr buffer may be changed by this
   * function. Returns:
   *   o %0 in case of success;
 - *   o %MOVE_CANCEL_RACE, %MOVE_TARGET_WR_ERR, %MOVE_CANCEL_BITFLIPS, etc;
 + *   o %MOVE_CANCEL_RACE, %MOVE_TARGET_WR_ERR, %MOVE_TARGET_BITFLIPS, etc;
   *   o a negative error code in case of failure.
   */
  int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
         * cancel it.
         */
        if (vol->eba_tbl[lnum] != from) {
 -              dbg_wl("LEB %d:%d is no longer mapped to PEB %d, mapped to "
 -                     "PEB %d, cancel", vol_id, lnum, from,
 -                     vol->eba_tbl[lnum]);
 +              dbg_wl("LEB %d:%d is no longer mapped to PEB %d, mapped to PEB %d, cancel",
 +                     vol_id, lnum, from, vol->eba_tbl[lnum]);
                err = MOVE_CANCEL_RACE;
                goto out_unlock_leb;
        }
  
        /*
         * OK, now the LEB is locked and we can safely start moving it. Since
 -       * this function utilizes the @ubi->peb_buf1 buffer which is shared
 +       * this function utilizes the @ubi->peb_buf buffer which is shared
         * with some other functions - we lock the buffer by taking the
         * @ubi->buf_mutex.
         */
        mutex_lock(&ubi->buf_mutex);
        dbg_wl("read %d bytes of data", aldata_size);
 -      err = ubi_io_read_data(ubi, ubi->peb_buf1, from, 0, aldata_size);
 +      err = ubi_io_read_data(ubi, ubi->peb_buf, from, 0, aldata_size);
        if (err && err != UBI_IO_BITFLIPS) {
                ubi_warn("error %d while reading data from PEB %d",
                         err, from);
         */
        if (vid_hdr->vol_type == UBI_VID_DYNAMIC)
                aldata_size = data_size =
 -                      ubi_calc_data_len(ubi, ubi->peb_buf1, data_size);
 +                      ubi_calc_data_len(ubi, ubi->peb_buf, data_size);
  
        cond_resched();
 -      crc = crc32(UBI_CRC32_INIT, ubi->peb_buf1, data_size);
 +      crc = crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size);
        cond_resched();
  
        /*
        err = ubi_io_read_vid_hdr(ubi, to, vid_hdr, 1);
        if (err) {
                if (err != UBI_IO_BITFLIPS) {
 -                      ubi_warn("error %d while reading VID header back from "
 -                                "PEB %d", err, to);
 +                      ubi_warn("error %d while reading VID header back from PEB %d",
 +                               err, to);
                        if (is_error_sane(err))
                                err = MOVE_TARGET_RD_ERR;
                } else
 -                      err = MOVE_CANCEL_BITFLIPS;
 +                      err = MOVE_TARGET_BITFLIPS;
                goto out_unlock_buf;
        }
  
        if (data_size > 0) {
 -              err = ubi_io_write_data(ubi, ubi->peb_buf1, to, 0, aldata_size);
 +              err = ubi_io_write_data(ubi, ubi->peb_buf, to, 0, aldata_size);
                if (err) {
                        if (err == -EIO)
                                err = MOVE_TARGET_WR_ERR;
                 * We've written the data and are going to read it back to make
                 * sure it was written correctly.
                 */
 -
 -              err = ubi_io_read_data(ubi, ubi->peb_buf2, to, 0, aldata_size);
 +              memset(ubi->peb_buf, 0xFF, aldata_size);
 +              err = ubi_io_read_data(ubi, ubi->peb_buf, to, 0, aldata_size);
                if (err) {
                        if (err != UBI_IO_BITFLIPS) {
 -                              ubi_warn("error %d while reading data back "
 -                                       "from PEB %d", err, to);
 +                              ubi_warn("error %d while reading data back from PEB %d",
 +                                       err, to);
                                if (is_error_sane(err))
                                        err = MOVE_TARGET_RD_ERR;
                        } else
 -                              err = MOVE_CANCEL_BITFLIPS;
 +                              err = MOVE_TARGET_BITFLIPS;
                        goto out_unlock_buf;
                }
  
                cond_resched();
  
 -              if (memcmp(ubi->peb_buf1, ubi->peb_buf2, aldata_size)) {
 -                      ubi_warn("read data back from PEB %d and it is "
 -                               "different", to);
 +              if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size)) {
 +                      ubi_warn("read data back from PEB %d and it is different",
 +                               to);
                        err = -EINVAL;
                        goto out_unlock_buf;
                }
@@@ -1164,7 -1180,7 +1173,7 @@@ out_unlock_leb
   * print_rsvd_warning - warn about not having enough reserved PEBs.
   * @ubi: UBI device description object
   *
 - * This is a helper function for 'ubi_eba_init_scan()' which is called when UBI
 + * This is a helper function for 'ubi_eba_init()' which is called when UBI
   * cannot reserve enough PEBs for bad block handling. This function makes a
   * decision whether we have to print a warning or not. The algorithm is as
   * follows:
   * reported by real users.
   */
  static void print_rsvd_warning(struct ubi_device *ubi,
 -                             struct ubi_scan_info *si)
 +                             struct ubi_attach_info *ai)
  {
        /*
         * The 1 << 18 (256KiB) number is picked randomly, just a reasonably
         * large number to distinguish between newly flashed and used images.
         */
 -      if (si->max_sqnum > (1 << 18)) {
 +      if (ai->max_sqnum > (1 << 18)) {
                int min = ubi->beb_rsvd_level / 10;
  
                if (!min)
                        return;
        }
  
 -      ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d,"
 -               " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
 +      ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d, need %d",
 +               ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
        if (ubi->corr_peb_count)
                ubi_warn("%d PEBs are corrupted and not used",
 -                      ubi->corr_peb_count);
 +                       ubi->corr_peb_count);
  }
  
  /**
 - * ubi_eba_init_scan - initialize the EBA sub-system using scanning information.
 + * ubi_eba_init - initialize the EBA sub-system using attaching information.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: attaching information
   *
   * This function returns zero in case of success and a negative error code in
   * case of failure.
   */
 -int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si)
 +int ubi_eba_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
  {
        int i, j, err, num_volumes;
 -      struct ubi_scan_volume *sv;
 +      struct ubi_ainf_volume *av;
        struct ubi_volume *vol;
 -      struct ubi_scan_leb *seb;
 +      struct ubi_ainf_peb *aeb;
        struct rb_node *rb;
  
        dbg_eba("initialize EBA sub-system");
        mutex_init(&ubi->alc_mutex);
        ubi->ltree = RB_ROOT;
  
 -      ubi->global_sqnum = si->max_sqnum + 1;
 +      ubi->global_sqnum = ai->max_sqnum + 1;
        num_volumes = ubi->vtbl_slots + UBI_INT_VOL_COUNT;
  
        for (i = 0; i < num_volumes; i++) {
                for (j = 0; j < vol->reserved_pebs; j++)
                        vol->eba_tbl[j] = UBI_LEB_UNMAPPED;
  
 -              sv = ubi_scan_find_sv(si, idx2vol_id(ubi, i));
 -              if (!sv)
 +              av = ubi_find_av(ai, idx2vol_id(ubi, i));
 +              if (!av)
                        continue;
  
 -              ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
 -                      if (seb->lnum >= vol->reserved_pebs)
 +              ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) {
 +                      if (aeb->lnum >= vol->reserved_pebs)
                                /*
                                 * This may happen in case of an unclean reboot
                                 * during re-size.
                                 */
 -                              ubi_scan_move_to_list(sv, seb, &si->erase);
 +                              ubi_move_aeb_to_list(av, aeb, &ai->erase);
                        else
 -                              vol->eba_tbl[seb->lnum] = seb->pnum;
 +                              vol->eba_tbl[aeb->lnum] = aeb->pnum;
                }
        }
  
                if (ubi->avail_pebs < ubi->beb_rsvd_level) {
                        /* No enough free physical eraseblocks */
                        ubi->beb_rsvd_pebs = ubi->avail_pebs;
 -                      print_rsvd_warning(ubi, si);
 +                      print_rsvd_warning(ubi, ai);
                } else
                        ubi->beb_rsvd_pebs = ubi->beb_rsvd_level;
  
diff --combined fs/ubifs/file.c
@@@ -53,6 -53,7 +53,7 @@@
  #include <linux/mount.h>
  #include <linux/namei.h>
  #include <linux/slab.h>
+ #include <linux/migrate.h>
  
  static int read_block(struct inode *inode, void *addr, unsigned int block,
                      struct ubifs_data_node *dn)
@@@ -97,7 -98,7 +98,7 @@@
  dump:
        ubifs_err("bad data node (block %u, inode %lu)",
                  block, inode->i_ino);
 -      dbg_dump_node(c, dn);
 +      ubifs_dump_node(c, dn);
        return -EINVAL;
  }
  
@@@ -1421,6 -1422,26 +1422,26 @@@ static int ubifs_set_page_dirty(struct 
        return ret;
  }
  
+ #ifdef CONFIG_MIGRATION
+ static int ubifs_migrate_page(struct address_space *mapping,
+               struct page *newpage, struct page *page, enum migrate_mode mode)
+ {
+       int rc;
+       rc = migrate_page_move_mapping(mapping, newpage, page, NULL, mode);
+       if (rc != 0)
+               return rc;
+       if (PagePrivate(page)) {
+               ClearPagePrivate(page);
+               SetPagePrivate(newpage);
+       }
+       migrate_page_copy(newpage, page);
+       return 0;
+ }
+ #endif
  static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
  {
        /*
@@@ -1486,8 -1507,8 +1507,8 @@@ static int ubifs_vm_page_mkwrite(struc
        err = ubifs_budget_space(c, &req);
        if (unlikely(err)) {
                if (err == -ENOSPC)
 -                      ubifs_warn("out of space for mmapped file "
 -                                 "(inode number %lu)", inode->i_ino);
 +                      ubifs_warn("out of space for mmapped file (inode number %lu)",
 +                                 inode->i_ino);
                return VM_FAULT_SIGBUS;
        }
  
@@@ -1555,16 -1576,21 +1576,19 @@@ const struct address_space_operations u
        .write_end      = ubifs_write_end,
        .invalidatepage = ubifs_invalidatepage,
        .set_page_dirty = ubifs_set_page_dirty,
+ #ifdef CONFIG_MIGRATION
+       .migratepage    = ubifs_migrate_page,
+ #endif
        .releasepage    = ubifs_releasepage,
  };
  
  const struct inode_operations ubifs_file_inode_operations = {
        .setattr     = ubifs_setattr,
        .getattr     = ubifs_getattr,
 -#ifdef CONFIG_UBIFS_FS_XATTR
        .setxattr    = ubifs_setxattr,
        .getxattr    = ubifs_getxattr,
        .listxattr   = ubifs_listxattr,
        .removexattr = ubifs_removexattr,
 -#endif
  };
  
  const struct inode_operations ubifs_symlink_inode_operations = {
diff --combined include/linux/mm.h
@@@ -1527,6 -1527,7 +1527,7 @@@ struct page *follow_page(struct vm_area
  #define FOLL_MLOCK    0x40    /* mark page as mlocked */
  #define FOLL_SPLIT    0x80    /* don't return transhuge pages, split them */
  #define FOLL_HWPOISON 0x100   /* check page is hwpoisoned */
+ #define FOLL_COW      0x4000  /* internal GUP flag */
  
  typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
                        void *data);
@@@ -1633,22 -1634,5 +1634,22 @@@ extern void copy_user_huge_page(struct 
                                unsigned int pages_per_huge_page);
  #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
  
 +#ifdef CONFIG_DEBUG_PAGEALLOC
 +extern unsigned int _debug_guardpage_minorder;
 +
 +static inline unsigned int debug_guardpage_minorder(void)
 +{
 +      return _debug_guardpage_minorder;
 +}
 +
 +static inline bool page_is_guard(struct page *page)
 +{
 +      return test_bit(PAGE_DEBUG_FLAG_GUARD, &page->debug_flags);
 +}
 +#else
 +static inline unsigned int debug_guardpage_minorder(void) { return 0; }
 +static inline bool page_is_guard(struct page *page) { return false; }
 +#endif /* CONFIG_DEBUG_PAGEALLOC */
 +
  #endif /* __KERNEL__ */
  #endif /* _LINUX_MM_H */
diff --combined kernel/exit.c
@@@ -499,7 -499,6 +499,7 @@@ struct files_struct *get_files_struct(s
  
        return files;
  }
 +EXPORT_SYMBOL_GPL(get_files_struct);
  
  void put_files_struct(struct files_struct *files)
  {
                rcu_read_unlock();
        }
  }
 +EXPORT_SYMBOL_GPL(put_files_struct);
  
  void reset_files_struct(struct files_struct *files)
  {
@@@ -1140,17 -1138,28 +1140,28 @@@ static int eligible_pid(struct wait_opt
                task_pid_type(p, wo->wo_type) == wo->wo_pid;
  }
  
- static int eligible_child(struct wait_opts *wo, struct task_struct *p)
+ static int
+ eligible_child(struct wait_opts *wo, bool ptrace, struct task_struct *p)
  {
        if (!eligible_pid(wo, p))
                return 0;
-       /* Wait for all children (clone and not) if __WALL is set;
-        * otherwise, wait for clone children *only* if __WCLONE is
-        * set; otherwise, wait for non-clone children *only*.  (Note:
-        * A "clone" child here is one that reports to its parent
-        * using a signal other than SIGCHLD.) */
-       if (((p->exit_signal != SIGCHLD) ^ !!(wo->wo_flags & __WCLONE))
-           && !(wo->wo_flags & __WALL))
+       /*
+        * Wait for all children (clone and not) if __WALL is set or
+        * if it is traced by us.
+        */
+       if (ptrace || (wo->wo_flags & __WALL))
+               return 1;
+       /*
+        * Otherwise, wait for clone children *only* if __WCLONE is set;
+        * otherwise, wait for non-clone children *only*.
+        *
+        * Note: a "clone" child here is one that reports to its parent
+        * using a signal other than SIGCHLD, or a non-leader thread which
+        * we can only see if it is traced by us.
+        */
+       if ((p->exit_signal != SIGCHLD) ^ !!(wo->wo_flags & __WCLONE))
                return 0;
  
        return 1;
@@@ -1527,7 -1536,7 +1538,7 @@@ static int wait_task_continued(struct w
  static int wait_consider_task(struct wait_opts *wo, int ptrace,
                                struct task_struct *p)
  {
-       int ret = eligible_child(wo, p);
+       int ret = eligible_child(wo, ptrace, p);
        if (!ret)
                return ret;
  
diff --combined kernel/sched.c
@@@ -3507,10 -3507,13 +3507,13 @@@ static long calc_load_fold_active(struc
  static unsigned long
  calc_load(unsigned long load, unsigned long exp, unsigned long active)
  {
-       load *= exp;
-       load += active * (FIXED_1 - exp);
-       load += 1UL << (FSHIFT - 1);
-       return load >> FSHIFT;
+       unsigned long newload;
+       newload = load * exp + active * (FIXED_1 - exp);
+       if (active >= load)
+               newload += FIXED_1-1;
+       return newload / FIXED_1;
  }
  
  #ifdef CONFIG_NO_HZ
@@@ -5317,7 -5320,6 +5320,7 @@@ int can_nice(const struct task_struct *
        return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
                capable(CAP_SYS_NICE));
  }
 +EXPORT_SYMBOL_GPL(can_nice);
  
  #ifdef __ARCH_WANT_SYS_NICE
  
@@@ -6258,14 -6260,16 +6261,16 @@@ void show_state_filter(unsigned long st
                /*
                 * reset the NMI-timeout, listing all files on a slow
                 * console might take a lot of time:
+                * Also, reset softlockup watchdogs on all CPUs, because
+                * another CPU might be blocked waiting for us to process
+                * an IPI.
                 */
                touch_nmi_watchdog();
+               touch_all_softlockup_watchdogs();
                if (!state_filter || (p->state & state_filter))
                        sched_show_task(p);
        } while_each_thread(g, p);
  
-       touch_all_softlockup_watchdogs();
  #ifdef CONFIG_SCHED_DEBUG
        sysrq_sched_debug_show();
  #endif
@@@ -8514,7 -8518,6 +8519,7 @@@ void __init sched_init(void
  #ifdef CONFIG_CGROUP_SCHED
        list_add(&root_task_group.list, &task_groups);
        INIT_LIST_HEAD(&root_task_group.children);
 +      INIT_LIST_HEAD(&root_task_group.siblings);
        autogroup_init(&init_task);
  #endif /* CONFIG_CGROUP_SCHED */
  
diff --combined mm/memory.c
@@@ -1403,7 -1403,6 +1403,7 @@@ unsigned long zap_page_range(struct vm_
        tlb_finish_mmu(&tlb, address, end);
        return end;
  }
 +EXPORT_SYMBOL_GPL(zap_page_range);
  
  /**
   * zap_vma_ptes - remove ptes mapping the vma
@@@ -1428,6 -1427,24 +1428,24 @@@ int zap_vma_ptes(struct vm_area_struct 
  }
  EXPORT_SYMBOL_GPL(zap_vma_ptes);
  
+ static inline bool can_follow_write_pte(pte_t pte, struct page *page,
+                                       unsigned int flags)
+ {
+       if (pte_write(pte))
+               return true;
+       /*
+        * Make sure that we are really following CoWed page. We do not really
+        * have to care about exclusiveness of the page because we only want
+        * to ensure that once COWed page hasn't disappeared in the meantime
+        * or it hasn't been merged to a KSM page.
+        */
+       if ((flags & FOLL_FORCE) && (flags & FOLL_COW))
+               return page && PageAnon(page) && !PageKsm(page);
+       return false;
+ }
  /**
   * follow_page - look up a page descriptor from a user-virtual address
   * @vma: vm_area_struct mapping @address
@@@ -1510,10 -1527,13 +1528,13 @@@ split_fallthrough
        pte = *ptep;
        if (!pte_present(pte))
                goto no_page;
-       if ((flags & FOLL_WRITE) && !pte_write(pte))
-               goto unlock;
  
        page = vm_normal_page(vma, address, pte);
+       if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, page, flags)) {
+               pte_unmap_unlock(ptep, ptl);
+               return NULL;
+       }
        if (unlikely(!page)) {
                if ((flags & FOLL_DUMP) ||
                    !is_zero_pfn(pte_pfn(pte)))
                        unlock_page(page);
                }
        }
- unlock:
        pte_unmap_unlock(ptep, ptl);
  out:
        return page;
@@@ -1790,17 -1810,13 +1811,13 @@@ int __get_user_pages(struct task_struc
                                 * The VM_FAULT_WRITE bit tells us that
                                 * do_wp_page has broken COW when necessary,
                                 * even if maybe_mkwrite decided not to set
-                                * pte_write. We can thus safely do subsequent
-                                * page lookups as if they were reads. But only
-                                * do so when looping for pte_write is futile:
-                                * in some cases userspace may also be wanting
-                                * to write to the gotten user page, which a
-                                * read fault here might prevent (a readonly
-                                * page might get reCOWed by userspace write).
+                                * pte_write. We cannot simply drop FOLL_WRITE
+                                * here because the COWed page might be gone by
+                                * the time we do the subsequent page lookups.
                                 */
                                if ((ret & VM_FAULT_WRITE) &&
                                    !(vma->vm_flags & VM_WRITE))
-                                       foll_flags &= ~FOLL_WRITE;
+                                       foll_flags |= FOLL_COW;
  
                                cond_resched();
                        }
@@@ -3559,9 -3575,8 +3576,9 @@@ retry
  
                barrier();
                if (pmd_trans_huge(orig_pmd)) {
 -                      if (flags & FAULT_FLAG_WRITE &&
 -                          !pmd_write(orig_pmd) &&
 +                      unsigned int dirty = flags & FAULT_FLAG_WRITE;
 +
 +                      if (dirty && !pmd_write(orig_pmd) &&
                            !pmd_trans_splitting(orig_pmd)) {
                                ret = do_huge_pmd_wp_page(mm, vma, address, pmd,
                                                          orig_pmd);
                                if (unlikely(ret & VM_FAULT_OOM))
                                        goto retry;
                                return ret;
 +                      } else {
 +                              huge_pmd_set_accessed(mm, vma, address, pmd,
 +                                                    orig_pmd, dirty);
                        }
                        return 0;
                }
@@@ -3890,11 -3902,7 +3907,11 @@@ static int __access_remote_vm(struct ta
                        vma = find_vma(mm, addr);
                        if (!vma || vma->vm_start > addr)
                                break;
 -                      if (vma->vm_ops && vma->vm_ops->access)
 +                      if ((vma->vm_flags & VM_PFNMAP) &&
 +                          !(vma->vm_flags & VM_IO))
 +                              ret = generic_access_phys(vma, addr, buf,
 +                                                        len, write);
 +                      if (ret <= 0 && vma->vm_ops && vma->vm_ops->access)
                                ret = vma->vm_ops->access(vma, addr, buf,
                                                          len, write);
                        if (ret <= 0)