Merge branch 'for-4.4/io-poll' of git://git.kernel.dk/linux-block
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Nov 2015 01:23:49 +0000 (17:23 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 11 Nov 2015 01:23:49 +0000 (17:23 -0800)
Pull block IO poll support from Jens Axboe:
 "Various groups have been doing experimentation around IO polling for
  (really) fast devices.  The code has been reviewed and has been
  sitting on the side for a few releases, but this is now good enough
  for coordinated benchmarking and further experimentation.

  Currently O_DIRECT sync read/write are supported.  A framework is in
  the works that allows scalable stats tracking so we can auto-tune
  this.  And we'll add libaio support as well soon.  Fow now, it's an
  opt-in feature for test purposes"

* 'for-4.4/io-poll' of git://git.kernel.dk/linux-block:
  direct-io: be sure to assign dio->bio_bdev for both paths
  directio: add block polling support
  NVMe: add blk polling support
  block: add block polling support
  blk-mq: return tag/queue combo in the make_request_fn handlers
  block: change ->make_request_fn() and users to return a queue cookie

1  2 
block/blk-core.c
block/blk-mq.c
drivers/block/pktcdvd.c
drivers/block/zram/zram_drv.c
drivers/nvdimm/pmem.c
drivers/nvme/host/pci.c
fs/direct-io.c
include/linux/fs.h

diff --combined block/blk-core.c
index 590cca21c24a771fe04339046ef172a23b278f35,fa36b4ff7d63146d3af4a48802f0f4070d286109..2bbf08cd29007a8da2db6e9cca053c79094ee504
@@@ -638,7 -638,7 +638,7 @@@ int blk_queue_enter(struct request_queu
                if (percpu_ref_tryget_live(&q->q_usage_counter))
                        return 0;
  
 -              if (!(gfp & __GFP_WAIT))
 +              if (!gfpflags_allow_blocking(gfp))
                        return -EBUSY;
  
                ret = wait_event_interruptible(q->mq_freeze_wq,
@@@ -809,7 -809,7 +809,7 @@@ blk_init_queue_node(request_fn_proc *rf
  }
  EXPORT_SYMBOL(blk_init_queue_node);
  
- static void blk_queue_bio(struct request_queue *q, struct bio *bio);
+ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio);
  
  struct request_queue *
  blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn,
@@@ -1206,8 -1206,8 +1206,8 @@@ rq_starved
   * @bio: bio to allocate request for (can be %NULL)
   * @gfp_mask: allocation mask
   *
 - * Get a free request from @q.  If %__GFP_WAIT is set in @gfp_mask, this
 - * function keeps retrying under memory pressure and fails iff @q is dead.
 + * Get a free request from @q.  If %__GFP_DIRECT_RECLAIM is set in @gfp_mask,
 + * this function keeps retrying under memory pressure and fails iff @q is dead.
   *
   * Must be called with @q->queue_lock held and,
   * Returns ERR_PTR on failure, with @q->queue_lock held.
@@@ -1227,7 -1227,7 +1227,7 @@@ retry
        if (!IS_ERR(rq))
                return rq;
  
 -      if (!(gfp_mask & __GFP_WAIT) || unlikely(blk_queue_dying(q))) {
 +      if (!gfpflags_allow_blocking(gfp_mask) || unlikely(blk_queue_dying(q))) {
                blk_put_rl(rl);
                return rq;
        }
@@@ -1305,11 -1305,11 +1305,11 @@@ EXPORT_SYMBOL(blk_get_request)
   * BUG.
   *
   * WARNING: When allocating/cloning a bio-chain, careful consideration should be
 - * given to how you allocate bios. In particular, you cannot use __GFP_WAIT for
 - * anything but the first bio in the chain. Otherwise you risk waiting for IO
 - * completion of a bio that hasn't been submitted yet, thus resulting in a
 - * deadlock. Alternatively bios should be allocated using bio_kmalloc() instead
 - * of bio_alloc(), as that avoids the mempool deadlock.
 + * given to how you allocate bios. In particular, you cannot use
 + * __GFP_DIRECT_RECLAIM for anything but the first bio in the chain. Otherwise
 + * you risk waiting for IO completion of a bio that hasn't been submitted yet,
 + * thus resulting in a deadlock. Alternatively bios should be allocated using
 + * bio_kmalloc() instead of bio_alloc(), as that avoids the mempool deadlock.
   * If possible a big IO should be split into smaller parts when allocation
   * fails. Partial allocation should not be an error, or you risk a live-lock.
   */
@@@ -1678,7 -1678,7 +1678,7 @@@ void init_request_from_bio(struct reque
        blk_rq_bio_prep(req->q, req, bio);
  }
  
- static void blk_queue_bio(struct request_queue *q, struct bio *bio)
+ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
  {
        const bool sync = !!(bio->bi_rw & REQ_SYNC);
        struct blk_plug *plug;
        if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
                bio->bi_error = -EIO;
                bio_endio(bio);
-               return;
+               return BLK_QC_T_NONE;
        }
  
        if (bio->bi_rw & (REQ_FLUSH | REQ_FUA)) {
         */
        if (!blk_queue_nomerges(q)) {
                if (blk_attempt_plug_merge(q, bio, &request_count, NULL))
-                       return;
+                       return BLK_QC_T_NONE;
        } else
                request_count = blk_plug_queued_count(q);
  
@@@ -1791,6 -1791,8 +1791,8 @@@ get_rq
  out_unlock:
                spin_unlock_irq(q->queue_lock);
        }
+       return BLK_QC_T_NONE;
  }
  
  /*
@@@ -1996,12 -1998,13 +1998,13 @@@ end_io
   * a lower device by calling into generic_make_request recursively, which
   * means the bio should NOT be touched after the call to ->make_request_fn.
   */
void generic_make_request(struct bio *bio)
blk_qc_t generic_make_request(struct bio *bio)
  {
        struct bio_list bio_list_on_stack;
+       blk_qc_t ret = BLK_QC_T_NONE;
  
        if (!generic_make_request_checks(bio))
-               return;
+               goto out;
  
        /*
         * We only want one ->make_request_fn to be active at a time, else
         */
        if (current->bio_list) {
                bio_list_add(current->bio_list, bio);
-               return;
+               goto out;
        }
  
        /* following loop may be a bit non-obvious, and so deserves some
        do {
                struct request_queue *q = bdev_get_queue(bio->bi_bdev);
  
 -              if (likely(blk_queue_enter(q, __GFP_WAIT) == 0)) {
 +              if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) {
  
-                       q->make_request_fn(q, bio);
+                       ret = q->make_request_fn(q, bio);
  
                        blk_queue_exit(q);
  
                }
        } while (bio);
        current->bio_list = NULL; /* deactivate */
+ out:
+       return ret;
  }
  EXPORT_SYMBOL(generic_make_request);
  
   * interfaces; @bio must be presetup and ready for I/O.
   *
   */
void submit_bio(int rw, struct bio *bio)
blk_qc_t submit_bio(int rw, struct bio *bio)
  {
        bio->bi_rw |= rw;
  
                }
        }
  
-       generic_make_request(bio);
+       return generic_make_request(bio);
  }
  EXPORT_SYMBOL(submit_bio);
  
