qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] migration: Replace gemu_log with qemu_log
@ 2020-01-14  3:01 Josh Kunz
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
                   ` (5 more replies)
  0 siblings, 6 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-14  3:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent, alex.bennee, armbru, Josh Kunz

The linux-user and bsd-user trees both widely use a function called
`gemu_log` (notice the 'g') for miscellaneous and strace logging. This
function predates the newer `qemu_log` function, and has a few drawbacks
compared to `qemu_log`:

  1. Always logs to `stderr`, no logging redirection.
  2. "Miscellaneous" logging cannot be disabled, so it may mix with guest
     logging.
  3. Inconsistency with other parts of the QEMU codebase, and a
     confusing name.

The second issue is especially troubling because it can interfere with
programs that expect to communicate via stderr.

This change introduces two new logging masks to the `qemu_log` subsystem
to support its use for user-mode logging. The `LOG_USER` mask, for
miscellaneous logs, and the `LOG_STRACE` mask for strace-specific
logging. Further, it replaces all existing uses of `gemu_log` with the
appropriate `qemu_log_mask(LOG_{USER,STRACE}, ...)` based on the log
message. To avoid potential backwards incompatibility, this patch series
also introduces a new flag: `-no-force-user-mode-logging`. Since "user
mode" logging was always enabled before this change, by-default the
LOG_USER mask is always set. The flag is provided for users that want to
disable LOG_USER. Hopefully, this flag can be removed, or turned into a
no-op in the futre, and -d/QEMU_LOG can be used directly to enable
user-mode logging if desired.

Unfortunately, this change introduces one small backwards incompatibility
for the linux-user tree: If an explicit `-D` option is provided, or the
`QEMU_LOG_FILENAME`_ environment variable is set, strace and user-mode
logging statements will log to the QEMU log file instead of stderr.

Tested:
  * Built with clang 9 and g++ 8.3
  * `make check` run with clang 9 build 
  * Verified:
    * QEMU_STRACE/-strace still works for linux-user
    * -no-force-user-mode-logging uses QEMU_LOG + `user_mode` or
      `strace` can be set in QEMU_LOG to trigger the appropriate
      logging.

Not tested:
  * Build/logging with bsd-user. I do not have easy access to a BSD system.

Josh Kunz (4):
  linux-user: Use `qemu_log' for non-strace logging
  linux-user: Use `qemu_log' for strace
  linux-user: remove gemu_log from the linux-user tree
  bsd-user: Replace gemu_log with qemu_log

 bsd-user/main.c           |  13 +-
 bsd-user/qemu.h           |   2 -
 bsd-user/strace.c         |  32 ++-
 bsd-user/syscall.c        |  31 ++-
 include/qemu/log.h        |  15 ++
 linux-user/arm/cpu_loop.c |   5 +-
 linux-user/fd-trans.c     |  55 +++--
 linux-user/main.c         |  50 +++-
 linux-user/qemu.h         |   2 -
 linux-user/signal.c       |   3 +-
 linux-user/strace.c       | 479 +++++++++++++++++++-------------------
 linux-user/syscall.c      |  43 ++--
 linux-user/vm86.c         |   3 +-
 util/log.c                |   5 +
 14 files changed, 404 insertions(+), 334 deletions(-)

-- 
2.25.0.rc1.283.g88dfdc4193-goog



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
@ 2020-01-14  3:01 ` Josh Kunz
  2020-01-14  8:28   ` Laurent Vivier
                     ` (2 more replies)
  2020-01-14  3:01 ` [PATCH 2/4] linux-user: Use `qemu_log' for strace Josh Kunz
                   ` (4 subsequent siblings)
  5 siblings, 3 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-14  3:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent, alex.bennee, armbru, Josh Kunz

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 <jkz@google.com>
---
 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



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
@ 2020-01-14  3:01 ` Josh Kunz
  2020-01-14  9:09   ` Laurent Vivier
  2020-01-14 10:55   ` Alex Bennée
  2020-01-14  3:01 ` [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree Josh Kunz
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-14  3:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent, alex.bennee, armbru, Josh Kunz

This change switches linux-user strace logging to use the newer `qemu_log`
logging subsystem rather than the older `gemu_log` (notice the "g")
logger. `qemu_log` has several advantages, namely that it allows logging
to a file, and provides a more unified interface for configuration
of logging (via the QEMU_LOG environment variable or options).

Signed-off-by: Josh Kunz <jkz@google.com>
---
 include/qemu/log.h   |  13 ++
 linux-user/main.c    |  17 +-
 linux-user/qemu.h    |   1 -
 linux-user/signal.c  |   3 +-
 linux-user/strace.c  | 479 ++++++++++++++++++++++---------------------
 linux-user/syscall.c |  13 +-
 util/log.c           |   2 +
 7 files changed, 282 insertions(+), 246 deletions(-)

diff --git a/include/qemu/log.h b/include/qemu/log.h
index 503e4f88d5..8f044c1716 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -64,6 +64,7 @@ static inline bool qemu_log_separate(void)
 #define CPU_LOG_PLUGIN     (1 << 18)
 /* LOG_USER is used for some informational user-mode logging. */
 #define LOG_USER           (1 << 19)
+#define LOG_STRACE         (1 << 20)
 
 /* 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
@@ -154,6 +155,18 @@ void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
 bool qemu_log_in_addr_range(uint64_t addr);
 int qemu_str_to_log_mask(const char *str);
 
+/* Add (union) the given "log_flags" to the current log mask. */
+static inline void qemu_add_log(int log_flags)
+{
+    qemu_set_log(qemu_loglevel | log_flags);
+}
+
+/* Remove (subtract) the given log flags from the current log mask. */
+static inline void qemu_del_log(int log_flags)
+{
+    qemu_set_log(qemu_loglevel & ~(log_flags));
+}
+
 /* Print a usage message listing all the valid logging categories
  * to the specified FILE*.
  */
diff --git a/linux-user/main.c b/linux-user/main.c
index c4f3de77db..0bf40c4d27 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -63,6 +63,12 @@ int have_guest_base;
 /* Used to implement backwards-compatibility for user-mode logging. */
 static bool force_user_mode_logging = true;
 
+/*
+ * Used to implement backwards-compatibility for the `-strace`, and
+ * QEMU_STRACE options.
+ */
+static bool enable_strace;
+
 /*
  * 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.
@@ -378,7 +384,7 @@ static void handle_arg_singlestep(const char *arg)
 
 static void handle_arg_strace(const char *arg)
 {
-    do_strace = 1;
+    enable_strace = true;
 }
 
 static void handle_arg_version(const char *arg)
@@ -672,6 +678,15 @@ int main(int argc, char **argv, char **envp)
     qemu_plugin_add_opts();
 
     optind = parse_args(argc, argv);
+    /*
+     * Backwards Compatability: If handle_arg_strace just enabled strace
+     * logging directly, then it could be accidentally turned off by a
+     * QEMU_LOG/-d option. To make sure that strace logging is always enabled
+     * when QEMU_STRACE/-strace is set, re-enable LOG_STRACE here.
+     */
+    if (enable_strace) {
+        qemu_add_log(LOG_STRACE);
+    }
 
     if (force_user_mode_logging) {
         /*
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index f6f5fe5fbb..02c6890c8a 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -385,7 +385,6 @@ void print_syscall_ret(int num, abi_long arg1);
  * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
  */
 void print_taken_signal(int target_signum, const target_siginfo_t *tinfo);
-extern int do_strace;
 
 /* signal.c */
 void process_pending_signals(CPUArchState *cpu_env);
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 5ca6d62b15..2ff0065804 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -864,9 +864,8 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
         handler = sa->_sa_handler;
     }
 
-    if (do_strace) {
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE)))
         print_taken_signal(sig, &k->info);
-    }
 
     if (handler == TARGET_SIG_DFL) {
         /* default handler : ignore some signal. The other are job control or fatal */
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 3d4d684450..4f7130b2ff 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -12,8 +12,6 @@
 #include <sched.h>
 #include "qemu.h"
 
-int do_strace=0;
-
 struct syscallname {
     int nr;
     const char *name;
@@ -80,7 +78,7 @@ print_ipc_cmd(int cmd)
 {
 #define output_cmd(val) \
 if( cmd == val ) { \
-    gemu_log(#val); \
+    qemu_log(#val); \
     return; \
 }
 
@@ -120,7 +118,7 @@ if( cmd == val ) { \
     output_cmd( IPC_RMID );
 
     /* Some value we don't recognize */
-    gemu_log("%d",cmd);
+    qemu_log("%d", cmd);
 }
 
 static void
@@ -151,7 +149,7 @@ print_signal(abi_ulong arg, int last)
         print_raw_param("%ld", arg, last);
         return;
     }
-    gemu_log("%s%s", signal_name, get_comma(last));
+    qemu_log("%s%s", signal_name, get_comma(last));
 }
 
 static void print_si_code(int arg)
@@ -184,10 +182,10 @@ static void print_si_code(int arg)
         codename = "SI_TKILL";
         break;
     default:
-        gemu_log("%d", arg);
+        qemu_log("%d", arg);
         return;
     }
-    gemu_log("%s", codename);
+    qemu_log("%s", codename);
 }
 
 static void get_target_siginfo(target_siginfo_t *tinfo,
@@ -288,33 +286,33 @@ static void print_siginfo(const target_siginfo_t *tinfo)
     int si_type = extract32(tinfo->si_code, 16, 16);
     int si_code = sextract32(tinfo->si_code, 0, 16);
 
-    gemu_log("{si_signo=");
+    qemu_log("{si_signo=");
     print_signal(tinfo->si_signo, 1);
-    gemu_log(", si_code=");
+    qemu_log(", si_code=");
     print_si_code(si_code);
 
     switch (si_type) {
     case QEMU_SI_KILL:
-        gemu_log(", si_pid=%u, si_uid=%u",
+        qemu_log(", si_pid=%u, si_uid=%u",
                  (unsigned int)tinfo->_sifields._kill._pid,
                  (unsigned int)tinfo->_sifields._kill._uid);
         break;
     case QEMU_SI_TIMER:
-        gemu_log(", si_timer1=%u, si_timer2=%u",
+        qemu_log(", si_timer1=%u, si_timer2=%u",
                  tinfo->_sifields._timer._timer1,
                  tinfo->_sifields._timer._timer2);
         break;
     case QEMU_SI_POLL:
-        gemu_log(", si_band=%d, si_fd=%d",
+        qemu_log(", si_band=%d, si_fd=%d",
                  tinfo->_sifields._sigpoll._band,
                  tinfo->_sifields._sigpoll._fd);
         break;
     case QEMU_SI_FAULT:
-        gemu_log(", si_addr=");
+        qemu_log(", si_addr=");
         print_pointer(tinfo->_sifields._sigfault._addr, 1);
         break;
     case QEMU_SI_CHLD:
-        gemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
+        qemu_log(", si_pid=%u, si_uid=%u, si_status=%d"
                  ", si_utime=" TARGET_ABI_FMT_ld
                  ", si_stime=" TARGET_ABI_FMT_ld,
                  (unsigned int)(tinfo->_sifields._sigchld._pid),
@@ -324,7 +322,7 @@ static void print_siginfo(const target_siginfo_t *tinfo)
                  tinfo->_sifields._sigchld._stime);
         break;
     case QEMU_SI_RT:
-        gemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
+        qemu_log(", si_pid=%u, si_uid=%u, si_sigval=" TARGET_ABI_FMT_ld,
                  (unsigned int)tinfo->_sifields._rt._pid,
                  (unsigned int)tinfo->_sifields._rt._uid,
                  tinfo->_sifields._rt._sigval.sival_ptr);
@@ -332,7 +330,7 @@ static void print_siginfo(const target_siginfo_t *tinfo)
     default:
         g_assert_not_reached();
     }
-    gemu_log("}");
+    qemu_log("}");
 }
 
 static void
@@ -349,76 +347,76 @@ print_sockaddr(abi_ulong addr, abi_long addrlen, int last)
         case AF_UNIX: {
             struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
             int i;
-            gemu_log("{sun_family=AF_UNIX,sun_path=\"");
+            qemu_log("{sun_family=AF_UNIX,sun_path=\"");
             for (i = 0; i < addrlen -
                             offsetof(struct target_sockaddr_un, sun_path) &&
                  un->sun_path[i]; i++) {
-                gemu_log("%c", un->sun_path[i]);
+                qemu_log("%c", un->sun_path[i]);
             }
-            gemu_log("\"}");
+            qemu_log("\"}");
             break;
         }
         case AF_INET: {
             struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
             uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
-            gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
+            qemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
                      ntohs(in->sin_port));
-            gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
+            qemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
                      c[0], c[1], c[2], c[3]);
-            gemu_log("}");
+            qemu_log("}");
             break;
         }
         case AF_PACKET: {
             struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
             uint8_t *c = (uint8_t *)&ll->sll_addr;
-            gemu_log("{sll_family=AF_PACKET,"
+            qemu_log("{sll_family=AF_PACKET,"
                      "sll_protocol=htons(0x%04x),if%d,pkttype=",
                      ntohs(ll->sll_protocol), ll->sll_ifindex);
             switch (ll->sll_pkttype) {
             case PACKET_HOST:
-                gemu_log("PACKET_HOST");
+                qemu_log("PACKET_HOST");
                 break;
             case PACKET_BROADCAST:
-                gemu_log("PACKET_BROADCAST");
+                qemu_log("PACKET_BROADCAST");
                 break;
             case PACKET_MULTICAST:
-                gemu_log("PACKET_MULTICAST");
+                qemu_log("PACKET_MULTICAST");
                 break;
             case PACKET_OTHERHOST:
-                gemu_log("PACKET_OTHERHOST");
+                qemu_log("PACKET_OTHERHOST");
                 break;
             case PACKET_OUTGOING:
-                gemu_log("PACKET_OUTGOING");
+                qemu_log("PACKET_OUTGOING");
                 break;
             default:
-                gemu_log("%d", ll->sll_pkttype);
+                qemu_log("%d", ll->sll_pkttype);
                 break;
             }
-            gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
+            qemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
                      c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
-            gemu_log("}");
+            qemu_log("}");
             break;
         }
         case AF_NETLINK: {
             struct target_sockaddr_nl *nl = (struct target_sockaddr_nl *)sa;
-            gemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
+            qemu_log("{nl_family=AF_NETLINK,nl_pid=%u,nl_groups=%u}",
                      tswap32(nl->nl_pid), tswap32(nl->nl_groups));
             break;
         }
         default:
-            gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
+            qemu_log("{sa_family=%d, sa_data={", sa->sa_family);
             for (i = 0; i < 13; i++) {
-                gemu_log("%02x, ", sa->sa_data[i]);
+                qemu_log("%02x, ", sa->sa_data[i]);
             }
-            gemu_log("%02x}", sa->sa_data[i]);
-            gemu_log("}");
+            qemu_log("%02x}", sa->sa_data[i]);
+            qemu_log("}");
             break;
         }
         unlock_user(sa, addr, 0);
     } else {
         print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
     }
-    gemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
+    qemu_log(", "TARGET_ABI_FMT_ld"%s", addrlen, get_comma(last));
 }
 
 static void
@@ -426,19 +424,19 @@ print_socket_domain(int domain)
 {
     switch (domain) {
     case PF_UNIX:
-        gemu_log("PF_UNIX");
+        qemu_log("PF_UNIX");
         break;
     case PF_INET:
-        gemu_log("PF_INET");
+        qemu_log("PF_INET");
         break;
     case PF_NETLINK:
-        gemu_log("PF_NETLINK");
+        qemu_log("PF_NETLINK");
         break;
     case PF_PACKET:
-        gemu_log("PF_PACKET");
+        qemu_log("PF_PACKET");
         break;
     default:
-        gemu_log("%d", domain);
+        qemu_log("%d", domain);
         break;
     }
 }
@@ -448,22 +446,22 @@ print_socket_type(int type)
 {
     switch (type) {
     case TARGET_SOCK_DGRAM:
-        gemu_log("SOCK_DGRAM");
+        qemu_log("SOCK_DGRAM");
         break;
     case TARGET_SOCK_STREAM:
-        gemu_log("SOCK_STREAM");
+        qemu_log("SOCK_STREAM");
         break;
     case TARGET_SOCK_RAW:
-        gemu_log("SOCK_RAW");
+        qemu_log("SOCK_RAW");
         break;
     case TARGET_SOCK_RDM:
-        gemu_log("SOCK_RDM");
+        qemu_log("SOCK_RDM");
         break;
     case TARGET_SOCK_SEQPACKET:
-        gemu_log("SOCK_SEQPACKET");
+        qemu_log("SOCK_SEQPACKET");
         break;
     case TARGET_SOCK_PACKET:
-        gemu_log("SOCK_PACKET");
+        qemu_log("SOCK_PACKET");
         break;
     }
 }
@@ -475,10 +473,10 @@ print_socket_protocol(int domain, int type, int protocol)
         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
         switch (protocol) {
         case 0x0003:
-            gemu_log("ETH_P_ALL");
+            qemu_log("ETH_P_ALL");
             break;
         default:
-            gemu_log("%d", protocol);
+            qemu_log("%d", protocol);
         }
         return;
     }
@@ -486,25 +484,25 @@ print_socket_protocol(int domain, int type, int protocol)
     if (domain == PF_NETLINK) {
         switch (protocol) {
         case NETLINK_ROUTE:
-            gemu_log("NETLINK_ROUTE");
+            qemu_log("NETLINK_ROUTE");
             break;
         case NETLINK_AUDIT:
-            gemu_log("NETLINK_AUDIT");
+            qemu_log("NETLINK_AUDIT");
             break;
         case NETLINK_NETFILTER:
-            gemu_log("NETLINK_NETFILTER");
+            qemu_log("NETLINK_NETFILTER");
             break;
         case NETLINK_KOBJECT_UEVENT:
-            gemu_log("NETLINK_KOBJECT_UEVENT");
+            qemu_log("NETLINK_KOBJECT_UEVENT");
             break;
         case NETLINK_RDMA:
-            gemu_log("NETLINK_RDMA");
+            qemu_log("NETLINK_RDMA");
             break;
         case NETLINK_CRYPTO:
-            gemu_log("NETLINK_CRYPTO");
+            qemu_log("NETLINK_CRYPTO");
             break;
         default:
-            gemu_log("%d", protocol);
+            qemu_log("%d", protocol);
             break;
         }
         return;
@@ -512,19 +510,19 @@ print_socket_protocol(int domain, int type, int protocol)
 
     switch (protocol) {
     case IPPROTO_IP:
-        gemu_log("IPPROTO_IP");
+        qemu_log("IPPROTO_IP");
         break;
     case IPPROTO_TCP:
-        gemu_log("IPPROTO_TCP");
+        qemu_log("IPPROTO_TCP");
         break;
     case IPPROTO_UDP:
-        gemu_log("IPPROTO_UDP");
+        qemu_log("IPPROTO_UDP");
         break;
     case IPPROTO_RAW:
-        gemu_log("IPPROTO_RAW");
+        qemu_log("IPPROTO_RAW");
         break;
     default:
-        gemu_log("%d", protocol);
+        qemu_log("%d", protocol);
         break;
     }
 }
@@ -536,7 +534,7 @@ print_fdset(int n, abi_ulong target_fds_addr)
 {
     int i;
 
-    gemu_log("[");
+    qemu_log("[");
     if( target_fds_addr ) {
         abi_long *target_fds;
 
@@ -550,11 +548,11 @@ print_fdset(int n, abi_ulong target_fds_addr)
 
         for (i=n; i>=0; i--) {
             if ((tswapal(target_fds[i / TARGET_ABI_BITS]) >> (i & (TARGET_ABI_BITS - 1))) & 1)
-                gemu_log("%d,", i );
+                qemu_log("%d,", i);
             }
         unlock_user(target_fds, target_fds_addr, 0);
     }
-    gemu_log("]");
+    qemu_log("]");
 }
 #endif
 
@@ -578,46 +576,46 @@ print_clockid(int clockid, int last)
 {
     switch (clockid) {
     case TARGET_CLOCK_REALTIME:
-        gemu_log("CLOCK_REALTIME");
+        qemu_log("CLOCK_REALTIME");
         break;
     case TARGET_CLOCK_MONOTONIC:
-        gemu_log("CLOCK_MONOTONIC");
+        qemu_log("CLOCK_MONOTONIC");
         break;
     case TARGET_CLOCK_PROCESS_CPUTIME_ID:
-        gemu_log("CLOCK_PROCESS_CPUTIME_ID");
+        qemu_log("CLOCK_PROCESS_CPUTIME_ID");
         break;
     case TARGET_CLOCK_THREAD_CPUTIME_ID:
-        gemu_log("CLOCK_THREAD_CPUTIME_ID");
+        qemu_log("CLOCK_THREAD_CPUTIME_ID");
         break;
     case TARGET_CLOCK_MONOTONIC_RAW:
-        gemu_log("CLOCK_MONOTONIC_RAW");
+        qemu_log("CLOCK_MONOTONIC_RAW");
         break;
     case TARGET_CLOCK_REALTIME_COARSE:
-        gemu_log("CLOCK_REALTIME_COARSE");
+        qemu_log("CLOCK_REALTIME_COARSE");
         break;
     case TARGET_CLOCK_MONOTONIC_COARSE:
-        gemu_log("CLOCK_MONOTONIC_COARSE");
+        qemu_log("CLOCK_MONOTONIC_COARSE");
         break;
     case TARGET_CLOCK_BOOTTIME:
-        gemu_log("CLOCK_BOOTTIME");
+        qemu_log("CLOCK_BOOTTIME");
         break;
     case TARGET_CLOCK_REALTIME_ALARM:
-        gemu_log("CLOCK_REALTIME_ALARM");
+        qemu_log("CLOCK_REALTIME_ALARM");
         break;
     case TARGET_CLOCK_BOOTTIME_ALARM:
-        gemu_log("CLOCK_BOOTTIME_ALARM");
+        qemu_log("CLOCK_BOOTTIME_ALARM");
         break;
     case TARGET_CLOCK_SGI_CYCLE:
-        gemu_log("CLOCK_SGI_CYCLE");
+        qemu_log("CLOCK_SGI_CYCLE");
         break;
     case TARGET_CLOCK_TAI:
-        gemu_log("CLOCK_TAI");
+        qemu_log("CLOCK_TAI");
         break;
     default:
-        gemu_log("%d", clockid);
+        qemu_log("%d", clockid);
         break;
     }
-    gemu_log("%s", get_comma(last));
+    qemu_log("%s", get_comma(last));
 }
 #endif
 
@@ -638,15 +636,15 @@ print_newselect(const struct syscallname *name,
                 abi_long arg1, abi_long arg2, abi_long arg3,
                 abi_long arg4, abi_long arg5, abi_long arg6)
 {
-    gemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
+    qemu_log("%s(" TARGET_ABI_FMT_ld ",", name->name, arg1);
     print_fdset(arg1, arg2);
-    gemu_log(",");
+    qemu_log(",");
     print_fdset(arg1, arg3);
-    gemu_log(",");
+    qemu_log(",");
     print_fdset(arg1, arg4);
-    gemu_log(",");
+    qemu_log(",");
     print_timeval(arg5, 1);
-    gemu_log(")");
+    qemu_log(")");
 
     /* save for use in the return output function below */
     newselect_arg1=arg1;
@@ -663,9 +661,10 @@ print_semctl(const struct syscallname *name,
              abi_long arg1, abi_long arg2, abi_long arg3,
              abi_long arg4, abi_long arg5, abi_long arg6)
 {
-    gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", name->name, arg1, arg2);
+    qemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
+             name->name, arg1, arg2);
     print_ipc_cmd(arg3);
-    gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
+    qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
 }
 #endif
 
@@ -679,7 +678,7 @@ print_execve(const struct syscallname *name,
 
     if (!(s = lock_user_string(arg1)))
         return;
-    gemu_log("%s(\"%s\",{", name->name, s);
+    qemu_log("%s(\"%s\",{", name->name, s);
     unlock_user(s, arg1, 0);
 
     for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
@@ -693,12 +692,12 @@ print_execve(const struct syscallname *name,
         if (!arg_addr)
             break;
         if ((s = lock_user_string(arg_addr))) {
-            gemu_log("\"%s\",", s);
+            qemu_log("\"%s\",", s);
             unlock_user(s, arg_addr, 0);
         }
     }
 
-    gemu_log("NULL})");
+    qemu_log("NULL})");
 }
 
 #ifdef TARGET_NR_ipc
@@ -709,12 +708,18 @@ print_ipc(const struct syscallname *name,
 {
     switch(arg1) {
     case IPCOP_semctl:
-        gemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",", arg1, arg2);
+        qemu_log("semctl(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ",",
+                 arg1, arg2);
         print_ipc_cmd(arg3);
-        gemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
+        qemu_log(",0x" TARGET_ABI_FMT_lx ")", arg4);
         break;
     default:
-        gemu_log("%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")",
+        qemu_log(("%s("
+                  TARGET_ABI_FMT_ld ","
+                  TARGET_ABI_FMT_ld ","
+                  TARGET_ABI_FMT_ld ","
+                  TARGET_ABI_FMT_ld
+                  ")"),
                  name->name, arg1, arg2, arg3, arg4);
     }
 }
@@ -733,9 +738,9 @@ print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
         errstr = target_strerror(-ret);
     }
     if (errstr) {
-        gemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
+        qemu_log(" = -1 errno=%d (%s)\n", (int)-ret, errstr);
     } else {
-        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
+        qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
     }
 }
 
@@ -743,7 +748,7 @@ print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 static void
 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
 {
-        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
+        qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 }
 #endif
 
@@ -751,15 +756,15 @@ print_syscall_ret_raw(struct syscallname *name, abi_long ret)
 static void
 print_syscall_ret_newselect(const struct syscallname *name, abi_long ret)
 {
-    gemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
+    qemu_log(" = 0x" TARGET_ABI_FMT_lx " (", ret);
     print_fdset(newselect_arg1,newselect_arg2);
-    gemu_log(",");
+    qemu_log(",");
     print_fdset(newselect_arg1,newselect_arg3);
-    gemu_log(",");
+    qemu_log(",");
     print_fdset(newselect_arg1,newselect_arg4);
-    gemu_log(",");
+    qemu_log(",");
     print_timeval(newselect_arg5, 1);
-    gemu_log(")\n");
+    qemu_log(")\n");
 }
 #endif
 
@@ -775,38 +780,38 @@ print_syscall_ret_adjtimex(const struct syscallname *name, abi_long ret)
 {
     const char *errstr = NULL;
 
-    gemu_log(" = ");
+    qemu_log(" = ");
     if (ret < 0) {
-        gemu_log("-1 errno=%d", errno);
+        qemu_log("-1 errno=%d", errno);
         errstr = target_strerror(-ret);
         if (errstr) {
-            gemu_log(" (%s)", errstr);
+            qemu_log(" (%s)", errstr);
         }
     } else {
-        gemu_log(TARGET_ABI_FMT_ld, ret);
+        qemu_log(TARGET_ABI_FMT_ld, ret);
         switch (ret) {
         case TARGET_TIME_OK:
-            gemu_log(" TIME_OK (clock synchronized, no leap second)");
+            qemu_log(" TIME_OK (clock synchronized, no leap second)");
             break;
         case TARGET_TIME_INS:
-            gemu_log(" TIME_INS (insert leap second)");
+            qemu_log(" TIME_INS (insert leap second)");
             break;
         case TARGET_TIME_DEL:
-            gemu_log(" TIME_DEL (delete leap second)");
+            qemu_log(" TIME_DEL (delete leap second)");
             break;
         case TARGET_TIME_OOP:
-            gemu_log(" TIME_OOP (leap second in progress)");
+            qemu_log(" TIME_OOP (leap second in progress)");
             break;
         case TARGET_TIME_WAIT:
-            gemu_log(" TIME_WAIT (leap second has occurred)");
+            qemu_log(" TIME_WAIT (leap second has occurred)");
             break;
         case TARGET_TIME_ERROR:
-            gemu_log(" TIME_ERROR (clock not synchronized)");
+            qemu_log(" TIME_ERROR (clock not synchronized)");
             break;
         }
     }
 
-    gemu_log("\n");
+    qemu_log("\n");
 }
 
 UNUSED static struct flags access_flags[] = {
@@ -1104,12 +1109,12 @@ print_flags(const struct flags *f, abi_long flags, int last)
     int n;
 
     if ((flags == 0) && (f->f_value == 0)) {
-        gemu_log("%s%s", f->f_string, get_comma(last));
+        qemu_log("%s%s", f->f_string, get_comma(last));
         return;
     }
     for (n = 0; f->f_string != NULL; f++) {
         if ((f->f_value != 0) && ((flags & f->f_value) == f->f_value)) {
-            gemu_log("%s%s", sep, f->f_string);
+            qemu_log("%s%s", sep, f->f_string);
             flags &= ~f->f_value;
             sep = "|";
             n++;
@@ -1119,13 +1124,13 @@ print_flags(const struct flags *f, abi_long flags, int last)
     if (n > 0) {
         /* print rest of the flags as numeric */
         if (flags != 0) {
-            gemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
+            qemu_log("%s%#x%s", sep, (unsigned int)flags, get_comma(last));
         } else {
-            gemu_log("%s", get_comma(last));
+            qemu_log("%s", get_comma(last));
         }
     } else {
         /* no string version of flags found, print them in hex then */
-        gemu_log("%#x%s", (unsigned int)flags, get_comma(last));
+        qemu_log("%#x%s", (unsigned int)flags, get_comma(last));
     }
 }
 
@@ -1134,11 +1139,11 @@ print_at_dirfd(abi_long dirfd, int last)
 {
 #ifdef AT_FDCWD
     if (dirfd == AT_FDCWD) {
-        gemu_log("AT_FDCWD%s", get_comma(last));
+        qemu_log("AT_FDCWD%s", get_comma(last));
         return;
     }
 #endif
-    gemu_log("%d%s", (int)dirfd, get_comma(last));
+    qemu_log("%d%s", (int)dirfd, get_comma(last));
 }
 
 static void
@@ -1149,7 +1154,7 @@ print_file_mode(abi_long mode, int last)
 
     for (m = &mode_flags[0]; m->f_string != NULL; m++) {
         if ((m->f_value & mode) == m->f_value) {
-            gemu_log("%s%s", m->f_string, sep);
+            qemu_log("%s%s", m->f_string, sep);
             sep = "|";
             mode &= ~m->f_value;
             break;
@@ -1159,9 +1164,9 @@ print_file_mode(abi_long mode, int last)
     mode &= ~S_IFMT;
     /* print rest of the mode as octal */
     if (mode != 0)
-        gemu_log("%s%#o", sep, (unsigned int)mode);
+        qemu_log("%s%#o", sep, (unsigned int)mode);
 
-    gemu_log("%s", get_comma(last));
+    qemu_log("%s", get_comma(last));
 }
 
 static void
@@ -1170,17 +1175,17 @@ print_open_flags(abi_long flags, int last)
     print_flags(open_access_flags, flags & TARGET_O_ACCMODE, 1);
     flags &= ~TARGET_O_ACCMODE;
     if (flags == 0) {
-        gemu_log("%s", get_comma(last));
+        qemu_log("%s", get_comma(last));
         return;
     }
-    gemu_log("|");
+    qemu_log("|");
     print_flags(open_flags, flags, last);
 }
 
 static void
 print_syscall_prologue(const struct syscallname *sc)
 {
-    gemu_log("%s(", sc->name);
+    qemu_log("%s(", sc->name);
 }
 
 /*ARGSUSED*/
@@ -1188,7 +1193,7 @@ static void
 print_syscall_epilogue(const struct syscallname *sc)
 {
     (void)sc;
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void
@@ -1197,7 +1202,7 @@ print_string(abi_long addr, int last)
     char *s;
 
     if ((s = lock_user_string(addr)) != NULL) {
-        gemu_log("\"%s\"%s", s, get_comma(last));
+        qemu_log("\"%s\"%s", s, get_comma(last));
         unlock_user(s, addr, 0);
     } else {
         /* can't get string out of it, so print it as pointer */
@@ -1214,20 +1219,20 @@ print_buf(abi_long addr, abi_long len, int last)
 
     s = lock_user(VERIFY_READ, addr, len, 1);
     if (s) {
-        gemu_log("\"");
+        qemu_log("\"");
         for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
             if (isprint(s[i])) {
-                gemu_log("%c", s[i]);
+                qemu_log("%c", s[i]);
             } else {
-                gemu_log("\\%o", s[i]);
+                qemu_log("\\%o", s[i]);
             }
         }
-        gemu_log("\"");
+        qemu_log("\"");
         if (i != len) {
-            gemu_log("...");
+            qemu_log("...");
         }
         if (!last) {
-            gemu_log(",");
+            qemu_log(",");
         }
         unlock_user(s, addr, 0);
     } else {
@@ -1245,16 +1250,16 @@ print_raw_param(const char *fmt, abi_long param, int last)
     char format[64];
 
     (void) snprintf(format, sizeof (format), "%s%s", fmt, get_comma(last));
-    gemu_log(format, param);
+    qemu_log(format, param);
 }
 
 static void
 print_pointer(abi_long p, int last)
 {
     if (p == 0)
-        gemu_log("NULL%s", get_comma(last));
+        qemu_log("NULL%s", get_comma(last));
     else
-        gemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
+        qemu_log("0x" TARGET_ABI_FMT_lx "%s", p, get_comma(last));
 }
 
 /*
@@ -1265,12 +1270,12 @@ static void
 print_number(abi_long addr, int last)
 {
     if (addr == 0) {
-        gemu_log("NULL%s", get_comma(last));
+        qemu_log("NULL%s", get_comma(last));
     } else {
         int num;
 
         get_user_s32(num, addr);
-        gemu_log("[%d]%s", num, get_comma(last));
+        qemu_log("[%d]%s", num, get_comma(last));
     }
 }
 
@@ -1285,11 +1290,11 @@ print_timeval(abi_ulong tv_addr, int last)
             print_pointer(tv_addr, last);
             return;
         }
-        gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
+        qemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
             tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
         unlock_user(tv, tv_addr, 0);
     } else
-        gemu_log("NULL%s", get_comma(last));
+        qemu_log("NULL%s", get_comma(last));
 }
 
 static void
@@ -1303,11 +1308,11 @@ print_timezone(abi_ulong tz_addr, int last)
             print_pointer(tz_addr, last);
             return;
         }
-        gemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
+        qemu_log("{%d,%d}%s", tswap32(tz->tz_minuteswest),
                  tswap32(tz->tz_dsttime), get_comma(last));
         unlock_user(tz, tz_addr, 0);
     } else {
-        gemu_log("NULL%s", get_comma(last));
+        qemu_log("NULL%s", get_comma(last));
     }
 }
 
@@ -1515,83 +1520,83 @@ print_fcntl(const struct syscallname *name,
     print_raw_param("%d", arg0, 0);
     switch(arg1) {
     case TARGET_F_DUPFD:
-        gemu_log("F_DUPFD,");
+        qemu_log("F_DUPFD,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
         break;
     case TARGET_F_GETFD:
-        gemu_log("F_GETFD");
+        qemu_log("F_GETFD");
         break;
     case TARGET_F_SETFD:
-        gemu_log("F_SETFD,");
+        qemu_log("F_SETFD,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
         break;
     case TARGET_F_GETFL:
-        gemu_log("F_GETFL");
+        qemu_log("F_GETFL");
         break;
     case TARGET_F_SETFL:
-        gemu_log("F_SETFL,");
+        qemu_log("F_SETFL,");
         print_open_flags(arg2, 1);
         break;
     case TARGET_F_GETLK:
-        gemu_log("F_GETLK,");
+        qemu_log("F_GETLK,");
         print_pointer(arg2, 1);
         break;
     case TARGET_F_SETLK:
-        gemu_log("F_SETLK,");
+        qemu_log("F_SETLK,");
         print_pointer(arg2, 1);
         break;
     case TARGET_F_SETLKW:
-        gemu_log("F_SETLKW,");
+        qemu_log("F_SETLKW,");
         print_pointer(arg2, 1);
         break;
     case TARGET_F_GETOWN:
-        gemu_log("F_GETOWN");
+        qemu_log("F_GETOWN");
         break;
     case TARGET_F_SETOWN:
-        gemu_log("F_SETOWN,");
+        qemu_log("F_SETOWN,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
         break;
     case TARGET_F_GETSIG:
-        gemu_log("F_GETSIG");
+        qemu_log("F_GETSIG");
         break;
     case TARGET_F_SETSIG:
-        gemu_log("F_SETSIG,");
+        qemu_log("F_SETSIG,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
         break;
 #if TARGET_ABI_BITS == 32
     case TARGET_F_GETLK64:
-        gemu_log("F_GETLK64,");
+        qemu_log("F_GETLK64,");
         print_pointer(arg2, 1);
         break;
     case TARGET_F_SETLK64:
-        gemu_log("F_SETLK64,");
+        qemu_log("F_SETLK64,");
         print_pointer(arg2, 1);
         break;
     case TARGET_F_SETLKW64:
-        gemu_log("F_SETLKW64,");
+        qemu_log("F_SETLKW64,");
         print_pointer(arg2, 1);
         break;
 #endif
     case TARGET_F_SETLEASE:
-        gemu_log("F_SETLEASE,");
+        qemu_log("F_SETLEASE,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
         break;
     case TARGET_F_GETLEASE:
-        gemu_log("F_GETLEASE");
+        qemu_log("F_GETLEASE");
         break;
     case TARGET_F_SETPIPE_SZ:
-        gemu_log("F_SETPIPE_SZ,");
+        qemu_log("F_SETPIPE_SZ,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
         break;
     case TARGET_F_GETPIPE_SZ:
-        gemu_log("F_GETPIPE_SZ");
+        qemu_log("F_GETPIPE_SZ");
         break;
     case TARGET_F_DUPFD_CLOEXEC:
-        gemu_log("F_DUPFD_CLOEXEC,");
+        qemu_log("F_DUPFD_CLOEXEC,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
         break;
     case TARGET_F_NOTIFY:
-        gemu_log("F_NOTIFY,");
+        qemu_log("F_NOTIFY,");
         print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
         break;
     default:
@@ -1679,7 +1684,7 @@ print__llseek(const struct syscallname *name,
     case SEEK_CUR: whence = "SEEK_CUR"; break;
     case SEEK_END: whence = "SEEK_END"; break;
     }
-    gemu_log("%s",whence);
+    qemu_log("%s", whence);
     print_syscall_epilogue(name);
 }
 #endif
@@ -1694,9 +1699,9 @@ print_socket(const struct syscallname *name,
 
     print_syscall_prologue(name);
     print_socket_domain(domain);
-    gemu_log(",");
+    qemu_log(",");
     print_socket_type(type);
-    gemu_log(",");
+    qemu_log(",");
     if (domain == AF_PACKET ||
         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
         protocol = tswap16(protocol);
@@ -1728,17 +1733,17 @@ static void do_print_socket(const char *name, abi_long arg1)
     get_user_ualx(domain, arg1, 0);
     get_user_ualx(type, arg1, 1);
     get_user_ualx(protocol, arg1, 2);
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_socket_domain(domain);
-    gemu_log(",");
+    qemu_log(",");
     print_socket_type(type);
-    gemu_log(",");
+    qemu_log(",");
     if (domain == AF_PACKET ||
         (domain == AF_INET && type == TARGET_SOCK_PACKET)) {
         protocol = tswap16(protocol);
     }
     print_socket_protocol(domain, type, protocol);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_sockaddr(const char *name, abi_long arg1)
@@ -1749,10 +1754,10 @@ static void do_print_sockaddr(const char *name, abi_long arg1)
     get_user_ualx(addr, arg1, 1);
     get_user_ualx(addrlen, arg1, 2);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     print_sockaddr(addr, addrlen, 0);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_listen(const char *name, abi_long arg1)
@@ -1762,10 +1767,10 @@ static void do_print_listen(const char *name, abi_long arg1)
     get_user_ualx(sockfd, arg1, 0);
     get_user_ualx(backlog, arg1, 1);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_socketpair(const char *name, abi_long arg1)
@@ -1777,15 +1782,15 @@ static void do_print_socketpair(const char *name, abi_long arg1)
     get_user_ualx(protocol, arg1, 2);
     get_user_ualx(tab, arg1, 3);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_socket_domain(domain);
-    gemu_log(",");
+    qemu_log(",");
     print_socket_type(type);
-    gemu_log(",");
+    qemu_log(",");
     print_socket_protocol(domain, type, protocol);
-    gemu_log(",");
+    qemu_log(",");
     print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_sendrecv(const char *name, abi_long arg1)
@@ -1797,12 +1802,12 @@ static void do_print_sendrecv(const char *name, abi_long arg1)
     get_user_ualx(len, arg1, 2);
     get_user_ualx(flags, arg1, 3);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     print_buf(msg, len, 0);
     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
     print_flags(msg_flags, flags, 1);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_msgaddr(const char *name, abi_long arg1)
@@ -1816,13 +1821,13 @@ static void do_print_msgaddr(const char *name, abi_long arg1)
     get_user_ualx(addr, arg1, 4);
     get_user_ualx(addrlen, arg1, 5);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     print_buf(msg, len, 0);
     print_raw_param(TARGET_ABI_FMT_ld, len, 0);
     print_flags(msg_flags, flags, 0);
     print_sockaddr(addr, addrlen, 0);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_shutdown(const char *name, abi_long arg1)
@@ -1832,23 +1837,23 @@ static void do_print_shutdown(const char *name, abi_long arg1)
     get_user_ualx(sockfd, arg1, 0);
     get_user_ualx(how, arg1, 1);
 
-    gemu_log("shutdown(");
+    qemu_log("shutdown(");
     print_sockfd(sockfd, 0);
     switch (how) {
     case SHUT_RD:
-        gemu_log("SHUT_RD");
+        qemu_log("SHUT_RD");
         break;
     case SHUT_WR:
-        gemu_log("SHUT_WR");
+        qemu_log("SHUT_WR");
         break;
     case SHUT_RDWR:
-        gemu_log("SHUT_RDWR");
+        qemu_log("SHUT_RDWR");
         break;
     default:
         print_raw_param(TARGET_ABI_FMT_ld, how, 1);
         break;
     }
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_msg(const char *name, abi_long arg1)
@@ -1859,11 +1864,11 @@ static void do_print_msg(const char *name, abi_long arg1)
     get_user_ualx(msg, arg1, 1);
     get_user_ualx(flags, arg1, 2);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     print_pointer(msg, 0);
     print_flags(msg_flags, flags, 1);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 static void do_print_sockopt(const char *name, abi_long arg1)
@@ -1876,113 +1881,113 @@ static void do_print_sockopt(const char *name, abi_long arg1)
     get_user_ualx(optval, arg1, 3);
     get_user_ualx(optlen, arg1, 4);
 
-    gemu_log("%s(", name);
+    qemu_log("%s(", name);
     print_sockfd(sockfd, 0);
     switch (level) {
     case SOL_TCP:
-        gemu_log("SOL_TCP,");
+        qemu_log("SOL_TCP,");
         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
         print_pointer(optval, 0);
         break;
     case SOL_IP:
-        gemu_log("SOL_IP,");
+        qemu_log("SOL_IP,");
         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
         print_pointer(optval, 0);
         break;
     case SOL_RAW:
-        gemu_log("SOL_RAW,");
+        qemu_log("SOL_RAW,");
         print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
         print_pointer(optval, 0);
         break;
     case TARGET_SOL_SOCKET:
-        gemu_log("SOL_SOCKET,");
+        qemu_log("SOL_SOCKET,");
         switch (optname) {
         case TARGET_SO_DEBUG:
-            gemu_log("SO_DEBUG,");
+            qemu_log("SO_DEBUG,");
 print_optint:
             print_number(optval, 0);
             break;
         case TARGET_SO_REUSEADDR:
-            gemu_log("SO_REUSEADDR,");
+            qemu_log("SO_REUSEADDR,");
             goto print_optint;
         case TARGET_SO_REUSEPORT:
-            gemu_log("SO_REUSEPORT,");
+            qemu_log("SO_REUSEPORT,");
             goto print_optint;
         case TARGET_SO_TYPE:
-            gemu_log("SO_TYPE,");
+            qemu_log("SO_TYPE,");
             goto print_optint;
         case TARGET_SO_ERROR:
-            gemu_log("SO_ERROR,");
+            qemu_log("SO_ERROR,");
             goto print_optint;
         case TARGET_SO_DONTROUTE:
-            gemu_log("SO_DONTROUTE,");
+            qemu_log("SO_DONTROUTE,");
             goto print_optint;
         case TARGET_SO_BROADCAST:
-            gemu_log("SO_BROADCAST,");
+            qemu_log("SO_BROADCAST,");
             goto print_optint;
         case TARGET_SO_SNDBUF:
-            gemu_log("SO_SNDBUF,");
+            qemu_log("SO_SNDBUF,");
             goto print_optint;
         case TARGET_SO_RCVBUF:
-            gemu_log("SO_RCVBUF,");
+            qemu_log("SO_RCVBUF,");
             goto print_optint;
         case TARGET_SO_KEEPALIVE:
-            gemu_log("SO_KEEPALIVE,");
+            qemu_log("SO_KEEPALIVE,");
             goto print_optint;
         case TARGET_SO_OOBINLINE:
-            gemu_log("SO_OOBINLINE,");
+            qemu_log("SO_OOBINLINE,");
             goto print_optint;
         case TARGET_SO_NO_CHECK:
-            gemu_log("SO_NO_CHECK,");
+            qemu_log("SO_NO_CHECK,");
             goto print_optint;
         case TARGET_SO_PRIORITY:
-            gemu_log("SO_PRIORITY,");
+            qemu_log("SO_PRIORITY,");
             goto print_optint;
         case TARGET_SO_BSDCOMPAT:
-            gemu_log("SO_BSDCOMPAT,");
+            qemu_log("SO_BSDCOMPAT,");
             goto print_optint;
         case TARGET_SO_PASSCRED:
-            gemu_log("SO_PASSCRED,");
+            qemu_log("SO_PASSCRED,");
             goto print_optint;
         case TARGET_SO_TIMESTAMP:
-            gemu_log("SO_TIMESTAMP,");
+            qemu_log("SO_TIMESTAMP,");
             goto print_optint;
         case TARGET_SO_RCVLOWAT:
-            gemu_log("SO_RCVLOWAT,");
+            qemu_log("SO_RCVLOWAT,");
             goto print_optint;
         case TARGET_SO_RCVTIMEO:
-            gemu_log("SO_RCVTIMEO,");
+            qemu_log("SO_RCVTIMEO,");
             print_timeval(optval, 0);
             break;
         case TARGET_SO_SNDTIMEO:
-            gemu_log("SO_SNDTIMEO,");
+            qemu_log("SO_SNDTIMEO,");
             print_timeval(optval, 0);
             break;
         case TARGET_SO_ATTACH_FILTER: {
             struct target_sock_fprog *fprog;
 
-            gemu_log("SO_ATTACH_FILTER,");
+            qemu_log("SO_ATTACH_FILTER,");
 
             if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
                 struct target_sock_filter *filter;
-                gemu_log("{");
+                qemu_log("{");
                 if (lock_user_struct(VERIFY_READ, filter,
                                      tswapal(fprog->filter),  0)) {
                     int i;
                     for (i = 0; i < tswap16(fprog->len) - 1; i++) {
-                        gemu_log("[%d]{0x%x,%d,%d,0x%x},",
+                        qemu_log("[%d]{0x%x,%d,%d,0x%x},",
                                  i, tswap16(filter[i].code),
                                  filter[i].jt, filter[i].jf,
                                  tswap32(filter[i].k));
                     }
-                    gemu_log("[%d]{0x%x,%d,%d,0x%x}",
+                    qemu_log("[%d]{0x%x,%d,%d,0x%x}",
                              i, tswap16(filter[i].code),
                              filter[i].jt, filter[i].jf,
                              tswap32(filter[i].k));
                 } else {
-                    gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
+                    qemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
                 }
-                gemu_log(",%d},", tswap16(fprog->len));
+                qemu_log(",%d},", tswap16(fprog->len));
                 unlock_user(fprog, optval, 0);
             } else {
                 print_pointer(optval, 0);
@@ -2002,7 +2007,7 @@ print_optint:
         break;
     }
     print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
-    gemu_log(")");
+    qemu_log(")");
 }
 
 #define PRINT_SOCKOP(name, func) \
@@ -2164,7 +2169,7 @@ print_rt_sigprocmask(const struct syscallname *name,
     case TARGET_SIG_UNBLOCK: how = "SIG_UNBLOCK"; break;
     case TARGET_SIG_SETMASK: how = "SIG_SETMASK"; break;
     }
-    gemu_log("%s,",how);
+    qemu_log("%s,", how);
     print_pointer(arg1, 0);
     print_pointer(arg2, 1);
     print_syscall_epilogue(name);
@@ -2278,7 +2283,7 @@ print_syslog_action(abi_ulong arg, int last)
             return;
         }
     }
-    gemu_log("%s%s", type, get_comma(last));
+    qemu_log("%s%s", type, get_comma(last));
 }
 
 static void
@@ -2683,20 +2688,20 @@ static void print_futex_op(abi_long tflag, int last)
 {
 #define print_op(val) \
 if( cmd == val ) { \
-    gemu_log(#val); \
+    qemu_log(#val); \
     return; \
 }
 
     int cmd = (int)tflag;
 #ifdef FUTEX_PRIVATE_FLAG
     if (cmd & FUTEX_PRIVATE_FLAG) {
-        gemu_log("FUTEX_PRIVATE_FLAG|");
+        qemu_log("FUTEX_PRIVATE_FLAG|");
         cmd &= ~FUTEX_PRIVATE_FLAG;
     }
 #endif
 #ifdef FUTEX_CLOCK_REALTIME
     if (cmd & FUTEX_CLOCK_REALTIME) {
-        gemu_log("FUTEX_CLOCK_REALTIME|");
+        qemu_log("FUTEX_CLOCK_REALTIME|");
         cmd &= ~FUTEX_CLOCK_REALTIME;
     }
 #endif
@@ -2716,7 +2721,7 @@ if( cmd == val ) { \
     print_op(FUTEX_WAKE_BITSET)
 #endif
     /* unknown values */
-    gemu_log("%d",cmd);
+    qemu_log("%d", cmd);
 }
 
 static void
@@ -2812,22 +2817,24 @@ print_syscall(int num,
     int i;
     const char *format="%s(" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ")";
 
-    gemu_log("%d ", getpid() );
+    qemu_log("%d ", getpid());
 
     for(i=0;i<nsyscalls;i++)
         if( scnames[i].nr == num ) {
             if( scnames[i].call != NULL ) {
-                scnames[i].call(&scnames[i],arg1,arg2,arg3,arg4,arg5,arg6);
+                scnames[i].call(
+                    &scnames[i], arg1, arg2, arg3, arg4, arg5, arg6);
             } else {
                 /* XXX: this format system is broken because it uses
                    host types and host pointers for strings */
                 if( scnames[i].format != NULL )
                     format = scnames[i].format;
-                gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
+                qemu_log(format,
+                         scnames[i].name, arg1, arg2, arg3, arg4, arg5, arg6);
             }
             return;
         }
-    gemu_log("Unknown syscall %d\n", num);
+    qemu_log("Unknown syscall %d\n", num);
 }
 
 
@@ -2840,16 +2847,16 @@ print_syscall_ret(int num, abi_long ret)
     for(i=0;i<nsyscalls;i++)
         if( scnames[i].nr == num ) {
             if( scnames[i].result != NULL ) {
-                scnames[i].result(&scnames[i],ret);
+                scnames[i].result(&scnames[i], ret);
             } else {
                 if (ret < 0) {
                     errstr = target_strerror(-ret);
                 }
                 if (errstr) {
-                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
+                    qemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n",
                              -ret, errstr);
                 } else {
-                    gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
+                    qemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
                 }
             }
             break;
@@ -2861,9 +2868,9 @@ void print_taken_signal(int target_signum, const target_siginfo_t *tinfo)
     /* Print the strace output for a signal being taken:
      * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
      */
-    gemu_log("--- ");
+    qemu_log("--- ");
     print_signal(target_signum, 1);
-    gemu_log(" ");
+    qemu_log(" ");
     print_siginfo(tinfo);
-    gemu_log(" ---\n");
+    qemu_log(" ---\n");
 }
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7e23dd6327..aa55040b42 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -12098,14 +12098,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     record_syscall_start(cpu, num, arg1,
                          arg2, arg3, arg4, arg5, arg6, arg7, arg8);
 
-    if (unlikely(do_strace)) {
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
-        ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
-                          arg5, arg6, arg7, arg8);
+    }
+
+    ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
+                      arg5, arg6, arg7, arg8);
+
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_syscall_ret(num, ret);
-    } else {
-        ret = do_syscall1(cpu_env, num, arg1, arg2, arg3, arg4,
-                          arg5, arg6, arg7, arg8);
     }
 
     record_syscall_return(cpu, num, ret);
diff --git a/util/log.c b/util/log.c
index b14d17fafb..b8ca50165d 100644
--- a/util/log.c
+++ b/util/log.c
@@ -331,6 +331,8 @@ const QEMULogItem qemu_log_items[] = {
     { 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" },
+    { LOG_STRACE, "strace",
+      "log every user-mode syscall, its input, and its result" },
     { 0, NULL, NULL },
 };
 
-- 
2.25.0.rc1.283.g88dfdc4193-goog



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
  2020-01-14  3:01 ` [PATCH 2/4] linux-user: Use `qemu_log' for strace Josh Kunz
@ 2020-01-14  3:01 ` Josh Kunz
  2020-01-14 10:56   ` Alex Bennée
  2020-01-14  3:01 ` [PATCH 4/4] bsd-user: Replace gemu_log with qemu_log Josh Kunz
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 21+ messages in thread
From: Josh Kunz @ 2020-01-14  3:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent, alex.bennee, armbru, Josh Kunz

