Merge branch 'stable-3.2' into pandora-3.2
authorGrazvydas Ignotas <notasas@gmail.com>
Sat, 22 Sep 2012 21:32:18 +0000 (00:32 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 22 Sep 2012 21:32:18 +0000 (00:32 +0300)
Conflicts:
drivers/mtd/ubi/vtbl.c

1  2 
arch/arm/Kconfig
arch/arm/include/asm/pgtable.h
drivers/mtd/ubi/vtbl.c
fs/open.c
kernel/sched.c
mm/memory.c

diff --combined arch/arm/Kconfig
@@@ -1775,7 -1775,7 +1775,7 @@@ config LEDS_CP
          will overrule the CPU usage LED.
  
  config ALIGNMENT_TRAP
 -      bool
 +      bool "Enable alignment trap"
        depends on CPU_CP15_MMU
        default y if !ARCH_EBSA110
        select HAVE_PROC_CPU if PROC_FS
@@@ -1837,11 -1837,6 +1837,11 @@@ config DEPRECATED_PARAM_STRUC
          This was deprecated in 2001 and announced to live on for 5 years.
          Some old boot loaders still use this way.
  
 +config CPU_V7_SYSFS
 +      bool
 +      depends on CPU_V7 && SYSFS
 +      default y
 +
  endmenu
  
  menu "Boot options"
@@@ -2070,6 -2065,7 +2070,7 @@@ source "drivers/cpufreq/Kconfig
  config CPU_FREQ_IMX
        tristate "CPUfreq driver for i.MX CPUs"
        depends on ARCH_MXC && CPU_FREQ
+       select CPU_FREQ_TABLE
        help
          This enables the CPUfreq driver for i.MX CPUs.
  
@@@ -104,9 -104,6 +104,9 @@@ extern pgprot_t            pgprot_kernel
  #define pgprot_stronglyordered(prot) \
        __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED)
  
 +#define pgprot_writethrough(prot) \
 +      __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_WRITETHROUGH)
 +
  #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  #define pgprot_dmacoherent(prot) \
        __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE | L_PTE_XN)
