From patchwork Mon Dec 20 20:24:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526054 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4422039imb; Mon, 20 Dec 2021 12:26:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9dswCR4SlcDczxJFPvQYp+8FhmRF8YPZDITPeE4eMPPtd8Ps/sKdGqzZo1FIYFaNf0vCI X-Received: by 2002:a92:ca91:: with SMTP id t17mr8614786ilo.33.1640032008417; Mon, 20 Dec 2021 12:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640032008; cv=none; d=google.com; s=arc-20160816; b=JUJpsHmGqYcdCTFhsfKVD3ncVb7x9EzHYJMRByLwlAPD7lcX+cgBDm+9fJhxVJx3Ou PoaK2xXa+yLmxG9eBKCewSRC5YqeBjQd1pjusjTZZoHIsd0PtFpU9QW+ONiee3tRCbWc 17VedkkcUFv59X1q80BhBDdnXMD8N5VdmzU9q+sRVzcfexJSOpNTO8lmyfxsXms+hdgJ XV1JvDV3cwdcpCQuUaZ89L0VS6AmAcu1XKtGbHITwQt1LoCGd/evbfouMcUrkM2rvMPk Icar8Xuk/C8lJRDzrgrryLfyZ61iw3pHGuC8w/NY2bk4q8Flc0VXzi34+R4T61HskIDi CffQ== 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=0Ij3KpROxLC8dtK7aIvTpcOO8V/yzRNnTNXtooq2NSs=; b=ENqpblLibfdQvTpBIjYXd2FWAtppnsMG8o7L0q0GYw5VPcDdA8ZH6gkK/Q/nGbekN5 1SCTIbXbQKslkxGhWmCROwTdFCQNHwgh9BZVqlJIC3JgXa2dBK01nbJvqQrbyBScmNy1 qSFw/tflGWyQMYLgiUpGYWfMqFwpS6c6SXvW3RJLMbll2KpZnnd49kfufxAxIn4e8yy2 IXA2bOLEQ3JlZ+A8MgFPh0yRHAHtIZSYZsgLW0ladXluLptBT+XC0dDp1SAQAhxTfGPx ynee+MXXgi2YVxHcFbsj8LOYRnHOIy7Cf1XCWu0E5AQqY+uXtHuTsL/R+f95LjlAuZl6 57SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jzlkNKQE; 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=pass (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 x8si7373860ila.170.2021.12.20.12.26.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 12:26:48 -0800 (PST) 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=pass header.i=@linaro.org header.s=google header.b=jzlkNKQE; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzPF9-0001gi-TP for patch@linaro.org; Mon, 20 Dec 2021 15:26:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzPDe-0001fY-SI for qemu-devel@nongnu.org; Mon, 20 Dec 2021 15:25:15 -0500 Received: from [2607:f8b0:4864:20::42e] (port=42873 helo=mail-pf1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzPDX-0006zw-Bf for qemu-devel@nongnu.org; Mon, 20 Dec 2021 15:25:09 -0500 Received: by mail-pf1-x42e.google.com with SMTP id t19so3393820pfg.9 for ; Mon, 20 Dec 2021 12:25:06 -0800 (PST) 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=0Ij3KpROxLC8dtK7aIvTpcOO8V/yzRNnTNXtooq2NSs=; b=jzlkNKQErIHVxlwRHnlBOfoMsT3ttJDGtY1KP7fOap/thxnXd9RYNZ3VqI5N6g5bAm OfmNdzAMTrzXNyuIIeHQKqLjEse/wSLEWpZ+nFqxu97lCFqjsu8o2hoDdfQEv0H8eOlV GRX8Cfhad/5HrIOqVb3CReJbV40iCXO+4IY7uZfcPWv1fiQ68EJqnFqulftRbbUq1gDh t+87AV57G5PZ3wU4y8SmP5zn3y9wDqcR0rRCk6Hv/1bU5PC044P9Jz8Zg+DGQh03gtsZ uqPENlNMbgFes9cBH8Hy+oSfybRbf2rK1ELe4HUhzCwBY2AAbx7J0zRj+ZWRWB/8MC94 fe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Ij3KpROxLC8dtK7aIvTpcOO8V/yzRNnTNXtooq2NSs=; b=ojeizySKt6SHLGcjUCB8ZmDkjOyfroE+zUM35u6AZDvA7Yh/WD/E1CBfTcKbXuwDK2 GnQajpOB4QH3GCA6kDMPxPPajajgbcdIaDMK4scVF0Uu3PvOsThFnBcHGGLcc5OHnS52 ZpdTjW+JS1HuTauI8q3czLmbWzVRBgWIcKx0YPrnVPsjOHqrdwSx3ndoVo34tYiMSstf lgxul+RQKdV6RIzOA3uisi9DdnEgKstBqDLHaVm7ggOe8DIn2hTI6HS0LOeHgmo5r3zJ ftgdqQkXD58TZG/f8lDZA0hp/2NQyIMDoE4xL8LQblEdJy1+3NjJgshTReHUt6SdxKXW Klyw== X-Gm-Message-State: AOAM531HQFrIv2xbGppqdUTqdbQbFeKF5L51GKh8K9d89wH/wBToT9UM HU2jeNeCmGO0UqiXARCEodEajKZRWbFNMg== X-Received: by 2002:a63:701b:: with SMTP id l27mr16235615pgc.241.1640031906032; Mon, 20 Dec 2021 12:25:06 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id q19sm233118pjd.21.2021.12.20.12.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 12:25:05 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/15] linux-user/host/sparc64: Add safe-syscall.inc.S Date: Mon, 20 Dec 2021 12:24:49 -0800 Message-Id: <20211220202500.111897-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211220202500.111897-1-richard.henderson@linaro.org> References: <20211220202500.111897-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/host/sparc64/hostdep.h | 3 + linux-user/host/sparc64/safe-syscall.inc.S | 89 ++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 linux-user/host/sparc64/safe-syscall.inc.S diff --git a/linux-user/host/sparc64/hostdep.h b/linux-user/host/sparc64/hostdep.h index ce3968fca0..d832868cb1 100644 --- a/linux-user/host/sparc64/hostdep.h +++ b/linux-user/host/sparc64/hostdep.h @@ -12,4 +12,7 @@ #ifndef SPARC64_HOSTDEP_H #define SPARC64_HOSTDEP_H +/* We have a safe-syscall.inc.S */ +#define HAVE_SAFE_SYSCALL + #endif diff --git a/linux-user/host/sparc64/safe-syscall.inc.S b/linux-user/host/sparc64/safe-syscall.inc.S new file mode 100644 index 0000000000..901db15959 --- /dev/null +++ b/linux-user/host/sparc64/safe-syscall.inc.S @@ -0,0 +1,89 @@ +/* + * 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) 2021 Linaro, 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. + */ + + .text + .balign 4 + + .register %g2, #scratch + .register %g3, #scratch + + .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 + +#define STACK_BIAS 2047 +#define PARAM(N) STACK_BIAS + N*8 + + /* + * 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'). + */ +safe_syscall_base: + .cfi_startproc + /* + * The syscall calling convention isn't the same as the C one: + * we enter with o0 == &signal_pending + * o1 == syscall number + * o2 ... o5, (stack) == syscall arguments + * and return the result in x0 + * and the syscall instruction needs + * g1 == syscall number + * o0 ... o5 == syscall arguments + * and returns the result in o0 + * Shuffle everything around appropriately. + */ + mov %o0, %g2 /* signal_pending pointer */ + mov %o1, %g1 /* syscall number */ + mov %o2, %o0 /* syscall arguments */ + mov %o3, %o1 + mov %o4, %o2 + mov %o5, %o3 + ldx [%sp + PARAM(6)], %o4 + ldx [%sp + PARAM(7)], %o5 + + /* + * 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 */ + lduw [%g2], %g3 + brnz,pn %g3, 2f + nop + ta 0x6d +safe_syscall_end: + /* code path for having successfully executed the syscall */ + bcs,pn %xcc, 1f + nop + ret + nop + + /* code path when we didn't execute the syscall */ +2: set TARGET_ERESTARTSYS, %o0 + + /* code path setting errno */ +1: mov %o7, %g1 + call safe_syscall_set_errno_tail + mov %g1, %o7 + + .cfi_endproc + .size safe_syscall_base, .-safe_syscall_base