[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250529053513.1592088-12-yilun.xu@linux.intel.com>
Date: Thu, 29 May 2025 13:34:54 +0800
From: Xu Yilun <yilun.xu@...ux.intel.com>
To: kvm@...r.kernel.org,
sumit.semwal@...aro.org,
christian.koenig@....com,
pbonzini@...hat.com,
seanjc@...gle.com,
alex.williamson@...hat.com,
jgg@...dia.com,
dan.j.williams@...el.com,
aik@....com,
linux-coco@...ts.linux.dev
Cc: dri-devel@...ts.freedesktop.org,
linux-media@...r.kernel.org,
linaro-mm-sig@...ts.linaro.org,
vivek.kasireddy@...el.com,
yilun.xu@...el.com,
yilun.xu@...ux.intel.com,
linux-kernel@...r.kernel.org,
lukas@...ner.de,
yan.y.zhao@...el.com,
daniel.vetter@...ll.ch,
leon@...nel.org,
baolu.lu@...ux.intel.com,
zhenzhong.duan@...el.com,
tao1.su@...el.com,
linux-pci@...r.kernel.org,
zhiw@...dia.com,
simona.vetter@...ll.ch,
shameerali.kolothum.thodi@...wei.com,
aneesh.kumar@...nel.org,
iommu@...ts.linux.dev,
kevin.tian@...el.com
Subject: [RFC PATCH 11/30] KVM: vfio_dmabuf: Fetch VFIO specific dma-buf data for sanity check
Fetch VFIO specific dma-buf data to see if the dma-buf is eligible to
be assigned to CoCo VM as private MMIO.
KVM expects host unaccessible MMIO regions been mapped in private
roots. So need to identify VFIO dma-buf by successfully getting VFIO
specific dma-buf data. VFIO dma-buf also provides the struct kvm *kvm
handler for KVM to check if the owner device of the MMIO region is
already assigned to the same CoCo VM.
Signed-off-by: Xu Yilun <yilun.xu@...ux.intel.com>
---
virt/kvm/vfio_dmabuf.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/virt/kvm/vfio_dmabuf.c b/virt/kvm/vfio_dmabuf.c
index c427ab39c68a..ef695039402f 100644
--- a/virt/kvm/vfio_dmabuf.c
+++ b/virt/kvm/vfio_dmabuf.c
@@ -12,6 +12,22 @@ struct kvm_vfio_dmabuf {
struct kvm_memory_slot *slot;
};
+static struct vfio_dma_buf_data *kvm_vfio_dma_buf_get_data(struct dma_buf *dmabuf)
+{
+ struct vfio_dma_buf_data *(*fn)(struct dma_buf *dmabuf);
+ struct vfio_dma_buf_data *ret;
+
+ fn = symbol_get(vfio_dma_buf_get_data);
+ if (!fn)
+ return ERR_PTR(-ENOENT);
+
+ ret = fn(dmabuf);
+
+ symbol_put(vfio_dma_buf_get_data);
+
+ return ret;
+}
+
static void kv_dmabuf_move_notify(struct dma_buf_attachment *attach)
{
struct kvm_vfio_dmabuf *kv_dmabuf = attach->importer_priv;
@@ -48,6 +64,7 @@ int kvm_vfio_dmabuf_bind(struct kvm *kvm, struct kvm_memory_slot *slot,
size_t size = slot->npages << PAGE_SHIFT;
struct dma_buf_attachment *attach;
struct kvm_vfio_dmabuf *kv_dmabuf;
+ struct vfio_dma_buf_data *data;
struct dma_buf *dmabuf;
int ret;
@@ -60,6 +77,15 @@ int kvm_vfio_dmabuf_bind(struct kvm *kvm, struct kvm_memory_slot *slot,
goto err_dmabuf;
}
+ data = kvm_vfio_dma_buf_get_data(dmabuf);
+ if (IS_ERR(data))
+ goto err_dmabuf;
+
+ if (data->kvm != kvm) {
+ ret = -EINVAL;
+ goto err_dmabuf;
+ }
+
kv_dmabuf = kzalloc(sizeof(*kv_dmabuf), GFP_KERNEL);
if (!kv_dmabuf) {
ret = -ENOMEM;
--
2.25.1
Powered by blists - more mailing lists