From patchwork Mon Jul 15 11:11:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 2827411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1AE119F967 for ; Mon, 15 Jul 2013 11:18:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E8B3B20155 for ; Mon, 15 Jul 2013 11:18:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 008822010C for ; Mon, 15 Jul 2013 11:18:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755578Ab3GOLSa (ORCPT ); Mon, 15 Jul 2013 07:18:30 -0400 Received: from ch1ehsobe002.messaging.microsoft.com ([216.32.181.182]:49574 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755362Ab3GOLS3 (ORCPT ); Mon, 15 Jul 2013 07:18:29 -0400 Received: from mail63-ch1-R.bigfish.com (10.43.68.229) by CH1EHSOBE007.bigfish.com (10.43.70.57) with Microsoft SMTP Server id 14.1.225.22; Mon, 15 Jul 2013 11:18:28 +0000 Received: from mail63-ch1 (localhost [127.0.0.1]) by mail63-ch1-R.bigfish.com (Postfix) with ESMTP id 2EA8A4C00F0; Mon, 15 Jul 2013 11:18:28 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VS3(zzzz1f42h1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6h1082kzz8275bhz2dh2a8h668h839he5bhf0ah107ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1dfeh1dffh1e1dh1e23h1155h) Received: from mail63-ch1 (localhost.localdomain [127.0.0.1]) by mail63-ch1 (MessageSwitch) id 1373887105702589_4739; Mon, 15 Jul 2013 11:18:25 +0000 (UTC) Received: from CH1EHSMHS032.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.247]) by mail63-ch1.bigfish.com (Postfix) with ESMTP id A64A020047; Mon, 15 Jul 2013 11:18:25 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS032.bigfish.com (10.43.70.32) with Microsoft SMTP Server (TLS) id 14.16.227.3; Mon, 15 Jul 2013 11:18:25 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.3.136.1; Mon, 15 Jul 2013 11:20:41 +0000 Received: from freescale.com ([10.232.15.72]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with SMTP id r6FBIKTA020637; Mon, 15 Jul 2013 04:18:21 -0700 Received: by freescale.com (sSMTP sendmail emulation); Mon, 15 Jul 2013 16:41:32 +0530 From: Bharat Bhushan To: , , , , CC: Bharat Bhushan , Bharat Bhushan Subject: [PATCH 2/5] booke: exit to guest userspace for unimplemented hcalls in kvm Date: Mon, 15 Jul 2013 16:41:16 +0530 Message-ID: <1373886679-19581-3-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1373886679-19581-1-git-send-email-Bharat.Bhushan@freescale.com> References: <1373886679-19581-1-git-send-email-Bharat.Bhushan@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Exit to guest user space if kvm does not implement the hcall. Signed-off-by: Bharat Bhushan --- arch/powerpc/kvm/booke.c | 47 +++++++++++++++++++++++++++++++++++++------ arch/powerpc/kvm/powerpc.c | 1 + include/uapi/linux/kvm.h | 1 + 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 17722d8..c8b41b4 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -1005,9 +1005,25 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, break; #ifdef CONFIG_KVM_BOOKE_HV - case BOOKE_INTERRUPT_HV_SYSCALL: + case BOOKE_INTERRUPT_HV_SYSCALL: { + int i; if (!(vcpu->arch.shared->msr & MSR_PR)) { - kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); + r = kvmppc_kvm_pv(vcpu); + if (r != EV_UNIMPLEMENTED) { + /* except unimplemented return to guest */ + kvmppc_set_gpr(vcpu, 3, r); + kvmppc_account_exit(vcpu, SYSCALL_EXITS); + r = RESUME_GUEST; + break; + } + /* Exit to userspace for unimplemented hcalls in kvm */ + run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11); + run->epapr_hcall.ret = 0; + for (i = 0; i < 8; i++) + run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i); + vcpu->arch.hcall_needed = 1; + kvmppc_account_exit(vcpu, SYSCALL_EXITS); + r = RESUME_HOST; } else { /* * hcall from guest userspace -- send privileged @@ -1016,22 +1032,39 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, kvmppc_core_queue_program(vcpu, ESR_PPR); } - r = RESUME_GUEST; + run->exit_reason = KVM_EXIT_EPAPR_HCALL; break; + } #else - case BOOKE_INTERRUPT_SYSCALL: + case BOOKE_INTERRUPT_SYSCALL: { + int i; + r = RESUME_GUEST; if (!(vcpu->arch.shared->msr & MSR_PR) && (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { /* KVM PV hypercalls */ - kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); - r = RESUME_GUEST; + r = kvmppc_kvm_pv(vcpu); + if (r != EV_UNIMPLEMENTED) { + /* except unimplemented return to guest */ + kvmppc_set_gpr(vcpu, 3, r); + kvmppc_account_exit(vcpu, SYSCALL_EXITS); + r = RESUME_GUEST; + break; + } + /* Exit to userspace for unimplemented hcalls in kvm */ + run->epapr_hcall.nr = kvmppc_get_gpr(vcpu, 11); + run->epapr_hcall.ret = 0; + for (i = 0; i < 8; i++) + run->epapr_hcall.args[i] = kvmppc_get_gpr(vcpu, 3 + i); + vcpu->arch.hcall_needed = 1; + run->exit_reason = KVM_EXIT_EPAPR_HCALL; + r = RESUME_HOST; } else { /* Guest syscalls */ kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); } kvmppc_account_exit(vcpu, SYSCALL_EXITS); - r = RESUME_GUEST; break; + } #endif case BOOKE_INTERRUPT_DTLB_MISS: { diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 4e05f8c..6c6199d 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -307,6 +307,7 @@ int kvm_dev_ioctl_check_extension(long ext) case KVM_CAP_PPC_BOOKE_SREGS: case KVM_CAP_PPC_BOOKE_WATCHDOG: case KVM_CAP_PPC_EPR: + case KVM_CAP_EXIT_EPAPR_HCALL: #else case KVM_CAP_PPC_SEGSTATE: case KVM_CAP_PPC_HIOR: diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 01ee50e..b5266e5 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_PPC_RTAS 91 #define KVM_CAP_IRQ_XICS 92 #define KVM_CAP_ARM_EL1_32BIT 93 +#define KVM_CAP_EXIT_EPAPR_HCALL 94 #ifdef KVM_CAP_IRQ_ROUTING