euleros inclusion category: feature bugzilla: NA CVE: NA
These two patches enable the support for vhost-net on RISC-V architecture.
The following two steps are performed to run a vm with vhost-net:
1. create virbr0 on riscv64 emulation $ brctl addbr virbr0 $ brctl stp virbr0 on $ ifconfig virbr0 up $ ifconfig virbr0 virbr0_ip netmask 255.255.255.0
2. boot a riscv64 guest OS on riscv64 emulation $ ./qemu-system-riscv64 -M virt,accel=kvm -m 1024M -cpu host -nographic \ -name guest=riscv-guest \ -smp 2 \ -kernel ./Image \ -drive file=./guest.img,format=raw,id=hd0 \ -device virtio-blk,drive=hd0 \ -netdev type=tap,vhost=on,script=./ifup.sh,downscript=./ifdown.sh,id=net0 \ -append "root=/dev/vda rw console=ttyS0 earlycon=sbi"
$ cat ifup.sh #!/bin/sh brctl addif virbr0 $1 ifconfig $1 up
$ cat ifdown.sh #!/bin/sh ifconfig $1 down brctl delif virbr0 $1
This brenchmark netperf is used to test the performance of vhost-net and virtio-net. The results are as follow:
$ ./netperf -H virbr0_ip -l 100 -t TCP_STREAM
vhost-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 100.06 521.62
virtio-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 292.86 292.86
Link: https://gitee.com/openeuler/kernel/issues/I1SQJ2
Yifei Jiang (2): RISC-V: KVM: enable ioeventfd capability RISC-V: KVM: kernel mmio read/write support
arch/riscv/kvm/Kconfig | 2 ++ arch/riscv/kvm/Makefile | 2 +- arch/riscv/kvm/vcpu_exit.c | 28 ++++++++++++++++++++++++++-- arch/riscv/kvm/vm.c | 1 + 4 files changed, 30 insertions(+), 3 deletions(-)
euleros inclusion category: feature bugzilla: NA CVE: NA
Add eventfd file to riscv kvm Makefile.
Link: https://gitee.com/openeuler/kernel/issues/I1SQJ2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Mingwang Li limingwang@huawei.com --- 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 2356dc52e..95d85d893 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 b56dc1650..3ad46fe44 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 4f2498198..473299e71 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:
euleros inclusion category: feature bugzilla: NA CVE: NA
When a guest accesses a mmio address and a trap is raised to be handled by KVM, KVM checks whether the mmio address access is operated by kernel.
Link: https://gitee.com/openeuler/kernel/issues/I1SQJ2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Mingwang Li limingwang@huawei.com --- arch/riscv/kvm/vcpu_exit.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c index f3a3acdc8..57563c433 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, insn_len = 0; struct kvm_cpu_trap utrap = { 0 }; @@ -275,10 +277,21 @@ 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;
+ run->mmio.is_write = false; + + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, fault_addr, len, + data_buf); + 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; - run->mmio.is_write = false; run->mmio.phys_addr = fault_addr; run->mmio.len = len;
@@ -288,6 +301,7 @@ static int emulate_load(struct kvm_vcpu *vcpu, struct kvm_run *run, 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; @@ -384,10 +398,20 @@ static int emulate_store(struct kvm_vcpu *vcpu, struct kvm_run *run, return -ENOTSUPP; };
+ run->mmio.is_write = true; + + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, fault_addr, len, + run->mmio.data); + 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; - run->mmio.is_write = true; run->mmio.phys_addr = fault_addr; run->mmio.len = len;
Reviewed-by: Kai Deng dengkai1@huawei.com
-----邮件原件----- 发件人: Jiangyifei 发送时间: 2020年8月25日 19:30 收件人: Xiexiuqi xiexiuqi@huawei.com; Guohanjun (Hanjun Guo) guohanjun@huawei.com 抄送: Zhanghailiang zhang.zhanghailiang@huawei.com; kernel.openeuler kernel.openeuler@huawei.com; kernel@openeuler.org; Chenzhendong (alex) alex.chen@huawei.com; dengkai (A) dengkai1@huawei.com; Zhangxiaofeng (F) victor.zhangxiaofeng@huawei.com 主题: [PATCH 0/2] Add risc-v vhost-net support
euleros inclusion category: feature bugzilla: NA CVE: NA
These two patches enable the support for vhost-net on RISC-V architecture.
The following two steps are performed to run a vm with vhost-net:
1. create virbr0 on riscv64 emulation $ brctl addbr virbr0 $ brctl stp virbr0 on $ ifconfig virbr0 up $ ifconfig virbr0 virbr0_ip netmask 255.255.255.0
2. boot a riscv64 guest OS on riscv64 emulation $ ./qemu-system-riscv64 -M virt,accel=kvm -m 1024M -cpu host -nographic \ -name guest=riscv-guest \ -smp 2 \ -kernel ./Image \ -drive file=./guest.img,format=raw,id=hd0 \ -device virtio-blk,drive=hd0 \ -netdev type=tap,vhost=on,script=./ifup.sh,downscript=./ifdown.sh,id=net0 \ -append "root=/dev/vda rw console=ttyS0 earlycon=sbi"
$ cat ifup.sh #!/bin/sh brctl addif virbr0 $1 ifconfig $1 up
$ cat ifdown.sh #!/bin/sh ifconfig $1 down brctl delif virbr0 $1
This brenchmark netperf is used to test the performance of vhost-net and virtio-net. The results are as follow:
$ ./netperf -H virbr0_ip -l 100 -t TCP_STREAM
vhost-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 100.06 521.62
virtio-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 292.86 292.86
Link: https://gitee.com/openeuler/kernel/issues/I1SQJ2
Yifei Jiang (2): RISC-V: KVM: enable ioeventfd capability RISC-V: KVM: kernel mmio read/write support
arch/riscv/kvm/Kconfig | 2 ++ arch/riscv/kvm/Makefile | 2 +- arch/riscv/kvm/vcpu_exit.c | 28 ++++++++++++++++++++++++++-- arch/riscv/kvm/vm.c | 1 + 4 files changed, 30 insertions(+), 3 deletions(-)
-- 2.19.1
Acked-by: Xie XiuQi xiexiuqi@huawei.com
On 2020/8/25 19:30, Yifei Jiang wrote:
euleros inclusion category: feature bugzilla: NA CVE: NA
These two patches enable the support for vhost-net on RISC-V architecture.
The following two steps are performed to run a vm with vhost-net:
- create virbr0 on riscv64 emulation
$ brctl addbr virbr0 $ brctl stp virbr0 on $ ifconfig virbr0 up $ ifconfig virbr0 virbr0_ip netmask 255.255.255.0
- boot a riscv64 guest OS on riscv64 emulation
$ ./qemu-system-riscv64 -M virt,accel=kvm -m 1024M -cpu host -nographic \ -name guest=riscv-guest \ -smp 2 \ -kernel ./Image \ -drive file=./guest.img,format=raw,id=hd0 \ -device virtio-blk,drive=hd0 \ -netdev type=tap,vhost=on,script=./ifup.sh,downscript=./ifdown.sh,id=net0 \ -append "root=/dev/vda rw console=ttyS0 earlycon=sbi"
$ cat ifup.sh #!/bin/sh brctl addif virbr0 $1 ifconfig $1 up
$ cat ifdown.sh #!/bin/sh ifconfig $1 down brctl delif virbr0 $1
This brenchmark netperf is used to test the performance of vhost-net and virtio-net. The results are as follow:
$ ./netperf -H virbr0_ip -l 100 -t TCP_STREAM
vhost-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 100.06 521.62
virtio-net: Recv Send Send Socket Socket Message Elapsed Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
131072 16384 16384 292.86 292.86
Link: https://gitee.com/openeuler/kernel/issues/I1SQJ2
Yifei Jiang (2): RISC-V: KVM: enable ioeventfd capability RISC-V: KVM: kernel mmio read/write support
arch/riscv/kvm/Kconfig | 2 ++ arch/riscv/kvm/Makefile | 2 +- arch/riscv/kvm/vcpu_exit.c | 28 ++++++++++++++++++++++++++-- arch/riscv/kvm/vm.c | 1 + 4 files changed, 30 insertions(+), 3 deletions(-)