From patchwork Mon Jul 6 12:49:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 50745 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 72057229FC for ; Mon, 6 Jul 2015 12:50:28 +0000 (UTC) Received: by wipp2 with SMTP id p2sf31514889wip.2 for ; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=hhbrgNveLQRKrgD2ZNsMUP7M1FcfxwTlP4DzJKl/wVE=; b=fhz+lxgCvEMvTqsh0bWeTVH8QHqvW1HB+5LvcjdOBC7lV2fdpKb8eCO/TJilbbqazc fBc1JDeFhVu11RN89CoRaXvWsQx54pIknzDkE0EFfZcJeWqCKO1MCom590Ub9+e387H/ kZ1k40JhFwtGqmAxhKsUF28wI3u2O6+8ip/ZjXU0H3/Ly4O20eli8x0E+p1nve84nWXP 6CjCWP4fMzf5ZcV6jce/9XNflAojsCibQDs1pk/5Z4m57nidviFxqiefvMIOr3tZfcZs jRVN+UW4uX3p6geIMQy95SyGUTu2/FLogwOftylmwrTWmj83WE6mBNtVDx1011CHpVir RZOg== X-Gm-Message-State: ALoCoQm8hPonagWCio/gx2vRfRvN8uRRuq7rHHQZ5jpt5L2R8EkrreJAKJ9MF1hm642nOtKUAUcd X-Received: by 10.112.139.137 with SMTP id qy9mr153201lbb.17.1436187027808; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.167 with SMTP id t7ls587138lat.47.gmail; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) X-Received: by 10.152.115.199 with SMTP id jq7mr48616436lab.113.1436187027473; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id t18si15167126laz.137.2015.07.06.05.50.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 05:50:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labgy5 with SMTP id gy5so865531lab.2 for ; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) X-Received: by 10.152.26.163 with SMTP id m3mr48899507lag.86.1436187027379; Mon, 06 Jul 2015 05:50:27 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1704899lbb; Mon, 6 Jul 2015 05:50:26 -0700 (PDT) X-Received: by 10.194.200.194 with SMTP id ju2mr92383680wjc.61.1436187024538; Mon, 06 Jul 2015 05:50:24 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com. [209.85.212.178]) by mx.google.com with ESMTPS id cm2si30091632wjb.83.2015.07.06.05.50.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 05:50:24 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.178 as permitted sender) client-ip=209.85.212.178; Received: by widjy10 with SMTP id jy10so159945415wid.1 for ; Mon, 06 Jul 2015 05:50:24 -0700 (PDT) X-Received: by 10.180.218.227 with SMTP id pj3mr53110676wic.59.1436187024077; Mon, 06 Jul 2015 05:50:24 -0700 (PDT) Received: from gnx2579.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id o6sm28445526wiz.16.2015.07.06.05.50.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jul 2015 05:50:22 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: patches@linaro.org, alex.williamson@redhat.com, pbonzini@redhat.com Subject: [PATCH 2/2] kvm: arm/arm64: implement kvm_arm_[halt,resume]_guest Date: Mon, 6 Jul 2015 14:49:56 +0200 Message-Id: <1436186996-22528-3-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436186996-22528-1-git-send-email-eric.auger@linaro.org> References: <1436186996-22528-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On halt, the guest is forced to exit and prevented from being re-entered. This is synchronous. Those two operations will be needed for IRQ forwarding setting. Signed-off-by: Eric Auger --- RFC v1 -> v2: - add __maybe_unused RFC: - rename the function and this latter becomes static - remove __KVM_HAVE_ARCH_HALT_GUEST v4 -> v5: add arm64 support - also defines __KVM_HAVE_ARCH_HALT_GUEST for arm64 - add pause field --- arch/arm/include/asm/kvm_host.h | 3 +++ arch/arm/kvm/arm.c | 35 ++++++++++++++++++++++++++++++++--- arch/arm64/include/asm/kvm_host.h | 3 +++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 304004d..899ae27 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -132,6 +132,9 @@ struct kvm_vcpu_arch { /* vcpu power-off state */ bool power_off; + /* Don't run the guest */ + bool pause; + /* IO related fields */ struct kvm_decode mmio_decode; diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 7537e68..46d4ef6 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -471,11 +471,39 @@ bool kvm_arch_intc_initialized(struct kvm *kvm) return vgic_initialized(kvm); } +static void kvm_arm_halt_guest(struct kvm *kvm) __maybe_unused; +static void kvm_arm_resume_guest(struct kvm *kvm) __maybe_unused; + +static void kvm_arm_halt_guest(struct kvm *kvm) +{ + int i; + struct kvm_vcpu *vcpu; + + kvm_for_each_vcpu(i, vcpu, kvm) + vcpu->arch.pause = true; + force_vm_exit(cpu_all_mask); +} + +static void kvm_arm_resume_guest(struct kvm *kvm) +{ + int i; + struct kvm_vcpu *vcpu; + + kvm_for_each_vcpu(i, vcpu, kvm) { + wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu); + + vcpu->arch.pause = false; + wake_up_interruptible(wq); + } +} + + static void vcpu_pause(struct kvm_vcpu *vcpu) { wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu); - wait_event_interruptible(*wq, !vcpu->arch.power_off); + wait_event_interruptible(*wq, ((!vcpu->arch.power_off) && + (!vcpu->arch.pause))); } static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) @@ -525,7 +553,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) update_vttbr(vcpu->kvm); - if (vcpu->arch.power_off) + if (vcpu->arch.power_off || vcpu->arch.pause) vcpu_pause(vcpu); /* @@ -551,7 +579,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) run->exit_reason = KVM_EXIT_INTR; } - if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) { + if (ret <= 0 || need_new_vmid_gen(vcpu->kvm) || + vcpu->arch.pause) { local_irq_enable(); preempt_enable(); kvm_vgic_sync_hwstate(vcpu); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 009da6b..69e3785 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -125,6 +125,9 @@ struct kvm_vcpu_arch { /* vcpu power-off state */ bool power_off; + /* Don't run the guest */ + bool pause; + /* IO related fields */ struct kvm_decode mmio_decode;