Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2023-01-18 Thread Alistair Francis
On Mon, Jan 16, 2023 at 3:20 PM Anup Patel  wrote:
>
> Hi Alistair,
>
> On Tue, Jan 3, 2023 at 9:43 PM Anup Patel  wrote:
> >
> > Hi Alistair,
> >
> > On Wed, Dec 28, 2022 at 11:08 AM Alistair Francis  
> > wrote:
> > >
> > > On Fri, Dec 23, 2022 at 11:14 PM Anup Patel  
> > > wrote:
> > > >
> > > > On Thu, Dec 15, 2022 at 8:55 AM Alistair Francis  
> > > > wrote:
> > > > >
> > > > > On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  
> > > > > wrote:
> > > > > >
> > > > > > On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis 
> > > > > >  wrote:
> > > > > > >
> > > > > > > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel 
> > > > > > >  wrote:
> > > > > > > >
> > > > > > > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis 
> > > > > > > >  wrote:
> > > > > > > > >
> > > > > > > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel 
> > > > > > > > >  wrote:
> > > > > > > > > >
> > > > > > > > > > The htimedelta[h] CSR has impact on the VS timer comparison 
> > > > > > > > > > so we
> > > > > > > > > > should call riscv_timer_write_timecmp() whenever htimedelta 
> > > > > > > > > > changes.
> > > > > > > > > >
> > > > > > > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > > > > > > Signed-off-by: Anup Patel 
> > > > > > > > > > Reviewed-by: Alistair Francis 
> > > > > > > > >
> > > > > > > > > This patch breaks my Xvisor test. When running OpenSBI and 
> > > > > > > > > Xvisor like this:
> > > > > > > > >
> > > > > > > > > qemu-system-riscv64 -machine virt \
> > > > > > > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > > > > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount 
> > > > > > > > > initrd
> > > > > > > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest 
> > > > > > > > > kick guest0;
> > > > > > > > > vserial bind guest0/uart0"' \
> > > > > > > > > -smp 4 -d guest_errors \
> > > > > > > > > -bios none \
> > > > > > > > > -device 
> > > > > > > > > loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > > > > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > > > > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu 
> > > > > > > > > rv64,h=true
> > > > > > > > >
> > > > > > > > > Running:
> > > > > > > > >
> > > > > > > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > > > > > > >
> > > > > > > > > I see this failure:
> > > > > > > > >
> > > > > > > > > INIT: bootcmd:  guest kick guest0
> > > > > > > > >
> > > > > > > > > guest0: Kicked
> > > > > > > > >
> > > > > > > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > > > > > > >
> > > > > > > > > [guest0/uart0] cpu_vcpu_stage2_map: 
> > > > > > > > > guest_phys=0x3B9AC000
> > > > > > > > > size=0x4096 map failed
> > > > > > > > >
> > > > > > > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > > > > > > >
> > > > > > > > >zero=0x  ra=0x80001B4E
> > > > > > > > >
> > > > > > > > >  sp=0x8001CF80  gp=0x
> > > > > > > > >
> > > > > > > > >  tp=0x  s0=0x8001CFB0
> > > > > > > > >
> > > > > > > > >  s1=0x  a0=0x10001048
> > > > > > > > >
> > > > > > > > >  a1=0x  a2=0x00989680
> > > > > > > > >
> > > > > > > > >  a3=0x3B9ACA00  a4=0x0048
> > > > > > > > >
> > > > > > > > >  a5=0x  a6=0x00019000
> > > > > > > > >
> > > > > > > > >  a7=0x  s2=0x
> > > > > > > > >
> > > > > > > > >  s3=0x  s4=0x
> > > > > > > > >
> > > > > > > > >  s5=0x  s6=0x
> > > > > > > > >
> > > > > > > > >  s7=0x  s8=0x
> > > > > > > > >
> > > > > > > > >  s9=0x s10=0x
> > > > > > > > >
> > > > > > > > > s11=0x  t0=0x4000
> > > > > > > > >
> > > > > > > > >  t1=0x0100  t2=0x
> > > > > > > > >
> > > > > > > > >  t3=0x  t4=0x
> > > > > > > > >
> > > > > > > > >  t5=0x  t6=0x
> > > > > > > > >
> > > > > > > > >sepc=0x80001918 sstatus=0x00024120
> > > > > > > > >
> > > > > > > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > > > > > > >
> > > > > > > > >  scause=0x0017   stval=0x3B9ACAF8
> > > > > > > > >
> > > > > > > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > > > > > > >
> > > > > > > > > I have tried updating to a newer Xvisor release, but with 
> > > > > > > > > that I don't
> > > > > > > > > get any serial output.
> > > > > > > > >
> > > > > > > > > Can 

Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2023-01-15 Thread Anup Patel
Hi Alistair,