Now that all uses have been migrated to `qemu_log' it is no longer
needed.

Signed-off-by: Josh Kunz <jkz@google.com>
---
 linux-user/main.c | 9 ---------
 linux-user/qemu.h | 1 -
 2 files changed, 10 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 0bf40c4d27..945b6adf3a 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -108,15 +108,6 @@ const char *qemu_uname_release;
    by remapping the process stack directly at the right place */
 unsigned long guest_stack_size = 8 * 1024 * 1024UL;
 
-void gemu_log(const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    vfprintf(stderr, fmt, ap);
-    va_end(ap);
-}
-
 #if defined(TARGET_I386)
 int cpu_get_pic_interrupt(CPUX86State *env)
 {
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 02c6890c8a..329b409e65 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -210,7 +210,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
                     abi_long arg2, abi_long arg3, abi_long arg4,
                     abi_long arg5, abi_long arg6, abi_long arg7,
                     abi_long arg8);
-void gemu_log(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 extern __thread CPUState *thread_cpu;
 void cpu_loop(CPUArchState *env);
 const char *target_strerror(int err);
-- 
2.25.0.rc1.283.g88dfdc4193-goog



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH 4/4] bsd-user: Replace gemu_log with qemu_log
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
                   ` (2 preceding siblings ...)
  2020-01-14  3:01 ` [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree Josh Kunz
@ 2020-01-14  3:01 ` Josh Kunz
  2020-01-14  3:06 ` [PATCH 0/4] migration: " Warner Losh
  2020-01-14 11:02 ` Alex Bennée
  5 siblings, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-14  3:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: riku.voipio, laurent, alex.bennee, armbru, Josh Kunz

