| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Description: |
|---|
| 7 | 8 | * This file is derived from arch/powerpc/kvm/44x.c, |
|---|
| 8 | 9 | * by Hollis Blanchard <hollisb@us.ibm.com>. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License, version 2, as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/kvm_host.h> |
|---|
| .. | .. |
|---|
| 436 | 433 | return r; |
|---|
| 437 | 434 | } |
|---|
| 438 | 435 | |
|---|
| 439 | | -static struct kvm_vcpu *kvmppc_core_vcpu_create_e500(struct kvm *kvm, |
|---|
| 440 | | - unsigned int id) |
|---|
| 436 | +static int kvmppc_core_vcpu_create_e500(struct kvm_vcpu *vcpu) |
|---|
| 441 | 437 | { |
|---|
| 442 | 438 | struct kvmppc_vcpu_e500 *vcpu_e500; |
|---|
| 443 | | - struct kvm_vcpu *vcpu; |
|---|
| 444 | 439 | int err; |
|---|
| 445 | 440 | |
|---|
| 446 | | - vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); |
|---|
| 447 | | - if (!vcpu_e500) { |
|---|
| 448 | | - err = -ENOMEM; |
|---|
| 449 | | - goto out; |
|---|
| 450 | | - } |
|---|
| 441 | + BUILD_BUG_ON(offsetof(struct kvmppc_vcpu_e500, vcpu) != 0); |
|---|
| 442 | + vcpu_e500 = to_e500(vcpu); |
|---|
| 451 | 443 | |
|---|
| 452 | | - vcpu = &vcpu_e500->vcpu; |
|---|
| 453 | | - err = kvm_vcpu_init(vcpu, kvm, id); |
|---|
| 454 | | - if (err) |
|---|
| 455 | | - goto free_vcpu; |
|---|
| 456 | | - |
|---|
| 457 | | - if (kvmppc_e500_id_table_alloc(vcpu_e500) == NULL) { |
|---|
| 458 | | - err = -ENOMEM; |
|---|
| 459 | | - goto uninit_vcpu; |
|---|
| 460 | | - } |
|---|
| 444 | + if (kvmppc_e500_id_table_alloc(vcpu_e500) == NULL) |
|---|
| 445 | + return -ENOMEM; |
|---|
| 461 | 446 | |
|---|
| 462 | 447 | err = kvmppc_e500_tlb_init(vcpu_e500); |
|---|
| 463 | 448 | if (err) |
|---|
| .. | .. |
|---|
| 469 | 454 | goto uninit_tlb; |
|---|
| 470 | 455 | } |
|---|
| 471 | 456 | |
|---|
| 472 | | - return vcpu; |
|---|
| 457 | + return 0; |
|---|
| 473 | 458 | |
|---|
| 474 | 459 | uninit_tlb: |
|---|
| 475 | 460 | kvmppc_e500_tlb_uninit(vcpu_e500); |
|---|
| 476 | 461 | uninit_id: |
|---|
| 477 | 462 | kvmppc_e500_id_table_free(vcpu_e500); |
|---|
| 478 | | -uninit_vcpu: |
|---|
| 479 | | - kvm_vcpu_uninit(vcpu); |
|---|
| 480 | | -free_vcpu: |
|---|
| 481 | | - kmem_cache_free(kvm_vcpu_cache, vcpu_e500); |
|---|
| 482 | | -out: |
|---|
| 483 | | - return ERR_PTR(err); |
|---|
| 463 | + return err; |
|---|
| 484 | 464 | } |
|---|
| 485 | 465 | |
|---|
| 486 | 466 | static void kvmppc_core_vcpu_free_e500(struct kvm_vcpu *vcpu) |
|---|
| .. | .. |
|---|
| 490 | 470 | free_page((unsigned long)vcpu->arch.shared); |
|---|
| 491 | 471 | kvmppc_e500_tlb_uninit(vcpu_e500); |
|---|
| 492 | 472 | kvmppc_e500_id_table_free(vcpu_e500); |
|---|
| 493 | | - kvm_vcpu_uninit(vcpu); |
|---|
| 494 | | - kmem_cache_free(kvm_vcpu_cache, vcpu_e500); |
|---|
| 495 | 473 | } |
|---|
| 496 | 474 | |
|---|
| 497 | 475 | static int kvmppc_core_init_vm_e500(struct kvm *kvm) |
|---|
| .. | .. |
|---|
| 512 | 490 | .vcpu_put = kvmppc_core_vcpu_put_e500, |
|---|
| 513 | 491 | .vcpu_create = kvmppc_core_vcpu_create_e500, |
|---|
| 514 | 492 | .vcpu_free = kvmppc_core_vcpu_free_e500, |
|---|
| 515 | | - .mmu_destroy = kvmppc_mmu_destroy_e500, |
|---|
| 516 | 493 | .init_vm = kvmppc_core_init_vm_e500, |
|---|
| 517 | 494 | .destroy_vm = kvmppc_core_destroy_vm_e500, |
|---|
| 518 | 495 | .emulate_op = kvmppc_core_emulate_op_e500, |
|---|