@@@ -235,6 -232,18 +235,18 @@@ static inline pte_t *pmd_page_vaddr(pmd
  #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext)
  #define pte_clear(mm,addr,ptep)       set_pte_ext(ptep, __pte(0), 0)
  
+ #define pte_none(pte)         (!pte_val(pte))
+ #define pte_present(pte)      (pte_val(pte) & L_PTE_PRESENT)
+ #define pte_write(pte)                (!(pte_val(pte) & L_PTE_RDONLY))
+ #define pte_dirty(pte)                (pte_val(pte) & L_PTE_DIRTY)
+ #define pte_young(pte)                (pte_val(pte) & L_PTE_YOUNG)
+ #define pte_exec(pte)         (!(pte_val(pte) & L_PTE_XN))
+ #define pte_special(pte)      (0)
+ #define pte_present_user(pte) \
+       ((pte_val(pte) & (L_PTE_PRESENT | L_PTE_USER)) == \
+        (L_PTE_PRESENT | L_PTE_USER))
  #if __LINUX_ARM_ARCH__ < 6
  static inline void __sync_icache_dcache(pte_t pteval)
  {
@@@ -246,25 -255,15 +258,15 @@@ extern void __sync_icache_dcache(pte_t 
  static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
                              pte_t *ptep, pte_t pteval)
  {
-       if (addr >= TASK_SIZE)
-               set_pte_ext(ptep, pteval, 0);
-       else {
+       unsigned long ext = 0;
+       if (addr < TASK_SIZE && pte_present_user(pteval)) {
                __sync_icache_dcache(pteval);
-               set_pte_ext(ptep, pteval, PTE_EXT_NG);
+               ext |= PTE_EXT_NG;
        }
- }
  
- #define pte_none(pte)         (!pte_val(pte))
- #define pte_present(pte)      (pte_val(pte) & L_PTE_PRESENT)
- #define pte_write(pte)                (!(pte_val(pte) & L_PTE_RDONLY))
- #define pte_dirty(pte)                (pte_val(pte) & L_PTE_DIRTY)
- #define pte_young(pte)                (pte_val(pte) & L_PTE_YOUNG)
- #define pte_exec(pte)         (!(pte_val(pte) & L_PTE_XN))
- #define pte_special(pte)      (0)
- #define pte_present_user(pte) \
-       ((pte_val(pte) & (L_PTE_PRESENT | L_PTE_USER)) == \
-        (L_PTE_PRESENT | L_PTE_USER))
+       set_pte_ext(ptep, pteval, ext);
+ }
  
  #define PTE_BIT_FUNC(fn,op) \
  static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; }
@@@ -291,13 -290,13 +293,13 @@@ static inline pte_t pte_modify(pte_t pt
   *
   *   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
   *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
-  *   <--------------- offset --------------------> <- type --> 0 0 0
+  *   <--------------- offset ----------------------> < type -> 0 0 0
   *
-  * This gives us up to 63 swap files and 32GB per swap file.  Note that
+  * This gives us up to 31 swap files and 64GB per swap file.  Note that
   * the offset field is always non-zero.
   */
  #define __SWP_TYPE_SHIFT      3
- #define __SWP_TYPE_BITS               6
+ #define __SWP_TYPE_BITS               5
  #define __SWP_TYPE_MASK               ((1 << __SWP_TYPE_BITS) - 1)
  #define __SWP_OFFSET_SHIFT    (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
  
diff --combined drivers/mtd/ubi/vtbl.c
   * LEB 1. This scheme guarantees recoverability from unclean reboots.
   *
   * In this UBI implementation the on-flash volume table does not contain any
 - * information about how many data static volumes contain. This information may
 - * be found from the scanning data.
 + * information about how much data static volumes contain.
   *
   * But it would still be beneficial to store this information in the volume
   * table. For example, suppose we have a static volume X, and all its physical
   * eraseblocks became bad for some reasons. Suppose we are attaching the
 - * corresponding MTD device, the scanning has found no logical eraseblocks
 + * corresponding MTD device, for some reason we find no logical eraseblocks
   * corresponding to the volume X. According to the volume table volume X does
   * exist. So we don't know whether it is just empty or all its physical
 - * eraseblocks went bad. So we cannot alarm the user about this corruption.
 + * eraseblocks went bad. So we cannot alarm the user properly.
   *
   * The volume table also stores so-called "update marker", which is used for
   * volume updates. Before updating the volume, the update marker is set, and
  #include <asm/div64.h>
  #include "ubi.h"
  
 -#ifdef CONFIG_MTD_UBI_DEBUG
 -static void paranoid_vtbl_check(const struct ubi_device *ubi);
 -#else
 -#define paranoid_vtbl_check(ubi)
 -#endif
 +static void self_vtbl_check(const struct ubi_device *ubi);
  
  /* Empty volume table record */
  static struct ubi_vtbl_record empty_vtbl_record;
@@@ -101,12 -106,12 +101,12 @@@ int ubi_change_vtbl_record(struct ubi_d
                        return err;
  
                err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
 -                                      ubi->vtbl_size, UBI_LONGTERM);
 +                                      ubi->vtbl_size);
                if (err)
                        return err;
        }
  
 -      paranoid_vtbl_check(ubi);
 +      self_vtbl_check(ubi);
        return 0;
  }
  
@@@ -153,7 -158,7 +153,7 @@@ int ubi_vtbl_rename_volumes(struct ubi_
                        return err;
  
                err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
 -                                      ubi->vtbl_size, UBI_LONGTERM);
 +                                      ubi->vtbl_size);
                if (err)
                        return err;
        }