gemu_log is an old logging mechanism used to implement strace logging in
the bsd-user tree. It logs directly to stderr and cannot easily be
redirected. This change instead causes strace to log via the qemu_log
subsystem which has fine-grained logging control, and a centralized
mechanism for log redirection. bsd-user does not currently implement any
logging redirection options, or log masking options, but this change
brings it more in line with the linux-user tree.

Signed-off-by: Josh Kunz <jkz@google.com>
---
 bsd-user/main.c    | 13 ++-----------
 bsd-user/qemu.h    |  2 --
 bsd-user/strace.c  | 32 +++++++++++++++-----------------
 bsd-user/syscall.c | 31 +++++++++++++++++++------------
 4 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 7f4e3cd627..e726b0a7fb 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -55,15 +55,6 @@ enum BSDType bsd_type;
    by remapping the process stack directly at the right place */
 unsigned long x86_stack_size = 512 * 1024;
 
-void gemu_log(const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    vfprintf(stderr, fmt, ap);
-    va_end(ap);
-}
-
 #if defined(TARGET_I386)
 int cpu_get_pic_interrupt(CPUX86State *env)
 {
@@ -845,7 +836,7 @@ int main(int argc, char **argv)
         } else if (!strcmp(r, "singlestep")) {
             singlestep = 1;
         } else if (!strcmp(r, "strace")) {
-            do_strace = 1;
+            qemu_add_log(LOG_STRACE);
         } else if (!strcmp(r, "trace")) {
             g_free(trace_file);
             trace_file = trace_opt_parse(optarg);
@@ -917,7 +908,7 @@ int main(int argc, char **argv)
     thread_cpu = cpu;
 
     if (getenv("QEMU_STRACE")) {
-        do_strace = 1;
+        qemu_add_log(LOG_STRACE);
     }
 
     target_environ = envlist_to_environ(envlist, NULL);
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 09e8aed9c7..5762e3a6e5 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -152,7 +152,6 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
 abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
                             abi_long arg2, abi_long arg3, abi_long arg4,
                             abi_long arg5, abi_long arg6);
