mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 14:41:27 +00:00
virtio: fixes
A couple of bug fixes. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> -----BEGIN PGP SIGNATURE----- iQFDBAABCAAtFiEEXQn9CHHI+FuUyooNKB8NuNKNVGkFAl6vmuYPHG1zdEByZWRo YXQuY29tAAoJECgfDbjSjVRp9n0H/3jlNn/NTaSpvHJUSfVl6jQRDXvfaDFRCjWO 30ueh+R+k0LnaL33XvWGLmfB0nQjnymYWhZT8MXwIG0iZUVDEMaiF3GV9SP+Ss6L iDokQT3Xhc+bP3PC/kk/PFkrJFmkJHi6M5j6jSRhbWR/Krxy5+eveNlaD9W3cbY0 tMw61WZ+IyhTmBV6u79A8arjCu8ihTVX7EPCcQ4ZcWWpBmKYtXPoDj22ZsoB4IJK cYM6XYmbnQ3ZTyL7EbgONgo8UvdkN2LN9L7CkdRVRrzMqWKkbJ3vbjanTtN+uOKA ZRSuw10dfgzBF3Gl/8kRF2UASXpMQHaR5fiLjC4V2D1A65+F2aU= =Ow6r -----END PGP SIGNATURE----- Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost Pull virtio fixes from Michael Tsirkin: "A couple of bug fixes" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: vsock: kick send_pkt worker once device is started virtio-blk: handle block_device_operations callbacks after hot unplug
This commit is contained in:
commit
a16a47e98a
2 changed files with 83 additions and 8 deletions
|
@ -33,6 +33,15 @@ struct virtio_blk_vq {
|
||||||
} ____cacheline_aligned_in_smp;
|
} ____cacheline_aligned_in_smp;
|
||||||
|
|
||||||
struct virtio_blk {
|
struct virtio_blk {
|
||||||
|
/*
|
||||||
|
* This mutex must be held by anything that may run after
|
||||||
|
* virtblk_remove() sets vblk->vdev to NULL.
|
||||||
|
*
|
||||||
|
* blk-mq, virtqueue processing, and sysfs attribute code paths are
|
||||||
|
* shut down before vblk->vdev is set to NULL and therefore do not need
|
||||||
|
* to hold this mutex.
|
||||||
|
*/
|
||||||
|
struct mutex vdev_mutex;
|
||||||
struct virtio_device *vdev;
|
struct virtio_device *vdev;
|
||||||
|
|
||||||
/* The disk structure for the kernel. */
|
/* The disk structure for the kernel. */
|
||||||
|
@ -44,6 +53,13 @@ struct virtio_blk {
|
||||||
/* Process context for config space updates */
|
/* Process context for config space updates */
|
||||||
struct work_struct config_work;
|
struct work_struct config_work;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tracks references from block_device_operations open/release and
|
||||||
|
* virtio_driver probe/remove so this object can be freed once no
|
||||||
|
* longer in use.
|
||||||
|
*/
|
||||||
|
refcount_t refs;
|
||||||
|
|
||||||
/* What host tells us, plus 2 for header & tailer. */
|
/* What host tells us, plus 2 for header & tailer. */
|
||||||
unsigned int sg_elems;
|
unsigned int sg_elems;
|
||||||
|
|
||||||
|
@ -295,10 +311,55 @@ out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void virtblk_get(struct virtio_blk *vblk)
|
||||||
|
{
|
||||||
|
refcount_inc(&vblk->refs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void virtblk_put(struct virtio_blk *vblk)
|
||||||
|
{
|
||||||
|
if (refcount_dec_and_test(&vblk->refs)) {
|
||||||
|
ida_simple_remove(&vd_index_ida, vblk->index);
|
||||||
|
mutex_destroy(&vblk->vdev_mutex);
|
||||||
|
kfree(vblk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int virtblk_open(struct block_device *bd, fmode_t mode)
|
||||||
|
{
|
||||||
|
struct virtio_blk *vblk = bd->bd_disk->private_data;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
mutex_lock(&vblk->vdev_mutex);
|
||||||
|
|
||||||
|
if (vblk->vdev)
|
||||||
|
virtblk_get(vblk);
|
||||||
|
else
|
||||||
|
ret = -ENXIO;
|
||||||
|
|
||||||
|
mutex_unlock(&vblk->vdev_mutex);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void virtblk_release(struct gendisk *disk, fmode_t mode)
|
||||||
|
{
|
||||||
|
struct virtio_blk *vblk = disk->private_data;
|
||||||
|
|
||||||
|
virtblk_put(vblk);
|
||||||
|
}
|
||||||
|
|
||||||
/* We provide getgeo only to please some old bootloader/partitioning tools */
|
/* We provide getgeo only to please some old bootloader/partitioning tools */
|
||||||
static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
|
static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
|
||||||
{
|
{
|
||||||
struct virtio_blk *vblk = bd->bd_disk->private_data;
|
struct virtio_blk *vblk = bd->bd_disk->private_data;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
mutex_lock(&vblk->vdev_mutex);
|
||||||
|
|
||||||
|
if (!vblk->vdev) {
|
||||||
|
ret = -ENXIO;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/* see if the host passed in geometry config */
|
/* see if the host passed in geometry config */
|
||||||
if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_GEOMETRY)) {
|
if (virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_GEOMETRY)) {
|
||||||
|
@ -314,11 +375,15 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
|
||||||
geo->sectors = 1 << 5;
|
geo->sectors = 1 << 5;
|
||||||
geo->cylinders = get_capacity(bd->bd_disk) >> 11;
|
geo->cylinders = get_capacity(bd->bd_disk) >> 11;
|
||||||
}
|
}
|
||||||
return 0;
|
out:
|
||||||
|
mutex_unlock(&vblk->vdev_mutex);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct block_device_operations virtblk_fops = {
|
static const struct block_device_operations virtblk_fops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
|
.open = virtblk_open,
|
||||||
|
.release = virtblk_release,
|
||||||
.getgeo = virtblk_getgeo,
|
.getgeo = virtblk_getgeo,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -655,6 +720,10 @@ static int virtblk_probe(struct virtio_device *vdev)
|
||||||
goto out_free_index;
|
goto out_free_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This reference is dropped in virtblk_remove(). */
|
||||||
|
refcount_set(&vblk->refs, 1);
|
||||||
|
mutex_init(&vblk->vdev_mutex);
|
||||||
|
|
||||||
vblk->vdev = vdev;
|
vblk->vdev = vdev;
|
||||||
vblk->sg_elems = sg_elems;
|
vblk->sg_elems = sg_elems;
|
||||||
|
|
||||||
|
@ -820,8 +889,6 @@ out:
|
||||||
static void virtblk_remove(struct virtio_device *vdev)
|
static void virtblk_remove(struct virtio_device *vdev)
|
||||||
{
|
{
|
||||||
struct virtio_blk *vblk = vdev->priv;
|
struct virtio_blk *vblk = vdev->priv;
|
||||||
int index = vblk->index;
|
|
||||||
int refc;
|
|
||||||
|
|
||||||
/* Make sure no work handler is accessing the device. */
|
/* Make sure no work handler is accessing the device. */
|
||||||
flush_work(&vblk->config_work);
|
flush_work(&vblk->config_work);
|
||||||
|
@ -831,18 +898,21 @@ static void virtblk_remove(struct virtio_device *vdev)
|
||||||
|
|
||||||
blk_mq_free_tag_set(&vblk->tag_set);
|
blk_mq_free_tag_set(&vblk->tag_set);
|
||||||
|
|
||||||
|
mutex_lock(&vblk->vdev_mutex);
|
||||||
|
|
||||||
/* Stop all the virtqueues. */
|
/* Stop all the virtqueues. */
|
||||||
vdev->config->reset(vdev);
|
vdev->config->reset(vdev);
|
||||||
|
|
||||||
refc = kref_read(&disk_to_dev(vblk->disk)->kobj.kref);
|
/* Virtqueues are stopped, nothing can use vblk->vdev anymore. */
|
||||||
|
vblk->vdev = NULL;
|
||||||
|
|
||||||
put_disk(vblk->disk);
|
put_disk(vblk->disk);
|
||||||
vdev->config->del_vqs(vdev);
|
vdev->config->del_vqs(vdev);
|
||||||
kfree(vblk->vqs);
|
kfree(vblk->vqs);
|
||||||
kfree(vblk);
|
|
||||||
|
|
||||||
/* Only free device id if we don't have any users */
|
mutex_unlock(&vblk->vdev_mutex);
|
||||||
if (refc == 1)
|
|
||||||
ida_simple_remove(&vd_index_ida, index);
|
virtblk_put(vblk);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_PM_SLEEP
|
#ifdef CONFIG_PM_SLEEP
|
||||||
|
|
|
@ -543,6 +543,11 @@ static int vhost_vsock_start(struct vhost_vsock *vsock)
|
||||||
mutex_unlock(&vq->mutex);
|
mutex_unlock(&vq->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Some packets may have been queued before the device was started,
|
||||||
|
* let's kick the send worker to send them.
|
||||||
|
*/
|
||||||
|
vhost_work_queue(&vsock->dev, &vsock->send_pkt_work);
|
||||||
|
|
||||||
mutex_unlock(&vsock->dev.mutex);
|
mutex_unlock(&vsock->dev.mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue