riscv: fix --enable-debug in riscv-to-apply.next
v2 cover riscv: fix --enable-debug in riscv-to-apply.next
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/[email protected]/
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(-)
Signature · 1 line
2.41.0
PATCH v2 1/2 hw/riscv/virt.c: fix non-KVM --enable-debug build
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.
--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/riscv/virt.c +3 -3
@@ -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,
Signature · 1 line
2.41.0
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
Quoted 20 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.
Quoted 6 lines
Suggested-by Richard Henderson<[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza<[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
r~
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
In reply to Daniel Henrique BarbozaQuoted 20 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.
Quoted 6 lines
Suggested-by Richard Henderson <[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Yay!
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
In reply to Daniel Henrique BarbozaQuoted 62 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.Suggested-by Richard Henderson <[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/riscv/virt.c +3
-3@@ -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,Signature · 1 line
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,
Thanks,
drew
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
Quoted 66 lines · Andrew Jones
Quoted 62 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.Suggested-by Richard Henderson <[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/riscv/virt.c +3
-3@@ -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,Signature · 1 line
2.41.0I think I'd prefer
Quoted 7 lines
/* 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:
hw/riscv/virt.c +6 -5
@@ -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
Quoted 7 lines
Either way,
Reviewed-by Andrew Jones <[email protected]>Thanks,
drew
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
In reply to Andrew JonesQuoted 29 lines · Andrew Jones
Quoted 20 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.Quoted 6 lines
Suggested-by Richard Henderson <[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 6 lines
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.
Quoted 1 line
}
Re: [PATCH v2 1/2] hw/riscv/virt.c: fix non-KVM --enable-debug build
Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Andrew Jones
Quoted 20 lines · 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 withvirt_use_kvm_aia()will make the compiler crop thekvm_riscv_aia_create()call entirely from a non-KVM build. Note that adding the 'kvm_enabled()' conditional insidevirt_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 wherevirt_use_kvm_aia()is checked to allow the compiler to elide these other kvm-only instances as well.Quoted 6 lines
Suggested-by Richard Henderson <[email protected]>Fixes dbdb99948e ("target/riscv: select KVM AIA in riscv virt machine")Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)I think I'd prefer
Quoted 7 lines
Quoted 4 lines
/* 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.
hw/intc/riscv_aplic.c +2 -2
@@ -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); }
PATCH v2 2/2 hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
In reply to Daniel Henrique BarbozaCommit 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/[email protected]/
--- hw/intc/riscv_aplic.c | 8 ++------ target/riscv/kvm.c | 5 +++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-)
hw/intc/riscv_aplic.c +2 -6
@@ -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);
target/riscv/kvm.c +5 -0
@@ -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) {
target/riscv/kvm_riscv.h +1 -0
@@ -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
Signature · 1 line
2.41.0
Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
Quoted 25 lines · Daniel Henrique Barboza
Commit
6df0b37e2abbreaks 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 statusThis 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 functionriscv_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()tokvm.cand add its declaration inkvm_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.
Quoted 8 lines
[1] https://lore.kernel.org/qemu-riscv/[email protected]/
Signed-off-by Daniel Henrique Barboza <[email protected]>--- 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.
r~
Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
In reply to Daniel Henrique BarbozaQuoted 25 lines · Daniel Henrique Barboza
Commit
6df0b37e2abbreaks 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 statusThis 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 functionriscv_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()tokvm.cand add its declaration inkvm_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.
Quoted 8 lines
[1] https://lore.kernel.org/qemu-riscv/[email protected]/
Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/intc/riscv_aplic.c | 8 ++------ target/riscv/kvm.c | 5 +++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-)
Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
In reply to Daniel Henrique BarbozaQuoted 98 lines · Daniel Henrique Barboza
Commit
6df0b37e2abbreaks 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 statusThis 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 functionriscv_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()tokvm.cand add its declaration inkvm_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/[email protected]/
Signed-off-by Daniel Henrique Barboza <[email protected]>--- hw/intc/riscv_aplic.c | 8 ++------ target/riscv/kvm.c | 5 +++++ target/riscv/kvm_riscv.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-)hw/intc/riscv_aplic.c +2
-6@@ -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);target/riscv/kvm.c +5
-0@@ -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) {target/riscv/kvm_riscv.h +1
-0@@ -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 Signature · 1 line
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
Thanks,
drew
Alistair Francis
AppliedQuoted 11 lines · 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 tokvm.cand it's now being declared inkvm_riscv.h.
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 25 lines
Changes from v1:
- changed patch order
- patch 1 (former 2):
- usekvm_enabled()to crop the whole block
- patch 2 (former 1):
- moveriscv_kvm_aplic_request()tokvm_riscv.h
- usekvm_enabled()to crop the whole block
- v1 link: https://lore.kernel.org/qemu-riscv/[email protected]/Daniel Henrique Barboza (2):
hw/riscv/virt.c: fix non-KVM --enable-debug buildhw/intc/riscv_aplic.cfix non-KVM --enable-debug buildhw/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