@@@ -3306,6 -3312,47 +3312,47 @@@ void blk_finish_plug(struct blk_plug *p
  }
  EXPORT_SYMBOL(blk_finish_plug);
  
+ bool blk_poll(struct request_queue *q, blk_qc_t cookie)
+ {
+       struct blk_plug *plug;
+       long state;
+       if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) ||
+           !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
+               return false;
+       plug = current->plug;
+       if (plug)
+               blk_flush_plug_list(plug, false);
+       state = current->state;
+       while (!need_resched()) {
+               unsigned int queue_num = blk_qc_t_to_queue_num(cookie);
+               struct blk_mq_hw_ctx *hctx = q->queue_hw_ctx[queue_num];
+               int ret;
+               hctx->poll_invoked++;
+               ret = q->mq_ops->poll(hctx, blk_qc_t_to_tag(cookie));
+               if (ret > 0) {
+                       hctx->poll_success++;
+                       set_current_state(TASK_RUNNING);
+                       return true;
+               }
+               if (signal_pending_state(state, current))
+                       set_current_state(TASK_RUNNING);
+               if (current->state == TASK_RUNNING)
+                       return true;
+               if (ret < 0)
+                       break;
+               cpu_relax();
+       }
+       return false;
+ }
  #ifdef CONFIG_PM
  /**
   * blk_pm_runtime_init - Block layer runtime PM initialization routine
diff --combined block/blk-mq.c
index 694f8703f83cf4b5db887399bbde818bde492eaf,66f3cf9c436d49a8ad1b7060d564a3ce7fa31983..86bd5b25288e29c0415700db4993cd239183366e
@@@ -244,11 -244,11 +244,11 @@@ struct request *blk_mq_alloc_request(st
  
        ctx = blk_mq_get_ctx(q);
        hctx = q->mq_ops->map_queue(q, ctx->cpu);
 -      blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_WAIT,
 +      blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_DIRECT_RECLAIM,
                        reserved, ctx, hctx);
  
        rq = __blk_mq_alloc_request(&alloc_data, rw);
 -      if (!rq && (gfp & __GFP_WAIT)) {
 +      if (!rq && (gfp & __GFP_DIRECT_RECLAIM)) {
                __blk_mq_run_hw_queue(hctx);
                blk_mq_put_ctx(ctx);
  
@@@ -1186,7 -1186,7 +1186,7 @@@ static struct request *blk_mq_map_reque
                ctx = blk_mq_get_ctx(q);
                hctx = q->mq_ops->map_queue(q, ctx->cpu);
                blk_mq_set_alloc_data(&alloc_data, q,
 -                              __GFP_WAIT|GFP_ATOMIC, false, ctx, hctx);
 +                              __GFP_RECLAIM|__GFP_HIGH, false, ctx, hctx);
                rq = __blk_mq_alloc_request(&alloc_data, rw);
                ctx = alloc_data.ctx;
                hctx = alloc_data.hctx;
        return rq;
  }
  
- static int blk_mq_direct_issue_request(struct request *rq)
+ static int blk_mq_direct_issue_request(struct request *rq, blk_qc_t *cookie)
  {
        int ret;
        struct request_queue *q = rq->q;
                .list = NULL,
                .last = 1
        };
+       blk_qc_t new_cookie = blk_tag_to_qc_t(rq->tag, hctx->queue_num);
  
        /*
         * For OK queue, we are done. For error, kill it. Any other
         * would have done
         */
        ret = q->mq_ops->queue_rq(hctx, &bd);
