From patchwork Fri Oct 25 06:36:35 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: 177657 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3269917ill; Fri, 25 Oct 2019 00:17:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMojF7VOPBMMHzGwQXozKUhK358S0NS0XKnMEe6+Mqs8U4JW9grqseHE79j2WHeiCxtZzG X-Received: by 2002:a37:4812:: with SMTP id v18mr1449031qka.27.1571987869228; Fri, 25 Oct 2019 00:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571987869; cv=none; d=google.com; s=arc-20160816; b=ijMcK9Rq/rrZfllcpzEfR/MykCHNqRR/+BhX/6NOYumsYm3YuAdj2ELUY9mAvLhygJ qhc6UdyDxHjSIoPQ/d58Kc3VFd5RMzwldP3vomU+5iAqyYQVDAjqaO1ee/2Wa+PYyW3m 24G4oaUNf2fp5PGc18uE95HHLDwCnF4oxry6dPGD7GE9NCGG4kbDJV3boJBSCYzBVAfa HuTZnxfgevzdqPI5kRmWjTc0RT/1jFaGLgzC4+WCDTRXRC4lc2Ad3s16Hsez9F1DyrsZ eD0CGqQMIdRCmzDtja5m9AzVoPh2/15UZzsPxVMMARx1S2y9WZClF78OStt1UBD5FmL3 lUJQ== 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=x47k/VxsI+WVM0DfT2oDeIPT5nZyOR1szQ7TpFo9UBw=; b=0aZgESAKHJM7KvpJBgPuExTAXG4UiDqGjriClRjQTkXlliZWu3HNXprgRCtx38srbX 8GSL7wzyITLqJ5uyl2L+p7ioU9BCFj9bgA/f8blZVN2rMpaLYXK9Dy0+WfiygFHE+ylp ozU0371gw/wPfsHpITnoZvm0yj6e2iFVk6gxcDv+rTLZwF+PsjRsAxx/XHB7phyDdXt9 bK0A6ru3FmverAOYd+rfa75awg2WHUVwl/O/Y3kthKNWnDNm0bkNw9qZ6TdnwssZw9sw Ilrx66Oqtbp2Yq1e4EU7DEN1f+VZruzT5+IW+gJBYkWqTnBNZja0PcYRWsyVLLmGhP5t DQmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T0izpLM0; 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 k4si746403qtq.10.2019.10.25.00.17.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Oct 2019 00:17:49 -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=T0izpLM0; 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]:56632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNtr2-0005Vz-7j for patch@linaro.org; Fri, 25 Oct 2019 03:17:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38175) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNtWY-0003KN-EG for qemu-devel@nongnu.org; Fri, 25 Oct 2019 02:56:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNtWW-0007do-T2 for qemu-devel@nongnu.org; Fri, 25 Oct 2019 02:56:38 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:42629) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNtWW-0007bu-Lq for qemu-devel@nongnu.org; Fri, 25 Oct 2019 02:56:36 -0400 Received: by mail-wr1-x441.google.com with SMTP id r1so951354wrs.9 for ; Thu, 24 Oct 2019 23:56:36 -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=x47k/VxsI+WVM0DfT2oDeIPT5nZyOR1szQ7TpFo9UBw=; b=T0izpLM0apia/pOyYCgJ7Db/DMNeS7kKrQvA1yEhusGCcxMn3U9Rw1gV5r7Dd4m6Qh oEkzDpXyNyxomqv4o6oBLF3qqpuGV/uaTNE8qVdAn0I3wNtcGt0at6sMSTPqRgAYibhQ yDf2TMX3Lygdt5iUeXbWN8Ije0qEf1+W3OUtFHfngzd01fPMCcNli8wZltJozrhc72tm WMsTpZ6uuoeNA3hMNTVgQuk2kpeygarjm3Fsn/HchJcBuLV8MHTEk4X8H+8RV44azX/x mNMkIE6cPOEI+/15NaBv7GeY+6UtFtcVD+txKkkD4ib8hA/QupE8AWSjTq86/JP8A0Rx McDA== 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=x47k/VxsI+WVM0DfT2oDeIPT5nZyOR1szQ7TpFo9UBw=; b=L+wuIQsNj2nNTAWVrUjY0OsCLH6q1hkBBnik1ImDCefJMfYJJaIVrZ4kW3xqsIdJGR WW64syQ9NgQUXcyvWvik7yzFMW9j8QMOuTwXKiO7YkJ4coOXpmtCnyD+PVaCLBWcae2v LRfFd919U3Ewjr0qVmT49ZLRfv1U6u3rdVBB9BXWaYyt4S9pUE0l4u/1OvPZ7OVqpCts PsBtr9kDZ4t2jIebbuGftiwXUZl6dadpXetuyHN3jsWN6FZn6z2PCBzXOIjgTsu8vDAg yR7jepQMtNcDfhsCGAxZxTgRva/8+qdUuq7713Nxs4BMubT4Ekd6gfs8iIWRt2tO/R6Z RVTQ== X-Gm-Message-State: APjAAAU4al9P8WEVG0C5zv6zp0aJhvvFPa3I4Z+XG58kzKNee2ddKVBW eC0eE93+ZLZt0f5+8kNAWhkFeg== X-Received: by 2002:a5d:544d:: with SMTP id w13mr1363580wrv.19.1571986594761; Thu, 24 Oct 2019 23:56:34 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r5sm1724815wrs.57.2019.10.24.23.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 23:56:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1DAC71FFBC; Fri, 25 Oct 2019 07:37:17 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL v2 35/73] *-user: plugin syscalls Date: Fri, 25 Oct 2019 07:36:35 +0100 Message-Id: <20191025063713.23374-36-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191025063713.23374-1-alex.bennee@linaro.org> References: <20191025063713.23374-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::441 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: Riku Voipio , Richard Henderson , qemu-devel@nongnu.org, Laurent Vivier , "Emilio G. Cota" , =?utf-8?q?Ale?= =?utf-8?b?eCBCZW5uw6ll?= 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 -- 2.20.1 diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 84a983a9a12..0d45b654bb3 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 00000000000..9e604736433 --- /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 f1ab81b9177..be2a3b93b3a 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" @@ -11983,8 +11984,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); @@ -11996,6 +11997,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; }