Merge tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 18 Oct 2014 17:25:09 +0000 (10:25 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 18 Oct 2014 17:25:09 +0000 (10:25 -0700)
Pull virtio updates from Rusty Russell:
 "One cc: stable commit, the rest are a series of minor cleanups which
  have been sitting in MST's tree during my vacation.  I changed a
  function name and made one trivial change, then they spent two days in
  linux-next"

* tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: (25 commits)
  virtio-rng: refactor probe error handling
  virtio_scsi: drop scan callback
  virtio_balloon: enable VQs early on restore
  virtio_scsi: fix race on device removal
  virito_scsi: use freezable WQ for events
  virtio_net: enable VQs early on restore
  virtio_console: enable VQs early on restore
  virtio_scsi: enable VQs early on restore
  virtio_blk: enable VQs early on restore
  virtio_scsi: move kick event out from virtscsi_init
  virtio_net: fix use after free on allocation failure
  9p/trans_virtio: enable VQs early
  virtio_console: enable VQs early
  virtio_blk: enable VQs early
  virtio_net: enable VQs early
  virtio: add API to enable VQs early
  virtio_net: minor cleanup
  virtio-net: drop config_mutex
  virtio_net: drop config_enable
  virtio-blk: drop config_mutex
  ...

1  2 
drivers/char/hw_random/virtio-rng.c
drivers/net/virtio_net.c
drivers/virtio/virtio_balloon.c

index 132c9ccfdc62b382cb22a9870e44038c6495a39d,14e351d094aea399a2bd166fe23593b38daf16ef..72295ea2fd1c9b99e0be51fd352e99c1de224a86
@@@ -36,7 -36,6 +36,7 @@@ struct virtrng_info 
        int index;
        bool busy;
        bool hwrng_register_done;
 +      bool hwrng_removed;
  };
  
  
