Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 1 | #include <linux/hrtimer.h> |
| 2 | #include <linux/init.h> |
| 3 | #include <linux/kernel.h> |
| 4 | #include <linux/kthread.h> |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 5 | #include <linux/mm.h> |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 6 | #include <linux/module.h> |
| 7 | #include <linux/sched/task.h> |
| 8 | #include <linux/slab.h> |
| 9 | |
Andrew Scull | 5570423 | 2018-08-10 17:19:54 +0100 | [diff] [blame] | 10 | #include <hf/call.h> |
| 11 | |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 12 | struct hf_vcpu { |
| 13 | spinlock_t lock; |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 14 | struct hf_vm *vm; |
Andrew Scull | 5570423 | 2018-08-10 17:19:54 +0100 | [diff] [blame] | 15 | uint32_t vcpu_index; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 16 | struct task_struct *task; |
| 17 | struct hrtimer timer; |
| 18 | bool pending_irq; |
| 19 | }; |
| 20 | |
| 21 | struct hf_vm { |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 22 | uint32_t id; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 23 | long vcpu_count; |
| 24 | struct hf_vcpu *vcpu; |
| 25 | }; |
| 26 | |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 27 | static struct hf_vm *hf_vms; |
| 28 | static long hf_vm_count; |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 29 | static struct page *hf_send_page = NULL; |
| 30 | static struct page *hf_recv_page = NULL; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 31 | |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 32 | /** |
| 33 | * Wakes up the thread associated with the vcpu that owns the given timer. This |
| 34 | * is called when the timer the thread is waiting on expires. |
| 35 | */ |
| 36 | static enum hrtimer_restart hf_vcpu_timer_expired(struct hrtimer *timer) |
| 37 | { |
| 38 | struct hf_vcpu *vcpu = container_of(timer, struct hf_vcpu, timer); |
| 39 | wake_up_process(vcpu->task); |
| 40 | return HRTIMER_NORESTART; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * This is the main loop of each vcpu. |
| 45 | */ |
| 46 | static int hf_vcpu_thread(void *data) |
| 47 | { |
| 48 | struct hf_vcpu *vcpu = data; |
| 49 | long ret; |
| 50 | |
| 51 | hrtimer_init(&vcpu->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 52 | vcpu->timer.function = &hf_vcpu_timer_expired; |
| 53 | |
| 54 | while (!kthread_should_stop()) { |
| 55 | unsigned long flags; |
| 56 | size_t irqs; |
| 57 | |
| 58 | set_current_state(TASK_RUNNING); |
| 59 | |
| 60 | /* Determine if we must interrupt the vcpu. */ |
| 61 | spin_lock_irqsave(&vcpu->lock, flags); |
| 62 | irqs = vcpu->pending_irq ? 1 : 0; |
| 63 | vcpu->pending_irq = false; |
| 64 | spin_unlock_irqrestore(&vcpu->lock, flags); |
| 65 | |
| 66 | /* Call into hafnium to run vcpu. */ |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 67 | ret = hf_vcpu_run(vcpu->vm->id, vcpu->vcpu_index); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 68 | |
| 69 | /* A negative return value indicates that this vcpu needs to |
| 70 | * sleep for the given number of nanoseconds. |
| 71 | */ |
| 72 | if (ret < 0) { |
| 73 | set_current_state(TASK_INTERRUPTIBLE); |
| 74 | if (kthread_should_stop()) |
| 75 | break; |
| 76 | hrtimer_start(&vcpu->timer, -ret, HRTIMER_MODE_REL); |
| 77 | schedule(); |
| 78 | hrtimer_cancel(&vcpu->timer); |
| 79 | continue; |
| 80 | } |
| 81 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 82 | switch (HF_VCPU_RUN_CODE(ret)) { |
| 83 | /* Yield (forcibly or voluntarily). */ |
| 84 | case HF_VCPU_RUN_YIELD: |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 85 | break; |
| 86 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 87 | /* WFI. */ |
| 88 | case HF_VCPU_RUN_WAIT_FOR_INTERRUPT: |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 89 | set_current_state(TASK_INTERRUPTIBLE); |
| 90 | if (kthread_should_stop()) |
| 91 | break; |
| 92 | schedule(); |
| 93 | break; |
| 94 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 95 | /* Wake up another vcpu. */ |
| 96 | case HF_VCPU_RUN_WAKE_UP: |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 97 | { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 98 | long target = HF_VCPU_RUN_DATA(ret); |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 99 | struct hf_vm *vm = vcpu->vm; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 100 | if (target < vm->vcpu_count) |
| 101 | wake_up_process(vm->vcpu[target].task); |
| 102 | } |
| 103 | break; |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 104 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 105 | /* Response available. */ |
| 106 | case HF_VCPU_RUN_RESPONSE_READY: |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 107 | { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 108 | size_t i, count = HF_VCPU_RUN_DATA(ret); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 109 | const char *buf = page_address(hf_recv_page); |
| 110 | pr_info("Received response (%zu bytes): ", |
| 111 | count); |
| 112 | for (i = 0; i < count; i++) |
| 113 | printk(KERN_CONT "%c", buf[i]); |
| 114 | printk(KERN_CONT "\n"); |
Andrew Scull | 5570423 | 2018-08-10 17:19:54 +0100 | [diff] [blame] | 115 | hf_rpc_ack(); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 116 | } |
| 117 | break; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | set_current_state(TASK_RUNNING); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Frees all resources, including threads, associated with the hafnium driver. |
| 128 | */ |
| 129 | static void hf_free_resources(long vm_count) |
| 130 | { |
| 131 | long i, j; |
| 132 | |
| 133 | /* |
| 134 | * First stop all worker threads. We need to do this before freeing |
| 135 | * resources because workers may reference each other, so it is only |
| 136 | * safe to free resources after they have all stopped. |
| 137 | */ |
| 138 | for (i = 0; i < vm_count; i++) { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 139 | struct hf_vm *vm = &hf_vms[i]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 140 | for (j = 0; j < vm->vcpu_count; j++) |
| 141 | kthread_stop(vm->vcpu[j].task); |
| 142 | } |
| 143 | |
| 144 | /* Free resources. */ |
| 145 | for (i = 0; i < vm_count; i++) { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 146 | struct hf_vm *vm = &hf_vms[i]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 147 | for (j = 0; j < vm->vcpu_count; j++) |
| 148 | put_task_struct(vm->vcpu[j].task); |
| 149 | kfree(vm->vcpu); |
| 150 | } |
| 151 | |
| 152 | kfree(hf_vms); |
| 153 | } |
| 154 | |
| 155 | static ssize_t hf_interrupt_store(struct kobject *kobj, |
| 156 | struct kobj_attribute *attr, const char *buf, |
| 157 | size_t count) |
| 158 | { |
| 159 | struct hf_vcpu *vcpu; |
| 160 | unsigned long flags; |
| 161 | struct task_struct *task; |
| 162 | |
| 163 | /* TODO: Parse input to determine which vcpu to interrupt. */ |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 164 | /* TODO: Check bounds. */ |
| 165 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 166 | vcpu = &hf_vms[0].vcpu[0]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 167 | |
| 168 | spin_lock_irqsave(&vcpu->lock, flags); |
| 169 | vcpu->pending_irq = true; |
| 170 | /* TODO: Do we need to increment the task's ref count here? */ |
| 171 | task = vcpu->task; |
| 172 | spin_unlock_irqrestore(&vcpu->lock, flags); |
| 173 | |
| 174 | /* Wake up the task. If it's already running, kick it out. */ |
| 175 | /* TODO: There's a race here: the kick may happen right before we go |
| 176 | * to the hypervisor. */ |
| 177 | if (wake_up_process(task) == 0) |
| 178 | kick_process(task); |
| 179 | |
| 180 | return count; |
| 181 | } |
| 182 | |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 183 | static ssize_t hf_send_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 184 | const char *buf, size_t count) |
| 185 | { |
| 186 | long ret; |
| 187 | struct hf_vm *vm; |
| 188 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 189 | count = min_t(size_t, count, HF_RPC_REQUEST_MAX_SIZE); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 190 | |
| 191 | /* Copy data to send buffer. */ |
| 192 | memcpy(page_address(hf_send_page), buf, count); |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 193 | |
| 194 | vm = &hf_vms[0]; |
| 195 | ret = hf_rpc_request(vm->id, count); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 196 | if (ret < 0) |
| 197 | return -EAGAIN; |
| 198 | |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 199 | if (ret > vm->vcpu_count) |
| 200 | return -EINVAL; |
| 201 | |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 202 | if (ret == vm->vcpu_count) { |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 203 | /* |
| 204 | * TODO: We need to interrupt some CPU because none is actually |
| 205 | * waiting for data. |
| 206 | */ |
| 207 | } else { |
| 208 | /* Wake up the vcpu that is going to process the data. */ |
| 209 | /* TODO: There's a race where thread may get wake up before it |
| 210 | * goes to sleep. Fix this. */ |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 211 | wake_up_process(vm->vcpu[ret].task); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | return count; |
| 215 | } |
| 216 | |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 217 | static struct kobject *hf_sysfs_obj = NULL; |
| 218 | static struct kobj_attribute interrupt_attr = |
| 219 | __ATTR(interrupt, 0200, NULL, hf_interrupt_store); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 220 | static struct kobj_attribute send_attr = |
| 221 | __ATTR(send, 0200, NULL, hf_send_store); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * Initializes the hafnium driver by creating a thread for each vCPU of each |
| 225 | * virtual machine. |
| 226 | */ |
| 227 | static int __init hf_init(void) |
| 228 | { |
| 229 | long ret; |
| 230 | long i, j; |
| 231 | |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 232 | /* Allocate a page for send and receive buffers. */ |
| 233 | hf_send_page = alloc_page(GFP_KERNEL); |
| 234 | if (!hf_send_page) { |
| 235 | pr_err("Unable to allocate send buffer\n"); |
| 236 | return -ENOMEM; |
| 237 | } |
| 238 | |
| 239 | hf_recv_page = alloc_page(GFP_KERNEL); |
| 240 | if (!hf_recv_page) { |
| 241 | __free_page(hf_send_page); |
| 242 | pr_err("Unable to allocate receive buffer\n"); |
| 243 | return -ENOMEM; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * Configure both addresses. Once configured, we cannot free these pages |
| 248 | * because the hypervisor will use them, even if the module is |
| 249 | * unloaded. |
| 250 | */ |
Andrew Scull | 5570423 | 2018-08-10 17:19:54 +0100 | [diff] [blame] | 251 | ret = hf_vm_configure(page_to_phys(hf_send_page), |
| 252 | page_to_phys(hf_recv_page)); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 253 | if (ret) { |
| 254 | __free_page(hf_send_page); |
| 255 | __free_page(hf_recv_page); |
| 256 | /* TODO: We may want to grab this information from hypervisor |
| 257 | * and go from there. */ |
| 258 | pr_err("Unable to configure VM\n"); |
| 259 | return -EIO; |
| 260 | } |
| 261 | |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 262 | /* Get the number of VMs and allocate storage for them. */ |
Andrew Scull | 5570423 | 2018-08-10 17:19:54 +0100 | [diff] [blame] | 263 | ret = hf_vm_get_count(); |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 264 | if (ret < 1) { |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 265 | pr_err("Unable to retrieve number of VMs: %ld\n", ret); |
| 266 | return ret; |
| 267 | } |
| 268 | |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 269 | /* Only track the secondary VMs. */ |
| 270 | hf_vm_count = ret - 1; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 271 | hf_vms = kmalloc(sizeof(struct hf_vm) * hf_vm_count, GFP_KERNEL); |
| 272 | if (!hf_vms) |
| 273 | return -ENOMEM; |
| 274 | |
| 275 | /* Initialize each VM. */ |
| 276 | for (i = 0; i < hf_vm_count; i++) { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 277 | struct hf_vm *vm = &hf_vms[i]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 278 | |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 279 | /* Adjust the ID as only the secondaries are tracked. */ |
| 280 | vm->id = i + 1; |
| 281 | |
| 282 | ret = hf_vcpu_get_count(vm->id); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 283 | if (ret < 0) { |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 284 | pr_err("HF_VCPU_GET_COUNT failed for vm=%d: %ld", vm->id, |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 285 | ret); |
| 286 | hf_free_resources(i); |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | vm->vcpu_count = ret; |
| 291 | vm->vcpu = kmalloc(sizeof(struct hf_vcpu) * vm->vcpu_count, |
| 292 | GFP_KERNEL); |
| 293 | if (!vm->vcpu) { |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 294 | pr_err("No memory for %ld vcpus for vm %d", |
| 295 | vm->vcpu_count, vm->id); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 296 | hf_free_resources(i); |
| 297 | return -ENOMEM; |
| 298 | } |
| 299 | |
| 300 | /* Create a kernel thread for each vcpu. */ |
| 301 | for (j = 0; j < vm->vcpu_count; j++) { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 302 | struct hf_vcpu *vcpu = &vm->vcpu[j]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 303 | vcpu->task = kthread_create(hf_vcpu_thread, vcpu, |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 304 | "vcpu_thread_%d_%ld", |
| 305 | vm->id, j); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 306 | if (IS_ERR(vcpu->task)) { |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 307 | pr_err("Error creating task (vm=%d,vcpu=%ld)" |
| 308 | ": %ld\n", vm->id, j, PTR_ERR(vcpu->task)); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 309 | vm->vcpu_count = j; |
| 310 | hf_free_resources(i + 1); |
| 311 | return PTR_ERR(vcpu->task); |
| 312 | } |
| 313 | |
| 314 | get_task_struct(vcpu->task); |
| 315 | spin_lock_init(&vcpu->lock); |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 316 | vcpu->vm = vm; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 317 | vcpu->vcpu_index = j; |
| 318 | vcpu->pending_irq = false; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /* Start running threads now that all is initialized. */ |
| 323 | for (i = 0; i < hf_vm_count; i++) { |
Andrew Scull | b3a61b5 | 2018-09-17 14:30:34 +0100 | [diff] [blame] | 324 | struct hf_vm *vm = &hf_vms[i]; |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 325 | for (j = 0; j < vm->vcpu_count; j++) |
| 326 | wake_up_process(vm->vcpu[j].task); |
| 327 | } |
| 328 | |
| 329 | /* Dump vm/vcpu count info. */ |
| 330 | pr_info("Hafnium successfully loaded with %ld VMs:\n", hf_vm_count); |
Andrew Scull | b722f95 | 2018-09-27 15:39:10 +0100 | [diff] [blame^] | 331 | for (i = 0; i < hf_vm_count; i++) { |
| 332 | struct hf_vm *vm = &hf_vms[i]; |
| 333 | pr_info("\tVM %d: %ld vCPUS\n", vm->id, vm->vcpu_count); |
| 334 | } |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 335 | |
| 336 | /* Create the sysfs interface to interrupt vcpus. */ |
| 337 | hf_sysfs_obj = kobject_create_and_add("hafnium", kernel_kobj); |
| 338 | if (!hf_sysfs_obj) { |
| 339 | pr_err("Unable to create sysfs object"); |
| 340 | } else { |
| 341 | ret = sysfs_create_file(hf_sysfs_obj, &interrupt_attr.attr); |
| 342 | if (ret) |
| 343 | pr_err("Unable to create 'interrupt' sysfs file"); |
Wedson Almeida Filho | f9e1192 | 2018-08-12 15:54:31 +0100 | [diff] [blame] | 344 | |
| 345 | ret = sysfs_create_file(hf_sysfs_obj, &send_attr.attr); |
| 346 | if (ret) |
| 347 | pr_err("Unable to create 'send' sysfs file"); |
Wedson Almeida Filho | 2f62b42 | 2018-06-19 06:44:32 +0100 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Frees up all resources used by the hafnium driver in preparation for |
| 355 | * unloading it. |
| 356 | */ |
| 357 | static void __exit hf_exit(void) |
| 358 | { |
| 359 | if (hf_sysfs_obj) |
| 360 | kobject_put(hf_sysfs_obj); |
| 361 | |
| 362 | pr_info("Preparing to unload hafnium\n"); |
| 363 | hf_free_resources(hf_vm_count); |
| 364 | pr_info("Hafnium ready to unload\n"); |
| 365 | } |
| 366 | |
| 367 | MODULE_LICENSE("GPL"); |
| 368 | |
| 369 | module_init(hf_init); |
| 370 | module_exit(hf_exit); |