From patchwork Fri Jun 24 09:53:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 640130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rbZ5d4PzSz9sBX for ; Fri, 24 Jun 2016 20:17:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=JZ2/xDc/; dkim-atps=neutral Received: from localhost ([::1]:42365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGOB9-0003lf-Hb for incoming@patchwork.ozlabs.org; Fri, 24 Jun 2016 06:17:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGNoD-000154-Tu for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGNo8-0003XR-Vq for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:56 -0400 Received: from mail-lf0-x22f.google.com ([2a00:1450:4010:c07::22f]:34792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGNo8-0003WM-Jt for qemu-devel@nongnu.org; Fri, 24 Jun 2016 05:53:52 -0400 Received: by mail-lf0-x22f.google.com with SMTP id h129so112859541lfh.1 for ; Fri, 24 Jun 2016 02:53:52 -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; bh=4+K/vMkAkdl+zusC4hITcI02gY44GzZxqDw7mAN8ei4=; b=JZ2/xDc/3a/inkUI92mtTnhuxWYNuVQmWlcnmEZpcm9nSp0XNZFqDgRcyvyk4VUoSA 2njvaItVzwisreXNCHqMdOl3fw5d5ZAIFyut0DILjl8Ub0K2jvv9r7nlz0EOzj5uvcwk i+cTt/rcQUJw7g14HfZ6XNmgVRt5RFnEHXXZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4+K/vMkAkdl+zusC4hITcI02gY44GzZxqDw7mAN8ei4=; b=TUPg5a+rfy9tvnkN0ilabgtY2/fFvpe3hxPIrJpBoTQk93g63HHMh2BP+k8FFxHwtR ReawgvhRlDt0GL7xzR1kiWKRF7Q0nQd1HILpb+UWaqkAgELBlMuj25NaXn8WMBHDvgmJ Qz4QtucJxNAqfaoK/gV5TCdTugxMYymuXjqet9nHweK9OZ8PLIIm/TpIBfV1tMxIk0eE 0bkW9sWPIiWYVoQMBT3gfLRHN4a/ItbMBbfkIs/bNIjyuWjN89fqkastUxeAIE+QY0HC k66dQg/ofGE3BuDTaKSGrLgRZlB7zZDdNPCwYvq6WTaRik9hV8dMPZRPMnoE9QwRtURt FoOw== X-Gm-Message-State: ALyK8tJLRuMXlYIX7TC9QegU64QYH3sPh9eiIG5IwUE1Pd05f0I7VriQs8kyWATSpQ4HuMDJ X-Received: by 10.25.157.142 with SMTP id g136mr1157779lfe.216.1466762031723; Fri, 24 Jun 2016 02:53:51 -0700 (PDT) Received: from beaming.home (85-76-80-69-nat.elisa-mobile.fi. [85.76.80.69]) by smtp.gmail.com with ESMTPSA id o137sm798203lfe.2.2016.06.24.02.53.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jun 2016 02:53:51 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 24 Jun 2016 12:53:17 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22f Subject: [Qemu-devel] [PULL 22/24] linux-user: Provide safe_syscall for aarch64 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: Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Signed-off-by: Riku Voipio [RV] Updated syscall argument comment to match code --- linux-user/host/aarch64/hostdep.h | 23 +++++++++ linux-user/host/aarch64/safe-syscall.inc.S | 75 ++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 linux-user/host/aarch64/safe-syscall.inc.S diff --git a/linux-user/host/aarch64/hostdep.h b/linux-user/host/aarch64/hostdep.h index 7609bf5..b79eaf1 100644 --- a/linux-user/host/aarch64/hostdep.h +++ b/linux-user/host/aarch64/hostdep.h @@ -12,4 +12,27 @@ #ifndef QEMU_HOSTDEP_H #define QEMU_HOSTDEP_H +/* We have a safe-syscall.inc.S */ +#define HAVE_SAFE_SYSCALL + +#ifndef __ASSEMBLER__ + +/* These are defined by the safe-syscall.inc.S file */ +extern char safe_syscall_start[]; +extern char safe_syscall_end[]; + +/* Adjust the signal context to rewind out of safe-syscall if we're in it */ +static inline void rewind_if_in_safe_syscall(void *puc) +{ + struct ucontext *uc = puc; + __u64 *pcreg = &uc->uc_mcontext.pc; + + if (*pcreg > (uintptr_t)safe_syscall_start + && *pcreg < (uintptr_t)safe_syscall_end) { + *pcreg = (uintptr_t)safe_syscall_start; + } +} + +#endif /* __ASSEMBLER__ */ + #endif diff --git a/linux-user/host/aarch64/safe-syscall.inc.S b/linux-user/host/aarch64/safe-syscall.inc.S new file mode 100644 index 0000000..58a2329 --- /dev/null +++ b/linux-user/host/aarch64/safe-syscall.inc.S @@ -0,0 +1,75 @@ +/* + * safe-syscall.inc.S : host-specific assembly fragment + * to handle signals occurring at the same time as system calls. + * This is intended to be included by linux-user/safe-syscall.S + * + * Written by Richard Henderson + * Copyright (C) 2016 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + + .global safe_syscall_base + .global safe_syscall_start + .global safe_syscall_end + .type safe_syscall_base, #function + .type safe_syscall_start, #function + .type safe_syscall_end, #function + + /* This is the entry point for making a system call. The calling + * convention here is that of a C varargs function with the + * first argument an 'int *' to the signal_pending flag, the + * second one the system call number (as a 'long'), and all further + * arguments being syscall arguments (also 'long'). + * We return a long which is the syscall's return value, which + * may be negative-errno on failure. Conversion to the + * -1-and-errno-set convention is done by the calling wrapper. + */ +safe_syscall_base: + .cfi_startproc + /* The syscall calling convention isn't the same as the + * C one: + * we enter with x0 == *signal_pending + * x1 == syscall number + * x2 ... x7, (stack) == syscall arguments + * and return the result in x0 + * and the syscall instruction needs + * x8 == syscall number + * x0 ... x7 == syscall arguments + * and returns the result in x0 + * Shuffle everything around appropriately. + */ + mov x9, x0 /* signal_pending pointer */ + mov x8, x1 /* syscall number */ + mov x0, x2 /* syscall arguments */ + mov x1, x3 + mov x2, x4 + mov x3, x5 + mov x4, x6 + mov x6, x7 + ldr x7, [sp] + + /* This next sequence of code works in conjunction with the + * rewind_if_safe_syscall_function(). If a signal is taken + * and the interrupted PC is anywhere between 'safe_syscall_start' + * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'. + * The code sequence must therefore be able to cope with this, and + * the syscall instruction must be the final one in the sequence. + */ +safe_syscall_start: + /* if signal_pending is non-zero, don't do the call */ + ldr w10, [x9] + cbnz w10, 0f + svc 0x0 +safe_syscall_end: + /* code path for having successfully executed the syscall */ + ret + +0: + /* code path when we didn't execute the syscall */ + mov x0, #-TARGET_ERESTARTSYS + ret + .cfi_endproc + + .size safe_syscall_base, .-safe_syscall_base