[PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header

Qiang Ma posted 1 patch 2 weeks, 4 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260512121954.2248026-1-maqianga@uniontech.com
Maintainers: Song Gao <gaosong@loongson.cn>
There is a newer version of this series
target/loongarch/kvm/kvm.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header
Posted by Qiang Ma 2 weeks, 4 days ago
After commit 71cab1a42d2 removed the indirect include of
exec/cpu-defs.h from target/loongarch/cpu.h, the TARGET_FMT_lx
macro is no longer visible in kvm.c, causing build failures:

  error: expected ')' before TARGET_FMT_lx

Add the missing #include exec/cpu-defs.h to restore the
TARGET_FMT_lx definition.

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 target/loongarch/kvm/kvm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index 9d844c4905..7989aec7c7 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -6,6 +6,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "exec/cpu-defs.h"
 #include <sys/ioctl.h>
 #include <linux/kvm.h>
 #include "asm-loongarch/kvm_para.h"
-- 
2.51.0
Re: [PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header
Posted by gaosong 2 weeks, 4 days ago
+Philippe,and bibo.
在 2026/5/12 下午8:19, Qiang Ma 写道:
> After commit 71cab1a42d2 removed the indirect include of
> exec/cpu-defs.h from target/loongarch/cpu.h, the TARGET_FMT_lx
> macro is no longer visible in kvm.c, causing build failures:
>
>    error: expected ')' before TARGET_FMT_lx
>
> Add the missing #include exec/cpu-defs.h to restore the
> TARGET_FMT_lx definition.
>
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> ---
>   target/loongarch/kvm/kvm.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
> index 9d844c4905..7989aec7c7 100644
> --- a/target/loongarch/kvm/kvm.c
> +++ b/target/loongarch/kvm/kvm.c
> @@ -6,6 +6,7 @@
>    */
>   
>   #include "qemu/osdep.h"
> +#include "exec/cpu-defs.h"
Simply add exec/target_long.h.

Thanks.
Song Gao
>   #include <sys/ioctl.h>
>   #include <linux/kvm.h>
>   #include "asm-loongarch/kvm_para.h"


Re: [PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
Hi,

On 12/5/26 14:36, gaosong wrote:
> +Philippe,and bibo.
> 在 2026/5/12 下午8:19, Qiang Ma 写道:
>> After commit 71cab1a42d2 removed the indirect include of
>> exec/cpu-defs.h from target/loongarch/cpu.h, the TARGET_FMT_lx
>> macro is no longer visible in kvm.c, causing build failures:
>>
>>    error: expected ')' before TARGET_FMT_lx
>>
>> Add the missing #include exec/cpu-defs.h to restore the
>> TARGET_FMT_lx definition.
>>
>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>> ---
>>   target/loongarch/kvm/kvm.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
>> index 9d844c4905..7989aec7c7 100644
>> --- a/target/loongarch/kvm/kvm.c
>> +++ b/target/loongarch/kvm/kvm.c
>> @@ -6,6 +6,7 @@
>>    */
>>   #include "qemu/osdep.h"
>> +#include "exec/cpu-defs.h"
> Simply add exec/target_long.h.

Correct.

Looking at the last build-loongarch64 job output,
https://gitlab.com/qemu-project/qemu/-/jobs/14336151206,
I see KVM is not build-covered:

configuring with:  '../configure' '--enable-werror' '--disable-docs' 
'--enable-fdt=system' '--disable-debug-info' 
'--target-list=loongarch64-linux-user loongarch64-softmmu' 
'--disable-tools' '--enable-debug'
[...]
   Targets and accelerators
     KVM support                     : NO

Why is that, what is missing?

Also I strongly suggest adding a cross-loongarch64-kvm-only job in
.gitlab-ci.d/crossbuilds.yml.

> 
> Thanks.
> Song Gao

Re: [PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header
Posted by Thomas Huth 2 weeks, 3 days ago
On 13/05/2026 07.59, Philippe Mathieu-Daudé wrote:
> Hi,
> 
> On 12/5/26 14:36, gaosong wrote:
>> +Philippe,and bibo.
>> 在 2026/5/12 下午8:19, Qiang Ma 写道:
>>> After commit 71cab1a42d2 removed the indirect include of
>>> exec/cpu-defs.h from target/loongarch/cpu.h, the TARGET_FMT_lx
>>> macro is no longer visible in kvm.c, causing build failures:
>>>
>>>    error: expected ')' before TARGET_FMT_lx
>>>
>>> Add the missing #include exec/cpu-defs.h to restore the
>>> TARGET_FMT_lx definition.
>>>
>>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>>> ---
>>>   target/loongarch/kvm/kvm.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
>>> index 9d844c4905..7989aec7c7 100644
>>> --- a/target/loongarch/kvm/kvm.c
>>> +++ b/target/loongarch/kvm/kvm.c
>>> @@ -6,6 +6,7 @@
>>>    */
>>>   #include "qemu/osdep.h"
>>> +#include "exec/cpu-defs.h"
>> Simply add exec/target_long.h.
> 
> Correct.
> 
> Looking at the last build-loongarch64 job output,
> https://gitlab.com/qemu-project/qemu/-/jobs/14336151206,
> I see KVM is not build-covered:
> 
> configuring with:  '../configure' '--enable-werror' '--disable-docs' '-- 
> enable-fdt=system' '--disable-debug-info' '--target-list=loongarch64-linux- 
> user loongarch64-softmmu' '--disable-tools' '--enable-debug'
> [...]
>    Targets and accelerators
>      KVM support                     : NO
> 
> Why is that, what is missing?

KVM only works if you build binaries where host architecture matches the 
target architecture. In that job, binaries are built for x86 hosts, so no 
KVM support here.

> Also I strongly suggest adding a cross-loongarch64-kvm-only job in
> .gitlab-ci.d/crossbuilds.yml.

Right, you'd need this for getting compile-coverage of the KVM code.

  Thomas


Re: [PATCH] target/loongarch/kvm: Include missing exec/cpu-defs.h header
Posted by Qiang Ma 2 weeks, 4 days ago
在 2026/5/12 20:36, gaosong 写道:
> +Philippe,and bibo.
> 在 2026/5/12 下午8:19, Qiang Ma 写道:
>> After commit 71cab1a42d2 removed the indirect include of
>> exec/cpu-defs.h from target/loongarch/cpu.h, the TARGET_FMT_lx
>> macro is no longer visible in kvm.c, causing build failures:
>>
>>    error: expected ')' before TARGET_FMT_lx
>>
>> Add the missing #include exec/cpu-defs.h to restore the
>> TARGET_FMT_lx definition.
>>
>> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
>> ---
>>   target/loongarch/kvm/kvm.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
>> index 9d844c4905..7989aec7c7 100644
>> --- a/target/loongarch/kvm/kvm.c
>> +++ b/target/loongarch/kvm/kvm.c
>> @@ -6,6 +6,7 @@
>>    */
>>     #include "qemu/osdep.h"
>> +#include "exec/cpu-defs.h"
> Simply add exec/target_long.h.
OK, Add #include "exec/target_long.h" in v2.
>
> Thanks.
> Song Gao
>>   #include <sys/ioctl.h>
>>   #include <linux/kvm.h>
>>   #include "asm-loongarch/kvm_para.h"
>
>