From: Yifei Jiang <jiangyifei@huawei.com>
To: <qemu-devel@nongnu.org>, <qemu-riscv@nongnu.org>
Cc: victor.zhangxiaofeng@huawei.com, zhang.zhanghailiang@huawei.com,
sagark@eecs.berkeley.edu, yinyipeng1@huawei.com,
kbastian@mail.uni-paderborn.de, anup.patel@wdc.com,
Alistair.Francis@wdc.com, kvm-riscv@lists.infradead.org,
palmer@dabbelt.com, Yifei Jiang <jiangyifei@huawei.com>,
dengkai1@huawei.com
Subject: [PATCH RFC v2 6/9] target/riscv: Support start kernel directly by KVM
Date: Sat, 11 Apr 2020 12:14:24 +0800 [thread overview]
Message-ID: <20200411041427.14828-7-jiangyifei@huawei.com> (raw)
In-Reply-To: <20200411041427.14828-1-jiangyifei@huawei.com>
Get kernel and fdt start address in virt.c, and pass them to KVM
when cpu reset. In addition, add kvm_riscv.h to place riscv specific
interface.
Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com>
---
hw/riscv/virt.c | 16 +++++++++++++---
target/riscv/cpu.c | 4 ++++
target/riscv/cpu.h | 3 +++
target/riscv/kvm.c | 14 ++++++++++++++
target/riscv/kvm_riscv.h | 24 ++++++++++++++++++++++++
5 files changed, 58 insertions(+), 3 deletions(-)
create mode 100644 target/riscv/kvm_riscv.h
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 85ec9e22aa..d72eb782e4 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -42,6 +42,7 @@
#include "exec/address-spaces.h"
#include "hw/pci/pci.h"
#include "hw/pci-host/gpex.h"
+#include "sysemu/kvm.h"
#include <libfdt.h>
@@ -480,6 +481,9 @@ static void riscv_virt_board_init(MachineState *machine)
target_ulong start_addr = memmap[VIRT_DRAM].base;
int i;
unsigned int smp_cpus = machine->smp.cpus;
+ uint64_t kernel_entry = 0;
+ hwaddr start_fdt;
+ CPUState *cs;
/* Initialize SOC */
object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc),
@@ -510,8 +514,7 @@ static void riscv_virt_board_init(MachineState *machine)
memmap[VIRT_DRAM].base);
if (machine->kernel_filename) {
- uint64_t kernel_entry = riscv_load_kernel(machine->kernel_filename,
- NULL);
+ kernel_entry = riscv_load_kernel(machine->kernel_filename, NULL);
if (machine->initrd_filename) {
hwaddr start;
@@ -564,10 +567,17 @@ static void riscv_virt_board_init(MachineState *machine)
exit(1);
}
qemu_fdt_dumpdtb(s->fdt, fdt_totalsize(s->fdt));
+ start_fdt = memmap[VIRT_MROM].base + sizeof(reset_vec);
rom_add_blob_fixed_as("mrom.fdt", s->fdt, fdt_totalsize(s->fdt),
- memmap[VIRT_MROM].base + sizeof(reset_vec),
+ start_fdt,
&address_space_memory);
+ for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
+ RISCVCPU *riscv_cpu = RISCV_CPU(cs);
+ riscv_cpu->env.loader_start = kernel_entry;
+ riscv_cpu->env.fdt_start = start_fdt;
+ }
+
/* create PLIC hart topology configuration string */
plic_hart_config_len = (strlen(VIRT_PLIC_HART_CONFIG) + 1) * smp_cpus;
plic_hart_config = g_malloc0(plic_hart_config_len);
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 4e578239d3..6a6af13ab9 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -28,6 +28,7 @@
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
#include "fpu/softfloat-helpers.h"
+#include "kvm_riscv.h"
/* RISC-V CPU definitions */
@@ -347,6 +348,9 @@ static void riscv_cpu_reset(DeviceState *dev)
cs->exception_index = EXCP_NONE;
env->load_res = -1;
set_default_nan_mode(1, &env->fp_status);
+#ifdef CONFIG_KVM
+ kvm_riscv_reset_vcpu(cpu);
+#endif
}
static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 7d21addbab..dcff112c5f 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -213,6 +213,9 @@ struct CPURISCVState {
/* Fields from here on are preserved across CPU reset. */
QEMUTimer *timer; /* Internal timer */
+
+ hwaddr loader_start;
+ hwaddr fdt_start;
};
#define RISCV_CPU_CLASS(klass) \
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
index 6dffda36bb..b9aec66b69 100644
--- a/target/riscv/kvm.c
+++ b/target/riscv/kvm.c
@@ -37,6 +37,7 @@
#include "hw/irq.h"
#include "qemu/log.h"
#include "hw/loader.h"
+#include "kvm_riscv.h"
static __u64 kvm_riscv_reg_id(__u64 type, __u64 idx)
{
@@ -426,3 +427,16 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
{
return 0;
}
+
+void kvm_riscv_reset_vcpu(RISCVCPU *cpu)
+{
+ CPURISCVState *env = &cpu->env;
+
+ if (!kvm_enabled()) {
+ return;
+ }
+ env->pc = cpu->env.loader_start;
+ env->gpr[10] = kvm_arch_vcpu_id(CPU(cpu)); /* a0 */
+ env->gpr[11] = cpu->env.fdt_start; /* a1 */
+}
+
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
new file mode 100644
index 0000000000..f38c82bf59
--- /dev/null
+++ b/target/riscv/kvm_riscv.h
@@ -0,0 +1,24 @@
+/*
+ * QEMU KVM support -- RISC-V specific functions.
+ *
+ * Copyright (c) 2020 Huawei Technologies Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef QEMU_KVM_RISCV_H
+#define QEMU_KVM_RISCV_H
+
+void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
+
+#endif
--
2.19.1
next prev parent reply other threads:[~2020-04-11 4:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-11 4:14 [PATCH RFC v2 0/9] Add riscv kvm accel support Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 1/9] linux-header: Update linux/kvm.h Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 2/9] target/riscv: Add target/riscv/kvm.c to place the public kvm interface Yifei Jiang
2020-04-17 22:34 ` Alistair Francis
2020-04-11 4:14 ` [PATCH RFC v2 3/9] target/riscv: Implement function kvm_arch_init_vcpu Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 4/9] target/riscv: Implement kvm_arch_get_registers Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 5/9] target/riscv: Implement kvm_arch_put_registers Yifei Jiang
2020-04-11 4:14 ` Yifei Jiang [this message]
2020-04-11 4:14 ` [PATCH RFC v2 7/9] hw/riscv: PLIC update external interrupt by KVM when kvm enabled Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 8/9] target/riscv: Handler KVM_EXIT_RISCV_SBI exit Yifei Jiang
2020-04-11 4:14 ` [PATCH RFC v2 9/9] target/riscv: add host cpu type Yifei Jiang
2020-04-11 5:47 ` [PATCH RFC v2 0/9] Add riscv kvm accel support no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200411041427.14828-7-jiangyifei@huawei.com \
--to=jiangyifei@huawei.com \
--cc=Alistair.Francis@wdc.com \
--cc=anup.patel@wdc.com \
--cc=dengkai1@huawei.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=kvm-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=sagark@eecs.berkeley.edu \
--cc=victor.zhangxiaofeng@huawei.com \
--cc=yinyipeng1@huawei.com \
--cc=zhang.zhanghailiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).