@@@ -192,7 -197,7 +192,7 @@@ static int vtbl_check(const struct ubi_
                if (be32_to_cpu(vtbl[i].crc) != crc) {
                        ubi_err("bad CRC at record %u: %#08x, not %#08x",
                                 i, crc, be32_to_cpu(vtbl[i].crc));
 -                      ubi_dbg_dump_vtbl_record(&vtbl[i], i);
 +                      ubi_dump_vtbl_record(&vtbl[i], i);
                        return 1;
                }
  
  
                n = ubi->leb_size % alignment;
                if (data_pad != n) {
 -                      dbg_err("bad data_pad, has to be %d", n);
 +                      ubi_err("bad data_pad, has to be %d", n);
                        err = 6;
                        goto bad;
                }
                }
  
                if (reserved_pebs > ubi->good_peb_count) {
 -                      dbg_err("too large reserved_pebs %d, good PEBs %d",
 +                      ubi_err("too large reserved_pebs %d, good PEBs %d",
                                reserved_pebs, ubi->good_peb_count);
                        err = 9;
                        goto bad;
                            !strncmp(vtbl[i].name, vtbl[n].name, len1)) {
                                ubi_err("volumes %d and %d have the same name"
                                        " \"%s\"", i, n, vtbl[i].name);
 -                              ubi_dbg_dump_vtbl_record(&vtbl[i], i);
 -                              ubi_dbg_dump_vtbl_record(&vtbl[n], n);
 +                              ubi_dump_vtbl_record(&vtbl[i], i);
 +                              ubi_dump_vtbl_record(&vtbl[n], n);
                                return -EINVAL;
                        }
                }
  
  bad:
        ubi_err("volume table check failed: record %d, error %d", i, err);
 -      ubi_dbg_dump_vtbl_record(&vtbl[i], i);
 +      ubi_dump_vtbl_record(&vtbl[i], i);
        return -EINVAL;
  }
  
  /**
   * create_vtbl - create a copy of volume table.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: attaching information
   * @copy: number of the volume table copy
   * @vtbl: contents of the volume table
   *
   * This function returns zero in case of success and a negative error code in
   * case of failure.
   */
 -static int create_vtbl(struct ubi_device *ubi, struct ubi_scan_info *si,
 +static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai,
                       int copy, void *vtbl)
  {
        int err, tries = 0;
        struct ubi_vid_hdr *vid_hdr;
 -      struct ubi_scan_leb *new_seb;
 +      struct ubi_ainf_peb *new_aeb;
  
        ubi_msg("create volume table (copy #%d)", copy + 1);
  
                return -ENOMEM;
  
  retry:
 -      new_seb = ubi_scan_get_free_peb(ubi, si);
 -      if (IS_ERR(new_seb)) {
 -              err = PTR_ERR(new_seb);
 +      new_aeb = ubi_early_get_peb(ubi, ai);
 +      if (IS_ERR(new_aeb)) {
 +              err = PTR_ERR(new_aeb);
                goto out_free;
        }
  
 -      vid_hdr->vol_type = UBI_VID_DYNAMIC;
 +      vid_hdr->vol_type = UBI_LAYOUT_VOLUME_TYPE;
        vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID);
        vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
        vid_hdr->data_size = vid_hdr->used_ebs =
                             vid_hdr->data_pad = cpu_to_be32(0);
        vid_hdr->lnum = cpu_to_be32(copy);
 -      vid_hdr->sqnum = cpu_to_be64(++si->max_sqnum);
 +      vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum);
  
        /* The EC header is already there, write the VID header */
 -      err = ubi_io_write_vid_hdr(ubi, new_seb->pnum, vid_hdr);
 +      err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr);
        if (err)
                goto write_error;
  
        /* Write the layout volume contents */
 -      err = ubi_io_write_data(ubi, vtbl, new_seb->pnum, 0, ubi->vtbl_size);
 +      err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
        if (err)
                goto write_error;
  
        /*
 -       * And add it to the scanning information. Don't delete the old version
 -       * of this LEB as it will be deleted and freed in 'ubi_scan_add_used()'.
 +       * And add it to the attaching information. Don't delete the old version
 +       * of this LEB as it will be deleted and freed in 'ubi_add_to_av()'.
         */
 -      err = ubi_scan_add_used(ubi, si, new_seb->pnum, new_seb->ec,
 -                              vid_hdr, 0);
 -      kmem_cache_free(si->scan_leb_slab, new_seb);
 +      err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
-       kfree(new_aeb);
++      kmem_cache_free(ai->aeb_slab_cache, new_aeb);
        ubi_free_vid_hdr(ubi, vid_hdr);
        return err;
  
@@@ -350,10 -356,10 +350,10 @@@ write_error
                 * Probably this physical eraseblock went bad, try to pick
                 * another one.
                 */
 -              list_add(&new_seb->u.list, &si->erase);
 +              list_add(&new_aeb->u.list, &ai->erase);
                goto retry;
        }
-       kfree(new_aeb);
 -      kmem_cache_free(si->scan_leb_slab, new_seb);
