From patchwork Mon Oct 14 10:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 176158 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4355857ill; Mon, 14 Oct 2019 04:06:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQkMTEbdSL9dzLVZjF70Rp5KKb0Kv8KsUW+OLWDdtQaxXyfIrt6x7C5zhBw0OxqOa1l0xD X-Received: by 2002:a50:ee81:: with SMTP id f1mr27250630edr.243.1571051193691; Mon, 14 Oct 2019 04:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571051193; cv=none; d=google.com; s=arc-20160816; b=TxYh6r0fdZr2YI/Q+U8MO+gxb9CCWPw1rdnt0IKrBJsieI968IjWMT524qfe09PRwL Ch46WpapiWuWe9lG8IDlHqRkXQn3X5f28GI0G+TEwAdLIztKMEO9/Oj6W/FkdKlG/6Us hdcZropvgRM5JuWqGhh28+JMxCAMlCx0diMHmMJ5VqPrA1hCpP6LJNewHLpuBVJGdX+j wMFvwU6NH5BIyXCb7ZH0Zolavn1siR1b7rdMBst5k0pkwpi2W/wRBW2FP3TfFiX7Ifyg czAu/zpOR+ei8GaXnHAMcH86HQVsUI4elNk2EYT1pd0nT457BwQJhy5PLPsdmH0RFc8V uhUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=etDCqYHg2LYQtZa+T5XCKHLqmFEuamg260f6vcRF/Qs=; b=TGbALdLevvGmZgUkQmwiqxG28ueJJuwXKel2pLW+SuZwXPE2Gsg9EoatuDDkixADh7 TDhc1x4mOkbxrESoONFb/7nISKms9Xlj7ocoMmg7q8f2XA6N8/SMU+3imxmqh6nsMIoA i4wg28bsYrKeOnje0EBxbVobH+ynOE0dHrE/MmD3y8VUUbJuMNYU+JBuRFpkm7Y9UrIb z4qU6ERq4nGn2T9qK/kOVzQVXgCYZJmzymcy/hlXlGInkeaiU+fr1TBjQzgjt1jKJKAe R3ml0+Xx8sfu02ABEsgrOQ/Cl7Xogq0VUB6Ab5LdxKsaXsOKINLzNTijmW0ZCUMwHLrY tj7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C4nPEaYI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v27si10669219ejb.182.2019.10.14.04.06.33 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 04:06:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C4nPEaYI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJyBM-0005XL-3R for patch@linaro.org; Mon, 14 Oct 2019 07:06:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44634) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJxvS-0007Ti-DU for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:50:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJxvQ-0006Db-UX for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:50:06 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39493) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJxvQ-0006CO-Nj for qemu-devel@nongnu.org; Mon, 14 Oct 2019 06:50:04 -0400 Received: by mail-wm1-x342.google.com with SMTP id v17so16247101wml.4 for ; Mon, 14 Oct 2019 03:50:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=etDCqYHg2LYQtZa+T5XCKHLqmFEuamg260f6vcRF/Qs=; b=C4nPEaYI9W5ytcgj11DsaGHtoskijPN7u8oRbLulaXg6uAZT6Be8Zaj1AoGximIrTs wpsciD5PvhfZ9EzVnzl3JKUqcjAAqYaVhuB+YFZUR81xuj+Og6ifsJweMhspHsFKW0Rq AfxzUjgzbLdNqjYWqahOBhk0QY5iIoz1GpgudxbkhtOf+sNVbC8rhamNEOfOoYVfniYo 4fQlJ4Aab1fInh+qmD/11sszXOzky5S3FYhTVCXxm1Gowbrk8kIDbzvv7fqB/k1J0hyC 6xXH7EtR+dI4rE6t5e3rcEb5iqtkAA21UF9KMqlNZG3Pb3urT8jqyD0l8aCRH0FMisZd ZliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=etDCqYHg2LYQtZa+T5XCKHLqmFEuamg260f6vcRF/Qs=; b=RnQuesIQFbYShHfW9As7JOh5b0ZOCO1m1v5bz7EdQddTFSktH6V6tH56uWEguRVVlo a28P9wuCMLmNIljd5vftvPHYwNKE0tOT8uPLU0L8QshoP/aYgudAkU9EGdnKor1QVaUY M+EN01Ad/la8xdjFn5mDo5uvzSOQ9AKT4hQh+hAc0yfCUmKZ0a5kfWcQbUJ2aWgbdCOZ VnQDImupckITO5Kyn5ATGQ2W+raFbQ4aW5NkzCODd2c/g8NZB+ggtBnzl8IcPy+b4meZ 2Ul6CBGb9YEW5NqICaNCgDrZf1CKgI7hFZ4K3wI5llTPWoFqDH0NH4Z/aUXX+263gJon Br8A== X-Gm-Message-State: APjAAAUMSLWaD3g2DZj7BEanLEa8HTeKye5C3ND5FNeTa9ZYxLL/GZX4 qbOhXXnrC0gM12dCGJeopbsuvQ== X-Received: by 2002:a7b:caea:: with SMTP id t10mr11165741wml.38.1571050203567; Mon, 14 Oct 2019 03:50:03 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a192sm15972917wma.1.2019.10.14.03.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 03:49:59 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E298D1FFA3; Mon, 14 Oct 2019 11:49:53 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 20/55] *-user: plugin syscalls Date: Mon, 14 Oct 2019 11:49:13 +0100 Message-Id: <20191014104948.4291-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014104948.4291-1-alex.bennee@linaro.org> References: <20191014104948.4291-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: robert.foley@futurewei.com, Riku Voipio , Richard Henderson , Laurent Vivier , peter.puhov@futurewei.com, aaron@os.amperecomputing.com, cota@braap.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" To avoid too much duplication add a wrapper that the existing trace and the new plugin calls can live in. We could move the -strace code here as well but that is left for a future series as the code is subtly different between the bsd and linux. Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson [AJB: wrap in syscall-trace.h, expand commit msg] Signed-off-by: Alex Bennée --- bsd-user/syscall.c | 21 +++++++++++++------ include/user/syscall-trace.h | 40 ++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 7 ++++--- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 include/user/syscall-trace.h -- 2.20.1 diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 84a983a9a1..0d45b654bb 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -26,6 +26,7 @@ #include "qemu.h" #include "qemu-common.h" +#include "user/syscall-trace.h" //#define DEBUG @@ -322,7 +323,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("freebsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_freebsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -403,7 +405,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_freebsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -421,7 +424,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("netbsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_netbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -479,7 +484,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_netbsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; @@ -497,7 +503,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, #ifdef DEBUG gemu_log("openbsd syscall %d\n", num); #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + + record_syscall_start(cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, 0, 0); + if(do_strace) print_openbsd_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -555,7 +563,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_openbsd_syscall_ret(num, ret); - trace_guest_user_syscall_ret(cpu, num, ret); + + record_syscall_return(cpu, num, ret); return ret; efault: ret = -TARGET_EFAULT; diff --git a/include/user/syscall-trace.h b/include/user/syscall-trace.h new file mode 100644 index 0000000000..9e60473643 --- /dev/null +++ b/include/user/syscall-trace.h @@ -0,0 +1,40 @@ +/* + * Common System Call Tracing Wrappers for *-user + * + * Copyright (c) 2019 Linaro + * Written by Alex Bennée + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _SYSCALL_TRACE_H_ +#define _SYSCALL_TRACE_H_ + +/* + * These helpers just provide a common place for the various + * subsystems that want to track syscalls to put their hooks in. We + * could potentially unify the -strace code here as well. + */ + +static inline void record_syscall_start(void *cpu, 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) +{ + trace_guest_user_syscall(cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); + qemu_plugin_vcpu_syscall(cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); +} + +static inline void record_syscall_return(void *cpu, int num, abi_long ret) +{ + trace_guest_user_syscall_ret(cpu, num, ret); + qemu_plugin_vcpu_syscall_ret(cpu, num, ret); +} + + +#endif /* _SYSCALL_TRACE_H_ */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e2af3c1494..77e87a959f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -112,6 +112,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "user/syscall-trace.h" #include "qapi/error.h" #include "fd-trans.h" @@ -11981,8 +11982,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } #endif - trace_guest_user_syscall(cpu, num, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8); + record_syscall_start(cpu, num, arg1, + arg2, arg3, arg4, arg5, arg6, arg7, arg8); if (unlikely(do_strace)) { print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6); @@ -11994,6 +11995,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg5, arg6, arg7, arg8); } - trace_guest_user_syscall_ret(cpu, num, ret); + record_syscall_return(cpu, num, ret); return ret; }