From patchwork Tue Dec 21 16:47:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526624 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp5246738imb; Tue, 21 Dec 2021 09:16:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzPa1emkD3MxIyr8eJKCKY1Angle+wjTEHXccpQtZrrpRE9JcgzAsk+JKSsHeS9prdja7v/ X-Received: by 2002:ad4:4423:: with SMTP id e3mr3377329qvt.55.1640106992894; Tue, 21 Dec 2021 09:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640106992; cv=none; d=google.com; s=arc-20160816; b=mrzH6Jt/UhySHdgzaNvewJfQLfLoh9XAkkkUOhC/ZkdI2DGnKYwrBLfJUn/Rd9PBFa D6JVrvro2kcRfq191V+pxzr+n4bfLU6R12FUE/uPIHlbCZwUnHJpcE7wpAGX+/jNkNQn VHrG7rcYpDWX+qsfPnoTDlFyWTUVBUT6axm+EQbjiNQvfKkBZddnIDC8H5Go/fRG6sCu kzyli0SzLkZrI0w8aoDybpKlDw/CTFA0sl/hP/B784jczml5FuEHXy6+Ng+y7J0RZQ9o Wqs3sW/42GJDeO7Il9+j7Qj5ZEC/ADFTSk2HrXoLbg3UNOUejZkEHxZeBdB4wT0WphiC X4SA== 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=NXitDDn0ZGVh6q/FUUAQ/qESIDgx/GkwWKwAawsJ6kU=; b=mGX+SA9Nxjt+KZqH7/PsEu7kSt8ZTsvCZdM1wgBDSG9FOMxOei1BlsERLuuGavCWUZ n7z0Lkm5GCngBaH5v9UB1jAJ2ZgLFXOPPyld77iEJQfuQZuFeVlSrFRQTDdhl+ab209o Nn60u+8V1/9E8nOnWhdX1eAjYlSpwbhAPeCWUNU/3EL1WEze5Kctpq72Q9J5folO6r9v N8pO0gBvxFOto5NvuXFH70hsBfUWNP9JZ/MLwCTA+p1UcHQjLNMU2DgTRHgNMzwSLXeu mbEUyN6dQS7+L/2gHIwbt3J5kuYSjN3riZY5//ED208AdZFo3BYA257eDExtYRVwLK7a cEhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iCcO7UI8; 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 s123si7620854qkf.742.2021.12.21.09.16.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Dec 2021 09:16:32 -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=iCcO7UI8; 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]:52178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzika-0006PS-A6 for patch@linaro.org; Tue, 21 Dec 2021 12:16:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mziJA-00010j-NX for qemu-devel@nongnu.org; Tue, 21 Dec 2021 11:48:12 -0500 Received: from [2607:f8b0:4864:20::42b] (port=43923 helo=mail-pf1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mziJ3-0007fY-OH for qemu-devel@nongnu.org; Tue, 21 Dec 2021 11:48:12 -0500 Received: by mail-pf1-x42b.google.com with SMTP id 196so8740052pfw.10 for ; Tue, 21 Dec 2021 08:48:05 -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=NXitDDn0ZGVh6q/FUUAQ/qESIDgx/GkwWKwAawsJ6kU=; b=iCcO7UI8hnnozrRaBK3DoglDt43UlLzkBXfI5I4+Br0Ci7iPj4Y2LvyPlwtDIDNgO5 XC+p2lIaP9h0jjXtb91E/5cIi/2uqX8/nHyxXG8zRqKvz8JZIiMra/WzwdULGxZBlTpn T1jMo+SFwOwGyH+dRuMDBKFrifBqP0Ojus7tg8p1qfGRmQu/mDzqAxmlqVcWSiop2j3G kE1s7JMnVaN/IKbUTg0Q8OVvWbNjZ4ROKATzmMXmfDMvXsJMdxUItRn/pXb38t1ljOQE o7Ih4DcmhhBZTvvkKaIQMTViOn9YtxfHbisE+B/vuDYr79SUx4hvPuKAkuRO44It2XC6 ITOQ== 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=NXitDDn0ZGVh6q/FUUAQ/qESIDgx/GkwWKwAawsJ6kU=; b=7KDj6iHVwqOHHT2XuiLYMbUgQCYgX3h7Rb9ezi23gzifqCUtigsbUVEgjatCi5Ywtu 21x2UTHAyx5J8E3PJHsYQ0lZRdU6gF1OK5SYv8Ps5O1oXJ0whXZR2DGx9IByVeaMGWlN W5TJnV9qVgvtWLUzV+RNDCeyiFqb8z8dLTW92Z6j2TYmmKD+nTXzJWwrA2V51VhHVFdv BcTiHX6xlF9F3dvbZ2YZCwgJA6bIgtDi+C97zj4+JQoLb26FhZgyYoUb7FxKS5Ldm7g4 xDABXONJI73bJiIuBCISf363os8s8XJd7KqfvmD2gwIyOo+mau690YAYQ55NkCS1BE2e QKEg== X-Gm-Message-State: AOAM531IEUEzHcyxO6WHvs0Qwt4N4kWRQRWqUN3lzVuzyUDMZUIDusLl W+xhO/iZKA8Qy84LOeNSNglbwEQwjX/XBQ== X-Received: by 2002:a63:1158:: with SMTP id 24mr3655380pgr.193.1640105284430; Tue, 21 Dec 2021 08:48:04 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id b192sm2256818pga.35.2021.12.21.08.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 08:48:04 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 28/31] common-user: Add safe syscall handling for loongarch64 hosts Date: Tue, 21 Dec 2021 08:47:34 -0800 Message-Id: <20211221164737.1076007-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221164737.1076007-1-richard.henderson@linaro.org> References: <20211221164737.1076007-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.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: WANG Xuerui Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: WANG Xuerui Signed-off-by: WANG Xuerui Reviewed-by: Richard Henderson Message-Id: <20211221054105.178795-29-git@xen0n.name> Signed-off-by: Richard Henderson --- .../host/loongarch64/safe-syscall.inc.S | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 common-user/host/loongarch64/safe-syscall.inc.S diff --git a/common-user/host/loongarch64/safe-syscall.inc.S b/common-user/host/loongarch64/safe-syscall.inc.S new file mode 100644 index 0000000000..b88a069c45 --- /dev/null +++ b/common-user/host/loongarch64/safe-syscall.inc.S @@ -0,0 +1,90 @@ +/* + * 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 common-user/safe-syscall.S + * + * Ported to LoongArch by WANG Xuerui + * + * Based on safe-syscall.inc.S code for RISC-V, + * originally written by Richard Henderson + * Copyright (C) 2018 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. + */ + + .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'). + */ +safe_syscall_base: + .cfi_startproc + /* + * The syscall calling convention is nearly the same as C: + * we enter with a0 == &signal_pending + * a1 == syscall number + * a2 ... a7 == syscall arguments + * and return the result in a0 + * and the syscall instruction needs + * a7 == syscall number + * a0 ... a5 == syscall arguments + * and returns the result in a0 + * Shuffle everything around appropriately. + */ + move $t0, $a0 /* signal_pending pointer */ + move $t1, $a1 /* syscall number */ + move $a0, $a2 /* syscall arguments */ + move $a1, $a3 + move $a2, $a4 + move $a3, $a5 + move $a4, $a6 + move $a5, $a7 + move $a7, $t1 + + /* + * We need to preserve the signal_pending pointer but t0 is + * clobbered by syscalls on LoongArch, so we need to move it + * somewhere else, ideally both preserved across syscalls and + * clobbered by procedure calls so we don't have to allocate a + * stack frame; a6 is just the register we want here. + */ + move $a6, $t0 + + /* + * 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 */ + ld.w $t1, $a6, 0 + bnez $t1, 2f + syscall 0 +safe_syscall_end: + /* code path for having successfully executed the syscall */ + li.w $t2, -4096 + bgtu $a0, $t2, 0f + jr $ra + + /* code path setting errno */ +0: sub.d $a0, $zero, $a0 + b safe_syscall_set_errno_tail + + /* code path when we didn't execute the syscall */ +2: li.w $a0, QEMU_ERESTARTSYS + b safe_syscall_set_errno_tail + .cfi_endproc + .size safe_syscall_base, .-safe_syscall_base