From: Andrew Jones <ajones@ventanamicro.com>
To: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
alistair.francis@wdc.com, bmeng@tinylab.org,
liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com,
palmer@rivosinc.com, richard.henderson@linaro.org
Subject: Re: [PATCH v2 2/2] hw/intc/riscv_aplic.c fix non-KVM --enable-debug build
Date: Thu, 31 Aug 2023 10:50:30 +0200 [thread overview]
Message-ID: <20230831-489a09cdba06b2f8a7fd4103@orel> (raw)
In-Reply-To: <20230830133503.711138-3-dbarboza@ventanamicro.com>
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
next prev parent reply other threads:[~2023-08-31 8:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-09-01 2:26 ` [PATCH v2 0/2] riscv: fix --enable-debug in riscv-to-apply.next Alistair Francis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230831-489a09cdba06b2f8a7fd4103@orel \
--to=ajones@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng@tinylab.org \
--cc=dbarboza@ventanamicro.com \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@rivosinc.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=zhiwei_liu@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).