* [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next @ 2023-08-30 13:35 Daniel Henrique Barboza 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza ` (2 more replies) 0 siblings, 3 replies; 13+ messages in thread From: Daniel Henrique Barboza @ 2023-08-30 13:35 UTC (permalink / raw) To: qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson, Daniel Henrique Barboza Hi, This is the second version of the --enable-debug build fix for the riscv-to-apply.next branch: https://github.com/alistair23/qemu/tree/riscv-to-apply.next This implements suggestions from Richard Henderson made in v1. Most notable difference is that riscv_kvm_aplic_request() was moved to kvm.c and it's now being declared in kvm_riscv.h. Changes from v1: - changed patch order - patch 1 (former 2): - use kvm_enabled() to crop the whole block - patch 2 (former 1): - move riscv_kvm_aplic_request() to kvm_riscv.h - use kvm_enabled() to crop the whole block - v1 link: https://lore.kernel.org/qemu-riscv/20230829122144.464489-1-dbarboza@ventanamicro.com/ Daniel Henrique Barboza (2): hw/riscv/virt.c: fix non-KVM --enable-debug build hw/intc/riscv_aplic.c fix non-KVM --enable-debug build hw/intc/riscv_aplic.c | 8 ++------ hw/riscv/virt.c | 6 +++--- target/riscv/kvm.c | 5 +++++ target/riscv/kvm_riscv.h | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) -- 2.41.0 ^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-30 13:35 [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Daniel Henrique Barboza @ 2023-08-30 13:35 ` Daniel Henrique Barboza 2023-08-30 14:15 ` Richard Henderson ` (2 more replies) 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza 2023-09-01 2:26 ` [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Alistair Francis 2 siblings, 3 replies; 13+ messages in thread From: Daniel Henrique Barboza @ 2023-08-30 13:35 UTC (permalink / raw) To: qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson, Daniel Henrique Barboza A build with --enable-debug and without KVM will fail as follows: /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' This happens because the code block with "if virt_use_kvm_aia(s)" isn't being ignored by the debug build, resulting in an undefined reference to a KVM only function. Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will make the compiler crop the kvm_riscv_aia_create() call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional inside virt_use_kvm_aia() won't fix the build because this function would need to be inlined multiple times to make the compiler zero out the entire block. While we're at it, use kvm_enabled() in all instances where virt_use_kvm_aia() is checked to allow the compiler to elide these other kvm-only instances as well. Suggested-by: Richard Henderson <richard.henderson@linaro.org> Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> --- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 388e52a294..3b259b9305 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -782,7 +782,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, } /* KVM AIA only has one APLIC instance */ - if (virt_use_kvm_aia(s)) { + if (kvm_enabled() && virt_use_kvm_aia(s)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, @@ -808,7 +808,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, g_free(intc_phandles); - if (virt_use_kvm_aia(s)) { + if (kvm_enabled() && virt_use_kvm_aia(s)) { *irq_mmio_phandle = xplic_phandles[0]; *irq_virtio_phandle = xplic_phandles[0]; *irq_pcie_phandle = xplic_phandles[0]; @@ -1461,7 +1461,7 @@ static void virt_machine_init(MachineState *machine) } } - if (virt_use_kvm_aia(s)) { + if (kvm_enabled() && virt_use_kvm_aia(s)) { kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, memmap[VIRT_APLIC_S].base, -- 2.41.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza @ 2023-08-30 14:15 ` Richard Henderson 2023-08-30 14:23 ` Philippe Mathieu-Daudé 2023-08-31 8:42 ` Andrew Jones 2 siblings, 0 replies; 13+ messages in thread From: Richard Henderson @ 2023-08-30 14:15 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer On 8/30/23 06:35, Daniel Henrique Barboza wrote: > A build with --enable-debug and without KVM will fail as follows: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': > ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' > > This happens because the code block with "if virt_use_kvm_aia(s)" isn't > being ignored by the debug build, resulting in an undefined reference to > a KVM only function. > > Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will > make the compiler crop the kvm_riscv_aia_create() call entirely from a > non-KVM build. Note that adding the 'kvm_enabled()' conditional inside > virt_use_kvm_aia() won't fix the build because this function would need > to be inlined multiple times to make the compiler zero out the entire > block. > > While we're at it, use kvm_enabled() in all instances where > virt_use_kvm_aia() is checked to allow the compiler to elide these other > kvm-only instances as well. > > Suggested-by: Richard Henderson<richard.henderson@linaro.org> > Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") > Signed-off-by: Daniel Henrique Barboza<dbarboza@ventanamicro.com> > --- > hw/riscv/virt.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~ ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza 2023-08-30 14:15 ` Richard Henderson @ 2023-08-30 14:23 ` Philippe Mathieu-Daudé 2023-08-31 8:42 ` Andrew Jones 2 siblings, 0 replies; 13+ messages in thread From: Philippe Mathieu-Daudé @ 2023-08-30 14:23 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On 30/8/23 15:35, Daniel Henrique Barboza wrote: > A build with --enable-debug and without KVM will fail as follows: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': > ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' > > This happens because the code block with "if virt_use_kvm_aia(s)" isn't > being ignored by the debug build, resulting in an undefined reference to > a KVM only function. > > Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will > make the compiler crop the kvm_riscv_aia_create() call entirely from a > non-KVM build. Note that adding the 'kvm_enabled()' conditional inside > virt_use_kvm_aia() won't fix the build because this function would need > to be inlined multiple times to make the compiler zero out the entire > block. > > While we're at it, use kvm_enabled() in all instances where > virt_use_kvm_aia() is checked to allow the compiler to elide these other > kvm-only instances as well. > > Suggested-by: Richard Henderson <richard.henderson@linaro.org> > Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > --- > hw/riscv/virt.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Yay! Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza 2023-08-30 14:15 ` Richard Henderson 2023-08-30 14:23 ` Philippe Mathieu-Daudé @ 2023-08-31 8:42 ` Andrew Jones 2023-08-31 9:22 ` Daniel Henrique Barboza 2023-08-31 12:47 ` Philippe Mathieu-Daudé 2 siblings, 2 replies; 13+ messages in thread From: Andrew Jones @ 2023-08-31 8:42 UTC (permalink / raw) To: Daniel Henrique Barboza Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On Wed, Aug 30, 2023 at 10:35:02AM -0300, Daniel Henrique Barboza wrote: > A build with --enable-debug and without KVM will fail as follows: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': > ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' > > This happens because the code block with "if virt_use_kvm_aia(s)" isn't > being ignored by the debug build, resulting in an undefined reference to > a KVM only function. > > Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will > make the compiler crop the kvm_riscv_aia_create() call entirely from a > non-KVM build. Note that adding the 'kvm_enabled()' conditional inside > virt_use_kvm_aia() won't fix the build because this function would need > to be inlined multiple times to make the compiler zero out the entire > block. > > While we're at it, use kvm_enabled() in all instances where > virt_use_kvm_aia() is checked to allow the compiler to elide these other > kvm-only instances as well. > > Suggested-by: Richard Henderson <richard.henderson@linaro.org> > Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > --- > hw/riscv/virt.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c > index 388e52a294..3b259b9305 100644 > --- a/hw/riscv/virt.c > +++ b/hw/riscv/virt.c > @@ -782,7 +782,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, > } > > /* KVM AIA only has one APLIC instance */ > - if (virt_use_kvm_aia(s)) { > + if (kvm_enabled() && virt_use_kvm_aia(s)) { > create_fdt_socket_aplic(s, memmap, 0, > msi_m_phandle, msi_s_phandle, phandle, > &intc_phandles[0], xplic_phandles, > @@ -808,7 +808,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, > > g_free(intc_phandles); > > - if (virt_use_kvm_aia(s)) { > + if (kvm_enabled() && virt_use_kvm_aia(s)) { > *irq_mmio_phandle = xplic_phandles[0]; > *irq_virtio_phandle = xplic_phandles[0]; > *irq_pcie_phandle = xplic_phandles[0]; > @@ -1461,7 +1461,7 @@ static void virt_machine_init(MachineState *machine) > } > } > > - if (virt_use_kvm_aia(s)) { > + if (kvm_enabled() && virt_use_kvm_aia(s)) { > kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, > VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, > memmap[VIRT_APLIC_S].base, > -- > 2.41.0 > > I think I'd prefer /* We need this inlined for debug (-O0) builds */ static inline QEMU_ALWAYS_INLINE bool virt_use_kvm_aia(RISCVVirtState *s) { return kvm_enabled() && kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; } assuming that works. Either way, Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Thanks, drew ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-31 8:42 ` Andrew Jones @ 2023-08-31 9:22 ` Daniel Henrique Barboza 2023-08-31 12:47 ` Philippe Mathieu-Daudé 1 sibling, 0 replies; 13+ messages in thread From: Daniel Henrique Barboza @ 2023-08-31 9:22 UTC (permalink / raw) To: Andrew Jones Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On 8/31/23 05:42, Andrew Jones wrote: > On Wed, Aug 30, 2023 at 10:35:02AM -0300, Daniel Henrique Barboza wrote: >> A build with --enable-debug and without KVM will fail as follows: >> >> /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': >> ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' >> >> This happens because the code block with "if virt_use_kvm_aia(s)" isn't >> being ignored by the debug build, resulting in an undefined reference to >> a KVM only function. >> >> Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will >> make the compiler crop the kvm_riscv_aia_create() call entirely from a >> non-KVM build. Note that adding the 'kvm_enabled()' conditional inside >> virt_use_kvm_aia() won't fix the build because this function would need >> to be inlined multiple times to make the compiler zero out the entire >> block. >> >> While we're at it, use kvm_enabled() in all instances where >> virt_use_kvm_aia() is checked to allow the compiler to elide these other >> kvm-only instances as well. >> >> Suggested-by: Richard Henderson <richard.henderson@linaro.org> >> Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") >> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> >> --- >> hw/riscv/virt.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c >> index 388e52a294..3b259b9305 100644 >> --- a/hw/riscv/virt.c >> +++ b/hw/riscv/virt.c >> @@ -782,7 +782,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, >> } >> >> /* KVM AIA only has one APLIC instance */ >> - if (virt_use_kvm_aia(s)) { >> + if (kvm_enabled() && virt_use_kvm_aia(s)) { >> create_fdt_socket_aplic(s, memmap, 0, >> msi_m_phandle, msi_s_phandle, phandle, >> &intc_phandles[0], xplic_phandles, >> @@ -808,7 +808,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, >> >> g_free(intc_phandles); >> >> - if (virt_use_kvm_aia(s)) { >> + if (kvm_enabled() && virt_use_kvm_aia(s)) { >> *irq_mmio_phandle = xplic_phandles[0]; >> *irq_virtio_phandle = xplic_phandles[0]; >> *irq_pcie_phandle = xplic_phandles[0]; >> @@ -1461,7 +1461,7 @@ static void virt_machine_init(MachineState *machine) >> } >> } >> >> - if (virt_use_kvm_aia(s)) { >> + if (kvm_enabled() && virt_use_kvm_aia(s)) { >> kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, >> VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, >> memmap[VIRT_APLIC_S].base, >> -- >> 2.41.0 >> >> > > I think I'd prefer > > /* We need this inlined for debug (-O0) builds */ > static inline QEMU_ALWAYS_INLINE bool virt_use_kvm_aia(RISCVVirtState *s) > { > return kvm_enabled() && kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; > } > > assuming that works. I've tried before with 'inline' but not with 'QEMU_ALWAYS_INLINE'. But unfortunately it doesn't work too: diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 3b259b9305..a600d81e77 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -77,9 +77,10 @@ #endif /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ -static bool virt_use_kvm_aia(RISCVVirtState *s) +static inline QEMU_ALWAYS_INLINE bool virt_use_kvm_aia(RISCVVirtState *s) { - return kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; + return kvm_enabled() && kvm_irqchip_in_kernel() && + s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; } static const MemMapEntry virt_memmap[] = { @@ -782,7 +783,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, } /* KVM AIA only has one APLIC instance */ - if (kvm_enabled() && virt_use_kvm_aia(s)) { + if (virt_use_kvm_aia(s)) { create_fdt_socket_aplic(s, memmap, 0, msi_m_phandle, msi_s_phandle, phandle, &intc_phandles[0], xplic_phandles, @@ -808,7 +809,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, g_free(intc_phandles); - if (kvm_enabled() && virt_use_kvm_aia(s)) { + if (virt_use_kvm_aia(s)) { *irq_mmio_phandle = xplic_phandles[0]; *irq_virtio_phandle = xplic_phandles[0]; *irq_pcie_phandle = xplic_phandles[0]; @@ -1461,7 +1462,7 @@ static void virt_machine_init(MachineState *machine) } } - if (kvm_enabled() && virt_use_kvm_aia(s)) { + if (virt_use_kvm_aia(s)) { kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, memmap[VIRT_APLIC_S].base, Same error: /libssh.so -lrbd -lrados -lbz2 -lutil -Wl,--end-group /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': /home/danielhb/work/qemu/build/../hw/riscv/virt.c:1466: undefined reference to `kvm_riscv_aia_create' collect2: error: ld returned 1 exit status Thanks, Daniel > > Either way, > > Reviewed-by: Andrew Jones <ajones@ventanamicro.com> > > Thanks, > drew ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-31 8:42 ` Andrew Jones 2023-08-31 9:22 ` Daniel Henrique Barboza @ 2023-08-31 12:47 ` Philippe Mathieu-Daudé 2023-08-31 14:20 ` Andrew Jones 1 sibling, 1 reply; 13+ messages in thread From: Philippe Mathieu-Daudé @ 2023-08-31 12:47 UTC (permalink / raw) To: Andrew Jones, Daniel Henrique Barboza Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On 31/8/23 10:42, Andrew Jones wrote: > On Wed, Aug 30, 2023 at 10:35:02AM -0300, Daniel Henrique Barboza wrote: >> A build with --enable-debug and without KVM will fail as follows: >> >> /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': >> ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' >> >> This happens because the code block with "if virt_use_kvm_aia(s)" isn't >> being ignored by the debug build, resulting in an undefined reference to >> a KVM only function. >> >> Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will >> make the compiler crop the kvm_riscv_aia_create() call entirely from a >> non-KVM build. Note that adding the 'kvm_enabled()' conditional inside >> virt_use_kvm_aia() won't fix the build because this function would need >> to be inlined multiple times to make the compiler zero out the entire >> block. >> >> While we're at it, use kvm_enabled() in all instances where >> virt_use_kvm_aia() is checked to allow the compiler to elide these other >> kvm-only instances as well. >> >> Suggested-by: Richard Henderson <richard.henderson@linaro.org> >> Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") >> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> >> --- >> hw/riscv/virt.c | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) > I think I'd prefer > > /* We need this inlined for debug (-O0) builds */ > static inline QEMU_ALWAYS_INLINE bool virt_use_kvm_aia(RISCVVirtState *s) > { > return kvm_enabled() && kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; Generally we should know whether KVM is enabled or not _before_ calling any foo_kvm() code, not after. > } ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build 2023-08-31 12:47 ` Philippe Mathieu-Daudé @ 2023-08-31 14:20 ` Andrew Jones 0 siblings, 0 replies; 13+ messages in thread From: Andrew Jones @ 2023-08-31 14:20 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: Daniel Henrique Barboza, qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On Thu, Aug 31, 2023 at 02:47:54PM +0200, Philippe Mathieu-Daudé wrote: > On 31/8/23 10:42, Andrew Jones wrote: > > On Wed, Aug 30, 2023 at 10:35:02AM -0300, Daniel Henrique Barboza wrote: > > > A build with --enable-debug and without KVM will fail as follows: > > > > > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_riscv_virt.c.o: in function `virt_machine_init': > > > ./qemu/build/../hw/riscv/virt.c:1465: undefined reference to `kvm_riscv_aia_create' > > > > > > This happens because the code block with "if virt_use_kvm_aia(s)" isn't > > > being ignored by the debug build, resulting in an undefined reference to > > > a KVM only function. > > > > > > Add a 'kvm_enabled()' conditional together with virt_use_kvm_aia() will > > > make the compiler crop the kvm_riscv_aia_create() call entirely from a > > > non-KVM build. Note that adding the 'kvm_enabled()' conditional inside > > > virt_use_kvm_aia() won't fix the build because this function would need > > > to be inlined multiple times to make the compiler zero out the entire > > > block. > > > > > > While we're at it, use kvm_enabled() in all instances where > > > virt_use_kvm_aia() is checked to allow the compiler to elide these other > > > kvm-only instances as well. > > > > > > Suggested-by: Richard Henderson <richard.henderson@linaro.org> > > > Fixes: dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine") > > > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > > > --- > > > hw/riscv/virt.c | 6 +++--- > > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > I think I'd prefer > > > > /* We need this inlined for debug (-O0) builds */ > > static inline QEMU_ALWAYS_INLINE bool virt_use_kvm_aia(RISCVVirtState *s) > > { > > return kvm_enabled() && kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; > > Generally we should know whether KVM is enabled or not _before_ > calling any foo_kvm() code, not after. That's reasonable and makes me want to suggest squashing the diff below into the second patch. diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 592c3ce76828..f712699a4040 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -816,7 +816,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) uint32_t i; RISCVAPLICState *aplic = RISCV_APLIC(dev); - if (!is_kvm_aia(aplic->msimode)) { + if (!kvm_enabled() || !is_kvm_aia(aplic->msimode)) { aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); aplic->state = g_new0(uint32_t, aplic->num_irqs); @@ -980,7 +980,7 @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - if (!is_kvm_aia(msimode)) { + if (!kvm_enabled() || !is_kvm_aia(msimode)) { sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); } ^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build 2023-08-30 13:35 [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Daniel Henrique Barboza 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza @ 2023-08-30 13:35 ` Daniel Henrique Barboza 2023-08-30 14:13 ` Richard Henderson ` (2 more replies) 2023-09-01 2:26 ` [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Alistair Francis 2 siblings, 3 replies; 13+ messages in thread From: Daniel Henrique Barboza @ 2023-08-30 13:35 UTC (permalink / raw) To: qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson, Daniel Henrique Barboza Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM environment with the following error: /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request': ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq' collect2: error: ld returned 1 exit status This happens because the debug build will poke into the 'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to the KVM only function riscv_kvm_aplic_request(). There are multiple solutions to fix this. We'll go with the same solution from the previous patch, i.e. add a kvm_enabled() conditional to filter out the block. But there's a catch: riscv_kvm_aplic_request() is a local function that would end up being used if the compiler crops the block, and this won't work. Quoting Richard Henderson's explanation in [1]: "(...) the compiler won't eliminate entire unused functions with -O0" We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its declaration in kvm_riscv.h, where all other KVM specific public functions are already declared. Other archs handles KVM specific code in this manner and we expect to do the same from now on. [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/ Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> --- hw/intc/riscv_aplic.c | 8 ++------ target/riscv/kvm.c | 5 +++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c index 592c3ce768..99aae8ccbe 100644 --- a/hw/intc/riscv_aplic.c +++ b/hw/intc/riscv_aplic.c @@ -32,6 +32,7 @@ #include "target/riscv/cpu.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "kvm_riscv.h" #include "migration/vmstate.h" #define APLIC_MAX_IDC (1UL << 14) @@ -481,11 +482,6 @@ static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) return topi; } -static void riscv_kvm_aplic_request(void *opaque, int irq, int level) -{ - kvm_set_irq(kvm_state, irq, !!level); -} - static void riscv_aplic_request(void *opaque, int irq, int level) { bool update = false; @@ -840,7 +836,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) * have IRQ lines delegated by their parent APLIC. */ if (!aplic->parent) { - if (is_kvm_aia(aplic->msimode)) { + if (kvm_enabled() && is_kvm_aia(aplic->msimode)) { qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); } else { qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c index faee8536ef..ac28a70723 100644 --- a/target/riscv/kvm.c +++ b/target/riscv/kvm.c @@ -46,6 +46,11 @@ #include "sysemu/runstate.h" #include "hw/riscv/numa.h" +void riscv_kvm_aplic_request(void *opaque, int irq, int level) +{ + kvm_set_irq(kvm_state, irq, !!level); +} + static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, uint64_t idx) { diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h index 7d4b7c60e2..de8c209ebc 100644 --- a/target/riscv/kvm_riscv.h +++ b/target/riscv/kvm_riscv.h @@ -26,5 +26,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, uint64_t aia_irq_num, uint64_t aia_msi_num, uint64_t aplic_base, uint64_t imsic_base, uint64_t guest_num); +void riscv_kvm_aplic_request(void *opaque, int irq, int level); #endif -- 2.41.0 ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza @ 2023-08-30 14:13 ` Richard Henderson 2023-08-30 14:24 ` Philippe Mathieu-Daudé 2023-08-31 8:50 ` Andrew Jones 2 siblings, 0 replies; 13+ messages in thread From: Richard Henderson @ 2023-08-30 14:13 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer On 8/30/23 06:35, Daniel Henrique Barboza wrote: > Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM > environment with the following error: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request': > ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq' > collect2: error: ld returned 1 exit status > > This happens because the debug build will poke into the > 'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to > the KVM only function riscv_kvm_aplic_request(). > > There are multiple solutions to fix this. We'll go with the same > solution from the previous patch, i.e. add a kvm_enabled() conditional > to filter out the block. But there's a catch: riscv_kvm_aplic_request() > is a local function that would end up being used if the compiler crops > the block, and this won't work. Quoting Richard Henderson's explanation > in [1]: > > "(...) the compiler won't eliminate entire unused functions with -O0" > > We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its > declaration in kvm_riscv.h, where all other KVM specific public > functions are already declared. Other archs handles KVM specific code in > this manner and we expect to do the same from now on. > > [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/ > > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > --- > hw/intc/riscv_aplic.c | 8 ++------ > target/riscv/kvm.c | 5 +++++ > target/riscv/kvm_riscv.h | 1 + > 3 files changed, 8 insertions(+), 6 deletions(-) Much better. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~ ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza 2023-08-30 14:13 ` Richard Henderson @ 2023-08-30 14:24 ` Philippe Mathieu-Daudé 2023-08-31 8:50 ` Andrew Jones 2 siblings, 0 replies; 13+ messages in thread From: Philippe Mathieu-Daudé @ 2023-08-30 14:24 UTC (permalink / raw) To: Daniel Henrique Barboza, qemu-devel Cc: qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On 30/8/23 15:35, Daniel Henrique Barboza wrote: > Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM > environment with the following error: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request': > ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq' > collect2: error: ld returned 1 exit status > > This happens because the debug build will poke into the > 'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to > the KVM only function riscv_kvm_aplic_request(). > > There are multiple solutions to fix this. We'll go with the same > solution from the previous patch, i.e. add a kvm_enabled() conditional > to filter out the block. But there's a catch: riscv_kvm_aplic_request() > is a local function that would end up being used if the compiler crops > the block, and this won't work. Quoting Richard Henderson's explanation > in [1]: > > "(...) the compiler won't eliminate entire unused functions with -O0" > > We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its > declaration in kvm_riscv.h, where all other KVM specific public > functions are already declared. Other archs handles KVM specific code in > this manner and we expect to do the same from now on. > > [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/ > > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > --- > hw/intc/riscv_aplic.c | 8 ++------ > target/riscv/kvm.c | 5 +++++ > target/riscv/kvm_riscv.h | 1 + > 3 files changed, 8 insertions(+), 6 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza 2023-08-30 14:13 ` Richard Henderson 2023-08-30 14:24 ` Philippe Mathieu-Daudé @ 2023-08-31 8:50 ` Andrew Jones 2 siblings, 0 replies; 13+ messages in thread From: Andrew Jones @ 2023-08-31 8:50 UTC (permalink / raw) To: Daniel Henrique Barboza Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On Wed, Aug 30, 2023 at 10:35:03AM -0300, Daniel Henrique Barboza wrote: > Commit 6df0b37e2ab breaks a --enable-debug build in a non-KVM > environment with the following error: > > /usr/bin/ld: libqemu-riscv64-softmmu.fa.p/hw_intc_riscv_aplic.c.o: in function `riscv_kvm_aplic_request': > ./qemu/build/../hw/intc/riscv_aplic.c:486: undefined reference to `kvm_set_irq' > collect2: error: ld returned 1 exit status > > This happens because the debug build will poke into the > 'if (is_kvm_aia(aplic->msimode))' block and fail to find a reference to > the KVM only function riscv_kvm_aplic_request(). > > There are multiple solutions to fix this. We'll go with the same > solution from the previous patch, i.e. add a kvm_enabled() conditional > to filter out the block. But there's a catch: riscv_kvm_aplic_request() > is a local function that would end up being used if the compiler crops > the block, and this won't work. Quoting Richard Henderson's explanation > in [1]: > > "(...) the compiler won't eliminate entire unused functions with -O0" > > We'll solve it by moving riscv_kvm_aplic_request() to kvm.c and add its > declaration in kvm_riscv.h, where all other KVM specific public > functions are already declared. Other archs handles KVM specific code in > this manner and we expect to do the same from now on. > > [1] https://lore.kernel.org/qemu-riscv/d2f1ad02-eb03-138f-9d08-db676deeed05@linaro.org/ > > Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > --- > hw/intc/riscv_aplic.c | 8 ++------ > target/riscv/kvm.c | 5 +++++ > target/riscv/kvm_riscv.h | 1 + > 3 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c > index 592c3ce768..99aae8ccbe 100644 > --- a/hw/intc/riscv_aplic.c > +++ b/hw/intc/riscv_aplic.c > @@ -32,6 +32,7 @@ > #include "target/riscv/cpu.h" > #include "sysemu/sysemu.h" > #include "sysemu/kvm.h" > +#include "kvm_riscv.h" > #include "migration/vmstate.h" > > #define APLIC_MAX_IDC (1UL << 14) > @@ -481,11 +482,6 @@ static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) > return topi; > } > > -static void riscv_kvm_aplic_request(void *opaque, int irq, int level) > -{ > - kvm_set_irq(kvm_state, irq, !!level); > -} > - > static void riscv_aplic_request(void *opaque, int irq, int level) > { > bool update = false; > @@ -840,7 +836,7 @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) > * have IRQ lines delegated by their parent APLIC. > */ > if (!aplic->parent) { > - if (is_kvm_aia(aplic->msimode)) { > + if (kvm_enabled() && is_kvm_aia(aplic->msimode)) { > qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); > } else { > qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); > diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c > index faee8536ef..ac28a70723 100644 > --- a/target/riscv/kvm.c > +++ b/target/riscv/kvm.c > @@ -46,6 +46,11 @@ > #include "sysemu/runstate.h" > #include "hw/riscv/numa.h" > > +void riscv_kvm_aplic_request(void *opaque, int irq, int level) > +{ > + kvm_set_irq(kvm_state, irq, !!level); > +} > + > static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, > uint64_t idx) > { > diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h > index 7d4b7c60e2..de8c209ebc 100644 > --- a/target/riscv/kvm_riscv.h > +++ b/target/riscv/kvm_riscv.h > @@ -26,5 +26,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, > uint64_t aia_irq_num, uint64_t aia_msi_num, > uint64_t aplic_base, uint64_t imsic_base, > uint64_t guest_num); > +void riscv_kvm_aplic_request(void *opaque, int irq, int level); > > #endif > -- > 2.41.0 > > I'd also try the always_inline trick with is_kvm_aia(), particularly because now we're inconsistent with how it's used. In two of the three places it's called we don't guard it with kvm_enabled(). But, I'm also mostly OK with this, so Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Thanks, drew ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next 2023-08-30 13:35 [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Daniel Henrique Barboza 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza @ 2023-09-01 2:26 ` Alistair Francis 2 siblings, 0 replies; 13+ messages in thread From: Alistair Francis @ 2023-09-01 2:26 UTC (permalink / raw) To: Daniel Henrique Barboza Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liweiwei, zhiwei_liu, palmer, richard.henderson On Wed, Aug 30, 2023 at 11:36 PM Daniel Henrique Barboza <dbarboza@ventanamicro.com> wrote: > > Hi, > > This is the second version of the --enable-debug build fix for the > riscv-to-apply.next branch: > > https://github.com/alistair23/qemu/tree/riscv-to-apply.next > > This implements suggestions from Richard Henderson made in v1. Most > notable difference is that riscv_kvm_aplic_request() was moved to > kvm.c and it's now being declared in kvm_riscv.h. Thanks! Applied to riscv-to-apply.next Alistair > > Changes from v1: > - changed patch order > - patch 1 (former 2): > - use kvm_enabled() to crop the whole block > - patch 2 (former 1): > - move riscv_kvm_aplic_request() to kvm_riscv.h > - use kvm_enabled() to crop the whole block > - v1 link: https://lore.kernel.org/qemu-riscv/20230829122144.464489-1-dbarboza@ventanamicro.com/ > > > Daniel Henrique Barboza (2): > hw/riscv/virt.c: fix non-KVM --enable-debug build > hw/intc/riscv_aplic.c fix non-KVM --enable-debug build > > hw/intc/riscv_aplic.c | 8 ++------ > hw/riscv/virt.c | 6 +++--- > target/riscv/kvm.c | 5 +++++ > target/riscv/kvm_riscv.h | 1 + > 4 files changed, 11 insertions(+), 9 deletions(-) > > -- > 2.41.0 > > ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-09-01 2:27 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-30 13:35 [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Daniel Henrique Barboza 2023-08-30 13:35 ` [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build Daniel Henrique Barboza 2023-08-30 14:15 ` Richard Henderson 2023-08-30 14:23 ` Philippe Mathieu-Daudé 2023-08-31 8:42 ` Andrew Jones 2023-08-31 9:22 ` Daniel Henrique Barboza 2023-08-31 12:47 ` Philippe Mathieu-Daudé 2023-08-31 14:20 ` Andrew Jones 2023-08-30 13:35 ` [PATCH v2 2/2] hw/intc/riscv_aplic.c " Daniel Henrique Barboza 2023-08-30 14:13 ` Richard Henderson 2023-08-30 14:24 ` Philippe Mathieu-Daudé 2023-08-31 8:50 ` Andrew Jones 2023-09-01 2:26 ` [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Alistair Francis
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).