++      kmem_cache_free(ai->aeb_slab_cache, new_aeb);
  out_free:
        ubi_free_vid_hdr(ubi, vid_hdr);
        return err;
  /**
   * process_lvol - process the layout volume.
   * @ubi: UBI device description object
 - * @si: scanning information
 - * @sv: layout volume scanning information
 + * @ai: attaching information
 + * @av: layout volume attaching information
   *
   * This function is responsible for reading the layout volume, ensuring it is
   * not corrupted, and recovering from corruptions if needed. Returns volume
   * table in case of success and a negative error code in case of failure.
   */
  static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
 -                                          struct ubi_scan_info *si,
 -                                          struct ubi_scan_volume *sv)
 +                                          struct ubi_attach_info *ai,
 +                                          struct ubi_ainf_volume *av)
  {
        int err;
        struct rb_node *rb;
 -      struct ubi_scan_leb *seb;
 +      struct ubi_ainf_peb *aeb;
        struct ubi_vtbl_record *leb[UBI_LAYOUT_VOLUME_EBS] = { NULL, NULL };
        int leb_corrupted[UBI_LAYOUT_VOLUME_EBS] = {1, 1};
  
        dbg_gen("check layout volume");
  
        /* Read both LEB 0 and LEB 1 into memory */
 -      ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
 -              leb[seb->lnum] = vzalloc(ubi->vtbl_size);
 -              if (!leb[seb->lnum]) {
 +      ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) {
 +              leb[aeb->lnum] = vzalloc(ubi->vtbl_size);
 +              if (!leb[aeb->lnum]) {
                        err = -ENOMEM;
                        goto out_free;
                }
  
 -              err = ubi_io_read_data(ubi, leb[seb->lnum], seb->pnum, 0,
 +              err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0,
                                       ubi->vtbl_size);
                if (err == UBI_IO_BITFLIPS || mtd_is_eccerr(err))
                        /*
                         * uncorrectable ECC error, but we have our own CRC and
                         * the data will be checked later. If the data is OK,
                         * the PEB will be scrubbed (because we set
 -                       * seb->scrub). If the data is not OK, the contents of
 +                       * aeb->scrub). If the data is not OK, the contents of
                         * the PEB will be recovered from the second copy, and
 -                       * seb->scrub will be cleared in
 -                       * 'ubi_scan_add_used()'.
 +                       * aeb->scrub will be cleared in
 +                       * 'ubi_add_to_av()'.
                         */
 -                      seb->scrub = 1;
 +                      aeb->scrub = 1;
                else if (err)
                        goto out_free;
        }
                                                  ubi->vtbl_size);
                if (leb_corrupted[1]) {
                        ubi_warn("volume table copy #2 is corrupted");
 -                      err = create_vtbl(ubi, si, 1, leb[0]);
 +                      err = create_vtbl(ubi, ai, 1, leb[0]);
                        if (err)
                                goto out_free;
                        ubi_msg("volume table was restored");
                }
  
                ubi_warn("volume table copy #1 is corrupted");
 -              err = create_vtbl(ubi, si, 0, leb[1]);
 +              err = create_vtbl(ubi, ai, 0, leb[1]);
                if (err)
                        goto out_free;
                ubi_msg("volume table was restored");
