Skip to content

Commit

Permalink
Support bo protection attribute virtualization
Browse files Browse the repository at this point in the history
guest i915 side pass protection attribute to virtio-gpu fe through dmabuf,
virtio-gpu fe pass it to virtio-gpu be, vrtio-gpu be call i915 ioctl to
set bo protection.

Tracked-On: OAM-121827
Signed-off-by: Xue Bosheng <[email protected]>
  • Loading branch information
bosheng1 committed Aug 14, 2024
1 parent a3b77f7 commit a8523cd
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 4 deletions.
3 changes: 1 addition & 2 deletions drivers/gpu/drm/i915/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ i915-$(CONFIG_DRM_I915_PXP) += \
virtio-pxp-y += \
pxp/virt/virtio_pxp.o

obj-m += virtio-pxp.o

# Post-mortem debug and GPU hang state capture
i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
i915-$(CONFIG_DRM_I915_SELFTEST) += \
Expand All @@ -405,6 +403,7 @@ include $(src)/gvt/Makefile

obj-$(CONFIG_DRM_I915) += i915.o
obj-$(CONFIG_DRM_I915_GVT_KVMGT) += kvmgt.o
obj-$(CONFIG_DRM_I915) += virtio-pxp.o

# kernel-doc test
#
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ struct dma_buf *i915_gem_prime_export(struct drm_gem_object *gem_obj, int flags)
{
struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
if (i915_gem_object_is_protected(obj))
gem_obj->protected = true;

exp_info.ops = &i915_dmabuf_ops;
exp_info.size = gem_obj->size;
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/i915_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@ static const struct drm_ioctl_desc i915_ioctls[] = {
DRM_IOCTL_DEF_DRV(I915_QUERY, i915_query_ioctl, DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(I915_GEM_VM_CREATE, i915_gem_vm_create_ioctl, DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(I915_GEM_VM_DESTROY, i915_gem_vm_destroy_ioctl, DRM_RENDER_ALLOW),
PRELIM_DRM_IOCTL_DEF_DRV(I915_PXP_BO_OPS, i915_pxp_bo_ops_ioctl, DRM_RENDER_ALLOW),
PRELIM_DRM_IOCTL_DEF_DRV(I915_PXP_OPS, i915_pxp_ops_ioctl, DRM_RENDER_ALLOW),
};

Expand Down
19 changes: 19 additions & 0 deletions drivers/gpu/drm/i915/pxp/intel_pxp.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,20 @@ static bool pxp_action_needs_arb_session(u32 action)

return true;
}
int i915_pxp_bo_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile)
{
int ret = 0;
struct prelim_drm_i915_pxp_bo_ops *pxp_bo_ops = data;
struct drm_i915_private *i915 = to_i915(dev);
struct drm_i915_gem_object *obj;
if (!intel_pxp_is_enabled(i915->pxp))
return -ENODEV;

obj = i915_gem_object_lookup_rcu(drmfile, pxp_bo_ops->handle);
obj->flags |= I915_BO_PROTECTED;
intel_pxp_key_check(i915->pxp, obj, pxp_bo_ops->assign);
return 0;
}

int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile)
{
Expand Down Expand Up @@ -957,6 +971,11 @@ void intel_pxp_close(struct intel_pxp *pxp, struct drm_file *drmfile)
{
}

int i915_pxp_bo_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile)
{
return -ENODEV;
}

