diff options
author | Avi Kivity <avi@redhat.com> | 2009-12-20 08:13:43 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2010-03-01 10:35:41 -0500 |
commit | 980da6ce573b7c40886406674ff8f022a975e65e (patch) | |
tree | b8751c6b766e937ea137d84a48d248b63c2ac02d /virt/kvm/coalesced_mmio.c | |
parent | 50eb2a3cd0f50d912b26d0b79b7f443344608390 (diff) |
KVM: Simplify coalesced mmio initialization
- add destructor function
- move related allocation into constructor
- add stubs for !CONFIG_KVM_MMIO
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt/kvm/coalesced_mmio.c')
-rw-r--r-- | virt/kvm/coalesced_mmio.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c index 04d69cd7049b..d68e6c68e0ff 100644 --- a/virt/kvm/coalesced_mmio.c +++ b/virt/kvm/coalesced_mmio.c | |||
@@ -92,11 +92,19 @@ static const struct kvm_io_device_ops coalesced_mmio_ops = { | |||
92 | int kvm_coalesced_mmio_init(struct kvm *kvm) | 92 | int kvm_coalesced_mmio_init(struct kvm *kvm) |
93 | { | 93 | { |
94 | struct kvm_coalesced_mmio_dev *dev; | 94 | struct kvm_coalesced_mmio_dev *dev; |
95 | struct page *page; | ||
95 | int ret; | 96 | int ret; |
96 | 97 | ||
98 | ret = -ENOMEM; | ||
99 | page = alloc_page(GFP_KERNEL | __GFP_ZERO); | ||
100 | if (!page) | ||
101 | goto out_err; | ||
102 | kvm->coalesced_mmio_ring = page_address(page); | ||
103 | |||
104 | ret = -ENOMEM; | ||
97 | dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); | 105 | dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); |
98 | if (!dev) | 106 | if (!dev) |
99 | return -ENOMEM; | 107 | goto out_free_page; |
100 | spin_lock_init(&dev->lock); | 108 | spin_lock_init(&dev->lock); |
101 | kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops); | 109 | kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops); |
102 | dev->kvm = kvm; | 110 | dev->kvm = kvm; |
@@ -104,11 +112,24 @@ int kvm_coalesced_mmio_init(struct kvm *kvm) | |||
104 | 112 | ||
105 | ret = kvm_io_bus_register_dev(kvm, &kvm->mmio_bus, &dev->dev); | 113 | ret = kvm_io_bus_register_dev(kvm, &kvm->mmio_bus, &dev->dev); |
106 | if (ret < 0) | 114 | if (ret < 0) |
107 | kfree(dev); | 115 | goto out_free_dev; |
116 | |||
117 | return ret; | ||
108 | 118 | ||
119 | out_free_dev: | ||
120 | kfree(dev); | ||
121 | out_free_page: | ||
122 | __free_page(page); | ||
123 | out_err: | ||
109 | return ret; | 124 | return ret; |
110 | } | 125 | } |
111 | 126 | ||
127 | void kvm_coalesced_mmio_free(struct kvm *kvm) | ||
128 | { | ||
129 | if (kvm->coalesced_mmio_ring) | ||
130 | free_page((unsigned long)kvm->coalesced_mmio_ring); | ||
131 | } | ||
132 | |||
112 | int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm, | 133 | int kvm_vm_ioctl_register_coalesced_mmio(struct kvm *kvm, |
113 | struct kvm_coalesced_mmio_zone *zone) | 134 | struct kvm_coalesced_mmio_zone *zone) |
114 | { | 135 | { |