]> git.karo-electronics.de Git - linux-beck.git/commitdiff
KVM: PPC: Add support for 64bit TCE windows
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Tue, 1 Mar 2016 06:54:40 +0000 (17:54 +1100)
committerPaul Mackerras <paulus@samba.org>
Tue, 1 Mar 2016 22:56:50 +0000 (09:56 +1100)
The existing KVM_CREATE_SPAPR_TCE only supports 32bit windows which is not
enough for directly mapped windows as the guest can get more than 4GB.

This adds KVM_CREATE_SPAPR_TCE_64 ioctl and advertises it
via KVM_CAP_SPAPR_TCE_64 capability. The table size is checked against
the locked memory limit.

Since 64bit windows are to support Dynamic DMA windows (DDW), let's add
@bus_offset and @page_shift which are also required by DDW.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Documentation/virtual/kvm/api.txt
arch/powerpc/include/asm/kvm_ppc.h
arch/powerpc/include/uapi/asm/kvm.h
arch/powerpc/kvm/book3s_64_vio.c
arch/powerpc/kvm/powerpc.c
include/uapi/linux/kvm.h

index da3943586a2bb5b07329fff81e77f413883aeaa0..bc78652b0d0755f3374ec353702552b78185c0c4 100644 (file)
@@ -3060,6 +3060,38 @@ an implementation for these despite the in kernel acceleration.
 
 This capability is always enabled.
 
+4.98 KVM_CREATE_SPAPR_TCE_64
+
+Capability: KVM_CAP_SPAPR_TCE_64
+Architectures: powerpc
+Type: vm ioctl
+Parameters: struct kvm_create_spapr_tce_64 (in)
+Returns: file descriptor for manipulating the created TCE table
+
+This is an extension for KVM_CAP_SPAPR_TCE which only supports 32bit
+windows, described in 4.62 KVM_CREATE_SPAPR_TCE
+
+This capability uses extended struct in ioctl interface:
+
+/* for KVM_CAP_SPAPR_TCE_64 */
+struct kvm_create_spapr_tce_64 {
+       __u64 liobn;
+       __u32 page_shift;
+       __u32 flags;
+       __u64 offset;   /* in pages */
+       __u64 size;     /* in pages */
+};
+
+The aim of extension is to support an additional bigger DMA window with
+a variable page size.
+KVM_CREATE_SPAPR_TCE_64 receives a 64bit window size, an IOMMU page shift and
+a bus offset of the corresponding DMA window, @size and @offset are numbers
+of IOMMU pages.
+
+@flags are not used at the moment.
+
+The rest of functionality is identical to KVM_CREATE_SPAPR_TCE.
+
 5. The kvm_run structure
 ------------------------
 
index 197a8aca2871e9375c8363de3d70134789ddf9e7..2544edabe7f392f1edb25fdf0c1c79a146b1c28b 100644 (file)
@@ -165,7 +165,7 @@ extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,
 extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
 
 extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
-                               struct kvm_create_spapr_tce *args);
+                               struct kvm_create_spapr_tce_64 *args);
 extern struct kvmppc_spapr_tce_table *kvmppc_find_table(
                struct kvm_vcpu *vcpu, unsigned long liobn);
 extern long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt,
index ab4d4732c492ebc4dd9514733cbb8461af0dbf87..c93cf35ce379550e37bcfe1d127def78af7de11c 100644 (file)
@@ -333,6 +333,15 @@ struct kvm_create_spapr_tce {
        __u32 window_size;
 };
 
+/* for KVM_CAP_SPAPR_TCE_64 */
+struct kvm_create_spapr_tce_64 {
+       __u64 liobn;
+       __u32 page_shift;
+       __u32 flags;
+       __u64 offset;   /* in pages */
+       __u64 size;     /* in pages */
+};
+
 /* for KVM_ALLOCATE_RMA */
 struct kvm_allocate_rma {
        __u64 rma_size;
index 61cbc449d0a8c795a573c6d96f95560a888f97c5..2c2d1030843acf5736e4ac0dd08c87b3522f2b17 100644 (file)
@@ -147,20 +147,23 @@ static const struct file_operations kvm_spapr_tce_fops = {
 };
 
 long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
-                                  struct kvm_create_spapr_tce *args)
+                                  struct kvm_create_spapr_tce_64 *args)
 {
        struct kvmppc_spapr_tce_table *stt = NULL;
        unsigned long npages, size;
        int ret = -ENOMEM;
        int i;
 
+       if (!args->size)
+               return -EINVAL;
+
        /* Check this LIOBN hasn't been previously allocated */
        list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
                if (stt->liobn == args->liobn)
                        return -EBUSY;
        }
 
