From patchwork Thu Aug 9 07:17:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 176010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 73D412C00C8 for ; Thu, 9 Aug 2012 17:20:14 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755728Ab2HIHUL (ORCPT ); Thu, 9 Aug 2012 03:20:11 -0400 Received: from [216.32.180.14] ([216.32.180.14]:1410 "EHLO va3outboundpool.messaging.microsoft.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1755679Ab2HIHUI (ORCPT ); Thu, 9 Aug 2012 03:20:08 -0400 Received: from mail268-va3-R.bigfish.com (10.7.14.253) by VA3EHSOBE002.bigfish.com (10.7.40.22) with Microsoft SMTP Server id 14.1.225.23; Thu, 9 Aug 2012 07:18:17 +0000 Received: from mail268-va3 (localhost [127.0.0.1]) by mail268-va3-R.bigfish.com (Postfix) with ESMTP id 6EF8417C0409; Thu, 9 Aug 2012 07:18:17 +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(zzzz1202h1082kzz8275bhz2dh2a8h668h839he5bhf0ah) Received: from mail268-va3 (localhost.localdomain [127.0.0.1]) by mail268-va3 (MessageSwitch) id 1344496695425652_32593; Thu, 9 Aug 2012 07:18:15 +0000 (UTC) Received: from VA3EHSMHS006.bigfish.com (unknown [10.7.14.240]) by mail268-va3.bigfish.com (Postfix) with ESMTP id 5C2A71D00047; Thu, 9 Aug 2012 07:18:15 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS006.bigfish.com (10.7.99.16) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 9 Aug 2012 07:18:15 +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.2.298.5; Thu, 9 Aug 2012 02:18:14 -0500 Received: from freescale.com ([10.232.15.72]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with SMTP id q797IAbs030276; Thu, 9 Aug 2012 00:18:11 -0700 Received: by freescale.com (sSMTP sendmail emulation); Thu, 09 Aug 2012 12:47:56 +0530 From: Bharat Bhushan To: , , CC: Bharat Bhushan Subject: [PATCH 1/4 v2] Introduce a common kvm requests handler Date: Thu, 9 Aug 2012 12:47:53 +0530 Message-ID: <1344496676-32426-1-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org Added a common requests handler which is called before returning to guest. This returns non zero value when some request demands exit to userspace. Signed-off-by: Bharat Bhushan --- v2: - checkpatch error removed arch/powerpc/kvm/booke.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index d25a097..0e51102 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -412,18 +412,30 @@ static void update_timer_ints(struct kvm_vcpu *vcpu) kvmppc_core_dequeue_dec(vcpu); } +/* + * This function handle all requests when returning to guest. This return + * non zero value when some request demands exit to userspace. + */ +static int kvmppc_handle_requests(struct kvm_vcpu *vcpu) +{ + int ret = 0; + + if (!vcpu->requests) + return 0; + + if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) { + smp_mb(); + update_timer_ints(vcpu); + } + + return ret; +} + static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu) { unsigned long *pending = &vcpu->arch.pending_exceptions; unsigned int priority; - if (vcpu->requests) { - if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) { - smp_mb(); - update_timer_ints(vcpu); - } - } - priority = __ffs(*pending); while (priority < BOOKE_IRQPRIO_MAX) { if (kvmppc_booke_irqprio_deliver(vcpu, priority)) @@ -479,10 +491,15 @@ static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu) } if (signal_pending(current)) { + vcpu->run->exit_reason = KVM_EXIT_INTR; r = 1; break; } + r = kvmppc_handle_requests(vcpu); + if (r) + break; + if (kvmppc_core_prepare_to_enter(vcpu)) { /* interrupts got enabled in between, so we are back at square 1 */ @@ -511,8 +528,10 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) local_irq_disable(); if (kvmppc_prepare_to_enter(vcpu)) { - kvm_run->exit_reason = KVM_EXIT_INTR; - ret = -EINTR; + if (kvm_run->exit_reason == KVM_EXIT_INTR) + ret = -EINTR; + else + ret = 0; goto out; } @@ -972,9 +991,12 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, if (!(r & RESUME_HOST)) { local_irq_disable(); if (kvmppc_prepare_to_enter(vcpu)) { - run->exit_reason = KVM_EXIT_INTR; - r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); - kvmppc_account_exit(vcpu, SIGNAL_EXITS); + if (run->exit_reason == KVM_EXIT_INTR) { + r = (-EINTR << 2) | RESUME_HOST | + (r & RESUME_FLAG_NV); + kvmppc_account_exit(vcpu, SIGNAL_EXITS); + } else + r = RESUME_HOST | (r & RESUME_FLAG_NV); } }