From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yke9U-00033t-El for qemu-devel@nongnu.org; Tue, 21 Apr 2015 15:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yke9P-0006Xo-R9 for qemu-devel@nongnu.org; Tue, 21 Apr 2015 15:48:12 -0400 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:53649) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yke9P-0006XW-J5 for qemu-devel@nongnu.org; Tue, 21 Apr 2015 15:48:07 -0400 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 21 Apr 2015 20:48:05 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 5153B2190046 for ; Tue, 21 Apr 2015 20:47:47 +0100 (BST) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3LJm3rQ63570142 for ; Tue, 21 Apr 2015 19:48:03 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3LJm2jj020539 for ; Tue, 21 Apr 2015 15:48:03 -0400 Message-ID: <5536A972.3070708@de.ibm.com> Date: Tue, 21 Apr 2015 21:48:02 +0200 From: Christian Borntraeger MIME-Version: 1.0 References: <1428569498-27393-1-git-send-email-cornelia.huck@de.ibm.com> <1428569498-27393-10-git-send-email-cornelia.huck@de.ibm.com> <55351366.9000600@de.ibm.com> <5536A11E.5020609@suse.de> <5536A65E.5090204@de.ibm.com> <5536A6C8.5010504@suse.de> In-Reply-To: <5536A6C8.5010504@suse.de> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 09/10] s390x/mmu: Use ioctl for reading and writing from/to guest memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf , Cornelia Huck , qemu-devel@nongnu.org Cc: jfrei@linux.vnet.ibm.com, Thomas Huth Am 21.04.2015 um 21:36 schrieb Alexander Graf: > On 04/21/2015 09:34 PM, Christian Borntraeger wrote: >> Am 21.04.2015 um 21:12 schrieb Alexander Graf: >>> On 04/20/2015 04:55 PM, Christian Borntraeger wrote: >>>> Am 09.04.2015 um 10:51 schrieb Cornelia Huck: >>>>> From: Thomas Huth >>>>> >>>>> 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 >>>>> Signed-off-by: Cornelia Huck >>>> Acked-by: Christian Borntraeger >>>> >>>>> --- >>>>> target-s390x/cpu.h | 7 +++++++ >>>>> target-s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++++ >>>>> target-s390x/mmu_helper.c | 9 +++++++++ >>>>> 3 files changed, 51 insertions(+) >>>>> >>>>> diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h >>>>> index 79bc80b..9c42743 100644 >>>>> --- a/target-s390x/cpu.h >>>>> +++ b/target-s390x/cpu.h >>>>> @@ -401,6 +401,8 @@ 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); >>>>> void kvm_s390_access_exception(S390CPU *cpu, uint16_t code, uint64_t te_code); >>>>> +int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, void *hostbuf, int len, >>>>> + bool is_write); >>>>> int kvm_s390_get_clock(uint8_t *tod_high, uint64_t *tod_clock); >>>>> int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_clock); >>>>> #else >>>>> @@ -418,6 +420,11 @@ static inline int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) >>>>> { >>>>> return -ENOSYS; >>>>> } >>>>> +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 619684b..e2ae2b3 100644 >>>>> --- a/target-s390x/kvm.c >>>>> +++ b/target-s390x/kvm.c >>>>> @@ -123,6 +123,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); >>>>> >>>>> @@ -247,6 +248,7 @@ int kvm_arch_init(MachineState *ms, 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); >>>>> >>>>> kvm_s390_enable_cmma(s); >>>>> >>>>> @@ -550,6 +552,39 @@ int kvm_s390_set_clock(uint8_t *tod_high, uint64_t *tod_low) >>>>> return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr); >>>>> } >>>>> >>>>> +/** >>>>> + * 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 9b88498..1e7412c 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)); >>> Won't this spill the logs like crazy when running new qemu on old kernels? >> kvm_s390_mem_op will return -ENOSYS if cap_mem_op is not set. > > Oh, I see the logic now. Can you think of any way to make it more obvious to a reader what's going on? > We could move the error_printf into kvm_s390_mem_op. Well Conny has to do it as Thomas has left IBM.