From patchwork Tue Feb 19 07:43:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 221640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 305D52C008D for ; Tue, 19 Feb 2013 18:44:25 +1100 (EST) Received: from localhost ([::1]:38220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7hsF-00030A-8v for incoming@patchwork.ozlabs.org; Tue, 19 Feb 2013 02:44:23 -0500 Received: from eggs.gnu.org ([208.118.235.92]:48980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7hrz-0002ki-6n for qemu-devel@nongnu.org; Tue, 19 Feb 2013 02:44:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7hrx-0003VA-Ev for qemu-devel@nongnu.org; Tue, 19 Feb 2013 02:44:07 -0500 Received: from mail-gg0-x231.google.com ([2607:f8b0:4002:c02::231]:46115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7hrx-0003Ue-9W for qemu-devel@nongnu.org; Tue, 19 Feb 2013 02:44:05 -0500 Received: by mail-gg0-f177.google.com with SMTP id q1so736949gge.36 for ; Mon, 18 Feb 2013 23:44:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=0CmYJuIjEmHdZHSM29bGAkJeGJi6NqCovfd/YqRfHDQ=; b=RK+T3hgE5FnRlKPCulZ2e8eWUnkgKL6uVmUlfsXJUkaxgOFqQufQiKeaGu/yNaJ7+R psXrl4uVePWTLls3gSh6eFrfMIeNPy/HmGEuz1H0RDzfyXucFFSs2ysRd9DQFuJgUhgo fLAQIIoRIZMoHyBre46M7fLCS85zvwZae36b12sD7ZjosYCetbiLOVLdXtxjmDr2rZtd ohxMqt1uBjlOCmKH5848D5A0yiAPDzhClCP57beUS5qTtCcqGr6N7FZ1m6mO8OkEExMF Er+3f6YydMTIlY4M1lUv6cUyCM4errZi0YBof7ASnfUzSiR+Mj319kzyU8rvy9fScaZX 6Z+A== X-Received: by 10.236.147.35 with SMTP id s23mr26249738yhj.97.1361259844461; Mon, 18 Feb 2013 23:44:04 -0800 (PST) Received: from ka1.ozlabs.ibm.com (ibmaus65.lnk.telstra.net. [165.228.126.9]) by mx.google.com with ESMTPS id j26sm66514368ani.6.2013.02.18.23.44.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 18 Feb 2013 23:44:03 -0800 (PST) From: Alexey Kardashevskiy To: David Gibson Date: Tue, 19 Feb 2013 18:43:37 +1100 Message-Id: <1361259817-9788-4-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1361259817-9788-1-git-send-email-aik@ozlabs.ru> References: <1361259817-9788-1-git-send-email-aik@ozlabs.ru> X-Gm-Message-State: ALoCoQlIbWJ8n4wqh1s2eJxTL44V+mYYUlQe3QUfPE3TQX/0api+LtQnhkJlOaLCXP+DSHTohnQD X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c02::231 Cc: Alexey Kardashevskiy , Alexander Graf , qemu-devel@nongnu.org, Alex Williamson , qemu-ppc@nongnu.org Subject: [Qemu-devel] [PATCH 3/3] spapr vfio: supporting realmode iommu acceleration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Normally TCE request coming from the guest are routed to QEMU by the host kernel. Since this way slows DMA operations, the host kernel may support a real mode acceleration. In order to use it, the host kernel supports new KVM_CAP_SPAPR_TCE_IOMMU capability and KVM_CREATE_SPAPR_TCE_IOMMU ioctl which lets QEMU tell the host what LIOBN is used for an IOMMU group. Signed-off-by: Alexey Kardashevskiy --- linux-headers/asm-powerpc/kvm.h | 8 ++++++++ linux-headers/linux/kvm.h | 2 ++ target-ppc/kvm.c | 24 ++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 1 + 4 files changed, 35 insertions(+) diff --git a/linux-headers/asm-powerpc/kvm.h b/linux-headers/asm-powerpc/kvm.h index 3c1bfb3..d53c8f2 100644 --- a/linux-headers/asm-powerpc/kvm.h +++ b/linux-headers/asm-powerpc/kvm.h @@ -291,6 +291,14 @@ struct kvm_create_spapr_tce { __u32 window_size; }; +/* for KVM_CAP_SPAPR_TCE_IOMMU */ +struct kvm_create_spapr_tce_iommu { + __u64 liobn; + __u32 iommu_id; +#define SPAPR_TCE_PUT_TCE_VIRTMODE_ONLY 1 /* for debug purposes */ + __u32 flags; +}; + /* for KVM_ALLOCATE_RMA */ struct kvm_allocate_rma { __u64 rma_size; diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 8aff3b0..a665fc7 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -634,6 +634,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_SPAPR_XICS 85 #define KVM_CAP_PPC_HTAB_FD 86 #define KVM_CAP_PPC_MULTITCE 87 +#define KVM_CAP_SPAPR_TCE_IOMMU 88 #ifdef KVM_CAP_IRQ_ROUTING @@ -883,6 +884,7 @@ struct kvm_s390_ucas_mapping { #endif #define KVM_IRQCHIP_GET_SOURCES _IOW(KVMIO, 0xad, struct kvm_irq_sources) #define KVM_IRQCHIP_SET_SOURCES _IOW(KVMIO, 0xae, struct kvm_irq_sources) +#define KVM_CREATE_SPAPR_TCE_IOMMU _IOW(KVMIO, 0xaf, struct kvm_create_spapr_tce_iommu) /* * ioctls for vcpu fds diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 11c2689..3cfa770 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -60,6 +60,7 @@ static int cap_booke_sregs; static int cap_ppc_smt; static int cap_ppc_rma; static int cap_spapr_tce; +static int cap_spapr_tce_iommu; static int cap_one_reg; static int cap_htab_fd; @@ -90,6 +91,7 @@ int kvm_arch_init(KVMState *s) cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT); cap_ppc_rma = kvm_check_extension(s, KVM_CAP_PPC_RMA); cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE); + cap_spapr_tce_iommu = kvm_check_extension(s, KVM_CAP_SPAPR_TCE_IOMMU); /* This capability is misnamed - it was introduced with the * KVM_SET_ONE_REG ioctl(), which at the time only supported the * HIOR. We don't want a different capability for every register @@ -1478,6 +1480,28 @@ int kvmppc_remove_spapr_tce(void *table, int fd, uint32_t window_size) return 0; } +int kvmppc_create_spapr_tce_iommu(uint32_t liobn, uint32_t iommu_id) +{ + int ret = 0; + struct kvm_create_spapr_tce_iommu args = { + .liobn = liobn, + .iommu_id = iommu_id, + /* .flags = SPAPR_TCE_PUT_TCE_VIRTMODE_ONLY */ + }; + + if (!cap_spapr_tce_iommu) { + fprintf(stderr, "KVM VFIO: TCE IOMMU capability is not present, DMA may be slow\n"); + return -1; + } + + ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_SPAPR_TCE_IOMMU, &args); + if (ret < 0) + fprintf(stderr, "KVM VFIO: Failed to create TCE table for liobn 0x%x, ret = %d, DMA may be slow\n", + liobn, ret); + + return ret; +} + int kvmppc_reset_htab(int shift_hint) { uint32_t shift = shift_hint; diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index 63a438a..225a173 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -29,6 +29,7 @@ int kvmppc_smt_threads(void); off_t kvmppc_alloc_rma(const char *name, MemoryRegion *sysmem); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t window_size, int *pfd); int kvmppc_remove_spapr_tce(void *table, int pfd, uint32_t window_size); +int kvmppc_create_spapr_tce_iommu(uint32_t liobn, uint32_t iommu_id); int kvmppc_reset_htab(int shift_hint); uint64_t kvmppc_rma_size(uint64_t current_size, unsigned int hash_shift); #endif /* !CONFIG_USER_ONLY */