From patchwork Tue Dec 14 00:25:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 523657 Delivered-To: patch@linaro.org Received: by 2002:adf:eccd:0:0:0:0:0 with SMTP id s13csp5338428wro; Mon, 13 Dec 2021 16:31:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNKKmeCWlW2F3aufeB5WlHbGsasF8ClMhutTqktfH0LrNvqjBqCWPaR1itZrg84H6SY1tc X-Received: by 2002:a05:6122:2088:: with SMTP id i8mr2928541vkd.5.1639441901206; Mon, 13 Dec 2021 16:31:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639441901; cv=none; d=google.com; s=arc-20160816; b=czqH9mrxI6pXpXhy4eqpnXvJorRDIdpVqnttnfngzocS+XgA7EVdmbRc6yHFBnyj9u 0f4Ie1RInB0YjNVv7Azgd2TPwXXRa1amiDx82V6qNAqEZde+672XL5OK5ESnz4VpS/iJ N6IxJTGQ2aWcOlHg8u1/0T0shvaZe2X9ATg4LhBLtS0TWllKcfKvauBP7nEp2VahMw8L jlQB6/9YmFKqXObAIlpPcRLU1G+Bi2H/1xhgMNGbEOZDe0TH3i++OEvnhjbvMt3ugDK0 7vUIRx7xomKo+CPm9bZA0Gfg6mVFtAVzH8Q2C946eNfR5svRDCi4XI6WsweUOvGKRD/Y 47uQ== 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=mT+zuzmDZjEjStGuNXpCAnb7RPXTMmCHpcEJ6vHxP1Y=; b=vF/NNxRM8l1aB4BccaU6/BHX3ugqWwGUv8kzi1iQ5mIjkfF6egnSA2dEo2Jr+znGKx Acu8vuMMiXIhhwK3IKv3Lm5lf373PzeduUQouGKfFveY9gTxWUG19N+YBeBk1OPnPOGd iNl6fj54B3vjTI//YwN7US/vDn225QepQTjg+wA3bbTah3RJd9ujpNOTKGBzyaH//sc6 CnKCUOtRV4h2iaW/AS+BLLeR4ZU78psU6sopaGWUOgQY/UM+uwx0w8c1/WRi0vHAqXjJ ZN8SfhOmIxejUEx5+ghJ92o37W/TJVQoWOgaV9HTdT/I6iYcOd8MhHpXDnmbLeOvVrGW RCKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YXF13fGg; 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 q2si11309989vsj.25.2021.12.13.16.31.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Dec 2021 16:31:41 -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=YXF13fGg; 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]:34928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwvjI-0005Vf-IB for patch@linaro.org; Mon, 13 Dec 2021 19:31:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwve4-0007wc-Te for qemu-devel@nongnu.org; Mon, 13 Dec 2021 19:26:16 -0500 Received: from [2607:f8b0:4864:20::430] (port=44686 helo=mail-pf1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mwvdz-0005Rf-LI for qemu-devel@nongnu.org; Mon, 13 Dec 2021 19:26:16 -0500 Received: by mail-pf1-x430.google.com with SMTP id k64so16381998pfd.11 for ; Mon, 13 Dec 2021 16:26:11 -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=mT+zuzmDZjEjStGuNXpCAnb7RPXTMmCHpcEJ6vHxP1Y=; b=YXF13fGg4flXkSMDyKjtvj47xNdYsKbM9bMeTnNo/ixKM3iasAgN3IX2PduOns+4jS t5wl6X1mRcet2X5ygudodl86nnLvOqNTQsBC1GX+NJ82FqVfuzYsdDL9QpH9UKIcvqAE YynWf0vLLXZPdnEthbszz2QwlpaZTXSyJ7eeA9/+/5jU7jVREHKFtmUp0PSEjVEbx1+0 XPB2WS9YIPKa3wF2wt1iiAiX3OqMRJS45KI1W4xpSlMfEEwHjRWsstf+nQrTNR228HZx MKDfkfOhuemgwUFkHKQtlIKxlSNhwyafSOv/DlcDujalIA3O9e0whHv4gX1qUJ0I0PgU knrA== 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=mT+zuzmDZjEjStGuNXpCAnb7RPXTMmCHpcEJ6vHxP1Y=; b=LxzllhdZOhp9JXy+pwtnnLx53UOWjOyQCVE+Q3HxujAvqnucV604B6WcwG93hkMKDa 77G+hsUdVQhURgKS3qtxUsva8h8RiIDMwMZi78DCBCbdIoqTNu6hoJfbF2NvcVoYGpMa 3U5naBYHqmLiRdEybbDCXMB/kvvL+4Uh3+fmOnTmxYS+uYQuFB3pp3QoB5byQqONPqah sHItdtBirMKeOKMScZjgdBPrPND8srfUoEuEk2tWqoLUsCCmKhFe9kD59YuvsY6r/83P CL4B/eDpwyBHtry4J55XRxlHB8lMEA3ydLbPVpZkrsGA8oOemGYNNq9a+MLEDLTpzrpb VYCw== X-Gm-Message-State: AOAM532Gerq261v0SH1F69VYcabg3bjSgEWNWtTWd87u9v5QJMuia3k+ rwPTyJgo5qVWmAgwVDa4plvh602yr90bgg== X-Received: by 2002:a63:354c:: with SMTP id c73mr1418923pga.532.1639441570355; Mon, 13 Dec 2021 16:26:10 -0800 (PST) Received: from localhost.localdomain (174-21-75-75.tukw.qwest.net. [174.21.75.75]) by smtp.gmail.com with ESMTPSA id w7sm11320253pgo.56.2021.12.13.16.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 16:26:09 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v7 04/15] linux-user/host/sparc64: Add safe-syscall.inc.S Date: Mon, 13 Dec 2021 16:25:53 -0800 Message-Id: <20211214002604.161983-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214002604.161983-1-richard.henderson@linaro.org> References: <20211214002604.161983-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::430 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.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, T_SPF_TEMPERROR=0.01 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: git@xen0n.name, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- 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..bb35c64cfc --- /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 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. + */ + + .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