@@@ -69,9 -68,6 +69,9 @@@ static int virtio_read(struct hwrng *rn
        int ret;
        struct virtrng_info *vi = (struct virtrng_info *)rng->priv;
  
 +      if (vi->hwrng_removed)
 +              return -ENODEV;
 +
        if (!vi->busy) {
                vi->busy = true;
                init_completion(&vi->have_data);
@@@ -109,8 -105,8 +109,8 @@@ static int probe_common(struct virtio_d
  
        vi->index = index = ida_simple_get(&rng_index_ida, 0, 0, GFP_KERNEL);
        if (index < 0) {
-               kfree(vi);
-               return index;
+               err = index;
+               goto err_ida;
        }
        sprintf(vi->name, "virtio_rng.%d", index);
        init_completion(&vi->have_data);
        vi->vq = virtio_find_single_vq(vdev, random_recv_done, "input");
        if (IS_ERR(vi->vq)) {
                err = PTR_ERR(vi->vq);
-               vi->vq = NULL;
-               kfree(vi);
-               ida_simple_remove(&rng_index_ida, index);
-               return err;
+               goto err_find;
        }
  
        return 0;
+ err_find:
+       ida_simple_remove(&rng_index_ida, index);
+ err_ida:
+       kfree(vi);
+       return err;
  }
  
  static void remove_common(struct virtio_device *vdev)
  {
        struct virtrng_info *vi = vdev->priv;
  
 +      vi->hwrng_removed = true;
 +      vi->data_avail = 0;
 +      complete(&vi->have_data);
        vdev->config->reset(vdev);
        vi->busy = false;
        if (vi->hwrng_register_done)
diff --combined drivers/net/virtio_net.c
index 13d0a8bc8bf3558d666087a273ab87109f902b59,4e0cbbcd60a7af281ef784791584ed23f2d3a838..d75256bd1a6ab8bb6284ad4088e9513469fffe8a
@@@ -123,9 -123,6 +123,6 @@@ struct virtnet_info 
        /* Host can handle any s/g split between our header and packet data */
        bool any_header_sg;
  
-       /* enable config space updates */
-       bool config_enable;
        /* Active statistics */
        struct virtnet_stats __percpu *stats;
  
        /* Work struct for config space updates */
        struct work_struct config_work;
  
-       /* Lock for config space updates */
-       struct mutex config_lock;
        /* Does the affinity hint is set for virtqueues? */
        bool affinity_hint_set;
  
@@@ -546,8 -540,8 +540,8 @@@ static int add_recvbuf_small(struct rec
        skb_put(skb, GOOD_PACKET_LEN);
  
        hdr = skb_vnet_hdr(skb);
 +      sg_init_table(rq->sg, MAX_SKB_FRAGS + 2);
        sg_set_buf(rq->sg, &hdr->hdr, sizeof hdr->hdr);
 -
        skb_to_sgvec(skb, rq->sg + 1, 0, skb->len);
  
        err = virtqueue_add_inbuf(rq->vq, rq->sg, 2, skb, gfp);
@@@ -563,8 -557,6 +557,8 @@@ static int add_recvbuf_big(struct recei
        char *p;
        int i, err, offset;
  
 +      sg_init_table(rq->sg, MAX_SKB_FRAGS + 2);
 +
        /* page in rq->sg[MAX_SKB_FRAGS + 1] is list tail */
        for (i = MAX_SKB_FRAGS + 1; i > 1; --i) {
                first = get_a_page(rq, gfp);
@@@ -901,7 -893,6 +895,7 @@@ static int xmit_skb(struct send_queue *
        if (vi->mergeable_rx_bufs)
                hdr->mhdr.num_buffers = 0;
  
 +      sg_init_table(sq->sg, MAX_SKB_FRAGS + 2);
        if (can_push) {
                __skb_push(skb, hdr_len);
                num_sg = skb_to_sgvec(skb, sq->sg, 0, skb->len);
@@@ -920,8 -911,6 +914,8 @@@ static netdev_tx_t start_xmit(struct sk
        int qnum = skb_get_queue_mapping(skb);
        struct send_queue *sq = &vi->sq[qnum];
        int err;
 +      struct netdev_queue *txq = netdev_get_tx_queue(dev, qnum);
 +      bool kick = !skb->xmit_more;
  
        /* Free up any pending old buffers before queueing new ones. */
        free_old_xmit_skbs(sq);
                dev_kfree_skb_any(skb);
                return NETDEV_TX_OK;
        }
 -      virtqueue_kick(sq->vq);
  
        /* Don't wait up for transmitted skbs to be freed. */
        skb_orphan(skb);
                }
        }
  
 +      if (kick || netif_xmit_stopped(txq))
 +              virtqueue_kick(sq->vq);
 +
        return NETDEV_TX_OK;
  }
  
@@@ -1414,13 -1401,9 +1408,9 @@@ static void virtnet_config_changed_work
                container_of(work, struct virtnet_info, config_work);
        u16 v;
  
-       mutex_lock(&vi->config_lock);
-       if (!vi->config_enable)
-               goto done;
        if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS,
                                 struct virtio_net_config, status, &v) < 0)
-               goto done;
+               return;
  
        if (v & VIRTIO_NET_S_ANNOUNCE) {
                netdev_notify_peers(vi->dev);
        v &= VIRTIO_NET_S_LINK_UP;
  
        if (vi->status == v)
-               goto done;
+               return;
  
        vi->status = v;
  
                netif_carrier_off(vi->dev);
                netif_tx_stop_all_queues(vi->dev);
        }
- done:
-       mutex_unlock(&vi->config_lock);
  }
  
  static void virtnet_config_changed(struct virtio_device *vdev)
@@@ -1764,8 -1745,6 +1752,6 @@@ static int virtnet_probe(struct virtio_
                u64_stats_init(&virtnet_stats->rx_syncp);
        }
  
-       mutex_init(&vi->config_lock);
-       vi->config_enable = true;
        INIT_WORK(&vi->config_work, virtnet_config_changed_work);
  
        /* If we can receive ANY GSO packets, we must allocate large ones. */
                goto free_vqs;
        }
  
+       virtio_device_ready(vdev);
        /* Last of all, set up some receive buffers. */
        for (i = 0; i < vi->curr_queue_pairs; i++) {
                try_fill_recv(&vi->rq[i], GFP_KERNEL);
        return 0;
  
  free_recv_bufs:
+       vi->vdev->config->reset(vdev);
        free_receive_bufs(vi);
        unregister_netdev(dev);
  free_vqs:
@@@ -1882,17 -1865,13 +1872,13 @@@ static void virtnet_remove(struct virti
  
        unregister_hotcpu_notifier(&vi->nb);
  
-       /* Prevent config work handler from accessing the device. */
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = false;
-       mutex_unlock(&vi->config_lock);
+       /* Make sure no work handler is accessing the device. */
+       flush_work(&vi->config_work);
  
        unregister_netdev(vi->dev);
  
        remove_vq_common(vi);
  
-       flush_work(&vi->config_work);
        free_percpu(vi->stats);
        free_netdev(vi->dev);
  }
@@@ -1905,10 -1884,8 +1891,8 @@@ static int virtnet_freeze(struct virtio
  
        unregister_hotcpu_notifier(&vi->nb);
  
-       /* Prevent config work handler from accessing the device */
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = false;
-       mutex_unlock(&vi->config_lock);
+       /* Make sure no work handler is accessing the device */
+       flush_work(&vi->config_work);
  
        netif_device_detach(vi->dev);
        cancel_delayed_work_sync(&vi->refill);
  
        remove_vq_common(vi);
  
-       flush_work(&vi->config_work);
        return 0;
  }
  
@@@ -1937,6 -1912,8 +1919,8 @@@ static int virtnet_restore(struct virti
        if (err)
                return err;
  
+       virtio_device_ready(vdev);
        if (netif_running(vi->dev)) {
                for (i = 0; i < vi->curr_queue_pairs; i++)
                        if (!try_fill_recv(&vi->rq[i], GFP_KERNEL))
  
        netif_device_attach(vi->dev);
  
-       mutex_lock(&vi->config_lock);
-       vi->config_enable = true;
-       mutex_unlock(&vi->config_lock);
        rtnl_lock();
        virtnet_set_queues(vi, vi->curr_queue_pairs);
        rtnl_unlock();
index f893148a107bf44d23c953f5df1c0b905b2e3c08,f4a28af4865ef450d62821d24f1ddf0f8239cfe5..c9703d4d6f676d8f4922462b6070e7c869d65f77
@@@ -59,7 -59,7 +59,7 @@@ struct virtio_balloo
         * Each page on this list adds VIRTIO_BALLOON_PAGES_PER_PAGE
         * to num_pages above.
         */
 -      struct balloon_dev_info *vb_dev_info;
 +      struct balloon_dev_info vb_dev_info;
  
        /* Synchronize access/update to this struct virtio_balloon elements */
        struct mutex balloon_lock;
@@@ -127,7 -127,7 +127,7 @@@ static void set_page_pfns(u32 pfns[], s
  
  static void fill_balloon(struct virtio_balloon *vb, size_t num)
  {
 -      struct balloon_dev_info *vb_dev_info = vb->vb_dev_info;
 +      struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info;
  
        /* We can only do one array worth at a time. */
        num = min(num, ARRAY_SIZE(vb->pfns));
@@@ -163,15 -163,15 +163,15 @@@ static void release_pages_by_pfn(const 
        /* Find pfns pointing at start of each page, get pages and free them. */
        for (i = 0; i < num; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
                struct page *page = balloon_pfn_to_page(pfns[i]);
 -              balloon_page_free(page);
                adjust_managed_page_count(page, 1);
 +              put_page(page); /* balloon reference */
        }
  }
  
  static void leak_balloon(struct virtio_balloon *vb, size_t num)
  {
        struct page *page;
 -      struct balloon_dev_info *vb_dev_info = vb->vb_dev_info;
 +      struct balloon_dev_info *vb_dev_info = &vb->vb_dev_info;
  
        /* We can only do one array worth at a time. */
        num = min(num, ARRAY_SIZE(vb->pfns));
@@@ -353,11 -353,12 +353,11 @@@ static int init_vqs(struct virtio_ballo
        return 0;
  }
  
 -static const struct address_space_operations virtio_balloon_aops;
  #ifdef CONFIG_BALLOON_COMPACTION
  /*
   * virtballoon_migratepage - perform the balloon page migration on behalf of
   *                         a compation thread.     (called under page lock)
 - * @mapping: the page->mapping which will be assigned to the new migrated page.
 + * @vb_dev_info: the balloon device
   * @newpage: page that will replace the isolated page after migration finishes.
   * @page   : the isolated (old) page that is about to be migrated to newpage.
   * @mode   : compaction mode -- not used for balloon page migration.
   * This function preforms the balloon page migration task.
   * Called through balloon_mapping->a_ops->migratepage
   */
 -static int virtballoon_migratepage(struct address_space *mapping,
 +static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
                struct page *newpage, struct page *page, enum migrate_mode mode)
  {
 -      struct balloon_dev_info *vb_dev_info = balloon_page_device(page);
 -      struct virtio_balloon *vb;
 +      struct virtio_balloon *vb = container_of(vb_dev_info,
 +                      struct virtio_balloon, vb_dev_info);
        unsigned long flags;
  
 -      BUG_ON(!vb_dev_info);
 -
 -      vb = vb_dev_info->balloon_device;
 -
        /*
         * In order to avoid lock contention while migrating pages concurrently
         * to leak_balloon() or fill_balloon() we just give up the balloon_lock
        if (!mutex_trylock(&vb->balloon_lock))
                return -EAGAIN;
  
 +      get_page(newpage); /* balloon reference */
 +
        /* balloon's page migration 1st step  -- inflate "newpage" */
        spin_lock_irqsave(&vb_dev_info->pages_lock, flags);
 -      balloon_page_insert(newpage, mapping, &vb_dev_info->pages);
 +      balloon_page_insert(vb_dev_info, newpage);
        vb_dev_info->isolated_pages--;
 +      __count_vm_event(BALLOON_MIGRATE);
        spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
        vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
        set_page_pfns(vb->pfns, newpage);
        tell_host(vb, vb->inflate_vq);
  
 -      /*
 -       * balloon's page migration 2nd step -- deflate "page"
 -       *
 -       * It's safe to delete page->lru here because this page is at
 -       * an isolated migration list, and this step is expected to happen here
 -       */
 +      /* balloon's page migration 2nd step -- deflate "page" */
        balloon_page_delete(page);
        vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
        set_page_pfns(vb->pfns, page);
  
        mutex_unlock(&vb->balloon_lock);
  
 -      return MIGRATEPAGE_BALLOON_SUCCESS;
 -}
 +      put_page(page); /* balloon reference */
  
 -/* define the balloon_mapping->a_ops callback to allow balloon page migration */
 -static const struct address_space_operations virtio_balloon_aops = {
 -                      .migratepage = virtballoon_migratepage,
 -};
 +      return MIGRATEPAGE_SUCCESS;
 +}
  #endif /* CONFIG_BALLOON_COMPACTION */
  
  static int virtballoon_probe(struct virtio_device *vdev)
  {
        struct virtio_balloon *vb;
 -      struct address_space *vb_mapping;
 -      struct balloon_dev_info *vb_devinfo;
        int err;
  
        vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
        vb->vdev = vdev;
        vb->need_stats_update = 0;
  
 -      vb_devinfo = balloon_devinfo_alloc(vb);
 -      if (IS_ERR(vb_devinfo)) {
 -              err = PTR_ERR(vb_devinfo);
 -              goto out_free_vb;
 -      }
 -
 -      vb_mapping = balloon_mapping_alloc(vb_devinfo,
 -                                         (balloon_compaction_check()) ?
 -                                         &virtio_balloon_aops : NULL);
 -      if (IS_ERR(vb_mapping)) {
 -              /*
 -               * IS_ERR(vb_mapping) && PTR_ERR(vb_mapping) == -EOPNOTSUPP
 -               * This means !CONFIG_BALLOON_COMPACTION, otherwise we get off.
 -               */
 -              err = PTR_ERR(vb_mapping);
 -              if (err != -EOPNOTSUPP)
 -                      goto out_free_vb_devinfo;
 -      }
 -
 -      vb->vb_dev_info = vb_devinfo;
 +      balloon_devinfo_init(&vb->vb_dev_info);
 +#ifdef CONFIG_BALLOON_COMPACTION
 +      vb->vb_dev_info.migratepage = virtballoon_migratepage;
 +#endif
  
        err = init_vqs(vb);
        if (err)
 -              goto out_free_vb_mapping;
 +              goto out_free_vb;
  
        vb->thread = kthread_run(balloon, vb, "vballoon");
        if (IS_ERR(vb->thread)) {
  
  out_del_vqs:
        vdev->config->del_vqs(vdev);
 -out_free_vb_mapping:
 -      balloon_mapping_free(vb_mapping);
 -out_free_vb_devinfo:
 -      balloon_devinfo_free(vb_devinfo);
  out_free_vb:
        kfree(vb);
  out:
@@@ -478,6 -510,8 +478,6 @@@ static void virtballoon_remove(struct v
  
        kthread_stop(vb->thread);
        remove_common(vb);
 -      balloon_mapping_free(vb->vb_dev_info->mapping);
 -      balloon_devinfo_free(vb->vb_dev_info);
        kfree(vb);
  }
  
@@@ -504,6 -538,8 +504,8 @@@ static int virtballoon_restore(struct v
        if (ret)
                return ret;
  
+       virtio_device_ready(vdev);
        fill_balloon(vb, towards_target(vb));
        update_balloon_size(vb);
        return 0;