int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile)
{
return -ENODEV;
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/pxp/intel_pxp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ int intel_pxp_key_check(struct intel_pxp *pxp,

void intel_pxp_invalidate(struct intel_pxp *pxp);
int i915_pxp_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile);
int i915_pxp_bo_ops_ioctl(struct drm_device *dev, void *data, struct drm_file *drmfile);
void intel_pxp_close(struct intel_pxp *pxp, struct drm_file *drmfile);

#endif /* __INTEL_PXP_H__ */
2 changes: 2 additions & 0 deletions drivers/gpu/drm/virtio/virtgpu_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct virtio_gpu_object_params {
uint32_t blob_mem;
uint32_t blob_flags;
uint64_t blob_id;
bool protected;
};

struct virtio_gpu_object {
Expand All @@ -95,6 +96,7 @@ struct virtio_gpu_object {

int uuid_state;
uuid_t uuid;
bool protected;
};
#define gem_to_virtio_gpu_obj(gobj) \
container_of((gobj), struct virtio_gpu_object, base.base)
Expand Down
11 changes: 9 additions & 2 deletions drivers/gpu/drm/virtio/virtgpu_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table(
struct virtio_gpu_object_params params = { 0 };
struct virtio_gpu_object *bo;
struct drm_gem_object *obj;
struct drm_gem_object *i915_obj;
struct virtio_gpu_mem_entry *ents;
unsigned int nents;
struct dma_buf *dmabuf;
int ret;

if (!vgdev->has_resource_blob || vgdev->has_virgl_3d) {
Expand All @@ -234,13 +236,18 @@ struct drm_gem_object *virtgpu_gem_prime_import_sg_table(
if (ret != 0) {
goto err_put_id;
}

dmabuf = attach->dmabuf;
if (dmabuf && strcmp(module_name(dmabuf->owner), "i915") == 0) {
dmabuf = attach->dmabuf;
i915_obj = dmabuf->priv;
bo->protected = i915_obj->protected;
}
bo->guest_blob = true;
params.blob_mem = VIRTGPU_BLOB_MEM_GUEST;
params.blob_flags = VIRTGPU_BLOB_FLAG_USE_SHAREABLE;
params.blob = true;
params.size = size;

params.protected = bo->protected;
virtio_gpu_cmd_resource_create_blob(vgdev, bo, &params,
ents, nents);
virtio_gpu_object_save_restore_list(vgdev, bo, &params);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/virtio/virtgpu_vq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@ virtio_gpu_cmd_resource_create_blob(struct virtio_gpu_device *vgdev,
cmd_p->blob_id = cpu_to_le64(params->blob_id);
cmd_p->size = cpu_to_le64(params->size);
cmd_p->nr_entries = cpu_to_le32(nents);
cmd_p->protected = cpu_to_le64(params->protected);

vbuf->data_buf = ents;
vbuf->data_size = sizeof(*ents) * nents;
Expand Down
6 changes: 6 additions & 0 deletions include/drm/drm_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ struct drm_gem_object {
* The current LRU list that the GEM object is on.
*/
struct drm_gem_lru *lru;
/**
* @protected:
*
* gem bo attribute.
*/
bool protected;
};

/**
Expand Down
11 changes: 11 additions & 0 deletions include/uapi/drm/i915_drm_prelim.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#define PRELIM_DRM_IOCTL_I915_PXP_OPS DRM_IOWR(DRM_COMMAND_BASE + PRELIM_DRM_I915_PXP_OPS, \
struct prelim_drm_i915_pxp_ops)

#define PRELIM_DRM_I915_PXP_BO_OPS 0x53

#define PRELIM_DRM_IOCTL_I915_PXP_BO_OPS DRM_IOWR(DRM_COMMAND_BASE + PRELIM_DRM_I915_PXP_BO_OPS, \
struct prelim_drm_i915_pxp_bo_ops)

/* End PRELIM ioctl's */

/*
Expand Down Expand Up @@ -145,5 +150,11 @@ struct prelim_drm_i915_pxp_ops {
__u64 params; /* in/out - pointer to data matching the action */
} __attribute__((packed));

struct prelim_drm_i915_pxp_bo_ops {
__u32 handle;
__u32 assign;
} __attribute__((packed));


#endif /* __I915_DRM_PRELIM_H__ */

1 change: 1 addition & 0 deletions include/uapi/linux/virtio_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ struct virtio_gpu_resource_create_blob {
__le32 nr_entries;
__le64 blob_id;
__le64 size;
__le64 protected;
/*
* sizeof(nr_entries * virtio_gpu_mem_entry) bytes follow
*/
Expand Down

0 comments on commit a8523cd

Please sign in to comment.