All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiangyifei <jiangyifei@huawei.com>
To: Alistair Francis <alistair23@gmail.com>
Cc: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"open list:RISC-V" <qemu-riscv@nongnu.org>,
	"kvm-riscv@lists.infradead.org" <kvm-riscv@lists.infradead.org>,
	"open list:Overall" <kvm@vger.kernel.org>,
	"libvir-list@redhat.com" <libvir-list@redhat.com>,
	Anup Patel <anup@brainfault.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Bin Meng <bin.meng@windriver.com>,
	"Fanliang (EulerOS)" <fanliang@huawei.com>,
	"Wubin (H)" <wu.wubin@huawei.com>,
	"Wanghaibin (D)" <wanghaibin.wang@huawei.com>,
	"wanbo (G)" <wanbo13@huawei.com>,
	"limingwang (A)" <limingwang@huawei.com>
Subject: RE: [PATCH v4 06/12] target/riscv: Support start kernel directly by KVM
Date: Wed, 12 Jan 2022 08:07:53 +0000	[thread overview]
Message-ID: <b592508d4a034ec5a3aeaf218819803d@huawei.com> (raw)
In-Reply-To: <CAKmqyKPNLSiLP_FGgod=1fa=kUnnkagYBOQD0Bx5O=96AAkhmQ@mail.gmail.com>


