From patchwork Wed Sep 13 11:18:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 9951171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E68196038F for ; Wed, 13 Sep 2017 11:19:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6BBF28415 for ; Wed, 13 Sep 2017 11:19:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C89F428D33; Wed, 13 Sep 2017 11:19:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C14128415 for ; Wed, 13 Sep 2017 11:19:58 +0000 (UTC) Received: from localhost ([::1]:41640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds5i1-0006e7-CI for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Sep 2017 07:19:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds5h1-0006b6-1A for qemu-devel@nongnu.org; Wed, 13 Sep 2017 07:18:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds5gx-0007CL-RF for qemu-devel@nongnu.org; Wed, 13 Sep 2017 07:18:54 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:47205) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds5gx-0007Bv-G2 for qemu-devel@nongnu.org; Wed, 13 Sep 2017 07:18:51 -0400 Received: from correu-1.ac.upc.es (correu-1.ac.upc.es [147.83.30.91]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v8DBIfZB010322; Wed, 13 Sep 2017 13:18:41 +0200 Received: from localhost (unknown [132.68.137.204]) by correu-1.ac.upc.es (Postfix) with ESMTPSA id 2784213E; Wed, 13 Sep 2017 13:18:36 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 14:18:35 +0300 Message-Id: <150530151489.10902.6711543027869901344.stgit@frigg.lan> X-Mailer: git-send-email 2.14.1 In-Reply-To: <150529642278.10902.18234057937634437857.stgit@frigg.lan> References: <150529642278.10902.18234057937634437857.stgit@frigg.lan> User-Agent: StGit/0.18 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id v8DBIfZB010322 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v6 21/22] instrument: Add event 'guest_user_syscall_ret' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Markus Armbruster , Laurent Vivier , "Emilio G. Cota" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: LluĂ­s Vilanova --- bsd-user/syscall.c | 3 +++ instrument/control.c | 15 +++++++++++++++ instrument/events.h | 5 +++++ instrument/events.inc.h | 13 +++++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 13 +++++++++++++ linux-user/syscall.c | 1 + stubs/instrument.c | 2 ++ 8 files changed, 53 insertions(+) diff --git a/bsd-user/syscall.c b/bsd-user/syscall.c index 0d92eaf8c4..fb468c0574 100644 --- a/bsd-user/syscall.c +++ b/bsd-user/syscall.c @@ -407,6 +407,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_freebsd_syscall_ret(num, ret); + instr_guest_user_syscall_ret(cpu, num, ret); trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: @@ -485,6 +486,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_netbsd_syscall_ret(num, ret); + instr_guest_user_syscall_ret(cpu, num, ret); trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: @@ -563,6 +565,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, #endif if (do_strace) print_openbsd_syscall_ret(num, ret); + instr_guest_user_syscall_ret(cpu, num, ret); trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: diff --git a/instrument/control.c b/instrument/control.c index 45efeef7ac..e58a38b7db 100644 --- a/instrument/control.c +++ b/instrument/control.c @@ -211,3 +211,18 @@ SYM_PUBLIC void qi_event_set_guest_user_syscall( #endif instr_set_event(guest_user_syscall, fn); } + + +void (*instr_event__guest_user_syscall_ret)( + QICPU vcpu, uint64_t num, uint64_t ret); + +SYM_PUBLIC void qi_event_set_guest_user_syscall_ret( + void (*fn)(QICPU vcpu, uint64_t num, uint64_t ret)) +{ + ERROR_IF(!instr_get_state(), "called outside instrumentation"); + ERROR_IF(!tcg_enabled(), "called without TCG"); +#if !defined(CONFIG_USER_ONLY) + ERROR_IF(true, "called in full-system mode"); +#endif + instr_set_event(guest_user_syscall_ret, fn); +} diff --git a/instrument/events.h b/instrument/events.h index 8c944e1f91..6197ece466 100644 --- a/instrument/events.h +++ b/instrument/events.h @@ -75,6 +75,11 @@ static inline void instr_guest_user_syscall( CPUState *vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8); +extern void (*instr_event__guest_user_syscall_ret)( + QICPU vcpu, uint64_t num, uint64_t ret); +static inline void instr_guest_user_syscall_ret( + CPUState *vcpu, uint64_t num, uint64_t ret); + #include "instrument/events.inc.h" diff --git a/instrument/events.inc.h b/instrument/events.inc.h index e2f4315fb0..d31dec54b8 100644 --- a/instrument/events.inc.h +++ b/instrument/events.inc.h @@ -94,3 +94,16 @@ static inline void instr_guest_user_syscall( instr_set_state(INSTR_STATE_DISABLE); } } + +static inline void instr_guest_user_syscall_ret( + CPUState *vcpu, uint64_t num, uint64_t ret) +{ + void (*cb)(QICPU vcpu, uint64_t num, uint64_t ret) + = instr_get_event(guest_user_syscall_ret); + if (cb) { + instr_set_state(INSTR_STATE_ENABLE); + QICPU vcpu_ = instr_cpu_to_qicpu(vcpu); + (*cb)(vcpu_, num, ret); + instr_set_state(INSTR_STATE_DISABLE); + } +} diff --git a/instrument/load.c b/instrument/load.c index a76f76e1d1..be13a90286 100644 --- a/instrument/load.c +++ b/instrument/load.c @@ -165,6 +165,7 @@ InstrUnloadError instr_unload(const char *id) instr_set_event(guest_mem_before_trans, NULL); instr_set_event(guest_mem_before_exec, NULL); instr_set_event(guest_user_syscall, NULL); + instr_set_event(guest_user_syscall_ret, NULL); instr_cpu_stop_all_end(&info); cpu_list_unlock(); diff --git a/instrument/qemu-instr/control.h b/instrument/qemu-instr/control.h index 136058af4f..bc4e49bef1 100644 --- a/instrument/qemu-instr/control.h +++ b/instrument/qemu-instr/control.h @@ -157,6 +157,19 @@ void qi_event_set_guest_user_syscall( uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8)); +/* + * Finish executing a guest system call in syscall emulation mode. + * + * @num: System call number. + * @ret: System call result value. + * + * Mode: user + * Targets: TCG(all) + * Time: exec + */ +void qi_event_set_guest_user_syscall_ret( + void (*fn)(QICPU vcpu, uint64_t num, uint64_t ret)); + #ifdef __cplusplus } #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c9f0b9fa56..44b91e3c52 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12398,6 +12398,7 @@ fail: #endif if(do_strace) print_syscall_ret(num, ret); + instr_guest_user_syscall_ret(cpu, num, ret); trace_guest_user_syscall_ret(cpu, num, ret); return ret; efault: diff --git a/stubs/instrument.c b/stubs/instrument.c index bb585c69ce..ae581174db 100644 --- a/stubs/instrument.c +++ b/stubs/instrument.c @@ -69,3 +69,5 @@ void (*instr_event__guest_mem_before_exec)( void (*instr_event__guest_user_syscall)( QICPU vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8); +void (*instr_event__guest_user_syscall_ret)( + QICPU vcpu, uint64_t num, uint64_t ret);