[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
From: |
Josh Kunz |
Subject: |
[PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging |
Date: |
Mon, 13 Jan 2020 19:01:35 -0800 |
This change introduces a new logging mask "LOG_USER", which is used for
masking general user-mode logging. This change also switches all non-strace
uses of `gemu_log' in linux-user/ to use `qemu_log_mask(LOG_USER, ...)'
instead. This allows the user to easily log to a file, and to mask out
these log messages if they desire.
Signed-off-by: Josh Kunz <address@hidden>
---
include/qemu/log.h | 2 ++
linux-user/arm/cpu_loop.c | 5 ++--
linux-user/fd-trans.c | 55 +++++++++++++++++++++++++--------------
linux-user/main.c | 24 +++++++++++++++++
linux-user/syscall.c | 30 ++++++++++++---------
linux-user/vm86.c | 3 ++-
util/log.c | 3 +++
7 files changed, 86 insertions(+), 36 deletions(-)
diff --git a/include/qemu/log.h b/include/qemu/log.h
index e0f4e40628..503e4f88d5 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -62,6 +62,8 @@ static inline bool qemu_log_separate(void)
#define CPU_LOG_TB_OP_IND (1 << 16)
#define CPU_LOG_TB_FPU (1 << 17)
#define CPU_LOG_PLUGIN (1 << 18)
+/* LOG_USER is used for some informational user-mode logging. */
+#define LOG_USER (1 << 19)
/* Lock output for a series of related logs. Since this is not needed
* for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we
diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index 1fae90c6df..830ba8f138 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -349,8 +349,9 @@ void cpu_loop(CPUARMState *env)
env->regs[0] = cpu_get_tls(env);
break;
default:
- gemu_log("qemu: Unsupported ARM syscall: 0x%x\n",
- n);
+ qemu_log_mask(LOG_USER,
+ "qemu: Unsupported ARM syscall:
0x%x\n",
+ n);
env->regs[0] = -TARGET_ENOSYS;
break;
}
diff --git a/linux-user/fd-trans.c b/linux-user/fd-trans.c
index 9b92386abf..a5324b8a06 100644
--- a/linux-user/fd-trans.c
+++ b/linux-user/fd-trans.c
@@ -514,7 +514,8 @@ static abi_long host_to_target_data_bridge_nlattr(struct
nlattr *nlattr,
u32[1] = tswap32(u32[1]); /* optmask */
break;
default:
- gemu_log("Unknown QEMU_IFLA_BR type %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown QEMU_IFLA_BR type %d\n",
+ nlattr->nla_type);
break;
}
return 0;
@@ -577,7 +578,8 @@ static abi_long
host_to_target_slave_data_bridge_nlattr(struct nlattr *nlattr,
case QEMU_IFLA_BRPORT_BRIDGE_ID:
break;
default:
- gemu_log("Unknown QEMU_IFLA_BRPORT type %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown QEMU_IFLA_BRPORT type %d\n",
+ nlattr->nla_type);
break;
}
return 0;
@@ -605,7 +607,8 @@ static abi_long host_to_target_data_tun_nlattr(struct
nlattr *nlattr,
*u32 = tswap32(*u32);
break;
default:
- gemu_log("Unknown QEMU_IFLA_TUN type %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown QEMU_IFLA_TUN type %d\n",
+ nlattr->nla_type);
break;
}
return 0;
@@ -652,7 +655,8 @@ static abi_long host_to_target_data_linkinfo_nlattr(struct
nlattr *nlattr,
NULL,
host_to_target_data_tun_nlattr);
} else {
- gemu_log("Unknown QEMU_IFLA_INFO_KIND %s\n", li_context->name);
+ qemu_log_mask(LOG_USER, "Unknown QEMU_IFLA_INFO_KIND %s\n",
+ li_context->name);
}
break;
case QEMU_IFLA_INFO_SLAVE_DATA:
@@ -663,12 +667,13 @@ static abi_long
host_to_target_data_linkinfo_nlattr(struct nlattr *nlattr,
NULL,
host_to_target_slave_data_bridge_nlattr);
} else {
- gemu_log("Unknown QEMU_IFLA_INFO_SLAVE_KIND %s\n",
+ qemu_log_mask(LOG_USER, "Unknown QEMU_IFLA_INFO_SLAVE_KIND %s\n",
li_context->slave_name);
}
break;
default:
- gemu_log("Unknown host QEMU_IFLA_INFO type: %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown host QEMU_IFLA_INFO type: %d\n",
+ nlattr->nla_type);
break;
}
@@ -690,7 +695,8 @@ static abi_long host_to_target_data_inet_nlattr(struct
nlattr *nlattr,
}
break;
default:
- gemu_log("Unknown host AF_INET type: %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown host AF_INET type: %d\n",
+ nlattr->nla_type);
}
return 0;
}
@@ -741,7 +747,8 @@ static abi_long host_to_target_data_inet6_nlattr(struct
nlattr *nlattr,
}
break;
default:
- gemu_log("Unknown host AF_INET6 type: %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown host AF_INET6 type: %d\n",
+ nlattr->nla_type);
}
return 0;
}
@@ -759,7 +766,8 @@ static abi_long host_to_target_data_spec_nlattr(struct
nlattr *nlattr,
NULL,
host_to_target_data_inet6_nlattr);
default:
- gemu_log("Unknown host AF_SPEC type: %d\n", nlattr->nla_type);
+ qemu_log_mask(LOG_USER, "Unknown host AF_SPEC type: %d\n",
+ nlattr->nla_type);
break;
}
return 0;
@@ -780,7 +788,8 @@ static abi_long host_to_target_data_xdp_nlattr(struct
nlattr *nlattr,
*u32 = tswap32(*u32);
break;
default:
- gemu_log("Unknown host XDP type: %d\n", nlattr->nla_type);
+ qemu_log_mask(
+ LOG_USER, "Unknown host XDP type: %d\n", nlattr->nla_type);
break;
}
return 0;
@@ -920,7 +929,8 @@ static abi_long host_to_target_data_link_rtattr(struct
rtattr *rtattr)
NULL,
host_to_target_data_xdp_nlattr);
default:
- gemu_log("Unknown host QEMU_IFLA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(LOG_USER, "Unknown host QEMU_IFLA type: %d\n",
+ rtattr->rta_type);
break;
}
return 0;
@@ -954,7 +964,8 @@ static abi_long host_to_target_data_addr_rtattr(struct
rtattr *rtattr)
ci->tstamp = tswap32(ci->tstamp);
break;
default:
- gemu_log("Unknown host IFA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(
+ LOG_USER, "Unknown host IFA type: %d\n", rtattr->rta_type);
break;
}
return 0;
@@ -996,7 +1007,8 @@ static abi_long host_to_target_data_route_rtattr(struct
rtattr *rtattr)
#endif
break;
default:
- gemu_log("Unknown host RTA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(
+ LOG_USER, "Unknown host RTA type: %d\n", rtattr->rta_type);
break;
}
return 0;
@@ -1111,7 +1123,8 @@ static abi_long target_to_host_data_link_rtattr(struct
rtattr *rtattr)
{
switch (rtattr->rta_type) {
default:
- gemu_log("Unknown target QEMU_IFLA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(LOG_USER, "Unknown target QEMU_IFLA type: %d\n",
+ rtattr->rta_type);
break;
}
return 0;
@@ -1125,7 +1138,8 @@ static abi_long target_to_host_data_addr_rtattr(struct
rtattr *rtattr)
case IFA_ADDRESS:
break;
default:
- gemu_log("Unknown target IFA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(LOG_USER, "Unknown target IFA type: %d\n",
+ rtattr->rta_type);
break;
}
return 0;
@@ -1147,7 +1161,8 @@ static abi_long target_to_host_data_route_rtattr(struct
rtattr *rtattr)
*u32 = tswap32(*u32);
break;
default:
- gemu_log("Unknown target RTA type: %d\n", rtattr->rta_type);
+ qemu_log_mask(LOG_USER, "Unknown target RTA type: %d\n",
+ rtattr->rta_type);
break;
}
return 0;
@@ -1232,8 +1247,8 @@ static abi_long host_to_target_data_audit(struct nlmsghdr
*nlh)
{
switch (nlh->nlmsg_type) {
default:
- gemu_log("Unknown host audit message type %d\n",
- nlh->nlmsg_type);
+ qemu_log_mask(LOG_USER, "Unknown host audit message type %d\n",
+ nlh->nlmsg_type);
return -TARGET_EINVAL;
}
return 0;
@@ -1253,8 +1268,8 @@ static abi_long target_to_host_data_audit(struct nlmsghdr
*nlh)
case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
break;
default:
- gemu_log("Unknown target audit message type %d\n",
- nlh->nlmsg_type);
+ qemu_log_mask(LOG_USER, "Unknown target audit message type %d\n",
+ nlh->nlmsg_type);
return -TARGET_EINVAL;
}
diff --git a/linux-user/main.c b/linux-user/main.c
index 8718d03ee2..c4f3de77db 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -60,6 +60,9 @@ unsigned long mmap_min_addr;
unsigned long guest_base;
int have_guest_base;
+/* Used to implement backwards-compatibility for user-mode logging. */
+static bool force_user_mode_logging = true;
+
/*
* When running 32-on-64 we should make sure we can fit all of the possible
* guest address space into a contiguous chunk of virtual host memory.
@@ -399,6 +402,11 @@ static void handle_arg_abi_call0(const char *arg)
}
#endif
+static void handle_arg_no_force_user_mode_logging(const char *arg)
+{
+ force_user_mode_logging = false;
+}
+
static QemuPluginList plugins = QTAILQ_HEAD_INITIALIZER(plugins);
#ifdef CONFIG_PLUGIN
@@ -469,6 +477,10 @@ static const struct qemu_argument arg_table[] = {
{"xtensa-abi-call0", "QEMU_XTENSA_ABI_CALL0", false, handle_arg_abi_call0,
"", "assume CALL0 Xtensa ABI"},
#endif
+ {"no-force-user-mode-logging", "", false,
+ handle_arg_no_force_user_mode_logging,
+ "", "disable forced user-mode logging, other logging options "
+ "will be used exactly as provided" },
{NULL, NULL, false, NULL, NULL, NULL}
};
@@ -661,6 +673,18 @@ int main(int argc, char **argv, char **envp)
optind = parse_args(argc, argv);
+ if (force_user_mode_logging) {
+ /*
+ * Backwards Compatibility: gemu_log for non-strace messages was not
+ * configurable, and was always on. Unless the user explicitly disables
+ * forced LOG_USER, force LOG_USER into the mask.
+ */
+ qemu_add_log(LOG_USER);
+ }
+
+ qemu_log_mask(LOG_USER, "--> from user\n");
+ qemu_log_mask(LOG_STRACE, "--> from strace\n");
+
if (!trace_init_backends()) {
exit(1);
}
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 171c0caef3..7e23dd6327 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1555,7 +1555,7 @@ static inline abi_long target_to_host_cmsg(struct msghdr
*msgh,
* something more intelligent than "twice the size of the
* target buffer we're reading from".
*/
- gemu_log("Host cmsg overflow\n");
+ qemu_log_mask(LOG_USER, "Host cmsg overflow\n");
break;
}
@@ -1585,8 +1585,8 @@ static inline abi_long target_to_host_cmsg(struct msghdr
*msgh,
__get_user(cred->uid, &target_cred->uid);
__get_user(cred->gid, &target_cred->gid);
} else {
- gemu_log("Unsupported ancillary data: %d/%d\n",
- cmsg->cmsg_level, cmsg->cmsg_type);
+ qemu_log_mask(LOG_USER, "Unsupported ancillary data: %d/%d\n",
+ cmsg->cmsg_level, cmsg->cmsg_type);
memcpy(data, target_data, len);
}
@@ -1807,8 +1807,8 @@ static inline abi_long host_to_target_cmsg(struct
target_msghdr *target_msgh,
default:
unimplemented:
- gemu_log("Unsupported ancillary data: %d/%d\n",
- cmsg->cmsg_level, cmsg->cmsg_type);
+ qemu_log_mask(LOG_USER, "Unsupported ancillary data: %d/%d\n",
+ cmsg->cmsg_level, cmsg->cmsg_type);
memcpy(target_data, data, MIN(len, tgt_len));
if (tgt_len > len) {
memset(target_data + len, 0, tgt_len - len);
@@ -2283,7 +2283,8 @@ set_timeout:
#endif /* SOL_NETLINK */
default:
unimplemented:
- gemu_log("Unsupported setsockopt level=%d optname=%d\n", level,
optname);
+ qemu_log_mask(LOG_USER, "Unsupported setsockopt level=%d optname=%d\n",
+ level, optname);
ret = -TARGET_ENOPROTOOPT;
}
return ret;
@@ -2636,8 +2637,9 @@ static abi_long do_getsockopt(int sockfd, int level, int
optname,
#endif /* SOL_NETLINK */
default:
unimplemented:
- gemu_log("getsockopt level=%d optname=%d not yet supported\n",
- level, optname);
+ qemu_log_mask(LOG_USER,
+ "getsockopt level=%d optname=%d not yet supported\n",
+ level, optname);
ret = -TARGET_EOPNOTSUPP;
break;
}
@@ -3392,7 +3394,7 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
case TARGET_SYS_SENDMMSG: /* sockfd, msgvec, vlen, flags */
return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 1);
default:
- gemu_log("Unsupported socketcall: %d\n", num);
+ qemu_log_mask(LOG_USER, "Unsupported socketcall: %d\n", num);
return -TARGET_EINVAL;
}
}
@@ -4303,7 +4305,8 @@ static abi_long do_ipc(CPUArchState *cpu_env,
ret = do_shmctl(first, second, ptr);
break;
default:
- gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
+ qemu_log_mask(LOG_USER, "Unsupported ipc call: %d (version %d)\n",
+ call, version);
ret = -TARGET_ENOSYS;
break;
}
@@ -5151,7 +5154,8 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
ie = ioctl_entries;
for(;;) {
if (ie->target_cmd == 0) {
- gemu_log("Unsupported ioctl: cmd=0x%04lx\n", (long)cmd);
+ qemu_log_mask(
+ LOG_USER, "Unsupported ioctl: cmd=0x%04lx\n", (long)cmd);
return -TARGET_ENOSYS;
}
if (ie->target_cmd == cmd)
@@ -5217,8 +5221,8 @@ static abi_long do_ioctl(int fd, int cmd, abi_long arg)
}
break;
default:
- gemu_log("Unsupported ioctl type: cmd=0x%04lx type=%d\n",
- (long)cmd, arg_type[0]);
+ qemu_log_mask(LOG_USER, "Unsupported ioctl type: cmd=0x%04lx
type=%d\n",
+ (long)cmd, arg_type[0]);
ret = -TARGET_ENOSYS;
break;
}
diff --git a/linux-user/vm86.c b/linux-user/vm86.c
index 2fa7a89edc..0013fd8368 100644
--- a/linux-user/vm86.c
+++ b/linux-user/vm86.c
@@ -402,7 +402,8 @@ int do_vm86(CPUX86State *env, long subfunction, abi_ulong
vm86_addr)
case TARGET_VM86_FREE_IRQ:
case TARGET_VM86_GET_IRQ_BITS:
case TARGET_VM86_GET_AND_RESET_IRQ:
- gemu_log("qemu: unsupported vm86 subfunction (%ld)\n", subfunction);
+ qemu_log_mask(LOG_USER, "qemu: unsupported vm86 subfunction (%ld)\n",
+ subfunction);
ret = -TARGET_EINVAL;
goto out;
case TARGET_VM86_PLUS_INSTALL_CHECK:
diff --git a/util/log.c b/util/log.c
index 867264da8d..b14d17fafb 100644
--- a/util/log.c
+++ b/util/log.c
@@ -328,6 +328,9 @@ const QEMULogItem qemu_log_items[] = {
#ifdef CONFIG_PLUGIN
{ CPU_LOG_PLUGIN, "plugin", "output from TCG plugins\n"},
#endif
+ { LOG_USER, "user_mode",
+ "log when QEMU encounters errors in the user-mode emulation layer.\n"
+ "For example, when a socket option or syscall is not implemented" },
{ 0, NULL, NULL },
};
--
2.25.0.rc1.283.g88dfdc4193-goog