From patchwork Fri Aug 7 16:08:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 52050 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 patches.linaro.org (Postfix) with ESMTPS id 9B19522EAD for ; Fri, 7 Aug 2015 16:09:32 +0000 (UTC) Received: by wilj18 with SMTP id j18sf18576642wil.0 for ; Fri, 07 Aug 2015 09:09:31 -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=M0JLc1/hJQPu56II1HnshXa7Vy+VrR+7emFCxwJCcCw=; b=SiVL0XjMwZQPN7ER1TcD05rfrs/oiIDU536aPHfa/7s5fs31Bg2krLinlXhfKUhLIc NdPUfVGT8uMyhdlLbdVKlvgw8dOwRK4KQfZ9oivkrfkSWgV6uzg14hdOS0TVIzM6KILL zmSPFjlNh2SUz3LqMM4itz/C2bJAMfBTf6WWyjYKEyAaek4uikCRPGmJDJHx5Mjh/5lX xnwFAycamLrp9v1xAOEPJ4Y4WQt9wfMaNQRywlmaRNoPMc7AIXimbfIvRFVPxjzTPiis NcyExGSuY6QcR+4Hx0H7CTy95YPOyV8UiDl8oYAHMegVM1hjXBeQq6TpJJL0rgWURI8C 2r+g== X-Gm-Message-State: ALoCoQmu0/E39um3xNlZpgvQUMPzrZhdfmSrhEiJlOTn0/CdpZEBCqypfc1dq2sLvdZGAp2kqFql X-Received: by 10.194.19.33 with SMTP id b1mr2375553wje.6.1438963771984; Fri, 07 Aug 2015 09:09:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.228 with SMTP id bb4ls442334lab.88.gmail; Fri, 07 Aug 2015 09:09:31 -0700 (PDT) X-Received: by 10.112.55.33 with SMTP id o1mr8254142lbp.96.1438963771624; Fri, 07 Aug 2015 09:09:31 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id i1si7810838lbs.87.2015.08.07.09.09.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2015 09:09:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbtg9 with SMTP id tg9so25664335lbb.1 for ; Fri, 07 Aug 2015 09:09:31 -0700 (PDT) X-Received: by 10.152.120.135 with SMTP id lc7mr8230454lab.41.1438963771533; Fri, 07 Aug 2015 09:09:31 -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.7.198 with SMTP id l6csp480633lba; Fri, 7 Aug 2015 09:09:30 -0700 (PDT) X-Received: by 10.194.175.200 with SMTP id cc8mr17421508wjc.87.1438963767031; Fri, 07 Aug 2015 09:09:27 -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 p3si11878527wiy.86.2015.08.07.09.09.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2015 09:09:27 -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 wibxm9 with SMTP id xm9so71908491wib.1 for ; Fri, 07 Aug 2015 09:09:26 -0700 (PDT) X-Received: by 10.180.73.237 with SMTP id o13mr8140304wiv.55.1438963766746; Fri, 07 Aug 2015 09:09:26 -0700 (PDT) Received: from gnx2579.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id by17sm9127438wib.18.2015.08.07.09.09.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Aug 2015 09:09:25 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, drjones@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, patches@linaro.org, pbonzini@redhat.com Subject: [PATCH v2 4/4] KVM: arm/arm64: implement kvm_arm_[halt, resume]_guest Date: Fri, 7 Aug 2015 18:08:33 +0200 Message-Id: <1438963713-10460-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438963713-10460-1-git-send-email-eric.auger@linaro.org> References: <1438963713-10460-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.217.171 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: , We introduce kvm_arm_halt_guest and resume functions. They will be used for IRQ forward state change. Halt is synchronous and prevents the guest from being re-entered. We use the same mechanism put in place for PSCI former pause, now renamed power_off. A new flag is introduced in arch vcpu state, pause, only meant to be used by those functions. Signed-off-by: Eric Auger Reviewed-by: Christoffer Dall --- v1 -> v2: - check pause in kvm_arch_vcpu_runnable - we cannot use kvm_vcpu_block since this latter would exit on IRQ/FIQ and this is not what we want --- 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, 37 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 304004d..dac85f6 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; + /* Exit and don't run the guest (internal implementation need) */ + 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 cc404a8..0529b38 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -348,7 +348,7 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) { return ((!!v->arch.irq_lines || kvm_vgic_vcpu_pending_irq(v)) - && !v->arch.power_off); + && !v->arch.power_off && !v->arch.pause); } /* Just ensure a guest exit from a particular CPU */ @@ -474,11 +474,38 @@ 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_sleep(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) @@ -528,7 +555,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_sleep(vcpu); /* @@ -556,7 +583,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) } if (ret <= 0 || need_new_vmid_gen(vcpu->kvm) || - vcpu->arch.power_off) { + vcpu->arch.power_off || vcpu->arch.pause) { local_irq_enable(); kvm_vgic_sync_hwstate(vcpu); preempt_enable(); 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;