From patchwork Mon Feb 6 10:46:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Hogan X-Patchwork-Id: 9557537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A586C60413 for ; Mon, 6 Feb 2017 10:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92AEE223A6 for ; Mon, 6 Feb 2017 10:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8767E27F93; Mon, 6 Feb 2017 10:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3387223A6 for ; Mon, 6 Feb 2017 10:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751531AbdBFKrS (ORCPT ); Mon, 6 Feb 2017 05:47:18 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:38480 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbdBFKrK (ORCPT ); Mon, 6 Feb 2017 05:47:10 -0500 Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id F00B4FA77CD11; Mon, 6 Feb 2017 10:47:05 +0000 (GMT) Received: from jhogan-linux.le.imgtec.org (192.168.154.110) by hhmail02.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Mon, 6 Feb 2017 10:47:08 +0000 From: James Hogan To: CC: James Hogan , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Ralf Baechle , Andreas Herrmann , David Daney , Jonathan Corbet , , Subject: [PATCH 4/4] KVM: MIPS: Implement console output hypercall Date: Mon, 6 Feb 2017 10:46:49 +0000 Message-ID: <7ae3d49bf9ce153a5460a393bfa513a585930487.1486377433.git-series.james.hogan@imgtec.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 In-Reply-To: References: X-Originating-IP: [192.168.154.110] Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement console output hypercall by exiting back to userland with KVM_EXIT_HYPERCALL, and setting the return value on next KVM_RUN. We also document the hypercall along with the others as the documentation was never added Signed-off-by: James Hogan Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Ralf Baechle Cc: Andreas Herrmann Cc: David Daney Cc: Jonathan Corbet Cc: linux-mips@linux-mips.org Cc: kvm@vger.kernel.org Cc: linux-doc@vger.kernel.org --- Documentation/virtual/kvm/api.txt seems to suggest that KVM_EXIT_HYPERCALL is obsolete. When it suggests using KVM_EXIT_MMIO, does it simply mean the guest should use MMIO to some virtio device of some sort rather than using hypercalls, or that the hypercall should somehow be munged into the mmio exit information? --- Documentation/virtual/kvm/hypercalls.txt | 10 ++++++++++ arch/mips/include/asm/kvm_host.h | 4 ++++ arch/mips/kvm/hypcall.c | 20 ++++++++++++++++++++ arch/mips/kvm/mips.c | 3 +++ 4 files changed, 37 insertions(+), 0 deletions(-) diff --git a/Documentation/virtual/kvm/hypercalls.txt b/Documentation/virtual/kvm/hypercalls.txt index f8108c84c46b..4e6e57026bfe 100644 --- a/Documentation/virtual/kvm/hypercalls.txt +++ b/Documentation/virtual/kvm/hypercalls.txt @@ -98,3 +98,13 @@ Purpose: Return the frequency of CP0_Count in HZ. Architecture: mips Status: active Purpose: Shut down the virtual machine. + +8. KVM_HC_MIPS_CONSOLE_OUTPUT +------------------------ +Architecture: mips +Status: active +Purpose: Output a string to a console. +Argument 1 contains the virtual terminal number to write to. +Argument 2 contains a guest virtual address pointer to the string, which must +be in an unmapped virtual memory segment (e.g. KSeg0, KSeg1 or XKPhys). +Argument 3 contains the number of bytes to write. diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h index 0d308d4f2429..e0f1da0c35e9 100644 --- a/arch/mips/include/asm/kvm_host.h +++ b/arch/mips/include/asm/kvm_host.h @@ -309,6 +309,9 @@ struct kvm_vcpu_arch { /* GPR used as IO source/target */ u32 io_gpr; + /* Whether a hypercall needs completing */ + int hypercall_needed; + struct hrtimer comparecount_timer; /* Count timer control KVM register */ u32 count_ctl; @@ -838,6 +841,7 @@ unsigned int kvm_mips_config5_wrmask(struct kvm_vcpu *vcpu); enum emulation_result kvm_mips_emul_hypcall(struct kvm_vcpu *vcpu, union mips_instruction inst); int kvm_mips_handle_hypcall(struct kvm_vcpu *vcpu); +void kvm_mips_complete_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run); /* Dynamic binary translation */ extern int kvm_mips_trans_cache_index(union mips_instruction inst, diff --git a/arch/mips/kvm/hypcall.c b/arch/mips/kvm/hypcall.c index c3345e5eec02..9cb8f37ca43a 100644 --- a/arch/mips/kvm/hypcall.c +++ b/arch/mips/kvm/hypcall.c @@ -33,6 +33,7 @@ static int kvm_mips_hypercall(struct kvm_vcpu *vcpu, unsigned long num, const unsigned long *args, unsigned long *hret) { int ret = RESUME_GUEST; + int i; switch (num) { case KVM_HC_MIPS_GET_CLOCK_FREQ: @@ -49,6 +50,19 @@ static int kvm_mips_hypercall(struct kvm_vcpu *vcpu, unsigned long num, ret = RESUME_HOST; break; + /* Hypercalls passed to userland to handle */ + case KVM_HC_MIPS_CONSOLE_OUTPUT: + /* Pass to userland via KVM_EXIT_HYPERCALL */ + memset(&vcpu->run->hypercall, 0, sizeof(vcpu->run->hypercall)); + vcpu->run->hypercall.nr = num; + for (i = 0; i < MAX_HYPCALL_ARGS; ++i) + vcpu->run->hypercall.args[i] = args[i]; + vcpu->run->hypercall.ret = -KVM_ENOSYS; /* default */ + vcpu->run->exit_reason = KVM_EXIT_HYPERCALL; + vcpu->arch.hypercall_needed = 1; + ret = RESUME_HOST; + break; + default: /* Report unimplemented hypercall to guest */ *hret = -KVM_ENOSYS; @@ -72,3 +86,9 @@ int kvm_mips_handle_hypcall(struct kvm_vcpu *vcpu) return kvm_mips_hypercall(vcpu, num, args, &vcpu->arch.gprs[2] /* v0 */); } + +void kvm_mips_complete_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + vcpu->arch.gprs[2] = run->hypercall.ret; /* v0 */ + vcpu->arch.hypercall_needed = 0; +} diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index 31ee5ee0010b..1c23dc29db5d 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -409,6 +409,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) vcpu->mmio_needed = 0; } + if (vcpu->arch.hypercall_needed) + kvm_mips_complete_hypercall(vcpu, run); + lose_fpu(1); local_irq_disable();