-       if (ret == BLK_MQ_RQ_QUEUE_OK)
+       if (ret == BLK_MQ_RQ_QUEUE_OK) {
+               *cookie = new_cookie;
                return 0;
-       else {
-               __blk_mq_requeue_request(rq);
+       }
  
-               if (ret == BLK_MQ_RQ_QUEUE_ERROR) {
-                       rq->errors = -EIO;
-                       blk_mq_end_request(rq, rq->errors);
-                       return 0;
-               }
-               return -1;
+       __blk_mq_requeue_request(rq);
+       if (ret == BLK_MQ_RQ_QUEUE_ERROR) {
+               *cookie = BLK_QC_T_NONE;
+               rq->errors = -EIO;
+               blk_mq_end_request(rq, rq->errors);
+               return 0;
        }
+       return -1;
  }
  
  /*
   * but will attempt to bypass the hctx queueing if we can go straight to
   * hardware for SYNC IO.
   */
- static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
+ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
  {
        const int is_sync = rw_is_sync(bio->bi_rw);
        const int is_flush_fua = bio->bi_rw & (REQ_FLUSH | REQ_FUA);
        unsigned int request_count = 0;
        struct blk_plug *plug;
        struct request *same_queue_rq = NULL;
+       blk_qc_t cookie;
  
        blk_queue_bounce(q, &bio);
  
        if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
                bio_io_error(bio);
-               return;
+               return BLK_QC_T_NONE;
        }
  
        blk_queue_split(q, &bio, q->bio_split);
        if (!is_flush_fua && !blk_queue_nomerges(q)) {
                if (blk_attempt_plug_merge(q, bio, &request_count,
                                           &same_queue_rq))
-                       return;
+                       return BLK_QC_T_NONE;
        } else
                request_count = blk_plug_queued_count(q);
  
        rq = blk_mq_map_request(q, bio, &data);
        if (unlikely(!rq))
