From patchwork Fri Jul 24 08:54:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifei Jiang X-Patchwork-Id: 11682739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99D0C913 for ; Fri, 24 Jul 2020 08:55:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8978820748 for ; Fri, 24 Jul 2020 08:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727847AbgGXIzt (ORCPT ); Fri, 24 Jul 2020 04:55:49 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:55940 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727112AbgGXIzt (ORCPT ); Fri, 24 Jul 2020 04:55:49 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DDC697F4DEC214F115C6; Fri, 24 Jul 2020 16:55:38 +0800 (CST) Received: from huawei.com (10.174.187.31) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 24 Jul 2020 16:55:28 +0800 From: Yifei Jiang To: , , , CC: , , , , , , , , , , , Yifei Jiang Subject: [RFC 1/2] RISC-V: KVM: enable ioeventfd capability and compile for risc-v Date: Fri, 24 Jul 2020 16:54:40 +0800 Message-ID: <20200724085441.1514-2-jiangyifei@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200724085441.1514-1-jiangyifei@huawei.com> References: <20200724085441.1514-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.31] X-CFilter-Loop: Reflected Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Yifei Jiang Signed-off-by: Mingwang Li --- arch/riscv/kvm/Kconfig | 2 ++ arch/riscv/kvm/Makefile | 2 +- arch/riscv/kvm/vm.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index 2356dc52ebb3..95d85d893ab6 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -4,6 +4,7 @@ # source "virt/kvm/Kconfig" +source "drivers/vhost/Kconfig" menuconfig VIRTUALIZATION bool "Virtualization" @@ -26,6 +27,7 @@ config KVM select KVM_MMIO select HAVE_KVM_VCPU_ASYNC_IOCTL select SRCU + select HAVE_KVM_EVENTFD help Support hosting virtualized guest machines. diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index b56dc1650d2c..3ad46fe44900 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -2,7 +2,7 @@ # Makefile for RISC-V KVM support # -common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o) +common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o eventfd.o) ccflags-y := -Ivirt/kvm -Iarch/riscv/kvm diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 4f2498198cb5..473299e71f68 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -52,6 +52,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) int r; switch (ext) { + case KVM_CAP_IOEVENTFD: case KVM_CAP_DEVICE_CTRL: case KVM_CAP_USER_MEMORY: case KVM_CAP_SYNC_MMU: From patchwork Fri Jul 24 08:54:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifei Jiang X-Patchwork-Id: 11682735 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7FA77913 for ; Fri, 24 Jul 2020 08:55:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 715CB2064C for ; Fri, 24 Jul 2020 08:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727784AbgGXIzl (ORCPT ); Fri, 24 Jul 2020 04:55:41 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:55964 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727109AbgGXIzl (ORCPT ); Fri, 24 Jul 2020 04:55:41 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E57FCE0BEBBE4295DAF2; Fri, 24 Jul 2020 16:55:38 +0800 (CST) Received: from huawei.com (10.174.187.31) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 24 Jul 2020 16:55:29 +0800 From: Yifei Jiang To: , , , CC: , , , , , , , , , , , Yifei Jiang Subject: [RFC 2/2] RISC-V: KVM: read\write kernel mmio device support Date: Fri, 24 Jul 2020 16:54:41 +0800 Message-ID: <20200724085441.1514-3-jiangyifei@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200724085441.1514-1-jiangyifei@huawei.com> References: <20200724085441.1514-1-jiangyifei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.31] X-CFilter-Loop: Reflected Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Yifei Jiang Signed-off-by: Mingwang Li --- arch/riscv/kvm/vcpu_exit.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c index e97ba96cb0ae..448f11179fa8 100644 --- a/arch/riscv/kvm/vcpu_exit.c +++ b/arch/riscv/kvm/vcpu_exit.c @@ -191,6 +191,8 @@ static int virtual_inst_fault(struct kvm_vcpu *vcpu, struct kvm_run *run, static int emulate_load(struct kvm_vcpu *vcpu, struct kvm_run *run, unsigned long fault_addr, unsigned long htinst) { + int ret; + u8 data_buf[8]; unsigned long insn; int shift = 0, len = 0; struct kvm_cpu_trap utrap = { 0 }; @@ -272,19 +274,32 @@ static int emulate_load(struct kvm_vcpu *vcpu, struct kvm_run *run, vcpu->arch.mmio_decode.len = len; vcpu->arch.mmio_decode.return_handled = 0; - /* Exit to userspace for MMIO emulation */ - vcpu->stat.mmio_exit_user++; - run->exit_reason = KVM_EXIT_MMIO; + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, fault_addr, len, + data_buf); + run->mmio.is_write = false; run->mmio.phys_addr = fault_addr; run->mmio.len = len; + if (!ret) { + /* We handled the access successfully in the kernel. */ + memcpy(run->mmio.data, data_buf, len); + vcpu->stat.mmio_exit_kernel++; + kvm_riscv_vcpu_mmio_return(vcpu, run); + return 1; + } + + /* Exit to userspace for MMIO emulation */ + vcpu->stat.mmio_exit_user++; + run->exit_reason = KVM_EXIT_MMIO; + return 0; } static int emulate_store(struct kvm_vcpu *vcpu, struct kvm_run *run, unsigned long fault_addr, unsigned long htinst) { + int ret; u8 data8; u16 data16; u32 data32; @@ -378,13 +393,24 @@ static int emulate_store(struct kvm_vcpu *vcpu, struct kvm_run *run, return -ENOTSUPP; }; - /* Exit to userspace for MMIO emulation */ - vcpu->stat.mmio_exit_user++; - run->exit_reason = KVM_EXIT_MMIO; + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, fault_addr, len, + run->mmio.data); + run->mmio.is_write = true; run->mmio.phys_addr = fault_addr; run->mmio.len = len; + if (!ret) { + /* We handled the access successfully in the kernel. */ + vcpu->stat.mmio_exit_kernel++; + kvm_riscv_vcpu_mmio_return(vcpu, run); + return 1; + } + + /* Exit to userspace for MMIO emulation */ + vcpu->stat.mmio_exit_user++; + run->exit_reason = KVM_EXIT_MMIO; + return 0; }