From patchwork Sun Jun 22 21:23:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 4396581 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70F4DBEEAA for ; Sun, 22 Jun 2014 21:24:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9BD30201DE for ; Sun, 22 Jun 2014 21:24:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5ADE2021A for ; Sun, 22 Jun 2014 21:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbaFVVYA (ORCPT ); Sun, 22 Jun 2014 17:24:00 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33357 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752191AbaFVVXn (ORCPT ); Sun, 22 Jun 2014 17:23:43 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 38995AD69; Sun, 22 Jun 2014 21:23:38 +0000 (UTC) From: Alexander Graf To: kvm-ppc@vger.kernel.org Cc: kvm@vger.kernel.org Subject: [PATCH 16/33] KVM: PPC: Add ld instruction emulation Date: Sun, 22 Jun 2014 23:23:20 +0200 Message-Id: <1403472217-22263-17-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1403472217-22263-1-git-send-email-agraf@suse.de> References: <1403472217-22263-1-git-send-email-agraf@suse.de> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds full emulation support for the ld instruction. It also introduces a generic framework to handle guest load instructions. Signed-off-by: Alexander Graf --- arch/powerpc/kvm/emulate.c | 68 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index 6658dea..9f89a41 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -380,11 +380,66 @@ static int kvmppc_emulate_store(struct kvm_vcpu *vcpu, ulong addr, u64 value, return r; } +static int kvmppc_emulate_load(struct kvm_vcpu *vcpu, ulong addr, u64 *value, + int size) +{ + ulong paddr = addr; + int r; + + r = kvmppc_ld(vcpu, &paddr, size, value, true); + + switch (r) { + case EMULATE_DONE: + switch (size) { + case 1: *value = *(u8*)value; break; + case 2: *value = *(u16*)value; break; + case 4: *value = *(u32*)value; break; + case 8: break; + } + + if (kvmppc_need_byteswap(vcpu)) { + switch (size) { + case 1: break; + case 2: *value = swab16(*value); break; + case 4: *value = swab32(*value); break; + case 8: *value = swab64(*value); break; + } + } + break; + case -ENOENT: +#ifdef CONFIG_PPC_BOOK3S + kvmppc_core_queue_data_storage(vcpu, addr, DSISR_NOHPTE); +#else + kvmppc_core_queue_dtlb_miss(vcpu, addr, ESR_DST); +#endif + r = EMULATE_AGAIN; + break; + case -EPERM: +#ifdef CONFIG_PPC_BOOK3S + kvmppc_core_queue_data_storage(vcpu, addr, DSISR_PROTFAULT); +#else + kvmppc_core_queue_data_storage(vcpu, addr, 0); +#endif + r = EMULATE_AGAIN; + break; + case EMULATE_DO_MMIO: + vcpu->stat.mmio_exits++; + vcpu->arch.paddr_accessed = paddr; + vcpu->arch.vaddr_accessed = addr; + vcpu->run->exit_reason = KVM_EXIT_MMIO; + r = kvmppc_emulate_loadstore(vcpu); + break; + } + + return r; +} + /* Emulates privileged and non-privileged instructions */ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu) { u32 inst = kvmppc_get_last_inst(vcpu); - ulong addr, value; + ulong addr; + u64 value; enum emulation_result emulated = EMULATE_DONE; int advance = 1; @@ -402,6 +457,17 @@ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu) value = kvmppc_get_gpr(vcpu, get_rs(inst)); emulated = kvmppc_emulate_store(vcpu, addr, value, 4); break; + case OP_LD: + addr = get_addr(vcpu, (s16)get_d(inst), get_ra(inst)); + if (addr & 0x3) { + /* other instructions */ + emulated = EMULATE_FAIL; + break; + } + emulated = kvmppc_emulate_load(vcpu, addr, &value, 8); + if (emulated == EMULATE_DONE) + kvmppc_set_gpr(vcpu, get_rt(inst), value); + break; default: emulated = EMULATE_FAIL; break;