-               return;
+               return BLK_QC_T_NONE;
+       cookie = blk_tag_to_qc_t(rq->tag, data.hctx->queue_num);
  
        if (unlikely(is_flush_fua)) {
                blk_mq_bio_to_request(rq, bio);
                        old_rq = rq;
                blk_mq_put_ctx(data.ctx);
                if (!old_rq)
-                       return;
-               if (!blk_mq_direct_issue_request(old_rq))
-                       return;
+                       goto done;
+               if (!blk_mq_direct_issue_request(old_rq, &cookie))
+                       goto done;
                blk_mq_insert_request(old_rq, false, true, true);
-               return;
+               goto done;
        }
  
        if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) {
@@@ -1320,13 -1327,15 +1327,15 @@@ run_queue
                blk_mq_run_hw_queue(data.hctx, !is_sync || is_flush_fua);
        }
        blk_mq_put_ctx(data.ctx);
+ done:
+       return cookie;
  }
  
  /*
   * Single hardware queue variant. This will attempt to use any per-process
   * plug for merging and IO deferral.
   */
- static void blk_sq_make_request(struct request_queue *q, struct bio *bio)
+ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio)
  {
        const int is_sync = rw_is_sync(bio->bi_rw);
        const int is_flush_fua = bio->bi_rw & (REQ_FLUSH | REQ_FUA);
        unsigned int request_count = 0;
        struct blk_map_ctx data;
        struct request *rq;
+       blk_qc_t cookie;
  
        blk_queue_bounce(q, &bio);
  
        if (bio_integrity_enabled(bio) && bio_integrity_prep(bio)) {
                bio_io_error(bio);
-               return;
+               return BLK_QC_T_NONE;
        }
  
        blk_queue_split(q, &bio, q->bio_split);
  
        if (!is_flush_fua && !blk_queue_nomerges(q) &&
            blk_attempt_plug_merge(q, bio, &request_count, NULL))
-               return;
+               return BLK_QC_T_NONE;
  
        rq = blk_mq_map_request(q, bio, &data);
        if (unlikely(!rq))
-               return;
+               return BLK_QC_T_NONE;
+       cookie = blk_tag_to_qc_t(rq->tag, data.hctx->queue_num);
  
        if (unlikely(is_flush_fua)) {
                blk_mq_bio_to_request(rq, bio);
                }
                list_add_tail(&rq->queuelist, &plug->mq_list);
                blk_mq_put_ctx(data.ctx);
-               return;
+               return cookie;
        }
  
        if (!blk_mq_merge_queue_io(data.hctx, data.ctx, rq, bio)) {
@@@ -1389,6 -1401,7 +1401,7 @@@ run_queue
        }
  
        blk_mq_put_ctx(data.ctx);
+       return cookie;
  }
  
  /*
diff --combined drivers/block/pktcdvd.c
index 2f477d45d6cfa42d586080db8c293d41406055ae,a7f4abcedee18fbc612f532080771349a062e23c..d06c62eccdf00b81241fba6b3e6d3a05e4e4c923
@@@ -704,14 -704,14 +704,14 @@@ static int pkt_generic_packet(struct pk
        int ret = 0;
  
        rq = blk_get_request(q, (cgc->data_direction == CGC_DATA_WRITE) ?
 -                           WRITE : READ, __GFP_WAIT);
 +                           WRITE : READ, __GFP_RECLAIM);
        if (IS_ERR(rq))
                return PTR_ERR(rq);
        blk_rq_set_block_pc(rq);
  
        if (cgc->buflen) {
                ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
 -                                    __GFP_WAIT);
 +                                    __GFP_RECLAIM);
                if (ret)
                        goto out;
        }
@@@ -2441,7 -2441,7 +2441,7 @@@ static void pkt_make_request_write(stru
        }
  }
  
- static void pkt_make_request(struct request_queue *q, struct bio *bio)
+ static blk_qc_t pkt_make_request(struct request_queue *q, struct bio *bio)
  {
        struct pktcdvd_device *pd;
        char b[BDEVNAME_SIZE];
         */
        if (bio_data_dir(bio) == READ) {
                pkt_make_request_read(pd, bio);
-               return;
+               return BLK_QC_T_NONE;
        }
  
        if (!test_bit(PACKET_WRITABLE, &pd->flags)) {
                pkt_make_request_write(q, split);
        } while (split != bio);
  
-       return;
+       return BLK_QC_T_NONE;
  end_io:
        bio_io_error(bio);