@@@ -488,13 -494,13 +488,13 @@@ out_free
  /**
   * create_empty_lvol - create empty layout volume.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: attaching information
   *
   * This function returns volume table contents in case of success and a
   * negative error code in case of failure.
   */
  static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
 -                                               struct ubi_scan_info *si)
 +                                               struct ubi_attach_info *ai)
  {
        int i;
        struct ubi_vtbl_record *vtbl;
        for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
                int err;
  
 -              err = create_vtbl(ubi, si, i, vtbl);
 +              err = create_vtbl(ubi, ai, i, vtbl);
                if (err) {
                        vfree(vtbl);
                        return ERR_PTR(err);
  /**
   * init_volumes - initialize volume information for existing volumes.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: scanning information
   * @vtbl: volume table
   *
   * This function allocates volume description objects for existing volumes.
   * Returns zero in case of success and a negative error code in case of
   * failure.
   */
 -static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
 +static int init_volumes(struct ubi_device *ubi,
 +                      const struct ubi_attach_info *ai,
                        const struct ubi_vtbl_record *vtbl)
  {
        int i, reserved_pebs = 0;
 -      struct ubi_scan_volume *sv;
 +      struct ubi_ainf_volume *av;
        struct ubi_volume *vol;
  
        for (i = 0; i < ubi->vtbl_slots; i++) {
                }
  
                /* Static volumes only */
 -              sv = ubi_scan_find_sv(si, i);
 -              if (!sv) {
 +              av = ubi_find_av(ai, i);
 +              if (!av) {
                        /*
                         * No eraseblocks belonging to this volume found. We
                         * don't actually know whether this static volume is
                        continue;
                }
  
 -              if (sv->leb_count != sv->used_ebs) {
 +              if (av->leb_count != av->used_ebs) {
                        /*
                         * We found a static volume which misses several
                         * eraseblocks. Treat it as corrupted.
                         */
                        ubi_warn("static volume %d misses %d LEBs - corrupted",
 -                               sv->vol_id, sv->used_ebs - sv->leb_count);
 +                               av->vol_id, av->used_ebs - av->leb_count);
                        vol->corrupted = 1;
                        continue;
                }
  
 -              vol->used_ebs = sv->used_ebs;
 +              vol->used_ebs = av->used_ebs;
                vol->used_bytes =
                        (long long)(vol->used_ebs - 1) * vol->usable_leb_size;
 -              vol->used_bytes += sv->last_data_size;
 -              vol->last_eb_bytes = sv->last_data_size;
 +              vol->used_bytes += av->last_data_size;
 +              vol->last_eb_bytes = av->last_data_size;
        }
  
        /* And add the layout volume */
                return -ENOMEM;
  
        vol->reserved_pebs = UBI_LAYOUT_VOLUME_EBS;
 -      vol->alignment = 1;
 +      vol->alignment = UBI_LAYOUT_VOLUME_ALIGN;
        vol->vol_type = UBI_DYNAMIC_VOLUME;
        vol->name_len = sizeof(UBI_LAYOUT_VOLUME_NAME) - 1;
        memcpy(vol->name, UBI_LAYOUT_VOLUME_NAME, vol->name_len + 1);
  }
  
  /**
 - * check_sv - check volume scanning information.
 + * check_av - check volume attaching information.
   * @vol: UBI volume description object
 - * @sv: volume scanning information
 + * @av: volume attaching information
   *
 - * This function returns zero if the volume scanning information is consistent
 + * This function returns zero if the volume attaching information is consistent
   * to the data read from the volume tabla, and %-EINVAL if not.
   */
 -static int check_sv(const struct ubi_volume *vol,
 -                  const struct ubi_scan_volume *sv)
 +static int check_av(const struct ubi_volume *vol,
 +                  const struct ubi_ainf_volume *av)
  {
        int err;
  
 -      if (sv->highest_lnum >= vol->reserved_pebs) {
 +      if (av->highest_lnum >= vol->reserved_pebs) {
                err = 1;
                goto bad;
        }
 -      if (sv->leb_count > vol->reserved_pebs) {
 +      if (av->leb_count > vol->reserved_pebs) {
                err = 2;
                goto bad;
        }
 -      if (sv->vol_type != vol->vol_type) {
 +      if (av->vol_type != vol->vol_type) {
                err = 3;
                goto bad;
        }
 -      if (sv->used_ebs > vol->reserved_pebs) {
 +      if (av->used_ebs > vol->reserved_pebs) {
                err = 4;
                goto bad;
        }
 -      if (sv->data_pad != vol->data_pad) {
 +      if (av->data_pad != vol->data_pad) {
                err = 5;
                goto bad;
        }
        return 0;
  
  bad:
 -      ubi_err("bad scanning information, error %d", err);
 -      ubi_dbg_dump_sv(sv);
 -      ubi_dbg_dump_vol_info(vol);
 +      ubi_err("bad attaching information, error %d", err);
 +      ubi_dump_av(av);
 +      ubi_dump_vol_info(vol);
        return -EINVAL;
  }
  
  /**
 - * check_scanning_info - check that scanning information.
 + * check_attaching_info - check that attaching information.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: attaching information
   *
   * Even though we protect on-flash data by CRC checksums, we still don't trust
 - * the media. This function ensures that scanning information is consistent to
 - * the information read from the volume table. Returns zero if the scanning
 + * the media. This function ensures that attaching information is consistent to
 + * the information read from the volume table. Returns zero if the attaching
   * information is OK and %-EINVAL if it is not.
   */
 -static int check_scanning_info(const struct ubi_device *ubi,
 -                             struct ubi_scan_info *si)
 +static int check_attaching_info(const struct ubi_device *ubi,
 +                             struct ubi_attach_info *ai)
  {
        int err, i;
 -      struct ubi_scan_volume *sv;
 +      struct ubi_ainf_volume *av;
        struct ubi_volume *vol;
  
 -      if (si->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
 -              ubi_err("scanning found %d volumes, maximum is %d + %d",
 -                      si->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
 +      if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
 +              ubi_err("found %d volumes while attaching, maximum is %d + %d",
 +                      ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
                return -EINVAL;
        }
  
 -      if (si->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
 -          si->highest_vol_id < UBI_INTERNAL_VOL_START) {
 -              ubi_err("too large volume ID %d found by scanning",
 -                      si->highest_vol_id);
 +      if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
 +          ai->highest_vol_id < UBI_INTERNAL_VOL_START) {
 +              ubi_err("too large volume ID %d found", ai->highest_vol_id);
                return -EINVAL;
        }
  
        for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
                cond_resched();
  
 -              sv = ubi_scan_find_sv(si, i);
 +              av = ubi_find_av(ai, i);
                vol = ubi->volumes[i];
                if (!vol) {
 -                      if (sv)
 -                              ubi_scan_rm_volume(si, sv);
 +                      if (av)
 +                              ubi_remove_av(ai, av);
                        continue;
                }
  
                if (vol->reserved_pebs == 0) {
                        ubi_assert(i < ubi->vtbl_slots);
  
 -                      if (!sv)
 +                      if (!av)
                                continue;
  
                        /*
 -                       * During scanning we found a volume which does not
 +                       * During attaching we found a volume which does not
                         * exist according to the information in the volume
                         * table. This must have happened due to an unclean
                         * reboot while the volume was being removed. Discard
                         * these eraseblocks.
                         */
 -                      ubi_msg("finish volume %d removal", sv->vol_id);
 -                      ubi_scan_rm_volume(si, sv);
 -              } else if (sv) {
 -                      err = check_sv(vol, sv);
 +                      ubi_msg("finish volume %d removal", av->vol_id);
 +                      ubi_remove_av(ai, av);
 +              } else if (av) {
 +                      err = check_av(vol, av);
                        if (err)
                                return err;
                }
  /**
   * ubi_read_volume_table - read the volume table.
   * @ubi: UBI device description object
 - * @si: scanning information
 + * @ai: attaching information
   *
   * This function reads volume table, checks it, recover from errors if needed,
   * or creates it if needed. Returns zero in case of success and a negative
   * error code in case of failure.
   */
 -int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si)
 +int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
  {
        int i, err;
 -      struct ubi_scan_volume *sv;
 +      struct ubi_ainf_volume *av;
  
        empty_vtbl_record.crc = cpu_to_be32(0xf116c36b);
  
        ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE;
        ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size);
  
 -      sv = ubi_scan_find_sv(si, UBI_LAYOUT_VOLUME_ID);
 -      if (!sv) {
 +      av = ubi_find_av(ai, UBI_LAYOUT_VOLUME_ID);
 +      if (!av) {
                /*
                 * No logical eraseblocks belonging to the layout volume were
                 * found. This could mean that the flash is just empty. In
                 * But if flash is not empty this must be a corruption or the
                 * MTD device just contains garbage.
                 */
 -              if (si->is_empty) {
 -                      ubi->vtbl = create_empty_lvol(ubi, si);
 +              if (ai->is_empty) {
 +                      ubi->vtbl = create_empty_lvol(ubi, ai);
                        if (IS_ERR(ubi->vtbl))
                                return PTR_ERR(ubi->vtbl);
                } else {
                        return -EINVAL;
                }
        } else {
 -              if (sv->leb_count > UBI_LAYOUT_VOLUME_EBS) {
 +              if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) {
                        /* This must not happen with proper UBI images */
 -                      dbg_err("too many LEBs (%d) in layout volume",
 -                              sv->leb_count);
 +                      ubi_err("too many LEBs (%d) in layout volume",
 +                              av->leb_count);
                        return -EINVAL;
                }
  
 -              ubi->vtbl = process_lvol(ubi, si, sv);
 +              ubi->vtbl = process_lvol(ubi, ai, av);
                if (IS_ERR(ubi->vtbl))
                        return PTR_ERR(ubi->vtbl);
        }
         * The layout volume is OK, initialize the corresponding in-RAM data
         * structures.
         */
 -      err = init_volumes(ubi, si, ubi->vtbl);
 +      err = init_volumes(ubi, ai, ubi->vtbl);
        if (err)
                goto out_free;
  
        /*
 -       * Make sure that the scanning information is consistent to the
 +       * Make sure that the attaching information is consistent to the
         * information stored in the volume table.
         */
 -      err = check_scanning_info(ubi, si);
 +      err = check_attaching_info(ubi, ai);
        if (err)
                goto out_free;
  
@@@ -852,17 -858,21 +852,17 @@@ out_free
        return err;
  }
  
 -#ifdef CONFIG_MTD_UBI_DEBUG
 -
  /**
 - * paranoid_vtbl_check - check volume table.
 + * self_vtbl_check - check volume table.
   * @ubi: UBI device description object
   */
 -static void paranoid_vtbl_check(const struct ubi_device *ubi)
 +static void self_vtbl_check(const struct ubi_device *ubi)
  {
        if (!ubi->dbg->chk_gen)
                return;
  
        if (vtbl_check(ubi, ubi->vtbl)) {
 -              ubi_err("paranoid check failed");
 +              ubi_err("self-check failed");
                BUG();
        }
  }
 -
 -#endif /* CONFIG_MTD_UBI_DEBUG */
diff --combined fs/open.c
+++ b/fs/open.c
@@@ -60,7 -60,6 +60,7 @@@ int do_truncate(struct dentry *dentry, 
        mutex_unlock(&dentry->d_inode->i_mutex);
        return ret;
  }
 +EXPORT_SYMBOL(do_truncate);
  
  static long do_sys_truncate(const char __user *pathname, loff_t length)
  {
@@@ -837,7 -836,7 +837,7 @@@ EXPORT_SYMBOL(dentry_open)
  static void __put_unused_fd(struct files_struct *files, unsigned int fd)
  {
        struct fdtable *fdt = files_fdtable(files);
 -      __FD_CLR(fd, fdt->open_fds);
 +      __clear_open_fd(fd, fdt);
        if (fd < files->next_fd)
                files->next_fd = fd;
  }
@@@ -883,9 -882,10 +883,10 @@@ static inline int build_open_flags(int 
        int lookup_flags = 0;
        int acc_mode;
  
-       if (!(flags & O_CREAT))
-               mode = 0;
-       op->mode = mode;
+       if (flags & O_CREAT)
+               op->mode = (mode & S_IALLUGO) | S_IFREG;
+       else
+               op->mode = 0;
  
        /* Must never be set by userspace */
        flags &= ~FMODE_NONOTIFY;
@@@ -1081,7 -1081,7 +1082,7 @@@ SYSCALL_DEFINE1(close, unsigned int, fd
        if (!filp)
                goto out_unlock;
        rcu_assign_pointer(fdt->fd[fd], NULL);
 -      FD_CLR(fd, fdt->close_on_exec);
 +      __clear_close_on_exec(fd, fdt);
        __put_unused_fd(files, fd);
        spin_unlock(&files->file_lock);
        retval = filp_close(filp, files);
diff --combined kernel/sched.c
@@@ -746,22 -746,19 +746,19 @@@ static inline int cpu_of(struct rq *rq
  /*
   * Return the group to which this tasks belongs.
   *
-  * We use task_subsys_state_check() and extend the RCU verification with
-  * pi->lock and rq->lock because cpu_cgroup_attach() holds those locks for each
-  * task it moves into the cgroup. Therefore by holding either of those locks,
-  * we pin the task to the current cgroup.
+  * We cannot use task_subsys_state() and friends because the cgroup
+  * subsystem changes that value before the cgroup_subsys::attach() method
+  * is called, therefore we cannot pin it and might observe the wrong value.
+  *
+  * The same is true for autogroup's p->signal->autogroup->tg, the autogroup
+  * core changes this before calling sched_move_task().
+  *
+  * Instead we use a 'copy' which is updated from sched_move_task() while
+  * holding both task_struct::pi_lock and rq::lock.
   */
  static inline struct task_group *task_group(struct task_struct *p)
  {
-       struct task_group *tg;
-       struct cgroup_subsys_state *css;
-       css = task_subsys_state_check(p, cpu_cgroup_subsys_id,
-                       lockdep_is_held(&p->pi_lock) ||
-                       lockdep_is_held(&task_rq(p)->lock));
-       tg = container_of(css, struct task_group, css);
-       return autogroup_task_group(p, tg);
+       return p->sched_task_group;
  }
  
  /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
@@@ -2372,7 -2369,7 +2369,7 @@@ void set_task_cpu(struct task_struct *p
         * a task's CPU. ->pi_lock for waking tasks, rq->lock for runnable tasks.
         *
         * sched_move_task() holds both and thus holding either pins the cgroup,
-        * see set_task_rq().
+        * see task_group().
         *
         * Furthermore, all task_rq users should acquire both locks, see
         * task_rq_lock().
@@@ -4358,6 -4355,20 +4355,20 @@@ void thread_group_times(struct task_str
  # define nsecs_to_cputime(__nsecs)    nsecs_to_jiffies(__nsecs)
  #endif
  
+ static cputime_t scale_utime(cputime_t utime, cputime_t rtime, cputime_t total)
+ {
+       u64 temp = (__force u64) rtime;
+       temp *= (__force u64) utime;
+       if (sizeof(cputime_t) == 4)
+               temp = div_u64(temp, (__force u32) total);
+       else
+               temp = div64_u64(temp, (__force u64) total);
+       return (__force cputime_t) temp;
+ }
  void task_times(struct task_struct *p, cputime_t *ut, cputime_t *st)
  {
        cputime_t rtime, utime = p->utime, total = cputime_add(utime, p->stime);
         */
        rtime = nsecs_to_cputime(p->se.sum_exec_runtime);
  
-       if (total) {
-               u64 temp = rtime;
-               temp *= utime;
-               do_div(temp, total);
-               utime = (cputime_t)temp;
-       } else
+       if (total)
+               utime = scale_utime(utime, rtime, total);
+       else
                utime = rtime;
  
        /*
@@@ -4400,13 -4407,9 +4407,9 @@@ void thread_group_times(struct task_str
        total = cputime_add(cputime.utime, cputime.stime);
        rtime = nsecs_to_cputime(cputime.sum_exec_runtime);
  
-       if (total) {
-               u64 temp = rtime;
-               temp *= cputime.utime;
-               do_div(temp, total);
-               utime = (cputime_t)temp;
-       } else
+       if (total)
+               utime = scale_utime(cputime.utime, rtime, total);
+       else
                utime = rtime;
  
        sig->prev_utime = max(sig->prev_utime, utime);
@@@ -5290,7 -5293,6 +5293,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
  
@@@ -8953,6 -8955,7 +8956,7 @@@ void sched_destroy_group(struct task_gr
   */
  void sched_move_task(struct task_struct *tsk)
  {
+       struct task_group *tg;
        int on_rq, running;
        unsigned long flags;
        struct rq *rq;
        if (unlikely(running))
                tsk->sched_class->put_prev_task(rq, tsk);
  
+       tg = container_of(task_subsys_state_check(tsk, cpu_cgroup_subsys_id,
+                               lockdep_is_held(&tsk->sighand->siglock)),
+                         struct task_group, css);
+       tg = autogroup_task_group(tsk, tg);
+       tsk->sched_task_group = tg;
  #ifdef CONFIG_FAIR_GROUP_SCHED
        if (tsk->sched_class->task_move_group)
                tsk->sched_class->task_move_group(tsk, on_rq);
diff --combined mm/memory.c
@@@ -1358,8 -1358,11 +1358,11 @@@ unsigned long unmap_vmas(struct mmu_gat
                                 * Since no pte has actually been setup, it is
                                 * safe to do nothing in this case.
                                 */
-                               if (vma->vm_file)
-                                       unmap_hugepage_range(vma, start, end, NULL);
+                               if (vma->vm_file) {
+                                       mutex_lock(&vma->vm_file->f_mapping->i_mmap_mutex);
+                                       __unmap_hugepage_range_final(vma, start, end, NULL);
+                                       mutex_unlock(&vma->vm_file->f_mapping->i_mmap_mutex);
+                               }
  
                                start = end;
                        } else
@@@ -1393,7 -1396,6 +1396,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