On Tue, Jan 3, 2023 at 9:43 PM Anup Patel  wrote:
>
> Hi Alistair,
>
> On Wed, Dec 28, 2022 at 11:08 AM Alistair Francis  
> wrote:
> >
> > On Fri, Dec 23, 2022 at 11:14 PM Anup Patel  wrote:
> > >
> > > On Thu, Dec 15, 2022 at 8:55 AM Alistair Francis  
> > > wrote:
> > > >
> > > > On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  
> > > > wrote:
> > > > >
> > > > > On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis 
> > > > >  wrote:
> > > > > >
> > > > > > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  
> > > > > > wrote:
> > > > > > >
> > > > > > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis 
> > > > > > >  wrote:
> > > > > > > >
> > > > > > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel 
> > > > > > > >  wrote:
> > > > > > > > >
> > > > > > > > > The htimedelta[h] CSR has impact on the VS timer comparison 
> > > > > > > > > so we
> > > > > > > > > should call riscv_timer_write_timecmp() whenever htimedelta 
> > > > > > > > > changes.
> > > > > > > > >
> > > > > > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > > > > > Signed-off-by: Anup Patel 
> > > > > > > > > Reviewed-by: Alistair Francis 
> > > > > > > >
> > > > > > > > This patch breaks my Xvisor test. When running OpenSBI and 
> > > > > > > > Xvisor like this:
> > > > > > > >
> > > > > > > > qemu-system-riscv64 -machine virt \
> > > > > > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > > > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount 
> > > > > > > > initrd
> > > > > > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick 
> > > > > > > > guest0;
> > > > > > > > vserial bind guest0/uart0"' \
> > > > > > > > -smp 4 -d guest_errors \
> > > > > > > > -bios none \
> > > > > > > > -device 
> > > > > > > > loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > > > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > > > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu 
> > > > > > > > rv64,h=true
> > > > > > > >
> > > > > > > > Running:
> > > > > > > >
> > > > > > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > > > > > >
> > > > > > > > I see this failure:
> > > > > > > >
> > > > > > > > INIT: bootcmd:  guest kick guest0
> > > > > > > >
> > > > > > > > guest0: Kicked
> > > > > > > >
> > > > > > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > > > > > >
> > > > > > > > [guest0/uart0] cpu_vcpu_stage2_map: 
> > > > > > > > guest_phys=0x3B9AC000
> > > > > > > > size=0x4096 map failed
> > > > > > > >
> > > > > > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > > > > > >
> > > > > > > >zero=0x  ra=0x80001B4E
> > > > > > > >
> > > > > > > >  sp=0x8001CF80  gp=0x
> > > > > > > >
> > > > > > > >  tp=0x  s0=0x8001CFB0
> > > > > > > >
> > > > > > > >  s1=0x  a0=0x10001048
> > > > > > > >
> > > > > > > >  a1=0x  a2=0x00989680
> > > > > > > >
> > > > > > > >  a3=0x3B9ACA00  a4=0x0048
> > > > > > > >
> > > > > > > >  a5=0x  a6=0x00019000
> > > > > > > >
> > > > > > > >  a7=0x  s2=0x
> > > > > > > >
> > > > > > > >  s3=0x  s4=0x
> > > > > > > >
> > > > > > > >  s5=0x  s6=0x
> > > > > > > >
> > > > > > > >  s7=0x  s8=0x
> > > > > > > >
> > > > > > > >  s9=0x s10=0x
> > > > > > > >
> > > > > > > > s11=0x  t0=0x4000
> > > > > > > >
> > > > > > > >  t1=0x0100  t2=0x
> > > > > > > >
> > > > > > > >  t3=0x  t4=0x
> > > > > > > >
> > > > > > > >  t5=0x  t6=0x
> > > > > > > >
> > > > > > > >sepc=0x80001918 sstatus=0x00024120
> > > > > > > >
> > > > > > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > > > > > >
> > > > > > > >  scause=0x0017   stval=0x3B9ACAF8
> > > > > > > >
> > > > > > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > > > > > >
> > > > > > > > I have tried updating to a newer Xvisor release, but with that 
> > > > > > > > I don't
> > > > > > > > get any serial output.
> > > > > > > >
> > > > > > > > Can you help get the Xvisor tests back up and running?
> > > > > > >
> > > > > > > I tried the latest Xvisor-next 
> > > > > > > (https://github.com/avpatel/xvisor-next)
> > > > > > > with your QEMU riscv-to-apply.next branch and it works fine (both
> > > > > > > with and without Sstc).
> > > > > >
> > 

Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2023-01-03 Thread Anup Patel
Hi Alistair,

On Wed, Dec 28, 2022 at 11:08 AM Alistair Francis  wrote:
>
> On Fri, Dec 23, 2022 at 11:14 PM Anup Patel  wrote:
> >
> > On Thu, Dec 15, 2022 at 8:55 AM Alistair Francis  
> > wrote:
> > >
> > > On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  
> > > wrote:
> > > >
> > > > On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis 
> > > >  wrote:
> > > > >
> > > > > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  
> > > > > wrote:
> > > > > >
> > > > > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis 
> > > > > >  wrote:
> > > > > > >
> > > > > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel 
> > > > > > >  wrote:
> > > > > > > >
> > > > > > > > The htimedelta[h] CSR has impact on the VS timer comparison so 
> > > > > > > > we
> > > > > > > > should call riscv_timer_write_timecmp() whenever htimedelta 
> > > > > > > > changes.
> > > > > > > >
> > > > > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > > > > Signed-off-by: Anup Patel 
> > > > > > > > Reviewed-by: Alistair Francis 
> > > > > > >
> > > > > > > This patch breaks my Xvisor test. When running OpenSBI and Xvisor 
> > > > > > > like this:
> > > > > > >
> > > > > > > qemu-system-riscv64 -machine virt \
> > > > > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount 
> > > > > > > initrd
> > > > > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick 
> > > > > > > guest0;
> > > > > > > vserial bind guest0/uart0"' \
> > > > > > > -smp 4 -d guest_errors \
> > > > > > > -bios none \
> > > > > > > -device 
> > > > > > > loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu 
> > > > > > > rv64,h=true
> > > > > > >
> > > > > > > Running:
> > > > > > >
> > > > > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > > > > >
> > > > > > > I see this failure:
> > > > > > >
> > > > > > > INIT: bootcmd:  guest kick guest0
> > > > > > >
> > > > > > > guest0: Kicked
> > > > > > >
> > > > > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > > > > >
> > > > > > > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > > > > > > size=0x4096 map failed
> > > > > > >
> > > > > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > > > > >
> > > > > > >zero=0x  ra=0x80001B4E
> > > > > > >
> > > > > > >  sp=0x8001CF80  gp=0x
> > > > > > >
> > > > > > >  tp=0x  s0=0x8001CFB0
> > > > > > >
> > > > > > >  s1=0x  a0=0x10001048
> > > > > > >
> > > > > > >  a1=0x  a2=0x00989680
> > > > > > >
> > > > > > >  a3=0x3B9ACA00  a4=0x0048
> > > > > > >
> > > > > > >  a5=0x  a6=0x00019000
> > > > > > >
> > > > > > >  a7=0x  s2=0x
> > > > > > >
> > > > > > >  s3=0x  s4=0x
> > > > > > >
> > > > > > >  s5=0x  s6=0x
> > > > > > >
> > > > > > >  s7=0x  s8=0x
> > > > > > >
> > > > > > >  s9=0x s10=0x
> > > > > > >
> > > > > > > s11=0x  t0=0x4000
> > > > > > >
> > > > > > >  t1=0x0100  t2=0x
> > > > > > >
> > > > > > >  t3=0x  t4=0x
> > > > > > >
> > > > > > >  t5=0x  t6=0x
> > > > > > >
> > > > > > >sepc=0x80001918 sstatus=0x00024120
> > > > > > >
> > > > > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > > > > >
> > > > > > >  scause=0x0017   stval=0x3B9ACAF8
> > > > > > >
> > > > > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > > > > >
> > > > > > > I have tried updating to a newer Xvisor release, but with that I 
> > > > > > > don't
> > > > > > > get any serial output.
> > > > > > >
> > > > > > > Can you help get the Xvisor tests back up and running?
> > > > > >
> > > > > > I tried the latest Xvisor-next 
> > > > > > (https://github.com/avpatel/xvisor-next)
> > > > > > with your QEMU riscv-to-apply.next branch and it works fine (both
> > > > > > with and without Sstc).
> > > > >
> > > > > Does it work with the latest release?
> > > >
> > > > Yes, the latest Xvisor-next repo works for QEMU v7.2.0-rc4 and
> > > > your riscv-to-apply.next branch (commit 51bb9de2d188)
> > >
> > > I can't get anything to work with this patch. I have dropped this and
> > > the patches after this.
> > >
> > > I'm building 

Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-27 Thread Alistair Francis
On Fri, Dec 23, 2022 at 11:14 PM Anup Patel  wrote:
>
> On Thu, Dec 15, 2022 at 8:55 AM Alistair Francis  wrote:
> >
> > On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  wrote:
> > >
> > > On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis  
> > > wrote:
> > > >
> > > > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  
> > > > wrote:
> > > > >
> > > > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis 
> > > > >  wrote:
> > > > > >
> > > > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel 
> > > > > >  wrote:
> > > > > > >
> > > > > > > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > > > > > > should call riscv_timer_write_timecmp() whenever htimedelta 
> > > > > > > changes.
> > > > > > >
> > > > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > > > Signed-off-by: Anup Patel 
> > > > > > > Reviewed-by: Alistair Francis 
> > > > > >
> > > > > > This patch breaks my Xvisor test. When running OpenSBI and Xvisor 
> > > > > > like this:
> > > > > >
> > > > > > qemu-system-riscv64 -machine virt \
> > > > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> > > > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick 
> > > > > > guest0;
> > > > > > vserial bind guest0/uart0"' \
> > > > > > -smp 4 -d guest_errors \
> > > > > > -bios none \
> > > > > > -device 
> > > > > > loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
> > > > > >
> > > > > > Running:
> > > > > >
> > > > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > > > >
> > > > > > I see this failure:
> > > > > >
> > > > > > INIT: bootcmd:  guest kick guest0
> > > > > >
> > > > > > guest0: Kicked
> > > > > >
> > > > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > > > >
> > > > > > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > > > > > size=0x4096 map failed
> > > > > >
> > > > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > > > >
> > > > > >zero=0x  ra=0x80001B4E
> > > > > >
> > > > > >  sp=0x8001CF80  gp=0x
> > > > > >
> > > > > >  tp=0x  s0=0x8001CFB0
> > > > > >
> > > > > >  s1=0x  a0=0x10001048
> > > > > >
> > > > > >  a1=0x  a2=0x00989680
> > > > > >
> > > > > >  a3=0x3B9ACA00  a4=0x0048
> > > > > >
> > > > > >  a5=0x  a6=0x00019000
> > > > > >
> > > > > >  a7=0x  s2=0x
> > > > > >
> > > > > >  s3=0x  s4=0x
> > > > > >
> > > > > >  s5=0x  s6=0x
> > > > > >
> > > > > >  s7=0x  s8=0x
> > > > > >
> > > > > >  s9=0x s10=0x
> > > > > >
> > > > > > s11=0x  t0=0x4000
> > > > > >
> > > > > >  t1=0x0100  t2=0x
> > > > > >
> > > > > >  t3=0x  t4=0x
> > > > > >
> > > > > >  t5=0x  t6=0x
> > > > > >
> > > > > >sepc=0x80001918 sstatus=0x00024120
> > > > > >
> > > > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > > > >
> > > > > >  scause=0x0017   stval=0x3B9ACAF8
> > > > > >
> > > > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > > > >
> > > > > > I have tried updating to a newer Xvisor release, but with that I 
> > > > > > don't
> > > > > > get any serial output.
> > > > > >
> > > > > > Can you help get the Xvisor tests back up and running?
> > > > >
> > > > > I tried the latest Xvisor-next 
> > > > > (https://github.com/avpatel/xvisor-next)
> > > > > with your QEMU riscv-to-apply.next branch and it works fine (both
> > > > > with and without Sstc).
> > > >
> > > > Does it work with the latest release?
> > >
> > > Yes, the latest Xvisor-next repo works for QEMU v7.2.0-rc4 and
> > > your riscv-to-apply.next branch (commit 51bb9de2d188)
> >
> > I can't get anything to work with this patch. I have dropped this and
> > the patches after this.
> >
> > I'm building the latest Xvisor release with:
> >
> > export CROSS_COMPILE=riscv64-linux-gnu-
> > ARCH=riscv make generic-64b-defconfig
> > make
> >
> > and running it as above, yet nothing. What am I missing here?
>
> I tried multiple times with the latest Xvisor on different machines but
> still can't reproduce the issue you are seeing.

Odd

>
> We generally provide pre-built 

Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-23 Thread Anup Patel
On Thu, Dec 15, 2022 at 8:55 AM Alistair Francis  wrote:
>
> On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  wrote:
> >
> > On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis  
> > wrote:
> > >
> > > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  wrote:
> > > >
> > > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis  
> > > > wrote:
> > > > >
> > > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  
> > > > > wrote:
> > > > > >
> > > > > > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > > > > > should call riscv_timer_write_timecmp() whenever htimedelta changes.
> > > > > >
> > > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > > Signed-off-by: Anup Patel 
> > > > > > Reviewed-by: Alistair Francis 
> > > > >
> > > > > This patch breaks my Xvisor test. When running OpenSBI and Xvisor 
> > > > > like this:
> > > > >
> > > > > qemu-system-riscv64 -machine virt \
> > > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> > > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
> > > > > vserial bind guest0/uart0"' \
> > > > > -smp 4 -d guest_errors \
> > > > > -bios none \
> > > > > -device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
> > > > >
> > > > > Running:
> > > > >
> > > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > > >
> > > > > I see this failure:
> > > > >
> > > > > INIT: bootcmd:  guest kick guest0
> > > > >
> > > > > guest0: Kicked
> > > > >
> > > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > > >
> > > > > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > > > > size=0x4096 map failed
> > > > >
> > > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > > >
> > > > >zero=0x  ra=0x80001B4E
> > > > >
> > > > >  sp=0x8001CF80  gp=0x
> > > > >
> > > > >  tp=0x  s0=0x8001CFB0
> > > > >
> > > > >  s1=0x  a0=0x10001048
> > > > >
> > > > >  a1=0x  a2=0x00989680
> > > > >
> > > > >  a3=0x3B9ACA00  a4=0x0048
> > > > >
> > > > >  a5=0x  a6=0x00019000
> > > > >
> > > > >  a7=0x  s2=0x
> > > > >
> > > > >  s3=0x  s4=0x
> > > > >
> > > > >  s5=0x  s6=0x
> > > > >
> > > > >  s7=0x  s8=0x
> > > > >
> > > > >  s9=0x s10=0x
> > > > >
> > > > > s11=0x  t0=0x4000
> > > > >
> > > > >  t1=0x0100  t2=0x
> > > > >
> > > > >  t3=0x  t4=0x
> > > > >
> > > > >  t5=0x  t6=0x
> > > > >
> > > > >sepc=0x80001918 sstatus=0x00024120
> > > > >
> > > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > > >
> > > > >  scause=0x0017   stval=0x3B9ACAF8
> > > > >
> > > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > > >
> > > > > I have tried updating to a newer Xvisor release, but with that I don't
> > > > > get any serial output.
> > > > >
> > > > > Can you help get the Xvisor tests back up and running?
> > > >
> > > > I tried the latest Xvisor-next (https://github.com/avpatel/xvisor-next)
> > > > with your QEMU riscv-to-apply.next branch and it works fine (both
> > > > with and without Sstc).
> > >
> > > Does it work with the latest release?
> >
> > Yes, the latest Xvisor-next repo works for QEMU v7.2.0-rc4 and
> > your riscv-to-apply.next branch (commit 51bb9de2d188)
>
> I can't get anything to work with this patch. I have dropped this and
> the patches after this.
>
> I'm building the latest Xvisor release with:
>
> export CROSS_COMPILE=riscv64-linux-gnu-
> ARCH=riscv make generic-64b-defconfig
> make
>
> and running it as above, yet nothing. What am I missing here?

I tried multiple times with the latest Xvisor on different machines but
still can't reproduce the issue you are seeing.

We generally provide pre-built binaries with every Xvisor release
so I will share with you pre-built binaries of the upcoming Xvisor-0.3.2
release. Maybe that would help you ?

Regards,
Anup

>
> Alistair
>
> >
> > Regards,
> > Anup
> >
> > >
> > > Alistair
> > >
> > > >
> > > > Here's the QEMU command which I use:
> > > >
> > > > qemu-system-riscv64 -M virt -m 512M -nographic \
> > > > -bios 

Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-14 Thread Alistair Francis
On Mon, Dec 12, 2022 at 9:12 PM Anup Patel  wrote:
>
> On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis  
> wrote:
> >
> > On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  wrote:
> > >
> > > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis  
> > > wrote:
> > > >
> > > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  
> > > > wrote:
> > > > >
> > > > > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > > > > should call riscv_timer_write_timecmp() whenever htimedelta changes.
> > > > >
> > > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > > Signed-off-by: Anup Patel 
> > > > > Reviewed-by: Alistair Francis 
> > > >
> > > > This patch breaks my Xvisor test. When running OpenSBI and Xvisor like 
> > > > this:
> > > >
> > > > qemu-system-riscv64 -machine virt \
> > > > -m 1G -serial mon:stdio -serial null -nographic \
> > > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> > > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
> > > > vserial bind guest0/uart0"' \
> > > > -smp 4 -d guest_errors \
> > > > -bios none \
> > > > -device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
> > > >
> > > > Running:
> > > >
> > > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > > >
> > > > I see this failure:
> > > >
> > > > INIT: bootcmd:  guest kick guest0
> > > >
> > > > guest0: Kicked
> > > >
> > > > INIT: bootcmd:  vserial bind guest0/uart0
> > > >
> > > > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > > > size=0x4096 map failed
> > > >
> > > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > > >
> > > >zero=0x  ra=0x80001B4E
> > > >
> > > >  sp=0x8001CF80  gp=0x
> > > >
> > > >  tp=0x  s0=0x8001CFB0
> > > >
> > > >  s1=0x  a0=0x10001048
> > > >
> > > >  a1=0x  a2=0x00989680
> > > >
> > > >  a3=0x3B9ACA00  a4=0x0048
> > > >
> > > >  a5=0x  a6=0x00019000
> > > >
> > > >  a7=0x  s2=0x
> > > >
> > > >  s3=0x  s4=0x
> > > >
> > > >  s5=0x  s6=0x
> > > >
> > > >  s7=0x  s8=0x
> > > >
> > > >  s9=0x s10=0x
> > > >
> > > > s11=0x  t0=0x4000
> > > >
> > > >  t1=0x0100  t2=0x
> > > >
> > > >  t3=0x  t4=0x
> > > >
> > > >  t5=0x  t6=0x
> > > >
> > > >sepc=0x80001918 sstatus=0x00024120
> > > >
> > > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > > >
> > > >  scause=0x0017   stval=0x3B9ACAF8
> > > >
> > > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > > >
> > > > I have tried updating to a newer Xvisor release, but with that I don't
> > > > get any serial output.
> > > >
> > > > Can you help get the Xvisor tests back up and running?
> > >
> > > I tried the latest Xvisor-next (https://github.com/avpatel/xvisor-next)
> > > with your QEMU riscv-to-apply.next branch and it works fine (both
> > > with and without Sstc).
> >
> > Does it work with the latest release?
>
> Yes, the latest Xvisor-next repo works for QEMU v7.2.0-rc4 and
> your riscv-to-apply.next branch (commit 51bb9de2d188)

I can't get anything to work with this patch. I have dropped this and
the patches after this.

I'm building the latest Xvisor release with:

export CROSS_COMPILE=riscv64-linux-gnu-
ARCH=riscv make generic-64b-defconfig
make

and running it as above, yet nothing. What am I missing here?

Alistair

>
> Regards,
> Anup
>
> >
> > Alistair
> >
> > >
> > > Here's the QEMU command which I use:
> > >
> > > qemu-system-riscv64 -M virt -m 512M -nographic \
> > > -bios opensbi/build/platform/generic/firmware/fw_jump.bin \
> > > -kernel ../xvisor-next/build/vmm.bin \
> > > -initrd rbd_v64.img \
> > > -append "vmm.bootcmd=\"vfs mount initrd /;vfs run /boot.xscript;vfs
> > > cat /system/banner.txt\"" \
> > > -smp 4
> > >
> > > Also, I will be releasing Xvisor-0.3.2 by the end of Dec 2022 so I
> > > suggest using this upcoming release in your test.
> > >
> > > Regards,
> > > Anup



Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-12 Thread Anup Patel
On Mon, Dec 12, 2022 at 11:23 AM Alistair Francis  wrote:
>
> On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  wrote:
> >
> > On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis  
> > wrote:
> > >
> > > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  
> > > wrote:
> > > >
> > > > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > > > should call riscv_timer_write_timecmp() whenever htimedelta changes.
> > > >
> > > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > > Signed-off-by: Anup Patel 
> > > > Reviewed-by: Alistair Francis 
> > >
> > > This patch breaks my Xvisor test. When running OpenSBI and Xvisor like 
> > > this:
> > >
> > > qemu-system-riscv64 -machine virt \
> > > -m 1G -serial mon:stdio -serial null -nographic \
> > > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> > > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
> > > vserial bind guest0/uart0"' \
> > > -smp 4 -d guest_errors \
> > > -bios none \
> > > -device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > > -kernel ./images/qemuriscv64/fw_jump.elf \
> > > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
> > >
> > > Running:
> > >
> > > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> > >
> > > I see this failure:
> > >
> > > INIT: bootcmd:  guest kick guest0
> > >
> > > guest0: Kicked
> > >
> > > INIT: bootcmd:  vserial bind guest0/uart0
> > >
> > > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > > size=0x4096 map failed
> > >
> > > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> > >
> > >zero=0x  ra=0x80001B4E
> > >
> > >  sp=0x8001CF80  gp=0x
> > >
> > >  tp=0x  s0=0x8001CFB0
> > >
> > >  s1=0x  a0=0x10001048
> > >
> > >  a1=0x  a2=0x00989680
> > >
> > >  a3=0x3B9ACA00  a4=0x0048
> > >
> > >  a5=0x  a6=0x00019000
> > >
> > >  a7=0x  s2=0x
> > >
> > >  s3=0x  s4=0x
> > >
> > >  s5=0x  s6=0x
> > >
> > >  s7=0x  s8=0x
> > >
> > >  s9=0x s10=0x
> > >
> > > s11=0x  t0=0x4000
> > >
> > >  t1=0x0100  t2=0x
> > >
> > >  t3=0x  t4=0x
> > >
> > >  t5=0x  t6=0x
> > >
> > >sepc=0x80001918 sstatus=0x00024120
> > >
> > > hstatus=0x0002002001C0 sp_exec=0x10A64000
> > >
> > >  scause=0x0017   stval=0x3B9ACAF8
> > >
> > >   htval=0x0EE6B2BE  htinst=0x00D03021
> > >
> > > I have tried updating to a newer Xvisor release, but with that I don't
> > > get any serial output.
> > >
> > > Can you help get the Xvisor tests back up and running?
> >
> > I tried the latest Xvisor-next (https://github.com/avpatel/xvisor-next)
> > with your QEMU riscv-to-apply.next branch and it works fine (both
> > with and without Sstc).
>
> Does it work with the latest release?

Yes, the latest Xvisor-next repo works for QEMU v7.2.0-rc4 and
your riscv-to-apply.next branch (commit 51bb9de2d188)

Regards,
Anup

>
> Alistair
>
> >
> > Here's the QEMU command which I use:
> >
> > qemu-system-riscv64 -M virt -m 512M -nographic \
> > -bios opensbi/build/platform/generic/firmware/fw_jump.bin \
> > -kernel ../xvisor-next/build/vmm.bin \
> > -initrd rbd_v64.img \
> > -append "vmm.bootcmd=\"vfs mount initrd /;vfs run /boot.xscript;vfs
> > cat /system/banner.txt\"" \
> > -smp 4
> >
> > Also, I will be releasing Xvisor-0.3.2 by the end of Dec 2022 so I
> > suggest using this upcoming release in your test.
> >
> > Regards,
> > Anup



Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-11 Thread Alistair Francis
On Thu, Dec 8, 2022 at 6:41 PM Anup Patel  wrote:
>
> On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis  wrote:
> >
> > On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  wrote:
> > >
> > > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > > should call riscv_timer_write_timecmp() whenever htimedelta changes.
> > >
> > > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > > Signed-off-by: Anup Patel 
> > > Reviewed-by: Alistair Francis 
> >
> > This patch breaks my Xvisor test. When running OpenSBI and Xvisor like this:
> >
> > qemu-system-riscv64 -machine virt \
> > -m 1G -serial mon:stdio -serial null -nographic \
> > -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> > /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
> > vserial bind guest0/uart0"' \
> > -smp 4 -d guest_errors \
> > -bios none \
> > -device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> > -kernel ./images/qemuriscv64/fw_jump.elf \
> > -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
> >
> > Running:
> >
> > Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
> >
> > I see this failure:
> >
> > INIT: bootcmd:  guest kick guest0
> >
> > guest0: Kicked
> >
> > INIT: bootcmd:  vserial bind guest0/uart0
> >
> > [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> > size=0x4096 map failed
> >
> > do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
> >
> >zero=0x  ra=0x80001B4E
> >
> >  sp=0x8001CF80  gp=0x
> >
> >  tp=0x  s0=0x8001CFB0
> >
> >  s1=0x  a0=0x10001048
> >
> >  a1=0x  a2=0x00989680
> >
> >  a3=0x3B9ACA00  a4=0x0048
> >
> >  a5=0x  a6=0x00019000
> >
> >  a7=0x  s2=0x
> >
> >  s3=0x  s4=0x
> >
> >  s5=0x  s6=0x
> >
> >  s7=0x  s8=0x
> >
> >  s9=0x s10=0x
> >
> > s11=0x  t0=0x4000
> >
> >  t1=0x0100  t2=0x
> >
> >  t3=0x  t4=0x
> >
> >  t5=0x  t6=0x
> >
> >sepc=0x80001918 sstatus=0x00024120
> >
> > hstatus=0x0002002001C0 sp_exec=0x10A64000
> >
> >  scause=0x0017   stval=0x3B9ACAF8
> >
> >   htval=0x0EE6B2BE  htinst=0x00D03021
> >
> > I have tried updating to a newer Xvisor release, but with that I don't
> > get any serial output.
> >
> > Can you help get the Xvisor tests back up and running?
>
> I tried the latest Xvisor-next (https://github.com/avpatel/xvisor-next)
> with your QEMU riscv-to-apply.next branch and it works fine (both
> with and without Sstc).

Does it work with the latest release?

Alistair

>
> Here's the QEMU command which I use:
>
> qemu-system-riscv64 -M virt -m 512M -nographic \
> -bios opensbi/build/platform/generic/firmware/fw_jump.bin \
> -kernel ../xvisor-next/build/vmm.bin \
> -initrd rbd_v64.img \
> -append "vmm.bootcmd=\"vfs mount initrd /;vfs run /boot.xscript;vfs
> cat /system/banner.txt\"" \
> -smp 4
>
> Also, I will be releasing Xvisor-0.3.2 by the end of Dec 2022 so I
> suggest using this upcoming release in your test.
>
> Regards,
> Anup



Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-08 Thread Anup Patel
On Thu, Dec 8, 2022 at 9:00 AM Alistair Francis  wrote:
>
> On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  wrote:
> >
> > The htimedelta[h] CSR has impact on the VS timer comparison so we
> > should call riscv_timer_write_timecmp() whenever htimedelta changes.
> >
> > Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> > Signed-off-by: Anup Patel 
> > Reviewed-by: Alistair Francis 
>
> This patch breaks my Xvisor test. When running OpenSBI and Xvisor like this:
>
> qemu-system-riscv64 -machine virt \
> -m 1G -serial mon:stdio -serial null -nographic \
> -append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
> /;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
> vserial bind guest0/uart0"' \
> -smp 4 -d guest_errors \
> -bios none \
> -device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
> -kernel ./images/qemuriscv64/fw_jump.elf \
> -initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true
>
> Running:
>
> Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)
>
> I see this failure:
>
> INIT: bootcmd:  guest kick guest0
>
> guest0: Kicked
>
> INIT: bootcmd:  vserial bind guest0/uart0
>
> [guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
> size=0x4096 map failed
>
> do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)
>
>zero=0x  ra=0x80001B4E
>
>  sp=0x8001CF80  gp=0x
>
>  tp=0x  s0=0x8001CFB0
>
>  s1=0x  a0=0x10001048
>
>  a1=0x  a2=0x00989680
>
>  a3=0x3B9ACA00  a4=0x0048
>
>  a5=0x  a6=0x00019000
>
>  a7=0x  s2=0x
>
>  s3=0x  s4=0x
>
>  s5=0x  s6=0x
>
>  s7=0x  s8=0x
>
>  s9=0x s10=0x
>
> s11=0x  t0=0x4000
>
>  t1=0x0100  t2=0x
>
>  t3=0x  t4=0x
>
>  t5=0x  t6=0x
>
>sepc=0x80001918 sstatus=0x00024120
>
> hstatus=0x0002002001C0 sp_exec=0x10A64000
>
>  scause=0x0017   stval=0x3B9ACAF8
>
>   htval=0x0EE6B2BE  htinst=0x00D03021
>
> I have tried updating to a newer Xvisor release, but with that I don't
> get any serial output.
>
> Can you help get the Xvisor tests back up and running?

I tried the latest Xvisor-next (https://github.com/avpatel/xvisor-next)
with your QEMU riscv-to-apply.next branch and it works fine (both
with and without Sstc).

Here's the QEMU command which I use:

qemu-system-riscv64 -M virt -m 512M -nographic \
-bios opensbi/build/platform/generic/firmware/fw_jump.bin \
-kernel ../xvisor-next/build/vmm.bin \
-initrd rbd_v64.img \
-append "vmm.bootcmd=\"vfs mount initrd /;vfs run /boot.xscript;vfs
cat /system/banner.txt\"" \
-smp 4

Also, I will be releasing Xvisor-0.3.2 by the end of Dec 2022 so I
suggest using this upcoming release in your test.

Regards,
Anup



Re: [PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-12-07 Thread Alistair Francis
On Tue, Nov 8, 2022 at 11:07 PM Anup Patel  wrote:
>
> The htimedelta[h] CSR has impact on the VS timer comparison so we
> should call riscv_timer_write_timecmp() whenever htimedelta changes.
>
> Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
> Signed-off-by: Anup Patel 
> Reviewed-by: Alistair Francis 

This patch breaks my Xvisor test. When running OpenSBI and Xvisor like this:

qemu-system-riscv64 -machine virt \
-m 1G -serial mon:stdio -serial null -nographic \
-append 'vmm.console=uart@1000 vmm.bootcmd="vfs mount initrd
/;vfs run /boot.xscript;vfs cat /system/banner.txt; guest kick guest0;
vserial bind guest0/uart0"' \
-smp 4 -d guest_errors \
-bios none \
-device loader,file=./images/qemuriscv64/vmm.bin,addr=0x8020 \
-kernel ./images/qemuriscv64/fw_jump.elf \
-initrd ./images/qemuriscv64/vmm-disk-linux.img -cpu rv64,h=true

Running:

Xvisor v0.3.0-129-gbc33f339 (Jan  1 1970 00:00:00)

I see this failure:

INIT: bootcmd:  guest kick guest0

guest0: Kicked

INIT: bootcmd:  vserial bind guest0/uart0

[guest0/uart0] cpu_vcpu_stage2_map: guest_phys=0x3B9AC000
size=0x4096 map failed

do_error: CPU3: VCPU=guest0/vcpu0 page fault failed (error -1)

   zero=0x  ra=0x80001B4E

 sp=0x8001CF80  gp=0x

 tp=0x  s0=0x8001CFB0

 s1=0x  a0=0x10001048

 a1=0x  a2=0x00989680

 a3=0x3B9ACA00  a4=0x0048

 a5=0x  a6=0x00019000

 a7=0x  s2=0x

 s3=0x  s4=0x

 s5=0x  s6=0x

 s7=0x  s8=0x

 s9=0x s10=0x

s11=0x  t0=0x4000

 t1=0x0100  t2=0x

 t3=0x  t4=0x

 t5=0x  t6=0x

   sepc=0x80001918 sstatus=0x00024120

hstatus=0x0002002001C0 sp_exec=0x10A64000

 scause=0x0017   stval=0x3B9ACAF8

  htval=0x0EE6B2BE  htinst=0x00D03021

I have tried updating to a newer Xvisor release, but with that I don't
get any serial output.

Can you help get the Xvisor tests back up and running?

Alistair



[PATCH v2 2/5] target/riscv: Update VS timer whenever htimedelta changes

2022-11-08 Thread Anup Patel
The htimedelta[h] CSR has impact on the VS timer comparison so we
should call riscv_timer_write_timecmp() whenever htimedelta changes.

Fixes: 3ec0fe18a31f ("target/riscv: Add vstimecmp suppor")
Signed-off-by: Anup Patel 
Reviewed-by: Alistair Francis 
---
 target/riscv/csr.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 716f9d960e..4b1a608260 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -2722,6 +2722,8 @@ static RISCVException read_htimedelta(CPURISCVState *env, 
int csrno,
 static RISCVException write_htimedelta(CPURISCVState *env, int csrno,
target_ulong val)
 {
+RISCVCPU *cpu = env_archcpu(env);
+
 if (!env->rdtime_fn) {
 return RISCV_EXCP_ILLEGAL_INST;
 }
@@ -2731,6 +2733,12 @@ static RISCVException write_htimedelta(CPURISCVState 
*env, int csrno,
 } else {
 env->htimedelta = val;
 }
+
+if (cpu->cfg.ext_sstc && env->rdtime_fn) {
+riscv_timer_write_timecmp(cpu, env->vstimer, env->vstimecmp,
+  env->htimedelta, MIP_VSTIP);
+}
+
 return RISCV_EXCP_NONE;
 }
 
@@ -2748,11 +2756,19 @@ static RISCVException read_htimedeltah(CPURISCVState 
*env, int csrno,
 static RISCVException write_htimedeltah(CPURISCVState *env, int csrno,
 target_ulong val)
 {
+RISCVCPU *cpu = env_archcpu(env);
+
 if (!env->rdtime_fn) {
 return RISCV_EXCP_ILLEGAL_INST;
 }
 
 env->htimedelta = deposit64(env->htimedelta, 32, 32, (uint64_t)val);
+
+if (cpu->cfg.ext_sstc && env->rdtime_fn) {
+riscv_timer_write_timecmp(cpu, env->vstimer, env->vstimecmp,
+  env->htimedelta, MIP_VSTIP);
+}
+
 return RISCV_EXCP_NONE;
 }
 
-- 
2.34.1