From patchwork Thu Oct 17 13:15:40 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: 176616 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp937115ill; Thu, 17 Oct 2019 06:35:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2OQGyY8KqmctiwYpJtFQFFc/T+n5QoIc8AEp2Red3M7OPX1XFcd9TrXeCX46UN/1NHYSg X-Received: by 2002:a17:907:429d:: with SMTP id ny21mr3627906ejb.176.1571319318813; Thu, 17 Oct 2019 06:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571319318; cv=none; d=google.com; s=arc-20160816; b=w7xzeB35hP/i2iwzGkqfKMVVffzjEgzZR7DRr5wehTZSGRsOKVZmau7voNwV+9Muwy xRu2UPXM9UPj9ItWwJ7on/Zy3Da96prWwRXb6RiGi/Z1bDSNHkAYoTBEYpXUhZNtWp5B mkop1+cCIpVOdydUfhphYTWtDqTuuoG2FbK/Wq0YJyvs3CjPYmBYFgybBcFt8Oba5eCC R+cRV9Pq+KoD0LLs6+XdbfgVIKHgnZj4AwfPVaYjID+IAMOVpZOEmEGlSgZ2kdAZfIRo otYKoFy255UH4JVykD+Ki/9+RUQJrm2gJrGSQLUeFeaef2o9TfIa45fRk7u4Eg5SBJIP w1Ww== 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=Zh74vUOPTp0gxSs7A8PYljuKuP1xzpygb/d2J7Y2vUI6MpbJLXYH0N9nNP1NYXsGMq ryr24VfWZSQwJY74oepuXMSXewW6hwNhWZJcligjR+uXu3NPs08fukCksF1H1LxiWRhQ h1I+OJd/+drl4sIoEmKrPcFHStDTYkyAtIGw0UdSFUw+DHRxs6zJlDZWyKQfDgy1L2Jo 5c7kQX5fNxp3XW+AKM6RhHOV+GfIP3NSbhF8hqoKbnkTLvINmhODQU7rgjm4OoKoKpoM mbotBowGCbgtQZFdF9oM/dKAWL0F1lIB0wPz6Q186bLPy5pvqMe7JW9OogXBUS9Bxw/l wFPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="dSi9RR/F"; 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 dc10si1347833ejb.81.2019.10.17.06.35.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Oct 2019 06:35:18 -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="dSi9RR/F"; 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]:47932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5vw-0005BB-Uq for patch@linaro.org; Thu, 17 Oct 2019 09:35:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34012) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5dm-00089i-PD for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5dl-0005Ux-AL for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:30 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iL5dk-0005UM-MC for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:16:29 -0400 Received: by mail-wr1-x444.google.com with SMTP id r3so2319449wrj.6 for ; Thu, 17 Oct 2019 06:16:28 -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=dSi9RR/FAGfahfUx6d4zyjw8bGdRDSXq3te/ysoRb208aIloKC9qhn98xhhuTPVYgi RGedQoImgYAVvdFeTtGCE/tKLCHQCkTmZuAV0RMxg3Bcu0Qff4aUSBmePb2EC2F9HR9E 1Ei5VLvKMifhV3xzkjU6Kx5hAcXl4i+cnp0eOAAfsCAMu2Z2UwsUgpp6KfDBcrQr6Lf2 QCJeQBUk1BRKo22B0IdFY4otpsCY9tuQAj3E3A3z2C03M81S8OsyzCitZNdvZqOfZzvj Q0V88vkrv5zNKELfrGYBn0lIapNCmx0IisKMeRJ7cag3Q0mfiPqndRB2OAxksLCRFpxB zerg== 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=rsVcXhrEjsFnrTJGL7QxlBxXRh/IiUuz/yAokWNGy5jIE7JSnewu3/eqz9iv03vagu k6x94Ksb5zFdNAkRIbuhrNiw5HTRSoz8uL3ZlcrfilZzHIYjIGtM3rKwQym+tDzoL1VV +GTMBO6Q/JBPmBsXyZxI4XjlCXiCwQltWk5IRI7XpuCokXXNJg4gsBIAI9Ya1JZg9hNa ihco3c+WfIgqNp3Ha9hN7d9jZB/LxRQM3ruxid+/T9QuTpW/mYplbfDTg/iHtdraLR2b h1nE30tJVxP09ORIfYmPO58nqE3z9wdM6g4i+JRrawrs43rdYiUlAJpuGFBK5cA25R9/ RiMA== X-Gm-Message-State: APjAAAWhsyu64r1eN52/hjXA1otVUF5DfYNOx2Zar9DF/YkbWmfLrHg5 GXIz05cvuXDY240fkTtPwhSJtw== X-Received: by 2002:a05:6000:11c5:: with SMTP id i5mr2956100wrx.303.1571318187541; Thu, 17 Oct 2019 06:16:27 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v11sm1984454wml.30.2019.10.17.06.16.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 06:16:26 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BB24B1FFA5; Thu, 17 Oct 2019 14:16:17 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v6 19/54] *-user: plugin syscalls Date: Thu, 17 Oct 2019 14:15:40 +0100 Message-Id: <20191017131615.19660-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017131615.19660-1-alex.bennee@linaro.org> References: <20191017131615.19660-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::444 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; }