@samitouri / QOSamiQemu / commits / 0bd6562fc3

Guard HMP command implementations with CONFIG_HMP

Add #ifdef CONFIG_HMP around all hmp_* function implementations and their HMP-only helpers across subsystems. This covers monitor_register_hmp* callers, hmp_info_* handlers, and HMP-only helper functions like slirp_lookup. To link succesfully, use empty cmds tables in hmp-cmds.c (to be removed once meson build-sys is updated with !hmp support later in the series) Reviewed-by: Jason J. Herne <jjherne@linux.ibm.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-41-9227de146347@redhat.com>

Marc-André Lureau committed Aug 28, 2026 at 16:04 UTC 0bd6562fc3e54d6d96db1f7bc5188da512249349
27 files changed +82 -1
accel/accel-system.c
+2
@@ -109,7 +109,9 @@ void accel_init_ops_interfaces(AccelClass *ac)
109
110 static void accel_ops_class_init(ObjectClass *oc, const void *data)
111 {
112 +#ifdef CONFIG_HMP
113 monitor_register_hmp_info_hrt("accel", qmp_x_accel_stats);
114 +#endif
115 }
116
117 static const TypeInfo accel_ops_type_info = {
accel/tcg/monitor.c
+2
@@ -30,9 +30,11 @@ HumanReadableText *qmp_x_query_jit(Error **errp)
30 return human_readable_text_from_str(buf);
31 }
32
33 +#ifdef CONFIG_HMP
34 static void hmp_tcg_register(void)
35 {
36 monitor_register_hmp_info_hrt("jit", qmp_x_query_jit);
37 }
38
39 type_init(hmp_tcg_register);
40 +#endif
hw/i386/kvm/xen-stubs.c
+2
@@ -40,6 +40,7 @@ void xen_primary_console_set_be_port(uint16_t port)
40 {
41 }
42
43 +#ifdef CONFIG_HMP
44 void hmp_xen_event_list(MonitorHMP *hmp, const QDict *qdict)
45 {
46 monitor_hmp_printf(hmp, "XEN emulation is not available in this QEMU\n");
@@ -49,3 +50,4 @@ void hmp_xen_event_inject(MonitorHMP *hmp, const QDict *qdict)
50 {
51 monitor_hmp_printf(hmp, "XEN emulation is not available in this QEMU\n");
52 }
53 +#endif
hw/i386/kvm/xen_evtchn.c
+3
@@ -2344,6 +2344,7 @@ void qmp_xen_event_inject(uint32_t port, Error **errp)
2344 }
2345 }
2346
2347 +#ifdef CONFIG_HMP
2348 void hmp_xen_event_list(MonitorHMP *hmp, const QDict *qdict)
2349 {
2350 EvtchnInfoList *iter, *info_list;
@@ -2391,3 +2392,5 @@ void hmp_xen_event_inject(MonitorHMP *hmp, const QDict *qdict)
2392 monitor_hmp_printf(hmp, "Delivered port %d\n", port);
2393 }
2394 }
2395 +
2396 +#endif
hw/i386/sgx.c
+2
@@ -234,6 +234,7 @@ SgxInfo *qmp_query_sgx(Error **errp)
234 return info;
235 }
236
237 +#ifdef CONFIG_HMP
238 void hmp_info_sgx(MonitorHMP *hmp, const QDict *qdict)
239 {
240 Error *err = NULL;
@@ -265,6 +266,7 @@ void hmp_info_sgx(MonitorHMP *hmp, const QDict *qdict)
266 monitor_hmp_printf(hmp, "total size=%" PRIu64 "\n",
267 size);
268 }
269 +#endif
270
271 bool check_sgx_support(void)
272 {
hw/misc/mos6522-stub.c
+2
@@ -10,7 +10,9 @@
10 #include "monitor/monitor.h"
11 #include "monitor/hmp.h"
12
13 +#ifdef CONFIG_HMP
14 void hmp_info_via(MonitorHMP *hmp, const QDict *qdict)
15 {
16 monitor_hmp_printf(hmp, "MOS6522 VIA is not available in this QEMU\n");
17 }
18 +#endif
hw/misc/mos6522.c
+2
@@ -497,6 +497,7 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
497 }
498 }
499
500 +#ifdef CONFIG_HMP
501 static int qmp_x_query_via_foreach(Object *obj, void *opaque)
502 {
503 GString *buf = opaque;
@@ -597,6 +598,7 @@ void hmp_info_via(MonitorHMP *hmp, const QDict *qdict)
598 }
599 monitor_puts(mon, info->human_readable_text);
600 }
601 +#endif /* CONFIG_HMP */
602
603 static const MemoryRegionOps mos6522_ops = {
604 .read = mos6522_read,
hw/pci/pci-stub.c
+2
@@ -34,6 +34,7 @@ PciInfoList *qmp_query_pci(Error **errp)
34 return NULL;
35 }
36
37 +#ifdef CONFIG_HMP
38 void hmp_info_pci(MonitorHMP *hmp, const QDict *qdict)
39 {
40 }
@@ -42,6 +43,7 @@ void hmp_pcie_aer_inject_error(MonitorHMP *hmp, const QDict *qdict)
43 {
44 monitor_hmp_printf(hmp, "PCI devices not supported\n");
45 }
46 +#endif
47
48 /* kvm-all wants this */
49 MSIMessage pci_get_msi_message(PCIDevice *dev, int vector)
hw/s390x/s390-skeys.c
+2
@@ -104,6 +104,7 @@ static void write_keys(FILE *f, uint8_t *keys, uint64_t startgfn,
104 }
105 }
106
107 +#ifdef CONFIG_HMP
108 void hmp_info_skeys(MonitorHMP *hmp, const QDict *qdict)
109 {
110 S390SKeysState *ss = s390_get_skeys_device();
@@ -144,6 +145,7 @@ void hmp_dump_skeys(MonitorHMP *hmp, const QDict *qdict)
145 error_report_err(err);
146 }
147 }
148 +#endif
149
150 void s390_qmp_dump_skeys(const char *filename, Error **errp)
151 {
hw/s390x/s390-stattrib.c
+4
@@ -32,6 +32,7 @@
32 #define STATTR_FLAG_ERROR 0x04ULL
33 #define STATTR_FLAG_DONE 0x08ULL
34
35 +#ifdef CONFIG_HMP
36 static S390StAttribState *s390_get_stattrib_device(void)
37 {
38 S390StAttribState *sas;
@@ -40,6 +41,7 @@ static S390StAttribState *s390_get_stattrib_device(void)
41 assert(sas);
42 return sas;
43 }
44 +#endif
45
46 void s390_stattrib_init(void)
47 {
@@ -59,6 +61,7 @@ void s390_stattrib_init(void)
61
62 /* Console commands: */
63
64 +#ifdef CONFIG_HMP
65 void hmp_migrationmode(MonitorHMP *hmp, const QDict *qdict)
66 {
67 S390StAttribState *sas = s390_get_stattrib_device();
@@ -110,6 +113,7 @@ void hmp_info_cmma(MonitorHMP *hmp, const QDict *qdict)
113 out:
114 g_free(vals);
115 }
116 +#endif
117
118 /* Migration support: */
119
hw/uefi/ovmf-log.c
+2
@@ -256,6 +256,7 @@ FirmwareLog *qmp_query_firmware_log(bool have_max_size, uint64_t max_size,
256 return ret;
257 }
258
259 +#ifdef CONFIG_HMP
260 void hmp_info_firmware_log(MonitorHMP *hmp, const QDict *qdict)
261 {
262 g_autofree gchar *log_esc = NULL;
@@ -284,3 +285,4 @@ void hmp_info_firmware_log(MonitorHMP *hmp, const QDict *qdict)
285 log_esc = g_strescape((gchar *)log_out, "\r\n");
286 monitor_hmp_printf(hmp, "%s\n", log_esc);
287 }
288 +#endif
hw/usb/host-libusb.c
+6
@@ -184,6 +184,7 @@ static void usb_host_attach_kernel(USBHostDevice *s);
184 # define HAVE_SUPER_PLUS 1
185 #endif
186
187 +#ifdef CONFIG_HMP
188 static const char *speed_name[] = {
189 [LIBUSB_SPEED_UNKNOWN] = "?",
190 [LIBUSB_SPEED_LOW] = "1.5",
@@ -194,6 +195,7 @@ static const char *speed_name[] = {
195 [LIBUSB_SPEED_SUPER_PLUS] = "5000+",
196 #endif
197 };
198 +#endif
199
200 static const unsigned int speed_map[] = {
201 [LIBUSB_SPEED_LOW] = USB_SPEED_LOW,
@@ -1815,7 +1817,9 @@ module_kconfig(USB);
1817 static void usb_host_register_types(void)
1818 {
1819 type_register_static(&usb_host_dev_info);
1820 +#ifdef CONFIG_HMP
1821 monitor_register_hmp("usbhost", true, hmp_info_usbhost);
1822 +#endif
1823 }
1824
1825 type_init(usb_host_register_types)
@@ -1920,6 +1924,7 @@ static void usb_host_auto_check(void *unused)
1924 timer_mod(usb_auto_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 2000);
1925 }
1926
1927 +#ifdef CONFIG_HMP
1928 void hmp_info_usbhost(MonitorHMP *hmp, const QDict *qdict)
1929 {
1930 libusb_device **devs = NULL;
@@ -1963,3 +1968,4 @@ void hmp_info_usbhost(MonitorHMP *hmp, const QDict *qdict)
1968 }
1969 libusb_free_device_list(devs, 1);
1970 }
1971 +#endif
migration/dirtyrate.c
+2
@@ -856,6 +856,7 @@ struct DirtyRateInfo *qmp_query_dirty_rate(bool has_calc_time_unit,
856 has_calc_time_unit ? calc_time_unit : TIME_UNIT_SECOND);
857 }
858
859 +#ifdef CONFIG_HMP
860 void hmp_info_dirty_rate(MonitorHMP *hmp, const QDict *qdict)
861 {
862 DirtyRateInfo *info = query_dirty_rate_info(TIME_UNIT_SECOND);
@@ -932,3 +933,4 @@ void hmp_calc_dirty_rate(MonitorHMP *hmp, const QDict *qdict)
933 " seconds\n", sec);
934 monitor_hmp_printf(hmp, "[Please use 'info dirty_rate' to check results]\n");
935 }
936 +#endif
monitor/hmp-cmds.c
+5
@@ -42,6 +42,7 @@
42 #include "disas/disas.h"
43
44 /* Please update hmp-commands.hx when adding or changing commands */
45 +#ifdef CONFIG_HMP
46 static HMPCommand hmp_info_cmds[] = {
47 #include "hmp-commands-info.h"
48 { NULL, NULL, },
@@ -52,6 +53,10 @@ static HMPCommand hmp_cmds[] = {
53 #include "hmp-commands.h"
54 { NULL, NULL, },
55 };
56 +#else
57 +static HMPCommand hmp_info_cmds[] = { { NULL, NULL, }, };
58 +static HMPCommand hmp_cmds[] = { { NULL, NULL, }, };
59 +#endif
60
61 HMPCommand *hmp_cmds_for_target(bool info_command)
62 {
net/slirp.c
+6 -1
@@ -711,6 +711,7 @@ error:
711 return -1;
712 }
713
714 +#ifdef CONFIG_HMP
715 static SlirpState *slirp_lookup(MonitorHMP *hmp, const char *id)
716 {
717 if (id) {
@@ -801,6 +802,7 @@ void hmp_hostfwd_remove(MonitorHMP *hmp, const QDict *qdict)
802 fail_syntax:
803 monitor_hmp_printf(hmp, "invalid format\n");
804 }
805 +#endif
806
807 static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
808 {
@@ -957,6 +959,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str, Error **errp)
959 return -1;
960 }
961
962 +#ifdef CONFIG_HMP
963 void hmp_hostfwd_add(MonitorHMP *hmp, const QDict *qdict)
964 {
965 const char *redir_str;
@@ -977,8 +980,8 @@ void hmp_hostfwd_add(MonitorHMP *hmp, const QDict *qdict)
980 error_report_err(err);
981 }
982 }
980 -
983 }
984 +#endif
985
986 #if defined(CONFIG_SMBD_COMMAND)
987
@@ -1224,6 +1227,7 @@ UsernetInfoList *qmp_x_query_usernet(Error **errp)
1227 return head;
1228 }
1229
1230 +#ifdef CONFIG_HMP
1231 void hmp_info_usernet(MonitorHMP *hmp, const QDict *qdict)
1232 {
1233 g_autoptr(UsernetInfoList) list = NULL;
@@ -1237,6 +1241,7 @@ void hmp_info_usernet(MonitorHMP *hmp, const QDict *qdict)
1241 ui->hub_name, ui->info);
1242 }
1243 }
1244 +#endif
1245
1246 static void
1247 net_init_slirp_configs_host(const NetdevUserHostForwardList *fwd)
replay/replay-debugging.c
+8
@@ -31,6 +31,7 @@ bool replay_running_debug(void)
31 return replay_is_debugging;
32 }
33
34 +#ifdef CONFIG_HMP
35 void hmp_info_replay(MonitorHMP *hmp, const QDict *qdict)
36 {
37 if (replay_mode == REPLAY_MODE_NONE) {
@@ -42,6 +43,7 @@ void hmp_info_replay(MonitorHMP *hmp, const QDict *qdict)
43 replay_get_filename(), replay_get_current_icount());
44 }
45 }
46 +#endif
47
48 ReplayInfo *qmp_query_replay(Error **errp)
49 {
@@ -103,6 +105,7 @@ void qmp_replay_break(int64_t icount, Error **errp)
105 }
106 }
107
108 +#ifdef CONFIG_HMP
109 void hmp_replay_break(MonitorHMP *hmp, const QDict *qdict)
110 {
111 int64_t icount = qdict_get_try_int(qdict, "icount", -1LL);
@@ -114,6 +117,7 @@ void hmp_replay_break(MonitorHMP *hmp, const QDict *qdict)
117 return;
118 }
119 }
120 +#endif
121
122 void qmp_replay_delete_break(Error **errp)
123 {
@@ -124,6 +128,7 @@ void qmp_replay_delete_break(Error **errp)
128 }
129 }
130
131 +#ifdef CONFIG_HMP
132 void hmp_replay_delete_break(MonitorHMP *hmp, const QDict *qdict)
133 {
134 Error *err = NULL;
@@ -134,6 +139,7 @@ void hmp_replay_delete_break(MonitorHMP *hmp, const QDict *qdict)
139 return;
140 }
141 }
142 +#endif
143
144 static char *replay_find_nearest_snapshot(int64_t icount,
145 int64_t *snapshot_icount)
@@ -209,6 +215,7 @@ void qmp_replay_seek(int64_t icount, Error **errp)
215 replay_seek(icount, replay_stop_vm, errp);
216 }
217
218 +#ifdef CONFIG_HMP
219 void hmp_replay_seek(MonitorHMP *hmp, const QDict *qdict)
220 {
221 int64_t icount = qdict_get_try_int(qdict, "icount", -1LL);
@@ -220,6 +227,7 @@ void hmp_replay_seek(MonitorHMP *hmp, const QDict *qdict)
227 return;
228 }
229 }
230 +#endif
231
232 static void replay_stop_vm_debug(void *opaque)
233 {
replay/stubs-system.c
+6
@@ -63,22 +63,28 @@ void replay_vmstate_init(void)
63 #include "qapi/error.h"
64 #include "qemu/error-report.h"
65
66 +#ifdef CONFIG_HMP
67 void hmp_info_replay(MonitorHMP *hmp, const QDict *qdict)
68 {
69 error_report("replay support not available");
70 }
71 +
72 void hmp_replay_break(MonitorHMP *hmp, const QDict *qdict)
73 {
74 error_report("replay support not available");
75 }
76 +
77 void hmp_replay_delete_break(MonitorHMP *hmp, const QDict *qdict)
78 {
79 error_report("replay support not available");
80 }
81 +
82 void hmp_replay_seek(MonitorHMP *hmp, const QDict *qdict)
83 {
84 error_report("replay support not available");
85 }
86 +#endif
87 +
88 ReplayInfo *qmp_query_replay(Error **errp)
89 {
90 error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
system/qdev-monitor.c
+4
@@ -763,6 +763,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
763 return ret;
764 }
765
766 +#ifdef CONFIG_HMP
767 #define qdev_printf(fmt, ...) \
768 monitor_hmp_printf(hmp, "%*s" fmt, indent, "", ## __VA_ARGS__)
769
@@ -865,6 +866,7 @@ void hmp_info_qdm(MonitorHMP *hmp, const QDict *qdict)
866 {
867 qdev_print_devinfos(true);
868 }
869 +#endif /* CONFIG_HMP */
870
871 void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
872 {
@@ -1002,6 +1004,7 @@ void qmp_device_sync_config(const char *id, Error **errp)
1004 qdev_sync_config(dev, errp);
1005 }
1006
1007 +#ifdef CONFIG_HMP
1008 void hmp_device_add(MonitorHMP *hmp, const QDict *qdict)
1009 {
1010 Error *err = NULL;
@@ -1044,6 +1047,7 @@ void hmp_device_del(MonitorHMP *hmp, const QDict *qdict)
1047 qmp_device_del(id, &err);
1048 hmp_handle_error(hmp, err);
1049 }
1050 +#endif
1051
1052 void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
1053 {
target/i386/cpu-apic.c
+2
@@ -83,6 +83,7 @@ void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
83 }
84 }
85
86 +#ifdef CONFIG_HMP
87 void hmp_info_local_apic(MonitorHMP *hmp, const QDict *qdict)
88 {
89 CPUState *cs;
@@ -105,3 +106,4 @@ void hmp_info_local_apic(MonitorHMP *hmp, const QDict *qdict)
106 }
107 x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU);
108 }
109 +#endif
target/i386/monitor.c
+3
@@ -31,6 +31,8 @@
31 #include "qapi/qapi-commands-misc.h"
32 #include "system/memory.h"
33
34 +#ifdef CONFIG_HMP
35 +
36 /* Perform linear address sign extension */
37 static hwaddr addr_canonical(CPUArchState *env, hwaddr addr)
38 {
@@ -595,3 +597,4 @@ void hmp_mce(MonitorHMP *hmp, const QDict *qdict)
597 }
598 hmp_handle_error(hmp, err);
599 }
600 +#endif
target/i386/sev.c
+2
@@ -784,6 +784,7 @@ SevInfo *qmp_query_sev(Error **errp)
784 return info;
785 }
786
787 +#ifdef CONFIG_HMP
788 void hmp_info_sev(MonitorHMP *hmp, const QDict *qdict)
789 {
790 SevInfo *info = sev_get_info();
@@ -817,6 +818,7 @@ void hmp_info_sev(MonitorHMP *hmp, const QDict *qdict)
818 out:
819 qapi_free_SevInfo(info);
820 }
821 +#endif
822
823 static int
824 sev_get_pdh_info(int fd, guchar **pdh, size_t *pdh_len, guchar **cert_chain,
target/m68k/monitor.c
+2
@@ -10,6 +10,7 @@
10 #include "monitor/hmp.h"
11 #include "monitor/monitor.h"
12
13 +#ifdef CONFIG_HMP
14 void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
15 {
16 CPUArchState *env1 = monitor_hmp_get_cpu_env(hmp);
@@ -21,3 +22,4 @@ void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
22
23 dump_mmu(env1);
24 }
25 +#endif
target/ppc/monitor.c
+2
@@ -11,6 +11,7 @@
11 #include "monitor/hmp.h"
12 #include "cpu.h"
13
14 +#ifdef CONFIG_HMP
15 void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
16 {
17 CPUArchState *env1 = monitor_hmp_get_cpu_env(hmp);
@@ -21,3 +22,4 @@ void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
22 }
23 dump_mmu(env1);
24 }
25 +#endif
target/riscv/monitor.c
+3
@@ -39,6 +39,8 @@
39 #define PTE_HEADER_DELIMITER "-------- ---------------- -------- -------\n"
40 #endif
41
42 +#ifdef CONFIG_HMP
43 +
44 /* Perform linear address sign extension */
45 static target_ulong addr_canonical(int va_bits, target_ulong addr)
46 {
@@ -244,6 +246,7 @@ void hmp_info_mem(MonitorHMP *hmp, const QDict *qdict)
246
247 mem_info_svxx(hmp, env);
248 }
249 +#endif /* CONFIG_HMP */
250
251 #ifdef CONFIG_TCG
252 static bool reg_is_ulong_integer(CPURISCVState *env, const char *name,
target/sh4/monitor.c
+2
@@ -26,6 +26,7 @@
26 #include "monitor/monitor.h"
27 #include "monitor/hmp.h"
28
29 +#ifdef CONFIG_HMP
30 static void print_tlb(MonitorHMP *hmp, int idx, tlb_t *tlb)
31 {
32 monitor_hmp_printf(hmp, " tlb%i:\t"
@@ -55,3 +56,4 @@ void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
56 for (i = 0 ; i < UTLB_SIZE ; i++)
57 print_tlb(hmp, i, &env->utlb[i]);
58 }
59 +#endif
target/sparc/monitor.c
+2
@@ -27,6 +27,7 @@
27 #include "monitor/hmp.h"
28
29
30 +#ifdef CONFIG_HMP
31 void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
32 {
33 CPUArchState *env1 = monitor_hmp_get_cpu_env(hmp);
@@ -37,3 +38,4 @@ void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
38 }
39 dump_mmu(env1);
40 }
41 +#endif
target/xtensa/monitor.c
+2
@@ -26,6 +26,7 @@
26 #include "monitor/monitor.h"
27 #include "monitor/hmp.h"
28
29 +#ifdef CONFIG_HMP
30 void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
31 {
32 CPUArchState *env1 = monitor_hmp_get_cpu_env(hmp);
@@ -36,3 +37,4 @@ void hmp_info_tlb(MonitorHMP *hmp, const QDict *qdict)
37 }
38 dump_mmu(env1);
39 }
40 +#endif