From patchwork Mon Feb 16 12:22:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 440060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EEFB7140172 for ; Mon, 16 Feb 2015 23:24:50 +1100 (AEDT) Received: from localhost ([::1]:39079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNKjI-0007jd-T0 for incoming@patchwork.ozlabs.org; Mon, 16 Feb 2015 07:24:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNKih-0006Nj-Iw for qemu-devel@nongnu.org; Mon, 16 Feb 2015 07:24:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNKiX-00063g-Ej for qemu-devel@nongnu.org; Mon, 16 Feb 2015 07:24:11 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:58652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNKiX-000630-6Q for qemu-devel@nongnu.org; Mon, 16 Feb 2015 07:24:01 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 16 Feb 2015 12:24:00 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 16 Feb 2015 12:23:58 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id CB9FA17D807E for ; Mon, 16 Feb 2015 12:24:10 +0000 (GMT) Received: from d06av11.portsmouth.uk.ibm.com (d06av11.portsmouth.uk.ibm.com [9.149.37.252]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1GCMgEa53215348 for ; Mon, 16 Feb 2015 12:22:42 GMT Received: from d06av11.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1GCMfk1007974 for ; Mon, 16 Feb 2015 05:22:41 -0700 Received: from oc7435384737.ibm.com (dyn-9-152-224-89.boeblingen.de.ibm.com [9.152.224.89]) by d06av11.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t1GCMXJU007717; Mon, 16 Feb 2015 05:22:41 -0700 From: Thomas Huth To: qemu-devel@nongnu.org Date: Mon, 16 Feb 2015 13:22:18 +0100 Message-Id: <1424089338-14562-3-git-send-email-thuth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1424089338-14562-1-git-send-email-thuth@linux.vnet.ibm.com> References: <1424089338-14562-1-git-send-email-thuth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15021612-0009-0000-0000-00000329231A X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.108 Cc: Thomas Huth , kvm@vger.kernel.org, agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 2/2] s390x/mmu: Use ioctl for reading and writing from/to guest memory 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 Add code to make use of the new ioctl for reading from / writing to virtual guest memory. By using the ioctl, the memory accesses are now protected with the so-called ipte-lock in the kernel. Signed-off-by: Thomas Huth --- target-s390x/cpu.h | 7 +++++++ target-s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++++ target-s390x/mmu_helper.c | 9 +++++++++ 3 files changed, 51 insertions(+), 0 deletions(-) diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index b6b4632..cffdd1b 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -394,6 +394,8 @@ void kvm_s390_service_interrupt(uint32_t parm); void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq); void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq); int kvm_s390_inject_flic(struct kvm_s390_irq *irq); +int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, void *hostbuf, int len, + bool is_write); void kvm_s390_access_exception(S390CPU *cpu, uint16_t code, uint64_t te_code); #else static inline void kvm_s390_virtio_irq(int config_change, uint64_t token) @@ -402,6 +404,11 @@ static inline void kvm_s390_virtio_irq(int config_change, uint64_t token) static inline void kvm_s390_service_interrupt(uint32_t parm) { } +static inline int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, void *hostbuf, + int len, bool is_write) +{ + return -ENOSYS; +} static inline void kvm_s390_access_exception(S390CPU *cpu, uint16_t code, uint64_t te_code) { diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 195493c..57a3aa1 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -117,6 +117,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { static int cap_sync_regs; static int cap_async_pf; +static int cap_mem_op; static void *legacy_s390_alloc(size_t size, uint64_t *align); @@ -176,6 +177,7 @@ int kvm_arch_init(KVMState *s) { cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF); + cap_mem_op = kvm_check_extension(s, KVM_CAP_S390_MEM_OP); if (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES)) { kvm_s390_enable_cmma(s); @@ -436,6 +438,39 @@ int kvm_arch_get_registers(CPUState *cs) return 0; } +/** + * kvm_s390_mem_op: + * @addr: the logical start address in guest memory + * @hostbuf: buffer in host memory. NULL = do only checks w/o copying + * @len: length that should be transfered + * @is_write: true = write, false = read + * Returns: 0 on success, non-zero if an exception or error occured + * + * Use KVM ioctl to read/write from/to guest memory. An access exception + * is injected into the vCPU in case of translation errors. + */ +int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, void *hostbuf, int len, + bool is_write) +{ + struct kvm_s390_mem_op mem_op = { + .gaddr = addr, + .flags = KVM_S390_MEMOP_F_INJECT_EXCEPTION, + .size = len, + .op = is_write ? KVM_S390_MEMOP_LOGICAL_WRITE + : KVM_S390_MEMOP_LOGICAL_READ, + .buf = (uint64_t)hostbuf, + }; + + if (!cap_mem_op) { + return -ENOSYS; + } + if (!hostbuf) { + mem_op.flags |= KVM_S390_MEMOP_F_CHECK_ONLY; + } + + return kvm_vcpu_ioctl(CPU(cpu), KVM_S390_MEM_OP, &mem_op); +} + /* * Legacy layout for s390: * Older S390 KVM requires the topmost vma of the RAM to be diff --git a/target-s390x/mmu_helper.c b/target-s390x/mmu_helper.c index b061c85..22f965a 100644 --- a/target-s390x/mmu_helper.c +++ b/target-s390x/mmu_helper.c @@ -450,6 +450,15 @@ int s390_cpu_virt_mem_rw(S390CPU *cpu, vaddr laddr, void *hostbuf, target_ulong *pages; int ret; + if (kvm_enabled()) { + ret = kvm_s390_mem_op(cpu, laddr, hostbuf, len, is_write); + if (ret >= 0) { + return ret; + } else if (ret != -ENOSYS) { + error_printf("kvm_s390_mem_op() failed: %s\n", strerror(-ret)); + } + } + nr_pages = (((laddr & ~TARGET_PAGE_MASK) + len - 1) >> TARGET_PAGE_BITS) + 1; pages = g_malloc(nr_pages * sizeof(*pages));