> -----Original Message-----
> From: Alistair Francis [mailto:alistair23@gmail.com]
> Sent: Tuesday, January 11, 2022 8:28 AM
> To: Jiangyifei <jiangyifei@huawei.com>
> Cc: qemu-devel@nongnu.org Developers <qemu-devel@nongnu.org>; open
> list:RISC-V <qemu-riscv@nongnu.org>; kvm-riscv@lists.infradead.org; open
> list:Overall <kvm@vger.kernel.org>; libvir-list@redhat.com; Anup Patel
> <anup@brainfault.org>; Palmer Dabbelt <palmer@dabbelt.com>; Alistair
> Francis <Alistair.Francis@wdc.com>; Bin Meng <bin.meng@windriver.com>;
> Fanliang (EulerOS) <fanliang@huawei.com>; Wubin (H)
> <wu.wubin@huawei.com>; Wanghaibin (D) <wanghaibin.wang@huawei.com>;
> wanbo (G) <wanbo13@huawei.com>; limingwang (A)
> <limingwang@huawei.com>
> Subject: Re: [PATCH v4 06/12] target/riscv: Support start kernel directly by KVM
> 
> On Mon, Jan 10, 2022 at 11:52 AM Yifei Jiang via <qemu-devel@nongnu.org>
> wrote:
> >
> > Get kernel and fdt start address in virt.c, and pass them to KVM when
> > cpu reset. Add kvm_riscv.h to place riscv specific interface.
> >
> > In addition, PLIC is created without M-mode PLIC contexts when KVM is
> > enabled.
> >
> > Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
> > Signed-off-by: Mingwang Li <limingwang@huawei.com>
> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >  hw/intc/sifive_plic.c    | 21 +++++++---
> >  hw/riscv/boot.c          | 16 +++++++-
> >  hw/riscv/virt.c          | 83 ++++++++++++++++++++++++++++------------
> >  include/hw/riscv/boot.h  |  1 +
> >  target/riscv/cpu.c       |  8 ++++
> >  target/riscv/cpu.h       |  3 ++
> >  target/riscv/kvm-stub.c  | 25 ++++++++++++
> >  target/riscv/kvm.c       | 14 +++++++
> >  target/riscv/kvm_riscv.h | 24 ++++++++++++  target/riscv/meson.build
> > |  2 +-
> >  10 files changed, 164 insertions(+), 33 deletions(-)  create mode
> > 100644 target/riscv/kvm-stub.c  create mode 100644
> > target/riscv/kvm_riscv.h
> >
> > diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c index
> > 877e76877c..58c16881cb 100644
> > --- a/hw/intc/sifive_plic.c
> > +++ b/hw/intc/sifive_plic.c
> > @@ -30,6 +30,7 @@
> >  #include "target/riscv/cpu.h"
> >  #include "migration/vmstate.h"
> >  #include "hw/irq.h"
> > +#include "sysemu/kvm.h"
> >
> >  #define RISCV_DEBUG_PLIC 0
> >
> > @@ -533,6 +534,8 @@ DeviceState *sifive_plic_create(hwaddr addr, char
> > *hart_config,  {
> >      DeviceState *dev = qdev_new(TYPE_SIFIVE_PLIC);
> >      int i;
> > +    SiFivePLICState *plic;
> > +    int s_count = 0, m_count = 0;
> >
> >      assert(enable_stride == (enable_stride & -enable_stride));
> >      assert(context_stride == (context_stride & -context_stride)); @@
> > -550,13 +553,19 @@ DeviceState *sifive_plic_create(hwaddr addr, char
> *hart_config,
> >      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> >      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
> >
> > -    for (i = 0; i < num_harts; i++) {
> > -        CPUState *cpu = qemu_get_cpu(hartid_base + i);
> > +    plic = SIFIVE_PLIC(dev);
> > +    for (i = 0; i < plic->num_addrs; i++) {
> > +        CPUState *cpu = qemu_get_cpu(plic->addr_config[i].hartid);
> >
> > -        qdev_connect_gpio_out(dev, i,
> > -                              qdev_get_gpio_in(DEVICE(cpu),
> IRQ_S_EXT));
> > -        qdev_connect_gpio_out(dev, num_harts + i,
> > -                              qdev_get_gpio_in(DEVICE(cpu),
> IRQ_M_EXT));
> > +        if (plic->addr_config[i].mode == PLICMode_S) {
> > +            qdev_connect_gpio_out(dev, s_count++,
> > +                                  qdev_get_gpio_in(DEVICE(cpu),
> IRQ_S_EXT));
> > +        }
> > +
> > +        if (plic->addr_config[i].mode == PLICMode_M) {
> > +            qdev_connect_gpio_out(dev, num_harts + m_count++,
> > +                                  qdev_get_gpio_in(DEVICE(cpu),
> IRQ_M_EXT));
> > +        }
> >      }
> 
> This PLIC change breaks my 5.11.0 buildroot test case on the SiFive U board
> 
> The boot process just hangs at:
> 
> [    0.542798] usbcore: registered new interface driver usbhid
> [    0.543021] usbhid: USB HID core driver
> [    0.544584] NET: Registered protocol family 10
> [    4.054768] Segment Routing with IPv6
> [    4.055325] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
> [    4.057956] NET: Registered protocol family 17
> [    4.059327] 9pnet: Installing 9P2000 support
> [    4.059787] Key type dns_resolver registered
> [    4.060515] debug_vm_pgtable: [debug_vm_pgtable         ]:
> Validating architecture page table helpers
> [    4.078710] macb 10090000.ethernet eth0: PHY
> [10090000.ethernet-ffffffff:00] driver [Generic PHY] (irq=POLL)
> [    4.079454] macb 10090000.ethernet eth0: configuring for phy/gmii link
> mode
> [    4.087031] macb 10090000.ethernet eth0: Link is Up - 1Gbps/Full -
> flow control tx
> [    4.094634] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
> 
> Alistair

SiFive-u machine cpu 0 is the management hart that does not have S-mode.
The logic here causes an offset of the PLIC S-mode context. When the kernel
driver enables the CPU 1 S-mode interrupt, it shifts to CPU 0. As a result,
the interrupt is lost.

I will fix this bug in the next series.

Yifei

WARNING: multiple messages have this Message-ID (diff)
From: Jiangyifei via <qemu-devel@nongnu.org>
To: Alistair Francis <alistair23@gmail.com>
Cc: "qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	"open list:RISC-V" <qemu-riscv@nongnu.org>,
	"kvm-riscv@lists.infradead.org" <kvm-riscv@lists.infradead.org>,
	"open list:Overall" <kvm@vger.kernel.org>,
	"libvir-list@redhat.com" <libvir-list@redhat.com>,
	Anup Patel <anup@brainfault.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	Bin Meng <bin.meng@windriver.com>,
	"Fanliang (EulerOS)" <fanliang@huawei.com>,
	"Wubin (H)" <wu.wubin@huawei.com>,
	"Wanghaibin (D)" <wanghaibin.wang@huawei.com>,
	"wanbo (G)" <wanbo13@huawei.com>,
	"limingwang (A)" <limingwang@huawei.com>
Subject: RE: [PATCH v4 06/12] target/riscv: Support start kernel directly by KVM
Date: Wed, 12 Jan 2022 08:07:53 +0000	[thread overview]
Message-ID: <b592508d4a034ec5a3aeaf218819803d@huawei.com> (raw)
In-Reply-To: <CAKmqyKPNLSiLP_FGgod=1fa=kUnnkagYBOQD0Bx5O=96AAkhmQ@mail.gmail.com>


> -----Original Message-----
> From: Alistair Francis [mailto:alistair23@gmail.com]
> Sent: Tuesday, January 11, 2022 8:28 AM
> To: Jiangyifei <jiangyifei@huawei.com>
> Cc: qemu-devel@nongnu.org Developers <qemu-devel@nongnu.org>; open
> list:RISC-V <qemu-riscv@nongnu.org>; kvm-riscv@lists.infradead.org; open
> list:Overall <kvm@vger.kernel.org>; libvir-list@redhat.com; Anup Patel
> <anup@brainfault.org>; Palmer Dabbelt <palmer@dabbelt.com>; Alistair
> Francis <Alistair.Francis@wdc.com>; Bin Meng <bin.meng@windriver.com>;
> Fanliang (EulerOS) <fanliang@huawei.com>; Wubin (H)
> <wu.wubin@huawei.com>; Wanghaibin (D) <wanghaibin.wang@huawei.com>;
> wanbo (G) <wanbo13@huawei.com>; limingwang (A)
> <limingwang@huawei.com>
> Subject: Re: [PATCH v4 06/12] target/riscv: Support start kernel directly by KVM
> 
> On Mon, Jan 10, 2022 at 11:52 AM Yifei Jiang via <qemu-devel@nongnu.org>
> wrote:
> >
> > Get kernel and fdt start address in virt.c, and pass them to KVM when
> > cpu reset. Add kvm_riscv.h to place riscv specific interface.
> >
> > In addition, PLIC is created without M-mode PLIC contexts when KVM is
> > enabled.
> >
> > Signed-off-by: Yifei Jiang <jiangyifei@huawei.com>
> > Signed-off-by: Mingwang Li <limingwang@huawei.com>
> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> > ---
> >  hw/intc/sifive_plic.c    | 21 +++++++---
> >  hw/riscv/boot.c          | 16 +++++++-
> >  hw/riscv/virt.c          | 83 ++++++++++++++++++++++++++++------------
> >  include/hw/riscv/boot.h  |  1 +
> >  target/riscv/cpu.c       |  8 ++++
> >  target/riscv/cpu.h       |  3 ++
> >  target/riscv/kvm-stub.c  | 25 ++++++++++++
> >  target/riscv/kvm.c       | 14 +++++++
> >  target/riscv/kvm_riscv.h | 24 ++++++++++++  target/riscv/meson.build
> > |  2 +-
> >  10 files changed, 164 insertions(+), 33 deletions(-)  create mode
> > 100644 target/riscv/kvm-stub.c  create mode 100644
> > target/riscv/kvm_riscv.h
> >
> > diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c index
> > 877e76877c..58c16881cb 100644
> > --- a/hw/intc/sifive_plic.c
> > +++ b/hw/intc/sifive_plic.c
> > @@ -30,6 +30,7 @@
> >  #include "target/riscv/cpu.h"
> >  #include "migration/vmstate.h"
> >  #include "hw/irq.h"
> > +#include "sysemu/kvm.h"
> >
> >  #define RISCV_DEBUG_PLIC 0
> >
> > @@ -533,6 +534,8 @@ DeviceState *sifive_plic_create(hwaddr addr, char
> > *hart_config,  {
> >      DeviceState *dev = qdev_new(TYPE_SIFIVE_PLIC);
> >      int i;
> > +    SiFivePLICState *plic;
> > +    int s_count = 0, m_count = 0;
> >
> >      assert(enable_stride == (enable_stride & -enable_stride));
> >      assert(context_stride == (context_stride & -context_stride)); @@
> > -550,13 +553,19 @@ DeviceState *sifive_plic_create(hwaddr addr, char
> *hart_config,
> >      sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
> >      sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
> >
> > -    for (i = 0; i < num_harts; i++) {
> > -        CPUState *cpu = qemu_get_cpu(hartid_base + i);
> > +    plic = SIFIVE_PLIC(dev);
> > +    for (i = 0; i < plic->num_addrs; i++) {
> > +        CPUState *cpu = qemu_get_cpu(plic->addr_config[i].hartid);
> >
> > -        qdev_connect_gpio_out(dev, i,
> > -                              qdev_get_gpio_in(DEVICE(cpu),
> IRQ_S_EXT));
> > -        qdev_connect_gpio_out(dev, num_harts + i,
> > -                              qdev_get_gpio_in(DEVICE(cpu),
> IRQ_M_EXT));
> > +        if (plic->addr_config[i].mode == PLICMode_S) {
> > +            qdev_connect_gpio_out(dev, s_count++,
> > +                                  qdev_get_gpio_in(DEVICE(cpu),
> IRQ_S_EXT));
> > +        }
> > +
> > +        if (plic->addr_config[i].mode == PLICMode_M) {
> > +            qdev_connect_gpio_out(dev, num_harts + m_count++,
> > +                                  qdev_get_gpio_in(DEVICE(cpu),
> IRQ_M_EXT));
> > +        }
> >      }
> 
> This PLIC change breaks my 5.11.0 buildroot test case on the SiFive U board
> 
> The boot process just hangs at:
> 
> [    0.542798] usbcore: registered new interface driver usbhid
> [    0.543021] usbhid: USB HID core driver
> [    0.544584] NET: Registered protocol family 10
> [    4.054768] Segment Routing with IPv6
> [    4.055325] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver
> [    4.057956] NET: Registered protocol family 17
> [    4.059327] 9pnet: Installing 9P2000 support
> [    4.059787] Key type dns_resolver registered
> [    4.060515] debug_vm_pgtable: [debug_vm_pgtable         ]:
> Validating architecture page table helpers
> [    4.078710] macb 10090000.ethernet eth0: PHY
> [10090000.ethernet-ffffffff:00] driver [Generic PHY] (irq=POLL)
> [    4.079454] macb 10090000.ethernet eth0: configuring for phy/gmii link
> mode
> [    4.087031] macb 10090000.ethernet eth0: Link is Up - 1Gbps/Full -
> flow control tx
> [    4.094634] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
> 
> Alistair

SiFive-u machine cpu 0 is the management hart that does not have S-mode.
The logic here causes an offset of the PLIC S-mode context. When the kernel
driver enables the CPU 1 S-mode interrupt, it shifts to CPU 0. As a result,
the interrupt is lost.

I will fix this bug in the next series.

Yifei

  reply	other threads:[~2022-01-12  8:07 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10  1:38 [PATCH v4 00/12] Add riscv kvm accel support Yifei Jiang
2022-01-10  1:38 ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 01/12] update-linux-headers: Add asm-riscv/kvm.h Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 02/12] target/riscv: Add target/riscv/kvm.c to place the public kvm interface Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10 23:09   ` Alistair Francis
2022-01-10 23:09     ` Alistair Francis
2022-01-12  8:04     ` Jiangyifei
2022-01-12  8:04       ` Jiangyifei via
2022-01-10  1:38 ` [PATCH v4 03/12] target/riscv: Implement function kvm_arch_init_vcpu Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 04/12] target/riscv: Implement kvm_arch_get_registers Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 05/12] target/riscv: Implement kvm_arch_put_registers Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10 23:06   ` Alistair Francis
2022-01-10 23:06     ` Alistair Francis
2022-01-12  8:01     ` Jiangyifei
2022-01-12  8:01       ` Jiangyifei via
2022-01-10  1:38 ` [PATCH v4 06/12] target/riscv: Support start kernel directly by KVM Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-11  0:27   ` Alistair Francis
2022-01-11  0:27     ` Alistair Francis
2022-01-12  8:07     ` Jiangyifei [this message]
2022-01-12  8:07       ` Jiangyifei via
2022-01-10  1:38 ` [PATCH v4 07/12] target/riscv: Support setting external interrupt " Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 08/12] target/riscv: Handle KVM_EXIT_RISCV_SBI exit Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  6:48   ` Alistair Francis
2022-01-10  6:48     ` Alistair Francis
2022-01-10  1:38 ` [PATCH v4 09/12] target/riscv: Add host cpu type Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 10/12] target/riscv: Add kvm_riscv_get/put_regs_timer Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  6:52   ` Alistair Francis
2022-01-10  6:52     ` Alistair Francis
2022-01-10  1:38 ` [PATCH v4 11/12] target/riscv: Implement virtual time adjusting with vm state changing Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via
2022-01-10  1:38 ` [PATCH v4 12/12] target/riscv: Support virtual time context synchronization Yifei Jiang
2022-01-10  1:38   ` Yifei Jiang via

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=b592508d4a034ec5a3aeaf218819803d@huawei.com \
    --to=jiangyifei@huawei.com \
    --cc=Alistair.Francis@wdc.com \
    --cc=alistair23@gmail.com \
    --cc=anup@brainfault.org \
    --cc=bin.meng@windriver.com \
    --cc=fanliang@huawei.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=limingwang@huawei.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=wanbo13@huawei.com \
    --cc=wanghaibin.wang@huawei.com \
    --cc=wu.wubin@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.