-void gemu_log(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 extern THREAD CPUState *thread_cpu;
 void cpu_loop(CPUArchState *env);
 char *target_strerror(int err);
@@ -188,7 +187,6 @@ print_openbsd_syscall(int num,
                       abi_long arg1, abi_long arg2, abi_long arg3,
                       abi_long arg4, abi_long arg5, abi_long arg6);
 void print_openbsd_syscall_ret(int num, abi_long ret);
-extern int do_strace;
 
 /* signal.c */
 void process_pending_signals(CPUArchState *cpu_env);
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index fa66fe1ee2..6ee1510555 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -23,8 +23,6 @@
 
 #include "qemu.h"
 
-int do_strace;
-
 /*
  * Utility functions
  */
@@ -36,17 +34,17 @@ static void print_sysctl(const struct syscallname *name, abi_long arg1,
     uint32_t i;
     int32_t *namep;
 
-    gemu_log("%s({ ", name->name);
+    qemu_log("%s({ ", name->name);
     namep = lock_user(VERIFY_READ, arg1, sizeof(int32_t) * arg2, 1);
     if (namep) {
         int32_t *p = namep;
 
         for (i = 0; i < (uint32_t)arg2; i++) {
-            gemu_log("%d ", tswap32(*p++));
+            qemu_log("%d ", tswap32(*p++));
         }
         unlock_user(namep, arg1, 0);
     }
-    gemu_log("}, %u, 0x" TARGET_ABI_FMT_lx ", 0x" TARGET_ABI_FMT_lx ", 0x"
+    qemu_log("}, %u, 0x" TARGET_ABI_FMT_lx ", 0x" TARGET_ABI_FMT_lx ", 0x"
         TARGET_ABI_FMT_lx ", 0x" TARGET_ABI_FMT_lx ")",
         (uint32_t)arg2, arg3, arg4, arg5, arg6);
 }
@@ -62,7 +60,7 @@ static void print_execve(const struct syscallname *name, abi_long arg1,
     if (s == NULL) {
         return;
     }
-    gemu_log("%s(\"%s\",{", name->name, s);
+    qemu_log("%s(\"%s\",{", name->name, s);
     unlock_user(s, arg1, 0);
 
     for (arg_ptr_addr = arg2; ; arg_ptr_addr += sizeof(abi_ulong)) {
@@ -78,11 +76,11 @@ static void print_execve(const struct syscallname *name, abi_long arg1,
             break;
         }
         if ((s = lock_user_string(arg_addr))) {
-            gemu_log("\"%s\",", s);
+            qemu_log("\"%s\",", s);
             unlock_user(s, arg_addr, 0);
         }
     }
-    gemu_log("NULL})");
+    qemu_log("NULL})");
 }
 
 static void print_ioctl(const struct syscallname *name,
@@ -90,7 +88,7 @@ static void print_ioctl(const struct syscallname *name,
         abi_long arg5, abi_long arg6)
 {
     /* Decode the ioctl request */
-    gemu_log("%s(%d, 0x%0lx { IO%s%s GRP:0x%x('%c') CMD:%d LEN:%d }, 0x"
+    qemu_log("%s(%d, 0x%0lx { IO%s%s GRP:0x%x('%c') CMD:%d LEN:%d }, 0x"
             TARGET_ABI_FMT_lx ", ...)",
             name->name,
             (int)arg1,
@@ -111,9 +109,9 @@ static void print_ioctl(const struct syscallname *name,
 static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 {
     if (ret == -1) {
-        gemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno));
+        qemu_log(" = -1 errno=%d (%s)\n", errno, strerror(errno));
     } else {
-        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
+        qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
     }
 }
 
@@ -121,7 +119,7 @@ static void print_syscall_ret_addr(const struct syscallname *name, abi_long ret)
 static void
 print_syscall_ret_raw(struct syscallname *name, abi_long ret)
 {
-        gemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
+        qemu_log(" = 0x" TARGET_ABI_FMT_lx "\n", ret);
 }
 #endif
 
@@ -148,7 +146,7 @@ static void print_syscall(int num, const struct syscallname *scnames,
         TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld ","
         TARGET_ABI_FMT_ld ")";
 
-    gemu_log("%d ", getpid() );
+    qemu_log("%d ", getpid());
 
     for (i = 0; i < nscnames; i++) {
         if (scnames[i].nr == num) {
@@ -161,13 +159,13 @@ static void print_syscall(int num, const struct syscallname *scnames,
                 if (scnames[i].format != NULL) {
                     format = scnames[i].format;
                 }
-                gemu_log(format, scnames[i].name, arg1, arg2, arg3, arg4, arg5,
+                qemu_log(format, scnames[i].name, arg1, arg2, arg3, arg4, arg5,
                         arg6);
             }
             return;
         }
     }
-    gemu_log("Unknown syscall %d\n", num);
+    qemu_log("Unknown syscall %d\n", num);
 }
 
 static void print_syscall_ret(int num, abi_long ret,
@@ -181,10 +179,10 @@ static void print_syscall_ret(int num, abi_long ret,
                 scnames[i].result(&scnames[i], ret);
             } else {
                 if (ret < 0) {
-                    gemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret,
+                    qemu_log(" = -1 errno=" TARGET_ABI_FMT_ld " (%s)\n", -ret,
                              strerror(-ret));
                 } else {
-                    gemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
+                    qemu_log(" = " TARGET_ABI_FMT_ld "\n", ret);
                 }
             }
             break;
diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c
index 0d45b654bb..53635d183e 100644
--- a/bsd-user/syscall.c
+++ b/bsd-user/syscall.c
@@ -321,12 +321,13 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
     void *p;
 
 #ifdef DEBUG
-    gemu_log("freebsd syscall %d\n", num);
+    qemu_log("freebsd syscall %d\n", num);
 #endif
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch(num) {
     case TARGET_FREEBSD_NR_exit:
@@ -401,10 +402,12 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,
     }
  fail:
 #ifdef DEBUG
-    gemu_log(" = %ld\n", ret);
+    qemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_freebsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
@@ -422,13 +425,14 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
     void *p;
 
 #ifdef DEBUG
-    gemu_log("netbsd syscall %d\n", num);
+    qemu_log("netbsd syscall %d\n", num);
 #endif
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch(num) {
     case TARGET_NETBSD_NR_exit:
@@ -480,10 +484,11 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,
     }
  fail:
 #ifdef DEBUG
-    gemu_log(" = %ld\n", ret);
+    qemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_netbsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
@@ -501,13 +506,14 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
     void *p;
 
 #ifdef DEBUG
-    gemu_log("openbsd syscall %d\n", num);
+    qemu_log("openbsd syscall %d\n", num);
 #endif
 
     record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0);
 
-    if(do_strace)
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
 
     switch(num) {
     case TARGET_OPENBSD_NR_exit:
@@ -559,10 +565,11 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
     }
  fail:
 #ifdef DEBUG
-    gemu_log(" = %ld\n", ret);
+    qemu_log(" = %ld\n", ret);
 #endif
-    if (do_strace)
+    if (unlikely(qemu_loglevel_mask(LOG_STRACE))) {
         print_openbsd_syscall_ret(num, ret);
+    }
 
     record_syscall_return(cpu, num, ret);
     return ret;
-- 
2.25.0.rc1.283.g88dfdc4193-goog



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
                   ` (3 preceding siblings ...)
  2020-01-14  3:01 ` [PATCH 4/4] bsd-user: Replace gemu_log with qemu_log Josh Kunz
@ 2020-01-14  3:06 ` Warner Losh
  2020-01-16 23:13   ` Josh Kunz
  2020-01-14 11:02 ` Alex Bennée
  5 siblings, 1 reply; 21+ messages in thread
From: Warner Losh @ 2020-01-14  3:06 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, riku.voipio, alex.bennee, QEMU Developers, laurent

[-- Attachment #1: Type: text/plain, Size: 3298 bytes --]

On Mon, Jan 13, 2020, 8:03 PM Josh Kunz <jkz@google.com> wrote:

> The linux-user and bsd-user trees both widely use a function called
> `gemu_log` (notice the 'g') for miscellaneous and strace logging. This
> function predates the newer `qemu_log` function, and has a few drawbacks
> compared to `qemu_log`:
>
>   1. Always logs to `stderr`, no logging redirection.
>   2. "Miscellaneous" logging cannot be disabled, so it may mix with guest
>      logging.
>   3. Inconsistency with other parts of the QEMU codebase, and a
>      confusing name.
>
> The second issue is especially troubling because it can interfere with
> programs that expect to communicate via stderr.
>
> This change introduces two new logging masks to the `qemu_log` subsystem
> to support its use for user-mode logging. The `LOG_USER` mask, for
> miscellaneous logs, and the `LOG_STRACE` mask for strace-specific
> logging. Further, it replaces all existing uses of `gemu_log` with the
> appropriate `qemu_log_mask(LOG_{USER,STRACE}, ...)` based on the log
> message. To avoid potential backwards incompatibility, this patch series
> also introduces a new flag: `-no-force-user-mode-logging`. Since "user
> mode" logging was always enabled before this change, by-default the
> LOG_USER mask is always set. The flag is provided for users that want to
> disable LOG_USER. Hopefully, this flag can be removed, or turned into a
> no-op in the futre, and -d/QEMU_LOG can be used directly to enable
> user-mode logging if desired.
>
> Unfortunately, this change introduces one small backwards incompatibility
> for the linux-user tree: If an explicit `-D` option is provided, or the
> `QEMU_LOG_FILENAME`_ environment variable is set, strace and user-mode
> logging statements will log to the QEMU log file instead of stderr.
>
> Tested:
>   * Built with clang 9 and g++ 8.3
>   * `make check` run with clang 9 build
>   * Verified:
>     * QEMU_STRACE/-strace still works for linux-user
>     * -no-force-user-mode-logging uses QEMU_LOG + `user_mode` or
>       `strace` can be set in QEMU_LOG to trigger the appropriate
>       logging.
>
> Not tested:
>   * Build/logging with bsd-user. I do not have easy access to a BSD system.
>

The bsd-user that is in tree doesn't work. I've been trying to catch up to
qemu head of tree, but I'm only up to 3.2... chances are the bsd-user
changes will not change the state of things...

Warner

Josh Kunz (4):
>   linux-user: Use `qemu_log' for non-strace logging
>   linux-user: Use `qemu_log' for strace
>   linux-user: remove gemu_log from the linux-user tree
>   bsd-user: Replace gemu_log with qemu_log
>
>  bsd-user/main.c           |  13 +-
>  bsd-user/qemu.h           |   2 -
>  bsd-user/strace.c         |  32 ++-
>  bsd-user/syscall.c        |  31 ++-
>  include/qemu/log.h        |  15 ++
>  linux-user/arm/cpu_loop.c |   5 +-
>  linux-user/fd-trans.c     |  55 +++--
>  linux-user/main.c         |  50 +++-
>  linux-user/qemu.h         |   2 -
>  linux-user/signal.c       |   3 +-
>  linux-user/strace.c       | 479 +++++++++++++++++++-------------------
>  linux-user/syscall.c      |  43 ++--
>  linux-user/vm86.c         |   3 +-
>  util/log.c                |   5 +
>  14 files changed, 404 insertions(+), 334 deletions(-)
>
> --
> 2.25.0.rc1.283.g88dfdc4193-goog
>
>
>

[-- Attachment #2: Type: text/html, Size: 4244 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
@ 2020-01-14  8:28   ` Laurent Vivier
  2020-01-14  8:30   ` Laurent Vivier
  2020-01-14 10:42   ` Alex Bennée
  2 siblings, 0 replies; 21+ messages in thread
From: Laurent Vivier @ 2020-01-14  8:28 UTC (permalink / raw)
  To: qemu-devel

Le 14/01/2020 à 04:01, Josh Kunz a écrit :
> 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 <jkz@google.com>
> ---
>  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(-)

I think most of these log messages should use LOG_UNIMP, so no need for
a new flag.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
  2020-01-14  8:28   ` Laurent Vivier
@ 2020-01-14  8:30   ` Laurent Vivier
  2020-01-14 10:42   ` Alex Bennée
  2 siblings, 0 replies; 21+ messages in thread
From: Laurent Vivier @ 2020-01-14  8:30 UTC (permalink / raw)
  To: Josh Kunz, qemu-devel; +Cc: riku.voipio, alex.bennee, armbru

Le 14/01/2020 à 04:01, Josh Kunz a écrit :
> 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 <jkz@google.com>
> ---
>  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(-)
> 

I think most of these log messages should use LOG_UNIMP, so no need for
a new flag.

Thanks,
Laurent



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14  3:01 ` [PATCH 2/4] linux-user: Use `qemu_log' for strace Josh Kunz
@ 2020-01-14  9:09   ` Laurent Vivier
  2020-01-14 16:15     ` Paolo Bonzini
  2020-01-17 19:28     ` Josh Kunz
  2020-01-14 10:55   ` Alex Bennée
  1 sibling, 2 replies; 21+ messages in thread
From: Laurent Vivier @ 2020-01-14  9:09 UTC (permalink / raw)
  To: Josh Kunz, qemu-devel; +Cc: Paolo Bonzini, riku.voipio, alex.bennee, armbru

Le 14/01/2020 à 04:01, Josh Kunz a écrit :
> This change switches linux-user strace logging to use the newer `qemu_log`
> logging subsystem rather than the older `gemu_log` (notice the "g")
> logger. `qemu_log` has several advantages, namely that it allows logging
> to a file, and provides a more unified interface for configuration
> of logging (via the QEMU_LOG environment variable or options).
> 
> Signed-off-by: Josh Kunz <jkz@google.com>
> ---
>  include/qemu/log.h   |  13 ++
>  linux-user/main.c    |  17 +-
>  linux-user/qemu.h    |   1 -
>  linux-user/signal.c  |   3 +-
>  linux-user/strace.c  | 479 ++++++++++++++++++++++---------------------
>  linux-user/syscall.c |  13 +-
>  util/log.c           |   2 +
>  7 files changed, 282 insertions(+), 246 deletions(-)
> 
> diff --git a/include/qemu/log.h b/include/qemu/log.h
> index 503e4f88d5..8f044c1716 100644
> --- a/include/qemu/log.h
> +++ b/include/qemu/log.h
> @@ -64,6 +64,7 @@ static inline bool qemu_log_separate(void)
>  #define CPU_LOG_PLUGIN     (1 << 18)
>  /* LOG_USER is used for some informational user-mode logging. */
>  #define LOG_USER           (1 << 19)
> +#define LOG_STRACE         (1 << 20)

Perhaps we can use flag LOG_TRACE? (cc Paolo)

>  
>  /* 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
> @@ -154,6 +155,18 @@ void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
>  bool qemu_log_in_addr_range(uint64_t addr);
>  int qemu_str_to_log_mask(const char *str);
>  
> +/* Add (union) the given "log_flags" to the current log mask. */
> +static inline void qemu_add_log(int log_flags)
> +{
> +    qemu_set_log(qemu_loglevel | log_flags);
> +}

This is really a special case as the flags are all given at the same
time, could you use directly qemu_set_log() in main()?

> +/* Remove (subtract) the given log flags from the current log mask. */
> +static inline void qemu_del_log(int log_flags)
> +{
> +    qemu_set_log(qemu_loglevel & ~(log_flags));
> +}

Unused and unneeded.

Except that, the patch seems good.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
  2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
  2020-01-14  8:28   ` Laurent Vivier
  2020-01-14  8:30   ` Laurent Vivier
@ 2020-01-14 10:42   ` Alex Bennée
  2020-01-17 19:28     ` Josh Kunz
  2 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2020-01-14 10:42 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, riku.voipio, qemu-devel, laurent


Josh Kunz <jkz@google.com> writes:

> 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 <jkz@google.com>
> ---
>  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)

As Laurent said I think LOG_UNIMP is perfectly fine for stuff we haven't
done. I don't think any of the cases warrant LOG_GUEST_ERROR.
>  
> 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;
> +

I'm not sure want to bother with this. I know we like to avoid
regression but isn't this all debug log stuff? If we must keep it can we
invert the variable to save the initialisation.

>  /*
>   * 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");
> +

I mean we jumped through hoops to maintain backwards compatibility and
then added new output? Also LOG_STRACE doesn't exist yet.

>      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");

I'm not sure we shouldn't just be asserting this case above. The
comments imply it is a bug on our part. The rest look like good cases
for LOG_UNIMP.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14  3:01 ` [PATCH 2/4] linux-user: Use `qemu_log' for strace Josh Kunz
  2020-01-14  9:09   ` Laurent Vivier
@ 2020-01-14 10:55   ` Alex Bennée
  2020-01-17 19:28     ` Josh Kunz
  1 sibling, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2020-01-14 10:55 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, riku.voipio, qemu-devel, laurent


Josh Kunz <jkz@google.com> writes:

> This change switches linux-user strace logging to use the newer `qemu_log`
> logging subsystem rather than the older `gemu_log` (notice the "g")
> logger. `qemu_log` has several advantages, namely that it allows logging
> to a file, and provides a more unified interface for configuration
> of logging (via the QEMU_LOG environment variable or options).
>
> Signed-off-by: Josh Kunz <jkz@google.com>
> ---
>  include/qemu/log.h   |  13 ++
>  linux-user/main.c    |  17 +-
>  linux-user/qemu.h    |   1 -
>  linux-user/signal.c  |   3 +-
>  linux-user/strace.c  | 479 ++++++++++++++++++++++---------------------
>  linux-user/syscall.c |  13 +-
>  util/log.c           |   2 +
>  7 files changed, 282 insertions(+), 246 deletions(-)
>
> diff --git a/include/qemu/log.h b/include/qemu/log.h
> index 503e4f88d5..8f044c1716 100644
> --- a/include/qemu/log.h
> +++ b/include/qemu/log.h
> @@ -64,6 +64,7 @@ static inline bool qemu_log_separate(void)
>  #define CPU_LOG_PLUGIN     (1 << 18)
>  /* LOG_USER is used for some informational user-mode logging. */
>  #define LOG_USER           (1 << 19)
> +#define LOG_STRACE         (1 << 20)
>
>  /* 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
> @@ -154,6 +155,18 @@ void qemu_set_dfilter_ranges(const char *ranges, Error **errp);
>  bool qemu_log_in_addr_range(uint64_t addr);
>  int qemu_str_to_log_mask(const char *str);
>
> +/* Add (union) the given "log_flags" to the current log mask. */
> +static inline void qemu_add_log(int log_flags)
> +{
> +    qemu_set_log(qemu_loglevel | log_flags);
> +}
> +
> +/* Remove (subtract) the given log flags from the current log mask. */
> +static inline void qemu_del_log(int log_flags)
> +{
> +    qemu_set_log(qemu_loglevel & ~(log_flags));
> +}
> +
>  /* Print a usage message listing all the valid logging categories
>   * to the specified FILE*.
>   */
> diff --git a/linux-user/main.c b/linux-user/main.c
> index c4f3de77db..0bf40c4d27 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -63,6 +63,12 @@ int have_guest_base;
>  /* Used to implement backwards-compatibility for user-mode logging. */
>  static bool force_user_mode_logging = true;
>
> +/*
> + * Used to implement backwards-compatibility for the `-strace`, and
> + * QEMU_STRACE options.
> + */
> +static bool enable_strace;
> +
>  /*
>   * 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.
> @@ -378,7 +384,7 @@ static void handle_arg_singlestep(const char *arg)
>
>  static void handle_arg_strace(const char *arg)
>  {
> -    do_strace = 1;
> +    enable_strace = true;

Could we cut out the middle-man and just qemu_add_log(LOG_STRACE) here
and drop the enable_strace variable.

>  }
>
>  static void handle_arg_version(const char *arg)
> @@ -672,6 +678,15 @@ int main(int argc, char **argv, char **envp)
>      qemu_plugin_add_opts();
>
>      optind = parse_args(argc, argv);
> +    /*
> +     * Backwards Compatability: If handle_arg_strace just enabled strace
> +     * logging directly, then it could be accidentally turned off by a
> +     * QEMU_LOG/-d option. To make sure that strace logging is always enabled
> +     * when QEMU_STRACE/-strace is set, re-enable LOG_STRACE here.
> +     */
> +    if (enable_strace) {
> +        qemu_add_log(LOG_STRACE);
> +    }
>
>      if (force_user_mode_logging) {
>          /*
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index f6f5fe5fbb..02c6890c8a 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -385,7 +385,6 @@ void print_syscall_ret(int num, abi_long arg1);
>   * --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} ---
>   */
>  void print_taken_signal(int target_signum, const target_siginfo_t *tinfo);
> -extern int do_strace;
>
>  /* signal.c */
>  void process_pending_signals(CPUArchState *cpu_env);
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 5ca6d62b15..2ff0065804 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -864,9 +864,8 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig,
>          handler = sa->_sa_handler;
>      }
>
> -    if (do_strace) {
> +    if (unlikely(qemu_loglevel_mask(LOG_STRACE)))
>          print_taken_signal(sig, &k->info);
> -    }

Please don't drop the brace - c.f. CODING_STYLE.rst

Side note, print_taken_signal might want to consider using the
qemu_log_lock() functionality to keep sequential qemu_log's together. I
suspect you might want to do the same for syscalls.

--
Alex Bennée


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree
  2020-01-14  3:01 ` [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree Josh Kunz
@ 2020-01-14 10:56   ` Alex Bennée
  0 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2020-01-14 10:56 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, riku.voipio, qemu-devel, laurent


Josh Kunz <jkz@google.com> writes:

> Now that all uses have been migrated to `qemu_log' it is no longer
> needed.
>
> Signed-off-by: Josh Kunz <jkz@google.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

> ---
>  linux-user/main.c | 9 ---------
>  linux-user/qemu.h | 1 -
>  2 files changed, 10 deletions(-)
>
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 0bf40c4d27..945b6adf3a 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -108,15 +108,6 @@ const char *qemu_uname_release;
>     by remapping the process stack directly at the right place */
>  unsigned long guest_stack_size = 8 * 1024 * 1024UL;
>  
> -void gemu_log(const char *fmt, ...)
> -{
> -    va_list ap;
> -
> -    va_start(ap, fmt);
> -    vfprintf(stderr, fmt, ap);
> -    va_end(ap);
> -}
> -
>  #if defined(TARGET_I386)
>  int cpu_get_pic_interrupt(CPUX86State *env)
>  {
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 02c6890c8a..329b409e65 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -210,7 +210,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>                      abi_long arg2, abi_long arg3, abi_long arg4,
>                      abi_long arg5, abi_long arg6, abi_long arg7,
>                      abi_long arg8);
> -void gemu_log(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>  extern __thread CPUState *thread_cpu;
>  void cpu_loop(CPUArchState *env);
>  const char *target_strerror(int err);


-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
                   ` (4 preceding siblings ...)
  2020-01-14  3:06 ` [PATCH 0/4] migration: " Warner Losh
@ 2020-01-14 11:02 ` Alex Bennée
  2020-01-16 23:12   ` Josh Kunz
  5 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2020-01-14 11:02 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, riku.voipio, qemu-devel, laurent


Josh Kunz <jkz@google.com> writes:

<snip>
>
> Not tested:
>   * Build/logging with bsd-user. I do not have easy access to a BSD
> system.

If you have the time we have vm-build-netbsd:

  make vm-build-netbsd EXTRA_CONFIGURE_OPTS="--disable-system"
  
Which will create a NetBSD image for you and run the build through it.
Other images are available ;-)

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14  9:09   ` Laurent Vivier
@ 2020-01-14 16:15     ` Paolo Bonzini
  2020-01-17 19:28     ` Josh Kunz
  1 sibling, 0 replies; 21+ messages in thread
From: Paolo Bonzini @ 2020-01-14 16:15 UTC (permalink / raw)
  To: Laurent Vivier, Josh Kunz, qemu-devel; +Cc: riku.voipio, alex.bennee, armbru

On 14/01/20 10:09, Laurent Vivier wrote:
> Perhaps we can use flag LOG_TRACE? (cc Paolo)

No, LOG_TRACE is for trace-events tracepoints.  A new logging flag is
definitely the way to go.

Paolo



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-14 11:02 ` Alex Bennée
@ 2020-01-16 23:12   ` Josh Kunz
  2020-01-20 11:36     ` Alex Bennée
  0 siblings, 1 reply; 21+ messages in thread
From: Josh Kunz @ 2020-01-16 23:12 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-devel, Riku Voipio, Laurent Vivier, armbru

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]

On Tue, Jan 14, 2020 at 3:02 AM Alex Bennée <alex.bennee@linaro.org> wrote:

>
> Josh Kunz <jkz@google.com> writes:
>
> <snip>
> >
> > Not tested:
> >   * Build/logging with bsd-user. I do not have easy access to a BSD
> > system.
>
> If you have the time we have vm-build-netbsd:
>
>   make vm-build-netbsd EXTRA_CONFIGURE_OPTS="--disable-system"
>
> Which will create a NetBSD image for you and run the build through it.
> Other images are available ;-)
>

This works, but it looks like it only runs the tests on BSD, even with
`configure --enable-bsd-user` first. I don't see the bsd-user binaries
being produced in the output of this command.

[-- Attachment #2: Type: text/html, Size: 1120 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-14  3:06 ` [PATCH 0/4] migration: " Warner Losh
@ 2020-01-16 23:13   ` Josh Kunz
  0 siblings, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-16 23:13 UTC (permalink / raw)
  To: Warner Losh
  Cc: QEMU Developers, Riku Voipio, Laurent Vivier, alex.bennee, armbru

[-- Attachment #1: Type: text/plain, Size: 408 bytes --]

On Mon, Jan 13, 2020 at 7:06 PM Warner Losh <imp@bsdimp.com> wrote:

> The bsd-user that is in tree doesn't work. I've been trying to catch up to
> qemu head of tree, but I'm only up to 3.2... chances are the bsd-user
> changes will not change the state of things...
>

Ah good to know. Would you all prefer I don't modify it at all, to try and
keep the code "pristine"? Or is it OK to keep the patch as is?

[-- Attachment #2: Type: text/html, Size: 790 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14  9:09   ` Laurent Vivier
  2020-01-14 16:15     ` Paolo Bonzini
@ 2020-01-17 19:28     ` Josh Kunz
  1 sibling, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-17 19:28 UTC (permalink / raw)
  To: Laurent Vivier
  Cc: QEMU Developers, Riku Voipio, Alex Bennée, armbru, Paolo Bonzini

On Tue, Jan 14, 2020 at 1:09 AM Laurent Vivier <laurent@vivier.eu> wrote:
> This is really a special case as the flags are all given at the same
> time, could you use directly qemu_set_log() in main()?

Fixed in v2.

> > +/* Remove (subtract) the given log flags from the current log mask. */
> > +static inline void qemu_del_log(int log_flags)
> > +{
> > +    qemu_set_log(qemu_loglevel & ~(log_flags));
> > +}
>
> Unused and unneeded.

Removed in v2. Also removed `qemu_add_log`.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 2/4] linux-user: Use `qemu_log' for strace
  2020-01-14 10:55   ` Alex Bennée
@ 2020-01-17 19:28     ` Josh Kunz
  0 siblings, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-17 19:28 UTC (permalink / raw)
  To: Alex Bennée; +Cc: QEMU Developers, Riku Voipio, Laurent Vivier, armbru

On Tue, Jan 14, 2020 at 2:56 AM Alex Bennée <alex.bennee@linaro.org> wrote:
> Could we cut out the middle-man and just qemu_add_log(LOG_STRACE) here
> and drop the enable_strace variable.

This code has been re-factored based on Laurent's comments. In v2
`enable_strace` is still needed to avoid QEMU_LOG/-d overwriting the
mask set by -strace.

> Please don't drop the brace - c.f. CODING_STYLE.rst

Thanks for the catch!

> Side note, print_taken_signal might want to consider using the
> qemu_log_lock() functionality to keep sequential qemu_log's together. I
> suspect you might want to do the same for syscalls.

This is likely true, but outside the scope of this patch (this patch
preserves the current bad behavior). When I get some spare time I'll
try and address this in a follow up patch series.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging
  2020-01-14 10:42   ` Alex Bennée
@ 2020-01-17 19:28     ` Josh Kunz
  0 siblings, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-01-17 19:28 UTC (permalink / raw)
  To: Alex Bennée; +Cc: QEMU Developers, Riku Voipio, Laurent Vivier, armbru

On Tue, Jan 14, 2020 at 2:43 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> As Laurent said I think LOG_UNIMP is perfectly fine for stuff we haven't
> done. I don't think any of the cases warrant LOG_GUEST_ERROR.

I've replaced `LOG_USER` with `LOG_UNIMP`. Didn't catch that mask at
first, LOG_UNIMP is indeed a better fit for most of these.

> I'm not sure want to bother with this. I know we like to avoid
> regression but isn't this all debug log stuff? If we must keep it can we
> invert the variable to save the initialisation.

I'm all for removing it. I agree that it would be pretty odd for
someone to depend on debug log output in this way. I've removed this
in v2. It is a backwards incompatibility though, so I'm happy to
re-add the fix if people want it.

> I mean we jumped through hoops to maintain backwards compatibility and
> then added new output? Also LOG_STRACE doesn't exist yet.

This is leftover debug statements. I've removed it.

> I'm not sure we shouldn't just be asserting this case above. The
> comments imply it is a bug on our part. The rest look like good cases
> for LOG_UNIMP.

Switched to an assert in v2.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-16 23:12   ` Josh Kunz
@ 2020-01-20 11:36     ` Alex Bennée
  2020-02-04  2:55       ` Josh Kunz
  0 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2020-01-20 11:36 UTC (permalink / raw)
  To: Josh Kunz; +Cc: armbru, Riku Voipio, qemu-devel, Laurent Vivier


Josh Kunz <jkz@google.com> writes:

> On Tue, Jan 14, 2020 at 3:02 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>
>>
>> Josh Kunz <jkz@google.com> writes:
>>
>> <snip>
>> >
>> > Not tested:
>> >   * Build/logging with bsd-user. I do not have easy access to a BSD
>> > system.
>>
>> If you have the time we have vm-build-netbsd:
>>
>>   make vm-build-netbsd EXTRA_CONFIGURE_OPTS="--disable-system"
>>
>> Which will create a NetBSD image for you and run the build through it.
>> Other images are available ;-)
>>
>
> This works, but it looks like it only runs the tests on BSD, even with
> `configure --enable-bsd-user` first. I don't see the bsd-user binaries
> being produced in the output of this command.

Ahh the default build target for the BSDs is "check" but as bsd-user
doesn't have any checks it doesn't end up building. You can force it
with

  make vm-build-netbsd EXTRA_CONFIGURE_OPTS="--disable-system" BUILD_TARGET="all"

It would be worth plumbing in the tests/tcg tests at some point. I
suspect most of the user-mode tests are more POSIX than Linux.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH 0/4] migration: Replace gemu_log with qemu_log
  2020-01-20 11:36     ` Alex Bennée
@ 2020-02-04  2:55       ` Josh Kunz
  0 siblings, 0 replies; 21+ messages in thread
From: Josh Kunz @ 2020-02-04  2:55 UTC (permalink / raw)
  To: Alex Bennée; +Cc: QEMU Developers, Riku Voipio, Laurent Vivier, armbru

On Mon, Jan 20, 2020 at 3:36 AM Alex Bennée <alex.bennee@linaro.org> wrote:
> Ahh the default build target for the BSDs is "check" but as bsd-user
> doesn't have any checks it doesn't end up building. You can force it
> with
>
>   make vm-build-netbsd EXTRA_CONFIGURE_OPTS="--disable-system" BUILD_TARGET="all"
>
> It would be worth plumbing in the tests/tcg tests at some point. I
> suspect most of the user-mode tests are more POSIX than Linux.

Neat, thanks Alex! I've run this and verified the BSD user-mode binaries built.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-02-04  2:58 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14  3:01 [PATCH 0/4] migration: Replace gemu_log with qemu_log Josh Kunz
2020-01-14  3:01 ` [PATCH 1/4] linux-user: Use `qemu_log' for non-strace logging Josh Kunz
2020-01-14  8:28   ` Laurent Vivier
2020-01-14  8:30   ` Laurent Vivier
2020-01-14 10:42   ` Alex Bennée
2020-01-17 19:28     ` Josh Kunz
2020-01-14  3:01 ` [PATCH 2/4] linux-user: Use `qemu_log' for strace Josh Kunz
2020-01-14  9:09   ` Laurent Vivier
2020-01-14 16:15     ` Paolo Bonzini
2020-01-17 19:28     ` Josh Kunz
2020-01-14 10:55   ` Alex Bennée
2020-01-17 19:28     ` Josh Kunz
2020-01-14  3:01 ` [PATCH 3/4] linux-user: remove gemu_log from the linux-user tree Josh Kunz
2020-01-14 10:56   ` Alex Bennée
2020-01-14  3:01 ` [PATCH 4/4] bsd-user: Replace gemu_log with qemu_log Josh Kunz
2020-01-14  3:06 ` [PATCH 0/4] migration: " Warner Losh
2020-01-16 23:13   ` Josh Kunz
2020-01-14 11:02 ` Alex Bennée
2020-01-16 23:12   ` Josh Kunz
2020-01-20 11:36     ` Alex Bennée
2020-02-04  2:55       ` Josh Kunz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).