[PATCH v2] drm/i915/gvt: Use KVM r/w to access guest opregion
Zhang, Xiong Y
xiong.y.zhang at intel.com
Mon Jan 29 01:39:49 UTC 2018
> int intel_vgpu_emulate_opregion_request(struct intel_vgpu *vgpu, u32
> swsci) {
> - u32 *scic, *parm;
> + u32 scic, parm;
> u32 func, subfunc;
> + u64 scic_pa = 0, parm_pa = 0;
> + int ret;
>
> switch (intel_gvt_host.hypervisor_type) {
> case INTEL_GVT_HYPERVISOR_XEN:
> - scic = vgpu_opregion(vgpu)->va + INTEL_GVT_OPREGION_SCIC;
> - parm = vgpu_opregion(vgpu)->va + INTEL_GVT_OPREGION_PARM;
> + scic = *((u32 *)vgpu_opregion(vgpu)->va +
> + INTEL_GVT_OPREGION_SCIC);
> + parm = *((u32 *)vgpu_opregion(vgpu)->va +
> + INTEL_GVT_OPREGION_PARM);
> break;
> case INTEL_GVT_HYPERVISOR_KVM:
> - scic = vgpu_opregion(vgpu)->va_gopregion +
> - INTEL_GVT_OPREGION_SCIC;
> - parm = vgpu_opregion(vgpu)->va_gopregion +
> - INTEL_GVT_OPREGION_PARM;
> + scic_pa = (vgpu_opregion(vgpu)->gfn[0] << PAGE_SHIFT) +
> + INTEL_GVT_OPREGION_SCIC;
> + parm_pa = (vgpu_opregion(vgpu)->gfn[0] << PAGE_SHIFT) +
> + INTEL_GVT_OPREGION_PARM;
> +
> + ret = intel_gvt_hypervisor_read_gpa(vgpu, scic_pa,
> + &scic, sizeof(scic));
> + if (ret) {
> + gvt_vgpu_err("guest opregion read error %d, gpa 0x%llx,
> len %lu\n",
> + ret, scic_pa, sizeof(scic));
> + return ret;
> + }
> +
> + ret = intel_gvt_hypervisor_read_gpa(vgpu, parm_pa,
> + &parm, sizeof(parm));
> + if (ret) {
> + gvt_vgpu_err("guest opregion read error %d, gpa 0x%llx,
> len %lu\n",
> + ret, scic_pa, sizeof(scic));
> + return ret;
> + }
> +
> break;
> default:
> gvt_vgpu_err("not supported hypervisor\n"); @@ -510,9 +521,9
> @@ int intel_vgpu_emulate_opregion_request(struct intel_vgpu *vgpu, u32
> swsci)
> return 0;
> }
>
> - func = GVT_OPREGION_FUNC(*scic);
> - subfunc = GVT_OPREGION_SUBFUNC(*scic);
> - if (!querying_capabilities(*scic)) {
> + func = GVT_OPREGION_FUNC(scic);
> + subfunc = GVT_OPREGION_SUBFUNC(scic);
> + if (!querying_capabilities(scic)) {
> gvt_vgpu_err("requesting runtime service: func \"%s\","
> " subfunc \"%s\"\n",
> opregion_func_name(func),
> @@ -521,11 +532,43 @@ int intel_vgpu_emulate_opregion_request(struct
> intel_vgpu *vgpu, u32 swsci)
> * emulate exit status of function call, '0' means
> * "failure, generic, unsupported or unknown cause"
> */
> - *scic &= ~OPREGION_SCIC_EXIT_MASK;
> - return 0;
> + scic &= ~OPREGION_SCIC_EXIT_MASK;
> + goto out;
> + }
> +
> + scic = 0;
> + parm = 0;
> +
> +out:
> + switch (intel_gvt_host.hypervisor_type) {
> + case INTEL_GVT_HYPERVISOR_XEN:
> + *((u32 *)vgpu_opregion(vgpu)->va +
> + INTEL_GVT_OPREGION_SCIC) = scic;
> + *((u32 *)vgpu_opregion(vgpu)->va +
> + INTEL_GVT_OPREGION_PARM) = parm;
> + break;
> + case INTEL_GVT_HYPERVISOR_KVM:
> + ret = intel_gvt_hypervisor_write_gpa(vgpu, scic_pa,
> + &scic, sizeof(scic));
> + if (ret) {
> + gvt_vgpu_err("guest opregion write error %d, gpa 0x%llx,
> len %lu\n",
> + ret, scic_pa, sizeof(scic));
> + return ret;
> + }
> +
> + ret = intel_gvt_hypervisor_write_gpa(vgpu, parm_pa,
> + &parm, sizeof(parm));
> + if (ret) {
> + gvt_vgpu_err("guest opregion write error %d, gpa 0x%llx,
> len %lu\n",
> + ret, scic_pa, sizeof(scic));
> + return ret;
> + }
> +
> + break;
> + default:
> + gvt_vgpu_err("not supported hypervisor\n");
> + return -EINVAL;
> }
[Zhang, Xiong Y] Good idea to use intel_gvt_hypervisor_write/read_gpa, since it is a mpt function. XenGT could use it also, we don't need to diff XenGT and KvmGT in this function.
>
> - *scic = 0;
> - *parm = 0;
> return 0;
> }
> --
> 2.7.4
More information about the intel-gvt-dev
mailing list