+       return BLK_QC_T_NONE;
  }
  
  static void pkt_init_queue(struct pktcdvd_device *pd)
  {
        struct request_queue *q = pd->disk->queue;
@@@ -2803,7 -2802,8 +2802,7 @@@ out_new_dev
  out_mem2:
        put_disk(disk);
  out_mem:
 -      if (pd->rb_pool)
 -              mempool_destroy(pd->rb_pool);
 +      mempool_destroy(pd->rb_pool);
        kfree(pd);
  out_mutex:
        mutex_unlock(&ctl_mutex);
index 81a557c33a1f8b4a41b19f39b58d8c0e0e40ae35,4c99b6ba86813ddcdf59af1b00aaffe5806264bb..47915d736f8d4fd2f145dca24f97c015fa76a245
@@@ -106,7 -106,7 +106,7 @@@ static void zram_set_obj_size(struct zr
        meta->table[index].value = (flags << ZRAM_FLAG_SHIFT) | size;
  }
  
 -static inline int is_partial_io(struct bio_vec *bvec)
 +static inline bool is_partial_io(struct bio_vec *bvec)
  {
        return bvec->bv_len != PAGE_SIZE;
  }
  /*
   * Check if request is within bounds and aligned on zram logical blocks.
   */
 -static inline int valid_io_request(struct zram *zram,
 +static inline bool valid_io_request(struct zram *zram,
                sector_t start, unsigned int size)
  {
        u64 end, bound;
  
        /* unaligned request */
        if (unlikely(start & (ZRAM_SECTOR_PER_LOGICAL_BLOCK - 1)))
 -              return 0;
 +              return false;
        if (unlikely(size & (ZRAM_LOGICAL_BLOCK_SIZE - 1)))
 -              return 0;
 +              return false;
  
        end = start + (size >> SECTOR_SHIFT);
        bound = zram->disksize >> SECTOR_SHIFT;
        /* out of range range */
        if (unlikely(start >= bound || end > bound || start > end))
 -              return 0;
 +              return false;
  
        /* I/O request is valid */
 -      return 1;
 +      return true;
  }
  
  static void update_position(u32 *index, int *offset, struct bio_vec *bvec)
@@@ -157,7 -157,7 +157,7 @@@ static inline void update_used_max(stru
        } while (old_max != cur_max);
  }
  
 -static int page_zero_filled(void *ptr)
 +static bool page_zero_filled(void *ptr)
  {
        unsigned int pos;
        unsigned long *page;
  
        for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
                if (page[pos])
 -                      return 0;
 +                      return false;
        }
  
 -      return 1;
 +      return true;
  }
  
  static void handle_zero_page(struct bio_vec *bvec)
