Add Multi-Core Debug (MCD) API support
v2 cover Add Multi-Core Debug (MCD) API support
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol.
To keep the overhead of a communication protocol on top of MCD minimal, we follow a remote procedure call approach by using QAPI as an interface definition and transport infrastructure. This way, we can use qapi-gen to take care of generating the infrastructure to dispatch MCD functions and to (un)marshal their arguments and results. Furthermore, qapi-doc and qtest provide good integration into QEMU's documentation and test frameworks.
In v1 of this patch series, the MCD protocol was directly integrated in QMP and the QMP monitor was responsible for dispatching MCD's server stub. This introduced a dependency between QEMU's machine protocol and the MCD debug protocol which is not to be expected. For this reason, v2 introduces a MCD monitor which uses as much of the QMP monitor's framework as possible but keeps the two protocols separate from each other.
Similarly, MCD's test suite uses as much of the qtest framework as is useful for sending JSON commands to the QEMU under test but adds new code where required to prevent dependencies to QMP.
To enable MCD, configure QEMU with --enable-mcd.
To start the MCD monitor, run QEMU with the -mcd option:
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
To run the MCD test suite independently, start mcd-test:
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-test
To connect from a MCD client, a client stub corresponding to this patch series can be found at https://gitlab.com/lauterbach/mcdrefsrv
Mario Fleischmann (20):
mcd: Introduce Multi-Core Debug (MCD) API
meson: Add --enable-mcd option
mcd: Introduce MCD server
qapi: Introduce MCD schema
mcd: Introduce MCD server stub
qtest: Introduce MCD test suite
mcd: Implement target initialization API
mcd: Implement server connection API
mcd: Implement target system query
mcd: Implement core connection control
mcd: Implement memory space query
gdbstub: Expose GDBRegisterState
mcd: Implement register query
mcd: Implement runstate control
mcd test: Implement core state query
gdbstub: Expose gdb_write_register
mcd: Implement register/memory access
mcd: Implement single stepping
mcd: Implement trigger control
mcd: Implement reset control
MAINTAINERS | 9 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 65 + gdbstub/gdbstub.c | 15 +- include/exec/gdbstub.h | 18 +- include/exec/mcdstub.h | 18 + mcd/mcd_api.h | 3963 +++++++++++++++++++++++++++++++++ mcd/mcd_monitor.c | 90 + mcd/mcd_qapi.c | 505 +++++ mcd/mcd_qapi.h | 81 + mcd/mcd_server.c | 2274 +++++++++++++++++++ mcd/mcd_stub.c | 988 ++++++++ mcd/meson.build | 60 + meson.build | 5 + meson_options.txt | 3 + qapi/mcd.json | 2366 ++++++++++++++++++++ qemu-options.hx | 11 + scripts/meson-buildoptions.sh | 3 + system/vl.c | 13 + tests/qtest/mcd-test.c | 698 ++++++ tests/qtest/mcd-util.c | 389 ++++ tests/qtest/mcd-util.h | 73 + tests/qtest/meson.build | 5 + 23 files changed, 11643 insertions(+), 10 deletions(-) create mode 100644 docs/interop/mcd.rst create mode 100644 include/exec/mcdstub.h create mode 100644 mcd/mcd_api.h create mode 100644 mcd/mcd_monitor.c create mode 100644 mcd/mcd_qapi.c create mode 100644 mcd/mcd_qapi.h create mode 100644 mcd/mcd_server.c create mode 100644 mcd/mcd_stub.c create mode 100644 mcd/meson.build create mode 100644 qapi/mcd.json create mode 100644 tests/qtest/mcd-test.c create mode 100644 tests/qtest/mcd-util.c create mode 100644 tests/qtest/mcd-util.h
Signature · 1 line
2.34.1
PATCH v2 1/20 mcd: Introduce Multi-Core Debug (MCD) API
Formatting changes to mcd_api.h to compily with QEMU's coding style guidelines:
* limit line width to 80
* convert Doxygen to kernel-doc comments
* avoid architecture specific defines
The original MCD API version can be found at:
https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip
--- MAINTAINERS | 6 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 44 + mcd/mcd_api.h | 3963 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4014 insertions(+) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/mcd_api.h
MAINTAINERS +6 -0
@@ -3120,6 +3120,12 @@ F: scripts/feature_to_c.py F: scripts/probe-gdb-support.py T: git https://gitlab.com/stsquad/qemu gdbstub/next +MCD +M: Mario Fleischmann <[email protected]> +S: Maintained +F: mcd/* +F: docs/interop/mcd.rst + Memory API M: Paolo Bonzini <[email protected]> M: Peter Xu <[email protected]>
docs/interop/index.rst +1 -0
@@ -14,6 +14,7 @@ are useful for making QEMU interoperate with other software. dbus-vmstate dbus-display live-block-operations + mcd nbd parallels prl-xml
docs/interop/mcd.rst new file +44 -0
44 lines not on this page · raw message
mcd/mcd_api.h new file +3963 -0
2,937 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API
Quoted 8 lines · Mario Fleischmann
Formatting changes to
mcd_api.hto compily with QEMU's coding style guidelines:* limit line width to 80
* convert Doxygen to kernel-doc comments
* avoid architecture specific definesThe original MCD API version can be found at:
https://repo.lauterbach.com/sprint_mcd_api_v1_0.zip
The commit message needs to call out the license choice of the imported file.
Quoted 43 lines
Signed-off-by Mario Fleischmann <[email protected]>--- MAINTAINERS | 6 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 44 + mcd/mcd_api.h | 3963 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4014 insertions(+) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/mcd_api.hmcd/mcd_api.h new file +26
-0@@ -0,0 +1,3963 @@ +/* +* Copyright (c) 2008, ARM Ltd., Infineon Technologies, NXP Semiconductors, +* Lauterbach, STMicroelectronics and TIMA Laboratory. +* All rights reserved. +* +* PREAMBLE +* +* The MCD API (Multi-Core Debug) has been designed as an interface between +* software development tools and simulated or real systems with multi-core +* SoCs. The target is to allow consistent software tooling throughout the +* whole SoC development flow. +* The MCD API (the "SOFTWARE") has been developed jointly by ARM Ltd., +* Infineon Technologies, NXP Semiconductors, Lauterbach, +* STMicroelectronics and TIMA Laboratory as part of the SPRINT project +* (www.sprint-project.net). +* The SPRINT project has been funded by the European Commission. +* +* LICENSE +* +* Any redistribution and use of the SOFTWARE in source and binary forms, +* with or without modification constitutes the full acceptance of the +* following disclaimer as well as of the license herein and is permitted +* provided that the following conditions are met: +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the disclaimer detailed below. +* - Redistributions in binary form must reproduce the above copyright notice,
mcd/mcd_api.h line 36
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* this list of conditions and the disclaimer detailed below in the +* documentation and/or other materials provided with the distribution. +* - Neither the name of its copyright holders nor the names of its +* contributors may be used to endorse or promote products derived from the +* Software without specific prior written permission. +* - Modification of any or all of the source code, documentation and other +* materials provided under this license are subject to acknowledgement of +* the modification(s) by including a prominent notice on the modification(s) +* stating the change(s) to the file(s), identifying the date of such change +* and stating the name of the publisher of any such modification(s).
This 4th clause is rather obnoxious and....
Quoted 8 lines
mcd/mcd_api.h new file +8
-0+* VERSION HISTORY +* +* 1.0 "SPRINT Release" : SPRINT reference version +* +* 1.1 "Lauterbach Release" : +* - forces all boolean types to 8-bit on Linux and Mac-OS-X, +* but 32-bit on all other OS forces 32-bit enumeration types +* - additional memory spaces MCD_MEM_SPACE_IS_PHYSICAL,
mcd/mcd_api.h line 69
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* MCD_MEM_SPACE_IS_LOGICAL, MCD_MEM_SPACE_IS_AUX +* - changed type of 2nd argument of mcd_qry_input_handle_f from "int" to +* "uint32_t" +* - changed type of element "data" of of mcd_tx_st from "unsigned char" to +* "uint8_t" +* - specifying the calling convention for MS Windows (x86) to __cdecl +* +* 1.2 "QEMU Release" : +* - changes formatting to accommodate QEMU's coding style guidelines +* - includes qemu/osdep.h instead of mcd_types.h
....this appears to not be compliant with the license since it fails to include the dates
AFAICT this license is derived from a classic BSD 3 clause, with the extra 4th clause added.
I don't see any SPDX license matching this, which is painful as it means it is going to need license approval before it can be included by distributions downstream.
Does this really have to be under a custom license instead of a well known standard license ? There's really no good reason for inventing new open source licenses.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API
Quoted 7 lines · Daniel P. Berrangé
Quoted 6 lines · Mario Fleischmann
Formatting changes to
mcd_api.hto compily with QEMU's coding style guidelines:* limit line width to 80
* convert Doxygen to kernel-doc comments
* avoid architecture specific defines
Quoted 5 lines
Quoted 2 lines
The original MCD API version can be found at:
https://repo.lauterbach.com/sprint_mcd_api_v1_0.zipThe commit message needs to call out the license choice of the imported file.
Thanks for pointing that out. Will be added in the next version.
Quoted 74 lines
Quoted 42 lines
Signed-off-by Mario Fleischmann <[email protected]>--- MAINTAINERS | 6 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 44 + mcd/mcd_api.h | 3963 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4014 insertions(+) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/mcd_api.hmcd/mcd_api.h new file +26
-0@@ -0,0 +1,3963 @@ +/* +* Copyright (c) 2008, ARM Ltd., Infineon Technologies, NXP Semiconductors, +* Lauterbach, STMicroelectronics and TIMA Laboratory. +* All rights reserved. +* +* PREAMBLE +* +* The MCD API (Multi-Core Debug) has been designed as an interface between +* software development tools and simulated or real systems with multi-core +* SoCs. The target is to allow consistent software tooling throughout the +* whole SoC development flow. +* The MCD API (the "SOFTWARE") has been developed jointly by ARM Ltd., +* Infineon Technologies, NXP Semiconductors, Lauterbach, +* STMicroelectronics and TIMA Laboratory as part of the SPRINT project +* (www.sprint-project.net). +* The SPRINT project has been funded by the European Commission. +* +* LICENSE +* +* Any redistribution and use of the SOFTWARE in source and binary forms, +* with or without modification constitutes the full acceptance of the +* following disclaimer as well as of the license herein and is permitted +* provided that the following conditions are met: +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the disclaimer detailed below. +* - Redistributions in binary form must reproduce the above copyright notice, mcd/mcd_api.h line 36
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* this list of conditions and the disclaimer detailed below in the +* documentation and/or other materials provided with the distribution. +* - Neither the name of its copyright holders nor the names of its +* contributors may be used to endorse or promote products derived from the +* Software without specific prior written permission. +* - Modification of any or all of the source code, documentation and other +* materials provided under this license are subject to acknowledgement of +* the modification(s) by including a prominent notice on the modification(s) +* stating the change(s) to the file(s), identifying the date of such change +* and stating the name of the publisher of any such modification(s). This 4th clause is rather obnoxious and....
Quoted 8 lines
mcd/mcd_api.h new file +8
-0+* VERSION HISTORY +* +* 1.0 "SPRINT Release" : SPRINT reference version +* +* 1.1 "Lauterbach Release" : +* - forces all boolean types to 8-bit on Linux and Mac-OS-X, +* but 32-bit on all other OS forces 32-bit enumeration types +* - additional memory spaces MCD_MEM_SPACE_IS_PHYSICAL, mcd/mcd_api.h line 69
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* MCD_MEM_SPACE_IS_LOGICAL, MCD_MEM_SPACE_IS_AUX +* - changed type of 2nd argument of mcd_qry_input_handle_f from "int" to +* "uint32_t" +* - changed type of element "data" of of mcd_tx_st from "unsigned char" to +* "uint8_t" +* - specifying the calling convention for MS Windows (x86) to __cdecl +* +* 1.2 "QEMU Release" : +* - changes formatting to accommodate QEMU's coding style guidelines +* - includes qemu/osdep.h instead of mcd_types.h
Quoted 2 lines
....this appears to not be compliant with the license since it fails to include the dates
We've got the dates of modifications available at our version control. They will be added in the next version of this patch.
Quoted 10 lines
AFAICT this license is derived from a classic BSD 3 clause, with the extra 4th clause added.
I don't see any SPDX license matching this, which is painful as it means it is going to need license approval before it can be included by distributions downstream.
Does this really have to be under a custom license instead of a well known standard license ? There's really no good reason for inventing new open source licenses.
BSD 3-Clause Modification matches the license of the MCD API and is listed under the SPDX License List. Is it possible to extend checkpatch's @valid with "BSD-3-Clause-Modification"? That way, we can also add the SPDX-License-Identifier to mcd_api.h without an error being generated by the script.
Quoted 2 lines
With regards,
Daniel
Thank you very much for taking the time to review the patch! I will add the changes in the next version of this series but will wait for further reviews until submitting v3 in order to keep the mailing list less busy.
Best regards,
Mario
Re: [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API
Quoted 108 lines · Mario Fleischmann
Quoted 7 lines · Daniel P. Berrangé
Quoted 6 lines · Mario Fleischmann
Formatting changes to
mcd_api.hto compily with QEMU's coding style guidelines:* limit line width to 80
* convert Doxygen to kernel-doc comments
* avoid architecture specific definesQuoted 5 lines
Quoted 2 lines
The original MCD API version can be found at:
https://repo.lauterbach.com/sprint_mcd_api_v1_0.zipThe commit message needs to call out the license choice of the imported file.
Thanks for pointing that out. Will be added in the next version.
Quoted 74 lines
Quoted 42 lines
Signed-off-by Mario Fleischmann <[email protected]>--- MAINTAINERS | 6 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 44 + mcd/mcd_api.h | 3963 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 4014 insertions(+) create mode 100644 docs/interop/mcd.rst create mode 100644 mcd/mcd_api.hmcd/mcd_api.h new file +26
-0@@ -0,0 +1,3963 @@ +/* +* Copyright (c) 2008, ARM Ltd., Infineon Technologies, NXP Semiconductors, +* Lauterbach, STMicroelectronics and TIMA Laboratory. +* All rights reserved. +* +* PREAMBLE +* +* The MCD API (Multi-Core Debug) has been designed as an interface between +* software development tools and simulated or real systems with multi-core +* SoCs. The target is to allow consistent software tooling throughout the +* whole SoC development flow. +* The MCD API (the "SOFTWARE") has been developed jointly by ARM Ltd., +* Infineon Technologies, NXP Semiconductors, Lauterbach, +* STMicroelectronics and TIMA Laboratory as part of the SPRINT project +* (www.sprint-project.net). +* The SPRINT project has been funded by the European Commission. +* +* LICENSE +* +* Any redistribution and use of the SOFTWARE in source and binary forms, +* with or without modification constitutes the full acceptance of the +* following disclaimer as well as of the license herein and is permitted +* provided that the following conditions are met: +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the disclaimer detailed below. +* - Redistributions in binary form must reproduce the above copyright notice, mcd/mcd_api.h line 36
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* this list of conditions and the disclaimer detailed below in the +* documentation and/or other materials provided with the distribution. +* - Neither the name of its copyright holders nor the names of its +* contributors may be used to endorse or promote products derived from the +* Software without specific prior written permission. +* - Modification of any or all of the source code, documentation and other +* materials provided under this license are subject to acknowledgement of +* the modification(s) by including a prominent notice on the modification(s) +* stating the change(s) to the file(s), identifying the date of such change +* and stating the name of the publisher of any such modification(s). This 4th clause is rather obnoxious and....
Quoted 8 lines
mcd/mcd_api.h new file +8
-0+* VERSION HISTORY +* +* 1.0 "SPRINT Release" : SPRINT reference version +* +* 1.1 "Lauterbach Release" : +* - forces all boolean types to 8-bit on Linux and Mac-OS-X, +* but 32-bit on all other OS forces 32-bit enumeration types +* - additional memory spaces MCD_MEM_SPACE_IS_PHYSICAL, mcd/mcd_api.h line 69
Quoted 10 lines
mcd/mcd_api.h new file +10
-0+* MCD_MEM_SPACE_IS_LOGICAL, MCD_MEM_SPACE_IS_AUX +* - changed type of 2nd argument of mcd_qry_input_handle_f from "int" to +* "uint32_t" +* - changed type of element "data" of of mcd_tx_st from "unsigned char" to +* "uint8_t" +* - specifying the calling convention for MS Windows (x86) to __cdecl +* +* 1.2 "QEMU Release" : +* - changes formatting to accommodate QEMU's coding style guidelines +* - includes qemu/osdep.h instead of mcd_types.h Quoted 2 lines
....this appears to not be compliant with the license since it fails to include the dates
We've got the dates of modifications available at our version control. They will be added in the next version of this patch.
Quoted 10 lines
AFAICT this license is derived from a classic BSD 3 clause, with the extra 4th clause added.
I don't see any SPDX license matching this, which is painful as it means it is going to need license approval before it can be included by distributions downstream.
Does this really have to be under a custom license instead of a well known standard license ? There's really no good reason for inventing new open source licenses.
Quoted 5 lines
BSD 3-Clause Modification matches the license of the MCD API and is listed under the SPDX License List. Is it possible to extend checkpatch's @valid with "BSD-3-Clause-Modification"? That way, we can also add the SPDX-License-Identifier to
mcd_api.hwithout an error being generated by the script.
Conceptually this is similar to BSD-3-Clause-Modification, but the actual text of the license does not match
https://spdx.org/licenses/BSD-3-Clause-Modification.html
so IMHO we can't claim this is BSD-3-Clause-Modification currently.
IIUC, it would have to be submitted to SPDX for review to decide whether it needs to be a new license, or whether the permitted text for BSD-3-Clause-Modification can allow a choice of matches.
Quoted 3 lines
Thank you very much for taking the time to review the patch! I will add the changes in the next version of this series but will wait for further reviews until submitting v3 in order to keep the mailing list less busy.
Yep, makes sense.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Mario Fleischmann
Quoted 1 line · Daniel P. Berrangé
On Wed, Apr 30, 2025 at 07:27:22AM +0200, Mario Fleischmann wrote:
[...]
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
mcd/mcd_api.h new file +36
-0@@ -0,0 +1,3963 @@ +/* +* Copyright (c) 2008, ARM Ltd., Infineon Technologies, NXP Semiconductors, +* Lauterbach, STMicroelectronics and TIMA Laboratory. +* All rights reserved. +* +* PREAMBLE +* +* The MCD API (Multi-Core Debug) has been designed as an interface between +* software development tools and simulated or real systems with multi-core +* SoCs. The target is to allow consistent software tooling throughout the +* whole SoC development flow. +* The MCD API (the "SOFTWARE") has been developed jointly by ARM Ltd., +* Infineon Technologies, NXP Semiconductors, Lauterbach, +* STMicroelectronics and TIMA Laboratory as part of the SPRINT project +* (www.sprint-project.net). +* The SPRINT project has been funded by the European Commission. +* +* LICENSE +* +* Any redistribution and use of the SOFTWARE in source and binary forms, +* with or without modification constitutes the full acceptance of the +* following disclaimer as well as of the license herein and is permitted +* provided that the following conditions are met: +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the disclaimer detailed below. +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the disclaimer detailed below in the +* documentation and/or other materials provided with the distribution. +* - Neither the name of its copyright holders nor the names of its +* contributors may be used to endorse or promote products derived from the +* Software without specific prior written permission. +* - Modification of any or all of the source code, documentation and other +* materials provided under this license are subject to acknowledgement of +* the modification(s) by including a prominent notice on the modification(s) +* stating the change(s) to the file(s), identifying the date of such change +* and stating the name of the publisher of any such modification(s).
[...]
Quoted 20 lines
Quoted 11 lines
Quoted 10 lines
AFAICT this license is derived from a classic BSD 3 clause, with the extra 4th clause added.
I don't see any SPDX license matching this, which is painful as it means it is going to need license approval before it can be included by distributions downstream.
Does this really have to be under a custom license instead of a well known standard license ? There's really no good reason for inventing new open source licenses.
Quoted 5 lines
BSD 3-Clause Modification matches the license of the MCD API and is listed under the SPDX License List. Is it possible to extend checkpatch's @valid with "BSD-3-Clause-Modification"? That way, we can also add the SPDX-License-Identifier to
mcd_api.hwithout an error being generated by the script.Conceptually this is similar to BSD-3-Clause-Modification, but the actual text of the license does not match
Quoted 7 lines
https://spdx.org/licenses/BSD-3-Clause-Modification.html
so IMHO we can't claim this is BSD-3-Clause-Modification currently.
IIUC, it would have to be submitted to SPDX for review to decide whether it needs to be a new license, or whether the permitted text for BSD-3-Clause-Modification can allow a choice of matches.
So, according to the SPDX License List matching guidelines, changes to BSD-3-Clause-Modification can only be seen as equivalent if at most the clauses are stated in a different order, as indicated by the red text?
I assume we agree that the first three clauses match BSD-3-Clause. To show that the fourth clause matches BSD-3-Clause-Modification, I split up both license texts and indented MCD API's license:
If any files are modified, you must
Modification of any or all of the source code, documentation and other materials provided under this license are subject to
cause the modified files to carry prominent notices
acknowledgement of the modification(s) by including a prominent notice on the modification(s)
stating that you changed the files
stating the change(s) to the file(s)
... and stating the name of the publisher of any such modification(s)
and the date of any change.
identifying the date of such change
Stated like this, I think it is appropriate to see both clauses as equivalent. Since the contributor appendix on the third clause is not present in BSD-3-Clause-Modification, we have to specify the composite
Valid-License-Identifier: BSD-3-Clause-Modification AND BSD-3-Clause
Under which conditions is this Valid-License-Identifier ...well... valid? IIUC, we either need a formal approval from SPDX legal team or a relicensing of the MCD API. Is there maybe another way?
Best regards,
Mario
Re: [PATCH v2 01/20] mcd: Introduce Multi-Core Debug (MCD) API
Quoted 74 lines · Mario Fleischmann
Quoted 3 lines · Daniel P. Berrangé
Quoted 2 lines · Mario Fleischmann
Quoted 1 line · Daniel P. Berrangé
On Wed, Apr 30, 2025 at 07:27:22AM +0200, Mario Fleischmann wrote:
[...]
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
mcd/mcd_api.h new file +36
-0@@ -0,0 +1,3963 @@ +/* +* Copyright (c) 2008, ARM Ltd., Infineon Technologies, NXP Semiconductors, +* Lauterbach, STMicroelectronics and TIMA Laboratory. +* All rights reserved. +* +* PREAMBLE +* +* The MCD API (Multi-Core Debug) has been designed as an interface between +* software development tools and simulated or real systems with multi-core +* SoCs. The target is to allow consistent software tooling throughout the +* whole SoC development flow. +* The MCD API (the "SOFTWARE") has been developed jointly by ARM Ltd., +* Infineon Technologies, NXP Semiconductors, Lauterbach, +* STMicroelectronics and TIMA Laboratory as part of the SPRINT project +* (www.sprint-project.net). +* The SPRINT project has been funded by the European Commission. +* +* LICENSE +* +* Any redistribution and use of the SOFTWARE in source and binary forms, +* with or without modification constitutes the full acceptance of the +* following disclaimer as well as of the license herein and is permitted +* provided that the following conditions are met: +* - Redistributions of source code must retain the above copyright notice, +* this list of conditions and the disclaimer detailed below. +* - Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the disclaimer detailed below in the +* documentation and/or other materials provided with the distribution. +* - Neither the name of its copyright holders nor the names of its +* contributors may be used to endorse or promote products derived from the +* Software without specific prior written permission. +* - Modification of any or all of the source code, documentation and other +* materials provided under this license are subject to acknowledgement of +* the modification(s) by including a prominent notice on the modification(s) +* stating the change(s) to the file(s), identifying the date of such change +* and stating the name of the publisher of any such modification(s). [...]
Quoted 22 lines
Quoted 11 lines
Quoted 10 lines
AFAICT this license is derived from a classic BSD 3 clause, with the extra 4th clause added.
I don't see any SPDX license matching this, which is painful as it means it is going to need license approval before it can be included by distributions downstream.
Does this really have to be under a custom license instead of a well known standard license ? There's really no good reason for inventing new open source licenses.
Quoted 5 lines
BSD 3-Clause Modification matches the license of the MCD API and is listed under the SPDX License List. Is it possible to extend checkpatch's @valid with "BSD-3-Clause-Modification"? That way, we can also add the SPDX-License-Identifier to
mcd_api.hwithout an error being generated by the script.Conceptually this is similar to BSD-3-Clause-Modification, but the actual text of the license does not match
Quoted 8 lines
Quoted 5 lines
so IMHO we can't claim this is BSD-3-Clause-Modification currently.
IIUC, it would have to be submitted to SPDX for review to decide whether it needs to be a new license, or whether the permitted text for BSD-3-Clause-Modification can allow a choice of matches.
So, according to the SPDX License List matching guidelines, changes to BSD-3-Clause-Modification can only be seen as equivalent if at most the clauses are stated in a different order, as indicated by the red text?
I believe for matching requirements, ordering of paragraphs must be a fixed per:
In terms of lists, however, they permit the numbers to be substituted by bullets and vica-verca per
Quoted 1 line
I assume we agree that the first three clauses match BSD-3-Clause.
There are some slight wording differences in the first 2 clauses, but IMHO they don't make a semantic difference.
Quoted 2 lines
To show that the fourth clause matches BSD-3-Clause-Modification, I split up both license texts and indented MCD API's license:
For BSD-3-Clause-Modification it currently defines the 4th clause as
If any files are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
vs this file
Modification of any or all of the source code, documentation and other materials provided under this license are subject to acknowledgement of the modification(s) by including a prominent notice on the modification(s) stating the change(s) to the file(s), identifying the date of such change and stating the name of the publisher of any such modification(s).
Even though (IMHO) the legal implications are basically equivalent, under the SPDX matching guidelines I don't think we can consider this a match.
Quoted 5 lines
Stated like this, I think it is appropriate to see both clauses as equivalent. Since the contributor appendix on the third clause is not present in BSD-3-Clause-Modification, we have to specify the composite
Valid-License-Identifier: BSD-3-Clause-Modification AND BSD-3-Clause
I'm afraid that's not how SPDX license clauses work - the text of the license in the file needs to match one specific SPDX license, modulo fuzzy matching to the extent documented in the links above.
Quoted 3 lines
Under which conditions is this Valid-License-Identifier ...well... valid? IIUC, we either need a formal approval from SPDX legal team or a relicensing of the MCD API. Is there maybe another way?
The quickest option is almost certainly to get this reviewed by SPDX team as a new BSD variant.
Is there a canonical link where this license originates from ?
In terms of this QEMU series, I don't consider this a hard blocker, as we can work through it asynchronously.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v2 2/20 meson: Add --enable-mcd option
In reply to Mario Fleischmann--- docs/interop/mcd.rst | 6 ++++++ meson.build | 1 + meson_options.txt | 3 +++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 13 insertions(+)
docs/interop/mcd.rst +6 -0
@@ -38,6 +38,12 @@ The resulting system can be visualized as follows:: | qemu-system-* | | -machine | | -cpu | +----------------+ +----------+ +------+ +To configure the build for MCD support: + +.. code:: + + ./configure --enable-mcd + API Reference -------------
meson.build +1 -0
@@ -2500,6 +2500,7 @@ config_host_data.set('CONFIG_LIBSSH', libssh.found()) config_host_data.set('CONFIG_LINUX_AIO', libaio.found()) config_host_data.set('CONFIG_LINUX_IO_URING', linux_io_uring.found()) config_host_data.set('CONFIG_LIBPMEM', libpmem.found()) +config_host_data.set('CONFIG_MCD', get_option('mcd').enabled()) config_host_data.set('CONFIG_MODULES', enable_modules) config_host_data.set('CONFIG_NUMA', numa.found()) if numa.found()
meson_options.txt +3 -0
@@ -384,3 +384,6 @@ option('rust', type: 'feature', value: 'disabled', description: 'Rust support') option('strict_rust_lints', type: 'boolean', value: false, description: 'Enable stricter set of Rust warnings') + +option('mcd', type: 'feature', value: 'disabled', + description: 'debug support over the MCD API')
scripts/meson-buildoptions.sh +3 -0
@@ -152,6 +152,7 @@ meson_options_help() { printf "%s\n" ' lzfse lzfse support for DMG images' printf "%s\n" ' lzo lzo compression support' printf "%s\n" ' malloc-trim enable libc malloc_trim() for memory optimization' + printf "%s\n" ' mcd debug support over the MCD API' printf "%s\n" ' membarrier membarrier system call (for Linux 4.14+ or Windows' printf "%s\n" ' modules modules support (non Windows)' printf "%s\n" ' mpath Multipath persistent reservation passthrough'
@@ -401,6 +402,8 @@ _meson_option_parse() { --enable-malloc-trim) printf "%s" -Dmalloc_trim=enabled ;; --disable-malloc-trim) printf "%s" -Dmalloc_trim=disabled ;; --mandir=*) quote_sh "-Dmandir=$2" ;; + --enable-mcd) printf "%s" -Dmcd=enabled ;; + --disable-mcd) printf "%s" -Dmcd=disabled ;; --enable-membarrier) printf "%s" -Dmembarrier=enabled ;; --disable-membarrier) printf "%s" -Dmembarrier=disabled ;; --enable-module-upgrades) printf "%s" -Dmodule_upgrades=true ;;
Signature · 1 line
2.34.1
PATCH v2 3/20 mcd: Introduce MCD server
In reply to Mario FleischmannThe MCD implementation follows a remote procedure call approach and will use a client JSON protocol for communication.
While the MCD server implements the MCD API, the server stub will be responsible for handling the JSON connection and for dispatching the corresponding server functions.
--- mcd/mcd_server.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++ mcd/meson.build | 14 ++ meson.build | 4 + 3 files changed, 449 insertions(+) create mode 100644 mcd/mcd_server.c create mode 100644 mcd/meson.build
mcd/mcd_server.c new file +431 -0
@@ -0,0 +1,431 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* mcdserver - Multi-Core Debug (MCD) API implementation +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "mcd_api.h" + +static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_FN_UNIMPLEMENTED , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="" , +}; + +static const mcd_error_info_st MCD_ERROR_NONE = { + .return_status =MCD_RET_ACT_NONE , + .error_code =MCD_ERR_NONE , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="" , +}; + +/** +* struct mcdserver_state - State of the MCD server +* +* @last_error: Error info of most recent executed function. +*/ +typedef struct mcdserver_state { +const mcd_error_info_st *last_error; +}mcdserver_state ; + +static mcdserver_state g_server_state = { + .last_error = &MCD_ERROR_NONE , +}; + +mcd_return_et mcd_initialize_f (const mcd_api_version_st *version_req, +mcd_impl_version_info_st *impl_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +void mcd_exit_f (void ) +{ +return ; +} + +mcd_return_et mcd_qry_servers_f (const char *host,bool running, +uint32_t start_index,uint32_t *num_servers, +mcd_server_info_st *server_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_open_server_f (const char *system_key, +const char *config_string, +mcd_server_st **server) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_close_server_f (const mcd_server_st *server) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_set_server_config_f (const mcd_server_st *server, +const char *config_string) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_server_config_f (const mcd_server_st *server, +uint32_t *max_len, +char *config_string) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_systems_f (uint32_t start_index,uint32_t *num_systems, +mcd_core_con_info_st *system_con_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_devices_f (const mcd_core_con_info_st *system_con_info, +uint32_t start_index,uint32_t *num_devices, +mcd_core_con_info_st *device_con_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_cores_f (const mcd_core_con_info_st *connection_info, +uint32_t start_index,uint32_t *num_cores, +mcd_core_con_info_st *core_con_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_core_modes_f (const mcd_core_st *core, +uint32_t start_index,uint32_t *num_modes, +mcd_core_mode_info_st *core_mode_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_open_core_f (const mcd_core_con_info_st *core_con_info, +mcd_core_st **core) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_close_core_f (const mcd_core_st *core) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +void mcd_qry_error_info_f (const mcd_core_st *core, +mcd_error_info_st *error_info) +{ +if (error_info) { + *error_info = *g_server_state.last_error; + } +} + +mcd_return_et mcd_qry_device_description_f (const mcd_core_st *core,char *url, +uint32_t *url_length) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_max_payload_size_f (const mcd_core_st *core, +uint32_t *max_payload) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_input_handle_f (const mcd_core_st *core, +uint32_t *input_handle) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_mem_spaces_f (const mcd_core_st *core, +uint32_t start_index, +uint32_t *num_mem_spaces, +mcd_memspace_st *mem_spaces) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_mem_blocks_f (const mcd_core_st *core, +uint32_t mem_space_id,uint32_t start_index, +uint32_t *num_mem_blocks, +mcd_memblock_st *mem_blocks) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_active_overlays_f (const mcd_core_st *core, +uint32_t start_index, +uint32_t *num_active_overlays, +uint32_t *active_overlays) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_reg_groups_f (const mcd_core_st *core, +uint32_t start_index, +uint32_t *num_reg_groups, +mcd_register_group_st *reg_groups) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_reg_map_f (const mcd_core_st *core,uint32_t reg_group_id, +uint32_t start_index,uint32_t *num_regs, +mcd_register_info_st *reg_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_reg_compound_f (const mcd_core_st *core, +uint32_t compound_reg_id, +uint32_t start_index, +uint32_t *num_reg_ids, +uint32_t *reg_id_array) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trig_info_f (const mcd_core_st *core, +mcd_trig_info_st *trig_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_ctrigs_f (const mcd_core_st *core,uint32_t start_index, +uint32_t *num_ctrigs, +mcd_ctrig_info_st *ctrig_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_create_trig_f (const mcd_core_st *core,void *trig, +uint32_t *trig_id) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trig_f (const mcd_core_st *core,uint32_t trig_id, +uint32_t max_trig_size,void *trig) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_remove_trig_f (const mcd_core_st *core,uint32_t trig_id) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trig_state_f (const mcd_core_st *core,uint32_t trig_id, +mcd_trig_state_st *trig_state) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_activate_trig_set_f (const mcd_core_st *core) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_remove_trig_set_f (const mcd_core_st *core) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trig_set_f (const mcd_core_st *core,uint32_t start_index, +uint32_t *num_trigs,uint32_t *trig_ids) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trig_set_state_f (const mcd_core_st *core, +mcd_trig_set_state_st *trig_state) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_execute_txlist_f (const mcd_core_st *core, +mcd_txlist_st *txlist) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_run_f (const mcd_core_st *core,bool global) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_stop_f (const mcd_core_st *core,bool global) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_run_until_f (const mcd_core_st *core,bool global, +bool absolute_time,uint64_t run_until_time) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_current_time_f (const mcd_core_st *core, +uint64_t *current_time) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_step_f (const mcd_core_st *core,bool global, +mcd_core_step_type_et step_type,uint32_t n_steps) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_set_global_f (const mcd_core_st *core,bool enable) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_state_f (const mcd_core_st *core,mcd_core_state_st *state) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_execute_command_f (const mcd_core_st *core, +const char *command_string, +uint32_t result_string_size, +char *result_string) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_rst_classes_f (const mcd_core_st *core, +uint32_t *rst_class_vector) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_rst_class_info_f (const mcd_core_st *core, +uint8_t rst_class, +mcd_rst_info_st *rst_info) +{ + + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_rst_f (const mcd_core_st *core,uint32_t rst_class_vector, +bool rst_and_halt) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_chl_open_f (const mcd_core_st *core,mcd_chl_st *channel) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_send_msg_f (const mcd_core_st *core,const mcd_chl_st *channel, +uint32_t msg_len,const uint8_t *msg) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_receive_msg_f (const mcd_core_st *core, +const mcd_chl_st *channel,uint32_t timeout, +uint32_t *msg_len,uint8_t *msg) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_chl_reset_f (const mcd_core_st *core, +const mcd_chl_st *channel) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_chl_close_f (const mcd_core_st *core, +const mcd_chl_st *channel) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_traces_f (const mcd_core_st *core,uint32_t start_index, +uint32_t *num_traces, +mcd_trace_info_st *trace_info) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_qry_trace_state_f (const mcd_core_st *core,uint32_t trace_id, +mcd_trace_state_st *state) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_set_trace_state_f (const mcd_core_st *core,uint32_t trace_id, +mcd_trace_state_st *state) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +} + +mcd_return_et mcd_read_trace_f (const mcd_core_st *core,uint32_t trace_id, +uint64_t start_index,uint32_t *num_frames, +uint32_t trace_data_size,void *trace_data) +{ + g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +return g_server_state.last_error->return_status; +}
mcd/meson.build new file +14 -0
@@ -0,0 +1,14 @@ +mcd_ss = ss.source_set() + +mcd_ss.add(files( + 'mcd_server.c')) + +mcd_ss = mcd_ss.apply({}) + +libmcd = static_library('mcd_system', + mcd_ss.sources() + genh, + build_by_default: false) + +mcd = declare_dependency(objects: libmcd.extract_all_objects(recursive: false)) + +system_ss.add(mcd)
meson.build +4 -0
@@ -4030,6 +4030,10 @@ libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh, hwcore = declare_dependency(objects: libhwcore.extract_all_objects(recursive: false)) common_ss.add(hwcore) +if get_option('mcd').enabled() + subdir('mcd') +endif + ########### # Targets # ###########
Signature · 1 line
2.34.1
Re: [PATCH v2 03/20] mcd: Introduce MCD server
Quoted 22 lines · Mario Fleischmann
The MCD implementation follows a remote procedure call approach and will use a client JSON protocol for communication.
While the MCD server implements the MCD API, the server stub will be responsible for handling the JSON connection and for dispatching the corresponding server functions.
Signed-off-by Mario Fleischmann <[email protected]>--- mcd/mcd_server.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++ mcd/meson.build | 14 ++ meson.build | 4 + 3 files changed, 449 insertions(+) create mode 100644 mcd/mcd_server.c create mode 100644 mcd/meson.buildmcd/mcd_server.c new file +0
-0
mcd/mcd_server.c line 3
Quoted 3 lines
mcd/mcd_server.c new file +3
-0@@ -0,0 +1,431 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* mcdserver - Multi-Core Debug (MCD) API implementation
Nitpick - you don't need to open & close a comment just for the SPDX tag, just let the whole header flow as one comment
mcd/mcd_server.c line 8
Quoted 5 lines
mcd/mcd_server.c new file +5
-0+* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory.
This text should be omitted in any new files - only the SPDX tag is expected/required.
I won't repeat them on later patches, but these comments apply to all new files through this whole series.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v2 4/20 qapi: Introduce MCD schema
In reply to Mario FleischmannThe MCD implementation follows a remote procedure call approach:
Each function from mcd_api.h will correspond to one command in mcd.json.
--- MAINTAINERS | 1 + docs/interop/mcd.rst | 13 +++++++++++++ mcd/meson.build | 27 +++++++++++++++++++++++++++ qapi/mcd.json | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 qapi/mcd.json
MAINTAINERS +1 -0
@@ -3125,6 +3125,7 @@ M: Mario Fleischmann <[email protected]> S: Maintained F: mcd/* F: docs/interop/mcd.rst +F: qapi/mcd.json Memory API M: Paolo Bonzini <[email protected]>
docs/interop/mcd.rst +13 -0
@@ -44,6 +44,19 @@ To configure the build for MCD support: ./configure --enable-mcd +Debugging via QAPI +------------------ + +Since the MCD API does not define a communication protocol, a QAPI schema +has been added to implement a remote procedure call mechanism. +Each function within the API corresponds to one QAPI command, ensuring a +one-to-one mapping between the API's functions and the QAPI commands. + +QAPI Reference +-------------- + +.. qapi-doc:: qapi/mcd.json + API Reference -------------
mcd/meson.build +27 -0
@@ -1,5 +1,32 @@ +mcd_qapi_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-emit-events.c', + 'mcd-qapi-emit-events.h', + 'mcd-qapi-events.c', + 'mcd-qapi-events.h', + 'mcd-qapi-features.c', + 'mcd-qapi-features.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h', + 'mcd-qapi-introspect.c', + 'mcd-qapi-introspect.h', + 'mcd-qapi-types.c', + 'mcd-qapi-types.h', + 'mcd-qapi-visit.c', + 'mcd-qapi-visit.h', +] + +mcd_qapi_files = custom_target('MCD QAPI files', + output: mcd_qapi_outputs, + input: '../qapi/mcd.json', + command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', + '--suppress-tracing','@INPUT0@'], + depend_files: qapi_gen_depends) + mcd_ss = ss.source_set() +mcd_ss.add(mcd_qapi_files.to_list()) mcd_ss.add(files( 'mcd_server.c'))
qapi/mcd.json new file +6 -0
@@ -0,0 +1,6 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Multi-Core Debug (MCD) API +##
Signature · 1 line
2.34.1
Re: [PATCH v2 04/20] qapi: Introduce MCD schema
Quoted 34 lines · Mario Fleischmann
The MCD implementation follows a remote procedure call approach:
Each function frommcd_api.hwill correspond to one command in mcd.json.Signed-off-by Mario Fleischmann <[email protected]>--- MAINTAINERS | 1 + docs/interop/mcd.rst | 13 +++++++++++++ mcd/meson.build | 27 +++++++++++++++++++++++++++ qapi/mcd.json | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 qapi/mcd.jsonMAINTAINERS +1
-0@@ -3125,6 +3125,7 @@ M: Mario Fleischmann <[email protected]> S: Maintained F: mcd/* F: docs/interop/mcd.rst +F: qapi/mcd.json Memory API M: Paolo Bonzini <[email protected]>docs/interop/mcd.rst +2
-0@@ -44,6 +44,19 @@ To configure the build for MCD support: ./configure --enable-mcd +Debugging via QAPI +------------------
docs/interop/mcd.rst To configure the build for MCD support: · line 58
Quoted 10 lines
docs/interop/mcd.rst +10
-0+ +Since the MCD API does not define a communication protocol, a QAPI schema +has been added to implement a remote procedure call mechanism. +Each function within the API corresponds to one QAPI command, ensuring a +one-to-one mapping between the API's functions and the QAPI commands. + +QAPI Reference +-------------- + +.. qapi-doc:: qapi/mcd.json
You also need
:transmogrify:
because we haven't completed the transition to John Snow's new doc generator ("transmogrifier"), and
:namespace: MCD
for a properly separate namespace (see docs/devel/qapi-domain.rst).
I'd expect this to generate its own index, but it doesn't. John, can you have a look?
qapi/mcd.json
Quoted 46 lines
docs/interop/mcd.rst +1
-0+ API Reference -------------mcd/meson.build +27
-0@@ -1,5 +1,32 @@ +mcd_qapi_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-emit-events.c', + 'mcd-qapi-emit-events.h', + 'mcd-qapi-events.c', + 'mcd-qapi-events.h', + 'mcd-qapi-features.c', + 'mcd-qapi-features.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h', + 'mcd-qapi-introspect.c', + 'mcd-qapi-introspect.h', + 'mcd-qapi-types.c', + 'mcd-qapi-types.h', + 'mcd-qapi-visit.c', + 'mcd-qapi-visit.h', +] + +mcd_qapi_files = custom_target('MCD QAPI files', + output: mcd_qapi_outputs, + input: '../qapi/mcd.json', + command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', + '--suppress-tracing','@INPUT0@'], + depend_files: qapi_gen_depends) + mcd_ss = ss.source_set() +mcd_ss.add(mcd_qapi_files.to_list()) mcd_ss.add(files( 'mcd_server.c'))qapi/mcd.json new file +0
-0
Let's use mcd/qapi-schema.json, similar to the other independent QAPI schemas, such as qga/qapi-schema.json.
Quoted 7 lines
qapi/mcd.json new file +6
-0@@ -0,0 +1,6 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Multi-Core Debug (MCD) API +##
Re: [PATCH v2 04/20] qapi: Introduce MCD schema
Quoted 54 lines · Markus Armbruster
Quoted 34 lines · Mario Fleischmann
The MCD implementation follows a remote procedure call approach:
Each function frommcd_api.hwill correspond to one command in mcd.json.Signed-off-by Mario Fleischmann <[email protected]>--- MAINTAINERS | 1 + docs/interop/mcd.rst | 13 +++++++++++++ mcd/meson.build | 27 +++++++++++++++++++++++++++ qapi/mcd.json | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 qapi/mcd.jsonMAINTAINERS +1
-0@@ -3125,6 +3125,7 @@ M: Mario Fleischmann <[email protected]> S: Maintained F: mcd/* F: docs/interop/mcd.rst +F: qapi/mcd.json Memory API M: Paolo Bonzini <[email protected]>docs/interop/mcd.rst +2
-0@@ -44,6 +44,19 @@ To configure the build for MCD support: ./configure --enable-mcd +Debugging via QAPI +------------------docs/interop/mcd.rst To configure the build for MCD support: · line 58
Quoted 10 lines
docs/interop/mcd.rst +10
-0+ +Since the MCD API does not define a communication protocol, a QAPI schema +has been added to implement a remote procedure call mechanism. +Each function within the API corresponds to one QAPI command, ensuring a +one-to-one mapping between the API's functions and the QAPI commands. + +QAPI Reference +-------------- + +.. qapi-doc:: qapi/mcd.jsonYou also need
:transmogrify:
because we haven't completed the transition to John Snow's new doc generator ("transmogrifier"), and
Quoted 6 lines
:namespace: MCD
for a properly separate namespace (see
docs/devel/qapi-domain.rst).I'd expect this to generate its own index, but it doesn't. John, can you have a look?
John has since reminded me of the need to add it to docs/conf.py. Together, this generates docs/manual/qapi-mcd-index.html. You need to link to it manually. Sketch appended for you convenience.
Quoted 50 lines
qapi/mcd.json
Quoted 46 lines
docs/interop/mcd.rst +1
-0+ API Reference -------------mcd/meson.build +27
-0@@ -1,5 +1,32 @@ +mcd_qapi_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-emit-events.c', + 'mcd-qapi-emit-events.h', + 'mcd-qapi-events.c', + 'mcd-qapi-events.h', + 'mcd-qapi-features.c', + 'mcd-qapi-features.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h', + 'mcd-qapi-introspect.c', + 'mcd-qapi-introspect.h', + 'mcd-qapi-types.c', + 'mcd-qapi-types.h', + 'mcd-qapi-visit.c', + 'mcd-qapi-visit.h', +] + +mcd_qapi_files = custom_target('MCD QAPI files', + output: mcd_qapi_outputs, + input: '../qapi/mcd.json', + command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', + '--suppress-tracing','@INPUT0@'], + depend_files: qapi_gen_depends) + mcd_ss = ss.source_set() +mcd_ss.add(mcd_qapi_files.to_list()) mcd_ss.add(files( 'mcd_server.c'))qapi/mcd.json new file +0
-0Let's use
mcd/qapi-schema.json, similar to the other independent QAPI schemas, such asqga/qapi-schema.json.
Quoted 7 lines
qapi/mcd.json line 6
Quoted 7 lines
qapi/mcd.json new file +6
-0@@ -0,0 +1,6 @@ +# -*- Mode: Python -*- +# vim: filetype=python + +## +# = Multi-Core Debug (MCD) API +##
docs/conf.py +1 -0
@@ -201,6 +201,7 @@ # Due to a limitation in Sphinx, we need to know which indices to # generate in advance. Adding a namespace here allows that generation. qapi_namespaces = { + "MCD", "QGA", "QMP", "QSD",
docs/interop/mcd.rst +2 -0
@@ -58,6 +58,8 @@ QAPI Reference -------------- .. qapi-doc:: qapi/mcd.json + :transmogrify: + :namespace: MCD API Reference -------------
qapi/mcd.json +2 -0
@@ -3,6 +3,8 @@ ## # = Multi-Core Debug (MCD) API +# +# For locating a particular item, please see the `qapi-mcd-index`. ##
PATCH v2 5/20 mcd: Introduce MCD server stub
In reply to Mario FleischmannTo keep the MCD JSON protocol separate from QMP, a custom monitor has been implemented in mcd_monitor.c which can be run in parallel to the QMP monitor. It is responsible for handling the JSON communication and for dispatching the corresponding functions in mcd_stub.c
The MCD server stub will call the corresponding server functions.
To start the MCD monitor, configure QEMU with --enable-mcd and start it with the -mcd option.
--- MAINTAINERS | 1 + docs/interop/mcd.rst | 2 + include/exec/mcdstub.h | 17 ++++++++ mcd/mcd_monitor.c | 89 ++++++++++++++++++++++++++++++++++++++++++ mcd/mcd_stub.c | 11 ++++++ mcd/meson.build | 4 +- qemu-options.hx | 11 ++++++ system/vl.c | 13 ++++++ 8 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 include/exec/mcdstub.h create mode 100644 mcd/mcd_monitor.c create mode 100644 mcd/mcd_stub.c
MAINTAINERS +1 -0
@@ -3126,6 +3126,7 @@ S: Maintained F: mcd/* F: docs/interop/mcd.rst F: qapi/mcd.json +F: include/exec/mcdstub.h Memory API M: Paolo Bonzini <[email protected]>
docs/interop/mcd.rst +2 -0
@@ -52,6 +52,8 @@ has been added to implement a remote procedure call mechanism. Each function within the API corresponds to one QAPI command, ensuring a one-to-one mapping between the API's functions and the QAPI commands. +Use the option ``-mcd dev`` to start MCD's QAPI monitor. + QAPI Reference --------------
include/exec/mcdstub.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef MCDSTUB_H +#define MCDSTUB_H + +#include "qemu/osdep.h" +#include "qapi/error.h" + +bool mcd_monitor_start (const char *device,Error **errp); + +#endif /* MCDSTUB_H */
mcd/mcd_monitor.c new file +89 -0
89 lines not on this page · raw message
mcd/mcd_stub.c new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* mcdstub - Conversion of MCD QAPI requests to MCD server function calls +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "mcd_api.h"
mcd/meson.build +3 -1
@@ -28,7 +28,9 @@ mcd_ss = ss.source_set() mcd_ss.add(mcd_qapi_files.to_list()) mcd_ss.add(files( - 'mcd_server.c')) + 'mcd_server.c', + 'mcd_stub.c', + 'mcd_monitor.c')) mcd_ss = mcd_ss.apply({})
qemu-options.hx +11 -0
@@ -4724,6 +4724,17 @@ SRST (see the :ref:`GDB usage` chapter in the System Emulation Users Guide). ERST + +#ifdef CONFIG_MCD +DEF("mcd", HAS_ARG, QEMU_OPTION_mcd, \ + "-mcd dev accept MCD connection on 'dev'\n", + QEMU_ARCH_ALL) +SRST +``-mcd dev`` + Start the MCD QAPI monitor and accept connections on device 'dev'. +ERST +#endif + DEF("d", HAS_ARG, QEMU_OPTION_d, \ "-d item1,... enable logging of specified items (use '-d help' for a list of log items)\n", QEMU_ARCH_ALL)
system/vl.c +13 -0
@@ -71,6 +71,9 @@#include "system/numa.h" #include "system/hostmem.h" #include "exec/gdbstub.h" +#ifdef CONFIG_MCD +#include "exec/mcdstub.h" +#endif #include "gdbstub/enums.h" #include "qemu/timer.h" #include "chardev/char.h"
@@ -1280,6 +1283,7 @@ struct device_config {DEV_PARALLEL ,/* -parallel */ DEV_DEBUGCON ,/* -debugcon */ DEV_GDB ,/* -gdb, -s */ +DEV_MCD ,/* -mcd */ DEV_SCLP ,/* s390 sclp */ } type;const char *cmdline;
@@ -2789,6 +2793,10 @@ static bool qemu_machine_creation_done(Error **errp)foreach_device_config_or_exit (DEV_GDB , gdbserver_start); +#ifdef CONFIG_MCD +foreach_device_config_or_exit (DEV_MCD , mcd_monitor_start); +#endif +if (!vga_interface_created && !default_vga && vga_interface_type !=VGA_NONE ) { warn_report("A -vga option was passed but this machine "
@@ -3150,6 +3158,11 @@ void qemu_init(int argc, char **argv)case QEMU_OPTION_gdb:add_device_config (DEV_GDB , optarg);break ; +#ifdef CONFIG_MCD +case QEMU_OPTION_mcd: +add_device_config (DEV_MCD , optarg); +break ; +#endif case QEMU_OPTION_L :if (is_help_option (optarg)) { list_data_dirs = true;
Signature · 1 line
2.34.1
PATCH v2 6/20 qtest: Introduce MCD test suite
In reply to Mario Fleischmannqtest_qmp provides a convenient way to automatically serialize into the client JSON protocol and to send the command to the QMP socket. Since qtest has a strong dependency to the QMP monitor, a minimal number of function has been added to mcd-test.c for interoperability with MCD's protocol.
--- MAINTAINERS | 1 + tests/qtest/mcd-test.c | 82 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-util.h | 21 +++++++++++ tests/qtest/meson.build | 5 +++ 4 files changed, 109 insertions(+) create mode 100644 tests/qtest/mcd-test.c create mode 100644 tests/qtest/mcd-util.h
MAINTAINERS +1 -0
@@ -3127,6 +3127,7 @@ F: mcd/* F: docs/interop/mcd.rst F: qapi/mcd.json F: include/exec/mcdstub.h +X: tests/qtest/mcd-* Memory API M: Paolo Bonzini <[email protected]>
tests/qtest/mcd-test.c new file +82 -0
82 lines not on this page · raw message
tests/qtest/mcd-util.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* mcdutil - Utility functions for the MCD API test suite +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef TEST_MCD_UTILS_H +#define TEST_MCD_UTILS_H + +#include "libqtest.h" + +typedef struct { +QTestState *qts; +int mcd_fd; +}QTestStateMCD ; + +#endif /* TEST_MCD_UTILS_H */
tests/qtest/meson.build +5 -0
@@ -397,6 +397,11 @@ if dbus_display qtests += {'dbus-display-test': [dbus_display1, gio]} endif +if get_option('mcd').enabled() + qtests += { 'mcd-test': files('mcd-test.c') } + qtests_generic += [ 'mcd-test' ] +endif + qtest_executables = {} foreach dir : target_dirs if not dir.endswith('-softmmu')
Signature · 1 line
2.34.1
PATCH v2 7/20 mcd: Implement target initialization API
In reply to Mario FleischmannThe target initialization API ensures that the requested and provided MCD versions are compatible.
* implement mcd_initialize_f and mcd_qry_error_info_f in mcdserver
* implement QMP stub functionality
* add QTest
Thanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
--- mcd/mcd_qapi.c | 66 +++++++++++++++ mcd/mcd_qapi.h | 26 ++++++ mcd/mcd_server.c | 44 +++++++++- mcd/mcd_stub.c | 35 ++++++++ mcd/meson.build | 49 +++++++---- qapi/mcd.json | 183 ++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 62 ++++++++++++++ tests/qtest/mcd-util.c | 99 ++++++++++++++++++++++ tests/qtest/mcd-util.h | 6 ++ tests/qtest/meson.build | 2 +- 10 files changed, 554 insertions(+), 18 deletions(-) create mode 100644 mcd/mcd_qapi.c create mode 100644 mcd/mcd_qapi.h create mode 100644 tests/qtest/mcd-util.c
mcd/mcd_qapi.c new file +66 -0
@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "mcd_qapi.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version) +{ +MCDAPIVersion *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDAPIVersion ) { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + .author =g_strdup (api_version->author), + }; + +return marshal; +} + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version) +{ +mcd_api_version_st unmarshal = { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + }; +strncpy (unmarshal.author, api_version->author,MCD_API_IMP_VENDOR_LEN -1 ); +return unmarshal; +} + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info) +{ +MCDImplVersionInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDImplVersionInfo ) { + .v_api =marshal_mcd_api_version (&impl_info->v_api), + .v_imp_major = impl_info->v_imp_major, + .v_imp_minor = impl_info->v_imp_minor, + .v_imp_build = impl_info->v_imp_build, + .vendor =g_strdup (impl_info->vendor), + .date =g_strdup (impl_info->date), + }; + +return marshal; +} + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info) +{ +MCDErrorInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDErrorInfo ) { + .return_status = error_info->return_status, + .error_code = error_info->error_code, + .error_events = error_info->error_events, + .error_str =g_strdup (error_info->error_str), + }; + +return marshal; +}
mcd/mcd_qapi.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef MCD_QAPI_H +#define MCD_QAPI_H + +#include "mcd_api.h" +#include "mcd/mcd-qapi-types.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version); + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info); + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); + +#endif /* MCD_QAPI_H */
mcd/mcd_server.c +43 -1
73 lines not on this page · raw message
mcd/mcd_stub.c +35 -0
@@ -8,4 +8,39 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" +#include "mcd_qapi.h" +#include "mcd/mcd-qapi-commands.h" + +MCDInitializeResult *qmp_mcd_initialize (MCDAPIVersion *version_req, +Error **errp) +{ +mcd_impl_version_info_st impl_info; +MCDInitializeResult *result =g_malloc0 (sizeof (*result)); +mcd_api_version_st version_req_unmarshalled = +unmarshal_mcd_api_version (version_req); + + result->return_status =mcd_initialize_f (&version_req_unmarshalled, + &impl_info); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->impl_info =marshal_mcd_impl_version_info (&impl_info); + } + +return result; +} + +void qmp_mcd_exit (Error **errp) +{ +mcd_exit_f (); +} + +MCDErrorInfo *qmp_mcd_qry_error_info (Error **errp) +{ +MCDErrorInfo *result; +mcd_error_info_st error_info; +mcd_qry_error_info_f (NULL , &error_info); + result =marshal_mcd_error_info (&error_info); +return result; +}
mcd/meson.build +33 -16
74 lines not on this page · raw message
qapi/mcd.json +183 -0
186 lines not on this page · raw message
tests/qtest/mcd-test.c +62 -0
79 lines not on this page · raw message
tests/qtest/mcd-util.c new file +99 -0
99 lines not on this page · raw message
tests/qtest/mcd-util.h +6 -0
@@ -12,10 +12,16 @@#define TEST_MCD_UTILS_H #include "libqtest.h" +#include "mcd/mcd-qapi-visit.h" typedef struct {QTestState *qts;int mcd_fd; }QTestStateMCD ; +MCDInitializeResult *qtest_mcd_initialize (QTestStateMCD *qts, +q_obj_mcd_initialize_arg *args); + +MCDErrorInfo *qtest_mcd_qry_error_info (QTestStateMCD *qts); +#endif /* TEST_MCD_UTILS_H */
tests/qtest/meson.build +1 -1
@@ -398,7 +398,7 @@ if dbus_display endif if get_option('mcd').enabled() - qtests += { 'mcd-test': files('mcd-test.c') } + qtests += { 'mcd-test': files('mcd-test.c', 'mcd-util.c') + mcd_qapi } qtests_generic += [ 'mcd-test' ] endif
Signature · 1 line
2.34.1
Re: [PATCH v2 07/20] mcd: Implement target initialization API
Quoted 56 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>--- mcd/mcd_qapi.c | 66 +++++++++++++++ mcd/mcd_qapi.h | 26 ++++++ mcd/mcd_server.c | 44 +++++++++- mcd/mcd_stub.c | 35 ++++++++ mcd/meson.build | 49 +++++++---- qapi/mcd.json | 183 ++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 62 ++++++++++++++ tests/qtest/mcd-util.c | 99 ++++++++++++++++++++++ tests/qtest/mcd-util.h | 6 ++ tests/qtest/meson.build | 2 +- 10 files changed, 554 insertions(+), 18 deletions(-) create mode 100644 mcd/mcd_qapi.c create mode 100644 mcd/mcd_qapi.h create mode 100644 tests/qtest/mcd-util.cmcd/mcd_qapi.c new file +23
-0@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "mcd_qapi.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version) +{ +MCDAPIVersion *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDAPIVersion ) { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + .author =g_strdup (api_version->author), + }; +
mcd/mcd_qapi.c line 33
Quoted 10 lines
mcd/mcd_qapi.c new file +10
-0+return marshal; +} + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version) +{ +mcd_api_version_st unmarshal = { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + }; +strncpy (unmarshal.author, api_version->author,MCD_API_IMP_VENDOR_LEN -1 );
Have you considered sizeof(unmarshal.author) - 1 ?
pstrcpy() from qemu/cutils.h is easier to use safely.
Quoted 260 lines
mcd/mcd_qapi.c new file +33
-0+return unmarshal; +} + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info) +{ +MCDImplVersionInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDImplVersionInfo ) { + .v_api =marshal_mcd_api_version (&impl_info->v_api), + .v_imp_major = impl_info->v_imp_major, + .v_imp_minor = impl_info->v_imp_minor, + .v_imp_build = impl_info->v_imp_build, + .vendor =g_strdup (impl_info->vendor), + .date =g_strdup (impl_info->date), + }; + +return marshal; +} + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info) +{ +MCDErrorInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDErrorInfo ) { + .return_status = error_info->return_status, + .error_code = error_info->error_code, + .error_events = error_info->error_events, + .error_str =g_strdup (error_info->error_str), + }; + +return marshal; +}mcd/mcd_qapi.h new file +26
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef MCD_QAPI_H +#define MCD_QAPI_H + +#include "mcd_api.h" +#include "mcd/mcd-qapi-types.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version); + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info); + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); + +#endif /* MCD_QAPI_H */ mcd/mcd_server.c +43
-1@@ -8,6 +8,7 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = {@@ -17,6 +18,13 @@ static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = { .error_str = "", }; +static const mcd_error_info_st MCD_ERROR_INVALID_NULL_PARAM = { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="null was invalidly passed as a parameter" , +}; +static const mcd_error_info_st MCD_ERROR_NONE = { .return_status =MCD_RET_ACT_NONE , .error_code =MCD_ERR_NONE ,@@ -24,6 +32,9 @@ static const mcd_error_info_st MCD_ERROR_NONE = { .error_str = "", }; +/* reserves memory for custom errors */ +static mcd_error_info_st custom_mcd_error; +/** * struct mcdserver_state - State of the MCD server * @@ -40,12 +51,43 @@ static mcdserver_state g_server_state = {mcd_return_et mcd_initialize_f (const mcd_api_version_st *version_req,mcd_impl_version_info_st *impl_info) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +if (!version_req || !impl_info) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + *impl_info = (mcd_impl_version_info_st ) { + .v_api = (mcd_api_version_st ) { + .v_api_major =MCD_API_VER_MAJOR , + .v_api_minor =MCD_API_VER_MINOR , + .author =MCD_API_VER_AUTHOR , + }, + .v_imp_major =QEMU_VERSION_MAJOR , + .v_imp_minor =QEMU_VERSION_MINOR , + .v_imp_build =0 , + .vendor ="QEMU" , + .date = __DATE__, + }; + +if (version_req->v_api_major ==MCD_API_VER_MAJOR && + version_req->v_api_minor <=MCD_API_VER_MINOR ) { + g_server_state.last_error = &MCD_ERROR_NONE ; + }else { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_GENERAL , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="incompatible versions" , + }; + g_server_state.last_error = &custom_mcd_error; + } +return g_server_state.last_error->return_status; }void mcd_exit_f (void ) { + g_server_state.last_error = &MCD_ERROR_NONE ;return ; }mcd/mcd_stub.c +35
-0@@ -8,4 +8,39 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" +#include "mcd_qapi.h" +#include "mcd/mcd-qapi-commands.h" + +MCDInitializeResult *qmp_mcd_initialize (MCDAPIVersion *version_req, +Error **errp) +{ +mcd_impl_version_info_st impl_info; +MCDInitializeResult *result =g_malloc0 (sizeof (*result)); +mcd_api_version_st version_req_unmarshalled = +unmarshal_mcd_api_version (version_req); + + result->return_status =mcd_initialize_f (&version_req_unmarshalled, + &impl_info); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->impl_info =marshal_mcd_impl_version_info (&impl_info); + } + +return result; +} + +void qmp_mcd_exit (Error **errp) +{ +mcd_exit_f (); +} + +MCDErrorInfo *qmp_mcd_qry_error_info (Error **errp) +{ +MCDErrorInfo *result; +mcd_error_info_st error_info; +mcd_qry_error_info_f (NULL , &error_info); + result =marshal_mcd_error_info (&error_info); +return result; +}mcd/meson.build +25
-15@@ -1,14 +1,10 @@ mcd_qapi_outputs = [ - 'mcd-qapi-commands.c', - 'mcd-qapi-commands.h', 'mcd-qapi-emit-events.c', 'mcd-qapi-emit-events.h', 'mcd-qapi-events.c', 'mcd-qapi-events.h', 'mcd-qapi-features.c', 'mcd-qapi-features.h', - 'mcd-qapi-init-commands.c', - 'mcd-qapi-init-commands.h', 'mcd-qapi-introspect.c', 'mcd-qapi-introspect.h', 'mcd-qapi-types.c',@@ -17,27 +13,48 @@ mcd_qapi_outputs = [ 'mcd-qapi-visit.h', ] +# QAPI outputs that will only be used by the MCD server +mcd_qapi_server_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h' +] + mcd_qapi_files = custom_target('MCD QAPI files', - output: mcd_qapi_outputs, + output: mcd_qapi_outputs + mcd_qapi_server_outputs, input: '../qapi/mcd.json', command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', '--suppress-tracing','@INPUT0@'], depend_files: qapi_gen_depends) -mcd_ss = ss.source_set() +mcd_qapi_ss = ss.source_set() -mcd_ss.add(mcd_qapi_files.to_list()) -mcd_ss.add(files( - 'mcd_server.c', - 'mcd_stub.c', - 'mcd_monitor.c')) +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_outputs.contains(fs.name(f)) + mcd_qapi_ss.add([f]) + endif +endforeach -mcd_ss = mcd_ss.apply({}) +mcd_qapi_ss.add(files('mcd_qapi.c')) +mcd_qapi_ss = mcd_qapi_ss.apply({}) -libmcd = static_library('mcd_system', - mcd_ss.sources() + genh, +libmcd_qapi = static_library('mcd_qapi', + mcd_qapi_ss.sources() + genh, build_by_default: false) -mcd = declare_dependency(objects: libmcd.extract_all_objects(recursive: false)) +mcd_qapi = declare_dependency( + objects: libmcd_qapi.extract_all_objects(recursive: false)) + +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_server_outputs.contains(fs.name(f)) + libsystem_ss.add([f])
mcd/meson.build mcd_qapi_outputs = [ · line 60
Quoted 10 lines
mcd/meson.build +8
-1+ endif +endforeach + +libsystem_ss.add(files( + 'mcd_server.c', + 'mcd_stub.c', + 'mcd_monitor.c')) -system_ss.add(mcd) +libsystem_ss.add(mcd_qapi)
The commit message did not prepare me for such changes to meson.build. What are you doing here?
Quoted 181 lines
qapi/mcd.json +173
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- {
qapi/mcd.json line 189
Quoted 10 lines
qapi/mcd.json +10
-0+# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# } +# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }
You need "Since: 10.0" now.
From docs/devel/qapi-code-gen.rst:
For legibility, wrap text paragraphs so every line is at most 70 characters long.
and
Descriptions start with '\@name:'. The description text must be indented like this::
# @name: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
# do eiusmod tempor incididunt ut labore et dolore magna aliqua.
[...]
Re: [PATCH v2 07/20] mcd: Implement target initialization API
Thank you very much for the review!
Quoted 62 lines · Markus Armbruster
Quoted 60 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>--- mcd/mcd_qapi.c | 66 +++++++++++++++ mcd/mcd_qapi.h | 26 ++++++ mcd/mcd_server.c | 44 +++++++++- mcd/mcd_stub.c | 35 ++++++++ mcd/meson.build | 49 +++++++---- qapi/mcd.json | 183 ++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 62 ++++++++++++++ tests/qtest/mcd-util.c | 99 ++++++++++++++++++++++ tests/qtest/mcd-util.h | 6 ++ tests/qtest/meson.build | 2 +- 10 files changed, 554 insertions(+), 18 deletions(-) create mode 100644 mcd/mcd_qapi.c create mode 100644 mcd/mcd_qapi.h create mode 100644 tests/qtest/mcd-util.cmcd/mcd_qapi.c new file +27
-0@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "mcd_qapi.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version) +{ +MCDAPIVersion *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDAPIVersion ) { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + .author =g_strdup (api_version->author), + }; + +return marshal; +} + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version)
Quoted 8 lines
mcd/mcd_qapi.c line 33
Quoted 6 lines
mcd/mcd_qapi.c new file +6
-0+{ +mcd_api_version_st unmarshal = { + .v_api_major = api_version->v_api_major, + .v_api_minor = api_version->v_api_minor, + }; +strncpy (unmarshal.author, api_version->author,MCD_API_IMP_VENDOR_LEN -1 );Have you considered sizeof(unmarshal.author) - 1 ?
I'm not expecting the sizes of fixed arrays to change anytime soon in the API but also don't see a reason why not to use sizeof. I guess you're right, sizeof is the less error-prone option.
Quoted 1 line
pstrcpy()fromqemu/cutils.his easier to use safely.
Thanks for pointing that out.
Quoted 268 lines
Quoted 268 lines
mcd/mcd_qapi.c new file +33
-0+return unmarshal; +} + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info) +{ +MCDImplVersionInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDImplVersionInfo ) { + .v_api =marshal_mcd_api_version (&impl_info->v_api), + .v_imp_major = impl_info->v_imp_major, + .v_imp_minor = impl_info->v_imp_minor, + .v_imp_build = impl_info->v_imp_build, + .vendor =g_strdup (impl_info->vendor), + .date =g_strdup (impl_info->date), + }; + +return marshal; +} + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info) +{ +MCDErrorInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDErrorInfo ) { + .return_status = error_info->return_status, + .error_code = error_info->error_code, + .error_events = error_info->error_events, + .error_str =g_strdup (error_info->error_str), + }; + +return marshal; +}mcd/mcd_qapi.h new file +26
-0@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* QAPI marshalling helpers for structures of the MCD API +* +* Copyright (c) 2025 Lauterbach GmbH +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef MCD_QAPI_H +#define MCD_QAPI_H + +#include "mcd_api.h" +#include "mcd/mcd-qapi-types.h" + +MCDAPIVersion *marshal_mcd_api_version (const mcd_api_version_st *api_version); + +MCDImplVersionInfo *marshal_mcd_impl_version_info ( +const mcd_impl_version_info_st *impl_info); + +MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); + +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); + +#endif /* MCD_QAPI_H */ mcd/mcd_server.c +43
-1@@ -8,6 +8,7 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = {@@ -17,6 +18,13 @@ static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = { .error_str = "", }; +static const mcd_error_info_st MCD_ERROR_INVALID_NULL_PARAM = { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="null was invalidly passed as a parameter" , +}; +static const mcd_error_info_st MCD_ERROR_NONE = { .return_status =MCD_RET_ACT_NONE , .error_code =MCD_ERR_NONE ,@@ -24,6 +32,9 @@ static const mcd_error_info_st MCD_ERROR_NONE = { .error_str = "", }; +/* reserves memory for custom errors */ +static mcd_error_info_st custom_mcd_error; +/** * struct mcdserver_state - State of the MCD server * @@ -40,12 +51,43 @@ static mcdserver_state g_server_state = {mcd_return_et mcd_initialize_f (const mcd_api_version_st *version_req,mcd_impl_version_info_st *impl_info) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +if (!version_req || !impl_info) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + *impl_info = (mcd_impl_version_info_st ) { + .v_api = (mcd_api_version_st ) { + .v_api_major =MCD_API_VER_MAJOR , + .v_api_minor =MCD_API_VER_MINOR , + .author =MCD_API_VER_AUTHOR , + }, + .v_imp_major =QEMU_VERSION_MAJOR , + .v_imp_minor =QEMU_VERSION_MINOR , + .v_imp_build =0 , + .vendor ="QEMU" , + .date = __DATE__, + }; + +if (version_req->v_api_major ==MCD_API_VER_MAJOR && + version_req->v_api_minor <=MCD_API_VER_MINOR ) { + g_server_state.last_error = &MCD_ERROR_NONE ; + }else { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_GENERAL , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="incompatible versions" , + }; + g_server_state.last_error = &custom_mcd_error; + } +return g_server_state.last_error->return_status; }void mcd_exit_f (void ) { + g_server_state.last_error = &MCD_ERROR_NONE ;return ; }mcd/mcd_stub.c +35
-0@@ -8,4 +8,39 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "mcd_api.h" +#include "mcd_qapi.h" +#include "mcd/mcd-qapi-commands.h" + +MCDInitializeResult *qmp_mcd_initialize (MCDAPIVersion *version_req, +Error **errp) +{ +mcd_impl_version_info_st impl_info; +MCDInitializeResult *result =g_malloc0 (sizeof (*result)); +mcd_api_version_st version_req_unmarshalled = +unmarshal_mcd_api_version (version_req); + + result->return_status =mcd_initialize_f (&version_req_unmarshalled, + &impl_info); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->impl_info =marshal_mcd_impl_version_info (&impl_info); + } + +return result; +} + +void qmp_mcd_exit (Error **errp) +{ +mcd_exit_f (); +} + +MCDErrorInfo *qmp_mcd_qry_error_info (Error **errp) +{ +MCDErrorInfo *result; +mcd_error_info_st error_info; +mcd_qry_error_info_f (NULL , &error_info); + result =marshal_mcd_error_info (&error_info); +return result; +}mcd/meson.build +32
-15@@ -1,14 +1,10 @@ mcd_qapi_outputs = [ - 'mcd-qapi-commands.c', - 'mcd-qapi-commands.h', 'mcd-qapi-emit-events.c', 'mcd-qapi-emit-events.h', 'mcd-qapi-events.c', 'mcd-qapi-events.h', 'mcd-qapi-features.c', 'mcd-qapi-features.h', - 'mcd-qapi-init-commands.c', - 'mcd-qapi-init-commands.h', 'mcd-qapi-introspect.c', 'mcd-qapi-introspect.h', 'mcd-qapi-types.c',@@ -17,27 +13,48 @@ mcd_qapi_outputs = [ 'mcd-qapi-visit.h', ] +# QAPI outputs that will only be used by the MCD server +mcd_qapi_server_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h' +] + mcd_qapi_files = custom_target('MCD QAPI files', - output: mcd_qapi_outputs, + output: mcd_qapi_outputs + mcd_qapi_server_outputs, input: '../qapi/mcd.json', command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', '--suppress-tracing','@INPUT0@'], depend_files: qapi_gen_depends) -mcd_ss = ss.source_set() +mcd_qapi_ss = ss.source_set() -mcd_ss.add(mcd_qapi_files.to_list()) -mcd_ss.add(files( - 'mcd_server.c', - 'mcd_stub.c', - 'mcd_monitor.c')) +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_outputs.contains(fs.name(f)) + mcd_qapi_ss.add([f]) + endif +endforeach -mcd_ss = mcd_ss.apply({}) +mcd_qapi_ss.add(files('mcd_qapi.c')) +mcd_qapi_ss = mcd_qapi_ss.apply({}) -libmcd = static_library('mcd_system', - mcd_ss.sources() + genh, +libmcd_qapi = static_library('mcd_qapi', + mcd_qapi_ss.sources() + genh, build_by_default: false) -mcd = declare_dependency(objects: libmcd.extract_all_objects(recursive: false)) +mcd_qapi = declare_dependency( + objects: libmcd_qapi.extract_all_objects(recursive: false)) + +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_server_outputs.contains(fs.name(f)) + libsystem_ss.add([f]) + endif +endforeach + +libsystem_ss.add(files( + 'mcd_server.c', + 'mcd_stub.c', + 'mcd_monitor.c'))
Quoted 5 lines
mcd/meson.build mcd_qapi_outputs = [ · line 60
Quoted 2 lines
mcd/meson.build +1
-1-system_ss.add(mcd) +libsystem_ss.add(mcd_qapi)The commit message did not prepare me for such changes to meson.build. What are you doing here?
I understand that this requires further comments...
The goal is to provide the marshal helpers from mcd_qapi to mcd-test. We cannot use meson's mcd dependency for that since that would result in linker errors for functions that are not needed anyway:
cc -m64 -o tests/qtest/mcd-test [...] build/../mcd/mcd_monitor.c:53: undefined reference to `monitor_puts'
So we split meson's mcd dependency into two parts, one of them being mcd_qapi which will be used by mcd-test:
tests/qtest/meson.build if dbus_display · line 403
Quoted 12 lines
tests/qtest/meson.build +1
-1@@ -398,7 +398,7 @@ if dbus_display endif if get_option('mcd').enabled() - qtests += { 'mcd-test': files('mcd-test.c') } + qtests += { 'mcd-test': files('mcd-test.c', 'mcd-util.c') + mcd_qapi } qtests_generic += [ 'mcd-test' ] endif
I should've probably included this already in
[PATCH v2 06/20] qtest: Introduce MCD test suite
instead of keeping that version's meson files as simple as possible. Provided the explanation above makes sense, I will add a variant of it in the commit message for more context.
Thanks for pointing that out. After a working a longer stretch on a larger patch set, it's quite difficult to see which parts of the submission might be unclear.
Quoted 201 lines
Quoted 181 lines
qapi/mcd.json +173
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- {qapi/mcd.json line 189
Quoted 10 lines
qapi/mcd.json +10
-0+# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# } +# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }You need "Since: 10.0" now.
From
docs/devel/qapi-code-gen.rst:For legibility, wrap text paragraphs so every line is at most 70 characters long.
and
Quoted 7 lines
Descriptions start with '\@name:'. The description text must be indented like this::
# @name: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
# do eiusmod tempor incididunt ut labore et dolore magna aliqua.[...]
Will be changed in v3!
Best regards,
Mario
Re: [PATCH v2 07/20] mcd: Implement target initialization API
Quoted 17 lines · Mario Fleischmann
Thank you very much for the review!
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>
[...]
Quoted 102 lines
Quoted 78 lines
Quoted 78 lines
mcd/meson.build +32
-15@@ -1,14 +1,10 @@ mcd_qapi_outputs = [ - 'mcd-qapi-commands.c', - 'mcd-qapi-commands.h', 'mcd-qapi-emit-events.c', 'mcd-qapi-emit-events.h', 'mcd-qapi-events.c', 'mcd-qapi-events.h', 'mcd-qapi-features.c', 'mcd-qapi-features.h', - 'mcd-qapi-init-commands.c', - 'mcd-qapi-init-commands.h', 'mcd-qapi-introspect.c', 'mcd-qapi-introspect.h', 'mcd-qapi-types.c',@@ -17,27 +13,48 @@ mcd_qapi_outputs = [ 'mcd-qapi-visit.h', ] +# QAPI outputs that will only be used by the MCD server +mcd_qapi_server_outputs = [ + 'mcd-qapi-commands.c', + 'mcd-qapi-commands.h', + 'mcd-qapi-init-commands.c', + 'mcd-qapi-init-commands.h' +] + mcd_qapi_files = custom_target('MCD QAPI files', - output: mcd_qapi_outputs, + output: mcd_qapi_outputs + mcd_qapi_server_outputs, input: '../qapi/mcd.json', command: [ qapi_gen, '-p', 'mcd-', '-o', 'mcd', '--suppress-tracing','@INPUT0@'], depend_files: qapi_gen_depends) -mcd_ss = ss.source_set() +mcd_qapi_ss = ss.source_set() -mcd_ss.add(mcd_qapi_files.to_list()) -mcd_ss.add(files( - 'mcd_server.c', - 'mcd_stub.c', - 'mcd_monitor.c')) +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_outputs.contains(fs.name(f)) + mcd_qapi_ss.add([f]) + endif +endforeach -mcd_ss = mcd_ss.apply({}) +mcd_qapi_ss.add(files('mcd_qapi.c')) +mcd_qapi_ss = mcd_qapi_ss.apply({}) -libmcd = static_library('mcd_system', - mcd_ss.sources() + genh, +libmcd_qapi = static_library('mcd_qapi', + mcd_qapi_ss.sources() + genh, build_by_default: false) -mcd = declare_dependency(objects: libmcd.extract_all_objects(recursive: false)) +mcd_qapi = declare_dependency( + objects: libmcd_qapi.extract_all_objects(recursive: false)) + +foreach f : mcd_qapi_files.to_list() + if mcd_qapi_server_outputs.contains(fs.name(f)) + libsystem_ss.add([f]) + endif +endforeach + +libsystem_ss.add(files( + 'mcd_server.c', + 'mcd_stub.c', + 'mcd_monitor.c'))Quoted 5 lines
mcd/meson.build mcd_qapi_outputs = [ · line 60
Quoted 2 lines
mcd/meson.build +1
-1-system_ss.add(mcd) +libsystem_ss.add(mcd_qapi)The commit message did not prepare me for such changes to meson.build. What are you doing here?
I understand that this requires further comments...
The goal is to provide the marshal helpers frommcd_qapito mcd-test. We cannot use meson's mcd dependency for that since that would result in linker errors for functions that are not needed anyway:cc -m64 -o tests/qtest/mcd-test [...]
build/../mcd/mcd_monitor.c:53: undefined reference to `monitor_puts'So we split meson's mcd dependency into two parts, one of them being
mcd_qapiwhich will be used by mcd-test:Quoted 7 lines
tests/qtest/meson.build +0
-0@@ -398,7 +398,7 @@ if dbus_display endif
Quoted 9 lines
tests/qtest/meson.build if dbus_display · line 403
Quoted 5 lines
tests/qtest/meson.build +1
-1if get_option('mcd').enabled() - qtests += { 'mcd-test': files('mcd-test.c') } + qtests += { 'mcd-test': files('mcd-test.c', 'mcd-util.c') + mcd_qapi } qtests_generic += [ 'mcd-test' ] endifI should've probably included this already in
[PATCH v2 06/20] qtest: Introduce MCD test suite
instead of keeping that version's meson files as simple as possible.
Might be less surprising there.
Quoted 2 lines
Provided the explanation above makes sense, I will add a variant of it in the commit message for more context.
Yes, please!
Quoted 3 lines
Thanks for pointing that out. After a working a longer stretch on a larger patch set, it's quite difficult to see which parts of the submission might be unclear.
True!
Quoted 204 lines
Quoted 204 lines
Quoted 181 lines
qapi/mcd.json +173
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- {qapi/mcd.json line 189
Quoted 10 lines
qapi/mcd.json +10
-0+# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# } +# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }You need "Since: 10.0" now.
From
docs/devel/qapi-code-gen.rst:For legibility, wrap text paragraphs so every line is at most 70 characters long.
and
Descriptions start with '\@name:'. The description text must be indented like this::
Quoted 6 lines
Quoted 4 lines
# @name: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
# do eiusmod tempor incididunt ut labore et dolore magna aliqua.[...]
Will be changed in v3!
Correction: "Since: 10.1".
Re: [PATCH v2 07/20] mcd: Implement target initialization API
In reply to Mario FleischmannQuoted 11 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>
[...]
Quoted 181 lines
qapi/mcd.json +173
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- {
qapi/mcd.json line 189
Quoted 10 lines
qapi/mcd.json +10
-0+# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# } +# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }
You define some types under "Definition of Structures", and some elsewhere. How do you decide what goes where? Hmm, looks like you mirror mcd/mcd_api.h. Correct?
[...]
Re: [PATCH v2 07/20] mcd: Implement target initialization API
Quoted 203 lines · Markus Armbruster
Quoted 11 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>[...]
Quoted 187 lines
qapi/mcd.json +179
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- { +# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# }
Quoted 8 lines
qapi/mcd.json line 189
Quoted 4 lines
qapi/mcd.json +4
-0+# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }You define some types under "Definition of Structures", and some elsewhere. How do you decide what goes where? Hmm, looks like you mirror
mcd/mcd_api.h. Correct?
Generally, mcd/qapi-schema.json is intended to stay as close as possible to mcd_api.h. However, there are a few exceptions.
If a function "MCDFunction" from the MCD API has multiple return values, an additional QAPI struct with the naming scheme "MCDFunctionResult" is introduced which will be returned by "MCDFunction".
Since this struct is intended to be used by only one function, it is defined directly before that function.
If the type of an argument or return value cannot be serialized, most often because it is a pointer, it is changed to a type which is able to carry the same information. In most cases, an int carrying a unique identifier suffices. Sometimes, an additional struct is required. This struct can possibly be used by multiple functions, so I would expect it in the "Definition of Structures" section.
Re: [PATCH v2 07/20] mcd: Implement target initialization API
Quoted 223 lines · Mario Fleischmann
Quoted 203 lines · Markus Armbruster
Quoted 11 lines · Mario Fleischmann
The target initialization API ensures that the requested and provided MCD versions are compatible.
* implement
mcd_initialize_fandmcd_qry_error_info_fin mcdserver
* implement QMP stub functionality
* add QTestThanks to the QMP integration in QTest, function arguments and results can be (de)serialized automatically.
Signed-off-by Mario Fleischmann <[email protected]>[...]
Quoted 187 lines
qapi/mcd.json +179
-0@@ -4,3 +4,186 @@ ## # = Multi-Core Debug (MCD) API ## + + +## +# == Definition of Structures +## + + +## +# @MCDAPIVersion: +# +# Structure type containing the MCD API version information of the tool. +# +# @v-api-major: API major version. +# @v-api-minor: API minor version. +# @author: API name of the author of this MCD API version. +# +# Since: 9.1 +## +{ 'struct': 'MCDAPIVersion', + 'data': { + 'v-api-major': 'uint16', + 'v-api-minor': 'uint16', + 'author': 'str' } } + + +## +# @MCDImplVersionInfo: +# +# Structure type containing the MCD API implementation information. +# +# @v-api: Implemented API version. +# @v-imp-major: Major version number of this implementation. +# @v-imp-minor: Minor version number of this implementation. +# @v-imp-build: Build number of this implementation. +# @vendor: Name of vendor of the implementation. +# @date: String from __DATE__ macro at compile time. +# +# Since: 9.1 +## +{ 'struct': 'MCDImplVersionInfo', + 'data': { + 'v-api' : 'MCDAPIVersion', + 'v-imp-major': 'uint16', + 'v-imp-minor': 'uint16', + 'v-imp-build': 'uint16', + 'vendor' : 'str', + 'date' : 'str' } } + + +## +# @MCDErrorInfo: +# +# Structure type containing the error status and error event notification. +# +# @return-status: Return status from the last API call. +# @error-code: Detailed error code from the last API call. +# @error-events: Detailed event code from the last API call. +# @error-str: Detailed error text string from the last API call. +# +# Since: 9.1 +## +{ 'struct': 'MCDErrorInfo', + 'data': { + 'return-status': 'uint32', + 'error-code' : 'uint32', + 'error-events' : 'uint32', + 'error-str' : 'str' }} + + +## +# == Target Initialization API +## + + +## +# @MCDInitializeResult: +# +# Return value of @mcd-initialize. +# +# @return-status: Return code. +# +# @impl-info: Information about the QEMU build, its version and the version of +# the implemented MCD API. +# +# Since: 9.1 +## +{ 'struct': 'MCDInitializeResult', + 'data': { + 'return-status': 'uint32', + '*impl-info' : 'MCDImplVersionInfo' } } + + +## +# @mcd-initialize: +# +# Function initializing the interaction between a tool-side implementation and +# target-side implementation. +# +# @version-req: MCD API version as requested by an upper layer. +# +# Returns: @MCDInitializeResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Check compatibility with MCD server +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 1, +# "v-api-minor": 1, +# "author": "" } } } +# <- { +# "return": { +# "impl-info": { +# "v-api": { +# "v-api-minor": 1, +# "v-api-major": 1, +# "author": "QEMU Release" +# }, +# "vendor": "QEMU", +# "v-imp-minor": 2, +# "v-imp-major": 9, +# "v-imp-build": 0, +# "date": "Dec 18 2024" +# }, +# "return-status": 0 +# } +# } +## +{ 'command': 'mcd-initialize', + 'data': { 'version-req': 'MCDAPIVersion' }, + 'returns': 'MCDInitializeResult' } + + +## +# @mcd-exit: +# +# Function cleaning up all core and server connections from a tool. +# +# Since: 9.1 +## +{ 'command': 'mcd-exit' } + + +## +# == Core Connection API +## + + +## +# @mcd-qry-error-info: +# +# Function allowing the access to detailed error and/or event information after +# an API call. +# +# Returns: @MCDErrorInfo +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Incompatible MCD versions +# +# -> { "execute": "mcd-initialize", +# "arguments": { "version-req": { "v-api-major": 2, +# "v-api-minor": 0, +# "author": "" } } } +# <- { +# "return": { +# "return-status": 3 +# } +# } +# -> { "execute": "mcd-qry-error-info" } +# <- { +# "return": { +# "error-str": "incompatible versions", +# "error-code": 3840, +# "error-events": 0, +# "return-status": 3 +# }Quoted 8 lines
qapi/mcd.json line 189
Quoted 4 lines
qapi/mcd.json +4
-0+# } +## +{ 'command': 'mcd-qry-error-info', + 'returns': 'MCDErrorInfo' }You define some types under "Definition of Structures", and some elsewhere. How do you decide what goes where? Hmm, looks like you mirror
mcd/mcd_api.h. Correct?Generally,
mcd/qapi-schema.jsonis intended to stay as close as possible tomcd_api.h. However, there are a few exceptions.If a function "MCDFunction" from the MCD API has multiple return values, an additional QAPI struct with the naming scheme "MCDFunctionResult" is introduced which will be returned by "MCDFunction".
Since this struct is intended to be used by only one function, it is defined directly before that function.
Quoted 6 lines
If the type of an argument or return value cannot be serialized, most often because it is a pointer, it is changed to a type which is able to carry the same information. In most cases, an int carrying a unique identifier suffices. Sometimes, an additional struct is required. This struct can possibly be used by multiple functions, so I would expect it in the "Definition of Structures" section.
Makes sense.
Suggest to add a suitable varation of this explanation to the .json as a non-doc comment. Reminder:
##
# Doc comment
##
#
# Not a doc comment
#
PATCH v2 8/20 mcd: Implement server connection API
In reply to Mario FleischmannThis commit implements the necessary operations required to establish a connection with the MCD server:
* query information about the server
* connect to "
* disconnect from "
--- mcd/mcd_qapi.c | 13 +++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 110 +++++++++++++++++++++- mcd/mcd_stub.c | 98 ++++++++++++++++++++ qapi/mcd.json | 205 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 96 +++++++++++++++++++ tests/qtest/mcd-util.c | 60 ++++++++++++ tests/qtest/mcd-util.h | 9 ++ 8 files changed, 588 insertions(+), 5 deletions(-)
mcd/mcd_qapi.c +13 -0
@@ -64,3 +64,16 @@ MCDErrorInfo *marshal_mcd_error_info(const mcd_error_info_st *error_info)return marshal; } + +MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info) +{ +MCDServerInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDServerInfo ) { + .server =g_strdup (server_info->server), + .system_instance =g_strdup (server_info->system_instance), + .acc_hw =g_strdup (server_info->acc_hw), + }; + +return marshal; +}
mcd/mcd_qapi.h +2 -0
@@ -21,6 +21,8 @@ MCDImplVersionInfo *marshal_mcd_impl_version_info(MCDErrorInfo *marshal_mcd_error_info (const mcd_error_info_st *error_info); +MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);#endif /* MCD_QAPI_H */
mcd/mcd_server.c +105 -5
146 lines not on this page · raw message
mcd/mcd_stub.c +98 -0
110 lines not on this page · raw message
qapi/mcd.json +205 -0
217 lines not on this page · raw message
tests/qtest/mcd-test.c +96 -0
107 lines not on this page · raw message
tests/qtest/mcd-util.c +60 -0
63 lines not on this page · raw message
tests/qtest/mcd-util.h +9 -0
@@ -24,4 +24,13 @@ MCDInitializeResult *qtest_mcd_initialize(QTestStateMCD *qts,MCDErrorInfo *qtest_mcd_qry_error_info (QTestStateMCD *qts); +MCDQryServersResult *qtest_mcd_qry_servers (QTestStateMCD *qts, +q_obj_mcd_qry_servers_arg *args); + +MCDOpenServerResult *qtest_mcd_open_server (QTestStateMCD *qts, +q_obj_mcd_open_server_arg *args); + +MCDCloseServerResult *qtest_mcd_close_server (QTestStateMCD *qts, +q_obj_mcd_close_server_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 08/20] mcd: Implement server connection API
Quoted 27 lines · Mario Fleischmann
This commit implements the necessary operations required to establish a connection with the MCD server:
* query information about the server
* connect to "
* disconnect from "Signed-off-by Mario Fleischmann <[email protected]>--- mcd/mcd_qapi.c | 13 +++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 110 +++++++++++++++++++++- mcd/mcd_stub.c | 98 ++++++++++++++++++++ qapi/mcd.json | 205 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 96 +++++++++++++++++++ tests/qtest/mcd-util.c | 60 ++++++++++++ tests/qtest/mcd-util.h | 9 ++ 8 files changed, 588 insertions(+), 5 deletions(-)mcd/mcd_qapi.c +2
-0+MCDQryServersResult *qmp_mcd_qry_servers(const char *host, bool running, + uint32_t start_index,
mcd/mcd_qapi.c
Quoted 10 lines
mcd/mcd_qapi.c +10
-0+ uint32_t num_servers, Error **errp) +{ + MCDServerInfoList **tailp; +MCDServerInfo *info; +mcd_server_info_st *server_info =NULL ; +bool query_num_only = num_servers ==0 ; +MCDQryServersResult *result =g_malloc0 (sizeof (*result)); + +if (!query_num_only) { + server_info =g_malloc0 (num_servers *sizeof (*server_info));
This multiplication is (theoretically) subject to overflow. To eliminate this risk, this should use
g_new0(mcd_server_info_st, num_servers)
which will validate overflow & abort if hit.
There are many more instances of this code pattern in the series
$ git diff -r master | grep g_malloc | grep ' \* ' + .tx = g_malloc(txlist->num_tx * sizeof(mcd_tx_st)), + server_info = g_malloc0(num_servers * sizeof(*server_info)); + system_con_info = g_malloc0(num_systems * sizeof(*system_con_info)); + device_con_info = g_malloc0(num_devices * sizeof(*device_con_info)); + core_con_info = g_malloc0(num_cores * sizeof(*core_con_info)); + memspaces = g_malloc0(num_mem_spaces * sizeof(*memspaces)); + reg_groups = g_malloc0(num_reg_groups * sizeof(*reg_groups)); + regs = g_malloc0(num_regs * sizeof(*regs)); + ctrig_info = g_malloc0(num_ctrigs * sizeof(*ctrig_info)); + trig_ids = g_malloc0(num_trigs * sizeof(*trig_ids));
QEMU is a bit inconsistent, but we have a slight bias in favour of using g_new0, even for single struct allocations.
IMHO being in the habit of always using g_new0 instead of g_malloc makes it less likely for people to inadvertantly introduce the multiplication overflow code pattern with g_malloc.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v2 08/20] mcd: Implement server connection API
Quoted 61 lines · Daniel P. Berrangé
Quoted 27 lines · Mario Fleischmann
This commit implements the necessary operations required to establish a connection with the MCD server:
* query information about the server
* connect to "
* disconnect from "Signed-off-by Mario Fleischmann <[email protected]>--- mcd/mcd_qapi.c | 13 +++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 110 +++++++++++++++++++++- mcd/mcd_stub.c | 98 ++++++++++++++++++++ qapi/mcd.json | 205 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 96 +++++++++++++++++++ tests/qtest/mcd-util.c | 60 ++++++++++++ tests/qtest/mcd-util.h | 9 ++ 8 files changed, 588 insertions(+), 5 deletions(-)mcd/mcd_qapi.c +2
-0+MCDQryServersResult *qmp_mcd_qry_servers(const char *host, bool running, + uint32_t start_index,mcd/mcd_qapi.c
Quoted 10 lines
mcd/mcd_qapi.c +10
-0+ uint32_t num_servers, Error **errp) +{ + MCDServerInfoList **tailp; +MCDServerInfo *info; +mcd_server_info_st *server_info =NULL ; +bool query_num_only = num_servers ==0 ; +MCDQryServersResult *result =g_malloc0 (sizeof (*result)); + +if (!query_num_only) { + server_info =g_malloc0 (num_servers *sizeof (*server_info));This multiplication is (theoretically) subject to overflow. To eliminate this risk, this should use
g_new0(mcd_server_info_st, num_servers)which will validate overflow & abort if hit.
There are many more instances of this code pattern in the series
$ git diff -r master | grep g_malloc | grep ' \* '(quoted diff) +10
-0+ .tx = g_malloc(txlist->num_tx * sizeof(mcd_tx_st)), + server_info = g_malloc0(num_servers * sizeof(*server_info)); + system_con_info = g_malloc0(num_systems * sizeof(*system_con_info)); + device_con_info = g_malloc0(num_devices * sizeof(*device_con_info)); + core_con_info = g_malloc0(num_cores * sizeof(*core_con_info)); + memspaces = g_malloc0(num_mem_spaces * sizeof(*memspaces)); + reg_groups = g_malloc0(num_reg_groups * sizeof(*reg_groups)); + regs = g_malloc0(num_regs * sizeof(*regs)); + ctrig_info = g_malloc0(num_ctrigs * sizeof(*ctrig_info)); + trig_ids = g_malloc0(num_trigs * sizeof(*trig_ids));
Quoted 6 lines
QEMU is a bit inconsistent, but we have a slight bias in favour of using
g_new0, even for single struct allocations.IMHO being in the habit of always using
g_new0instead ofg_mallocmakes it less likely for people to inadvertantly introduce the multiplication overflow code pattern withg_malloc.
Oh, I didn't know that function, thanks for pointing it out! I agree, it's the more elegant option.
PATCH v2 9/20 mcd: Implement target system query
In reply to Mario FleischmannIn MCD, the target system is divided into system, devices and cores:
[ system ] 1-* [ devices ] 1-* [cores]
This commit implements the necessary functions to query information about the target system.
--- mcd/mcd_qapi.c | 48 ++++++ mcd/mcd_qapi.h | 4 + mcd/mcd_server.c | 165 ++++++++++++++++++- mcd/mcd_stub.c | 116 ++++++++++++++ qapi/mcd.json | 356 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 83 ++++++++++ tests/qtest/mcd-util.c | 67 ++++++++ tests/qtest/mcd-util.h | 11 ++ 8 files changed, 847 insertions(+), 3 deletions(-)
mcd/mcd_qapi.c +48 -0
@@ -77,3 +77,51 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info)return marshal; } + +MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info) +{ +MCDCoreConInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCoreConInfo ) { + .host =g_strdup (con_info->host), + .server_port = con_info->server_port, + .server_key =g_strdup (con_info->server_key), + .system_key =g_strdup (con_info->system_key), + .device_key =g_strdup (con_info->device_key), + .system =g_strdup (con_info->system), + .system_instance =g_strdup (con_info->system_instance), + .acc_hw =g_strdup (con_info->acc_hw), + .device_type = con_info->device_type, + .device =g_strdup (con_info->device), + .device_id = con_info->device_id, + .core =g_strdup (con_info->core), + .core_type = con_info->core_type, + .core_id = con_info->core_id, + }; + +return marshal; +} + +mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info) +{ +mcd_core_con_info_st unmarshal = { + .server_port = con_info->server_port, + .device_type = con_info->device_type, + .device_id = con_info->device_id, + .core_type = con_info->core_type, + .core_id = con_info->core_id, + }; + +strncpy (unmarshal.host, con_info->host,MCD_HOSTNAME_LEN -1 ); +strncpy (unmarshal.server_key, con_info->server_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.system_key, con_info->system_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.device_key, con_info->device_key,MCD_KEY_LEN -1 ); +strncpy (unmarshal.system, con_info->system,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.system_instance, con_info->system_instance, +MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.acc_hw, con_info->acc_hw,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.device, con_info->device,MCD_UNIQUE_NAME_LEN -1 ); +strncpy (unmarshal.core, con_info->core,MCD_UNIQUE_NAME_LEN -1 ); + +return unmarshal; +}
mcd/mcd_qapi.h +4 -0
@@ -23,6 +23,10 @@ MCDErrorInfo *marshal_mcd_error_info(const mcd_error_info_st *error_info);MCDServerInfo *marshal_mcd_server_info (const mcd_server_info_st *server_info); +MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version); +mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info); +#endif /* MCD_QAPI_H */
mcd/mcd_server.c +162 -3
231 lines not on this page · raw message
mcd/mcd_stub.c +116 -0
122 lines not on this page · raw message
qapi/mcd.json +356 -0
368 lines not on this page · raw message
tests/qtest/mcd-test.c +83 -0
94 lines not on this page · raw message
tests/qtest/mcd-util.c +67 -0
76 lines not on this page · raw message
tests/qtest/mcd-util.h +11 -0
@@ -24,6 +24,8 @@ MCDInitializeResult *qtest_mcd_initialize(QTestStateMCD *qts,MCDErrorInfo *qtest_mcd_qry_error_info (QTestStateMCD *qts); +void qtest_mcd_exit (QTestStateMCD *qts); +MCDQryServersResult *qtest_mcd_qry_servers (QTestStateMCD *qts,q_obj_mcd_qry_servers_arg *args);
@@ -33,4 +35,13 @@ MCDOpenServerResult *qtest_mcd_open_server(QTestStateMCD *qts,MCDCloseServerResult *qtest_mcd_close_server (QTestStateMCD *qts,q_obj_mcd_close_server_arg *args); +MCDQrySystemsResult *qtest_mcd_qry_systems (QTestStateMCD *qts, +q_obj_mcd_qry_systems_arg *args); + +MCDQryDevicesResult *qtest_mcd_qry_devices (QTestStateMCD *qts, +q_obj_mcd_qry_devices_arg *args); + +MCDQryCoresResult *qtest_mcd_qry_cores (QTestStateMCD *qts, +q_obj_mcd_qry_cores_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
PATCH v2 10/20 mcd: Implement core connection control
In reply to Mario FleischmannIn MCD, core-specific operations require an open connection to the core. This commit implements the necessary operations to open and close the connection to cores.
--- mcd/mcd_server.c | 176 +++++++++++++++++++++++++++++++--- mcd/mcd_stub.c | 129 ++++++++++++++++++++++++- qapi/mcd.json | 132 +++++++++++++++++++++++++- tests/qtest/mcd-test.c | 210 +++++++++++++++++++++++++++++------------ tests/qtest/mcd-util.c | 51 +++++++++- tests/qtest/mcd-util.h | 9 +- 6 files changed, 625 insertions(+), 82 deletions(-)
mcd/mcd_server.c +162 -14
@@ -34,6 +34,13 @@ static const mcd_error_info_st MCD_ERROR_SERVER_NOT_OPEN = { .error_str = "server is not open", }; +static const mcd_error_info_st MCD_ERROR_UNKNOWN_CORE = { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="specified core is unknown to server" , +}; +static const mcd_error_info_st MCD_ERROR_NONE = { .return_status =MCD_RET_ACT_NONE , .error_code =MCD_ERR_NONE ,
@@ -44,6 +51,24 @@ static const mcd_error_info_st MCD_ERROR_NONE = {/* reserves memory for custom errors */ static mcd_error_info_st custom_mcd_error; +/** +* struct mcdcore_state - State of a core. +* +* @last_error: Error info of most recent executed function. +* @info: Core connection information. +* @open_core: Open core instance as allocated in mcd_open_core_f(). +* +* MCD is mainly being used on the core level: +* After the initial query functions, a core connection is opened in +* mcd_open_core_f(). The allocated mcd_core_st instance is then the basis +* of subsequent operations. +*/ +typedef struct mcdcore_state { +const mcd_error_info_st *last_error; +mcd_core_con_info_st info; +mcd_core_st *open_core; +}mcdcore_state ; +/** * struct mcdserver_state - State of the MCD server *
@@ -66,6 +91,24 @@ static mcdserver_state g_server_state = { .cores = NULL, }; +static mcdcore_state *find_core (const mcd_core_con_info_st *core_con_info) +{ +uint32_t core_id; +mcdcore_state *core; + +if (!core_con_info || !g_server_state.cores) { +return NULL ; + } + + core_id = core_con_info->core_id; +if (core_id > g_server_state.cores->len) { +return NULL ; + } + + core = &g_array_index (g_server_state.cores, mcdcore_state, core_id); +return core; +} +mcd_return_et mcd_initialize_f (const mcd_api_version_st *version_req,mcd_impl_version_info_st *impl_info) {
@@ -200,16 +243,19 @@ mcd_return_et mcd_open_server_f(const char *system_key, }/* update the internal core information data base */ - g_server_state.cores =g_array_new (false, true, -sizeof (mcd_core_con_info_st)); + g_server_state.cores =g_array_new (false, true,sizeof (mcdcore_state));CPU_FOREACH (cpu) {ObjectClass *oc =object_get_class (OBJECT (cpu));const char *cpu_model =object_class_get_name (oc); -mcd_core_con_info_st info = { - .core_id = g_server_state.cores->len, +mcdcore_state c = { + .info = (mcd_core_con_info_st ) { + .core_id = g_server_state.cores->len, + }, + .last_error = &MCD_ERROR_NONE , + .open_core =NULL , }; -pstrcpy (info.core,MCD_UNIQUE_NAME_LEN , cpu_model); -g_array_append_val (g_server_state.cores, info); +pstrcpy (c.info.core,MCD_UNIQUE_NAME_LEN , cpu_model); +g_array_append_val (g_server_state.cores, c); } g_server_state.last_error = &MCD_ERROR_NONE ;
@@ -240,6 +286,14 @@ mcd_return_et mcd_close_server_f(const mcd_server_st *server)return g_server_state.last_error->return_status; } +for (int i =0 ; i < g_server_state.cores->len; i++) { +mcdcore_state *c = &g_array_index (g_server_state.cores, + mcdcore_state, i); +if (c->open_core) { +mcd_close_core_f (c->open_core); + } + } +g_array_free (g_server_state.cores, true);g_free (g_server_state.open_server); g_server_state.open_server =NULL ;
@@ -396,12 +450,11 @@ mcd_return_et mcd_qry_cores_f(const mcd_core_con_info_st *connection_info, i < *num_cores && start_index + i < g_server_state.cores->len; i++) { -mcd_core_con_info_st *info = &g_array_index (g_server_state.cores, - mcd_core_con_info_st, - start_index + i); +mcdcore_state *c = &g_array_index (g_server_state.cores, mcdcore_state, + start_index + i); core_con_info[i] = *connection_info; - core_con_info[i].core_id = info->core_id; -pstrcpy (core_con_info[i].core,MCD_UNIQUE_NAME_LEN , info->core); + core_con_info[i].core_id = c->info.core_id; +pstrcpy (core_con_info[i].core,MCD_UNIQUE_NAME_LEN , c->info.core); } *num_cores = i;
@@ -421,21 +474,116 @@ mcd_return_et mcd_qry_core_modes_f(const mcd_core_st *core,mcd_return_et mcd_open_core_f (const mcd_core_con_info_st *core_con_info,mcd_core_st **core) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +uint32_t core_id; +mcdcore_state *core_state; +mcd_core_con_info_st *info; + +if (!g_server_state.open_server) { + g_server_state.last_error = &MCD_ERROR_SERVER_NOT_OPEN ; +return g_server_state.last_error->return_status; + } + +if (!core_con_info || !core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_id = core_con_info->core_id; +if (core_id > g_server_state.cores->len) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="specified core index exceeds the number of cores" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + + core_state = &g_array_index (g_server_state.cores, mcdcore_state, core_id); +if (core_state->open_core) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core already open" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + + *core =g_malloc (sizeof (mcd_core_st)); + info =g_malloc (sizeof (mcd_core_con_info_st)); + *info = *core_con_info; + (*core)->core_con_info = info; + (*core)->instance =NULL ; + core_state->open_core = *core; + core_state->last_error = &MCD_ERROR_NONE ; + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }mcd_return_et mcd_close_core_f (const mcd_core_st *core) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +mcdcore_state *core_state; + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (core_state->open_core != core) { + custom_mcd_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core not open" , + }; + g_server_state.last_error = &custom_mcd_error; +return g_server_state.last_error->return_status; + } + +g_free ((void *)core->core_con_info); +g_free ((void *)core); + core_state->open_core =NULL ; + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }void mcd_qry_error_info_f (const mcd_core_st *core,mcd_error_info_st *error_info) { -if (error_info) { +mcdcore_state *core_state; + +if (!error_info) { +return ; + } + +if (!core) { *error_info = *g_server_state.last_error; +return ; + } + + core_state =find_core (core->core_con_info); +if (!core_state) { + *error_info =MCD_ERROR_UNKNOWN_CORE ; + }else if (core_state->open_core != core) { + *error_info = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_CONNECTION , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core not open" , + }; + }else { + *error_info = *core_state->last_error; } }
mcd/mcd_stub.c +125 -4
193 lines not on this page · raw message
qapi/mcd.json +131 -1
154 lines not on this page · raw message
tests/qtest/mcd-test.c +151 -59
257 lines not on this page · raw message
tests/qtest/mcd-util.c +48 -3
66 lines not on this page · raw message
tests/qtest/mcd-util.h +8 -1
@@ -22,7 +22,8 @@ typedef struct {MCDInitializeResult *qtest_mcd_initialize (QTestStateMCD *qts,q_obj_mcd_initialize_arg *args); -MCDErrorInfo *qtest_mcd_qry_error_info (QTestStateMCD *qts); +MCDErrorInfo *qtest_mcd_qry_error_info (QTestStateMCD *qts, +q_obj_mcd_qry_error_info_arg *args);void qtest_mcd_exit (QTestStateMCD *qts);
@@ -44,4 +45,10 @@ MCDQryDevicesResult *qtest_mcd_qry_devices(QTestStateMCD *qts,MCDQryCoresResult *qtest_mcd_qry_cores (QTestStateMCD *qts,q_obj_mcd_qry_cores_arg *args); +MCDOpenCoreResult *qtest_mcd_open_core (QTestStateMCD *qts, +q_obj_mcd_open_core_arg *args); + +MCDCloseCoreResult *qtest_mcd_close_core (QTestStateMCD *qts, +q_obj_mcd_close_core_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
PATCH v2 11/20 mcd: Implement memory space query
In reply to Mario FleischmannSupport three main memory space types:
* Physical memory
* Logical memory (MMU)
* GDB Registers
Use custom memory type to mark memory spaces as secure
V=1 QTEST_QEMU_BINARY="./qemu-system-arm -M virt,secure=on -cpu cortex-a15" tests/qtest/mcd-test
--- mcd/mcd_qapi.c | 22 +++++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 199 ++++++++++++++++++++++++++++++++++------- mcd/mcd_stub.c | 44 +++++++++ qapi/mcd.json | 199 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 79 ++++++++++++++++ tests/qtest/mcd-util.c | 20 +++++ tests/qtest/mcd-util.h | 3 + 8 files changed, 534 insertions(+), 34 deletions(-)
mcd/mcd_qapi.c +22 -0
@@ -125,3 +125,25 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info)return unmarshal; } + +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space) +{ +MCDMemspace *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDMemspace ) { + .mem_space_id = mem_space->mem_space_id, + .mem_space_name =g_strdup (mem_space->mem_space_name), + .mem_type = mem_space->mem_type, + .bits_per_mau = mem_space->bits_per_mau, + .invariance = mem_space->invariance, + .endian = mem_space->endian, + .min_addr = mem_space->min_addr, + .max_addr = mem_space->max_addr, + .num_mem_blocks = mem_space->num_mem_blocks, + .supported_access_options = mem_space->supported_access_options, + .core_mode_mask_read = mem_space->core_mode_mask_read, + .core_mode_mask_write = mem_space->core_mode_mask_write, + }; + +return marshal; +}
mcd/mcd_qapi.h +2 -0
@@ -25,6 +25,8 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info);MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcd_server.c +165 -34
374 lines not on this page · raw message
mcd/mcd_stub.c +44 -0
47 lines not on this page · raw message
qapi/mcd.json +199 -0
208 lines not on this page · raw message
tests/qtest/mcd-test.c +79 -0
90 lines not on this page · raw message
tests/qtest/mcd-util.c +20 -0
@@ -269,3 +269,23 @@ MCDCloseCoreResult *qtest_mcd_close_core(QTestStateMCD *qts,return unmarshal; } + +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces ( +QTestStateMCD *qts,q_obj_mcd_qry_mem_spaces_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryMemSpacesResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_mem_spaces_arg); + + resp =qtest_mcd (qts,"{'execute': 'mcd-qry-mem-spaces'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryMemSpacesResult); + +return unmarshal; +}
tests/qtest/mcd-util.h +3 -0
@@ -51,4 +51,7 @@ MCDOpenCoreResult *qtest_mcd_open_core(QTestStateMCD *qts,MCDCloseCoreResult *qtest_mcd_close_core (QTestStateMCD *qts,q_obj_mcd_close_core_arg *args); +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces (QTestStateMCD *qts, +q_obj_mcd_qry_mem_spaces_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
Re: [PATCH v2 11/20] mcd: Implement memory space query
Quoted 101 lines · Mario Fleischmann
Support three main memory space types:
* Physical memory
* Logical memory (MMU)
* GDB RegistersUse custom memory type to mark memory spaces as secure
V=1 QTEST_QEMU_BINARY="./qemu-system-arm -M virt,secure=on -cpu cortex-a15" tests/qtest/mcd-test
Signed-off-by Mario Fleischmann <[email protected]>---
mcd/mcd_qapi.c | 22 +++++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 199 ++++++++++++++++++++++++++++++++++------- mcd/mcd_stub.c | 44 +++++++++ qapi/mcd.json | 199 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 79 ++++++++++++++++ tests/qtest/mcd-util.c | 20 +++++ tests/qtest/mcd-util.h | 3 + 8 files changed, 534 insertions(+), 34 deletions(-)mcd/mcd_qapi.c +22
-0@@ -125,3 +125,25 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info)return unmarshal; } + +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space) +{ +MCDMemspace *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDMemspace ) { + .mem_space_id = mem_space->mem_space_id, + .mem_space_name =g_strdup (mem_space->mem_space_name), + .mem_type = mem_space->mem_type, + .bits_per_mau = mem_space->bits_per_mau, + .invariance = mem_space->invariance, + .endian = mem_space->endian, + .min_addr = mem_space->min_addr, + .max_addr = mem_space->max_addr, + .num_mem_blocks = mem_space->num_mem_blocks, + .supported_access_options = mem_space->supported_access_options, + .core_mode_mask_read = mem_space->core_mode_mask_read, + .core_mode_mask_write = mem_space->core_mode_mask_write, + }; + +return marshal; +}mcd/mcd_qapi.h +2
-0@@ -25,6 +25,8 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info);MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);mcd/mcd_server.c +10
-6@@ -12,6 +12,10 @@#include "qemu/cutils.h" #include "mcd_api.h" #include "hw/boards.h" +#include "exec/tswap.h" + +/* Custom memory space type */ +static const mcd_mem_type_et MCD_MEM_SPACE_IS_SECURE =0x00010000 ;static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = { .return_status =MCD_RET_ACT_HANDLE_ERROR ,@@ -48,37 +52,45 @@ static const mcd_error_info_st MCD_ERROR_NONE = { .error_str = "", }; -/* reserves memory for custom errors */ -static mcd_error_info_st custom_mcd_error; -/** * struct mcdcore_state - State of a core. * -* @last_error: Error info of most recent executed function. -* @info: Core connection information. -* @open_core: Open core instance as allocated in mcd_open_core_f(). +* @last_error: Error info of most recent executed core-related function. +* @custom_error: Reserves memory for custom MCD errors. +* @info: Core connection information. +* @open_core: Open core instance as allocated in mcd_open_core_f(). +* @cpu: QEMU's internal CPU handle. +* @memory_spaces: Memory spaces as queried by mcd_qry_mem_spaces_f(). * * MCD is mainly being used on the core level:
mcd/mcd_server.c static const mcd_error_info_st MCD_ERROR_NONE = { · line 75
Quoted 10 lines
mcd/mcd_server.c +4
-0* After the initial query functions, a core connection is opened in * mcd_open_core_f(). The allocated mcd_core_st instance is then the basis * of subsequent operations. +* +* @cpu is the internal CPU handle through which core specific debug +* functions are implemented. */ typedef struct mcdcore_state { const mcd_error_info_st *last_error; + mcd_error_info_st custom_error;
This patch LGTM overall (though I'm still not familiar with MCD itself, it's new to me) but this change feels unrelated to this patch. Maybe introduce custom_error field back in the patch that adds mcdcore_state and don't create the custom_mcd_error static in the first place? This'd also reduce the amount of diff lines in patches.
This is just a suggestion, I realise it means more work for you, so feel free to ignore it.
Quoted 307 lines
mcd/mcd_server.c +115
-28mcd_core_con_info_st info;mcd_core_st *open_core; +CPUState *cpu; +GArray *memory_spaces; } mcdcore_state;/** * struct mcdserver_state - State of the MCD server * -* @last_error: Error info of most recent executed function. -* @open_server: Open server instance as allocated in mcd_open_server_f(). -* @system_key: System key as provided in mcd_open_server_f() -* @cores: Internal core information database. +* @last_error: Error info of most recent executed function. +* @custom_error: Reserves memory for custom MCD errors. +* @open_server: Open server instance as allocated in mcd_open_server_f(). +* @system_key: System key as provided in mcd_open_server_f() +* @cores: Internal core information database. */ typedef struct mcdserver_state { const mcd_error_info_st *last_error; + mcd_error_info_st custom_error; mcd_server_st *open_server; char system_key[MCD_KEY_LEN]; GArray *cores;@@ -134,13 +146,13 @@ mcd_return_et mcd_initialize_f(const mcd_api_version_st *version_req, version_req->v_api_minor <= MCD_API_VER_MINOR) { g_server_state.last_error = &MCD_ERROR_NONE; } else { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_GENERAL , .error_events =MCD_ERR_EVT_NONE , .error_str ="incompatible versions" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error; }return g_server_state.last_error->return_status;@@ -160,13 +172,13 @@ mcd_return_et mcd_qry_servers_f(const char *host, bool running, mcd_server_info_st *server_info) {if (start_index >=1 ) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_PARAM , .error_events =MCD_ERR_EVT_NONE , .error_str ="QEMU only has one MCD server" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -214,13 +226,13 @@ mcd_return_et mcd_open_server_f(const char *system_key,CPUState *cpu;if (g_server_state.open_server) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_CONNECTION , .error_events =MCD_ERR_EVT_NONE , .error_str ="server already open" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -253,6 +265,8 @@ mcd_return_et mcd_open_server_f(const char *system_key, }, .last_error = &MCD_ERROR_NONE, .open_core = NULL, + .cpu = cpu, + .memory_spaces = g_array_new(false, true, sizeof(mcd_memspace_st)), };pstrcpy (c.info.core,MCD_UNIQUE_NAME_LEN , cpu_model);g_array_append_val (g_server_state.cores, c);@@ -265,24 +279,24 @@ mcd_return_et mcd_open_server_f(const char *system_key,mcd_return_et mcd_close_server_f (const mcd_server_st *server) {if (!g_server_state.open_server) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_CONNECTION , .error_events =MCD_ERR_EVT_NONE , .error_str ="server not open" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }if (server != g_server_state.open_server) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_CONNECTION , .error_events =MCD_ERR_EVT_NONE , .error_str ="unknown server" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -333,13 +347,13 @@ mcd_return_et mcd_qry_systems_f(uint32_t start_index, uint32_t *num_systems, }if (start_index >=1 ) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_PARAM , .error_events =MCD_ERR_EVT_NONE , .error_str ="QEMU only emulates one system" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -381,13 +395,13 @@ mcd_return_et mcd_qry_devices_f(const mcd_core_con_info_st *system_con_info, }if (start_index >=1 ) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_PARAM , .error_events =MCD_ERR_EVT_NONE , .error_str ="QEMU only emulates one machine" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -431,13 +445,13 @@ mcd_return_et mcd_qry_cores_f(const mcd_core_con_info_st *connection_info, }if (start_index >= g_server_state.cores->len) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_PARAM , .error_events =MCD_ERR_EVT_NONE , .error_str ="start_index exceeds the number of cores" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }@@ -471,6 +485,59 @@ mcd_return_et mcd_qry_core_modes_f(const mcd_core_st *core,return g_server_state.last_error->return_status; } +static mcd_return_et query_memspaces (mcdcore_state *core_state) +{ +g_array_set_size (core_state->memory_spaces,0 ); + +mcd_endian_et endian =target_big_endian () ?MCD_ENDIAN_BIG + :MCD_ENDIAN_LITTLE ; + +for (uint32_t i =0 ; i < core_state->cpu->num_ases; i++) { +AddressSpace *as =cpu_get_address_space (core_state->cpu, i); + +int secure_flag =0 ; +if (core_state->cpu->num_ases >1 ) { +int sid =cpu_asidx_from_attrs (core_state->cpu, + (MemTxAttrs ) { .secure =1 }); +if (i == sid) { + secure_flag =MCD_MEM_SPACE_IS_SECURE ; + } + } + +const char *as_name = as->name; +const char *mr_name = as->root->name; + +mcd_memspace_st physical = { +/* mem space ID 0 is reserved */ + .mem_space_id = core_state->memory_spaces->len +1 , + .mem_type =MCD_MEM_SPACE_IS_PHYSICAL | secure_flag, + .endian = endian, + }; +strncpy (physical.mem_space_name, mr_name,MCD_MEM_SPACE_NAME_LEN -1 ); + +g_array_append_val (core_state->memory_spaces, physical); + +mcd_memspace_st logical = { + .mem_space_id = core_state->memory_spaces->len +1 , + .mem_type =MCD_MEM_SPACE_IS_LOGICAL | secure_flag, + .endian = endian, + }; +strncpy (logical.mem_space_name, as_name,MCD_MEM_SPACE_NAME_LEN -1 ); + +g_array_append_val (core_state->memory_spaces, logical); + } + +mcd_memspace_st gdb_registers = { + .mem_space_id = core_state->memory_spaces->len +1 , + .mem_space_name ="GDB Registers" , + .mem_type =MCD_MEM_SPACE_IS_REGISTERS , + .endian = endian, + }; +g_array_append_val (core_state->memory_spaces, gdb_registers); + +return MCD_RET_ACT_NONE ; +} +mcd_return_et mcd_open_core_f (const mcd_core_con_info_st *core_con_info,mcd_core_st **core) {@@ -490,25 +557,29 @@ mcd_return_et mcd_open_core_f(const mcd_core_con_info_st *core_con_info, core_id = core_con_info->core_id;if (core_id > g_server_state.cores->len) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_PARAM , .error_events =MCD_ERR_EVT_NONE , .error_str ="specified core index exceeds the number of cores" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; } core_state = &g_array_index (g_server_state.cores, mcdcore_state, core_id);if (core_state->open_core) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_CONNECTION , .error_events =MCD_ERR_EVT_NONE , .error_str ="core already open" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error; +return g_server_state.last_error->return_status; + } + +if (query_memspaces (core_state) !=MCD_RET_ACT_NONE ) {return g_server_state.last_error->return_status; }@@ -540,19 +611,21 @@ mcd_return_et mcd_close_core_f(const mcd_core_st *core) }if (core_state->open_core != core) { - custom_mcd_error = (mcd_error_info_st ) { + g_server_state.custom_error = (mcd_error_info_st ) { .return_status =MCD_RET_ACT_HANDLE_ERROR , .error_code =MCD_ERR_CONNECTION , .error_events =MCD_ERR_EVT_NONE , .error_str ="core not open" , }; - g_server_state.last_error = &custom_mcd_error; + g_server_state.last_error = &g_server_state.custom_error;return g_server_state.last_error->return_status; }g_free ((void *)core->core_con_info);g_free ((void *)core); core_state->open_core =NULL ; + core_state->cpu =NULL ; +g_array_set_size (core_state->memory_spaces,0 ); g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status;@@ -613,8 +686,66 @@ mcd_return_et mcd_qry_mem_spaces_f(const mcd_core_st *core,uint32_t *num_mem_spaces, mcd_memspace_st *mem_spaces) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED; -return g_server_state.last_error->return_status; + uint32_t i; +mcdcore_state *core_state; + +if (!core || !num_mem_spaces) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +g_assert (core_state->memory_spaces); + +if (core_state->memory_spaces->len ==0 ) { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_NO_MEM_SPACES , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="" , + }; + core_state->last_error = &core_state->custom_error;
mcd/mcd_server.c mcd_return_et mcd_qry_mem_spaces_f(const mcd_core_st *core, · line 722
Quoted 10 lines
mcd/mcd_server.c +10
-0+return core_state->last_error->return_status; + } + +if (*num_mem_spaces ==0 ) { + *num_mem_spaces = core_state->memory_spaces->len; + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status; + } + +if (start_index >= core_state->memory_spaces->len) {
The first memory space gets an index of len + 1 == 1, since it's mentioned earlier that 0 is reserved, so if start_index is 1 should we not be failing here? Or am I misunderstanding something? Is start_index 0-based and mem_space_id 1-based?
Quoted 66 lines
mcd/mcd_server.c +26
-0+ core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_PARAM , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="start_index exceeds the number of memory spaces" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + +if (!mem_spaces) { + core_state->last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return core_state->last_error->return_status; + } + +for (i =0 ; i < *num_mem_spaces && + start_index + i < core_state->memory_spaces->len; i++) { + + mem_spaces[i] =g_array_index (core_state->memory_spaces, + mcd_memspace_st, start_index + i); + } + + *num_mem_spaces = i; + + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status; } mcd_return_et mcd_qry_mem_blocks_f(const mcd_core_st *core,mcd/mcd_stub.c +29
-0@@ -379,3 +379,47 @@ MCDErrorInfo *qmp_mcd_qry_error_info(uint32_t core_uid, Error **errp) result =marshal_mcd_error_info (&error_info);return result; } + +MCDQryMemSpacesResult *qmp_mcd_qry_mem_spaces (uint32_t core_uid, +uint32_t start_index, +uint32_t num_mem_spaces, +Error **errp) +{ +MCDMemspaceList **tailp; +MCDMemspace *ms; +mcd_memspace_st *memspaces =NULL ; +bool query_num_only = num_mem_spaces ==0 ; +MCDQryMemSpacesResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + +if (retrieve_open_core (core_uid, &core) !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; + } + +if (!query_num_only) { + memspaces =g_malloc0 (num_mem_spaces *sizeof (*memspaces)); + } + + result->return_status =mcd_qry_mem_spaces_f (core, start_index, + &num_mem_spaces, memspaces); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->has_num_mem_spaces = true; + result->num_mem_spaces = num_mem_spaces; +if (!query_num_only) { + result->has_mem_spaces = true;
mcd/mcd_stub.c MCDErrorInfo *qmp_mcd_qry_error_info(uint32_t core_uid, Error **errp) · line 420
Quoted 10 lines
mcd/mcd_stub.c +10
-0+ tailp = &(result->mem_spaces); +for (uint32_t i =0 ; i < num_mem_spaces; i++) { + ms =marshal_mcd_memspace (memspaces + i); +QAPI_LIST_APPEND (tailp, ms); + } + } + } + +if (!query_num_only) { +g_free (memspaces);
Who is responsible for freeing result and memspaces (if (query_num_only)) in this function? Could you accompany every g_malloc* with a comment that explains the resource's lifetime?
Quoted 359 lines
mcd/mcd_stub.c +5
-0+ } + + g_stub_state.on_error_ask_server = true; +return result; +}qapi/mcd.json +199
-0@@ -147,6 +147,74 @@ 'core-id' : 'uint32' } } +## +# @MCDMemspace: +# +# Structure type containing information about a memory space. +# +# @mem-space-id: ID of this memory space, ID 0 is reserved. +# @mem-space-name: Unique name of the memory space. +# @mem-type: Type of the memory space. +# @bits-per-mau: Bits per minimum addressable unit (MAU). The +# minimum addressable unit of a memory is defined as +# the size in bits of its basic block that may have +# a unique address. For example for a byte +# addressable memory this value would be set to '8' +# according to the 8 bits of a byte block. +# @invariance: The total number of bytes in a memory word, which +# is @bits-per-mau divided by 8, consists of groups +# of "invariant" bytes. These groups can be arranged +# in Big Endian or Little Endian order. +# For example an @invariance of '2' and '64' +# @bits-per-mau, a Little Endian word are +# represented as b0 b1 b2 b3 b4 b5 b6 b7. +# In contrast to this, a Big Endian word is +# represented as b6 b7 b4 b5 b2 b3 b0 b1. +# @endian: Endianness of this memory space. Can be overriden +# by @endian of a MCDMemblock. +# @min-addr: Minimum address of this memory space. +# @max-addr: Maximum address of this memory space. +# @num-mem-blocks: Number of memory blocks in this memory space. Each +# memory space may have a certain number of memory +# blocks. Memory blocks contain additional +# information pertaining to the intended purpose of +# the memory. This information may be used as a hint +# for memory data representation within a tool's +# memory view. This field specifies the number of +# memory blocks present in this memory space. +# @supported-access-options: Supported memory access options (OR'ed bitmask). +# Can be overriden by @supported-access-options of a +# MCDMemblock. +# @core-mode-mask-read: Mask of core modes for which read accesses are +# impossible. A set bit indicates that read accesses +# are denied in this mode. Bit 0 represents core +# mode '1', bit 31 represents core mode '32'. Can be +# overriden by @core-mode-mask-read of a MCDMemblock. +# @core-mode-mask-write: Mask of core modes for which write accesses are +# impossible; a set bit indicates that write +# accesses are denied in this mode. Bit 0 represents +# core mode '1', bit 31 represents core mode '32'. +# Can be overriden by +# @core-mode-mask-write of a MCDMemblock. +# +# Since: 9.1 +## +{ 'struct': 'MCDMemspace', + 'data': { + 'mem-space-id' : 'uint32', + 'mem-space-name' : 'str', + 'mem-type' : 'uint32', + 'bits-per-mau' : 'uint32', + 'invariance' : 'uint8', + 'endian' : 'uint32', + 'min-addr' : 'uint64', + 'max-addr' : 'uint64', + 'num-mem-blocks' : 'uint32', + 'supported-access-options': 'uint32', + 'core-mode-mask-read' : 'uint32', + 'core-mode-mask-write' : 'uint32' } } + + ## # == Target Initialization API ##@@ -878,3 +946,134 @@ { 'command': 'mcd-qry-error-info', 'data': { 'core-uid': 'uint32' }, 'returns': 'MCDErrorInfo' } + + +## +# @MCDQryMemSpacesResult: +# +# Return value of @mcd-qry-mem-spaces. +# +# @return-status: Return code. +# @num-mem-spaces: The number of returned memory spaces. In case the input value +# of @num-mem-spaces is '0', this is the number of all +# available memory spaces for the selected core. +# @mem-spaces: Memory space information. +# +# Since: 9.1 +## +{ 'struct': 'MCDQryMemSpacesResult', + 'data': { + 'return-status' : 'uint32', + '*num-mem-spaces': 'uint32', + '*mem-spaces' : [ 'MCDMemspace' ] }} + +## +# @mcd-qry-mem-spaces: +# +# Function querying the available memory spaces for a particular component. +# +# @core-uid: Unique identifier of the open core as returned by +# @mcd-open-core. +# @start-index: Start index of the requested memory spaces. This refers to +# an internal list of the target side implementation. +# @num-mem-spaces: Number of memory spaces, information is requested of. If it +# is set to '0', no memory space information is returned but +# the number of all available memory spaces for the selected +# core. +# +# Returns: @MCDQryMemSpacesResult +# +# Since: 9.1 +# +# .. qmp-example:: +# :title: Arm TrustZone +# +# -> { "execute": "mcd-qry-mem-spaces", +# "arguments": { "core-uid": 1, +# "start-index": 0, +# "num-mem-spaces": 20 } } +# <- { +# "return": { +# "mem-spaces": [ +# { +# "mem-space-id": 1, +# "bits-per-mau": 0, +# "mem-space-name": "system", +# "endian": 0, +# "max-addr": 0, +# "mem-type": 16, +# "core-mode-mask-write": 0, +# "core-mode-mask-read": 0, +# "supported-access-options": 0, +# "invariance": 0, +# "num-mem-blocks": 0, +# "min-addr": 0 +# }, +# { +# "mem-space-id": 2, +# "bits-per-mau": 0, +# "mem-space-name": "cpu-memory-0", +# "endian": 0, +# "max-addr": 0, +# "mem-type": 32, +# "core-mode-mask-write": 0, +# "core-mode-mask-read": 0, +# "supported-access-options": 0, +# "invariance": 0, +# "num-mem-blocks": 0, +# "min-addr": 0 +# }, +# { +# "mem-space-id": 3, +# "bits-per-mau": 0, +# "mem-space-name": "secure-memory", +# "endian": 0, +# "max-addr": 0, +# "mem-type": 65552, +# "core-mode-mask-write": 0, +# "core-mode-mask-read": 0, +# "supported-access-options": 0, +# "invariance": 0, +# "num-mem-blocks": 0, +# "min-addr": 0 +# }, +# { +# "mem-space-id": 4, +# "bits-per-mau": 0, +# "mem-space-name": "cpu-secure-memory-0", +# "endian": 0, +# "max-addr": 0, +# "mem-type": 65568, +# "core-mode-mask-write": 0, +# "core-mode-mask-read": 0, +# "supported-access-options": 0, +# "invariance": 0, +# "num-mem-blocks": 0, +# "min-addr": 0 +# }, +# { +# "mem-space-id": 5, +# "bits-per-mau": 0, +# "mem-space-name": "GDB Registers", +# "endian": 0, +# "max-addr": 0, +# "mem-type": 1, +# "core-mode-mask-write": 0, +# "core-mode-mask-read": 0, +# "supported-access-options": 0, +# "invariance": 0, +# "num-mem-blocks": 0, +# "min-addr": 0 +# } +# ], +# "return-status": 0, +# "num-mem-spaces": 5 +# } +# } +## +{ 'command': 'mcd-qry-mem-spaces', + 'data': { + 'core-uid' : 'uint32', + 'start-index' : 'uint32', + 'num-mem-spaces': 'uint32' }, + 'returns': 'MCDQryMemSpacesResult' }tests/qtest/mcd-test.c +79
-0@@ -399,6 +399,84 @@ static void test_open_core(void)mcdtest_quit (&qts); } +static void test_qry_core_info (void ) +{ +QTestStateMCD qts =mcdtest_init (QEMU_EXTRA_ARGS ); +MCDQryCoresResult *cores_query =open_server_query_cores (&qts); + +MCDCoreConInfoList *core_head = cores_query->core_con_info; +for (uint32_t c =0 ; c < cores_query->num_cores; c++) { +q_obj_mcd_qry_mem_spaces_arg qry_mem_spaces_args; +q_obj_mcd_close_core_arg close_core_args; +MCDQryMemSpacesResult *qry_mem_spaces_result; +MCDCloseCoreResult *close_core_result; + +MCDCoreConInfo *core_con_info = core_head->value; +q_obj_mcd_open_core_arg open_core_args = { + .core_con_info = core_con_info, + }; +MCDOpenCoreResult *open_core_result = +qtest_mcd_open_core (&qts, &open_core_args); +g_assert (open_core_result->return_status ==MCD_RET_ACT_NONE ); +g_assert (open_core_result->has_core_uid); + +if (verbose) { +fprintf (stderr,"[INFO]\tCore %s #%d\n" , + core_con_info->core, + core_con_info->core_id); + } + + qry_mem_spaces_args = (q_obj_mcd_qry_mem_spaces_arg ) { + .core_uid = open_core_result->core_uid, + .start_index =0 , + .num_mem_spaces =0 , + }; + + qry_mem_spaces_result =qtest_mcd_qry_mem_spaces (&qts, + &qry_mem_spaces_args); +g_assert (qry_mem_spaces_result->return_status ==MCD_RET_ACT_NONE ); +g_assert (qry_mem_spaces_result->has_num_mem_spaces); +g_assert (qry_mem_spaces_result->num_mem_spaces >0 ); + + qry_mem_spaces_args.num_mem_spaces = + qry_mem_spaces_result->num_mem_spaces; +qapi_free_MCDQryMemSpacesResult (qry_mem_spaces_result); + qry_mem_spaces_result =qtest_mcd_qry_mem_spaces (&qts, + &qry_mem_spaces_args); +g_assert (qry_mem_spaces_result->return_status ==MCD_RET_ACT_NONE ); +g_assert (qry_mem_spaces_result->has_num_mem_spaces); + +if (verbose) { +MCDMemspaceList *ms_head = qry_mem_spaces_result->mem_spaces; +for (uint32_t i =0 ; + i < qry_mem_spaces_result->num_mem_spaces; i++) { +MCDMemspace *ms = ms_head->value; +if (verbose) { +fprintf (stderr,"\tMemory Space: %s (#%d)\n" +"\t Type: 0x%x\n" , + ms->mem_space_name, + ms->mem_space_id, + ms->mem_type); + } + ms_head = ms_head->next; + } + } + +qapi_free_MCDQryMemSpacesResult (qry_mem_spaces_result); + close_core_args.core_uid = open_core_result->core_uid; + close_core_result =qtest_mcd_close_core (&qts, &close_core_args); +g_assert (close_core_result->return_status ==MCD_RET_ACT_NONE ); + +qapi_free_MCDCloseCoreResult (close_core_result); +qapi_free_MCDOpenCoreResult (open_core_result); + core_head = core_head->next; + } + +qapi_free_MCDQryCoresResult (cores_query); +qtest_mcd_exit (&qts); +mcdtest_quit (&qts); +} +int main (int argc,char *argv[]) {char *v_env =getenv ("V" );@@ -411,5 +489,6 @@ int main(int argc, char *argv[])qtest_add_func ("mcd/open-server" , test_open_server);qtest_add_func ("mcd/qry-cores" , test_qry_cores);qtest_add_func ("mcd/open-core" , test_open_core); +qtest_add_func ("mcd/qry-core-info" , test_qry_core_info);return g_test_run (); }tests/qtest/mcd-util.c +20
-0@@ -269,3 +269,23 @@ MCDCloseCoreResult *qtest_mcd_close_core(QTestStateMCD *qts,return unmarshal; } + +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces ( +QTestStateMCD *qts,q_obj_mcd_qry_mem_spaces_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryMemSpacesResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_mem_spaces_arg); + + resp =qtest_mcd (qts,"{'execute': 'mcd-qry-mem-spaces'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryMemSpacesResult); + +return unmarshal; +}tests/qtest/mcd-util.h +3
-0@@ -51,4 +51,7 @@ MCDOpenCoreResult *qtest_mcd_open_core(QTestStateMCD *qts,MCDCloseCoreResult *qtest_mcd_close_core (QTestStateMCD *qts,q_obj_mcd_close_core_arg *args); +MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces (QTestStateMCD *qts, +q_obj_mcd_qry_mem_spaces_arg *args); +#endif /* TEST_MCD_UTILS_H */ Signature · 1 line
2.34.1
--
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd
Re: [PATCH v2 11/20] mcd: Implement memory space query
Thank you for taking the time to review this patch!
Quoted 119 lines · Manos Pitsidianakis
Quoted 101 lines · Mario Fleischmann
Support three main memory space types:
* Physical memory
* Logical memory (MMU)
* GDB RegistersUse custom memory type to mark memory spaces as secure
V=1 QTEST_QEMU_BINARY="./qemu-system-arm -M virt,secure=on -cpu cortex-a15" tests/qtest/mcd-test
Signed-off-by Mario Fleischmann <[email protected]>---
mcd/mcd_qapi.c | 22 +++++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 199 ++++++++++++++++++++++++++++++++++------- mcd/mcd_stub.c | 44 +++++++++ qapi/mcd.json | 199 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 79 ++++++++++++++++ tests/qtest/mcd-util.c | 20 +++++ tests/qtest/mcd-util.h | 3 + 8 files changed, 534 insertions(+), 34 deletions(-)mcd/mcd_qapi.c +22
-0@@ -125,3 +125,25 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info)return unmarshal; } + +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space) +{ +MCDMemspace *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDMemspace ) { + .mem_space_id = mem_space->mem_space_id, + .mem_space_name =g_strdup (mem_space->mem_space_name), + .mem_type = mem_space->mem_type, + .bits_per_mau = mem_space->bits_per_mau, + .invariance = mem_space->invariance, + .endian = mem_space->endian, + .min_addr = mem_space->min_addr, + .max_addr = mem_space->max_addr, + .num_mem_blocks = mem_space->num_mem_blocks, + .supported_access_options = mem_space->supported_access_options, + .core_mode_mask_read = mem_space->core_mode_mask_read, + .core_mode_mask_write = mem_space->core_mode_mask_write, + }; + +return marshal; +}mcd/mcd_qapi.h +2
-0@@ -25,6 +25,8 @@ MCDServerInfo *marshal_mcd_server_info(const mcd_server_info_st *server_info);MCDCoreConInfo *marshal_mcd_core_con_info (const mcd_core_con_info_st *con_info); +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);mcd/mcd_server.c +10
-6@@ -12,6 +12,10 @@#include "qemu/cutils.h" #include "mcd_api.h" #include "hw/boards.h" +#include "exec/tswap.h" + +/* Custom memory space type */ +static const mcd_mem_type_et MCD_MEM_SPACE_IS_SECURE =0x00010000 ;static const mcd_error_info_st MCD_ERROR_NOT_IMPLEMENTED = { .return_status =MCD_RET_ACT_HANDLE_ERROR ,@@ -48,37 +52,45 @@ static const mcd_error_info_st MCD_ERROR_NONE = { .error_str = "", }; -/* reserves memory for custom errors */ -static mcd_error_info_st custom_mcd_error; -/** * struct mcdcore_state - State of a core. * -* @last_error: Error info of most recent executed function. -* @info: Core connection information. -* @open_core: Open core instance as allocated in mcd_open_core_f(). +* @last_error: Error info of most recent executed core-related function. +* @custom_error: Reserves memory for custom MCD errors. +* @info: Core connection information. +* @open_core: Open core instance as allocated in mcd_open_core_f(). +* @cpu: QEMU's internal CPU handle. +* @memory_spaces: Memory spaces as queried by mcd_qry_mem_spaces_f(). * * MCD is mainly being used on the core level: mcd/mcd_server.c static const mcd_error_info_st MCD_ERROR_NONE = { · line 75
Quoted 10 lines
mcd/mcd_server.c +4
-0* After the initial query functions, a core connection is opened in * mcd_open_core_f(). The allocated mcd_core_st instance is then the basis * of subsequent operations. +* +* @cpu is the internal CPU handle through which core specific debug +* functions are implemented. */ typedef struct mcdcore_state { const mcd_error_info_st *last_error; + mcd_error_info_st custom_error;This patch LGTM overall (though I'm still not familiar with MCD itself, it's new to me) but this change feels unrelated to this patch. Maybe introduce
custom_errorfield back in the patch that addsmcdcore_stateand don't create thecustom_mcd_errorstatic in the first place? This'd also reduce the amount of diff lines in patches.
Quoted 2 lines
This is just a suggestion, I realise it means more work for you, so feel free to ignore it.
I tried to only include changes in the patches that are necessary for the current use case but I guess in this case and the one from
[PATCH v2 07/20] mcd: Implement target initialization API
assuming _some_ future use case will result in a more explanatory patch series overall... I'll see what I can do!
[...]
Quoted 37 lines
Quoted 37 lines
mcd/mcd_server.c +31
-2@@ -613,8 +686,66 @@ mcd_return_et mcd_qry_mem_spaces_f(const mcd_core_st *core,uint32_t *num_mem_spaces, mcd_memspace_st *mem_spaces) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED; -return g_server_state.last_error->return_status; + uint32_t i; +mcdcore_state *core_state; + +if (!core || !num_mem_spaces) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +g_assert (core_state->memory_spaces); + +if (core_state->memory_spaces->len ==0 ) { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_NO_MEM_SPACES , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + +if (*num_mem_spaces ==0 ) { + *num_mem_spaces = core_state->memory_spaces->len; + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status;
Quoted 8 lines
mcd/mcd_server.c mcd_return_et mcd_qry_mem_spaces_f(const mcd_core_st *core, · line 722
Quoted 3 lines
mcd/mcd_server.c +3
-0+ } + +if (start_index >= core_state->memory_spaces->len) {The first memory space gets an index of len + 1 == 1, since it's mentioned earlier that 0 is reserved, so if
start_indexis 1 should we not be failing here? Or am I misunderstanding something? Isstart_index0-based andmem_space_id1-based?
Yes, this a gotcha from the MCD API...
/**
* mcd_qry_mem_spaces_f() - Function querying the available memory spaces for a particular component.
*
* @core: [in] A reference to the core the calling function
addresses.
* @start_index: [in] Start index of the requested memory spaces. This refers to an internal list of the target side implementation.
* ...
*/
As an example, it should be possible that the server manages memory spaces with the IDs [5, 4, 1, 3] internally. start_index = 0 would then point to the memory space with ID 5.
I will add a comment for it in the source code and in the commit message.
[...]
Quoted 43 lines
Quoted 43 lines
mcd/mcd_stub.c +35
-0@@ -379,3 +379,47 @@ MCDErrorInfo *qmp_mcd_qry_error_info(uint32_t core_uid, Error **errp) result =marshal_mcd_error_info (&error_info);return result; } + +MCDQryMemSpacesResult *qmp_mcd_qry_mem_spaces (uint32_t core_uid, +uint32_t start_index, +uint32_t num_mem_spaces, +Error **errp) +{ +MCDMemspaceList **tailp; +MCDMemspace *ms; +mcd_memspace_st *memspaces =NULL ; +bool query_num_only = num_mem_spaces ==0 ; +MCDQryMemSpacesResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + +if (retrieve_open_core (core_uid, &core) !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; + } + +if (!query_num_only) { + memspaces =g_malloc0 (num_mem_spaces *sizeof (*memspaces)); + } + + result->return_status =mcd_qry_mem_spaces_f (core, start_index, + &num_mem_spaces, memspaces); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->has_num_mem_spaces = true; + result->num_mem_spaces = num_mem_spaces; +if (!query_num_only) { + result->has_mem_spaces = true; + tailp = &(result->mem_spaces); +for (uint32_t i =0 ; i < num_mem_spaces; i++) { + ms =marshal_mcd_memspace (memspaces + i); +QAPI_LIST_APPEND (tailp, ms); + } + }
Quoted 8 lines
mcd/mcd_stub.c MCDErrorInfo *qmp_mcd_qry_error_info(uint32_t core_uid, Error **errp) · line 420
Quoted 4 lines
mcd/mcd_stub.c +4
-0+ } + +if (!query_num_only) { +g_free (memspaces);Who is responsible for freeing result and memspaces (if (
query_num_only)) in this function? Could you accompany every g_malloc* with a comment that explains the resource's lifetime?
Since, every qmp_mcd_* function follows a similar structure, would a comment at the top of mcd_stub.c suffice?
Function arguments and return values are freed by the QAPI infrastructure, i.e. qmp_marshal_mcd_qry_mem_spaces and qmp_marshal_output_MCDQryRegGroupsResult in build/mcd/mcd-qapi-commands.c
For MCD server functions, the ownership of arguments is defined by the MCD API with the server stub being the caller of the function. Therefore, the memspaces array needs to be freed by qmp_mcd_qry_mem_spaces.
PATCH v2 12/20 gdbstub: Expose GDBRegisterState
In reply to Mario Fleischmann--- gdbstub/gdbstub.c | 7 ------- include/exec/gdbstub.h | 8 +++++++- 2 files changed, 7 insertions(+), 8 deletions(-)
gdbstub/gdbstub.c +0 -7
@@ -48,13 +48,6 @@#include "internals.h" -typedef struct GDBRegisterState { -int base_reg; -gdb_get_reg_cb get_reg; -gdb_set_reg_cb set_reg; -const GDBFeature *feature; -}GDBRegisterState ; -GDBState gdbserver_state;void gdb_init_gdbserver_state (void )
include/exec/gdbstub.h +7 -1
@@ -16,11 +16,17 @@ typedef struct GDBFeatureBuilder {int base_reg; } GDBFeatureBuilder; -/* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb )(CPUState *cpu,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUState *cpu,uint8_t *buf,int reg); +typedef struct GDBRegisterState { +int base_reg; +gdb_get_reg_cb get_reg; +gdb_set_reg_cb set_reg; +const GDBFeature *feature; +}GDBRegisterState ; +/** * gdb_init_cpu(): Initialize the CPU for gdbstub. * @cpu: The CPU to be initialized.
Signature · 1 line
2.34.1
Re: [PATCH v2 12/20] gdbstub: Expose GDBRegisterState
Quoted 29 lines · Mario Fleischmann
Signed-off-by Mario Fleischmann <[email protected]>---
gdbstub/gdbstub.c| 7 -------include/exec/gdbstub.h| 8 +++++++-2 files changed, 7 insertions(+), 8 deletions(-)gdbstub/gdbstub.c +0
-7@@ -48,13 +48,6 @@#include "internals.h" -typedef struct GDBRegisterState { -int base_reg; -gdb_get_reg_cb get_reg; -gdb_set_reg_cb set_reg; -const GDBFeature *feature; -}GDBRegisterState ; -GDBState gdbserver_state;void gdb_init_gdbserver_state (void )include/exec/gdbstub.h +0
-0
include/exec/gdbstub.h typedef struct GDBFeatureBuilder { · line 19
Quoted 4 lines
include/exec/gdbstub.h +0
-1@@ -16,11 +16,17 @@ typedef struct GDBFeatureBuilder {int base_reg; } GDBFeatureBuilder; -
Accidental line deletion here?
With that fixed,
Quoted 18 lines
include/exec/gdbstub.h +7
-0/* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb )(CPUState *cpu,GByteArray *buf,int reg);typedef int (*gdb_set_reg_cb )(CPUState *cpu,uint8_t *buf,int reg); +typedef struct GDBRegisterState { +int base_reg; +gdb_get_reg_cb get_reg; +gdb_set_reg_cb set_reg; +const GDBFeature *feature; +}GDBRegisterState ; +/** * gdb_init_cpu(): Initialize the CPU for gdbstub. * @cpu: The CPU to be initialized. Signature · 1 line
2.34.1
Re: [PATCH v2 12/20] gdbstub: Expose GDBRegisterState
Quoted 33 lines · Manos Pitsidianakis
Quoted 32 lines · Mario Fleischmann
Signed-off-by Mario Fleischmann <[email protected]>---
gdbstub/gdbstub.c| 7 -------include/exec/gdbstub.h| 8 +++++++-2 files changed, 7 insertions(+), 8 deletions(-)gdbstub/gdbstub.c +0
-7@@ -48,13 +48,6 @@#include "internals.h" -typedef struct GDBRegisterState { -int base_reg; -gdb_get_reg_cb get_reg; -gdb_set_reg_cb set_reg; -const GDBFeature *feature; -}GDBRegisterState ; -GDBState gdbserver_state;void gdb_init_gdbserver_state (void )include/exec/gdbstub.h +0
-0@@ -16,11 +16,17 @@ typedef struct GDBFeatureBuilder {int base_reg; } GDBFeatureBuilder;
Quoted 7 lines
include/exec/gdbstub.h typedef struct GDBFeatureBuilder { · line 19
Quoted 1 line
include/exec/gdbstub.h +0
-1-Accidental line deletion here?
With that fixed,
Reviewed-by Manos Pitsidianakis <[email protected]>
Yes, thanks for pointing it out!
PATCH v2 13/20 mcd: Implement register query
In reply to Mario FleischmannDirectly map MCD register groups to GDB features lists
--- mcd/mcd_qapi.c | 48 +++++++ mcd/mcd_qapi.h | 8 ++ mcd/mcd_server.c | 237 +++++++++++++++++++++++++++++++-- mcd/mcd_stub.c | 93 +++++++++++++ qapi/mcd.json | 296 +++++++++++++++++++++++++++++++++++++++++ tests/qtest/mcd-test.c | 85 ++++++++++++ tests/qtest/mcd-util.c | 40 ++++++ tests/qtest/mcd-util.h | 6 + 8 files changed, 803 insertions(+), 10 deletions(-)
mcd/mcd_qapi.c +48 -0
@@ -147,3 +147,51 @@ MCDMemspace *marshal_mcd_memspace(const mcd_memspace_st *mem_space)return marshal; } + +MCDRegisterGroup *marshal_mcd_register_group ( +const mcd_register_group_st *reg_group) +{ +MCDRegisterGroup *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRegisterGroup ) { + .reg_group_id = reg_group->reg_group_id, + .reg_group_name =g_strdup (reg_group->reg_group_name), + .n_registers = reg_group->n_registers, + }; + +return marshal; +} + +MCDAddr *marshal_mcd_addr (const mcd_addr_st *addr) +{ +MCDAddr *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDAddr ) { + .address = addr->address, + .mem_space_id = addr->mem_space_id, + .addr_space_id = addr->addr_space_id, + .addr_space_type = addr->addr_space_type, + }; + +return marshal; +} + +MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info) +{ +MCDRegisterInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRegisterInfo ) { + .addr =marshal_mcd_addr (®_info->addr), + .reg_group_id = reg_info->reg_group_id, + .regname =g_strdup (reg_info->regname), + .regsize = reg_info->regsize, + .core_mode_mask_read = reg_info->core_mode_mask_read, + .core_mode_mask_write = reg_info->core_mode_mask_write, + .side_effects_read = reg_info->has_side_effects_read, + .side_effects_write = reg_info->has_side_effects_write, + .reg_type = reg_info->reg_type, + .hw_thread_id = reg_info->hw_thread_id, + }; + +return marshal; +}
mcd/mcd_qapi.h +8 -0
@@ -27,6 +27,14 @@ MCDCoreConInfo *marshal_mcd_core_con_info(const mcd_core_con_info_st *con_info);MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space); +MCDRegisterGroup *marshal_mcd_register_group ( +const mcd_register_group_st *reg_group); + +MCDAddr *marshal_mcd_addr (const mcd_addr_st *addr); + +MCDRegisterInfo *marshal_mcd_register_info ( +const mcd_register_info_st *reg_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcd_server.c +227 -10
297 lines not on this page · raw message
mcd/mcd_stub.c +93 -0
96 lines not on this page · raw message
qapi/mcd.json +296 -0
305 lines not on this page · raw message
tests/qtest/mcd-test.c +85 -0
105 lines not on this page · raw message
tests/qtest/mcd-util.c +40 -0
@@ -289,3 +289,43 @@ MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces(return unmarshal; } + +MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups ( +QTestStateMCD *qts,q_obj_mcd_qry_reg_groups_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryRegGroupsResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_reg_groups_arg); + + resp =qtest_mcd (qts,"{'execute': 'mcd-qry-reg-groups'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryRegGroupsResult); + +return unmarshal; +} + +MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestStateMCD *qts, +q_obj_mcd_qry_reg_map_arg *args) +{ +Visitor *v; +QObject *marshal; +QDict *arg, *resp; +QObject *ret; +bool ok; +MCDQryRegMapResult *unmarshal; + +MARSHAL_ARGS (q_obj_mcd_qry_reg_map_arg); + + resp =qtest_mcd (qts,"{'execute': 'mcd-qry-reg-map'," +"'arguments': %p}" , arg); + +UNMARSHAL_RESULT (MCDQryRegMapResult); + +return unmarshal; +}
tests/qtest/mcd-util.h +6 -0
@@ -54,4 +54,10 @@ MCDCloseCoreResult *qtest_mcd_close_core(QTestStateMCD *qts,MCDQryMemSpacesResult *qtest_mcd_qry_mem_spaces (QTestStateMCD *qts,q_obj_mcd_qry_mem_spaces_arg *args); +MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups (QTestStateMCD *qts, +q_obj_mcd_qry_reg_groups_arg *args); + +MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestStateMCD *qts, +q_obj_mcd_qry_reg_map_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
PATCH v2 14/20 mcd: Implement runstate control
In reply to Mario FleischmannCurrently, only global stop is implemented
--- mcd/mcd_server.c | 74 +++++++++++++++++++++++++++++++++-- mcd/mcd_stub.c | 52 ++++++++++++++++++++++++ qapi/mcd.json | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 222 insertions(+), 4 deletions(-)
mcd/mcd_server.c +70 -4
@@ -14,6 +14,8 @@#include "hw/boards.h" #include "exec/tswap.h" #include "exec/gdbstub.h" +#include "hw/core/cpu.h" +#include "system/runstate.h" /* Custom memory space type */ static const mcd_mem_type_et MCD_MEM_SPACE_IS_SECURE =0x00010000 ;
@@ -1087,13 +1089,53 @@ mcd_return_et mcd_execute_txlist_f(const mcd_core_st *core,mcd_return_et mcd_run_f (const mcd_core_st *core,bool global) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; -return g_server_state.last_error->return_status; +mcdcore_state *core_state; + +if (g_server_state.cores->len >1 && global) { +vm_start (); + g_server_state.last_error = &MCD_ERROR_NONE ; +return g_server_state.last_error->return_status; + } + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (!runstate_needs_reset () && !runstate_is_running () && + !vm_prepare_start (false)) { +cpu_resume (core_state->cpu); +qemu_clock_enable (QEMU_CLOCK_VIRTUAL , true); + } + + core_state->last_error = &MCD_ERROR_NONE ; +return core_state->last_error->return_status; }mcd_return_et mcd_stop_f (const mcd_core_st *core,bool global) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +if (g_server_state.cores->len >1 && !global) { + g_server_state.custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_FN_UNIMPLEMENTED , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="core-specific stop not implemented" , + }; + g_server_state.last_error = &g_server_state.custom_error; +return g_server_state.last_error->return_status; + } + +if (runstate_is_running ()) { +vm_stop (RUN_STATE_DEBUG ); + } + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }
@@ -1120,7 +1162,31 @@ mcd_return_et mcd_step_f(const mcd_core_st *core, bool global,mcd_return_et mcd_set_global_f (const mcd_core_st *core,bool enable) { - g_server_state.last_error = &MCD_ERROR_NOT_IMPLEMENTED ; +mcdcore_state *core_state; + +if (!core) { + g_server_state.last_error = &MCD_ERROR_INVALID_NULL_PARAM ; +return g_server_state.last_error->return_status; + } + + core_state =find_core (core->core_con_info); +if (!core_state || core_state->open_core != core) { + g_server_state.last_error = &MCD_ERROR_UNKNOWN_CORE ; +return g_server_state.last_error->return_status; + } + +if (!enable) { + core_state->custom_error = (mcd_error_info_st ) { + .return_status =MCD_RET_ACT_HANDLE_ERROR , + .error_code =MCD_ERR_GENERAL , + .error_events =MCD_ERR_EVT_NONE , + .error_str ="global stop activities cannot be disabled" , + }; + core_state->last_error = &core_state->custom_error; +return core_state->last_error->return_status; + } + + g_server_state.last_error = &MCD_ERROR_NONE ;return g_server_state.last_error->return_status; }
mcd/mcd_stub.c +52 -0
55 lines not on this page · raw message
qapi/mcd.json +100 -0
103 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 15/20 mcd test: Implement core state query
In reply to Mario FleischmannDepending on the VM and CPU state, core states can be queried:
* MCD_CORE_STATE_DEBUG: VM halted or CPU artifically stopped
* MCD_CORE_STATE_RUNNING: VM and CPU running
* MCD_CORE_STATE_HALTED: CPU suspended
--- mcd/mcd_qapi.c | 16 ++++++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 48 +++++++++++++++- mcd/mcd_stub.c | 21 +++++++ qapi/mcd.json | 55 +++++++++++++++++++ tests/qtest/mcd-test.c | 121 ++++++++++++++++++++++++++++++++++++++++- tests/qtest/mcd-util.c | 58 ++++++++++++++++++++ tests/qtest/mcd-util.h | 9 +++ 8 files changed, 328 insertions(+), 2 deletions(-)
mcd/mcd_qapi.c +16 -0
@@ -195,3 +195,19 @@ MCDRegisterInfo *marshal_mcd_register_info(const mcd_register_info_st *reg_info)return marshal; } + +MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state) +{ +MCDCoreState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCoreState ) { + .state = state->state, + .event = state->event, + .hw_thread_id = state->hw_thread_id, + .trig_id = state->trig_id, + .stop_str =g_strdup (state->stop_str), + .info_str =g_strdup (state->info_str), + }; + +return marshal; +}
mcd/mcd_qapi.h +2 -0
@@ -35,6 +35,8 @@ MCDAddr *marshal_mcd_addr(const mcd_addr_st *addr);MCDRegisterInfo *marshal_mcd_register_info (const mcd_register_info_st *reg_info); +MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcd_server.c +47 -1
60 lines not on this page · raw message
mcd/mcd_stub.c +21 -0
@@ -568,3 +568,24 @@ MCDSetGlobalResult *qmp_mcd_set_global(uint32_t core_uid, bool enable, g_stub_state.on_error_ask_server = true;return result; } + +MCDQryStateResult *qmp_mcd_qry_state (uint32_t core_uid,Error **errp) +{ +MCDQryStateResult *result =g_malloc0 (sizeof (*result)); +mcd_core_state_st state; +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + + result->return_status =mcd_qry_state_f (core, &state); +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->state =marshal_mcd_core_state (&state); + } + + g_stub_state.on_error_ask_server = true; +return result; +}
qapi/mcd.json +55 -0
64 lines not on this page · raw message
tests/qtest/mcd-test.c +120 -1
144 lines not on this page · raw message
tests/qtest/mcd-util.c +58 -0
61 lines not on this page · raw message
tests/qtest/mcd-util.h +9 -0
@@ -60,4 +60,13 @@ MCDQryRegGroupsResult *qtest_mcd_qry_reg_groups(QTestStateMCD *qts,MCDQryRegMapResult *qtest_mcd_qry_reg_map (QTestStateMCD *qts,q_obj_mcd_qry_reg_map_arg *args); +MCDRunResult *qtest_mcd_run (QTestStateMCD *qts, +q_obj_mcd_run_arg *args); + +MCDStopResult *qtest_mcd_stop (QTestStateMCD *qts, +q_obj_mcd_stop_arg *args); + +MCDQryStateResult *qtest_mcd_qry_state (QTestStateMCD *qts, +q_obj_mcd_qry_state_arg *args); +#endif /* TEST_MCD_UTILS_H */
Signature · 1 line
2.34.1
PATCH v2 16/20 gdbstub: Expose gdb_write_register
In reply to Mario Fleischmann--- gdbstub/gdbstub.c | 2 +- include/exec/gdbstub.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-)
gdbstub/gdbstub.c +1 -1
@@ -527,7 +527,7 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)return 0 ; } -static int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) {GDBRegisterState *r;
include/exec/gdbstub.h +10 -0
@@ -130,6 +130,16 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname);*/ int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +/** +* gdb_write_register() - Write a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @mem_buf: The buffer that the register will be written from. +* @reg: The register's number returned by gdb_find_feature_register(). +* +* Return: The number of written bytes. +*/ +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg); +/** * typedef GDBRegDesc - a register description from gdbstub */
Signature · 1 line
2.34.1
Re: [PATCH v2 16/20] gdbstub: Expose gdb_write_register
Quoted 24 lines · Mario Fleischmann
Signed-off-by Mario Fleischmann <[email protected]>---
gdbstub/gdbstub.c| 2 +-include/exec/gdbstub.h| 10 ++++++++++2 files changed, 11 insertions(+), 1 deletion(-)gdbstub/gdbstub.c +1
-1@@ -527,7 +527,7 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)return 0 ; } -static int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg) {GDBRegisterState *r;include/exec/gdbstub.h +0
-0
include/exec/gdbstub.h const GDBFeature *gdb_find_static_feature(const char *xmlname); · line 136
Quoted 7 lines
include/exec/gdbstub.h +4
-0@@ -130,6 +130,16 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname);*/ int gdb_read_register (CPUState *cpu,GByteArray *buf,int reg); +/** +* gdb_write_register() - Write a register associated with a CPU. +* @cpu: The CPU associated with the register. +* @mem_buf: The buffer that the register will be written from.
I think this is more explanatory:
"The buffer holding the bytes value that will be written to the register."
Either way,
Quoted 13 lines
include/exec/gdbstub.h +6
-0+* @reg: The register's number returned by gdb_find_feature_register(). +* +* Return: The number of written bytes. +*/ +int gdb_write_register (CPUState *cpu,uint8_t *mem_buf,int reg); +/** * typedef GDBRegDesc - a register description from gdbstub */ Signature · 1 line
2.34.1
PATCH v2 17/20 mcd: Implement register/memory access
In reply to Mario FleischmannIn MCD, all accesses to register or memory are issued over transaction lists. This commit implements three types of transactions:
* register access
* logical memory access (with MMU)
* physical memory access (no MMU)
In contrast to GDB's remote serial protocol, MCD supports specifying an access width for memory transactions.
--- mcd/mcd_qapi.c | 128 +++++++++++++++++++++++++++++ mcd/mcd_qapi.h | 14 ++++ mcd/mcd_server.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++- mcd/mcd_stub.c | 26 ++++++ qapi/mcd.json | 83 +++++++++++++++++++ 5 files changed, 456 insertions(+), 2 deletions(-)
mcd/mcd_qapi.c +128 -0
@@ -126,6 +126,18 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info)return unmarshal; } +mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr) +{ +mcd_addr_st unmarshal = { + .address = addr->address, + .mem_space_id = addr->mem_space_id, + .addr_space_id = addr->addr_space_id, + .addr_space_type = addr->addr_space_type, + }; + +return unmarshal; +} +MCDMemspace *marshal_mcd_memspace (const mcd_memspace_st *mem_space) {MCDMemspace *marshal =g_malloc0 (sizeof (*marshal));
@@ -211,3 +223,119 @@ MCDCoreState *marshal_mcd_core_state(const mcd_core_state_st *state)return marshal; } + +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx) +{ +MCDTx *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTx ) { + .addr =marshal_mcd_addr (&tx->addr), + .access_type = tx->access_type, + .options = tx->options, + .access_width = tx->access_width, + .core_mode = tx->core_mode, + .num_bytes = tx->num_bytes, + .num_bytes_ok = tx->num_bytes_ok, + }; + +if (tx->num_bytes ==0 ) { +return marshal; + } + +g_assert (tx->data); + +uint8List *head = marshal->data; +for (int i = tx->num_bytes -1 ; i >=0 ; i--) { +QAPI_LIST_PREPEND (head, tx->data[i]); + } + marshal->data = head; +return marshal; +} + +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx) +{ +mcd_tx_st unmarshal = { + .addr =unmarshal_mcd_addr (tx->addr), + .access_type = tx->access_type, + .options = tx->options, + .access_width = tx->access_width, + .core_mode = tx->core_mode, + .data =NULL , + .num_bytes = tx->num_bytes, + .num_bytes_ok = tx->num_bytes_ok, + }; + +if (tx->num_bytes ==0 ) { +return unmarshal; + } + + unmarshal.data =g_malloc (tx->num_bytes); +uint8List *current_data = tx->data; +for (uint32_t i =0 ; i < tx->num_bytes; i++) { +g_assert (current_data); + unmarshal.data[i] = current_data->value; + current_data = current_data->next; + } + +return unmarshal; +} + +void free_mcd_tx (mcd_tx_st *tx) +{ +g_free (tx->data); +} + +MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist) +{ +MCDTxlist *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTxlist ) { + .num_tx = txlist->num_tx, + .num_tx_ok = txlist->num_tx_ok, + }; + +if (txlist->num_tx ==0 ) { +return marshal; + } + +g_assert (txlist->tx); + +MCDTxList **tailp = &(marshal->tx); +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +MCDTx *tx =marshal_mcd_tx (txlist->tx + i); +QAPI_LIST_APPEND (tailp, tx); + } + +return marshal; +} + +mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist) +{ +mcd_txlist_st unmarshal = { + .tx =g_malloc (txlist->num_tx *sizeof (mcd_tx_st)), + .num_tx = txlist->num_tx, + .num_tx_ok = txlist->num_tx_ok, + }; + +MCDTxList *current_tx = txlist->tx; +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +g_assert (current_tx); + unmarshal.tx[i] =unmarshal_mcd_tx (current_tx->value); + current_tx = current_tx->next; + } + +return unmarshal; +} + +void free_mcd_txlist (mcd_txlist_st *txlist) +{ +if (!txlist->tx) { +return ; + } + +for (uint32_t i =0 ; i < txlist->num_tx; i++) { +free_mcd_tx (txlist->tx + i); + } + +g_free (txlist->tx); +}
mcd/mcd_qapi.h +14 -0
@@ -37,8 +37,22 @@ MCDRegisterInfo *marshal_mcd_register_info(MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx); + +MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info); +mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr); + +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx); + +mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist); + +void free_mcd_tx (mcd_tx_st *tx); + +void free_mcd_txlist (mcd_txlist_st *txlist); +#endif /* MCD_QAPI_H */
mcd/mcd_server.c +205 -2
216 lines not on this page · raw message
mcd/mcd_stub.c +26 -0
@@ -517,6 +517,32 @@ MCDQryRegMapResult *qmp_mcd_qry_reg_map(uint32_t core_uid,return result; } +MCDExecuteTxlistResult *qmp_mcd_execute_txlist (uint32_t core_uid, +MCDTxlist *txlist, +Error **errp) +{ +MCDExecuteTxlistResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + +mcd_txlist_st txlist_unmarshalled =unmarshal_mcd_txlist (txlist); + + result->return_status =mcd_execute_txlist_f (core, &txlist_unmarshalled); + +if (result->return_status ==MCD_RET_ACT_NONE ) { + result->txlist =marshal_mcd_txlist (&txlist_unmarshalled); + } + +free_mcd_txlist (&txlist_unmarshalled); + g_stub_state.on_error_ask_server = true; +return result; +} +MCDRunResult *qmp_mcd_run (uint32_t core_uid,bool global,Error **errp) {MCDRunResult *result =g_malloc0 (sizeof (*result));
qapi/mcd.json +83 -0
95 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 18/20 mcd: Implement single stepping
In reply to Mario Fleischmanngdbstub: abort gdb_set_stop_cpu when step is issued by mcdserver
--- gdbstub/gdbstub.c | 6 ++- mcd/mcd_server.c | 115 ++++++++++++++++++++++++++++++++++++++++++---- mcd/mcd_stub.c | 18 ++++++++ qapi/mcd.json | 38 ++++++++++++++- 4 files changed, 165 insertions(+), 12 deletions(-)
gdbstub/gdbstub.c +5 -1
@@ -226,6 +226,10 @@ GDBProcess *gdb_get_process(uint32_t pid)static GDBProcess *gdb_get_cpu_process (CPUState *cpu) { +if (!gdbserver_state.processes) { +return NULL ; + } +return gdb_get_process (gdb_get_cpu_pid (cpu)); }
@@ -2287,7 +2291,7 @@ void gdb_set_stop_cpu(CPUState *cpu) {GDBProcess *p =gdb_get_cpu_process (cpu); -if (!p->attached) { +if (!p || !p->attached) {/* * Having a stop CPU corresponding to a process that is not attached * confuses GDB. So we ignore the request.
mcd/mcd_server.c +105 -10
157 lines not on this page · raw message
mcd/mcd_stub.c +18 -0
@@ -577,6 +577,24 @@ MCDStopResult *qmp_mcd_stop(uint32_t core_uid, bool global, Error **errp)return result; } +MCDStepResult *qmp_mcd_step (uint32_t core_uid,bool global,uint32_t step_type, +uint32_t n_steps,Error **errp) +{ +MCDStepResult *result =g_malloc0 (sizeof (*result)); +mcd_core_st *core =NULL ; + + result->return_status =retrieve_open_core (core_uid, &core); +if (result->return_status !=MCD_RET_ACT_NONE ) { + g_stub_state.on_error_ask_server = false; +return result; + } + result->return_status =mcd_step_f (core, global, step_type, n_steps); + + g_stub_state.on_error_ask_server = true; +return result; +} + +MCDSetGlobalResult *qmp_mcd_set_global (uint32_t core_uid,bool enable,Error **errp) {
qapi/mcd.json +37 -1
@@ -1549,6 +1549,43 @@ 'global' : 'bool' }, 'returns': 'MCDStopResult' } + +## +# @MCDStepResult: +# +# Return value of @mcd-step. +# +# @return-status: Return code. +# +# Since: 9.1 +## +{ 'struct': 'MCDStepResult', 'data': { 'return-status': 'uint32' } } + + +## +# @mcd-step: +# +# Function stepping a target core based on the particular step type. +# +# @core-uid: Unique identifier of the open core as returned by @mcd-open-core. +# @global: Set to "TRUE" if all cores of a system shall start +# execution. Otherwise, starting execution of selected core only. +# @step-type: The unit, the stepping of the target core is based on. +# @n-steps: The number of steps, the target core is stepped for. +# +# Returns: @MCDStepResult +# +# Since: 9.1 +## +{ 'command': 'mcd-step', + 'data': { + 'core-uid' : 'uint32', + 'global' : 'bool', + 'step-type': 'uint32', + 'n-steps' : 'uint32' }, + 'returns': 'MCDStepResult' } + + ## # @MCDSetGlobalResult: #
@@ -1580,7 +1617,6 @@ 'enable' : 'bool' }, 'returns': 'MCDSetGlobalResult' } - ## # @MCDQryStateResult: #
Signature · 1 line
2.34.1
PATCH v2 19/20 mcd: Implement trigger control
In reply to Mario FleischmannMCD's trigger API functions support multiple triggers by expecting a pointer to the trigger instance. Each trigger structure reserves the first four bytes for its size. To get the specific structure, read a uint32_t at passed pointer and compare it to the sizes of known trigger structures.
This approach does not work for serialization. The sizes might vary between host machines and pointers cannot be sent over the network anyway.
Therefore, we define a MCDTrig structure which explicitly lists all supported trigger types as optional fields:
* mcd_trig_simple_core_st: mcd-trig-simple-core
* mcd_trig_complex_core_st: mcd-trig-complex-core
--- mcd/mcd_qapi.c | 152 ++++++++++++ mcd/mcd_qapi.h | 21 ++ mcd/mcd_server.c | 586 ++++++++++++++++++++++++++++++++++++++++++++-- mcd/mcd_stub.c | 290 +++++++++++++++++++++++ qapi/mcd.json | 588 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1618 insertions(+), 19 deletions(-)
mcd/mcd_qapi.c +152 -0
@@ -224,6 +224,158 @@ MCDCoreState *marshal_mcd_core_state(const mcd_core_state_st *state)return marshal; } +MCDTrigInfo *marshal_mcd_trig_info (const mcd_trig_info_st *trig_info) +{ +MCDTrigInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigInfo ) { + .type = trig_info->type, + .option = trig_info->option, + .action = trig_info->action, + .trig_number = trig_info->trig_number, + .state_number = trig_info->state_number, + .counter_number = trig_info->counter_number, + .sw_breakpoints = trig_info->sw_breakpoints, + }; + +return marshal; +} + +MCDCtrigInfo *marshal_mcd_ctrig_info (const mcd_ctrig_info_st *trig_info) +{ +MCDCtrigInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDCtrigInfo ) { + .ctrig_id = trig_info->ctrig_id, + .info_str =g_strdup (trig_info->info_str), + }; + +return marshal; +} + +MCDTrigSimpleCore *marshal_mcd_trig_simple_core ( +mcd_trig_simple_core_st const *trig_simple_core) +{ +MCDTrigSimpleCore *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigSimpleCore ) { + .type = trig_simple_core->type, + .option = trig_simple_core->option, + .action = trig_simple_core->action, + .action_param = trig_simple_core->action_param, + .modified = trig_simple_core->modified, + .state_mask = trig_simple_core->state_mask, + .addr_start =marshal_mcd_addr (&trig_simple_core->addr_start), + .addr_range = trig_simple_core->addr_range, + }; + +return marshal; +} + +mcd_trig_simple_core_st unmarshal_mcd_trig_simple_core ( +MCDTrigSimpleCore *trig_simple_core) +{ +mcd_trig_simple_core_st unmarshal = { + .struct_size =sizeof (mcd_trig_simple_core_st), + .type = trig_simple_core->type, + .option = trig_simple_core->option, + .action = trig_simple_core->action, + .action_param = trig_simple_core->action_param, + .modified = trig_simple_core->modified, + .state_mask = trig_simple_core->state_mask, + .addr_start =unmarshal_mcd_addr (trig_simple_core->addr_start), + .addr_range = trig_simple_core->addr_range, + }; + +return unmarshal; +} + +MCDTrigComplexCore *marshal_mcd_trig_complex_core ( +mcd_trig_complex_core_st const *trig_complex_core) +{ +MCDTrigComplexCore *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigComplexCore ) { + .type = trig_complex_core->type, + .option = trig_complex_core->option, + .action = trig_complex_core->action, + .action_param = trig_complex_core->action_param, + .modified = trig_complex_core->modified, + .state_mask = trig_complex_core->state_mask, + .addr_start =marshal_mcd_addr (&trig_complex_core->addr_start), + .addr_range = trig_complex_core->addr_range, + .data_start = trig_complex_core->data_start, + .data_range = trig_complex_core->data_range, + .data_mask = trig_complex_core->data_mask, + .data_size = trig_complex_core->data_size, + .hw_thread_id = trig_complex_core->hw_thread_id, + .sw_thread_id = trig_complex_core->sw_thread_id, + .core_mode_mask = trig_complex_core->core_mode_mask, + }; + +return marshal; +} + +mcd_trig_complex_core_st unmarshal_mcd_trig_complex_core ( +MCDTrigComplexCore *trig_complex_core) +{ +mcd_trig_complex_core_st unmarshal = { + .struct_size =sizeof (mcd_trig_complex_core_st), + .type = trig_complex_core->type, + .option = trig_complex_core->option, + .action = trig_complex_core->action, + .action_param = trig_complex_core->action_param, + .modified = trig_complex_core->modified, + .state_mask = trig_complex_core->state_mask, + .addr_start =unmarshal_mcd_addr (trig_complex_core->addr_start), + .addr_range = trig_complex_core->addr_range, + .data_start = trig_complex_core->data_start, + .data_range = trig_complex_core->data_range, + .data_mask = trig_complex_core->data_mask, + .data_size = trig_complex_core->data_size, + .hw_thread_id = trig_complex_core->hw_thread_id, + .sw_thread_id = trig_complex_core->sw_thread_id, + .core_mode_mask = trig_complex_core->core_mode_mask, + }; + +return unmarshal; +} + +MCDTrigState *marshal_mcd_trig_state (const mcd_trig_state_st *trig_info) +{ +MCDTrigState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigState ) { + .active = trig_info->active, + .captured = trig_info->captured, + .captured_valid = trig_info->captured_valid, + .count_value = trig_info->count_value, + .count_valid = trig_info->count_valid, + }; + +return marshal; +} + +MCDTrigSetState *marshal_mcd_trig_set_state ( +const mcd_trig_set_state_st *trig_state) +{ +MCDTrigSetState *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDTrigSetState ) { + .active = trig_state->active, + .state = trig_state->state, + .state_valid = trig_state->state_valid, + .trig_bus = trig_state->trig_bus, + .trig_bus_valid = trig_state->trig_bus_valid, + .trace = trig_state->trace, + .trace_valid = trig_state->trace_valid, + .analysis = trig_state->analysis, + .analysis_valid = trig_state->analysis_valid, + }; + +return marshal; +} +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx) {MCDTx *marshal =g_malloc0 (sizeof (*marshal));
mcd/mcd_qapi.h +21 -0
@@ -37,6 +37,21 @@ MCDRegisterInfo *marshal_mcd_register_info(MCDCoreState *marshal_mcd_core_state (const mcd_core_state_st *state); +MCDTrigInfo *marshal_mcd_trig_info (const mcd_trig_info_st *trig_info); + +MCDCtrigInfo *marshal_mcd_ctrig_info (const mcd_ctrig_info_st *trig_info); + +MCDTrigSimpleCore *marshal_mcd_trig_simple_core ( +const mcd_trig_simple_core_st *trig_simple_core); + +MCDTrigComplexCore *marshal_mcd_trig_complex_core ( +const mcd_trig_complex_core_st *trig_complex_core); + +MCDTrigState *marshal_mcd_trig_state (const mcd_trig_state_st *trig_info); + +MCDTrigSetState *marshal_mcd_trig_set_state ( +const mcd_trig_set_state_st *trig_state); +MCDTx *marshal_mcd_tx (const mcd_tx_st *tx);MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist);
@@ -47,6 +62,12 @@ mcd_core_con_info_st unmarshal_mcd_core_con_info(MCDCoreConInfo *con_info);mcd_addr_st unmarshal_mcd_addr (MCDAddr *addr); +mcd_trig_simple_core_st unmarshal_mcd_trig_simple_core ( +MCDTrigSimpleCore *trig_simple_core); + +mcd_trig_complex_core_st unmarshal_mcd_trig_complex_core ( +MCDTrigComplexCore *trig_complex_core); +mcd_tx_st unmarshal_mcd_tx (MCDTx *tx);mcd_txlist_st unmarshal_mcd_txlist (MCDTxlist *txlist);
mcd/mcd_server.c +567 -19
711 lines not on this page · raw message
mcd/mcd_stub.c +290 -0
293 lines not on this page · raw message
qapi/mcd.json +588 -0
597 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 20/20 mcd: Implement reset control
In reply to Mario FleischmannProvide a system reset vector and handle it similar to hmp_system_reset
We don't use a QMP related shutdown reason because the mcdserver is implemented independent of the used communication protocol. (In fact, another communication protocol implementation for MCD already exists and can be found at https://gitlab.com/lauterbach/mcdrefsrv)
--- mcd/mcd_qapi.c | 12 +++++ mcd/mcd_qapi.h | 2 + mcd/mcd_server.c | 98 +++++++++++++++++++++++++++++++++-- mcd/mcd_stub.c | 61 ++++++++++++++++++++++ qapi/mcd.json | 129 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 297 insertions(+), 5 deletions(-)
mcd/mcd_qapi.c +12 -0
@@ -491,3 +491,15 @@ void free_mcd_txlist(mcd_txlist_st *txlist)g_free (txlist->tx); } + +MCDRstInfo *marshal_mcd_rst_info (const mcd_rst_info_st *rst_info) +{ +MCDRstInfo *marshal =g_malloc0 (sizeof (*marshal)); + + *marshal = (MCDRstInfo ) { + .class_vector = rst_info->class_vector, + .info_str =g_strdup (rst_info->info_str), + }; + +return marshal; +}
mcd/mcd_qapi.h +2 -0
@@ -56,6 +56,8 @@ MCDTx *marshal_mcd_tx(const mcd_tx_st *tx);MCDTxlist *marshal_mcd_txlist (const mcd_txlist_st *txlist); +MCDRstInfo *marshal_mcd_rst_info (const mcd_rst_info_st *rst_info); +mcd_api_version_st unmarshal_mcd_api_version (MCDAPIVersion *api_version);mcd_core_con_info_st unmarshal_mcd_core_con_info (MCDCoreConInfo *con_info);
mcd/mcd_server.c +93 -5
123 lines not on this page · raw message
mcd/mcd_stub.c +61 -0
67 lines not on this page · raw message
qapi/mcd.json +129 -0
141 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 23 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol.
To keep the overhead of a communication protocol on top of MCD minimal, we follow a remote procedure call approach by using QAPI as an interface definition and transport infrastructure. This way, we can use qapi-gen to take care of generating the infrastructure to dispatch MCD functions and to (un)marshal their arguments and results. Furthermore, qapi-doc and qtest provide good integration into QEMU's documentation and test frameworks.
In v1 of this patch series, the MCD protocol was directly integrated in QMP and the QMP monitor was responsible for dispatching MCD's server stub. This introduced a dependency between QEMU's machine protocol and the MCD debug protocol which is not to be expected. For this reason, v2 introduces a MCD monitor which uses as much of the QMP monitor's framework as possible but keeps the two protocols separate from each other.
Similarly, MCD's test suite uses as much of the qtest framework as is useful for sending JSON commands to the QEMU under test but adds new code where required to prevent dependencies to QMP.
Quoted 4 lines
To enable MCD, configure QEMU with
--enable-mcd.To start the MCD monitor, run QEMU with the
-mcdoption:
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off
-mcd, I presume.
Quoted 5 lines
To run the MCD test suite independently, start
mcd-test:
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-testTo connect from a MCD client, a client stub corresponding to this patch series can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 25 lines · Markus Armbruster
Quoted 23 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol.
To keep the overhead of a communication protocol on top of MCD minimal, we follow a remote procedure call approach by using QAPI as an interface definition and transport infrastructure. This way, we can use qapi-gen to take care of generating the infrastructure to dispatch MCD functions and to (un)marshal their arguments and results. Furthermore, qapi-doc and qtest provide good integration into QEMU's documentation and test frameworks.
In v1 of this patch series, the MCD protocol was directly integrated in QMP and the QMP monitor was responsible for dispatching MCD's server stub. This introduced a dependency between QEMU's machine protocol and the MCD debug protocol which is not to be expected. For this reason, v2 introduces a MCD monitor which uses as much of the QMP monitor's framework as possible but keeps the two protocols separate from each other.
Similarly, MCD's test suite uses as much of the qtest framework as is useful for sending JSON commands to the QEMU under test but adds new code where required to prevent dependencies to QMP.
Quoted 6 lines
Quoted 4 lines
To enable MCD, configure QEMU with
--enable-mcd.To start the MCD monitor, run QEMU with the
-mcdoption:
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=off-mcd, I presume.
Yes, that one slip through.
Quoted 5 lines
Quoted 5 lines
To run the MCD test suite independently, start
mcd-test:
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-testTo connect from a MCD client, a client stub corresponding to this patch series can be found at https://gitlab.com/lauterbach/mcdrefsrv
Quoted 25 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol.
To keep the overhead of a communication protocol on top of MCD minimal, we follow a remote procedure call approach by using QAPI as an interface definition and transport infrastructure. This way, we can use qapi-gen to take care of generating the infrastructure to dispatch MCD functions and to (un)marshal their arguments and results. Furthermore, qapi-doc and qtest provide good integration into QEMU's documentation and test frameworks.
In v1 of this patch series, the MCD protocol was directly integrated in QMP and the QMP monitor was responsible for dispatching MCD's server stub. This introduced a dependency between QEMU's machine protocol and the MCD debug protocol which is not to be expected. For this reason, v2 introduces a MCD monitor which uses as much of the QMP monitor's framework as possible but keeps the two protocols separate from each other.
Similarly, MCD's test suite uses as much of the qtest framework as is useful for sending JSON commands to the QEMU under test but adds new code where required to prevent dependencies to QMP.To enable MCD, configure QEMU with
--enable-mcd.
Quoted 8 lines
To start the MCD monitor, run QEMU with the
-mcdoption:
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=offTo run the MCD test suite independently, start
mcd-test:
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-testTo connect from a MCD client, a client stub corresponding to this patch series can be found at https://gitlab.com/lauterbach/mcdrefsrv
I'm okay with the general approach.
[...]
Quoted 8 lines
MAINTAINERS | 9 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 65 + gdbstub/gdbstub.c | 15 +- include/exec/gdbstub.h | 18 +- include/exec/mcdstub.h | 18 + mcd/mcd_api.h | 3963 +++++++++++++++++++++++++++++++++ mcd/mcd_monitor.c | 90 +
Quoted 8 lines
mcd/mcd_qapi.c | 505 +++++ mcd/mcd_qapi.h | 81 + mcd/mcd_server.c | 2274 +++++++++++++++++++ mcd/mcd_stub.c | 988 ++++++++ mcd/meson.build | 60 + meson.build | 5 + meson_options.txt | 3 + qapi/mcd.json | 2366 ++++++++++++++++++++
The schema is too big for me to review in detail. I understand it's designed to mirror mcd/mcd_api.h closely, so review would be limited to checking the way you mirror is sane. I doubt that would be a good use of my time, but if you'd like advice on any non-trivial parts, just ask.
Some formatting nits caught my eye. docs/devel/qapi-code-gen.rst section "Documentation markup":
For legibility, wrap text paragraphs so every line is at most 70 characters long.
Separate sentences with two spaces.
I recommend to read the entire section.
[...]
Quoted 57 lines · Markus Armbruster
Quoted 25 lines · Mario Fleischmann
This patch series introduces support for the Multi-Core Debug (MCD) API, a commonly used debug interface by emulators. The MCD API, defined through a header file, consists of 54 functions for implementing debug and trace. However, since it is a header-file-only interface, MCD does not specify a communication protocol.
To keep the overhead of a communication protocol on top of MCD minimal, we follow a remote procedure call approach by using QAPI as an interface definition and transport infrastructure. This way, we can use qapi-gen to take care of generating the infrastructure to dispatch MCD functions and to (un)marshal their arguments and results. Furthermore, qapi-doc and qtest provide good integration into QEMU's documentation and test frameworks.
In v1 of this patch series, the MCD protocol was directly integrated in QMP and the QMP monitor was responsible for dispatching MCD's server stub. This introduced a dependency between QEMU's machine protocol and the MCD debug protocol which is not to be expected. For this reason, v2 introduces a MCD monitor which uses as much of the QMP monitor's framework as possible but keeps the two protocols separate from each other.
Similarly, MCD's test suite uses as much of the qtest framework as is useful for sending JSON commands to the QEMU under test but adds new code where required to prevent dependencies to QMP.To enable MCD, configure QEMU with
--enable-mcd.Quoted 8 lines
To start the MCD monitor, run QEMU with the
-mcdoption:
qemu-system-<arch> [options] -qmp tcp::1235,server=on,wait=offTo run the MCD test suite independently, start
mcd-test:
V=1 QTEST_QEMU_BINARY="./qemu-system-<arch> [options]" tests/qtest/mcd-testTo connect from a MCD client, a client stub corresponding to this patch series can be found at https://gitlab.com/lauterbach/mcdrefsrv
I'm okay with the general approach.
[...]
Quoted 8 lines
MAINTAINERS | 9 + docs/interop/index.rst | 1 + docs/interop/mcd.rst | 65 + gdbstub/gdbstub.c | 15 +- include/exec/gdbstub.h | 18 +- include/exec/mcdstub.h | 18 + mcd/mcd_api.h | 3963 +++++++++++++++++++++++++++++++++ mcd/mcd_monitor.c | 90 +Quoted 8 lines
mcd/mcd_qapi.c | 505 +++++ mcd/mcd_qapi.h | 81 + mcd/mcd_server.c | 2274 +++++++++++++++++++ mcd/mcd_stub.c | 988 ++++++++ mcd/meson.build | 60 + meson.build | 5 + meson_options.txt | 3 + qapi/mcd.json | 2366 ++++++++++++++++++++
Quoted 4 lines
The schema is too big for me to review in detail. I understand it's designed to mirror
mcd/mcd_api.hclosely, so review would be limited to checking the way you mirror is sane. I doubt that would be a good use of my time, but if you'd like advice on any non-trivial parts, just ask.
Let's do it this way: As explained in
"Re: [PATCH v2 07/20] mcd: Implement target initialization API" <[email protected]>
there are reasons to deviate from mcd/mcd_api.h in mcd/qapi-schema.json. In v3, I can highlight those changes briefly in the relevant commit messages. That way, you have the option to focus on the non-trivial parts.
Quoted 9 lines
Some formatting nits caught my eye.
docs/devel/qapi-code-gen.rstsection "Documentation markup":For legibility, wrap text paragraphs so every line is at most 70 characters long.
Separate sentences with two spaces.
I recommend to read the entire section.
Will do!
One more thing just caught my eye: every command starts with "mcd-", and every type starts with "MCD". This makes the index less useful than it could be. Not a show-stopper, but perhaps you'd like to consider dropping the command prefix.