HV: Use parameter directly to pass bdf for hcall_assign/deassign_ptdev

The the bdf(bus/dev/func) is used to determine which pass-through device should
be assigned/released. Now the hypervisor parses the corresponding bdf from the guest
physical address when hcall_assign_ptdev/hcall_deassign_ptdev is called.
As it is only uint16_t, it is unnecessary to use the GPA to pass the bdf parameter.
Instead the parameter can be used as the bdf directly.

In order to keep the compatibility, it still can get the bdf by using
copy_from_gpa when SOS passes the parameter based on the buffer. But this will
be depreciated.
This is based on the assumption that the GPA in SOS is greater than 0x10000
when one buffer is allocated to pass the corresponding hypercall parameter.
After the SOS uses the bdf to pass the hypercall paremeter, we can remove the code
that gets the bdf by using copy_from_gpa.

V1->V2: Add some comments for hcall_assign_ptdev/hcall_deassign_ptdev.

Tracked-on: #1751
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Zhao Yakui 2018-11-07 14:17:01 +08:00 committed by lijinxia
parent 605738fc0c
commit 3cbaf02830
2 changed files with 26 additions and 14 deletions

View File

@ -737,8 +737,9 @@ int32_t hcall_gpa_to_hpa(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* physical BDF of the assigning ptdev
* @param param the physical BDF of the assigning ptdev
* For the compatibility it still can be the guest physical address that
* points to the physical BDF of the assigning ptdev.(Depreciated)
*
* @pre Pointer vm shall point to VM0
* @return 0 on success, non-zero on error.
@ -754,10 +755,14 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
return -EINVAL;
}
if (copy_from_gpa(vm, &bdf, param, sizeof(bdf)) != 0) {
pr_err("%s: Unable copy param from vm %d\n",
if (param < 0x10000UL) {
bdf = (uint16_t) param;
} else {
if (copy_from_gpa(vm, &bdf, param, sizeof(bdf)) != 0) {
pr_err("%s: Unable copy param from vm %d\n",
__func__, vm->vm_id);
return -EIO;
return -EIO;
}
}
/* create a iommu domain for target VM if not created */
@ -786,8 +791,9 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* physical BDF of the deassigning ptdev
* @param param the physical BDF of the deassigning ptdev
* To keep the compatibility it still can be the guest physical address that
* points to the physical BDF of the deassigning ptdev.(Depreciated)
*
* @pre Pointer vm shall point to VM0
* @return 0 on success, non-zero on error.
@ -802,9 +808,13 @@ int32_t hcall_deassign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
return -1;
}
if (copy_from_gpa(vm, &bdf, param, sizeof(bdf)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
if (param < 0x10000UL) {
bdf = (uint16_t) param;
} else {
if (copy_from_gpa(vm, &bdf, param, sizeof(bdf)) != 0) {
pr_err("%s: Unable copy param to vm\n", __func__);
return -1;
}
}
ret = unassign_iommu_device(target_vm->iommu,
(uint8_t)(bdf >> 8U), (uint8_t)(bdf & 0xffU));

View File

@ -257,8 +257,9 @@ int32_t hcall_gpa_to_hpa(struct acrn_vm *vm, uint16_t vmid, uint64_t param);
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* physical BDF of the assigning ptdev
* @param param the physical BDF of the assigning ptdev
* To keep the compatibility it still can be the guest physical address that
* points to the physical BDF of the assigning ptdev.(Depreciated)
*
* @pre Pointer vm shall point to VM0
* @return 0 on success, non-zero on error.
@ -270,8 +271,9 @@ int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param);
*
* @param vm Pointer to VM data structure
* @param vmid ID of the VM
* @param param guest physical address. This gpa points to
* physical BDF of the deassigning ptdev
* @param param the physical BDF of the deassigning ptdev
* To keep the compatibility it still can be the guest physical address that
* points to the physical BDF of the deassigning ptdev.(Depreciated)
*
* @pre Pointer vm shall point to VM0
* @return 0 on success, non-zero on error.