@@@ -365,9 -365,6 +365,9 @@@ static ssize_t comp_algorithm_store(str
        struct zram *zram = dev_to_zram(dev);
        size_t sz;
  
 +      if (!zcomp_available_algorithm(buf))
 +              return -EINVAL;
 +
        down_write(&zram->init_lock);
        if (init_done(zram)) {
                up_write(&zram->init_lock);
        if (sz > 0 && zram->compressor[sz - 1] == '\n')
                zram->compressor[sz - 1] = 0x00;
  
 -      if (!zcomp_available_algorithm(zram->compressor))
 -              len = -EINVAL;
 -
        up_write(&zram->init_lock);
        return len;
  }
@@@ -726,14 -726,14 +726,14 @@@ static int zram_bvec_write(struct zram 
        }
  
        alloced_pages = zs_get_total_pages(meta->mem_pool);
 +      update_used_max(zram, alloced_pages);
 +
        if (zram->limit_pages && alloced_pages > zram->limit_pages) {
                zs_free(meta->mem_pool, handle);
                ret = -ENOMEM;
                goto out;
        }
  
 -      update_used_max(zram, alloced_pages);
 -
        cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO);
  
        if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) {
@@@ -894,7 -894,7 +894,7 @@@ out
  /*
   * Handler function for all zram I/O requests.
   */
- static void zram_make_request(struct request_queue *queue, struct bio *bio)
+ static blk_qc_t zram_make_request(struct request_queue *queue, struct bio *bio)
  {
        struct zram *zram = queue->queuedata;
  
  
        __zram_make_request(zram, bio);
        zram_meta_put(zram);
-       return;
+       return BLK_QC_T_NONE;
  put_zram:
        zram_meta_put(zram);
  error:
        bio_io_error(bio);
+       return BLK_QC_T_NONE;
  }
  
  static void zram_slot_free_notify(struct block_device *bdev,
diff --combined drivers/nvdimm/pmem.c
index 349f03e7ed064f20dfaf8d25bd0d62f83d829d79,3963b7533b65201cfe8260157a439d05d6401809..012e0649f1ac48374de47a690a2d0ac1d1865cac
@@@ -64,7 -64,7 +64,7 @@@ static void pmem_do_bvec(struct pmem_de
        kunmap_atomic(mem);
  }
  
- static void pmem_make_request(struct request_queue *q, struct bio *bio)
+ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
  {
        bool do_acct;
        unsigned long start;
@@@ -84,6 -84,7 +84,7 @@@
                wmb_pmem();
  
        bio_endio(bio);
+       return BLK_QC_T_NONE;
  }
  
  static int pmem_rw_page(struct block_device *bdev, sector_t sector,
@@@ -150,15 -151,18 +151,15 @@@ static struct pmem_device *pmem_alloc(s
                return ERR_PTR(-EBUSY);
        }
  
 -      if (pmem_should_map_pages(dev)) {
 -              void *addr = devm_memremap_pages(dev, res);
 +      if (pmem_should_map_pages(dev))
 +              pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, res);
 +      else
 +              pmem->virt_addr = (void __pmem *) devm_memremap(dev,
 +                              pmem->phys_addr, pmem->size,
 +                              ARCH_MEMREMAP_PMEM);
  
 -              if (IS_ERR(addr))
 -                      return addr;
 -              pmem->virt_addr = (void __pmem *) addr;
 -      } else {
 -              pmem->virt_addr = memremap_pmem(dev, pmem->phys_addr,
 -                              pmem->size);
 -              if (!pmem->virt_addr)
 -                      return ERR_PTR(-ENXIO);
 -      }
 +      if (IS_ERR(pmem->virt_addr))
 +              return (void __force *) pmem->virt_addr;
  
        return pmem;
  }
@@@ -176,10 -180,9 +177,10 @@@ static void pmem_detach_disk(struct pme
  static int pmem_attach_disk(struct device *dev,
                struct nd_namespace_common *ndns, struct pmem_device *pmem)
  {
 +      int nid = dev_to_node(dev);
        struct gendisk *disk;
  
 -      pmem->pmem_queue = blk_alloc_queue(GFP_KERNEL);
 +      pmem->pmem_queue = blk_alloc_queue_node(GFP_KERNEL, nid);
        if (!pmem->pmem_queue)
                return -ENOMEM;
  
        blk_queue_bounce_limit(pmem->pmem_queue, BLK_BOUNCE_ANY);
        queue_flag_set_unlocked(QUEUE_FLAG_NONROT, pmem->pmem_queue);
  
 -      disk = alloc_disk(0);
 +      disk = alloc_disk_node(0, nid);
        if (!disk) {
                blk_cleanup_queue(pmem->pmem_queue);
                return -ENOMEM;
@@@ -361,8 -364,8 +362,8 @@@ static int nvdimm_namespace_attach_pfn(
  
        /* establish pfn range for lookup, and switch to direct map */
        pmem = dev_get_drvdata(dev);
 -      memunmap_pmem(dev, pmem->virt_addr);
 -      pmem->virt_addr = (void __pmem *)devm_memremap_pages(dev, &nsio->res);
 +      devm_memunmap(dev, (void __force *) pmem->virt_addr);
 +      pmem->virt_addr = (void __pmem *) devm_memremap_pages(dev, &nsio->res);
        if (IS_ERR(pmem->virt_addr)) {
                rc = PTR_ERR(pmem->virt_addr);
                goto err;
diff --combined drivers/nvme/host/pci.c
index 97b6640a3745922fe030bbf04525a4b6de6566d6,4a715f49f5db986cb543dd2b522b66d455c195ad..3dfc28875cc31338be0c33ff040185d03302a3b7
@@@ -41,7 -41,7 +41,7 @@@
  #include <linux/types.h>
  #include <linux/pr.h>
  #include <scsi/sg.h>
 -#include <asm-generic/io-64-nonatomic-lo-hi.h>
 +#include <linux/io-64-nonatomic-lo-hi.h>
  #include <asm/unaligned.h>
  
  #include <uapi/linux/nvme_ioctl.h>
@@@ -90,7 -90,7 +90,7 @@@ static struct class *nvme_class
  
  static int __nvme_reset(struct nvme_dev *dev);
  static int nvme_reset(struct nvme_dev *dev);
- static int nvme_process_cq(struct nvme_queue *nvmeq);
+ static void nvme_process_cq(struct nvme_queue *nvmeq);
  static void nvme_dead_ctrl(struct nvme_dev *dev);
  
  struct async_cmd_info {
@@@ -935,7 -935,7 +935,7 @@@ static int nvme_queue_rq(struct blk_mq_
        return BLK_MQ_RQ_QUEUE_BUSY;
  }
  
- static int nvme_process_cq(struct nvme_queue *nvmeq)
+ static void __nvme_process_cq(struct nvme_queue *nvmeq, unsigned int *tag)
  {
        u16 head, phase;
  
                        head = 0;
                        phase = !phase;
                }
+               if (tag && *tag == cqe.command_id)
+                       *tag = -1;
                ctx = nvme_finish_cmd(nvmeq, cqe.command_id, &fn);
                fn(nvmeq, ctx, &cqe);
        }
         * a big problem.
         */
        if (head == nvmeq->cq_head && phase == nvmeq->cq_phase)
-               return 0;
+               return;
  
        writel(head, nvmeq->q_db + nvmeq->dev->db_stride);
        nvmeq->cq_head = head;
        nvmeq->cq_phase = phase;
  
        nvmeq->cqe_seen = 1;
-       return 1;
+ }
+ static void nvme_process_cq(struct nvme_queue *nvmeq)
+ {
+       __nvme_process_cq(nvmeq, NULL);
  }
  
  static irqreturn_t nvme_irq(int irq, void *data)
@@@ -995,6 -1001,23 +1001,23 @@@ static irqreturn_t nvme_irq_check(int i
        return IRQ_WAKE_THREAD;
  }
  
+ static int nvme_poll(struct blk_mq_hw_ctx *hctx, unsigned int tag)
+ {
+       struct nvme_queue *nvmeq = hctx->driver_data;
+       if ((le16_to_cpu(nvmeq->cqes[nvmeq->cq_head].status) & 1) ==
+           nvmeq->cq_phase) {
+               spin_lock_irq(&nvmeq->q_lock);
+               __nvme_process_cq(nvmeq, &tag);
+               spin_unlock_irq(&nvmeq->q_lock);
+               if (tag == -1)
+                       return 1;
+       }
+       return 0;
+ }
  /*
   * Returns 0 on success.  If the result is negative, it's a Linux error code;
   * if the result is positive, it's an NVM Express status code
@@@ -1025,13 -1048,11 +1048,13 @@@ int __nvme_submit_sync_cmd(struct reque
        req->special = (void *)0;
  
        if (buffer && bufflen) {
 -              ret = blk_rq_map_kern(q, req, buffer, bufflen, __GFP_WAIT);
 +              ret = blk_rq_map_kern(q, req, buffer, bufflen,
 +                                    __GFP_DIRECT_RECLAIM);
                if (ret)
                        goto out;
        } else if (ubuffer && bufflen) {
 -              ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen, __GFP_WAIT);
 +              ret = blk_rq_map_user(q, req, NULL, ubuffer, bufflen,
 +                                    __GFP_DIRECT_RECLAIM);
                if (ret)
                        goto out;
                bio = req->bio;
@@@ -1656,6 -1677,7 +1679,7 @@@ static struct blk_mq_ops nvme_mq_ops = 
        .init_hctx      = nvme_init_hctx,
        .init_request   = nvme_init_request,
        .timeout        = nvme_timeout,
+       .poll           = nvme_poll,
  };
  
  static void nvme_dev_remove_admin(struct nvme_dev *dev)
diff --combined fs/direct-io.c
index 18e7554cf94cac57d1eb3dc17ba4001e75cef5f6,15381c474a118e6b8a62c4d3fc242593a0c0e36a..cb5337d8c273a5dd58e97d9be587fb56d643e52a
@@@ -109,6 -109,8 +109,8 @@@ struct dio_submit 
  struct dio {
        int flags;                      /* doesn't change */
        int rw;
+       blk_qc_t bio_cookie;
+       struct block_device *bio_bdev;
        struct inode *inode;
        loff_t i_size;                  /* i_size when submitted */
        dio_iodone_t *end_io;           /* IO completion function */
@@@ -361,7 -363,7 +363,7 @@@ dio_bio_alloc(struct dio *dio, struct d
  
        /*
         * bio_alloc() is guaranteed to return a bio when called with
 -       * __GFP_WAIT and we request a valid number of vectors.
 +       * __GFP_RECLAIM and we request a valid number of vectors.
         */
        bio = bio_alloc(GFP_KERNEL, nr_vecs);
  
@@@ -397,11 -399,14 +399,14 @@@ static inline void dio_bio_submit(struc
        if (dio->is_async && dio->rw == READ && dio->should_dirty)
                bio_set_pages_dirty(bio);
  
-       if (sdio->submit_io)
+       dio->bio_bdev = bio->bi_bdev;
+       if (sdio->submit_io) {
                sdio->submit_io(dio->rw, bio, dio->inode,
                               sdio->logical_offset_in_bio);
-       else
-               submit_bio(dio->rw, bio);
+               dio->bio_cookie = BLK_QC_T_NONE;
+       } else
+               dio->bio_cookie = submit_bio(dio->rw, bio);
  
        sdio->bio = NULL;
        sdio->boundary = 0;
@@@ -440,7 -445,8 +445,8 @@@ static struct bio *dio_await_one(struc
                __set_current_state(TASK_UNINTERRUPTIBLE);
                dio->waiter = current;
                spin_unlock_irqrestore(&dio->bio_lock, flags);
-               io_schedule();
+               if (!blk_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))
+                       io_schedule();
                /* wake up sets us TASK_RUNNING */
                spin_lock_irqsave(&dio->bio_lock, flags);
                dio->waiter = NULL;
diff --combined include/linux/fs.h
index 9a1cb8c605e0e290d5d5b63829eb151aa55aa180,bcca36e4bc1e044899b79965d00d2d9cceb9250f..6230eb2a9ccadc1657a25b88e48f09e9560e067f
@@@ -1053,11 -1053,12 +1053,11 @@@ extern void locks_remove_file(struct fi
  extern void locks_release_private(struct file_lock *);
  extern void posix_test_lock(struct file *, struct file_lock *);
  extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
 -extern int posix_lock_inode_wait(struct inode *, struct file_lock *);
  extern int posix_unblock_lock(struct file_lock *);
  extern int vfs_test_lock(struct file *, struct file_lock *);
  extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
  extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
 -extern int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl);
 +extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
  extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
  extern void lease_get_mtime(struct inode *, struct timespec *time);
  extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
@@@ -1143,6 -1144,12 +1143,6 @@@ static inline int posix_lock_file(struc
        return -ENOLCK;
  }
  
 -static inline int posix_lock_inode_wait(struct inode *inode,
 -                                      struct file_lock *fl)
 -{
 -      return -ENOLCK;
 -}
 -
  static inline int posix_unblock_lock(struct file_lock *waiter)
  {
        return -ENOENT;
@@@ -1164,7 -1171,8 +1164,7 @@@ static inline int vfs_cancel_lock(struc
        return 0;
  }
  
 -static inline int flock_lock_inode_wait(struct inode *inode,
 -                                      struct file_lock *request)
 +static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
  {
        return -ENOLCK;
  }
@@@ -1207,9 -1215,14 +1207,9 @@@ static inline struct inode *file_inode(
        return f->f_inode;
  }
  
 -static inline int posix_lock_file_wait(struct file *filp, struct file_lock *fl)
 -{
 -      return posix_lock_inode_wait(file_inode(filp), fl);
 -}
 -
 -static inline int flock_lock_file_wait(struct file *filp, struct file_lock *fl)
 +static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
  {
 -      return flock_lock_inode_wait(file_inode(filp), fl);
 +      return locks_lock_inode_wait(file_inode(filp), fl);
  }
  
  struct fasync_struct {
@@@ -2409,7 -2422,6 +2409,7 @@@ extern int write_inode_now(struct inod
  extern int filemap_fdatawrite(struct address_space *);
  extern int filemap_flush(struct address_space *);
  extern int filemap_fdatawait(struct address_space *);
 +extern void filemap_fdatawait_keep_errors(struct address_space *);
  extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
                                   loff_t lend);
  extern int filemap_write_and_wait(struct address_space *mapping);
@@@ -2613,7 -2625,7 +2613,7 @@@ static inline void remove_inode_hash(st
  extern void inode_sb_list_add(struct inode *inode);
  
  #ifdef CONFIG_BLOCK
- extern void submit_bio(int, struct bio *);
+ extern blk_qc_t submit_bio(int, struct bio *);
  extern int bdev_read_only(struct block_device *);
  #endif
  extern int set_blocksize(struct block_device *, int);