-       size = args->window_size >> IOMMU_PAGE_SHIFT_4K;
+       size = args->size;
        npages = kvmppc_tce_pages(size);
        ret = kvmppc_account_memlimit(kvmppc_stt_pages(npages), true);
        if (ret) {
@@ -174,7 +177,8 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
                goto fail;
 
        stt->liobn = args->liobn;
-       stt->page_shift = IOMMU_PAGE_SHIFT_4K;
+       stt->page_shift = args->page_shift;
+       stt->offset = args->offset;
        stt->size = size;
        stt->kvm = kvm;
 
index 9258675e2ff7f6231863426dd9d8cc241061bd7f..19aa59b0850cf73489d5f61623794da607a6fc41 100644 (file)
@@ -33,6 +33,7 @@
 #include <asm/tlbflush.h>
 #include <asm/cputhreads.h>
 #include <asm/irqflags.h>
+#include <asm/iommu.h>
 #include "timing.h"
 #include "irq.h"
 #include "../mm/mmu_decl.h"
@@ -519,6 +520,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 
 #ifdef CONFIG_PPC_BOOK3S_64
        case KVM_CAP_SPAPR_TCE:
+       case KVM_CAP_SPAPR_TCE_64:
        case KVM_CAP_PPC_ALLOC_HTAB:
        case KVM_CAP_PPC_RTAS:
        case KVM_CAP_PPC_FIXUP_HCALL:
@@ -1344,13 +1346,34 @@ long kvm_arch_vm_ioctl(struct file *filp,
                break;
        }
 #ifdef CONFIG_PPC_BOOK3S_64
+       case KVM_CREATE_SPAPR_TCE_64: {
+               struct kvm_create_spapr_tce_64 create_tce_64;
+
+               r = -EFAULT;
+               if (copy_from_user(&create_tce_64, argp, sizeof(create_tce_64)))
+                       goto out;
+               if (create_tce_64.flags) {
+                       r = -EINVAL;
+                       goto out;
+               }
+               r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
+               goto out;
+       }
        case KVM_CREATE_SPAPR_TCE: {
                struct kvm_create_spapr_tce create_tce;
+               struct kvm_create_spapr_tce_64 create_tce_64;
 
                r = -EFAULT;
                if (copy_from_user(&create_tce, argp, sizeof(create_tce)))
                        goto out;
-               r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce);
+
+               create_tce_64.liobn = create_tce.liobn;
+               create_tce_64.page_shift = IOMMU_PAGE_SHIFT_4K;
+               create_tce_64.offset = 0;
+               create_tce_64.size = create_tce.window_size >>
+                               IOMMU_PAGE_SHIFT_4K;
+               create_tce_64.flags = 0;
+               r = kvm_vm_ioctl_create_spapr_tce(kvm, &create_tce_64);
                goto out;
        }
        case KVM_PPC_GET_SMMU_INFO: {
index 8ce5f643d078df4b2d50615a1294f7525ed604ca..b06208b2669c98ad3d6438956d6189f85694fd48 100644 (file)
@@ -1143,6 +1143,8 @@ struct kvm_s390_ucas_mapping {
 /* Available with KVM_CAP_PPC_ALLOC_HTAB */
 #define KVM_PPC_ALLOCATE_HTAB    _IOWR(KVMIO, 0xa7, __u32)
 #define KVM_CREATE_SPAPR_TCE     _IOW(KVMIO,  0xa8, struct kvm_create_spapr_tce)
+#define KVM_CREATE_SPAPR_TCE_64          _IOW(KVMIO,  0xa8, \
+                                      struct kvm_create_spapr_tce_64)
 /* Available with KVM_CAP_RMA */
 #define KVM_ALLOCATE_RMA         _IOR(KVMIO,  0xa9, struct kvm_allocate_rma)
 /* Available with KVM_CAP_PPC_HTAB_FD */