From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: linuxppc-dev@lists.ozlabs.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
Paul Mackerras <paulus@samba.org>,
Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH v1 11/13] KVM: PPC: Associate IOMMU group with guest copy of TCE table
Date: Tue, 15 Jul 2014 19:25:31 +1000 [thread overview]
Message-ID: <1405416333-12477-12-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1405416333-12477-1-git-send-email-aik@ozlabs.ru>
The existing in-kernel TCE table for emulated devices contains
guest physical addresses which are accesses by emulated devices.
Since we need to keep this information for VFIO devices too
in order to implement H_GET_TCE, we are reusing it.
This adds iommu_group* and iommu_table* pointers to kvmppc_spapr_tce_table.
This adds kvm_spapr_tce_attach_iommu_group() helper to initialize
the pointers.
This puts the group when guest copy of TCE table is destroyed which
happens when TCE table fd is closed.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
arch/powerpc/include/asm/kvm_host.h | 2 ++
arch/powerpc/include/asm/kvm_ppc.h | 5 +++++
arch/powerpc/kvm/book3s_64_vio.c | 28 ++++++++++++++++++++++++++++
3 files changed, 35 insertions(+)
diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 8a3b465..8d8eee9 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -184,6 +184,8 @@ struct kvmppc_spapr_tce_table {
u32 page_shift;
u64 offset; /* in pages */
u64 size; /* in pages */
+ struct iommu_table *tbl;
+ struct iommu_group *refgrp;/* reference counting only */
struct page *pages[0];
};
diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 86f5015..92be7f5 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -129,6 +129,11 @@ extern int kvmppc_spapr_tce_init(struct kvm_vcpu *vcpu);
extern void kvmppc_spapr_tce_free(struct kvm_vcpu *vcpu);
extern void kvmppc_iommu_hugepages_init(struct kvm_arch *ka);
extern void kvmppc_iommu_hugepages_cleanup(struct kvm_arch *ka);
+struct iommu_group;
+extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm,
+ unsigned long liobn,
+ phys_addr_t start_addr,
+ struct iommu_group *grp);
extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
struct kvm_create_spapr_tce_64 *args);
extern struct kvmppc_spapr_tce_table *kvmppc_find_tce_table(
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 573fd6d..b7de38e 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -28,6 +28,7 @@
#include <linux/hugetlb.h>
#include <linux/list.h>
#include <linux/anon_inodes.h>
+#include <linux/iommu.h>
#include <asm/tlbflush.h>
#include <asm/kvm_ppc.h>
@@ -205,6 +206,10 @@ static void release_spapr_tce_table(struct kvmppc_spapr_tce_table *stt)
mutex_lock(&kvm->lock);
list_del(&stt->list);
+
+ if (stt->refgrp)
+ iommu_group_put(stt->refgrp);
+
for (i = 0; i < npages; i++)
__free_page(stt->pages[i]);
@@ -253,6 +258,29 @@ static const struct file_operations kvm_spapr_tce_fops = {
.release = kvm_spapr_tce_release,
};
+extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm,
+ unsigned long liobn,
+ phys_addr_t start_addr,
+ struct iommu_group *grp)
+{
+ struct kvmppc_spapr_tce_table *stt = NULL;
+
+ /* Check this LIOBN hasn't been previously allocated */
+ list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
+ if (stt->liobn == liobn) {
+ struct spapr_tce_iommu_group *data;
+
+ data = iommu_group_get_iommudata(grp);
+ BUG_ON(!data);
+ stt->tbl = data->ops->get_table(data, start_addr);
+ stt->refgrp = grp;
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
+
long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
struct kvm_create_spapr_tce_64 *args)
{
--
2.0.0
next prev parent reply other threads:[~2014-07-15 9:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-15 9:25 [PATCH v1 00/13] powerpc: kvm: Enable in-kernel acceleration for VFIO Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 01/13] KVM: PPC: Account TCE pages in locked_vm Alexey Kardashevskiy
2014-07-15 9:29 ` Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 02/13] KVM: PPC: Rework kvmppc_spapr_tce_table to support variable page size Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 03/13] KVM: PPC: Enable IOMMU_API for KVM_BOOK3S_64 permanently Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 04/13] KVM: PPC: Reserve KVM_CAP_SPAPR_TCE_VFIO capability number Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 05/13] KVM: PPC: Reserve KVM_CAP_SPAPR_TCE_64 " Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 06/13] KVM: PPC: Add @offset to kvmppc_spapr_tce_table Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 07/13] KVM: PPC: Add support for 64bit TCE windows Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 08/13] KVM: PPC: Add hugepage support for IOMMU in-kernel handling Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 09/13] KVM: PPC: Add page_shift support for in-kernel H_PUT_TCE/etc handlers Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 10/13] KVM: PPC: Fix kvmppc_gpa_to_hva_and_get() to return host physical address Alexey Kardashevskiy
2014-07-15 9:25 ` Alexey Kardashevskiy [this message]
2014-07-15 9:25 ` [PATCH v1 12/13] KVM: PPC: vfio kvm device: support spapr tce Alexey Kardashevskiy
2014-07-15 9:25 ` [PATCH v1 13/13] KVM: PPC: Add support for IOMMU in-kernel handling Alexey Kardashevskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405416333-12477-12-git-send-email-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=gwshan@linux.vnet.ibm.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).