Skip to content

Commit

Permalink
Merge tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/kernel/git/rusty/linux

Pull virtio updates from Rusty Russell.

* tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux:
  Revert "hwrng: virtio - ensure reads happen after successful probe"
  virtio: rng: delay hwrng_register() till driver is ready
  virtio: rng: re-arrange struct elements for better packing
  virtio: rng: remove unused struct element
  virtio: Replace DEFINE_PCI_DEVICE_TABLE macro use
  virtio: console: remove unnecessary null test before debugfs_remove_recursive
  • Loading branch information
Linus Torvalds committed Aug 11, 2014
2 parents 155134f + eeec626 commit 801a71a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
6 changes: 0 additions & 6 deletions drivers/char/hw_random/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ static void add_early_randomness(struct hwrng *rng)
unsigned char bytes[16];
int bytes_read;

/*
* Currently only virtio-rng cannot return data during device
* probe, and that's handled in virtio-rng.c itself. If there
* are more such devices, this call to rng_get_data can be
* made conditional here instead of doing it per-device.
*/
bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1);
if (bytes_read > 0)
add_device_randomness(bytes, bytes_read);
Expand Down
39 changes: 17 additions & 22 deletions drivers/char/hw_random/virtio-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@
static DEFINE_IDA(rng_index_ida);

struct virtrng_info {
struct virtio_device *vdev;
struct hwrng hwrng;
struct virtqueue *vq;
unsigned int data_avail;
struct completion have_data;
bool busy;
char name[25];
unsigned int data_avail;
int index;
bool busy;
bool hwrng_register_done;
};

static bool probe_done;

static void random_recv_done(struct virtqueue *vq)
{
Expand Down Expand Up @@ -69,13 +68,6 @@ static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait)
int ret;
struct virtrng_info *vi = (struct virtrng_info *)rng->priv;

/*
* Don't ask host for data till we're setup. This call can
* happen during hwrng_register(), after commit d9e7972619.
*/
if (unlikely(!probe_done))
return 0;

if (!vi->busy) {
vi->busy = true;
init_completion(&vi->have_data);
Expand Down Expand Up @@ -137,25 +129,17 @@ static int probe_common(struct virtio_device *vdev)
return err;
}

err = hwrng_register(&vi->hwrng);
if (err) {
vdev->config->del_vqs(vdev);
vi->vq = NULL;
kfree(vi);
ida_simple_remove(&rng_index_ida, index);
return err;
}

probe_done = true;
return 0;
}

static void remove_common(struct virtio_device *vdev)
{
struct virtrng_info *vi = vdev->priv;

vdev->config->reset(vdev);
vi->busy = false;
hwrng_unregister(&vi->hwrng);
if (vi->hwrng_register_done)
hwrng_unregister(&vi->hwrng);
vdev->config->del_vqs(vdev);
ida_simple_remove(&rng_index_ida, vi->index);
kfree(vi);
Expand All @@ -171,6 +155,16 @@ static void virtrng_remove(struct virtio_device *vdev)
remove_common(vdev);
}

static void virtrng_scan(struct virtio_device *vdev)
{
struct virtrng_info *vi = vdev->priv;
int err;

err = hwrng_register(&vi->hwrng);
if (!err)
vi->hwrng_register_done = true;
}

#ifdef CONFIG_PM_SLEEP
static int virtrng_freeze(struct virtio_device *vdev)
{
Expand All @@ -195,6 +189,7 @@ static struct virtio_driver virtio_rng_driver = {
.id_table = id_table,
.probe = virtrng_probe,
.remove = virtrng_remove,
.scan = virtrng_scan,
#ifdef CONFIG_PM_SLEEP
.freeze = virtrng_freeze,
.restore = virtrng_restore,
Expand Down
6 changes: 2 additions & 4 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2262,8 +2262,7 @@ static int __init init(void)
unregister:
unregister_virtio_driver(&virtio_console);
free:
if (pdrvdata.debugfs_dir)
debugfs_remove_recursive(pdrvdata.debugfs_dir);
debugfs_remove_recursive(pdrvdata.debugfs_dir);
class_destroy(pdrvdata.class);
return err;
}
Expand All @@ -2276,8 +2275,7 @@ static void __exit fini(void)
unregister_virtio_driver(&virtio_rproc_serial);

class_destroy(pdrvdata.class);
if (pdrvdata.debugfs_dir)
debugfs_remove_recursive(pdrvdata.debugfs_dir);
debugfs_remove_recursive(pdrvdata.debugfs_dir);
}
module_init(init);
module_exit(fini);
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct virtio_pci_vq_info
};

/* Qumranet donated their vendor ID for devices 0x1000 thru 0x10FF. */
static DEFINE_PCI_DEVICE_TABLE(virtio_pci_id_table) = {
static const struct pci_device_id virtio_pci_id_table[] = {
{ PCI_DEVICE(0x1af4, PCI_ANY_ID) },
{ 0 }
};
Expand Down

0 comments on commit 801a71a

Please sign in to comment.