Commit e3d7640e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Zhi Wang
Browse files

drm/i915/gvt: devirtualize ->{read,write}_gpa



Just call the VFIO functions directly instead of through the method
table.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarZhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-14-hch@lst.de


Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarZhi Wang <zhi.a.wang@intel.com>
parent 3c340d05
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1011,7 +1011,7 @@ static int cmd_reg_handler(struct parser_exec_state *s,
	if (GRAPHICS_VER(s->engine->i915) == 9 &&
	    intel_gvt_mmio_is_sr_in_ctx(gvt, offset) &&
	    !strncmp(cmd, "lri", 3)) {
		intel_gvt_hypervisor_read_gpa(s->vgpu,
		intel_gvt_read_gpa(s->vgpu,
			s->workload->ring_context_gpa + 12, &ctx_sr_ctl, 4);
		/* check inhibit context */
		if (ctx_sr_ctl & 1) {
@@ -1775,7 +1775,7 @@ static int copy_gma_to_hva(struct intel_vgpu *vgpu, struct intel_vgpu_mm *mm,
		copy_len = (end_gma - gma) >= (I915_GTT_PAGE_SIZE - offset) ?
			I915_GTT_PAGE_SIZE - offset : end_gma - gma;

		intel_gvt_hypervisor_read_gpa(vgpu, gpa, va + len, copy_len);
		intel_gvt_read_gpa(vgpu, gpa, va + len, copy_len);

		len += copy_len;
		gma += copy_len;
+6 −6
Original line number Diff line number Diff line
@@ -159,10 +159,10 @@ static void emulate_csb_update(struct intel_vgpu_execlist *execlist,
	hwsp_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm,
					 vgpu->hws_pga[execlist->engine->id]);
	if (hwsp_gpa != INTEL_GVT_INVALID_ADDR) {
		intel_gvt_hypervisor_write_gpa(vgpu,
		intel_gvt_write_gpa(vgpu,
			hwsp_gpa + I915_HWS_CSB_BUF0_INDEX * 4 + write_pointer * 8,
			status, 8);
		intel_gvt_hypervisor_write_gpa(vgpu,
		intel_gvt_write_gpa(vgpu,
			hwsp_gpa + INTEL_HWS_CSB_WRITE_INDEX(execlist->engine->i915) * 4,
			&write_pointer, 4);
	}
+3 −3
Original line number Diff line number Diff line
@@ -314,7 +314,7 @@ static inline int gtt_get_entry64(void *pt,
		return -EINVAL;

	if (hypervisor_access) {
		ret = intel_gvt_hypervisor_read_gpa(vgpu, gpa +
		ret = intel_gvt_read_gpa(vgpu, gpa +
				(index << info->gtt_entry_size_shift),
				&e->val64, 8);
		if (WARN_ON(ret))
@@ -339,7 +339,7 @@ static inline int gtt_set_entry64(void *pt,
		return -EINVAL;

	if (hypervisor_access) {
		ret = intel_gvt_hypervisor_write_gpa(vgpu, gpa +
		ret = intel_gvt_write_gpa(vgpu, gpa +
				(index << info->gtt_entry_size_shift),
				&e->val64, 8);
		if (WARN_ON(ret))
@@ -1497,7 +1497,7 @@ static int attach_oos_page(struct intel_vgpu_oos_page *oos_page,
	struct intel_gvt *gvt = spt->vgpu->gvt;
	int ret;

	ret = intel_gvt_hypervisor_read_gpa(spt->vgpu,
	ret = intel_gvt_read_gpa(spt->vgpu,
			spt->guest_page.gfn << I915_GTT_PAGE_SHIFT,
			oos_page->mem, I915_GTT_PAGE_SIZE);
	if (ret)
+37 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@

#include <uapi/linux/pci_regs.h>
#include <linux/kvm_host.h>
#include <linux/vfio.h>

#include "i915_drv.h"
#include "intel_gvt.h"
@@ -720,6 +721,42 @@ static inline bool intel_gvt_mmio_is_cmd_write_patch(
	return gvt->mmio.mmio_attribute[offset >> 2] & F_CMD_WRITE_PATCH;
}

/**
 * intel_gvt_read_gpa - copy data from GPA to host data buffer
 * @vgpu: a vGPU
 * @gpa: guest physical address
 * @buf: host data buffer
 * @len: data length
 *
 * Returns:
 * Zero on success, negative error code if failed.
 */
static inline int intel_gvt_read_gpa(struct intel_vgpu *vgpu, unsigned long gpa,
		void *buf, unsigned long len)
{
	if (!vgpu->attached)
		return -ESRCH;
	return vfio_dma_rw(vgpu->vfio_group, gpa, buf, len, false);
}

/**
 * intel_gvt_write_gpa - copy data from host data buffer to GPA
 * @vgpu: a vGPU
 * @gpa: guest physical address
 * @buf: host data buffer
 * @len: data length
 *
 * Returns:
 * Zero on success, negative error code if failed.
 */
static inline int intel_gvt_write_gpa(struct intel_vgpu *vgpu,
		unsigned long gpa, void *buf, unsigned long len)
{
	if (!vgpu->attached)
		return -ESRCH;
	return vfio_dma_rw(vgpu->vfio_group, gpa, buf, len, true);
}

void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu);
void intel_gvt_debugfs_init(struct intel_gvt *gvt);
void intel_gvt_debugfs_clean(struct intel_gvt *gvt);
+0 −4
Original line number Diff line number Diff line
@@ -49,10 +49,6 @@ struct intel_gvt_mpt {
	int (*inject_msi)(struct intel_vgpu *vgpu, u32 addr, u16 data);
	int (*enable_page_track)(struct intel_vgpu *vgpu, u64 gfn);
	int (*disable_page_track)(struct intel_vgpu *vgpu, u64 gfn);
	int (*read_gpa)(struct intel_vgpu *vgpu, unsigned long gpa, void *buf,
			unsigned long len);
	int (*write_gpa)(struct intel_vgpu *vgpu, unsigned long gpa, void *buf,
			 unsigned long len);
	unsigned long (*gfn_to_mfn)(struct intel_vgpu *vgpu, unsigned long gfn);

	int (*dma_map_guest_page)(struct intel_vgpu *vgpu, unsigned long gfn,
Loading