From patchwork Mon Jul 22 21:43:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03229C3DA5D for ; Mon, 22 Jul 2024 21:45:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0q4-0005Em-IE; Mon, 22 Jul 2024 17:45:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0pv-00052A-DS for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:52 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pq-0004HM-8H for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:50 -0400 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-8046f65536dso229746439f.1 for ; Mon, 22 Jul 2024 14:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684683; x=1722289483; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9RgA/sQrSqu0rivwfkVX+vpcUdtyuMUfMJ/jiDAmIes=; b=YMSI1+CQv+RHQJbUuZiZO7yFE3XJvj5Ff6QkNM1YezMPsH2bPYF1ckwLRgZMQfac+W FpeP4Ol7o9As5lSeNqqcUTZbYO4sahBeYuyrJlaNpFFjq2uy2Kxr9mTfK25wj73nt3Pi Q+/XTroP1WjEMXPTve5v7xLQLF815HZAEpTZRq0pKCItNZ5Tps/bVLvlNRLiPxU7+5yB SZapWOkhLvsmg5OsG9FK/qfGWYR/mn0xSW7nTarYg9Q80TMS6WWcefrrBeL+TCh0J5zz YxhzU/ZacPz1p/BmDmjrLUpq3plPNE9EO1qC4cMbha/faJA2vvYqSF00NvS9mDNwyYkp KvXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684683; x=1722289483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9RgA/sQrSqu0rivwfkVX+vpcUdtyuMUfMJ/jiDAmIes=; b=r3+xqw0N9qN98Mi+79BWI+AgIrElqSspN5+UJZA54dTNQpkUWrzlU7Use/Uh4XxEZ7 ckwAbOT7ZtMoK+uHYu9Ceao6Hrp+/5yZpeG9VYAilORb2I0RIo2VrljDafL4qZDL0uXm 2LoxeSI90/O0crmxUncYoEJzm4mDlhFmzFXLmQk5eTGYsdf4Oohhy9dOuMzHAmPWA+ZK DV0ZrN65IlXnc1yVO5iWT5herrOTuPndR+EQfPp/xjwvAOnfygrGP2a4/O+37YlFBYVU OdInAl6Y/W+x6AsN/3XcRSn+XDbXOnuJnfL4kpb0xu0gHRBuyVHJwHT96Z+KPx0zo6It Maew== X-Gm-Message-State: AOJu0YyEXAgodHD9IMLPn4TGzxE8mngrjq4gJ8macTu6KSXGZLM3mrgK I1WFO6EEeB+lL01IOpuYaF4RFbQxG8DH4cIJmIQT1ZlDNZHXK3RpPHDNZhgpqPBB6bTn/+E5iY9 ikb8= X-Google-Smtp-Source: AGHT+IEnYzgDeUjkTAZvdefN6kDFSRxGkwG48wesp0etKIFuYMBSLVnS7wHFK2mDZKFcall0M4q6Tw== X-Received: by 2002:a05:6602:6d02:b0:817:49a2:fcf7 with SMTP id ca18e2360f4ac-81b35039b22mr965401139f.17.1721684683476; Mon, 22 Jul 2024 14:44:43 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:42 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Sean Bruno , Jessica Clarke , Richard Henderson Subject: [PATCH 01/14] bsd-user:Add CPU initialization and management functions Date: Mon, 22 Jul 2024 15:43:00 -0600 Message-ID: <20240722214313.89503-2-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2b; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Added function to initialize ARM CPU and check if it supports 64-bit mode. Implemented CPU loop function to handle exceptions and emulate execution of instructions. Added function to clone CPU state to create a new thread. Included AArch64 specific CPU functions for bsd-user to set and receive thread-local-storage value from the tpidr_el0 register. Introduced structure for storing CPU register states for BSD-USER. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Co-authored-by: Kyle Evans Co-authored-by: Sean Bruno Co-authored-by: Jessica Clarke Reviewed-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-2-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/target_arch_cpu.c | 31 +++++ bsd-user/aarch64/target_arch_cpu.h | 192 +++++++++++++++++++++++++++++ bsd-user/aarch64/target_syscall.h | 51 ++++++++ 3 files changed, 274 insertions(+) create mode 100644 bsd-user/aarch64/target_arch_cpu.c create mode 100644 bsd-user/aarch64/target_arch_cpu.h create mode 100644 bsd-user/aarch64/target_syscall.h diff --git a/bsd-user/aarch64/target_arch_cpu.c b/bsd-user/aarch64/target_arch_cpu.c new file mode 100644 index 00000000000..b2fa59efaf6 --- /dev/null +++ b/bsd-user/aarch64/target_arch_cpu.c @@ -0,0 +1,31 @@ +/* + * ARM AArch64 specific CPU for bsd-user + * + * Copyright (c) 2015 Stacey Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ +#include "qemu/osdep.h" +#include "target_arch.h" + +/* See cpu_set_user_tls() in arm64/arm64/vm_machdep.c */ +void target_cpu_set_tls(CPUARMState *env, target_ulong newtls) +{ + env->cp15.tpidr_el[0] = newtls; +} + +target_ulong target_cpu_get_tls(CPUARMState *env) +{ + return env->cp15.tpidr_el[0]; +} diff --git a/bsd-user/aarch64/target_arch_cpu.h b/bsd-user/aarch64/target_arch_cpu.h new file mode 100644 index 00000000000..5c150bb7e9c --- /dev/null +++ b/bsd-user/aarch64/target_arch_cpu.h @@ -0,0 +1,192 @@ +/* + * ARM AArch64 cpu init and loop + * + * Copyright (c) 2015 Stacey Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_CPU_H +#define TARGET_ARCH_CPU_H + +#include "target_arch.h" +#include "signal-common.h" +#include "target/arm/syndrome.h" + +#define TARGET_DEFAULT_CPU_MODEL "any" + +static inline void target_cpu_init(CPUARMState *env, + struct target_pt_regs *regs) +{ + int i; + + if (!(arm_feature(env, ARM_FEATURE_AARCH64))) { + fprintf(stderr, "The selected ARM CPU does not support 64 bit mode\n"); + exit(1); + } + for (i = 0; i < 31; i++) { + env->xregs[i] = regs->regs[i]; + } + env->pc = regs->pc; + env->xregs[31] = regs->sp; +} + + +static inline void target_cpu_loop(CPUARMState *env) +{ + CPUState *cs = env_cpu(env); + int trapnr, ec, fsc, si_code, si_signo; + uint64_t code, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + uint32_t pstate; + abi_long ret; + + for (;;) { + cpu_exec_start(cs); + trapnr = cpu_exec(cs); + cpu_exec_end(cs); + process_queued_cpu_work(cs); + + switch (trapnr) { + case EXCP_SWI: + /* See arm64/arm64/trap.c cpu_fetch_syscall_args() */ + code = env->xregs[8]; + if (code == TARGET_FREEBSD_NR_syscall || + code == TARGET_FREEBSD_NR___syscall) { + code = env->xregs[0]; + arg1 = env->xregs[1]; + arg2 = env->xregs[2]; + arg3 = env->xregs[3]; + arg4 = env->xregs[4]; + arg5 = env->xregs[5]; + arg6 = env->xregs[6]; + arg7 = env->xregs[7]; + arg8 = 0; + } else { + arg1 = env->xregs[0]; + arg2 = env->xregs[1]; + arg3 = env->xregs[2]; + arg4 = env->xregs[3]; + arg5 = env->xregs[4]; + arg6 = env->xregs[5]; + arg7 = env->xregs[6]; + arg8 = env->xregs[7]; + } + ret = do_freebsd_syscall(env, code, arg1, arg2, arg3, + arg4, arg5, arg6, arg7, arg8); + /* + * The carry bit is cleared for no error; set for error. + * See arm64/arm64/vm_machdep.c cpu_set_syscall_retval() + */ + pstate = pstate_read(env); + if (ret >= 0) { + pstate &= ~PSTATE_C; + env->xregs[0] = ret; + } else if (ret == -TARGET_ERESTART) { + env->pc -= 4; + break; + } else if (ret != -TARGET_EJUSTRETURN) { + pstate |= PSTATE_C; + env->xregs[0] = -ret; + } + pstate_write(env, pstate); + break; + + case EXCP_INTERRUPT: + /* Just indicate that signals should be handle ASAP. */ + break; + + case EXCP_UDEF: + force_sig_fault(TARGET_SIGILL, TARGET_ILL_ILLOPN, env->pc); + break; + + + case EXCP_PREFETCH_ABORT: + case EXCP_DATA_ABORT: + /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */ + ec = syn_get_ec(env->exception.syndrome); + assert(ec == EC_DATAABORT || ec == EC_INSNABORT); + + /* Both EC have the same format for FSC, or close enough. */ + fsc = extract32(env->exception.syndrome, 0, 6); + switch (fsc) { + case 0x04 ... 0x07: /* Translation fault, level {0-3} */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_MAPERR; + break; + case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */ + case 0x0d ... 0x0f: /* Permission fault, level {1-3} */ + si_signo = TARGET_SIGSEGV; + si_code = TARGET_SEGV_ACCERR; + break; + case 0x11: /* Synchronous Tag Check Fault */ + si_signo = TARGET_SIGSEGV; + si_code = /* TARGET_SEGV_MTESERR; */ TARGET_SEGV_ACCERR; + break; + case 0x21: /* Alignment fault */ + si_signo = TARGET_SIGBUS; + si_code = TARGET_BUS_ADRALN; + break; + default: + g_assert_not_reached(); + } + force_sig_fault(si_signo, si_code, env->exception.vaddress); + break; + + case EXCP_DEBUG: + case EXCP_BKPT: + force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); + break; + + case EXCP_ATOMIC: + cpu_exec_step_atomic(cs); + break; + + case EXCP_YIELD: + /* nothing to do here for user-mode, just resume guest code */ + break; + default: + fprintf(stderr, "qemu: unhandled CPU exception 0x%x - aborting\n", + trapnr); + cpu_dump_state(cs, stderr, 0); + abort(); + } /* switch() */ + process_pending_signals(env); + /* + * Exception return on AArch64 always clears the exclusive + * monitor, so any return to running guest code implies this. + * A strex (successful or otherwise) also clears the monitor, so + * we don't need to specialcase EXCP_STREX. + */ + env->exclusive_addr = -1; + } /* for (;;) */ +} + + +/* See arm64/arm64/vm_machdep.c cpu_fork() */ +static inline void target_cpu_clone_regs(CPUARMState *env, target_ulong newsp) +{ + if (newsp) { + env->xregs[31] = newsp; + } + env->regs[0] = 0; + env->regs[1] = 0; + pstate_write(env, 0); +} + +static inline void target_cpu_reset(CPUArchState *env) +{ +} + + +#endif /* TARGET_ARCH_CPU_H */ diff --git a/bsd-user/aarch64/target_syscall.h b/bsd-user/aarch64/target_syscall.h new file mode 100644 index 00000000000..08ae913c42e --- /dev/null +++ b/bsd-user/aarch64/target_syscall.h @@ -0,0 +1,51 @@ +/* + * ARM AArch64 specific CPU for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef BSD_USER_AARCH64_TARGET_SYSCALL_H +#define BSD_USER_AARCH64_TARGET_SYSCALL_H + +/* + * The aarch64 registers are named: + * + * x0 through x30 - for 64-bit-wide access (same registers) + * Register '31' is one of two registers depending on the instruction context: + * For instructions dealing with the stack, it is the stack pointer, named rsp + * For all other instructions, it is a "zero" register, which returns 0 when + * read and discards data when written - named rzr (xzr, wzr) + * + * Usage during syscall/function call: + * r0-r7 are used for arguments and return values + * For syscalls, the syscall number is in r8 + * r9-r15 are for temporary values (may get trampled) + * r16-r18 are used for intra-procedure-call and platform values (avoid) + * The called routine is expected to preserve r19-r28 + * r29 and r30 are used as the frame register and link register (avoid) + * See the ARM Procedure Call Reference for details. + */ +struct target_pt_regs { + uint64_t regs[31]; + uint64_t sp; + uint64_t pc; + uint64_t pstate; +}; + +#define TARGET_HW_MACHINE "arm64" +#define TARGET_HW_MACHINE_ARCH "aarch64" + +#endif /* BSD_USER_AARCH64_TARGET_SYSCALL_H */ From patchwork Mon Jul 22 21:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01421C3DA5D for ; Mon, 22 Jul 2024 21:45:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0q7-0005S3-OV; Mon, 22 Jul 2024 17:45:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0py-00052q-2o for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0ps-0004HX-9R for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:52 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-7f70a708f8aso195012239f.2 for ; Mon, 22 Jul 2024 14:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684685; x=1722289485; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yKi1gMVKcZkhr3TxLjW1YvmZHL7RtLDRQyR73xxYF4A=; b=qdEf5I7bRyJLHzRrPdZzScino/Xi8MFg6MKOwK3eyIccq4Asb3P7rAUuig9XPDDhEx sLI+of7QqhxsETR6YlKjepRsD+EZLmeVLcnIMhtcP/ERHnktim5BVOjyG6nomABlV9km slVPIGyY4dKwfLZVmjh8Ungvbr7hzbtMwqWl7a/DSBQ9LqyxyqfsFj7p56+GCln+L612 EEVIidJne4HtviupJa2Q1RnyPtcxB7y6mb97aHyLTLt7j0rcWJiVGc8jMtSUBe6lS2li WldkuPdbt4qRpsGvVTO1PO02hI9kXLWbSbjP9mviGw99vLP2fbwgJ1kPu6KDt+OAHQ3R 9QUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684685; x=1722289485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yKi1gMVKcZkhr3TxLjW1YvmZHL7RtLDRQyR73xxYF4A=; b=UVJsxunBIO3fAEJFaehAH+Uer8nJmGbKCNp8Ls2L4OOSuqinRE3MQXwK/A0XjN2Je8 MmQ9i7b4CYD393lLdBc5Hbmbe1adtkdMTNezzDhDSMAWYNNoqzn5VyR1yVvD1qtBdKWt 5CbXEX3X4U7fcUJbrPqlbxmb3i9R+PP/CWn3YsdAwfuC6Mh26oHhmlKN2TS/1fL2CY7l 0JQaohUWQG4NKwKaQU5BYVL1U/2qfCXzEVy1+JHnNE7cS4bN72jWrKKIpOy9C1ee7MIt IntMin5V+yQIkf7ryOM7jq25+FaFFtJh5VkqU1UFEl741Ji8C5rUBD1+sasvVu7sPLcm cCrw== X-Gm-Message-State: AOJu0YzWnL6pukoNie5hqu2AE2ruklPd3sDH3lNPVi2F9XCU9rMEx1o8 nIql5L+m1dqeXYh18MArQ+1ySXT8f1ral/MZ7zy9DFvS+nUWQJjYLqo9SmQjKhLh6KSBFpx7nM/ 1U2I= X-Google-Smtp-Source: AGHT+IHBn2ZFfZVlpTn6KB6T06JKbYiBYVyAPBKnBLJNuSEP5nEOBpKET7aWF2OBJkPj7GnfwTDEVw== X-Received: by 2002:a05:6602:2d94:b0:807:f0fb:11a2 with SMTP id ca18e2360f4ac-81ea4d83700mr126075839f.13.1721684684924; Mon, 22 Jul 2024 14:44:44 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:43 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Jessica Clarke , Sean Bruno , Richard Henderson Subject: [PATCH 02/14] bsd-user:Add AArch64 register handling and related functions Date: Mon, 22 Jul 2024 15:43:01 -0600 Message-ID: <20240722214313.89503-3-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Added header file for managing CPU register states in FreeBSD user mode. Introduced prototypes for setting and getting thread-local storage (TLS). Implemented AArch64 sysarch() system call emulation and a printing function. Added function for setting up thread upcall to add thread support to BSD-USER. Initialized thread's register state during thread setup. Updated ARM AArch64 VM parameter definitions for bsd-user, including address spaces for FreeBSD/arm64 and a function for getting the stack pointer from CPU and setting a return value. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Co-authored-by: Jessica Clarke Co-authored-by: Sean Bruno Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-3-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/target_arch.h | 28 +++++++++++ bsd-user/aarch64/target_arch_reg.h | 56 +++++++++++++++++++++ bsd-user/aarch64/target_arch_sysarch.h | 42 ++++++++++++++++ bsd-user/aarch64/target_arch_thread.h | 61 +++++++++++++++++++++++ bsd-user/aarch64/target_arch_vmparam.h | 68 ++++++++++++++++++++++++++ 5 files changed, 255 insertions(+) create mode 100644 bsd-user/aarch64/target_arch.h create mode 100644 bsd-user/aarch64/target_arch_reg.h create mode 100644 bsd-user/aarch64/target_arch_sysarch.h create mode 100644 bsd-user/aarch64/target_arch_thread.h create mode 100644 bsd-user/aarch64/target_arch_vmparam.h diff --git a/bsd-user/aarch64/target_arch.h b/bsd-user/aarch64/target_arch.h new file mode 100644 index 00000000000..27f47de8eb3 --- /dev/null +++ b/bsd-user/aarch64/target_arch.h @@ -0,0 +1,28 @@ +/* + * ARM AArch64 specific prototypes for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_H +#define TARGET_ARCH_H + +#include "qemu.h" + +void target_cpu_set_tls(CPUARMState *env, target_ulong newtls); +target_ulong target_cpu_get_tls(CPUARMState *env); + +#endif /* TARGET_ARCH_H */ diff --git a/bsd-user/aarch64/target_arch_reg.h b/bsd-user/aarch64/target_arch_reg.h new file mode 100644 index 00000000000..5c7154f0c18 --- /dev/null +++ b/bsd-user/aarch64/target_arch_reg.h @@ -0,0 +1,56 @@ +/* + * FreeBSD arm64 register structures + * + * Copyright (c) 2015 Stacey Son + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef TARGET_ARCH_REG_H +#define TARGET_ARCH_REG_H + +/* See sys/arm64/include/reg.h */ +typedef struct target_reg { + uint64_t x[30]; + uint64_t lr; + uint64_t sp; + uint64_t elr; + uint64_t spsr; +} target_reg_t; + +typedef struct target_fpreg { + __uint128_t fp_q[32]; + uint32_t fp_sr; + uint32_t fp_cr; +} target_fpreg_t; + +#define tswapreg(ptr) tswapal(ptr) + +static inline void target_copy_regs(target_reg_t *regs, CPUARMState *env) +{ + int i; + + for (i = 0; i < 30; i++) { + regs->x[i] = tswapreg(env->xregs[i]); + } + regs->lr = tswapreg(env->xregs[30]); + regs->sp = tswapreg(env->xregs[31]); + regs->elr = tswapreg(env->pc); + regs->spsr = tswapreg(pstate_read(env)); +} + +#undef tswapreg + +#endif /* TARGET_ARCH_REG_H */ diff --git a/bsd-user/aarch64/target_arch_sysarch.h b/bsd-user/aarch64/target_arch_sysarch.h new file mode 100644 index 00000000000..b003015daf4 --- /dev/null +++ b/bsd-user/aarch64/target_arch_sysarch.h @@ -0,0 +1,42 @@ +/* + * ARM AArch64 sysarch() system call emulation for bsd-user. + * + * Copyright (c) 2015 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_SYSARCH_H +#define TARGET_ARCH_SYSARCH_H + +#include "target_syscall.h" +#include "target_arch.h" + +/* See sysarch() in sys/arm64/arm64/sys_machdep.c */ +static inline abi_long do_freebsd_arch_sysarch(CPUARMState *env, int op, + abi_ulong parms) +{ + int ret = -TARGET_EOPNOTSUPP; + + fprintf(stderr, "sysarch"); + return ret; +} + +static inline void do_freebsd_arch_print_sysarch( + const struct syscallname *name, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ +} + +#endif /* TARGET_ARCH_SYSARCH_H */ diff --git a/bsd-user/aarch64/target_arch_thread.h b/bsd-user/aarch64/target_arch_thread.h new file mode 100644 index 00000000000..4c911e605ac --- /dev/null +++ b/bsd-user/aarch64/target_arch_thread.h @@ -0,0 +1,61 @@ +/* + * ARM AArch64 thread support for bsd-user. + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_THREAD_H +#define TARGET_ARCH_THREAD_H + +/* Compare to arm64/arm64/vm_machdep.c cpu_set_upcall_kse() */ +static inline void target_thread_set_upcall(CPUARMState *regs, abi_ulong entry, + abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size) +{ + abi_ulong sp; + + /* + * Make sure the stack is properly aligned. + * arm64/include/param.h (STACKLIGN() macro) + */ + sp = ROUND_DOWN(stack_base + stack_size, 16); + + /* sp = stack base */ + regs->xregs[31] = sp; + /* pc = start function entry */ + regs->pc = entry; + /* r0 = arg */ + regs->xregs[0] = arg; + + +} + +static inline void target_thread_init(struct target_pt_regs *regs, + struct image_info *infop) +{ + abi_long stack = infop->start_stack; + + /* + * Make sure the stack is properly aligned. + * arm64/include/param.h (STACKLIGN() macro) + */ + + memset(regs, 0, sizeof(*regs)); + regs->regs[0] = infop->start_stack; + regs->pc = infop->entry; + regs->sp = ROUND_DOWN(stack, 16); +} + +#endif /* TARGET_ARCH_THREAD_H */ diff --git a/bsd-user/aarch64/target_arch_vmparam.h b/bsd-user/aarch64/target_arch_vmparam.h new file mode 100644 index 00000000000..dc66e1289b5 --- /dev/null +++ b/bsd-user/aarch64/target_arch_vmparam.h @@ -0,0 +1,68 @@ +/* + * ARM AArch64 VM parameters definitions for bsd-user. + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_VMPARAM_H +#define TARGET_ARCH_VMPARAM_H + +#include "cpu.h" + +/** + * FreeBSD/arm64 Address space layout. + * + * ARMv8 implements up to a 48 bit virtual address space. The address space is + * split into 2 regions at each end of the 64 bit address space, with an + * out of range "hole" in the middle. + * + * We limit the size of the two spaces to 39 bits each. + * + * Upper region: 0xffffffffffffffff + * 0xffffff8000000000 + * + * Hole: 0xffffff7fffffffff + * 0x0000008000000000 + * + * Lower region: 0x0000007fffffffff + * 0x0000000000000000 + * + * The upper region for the kernel, and the lower region for userland. + */ + + +/* compare to sys/arm64/include/vmparam.h */ +#define TARGET_MAXTSIZ (1 * GiB) /* max text size */ +#define TARGET_DFLDSIZ (128 * MiB) /* initial data size limit */ +#define TARGET_MAXDSIZ (1 * GiB) /* max data size */ +#define TARGET_DFLSSIZ (128 * MiB) /* initial stack size limit */ +#define TARGET_MAXSSIZ (1 * GiB) /* max stack size */ +#define TARGET_SGROWSIZ (128 * KiB) /* amount to grow stack */ + + /* KERNBASE - 512 MB */ +#define TARGET_VM_MAXUSER_ADDRESS (0x00007fffff000000ULL - (512 * MiB)) +#define TARGET_USRSTACK TARGET_VM_MAXUSER_ADDRESS + +static inline abi_ulong get_sp_from_cpustate(CPUARMState *state) +{ + return state->xregs[31]; /* sp */ +} + +static inline void set_second_rval(CPUARMState *state, abi_ulong retval2) +{ + state->xregs[1] = retval2; /* XXX not really used on 64-bit arch */ +} +#endif /* TARGET_ARCH_VMPARAM_H */ From patchwork Mon Jul 22 21:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C2C0C3DA59 for ; Mon, 22 Jul 2024 21:46:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0q7-0005TN-TV; Mon, 22 Jul 2024 17:45:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0py-00052o-2H for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0ps-0004J5-Ah for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:52 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-8152f0c63c1so187724639f.1 for ; Mon, 22 Jul 2024 14:44:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684686; x=1722289486; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XhtuF+xcgb0CJwH2BcgYevwpIoQXvHSPcnXv2TrhcGA=; b=DhSFkC4/1YW3y3LS+V3rO/RSqzEw3Nc44ggtT/gxP7SVdweO91IgdY786h4jTVwJ7M sn2GKCsSsd6YhQIRZSiwAPLENUfhFjvXeKuMDBWtYgCko0j3pBbDuFKrVPBUi2RZ3p8n JLfE3zijkQurradj4WrJonx2VKWzbsbusU9jTcBLRsW0UzGOsIi7awove+R0mEnbHZka UmaWMI31V5MRtXrihOL2re+/LQjH5VQ8NBpFiCvyfdfRy2sqIp32UAI4Dz4nyQdYR+qL ssT/lFpC1nVeTzvjSLBLVNXxhxPDepTspKvlJ9Ig0rmycCQbyWyI/fvyFNENH3BYwraD 4Z2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684686; x=1722289486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XhtuF+xcgb0CJwH2BcgYevwpIoQXvHSPcnXv2TrhcGA=; b=CRIPVkhUBiaGHPUnCNCQKJuWyMb5VizA4tncw0zKFzKt5NJc6YKTNF/rFm0v0BboxP xi0VMZbkP+3N/5R5LRplsLRyNhQqnQXa5kPgiLi/u4D4OlfdJDVYVegAQ7QJh5T78+QZ iCKFnxys+SGwOVbAwAZeVvrMYeW28a+s31EKej7WgTg1iN87QjtB5g+gwAap4pnBPZOD KTKDY2D45avzWF4gX7sEjfg/yJiWfRd5T3ioet+6zHkBmdDOAv57JmEsJxvm0XaTWIw8 zyGvn63E0gN9kwJ+pUH1wlbs7QylXFUes8COgYxX6DbpGWemoYJ29MenNwWWA+XiqrUO AHOw== X-Gm-Message-State: AOJu0YzriFOX6+0QilkFGsPzWBicIDVuFDQu5HXFeax12qLRnmmk90h5 r2J+JYLaBV84kRhilurItPRRkdR49N1RPieIpfOJNWlAXABwpEFxOfvPiqtIu45tNbvM5M7z4rk UvUM= X-Google-Smtp-Source: AGHT+IFVjspCoZEl4a/3nipqyWY7P/QbsMK0/MGhNNlfzua4eLiVUuESW+gvWraZ0GKgEM5HJamRJA== X-Received: by 2002:a05:6602:160d:b0:7f9:217c:c109 with SMTP id ca18e2360f4ac-81ea3c2eff4mr145855639f.9.1721684686030; Mon, 22 Jul 2024 14:44:46 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:45 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Kyle Evans , Richard Henderson Subject: [PATCH 03/14] bsd-user:Add ARM AArch64 support and capabilities Date: Mon, 22 Jul 2024 15:43:02 -0600 Message-ID: <20240722214313.89503-4-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Added function to access rval2 by accessing the x1 register. Defined ARM AArch64 ELF parameters including mmap and dynamic load addresses. Introduced extensive hardware capability definitions and macros for retrieving hardware capability (hwcap) flags. Implemented function to retrieve ARM AArch64 hardware capabilities using the `GET_FEATURE_ID` macro. Added function to retrieve extended ARM AArch64 hardware capability flags. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-4-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/target_arch.h | 1 + bsd-user/aarch64/target_arch_elf.h | 163 +++++++++++++++++++++++++ bsd-user/aarch64/target_arch_vmparam.h | 6 + 3 files changed, 170 insertions(+) create mode 100644 bsd-user/aarch64/target_arch_elf.h diff --git a/bsd-user/aarch64/target_arch.h b/bsd-user/aarch64/target_arch.h index 27f47de8eb3..4815a56ae3c 100644 --- a/bsd-user/aarch64/target_arch.h +++ b/bsd-user/aarch64/target_arch.h @@ -21,6 +21,7 @@ #define TARGET_ARCH_H #include "qemu.h" +#include "target/arm/cpu-features.h" void target_cpu_set_tls(CPUARMState *env, target_ulong newtls); target_ulong target_cpu_get_tls(CPUARMState *env); diff --git a/bsd-user/aarch64/target_arch_elf.h b/bsd-user/aarch64/target_arch_elf.h new file mode 100644 index 00000000000..cc87f475b3f --- /dev/null +++ b/bsd-user/aarch64/target_arch_elf.h @@ -0,0 +1,163 @@ +/* + * ARM AArch64 ELF definitions for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_ELF_H +#define TARGET_ARCH_ELF_H + +#define ELF_START_MMAP 0x80000000 +#define ELF_ET_DYN_LOAD_ADDR 0x100000 + +#define elf_check_arch(x) ((x) == EM_AARCH64) + +#define ELF_CLASS ELFCLASS64 +#define ELF_DATA ELFDATA2LSB +#define ELF_ARCH EM_AARCH64 + +#define USE_ELF_CORE_DUMP +#define ELF_EXEC_PAGESIZE 4096 + +enum { + ARM_HWCAP_A64_FP = 1 << 0, + ARM_HWCAP_A64_ASIMD = 1 << 1, + ARM_HWCAP_A64_EVTSTRM = 1 << 2, + ARM_HWCAP_A64_AES = 1 << 3, + ARM_HWCAP_A64_PMULL = 1 << 4, + ARM_HWCAP_A64_SHA1 = 1 << 5, + ARM_HWCAP_A64_SHA2 = 1 << 6, + ARM_HWCAP_A64_CRC32 = 1 << 7, + ARM_HWCAP_A64_ATOMICS = 1 << 8, + ARM_HWCAP_A64_FPHP = 1 << 9, + ARM_HWCAP_A64_ASIMDHP = 1 << 10, + ARM_HWCAP_A64_CPUID = 1 << 11, + ARM_HWCAP_A64_ASIMDRDM = 1 << 12, + ARM_HWCAP_A64_JSCVT = 1 << 13, + ARM_HWCAP_A64_FCMA = 1 << 14, + ARM_HWCAP_A64_LRCPC = 1 << 15, + ARM_HWCAP_A64_DCPOP = 1 << 16, + ARM_HWCAP_A64_SHA3 = 1 << 17, + ARM_HWCAP_A64_SM3 = 1 << 18, + ARM_HWCAP_A64_SM4 = 1 << 19, + ARM_HWCAP_A64_ASIMDDP = 1 << 20, + ARM_HWCAP_A64_SHA512 = 1 << 21, + ARM_HWCAP_A64_SVE = 1 << 22, + ARM_HWCAP_A64_ASIMDFHM = 1 << 23, + ARM_HWCAP_A64_DIT = 1 << 24, + ARM_HWCAP_A64_USCAT = 1 << 25, + ARM_HWCAP_A64_ILRCPC = 1 << 26, + ARM_HWCAP_A64_FLAGM = 1 << 27, + ARM_HWCAP_A64_SSBS = 1 << 28, + ARM_HWCAP_A64_SB = 1 << 29, + ARM_HWCAP_A64_PACA = 1 << 30, + ARM_HWCAP_A64_PACG = 1UL << 31, + + ARM_HWCAP2_A64_DCPODP = 1 << 0, + ARM_HWCAP2_A64_SVE2 = 1 << 1, + ARM_HWCAP2_A64_SVEAES = 1 << 2, + ARM_HWCAP2_A64_SVEPMULL = 1 << 3, + ARM_HWCAP2_A64_SVEBITPERM = 1 << 4, + ARM_HWCAP2_A64_SVESHA3 = 1 << 5, + ARM_HWCAP2_A64_SVESM4 = 1 << 6, + ARM_HWCAP2_A64_FLAGM2 = 1 << 7, + ARM_HWCAP2_A64_FRINT = 1 << 8, + ARM_HWCAP2_A64_SVEI8MM = 1 << 9, + ARM_HWCAP2_A64_SVEF32MM = 1 << 10, + ARM_HWCAP2_A64_SVEF64MM = 1 << 11, + ARM_HWCAP2_A64_SVEBF16 = 1 << 12, + ARM_HWCAP2_A64_I8MM = 1 << 13, + ARM_HWCAP2_A64_BF16 = 1 << 14, + ARM_HWCAP2_A64_DGH = 1 << 15, + ARM_HWCAP2_A64_RNG = 1 << 16, + ARM_HWCAP2_A64_BTI = 1 << 17, + ARM_HWCAP2_A64_MTE = 1 << 18, +}; + +#define ELF_HWCAP get_elf_hwcap() +#define ELF_HWCAP2 get_elf_hwcap2() + +#define GET_FEATURE_ID(feat, hwcap) \ + do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) + +static uint32_t get_elf_hwcap(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + uint32_t hwcaps = 0; + + hwcaps |= ARM_HWCAP_A64_FP; + hwcaps |= ARM_HWCAP_A64_ASIMD; + hwcaps |= ARM_HWCAP_A64_CPUID; + + /* probe for the extra features */ + + GET_FEATURE_ID(aa64_aes, ARM_HWCAP_A64_AES); + GET_FEATURE_ID(aa64_pmull, ARM_HWCAP_A64_PMULL); + GET_FEATURE_ID(aa64_sha1, ARM_HWCAP_A64_SHA1); + GET_FEATURE_ID(aa64_sha256, ARM_HWCAP_A64_SHA2); + GET_FEATURE_ID(aa64_sha512, ARM_HWCAP_A64_SHA512); + GET_FEATURE_ID(aa64_crc32, ARM_HWCAP_A64_CRC32); + GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3); + GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3); + GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4); + GET_FEATURE_ID(aa64_fp16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); + GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS); + GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM); + GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP); + GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA); + GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE); + GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG); + GET_FEATURE_ID(aa64_fhm, ARM_HWCAP_A64_ASIMDFHM); + GET_FEATURE_ID(aa64_jscvt, ARM_HWCAP_A64_JSCVT); + GET_FEATURE_ID(aa64_sb, ARM_HWCAP_A64_SB); + GET_FEATURE_ID(aa64_condm_4, ARM_HWCAP_A64_FLAGM); + GET_FEATURE_ID(aa64_dcpop, ARM_HWCAP_A64_DCPOP); + GET_FEATURE_ID(aa64_rcpc_8_3, ARM_HWCAP_A64_LRCPC); + GET_FEATURE_ID(aa64_rcpc_8_4, ARM_HWCAP_A64_ILRCPC); + + return hwcaps; +} + +static uint32_t get_elf_hwcap2(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + uint32_t hwcaps = 0; + + GET_FEATURE_ID(aa64_dcpodp, ARM_HWCAP2_A64_DCPODP); + GET_FEATURE_ID(aa64_sve2, ARM_HWCAP2_A64_SVE2); + GET_FEATURE_ID(aa64_sve2_aes, ARM_HWCAP2_A64_SVEAES); + GET_FEATURE_ID(aa64_sve2_pmull128, ARM_HWCAP2_A64_SVEPMULL); + GET_FEATURE_ID(aa64_sve2_bitperm, ARM_HWCAP2_A64_SVEBITPERM); + GET_FEATURE_ID(aa64_sve2_sha3, ARM_HWCAP2_A64_SVESHA3); + GET_FEATURE_ID(aa64_sve2_sm4, ARM_HWCAP2_A64_SVESM4); + GET_FEATURE_ID(aa64_condm_5, ARM_HWCAP2_A64_FLAGM2); + GET_FEATURE_ID(aa64_frint, ARM_HWCAP2_A64_FRINT); + GET_FEATURE_ID(aa64_sve_i8mm, ARM_HWCAP2_A64_SVEI8MM); + GET_FEATURE_ID(aa64_sve_f32mm, ARM_HWCAP2_A64_SVEF32MM); + GET_FEATURE_ID(aa64_sve_f64mm, ARM_HWCAP2_A64_SVEF64MM); + GET_FEATURE_ID(aa64_sve_bf16, ARM_HWCAP2_A64_SVEBF16); + GET_FEATURE_ID(aa64_i8mm, ARM_HWCAP2_A64_I8MM); + GET_FEATURE_ID(aa64_bf16, ARM_HWCAP2_A64_BF16); + GET_FEATURE_ID(aa64_rndr, ARM_HWCAP2_A64_RNG); + GET_FEATURE_ID(aa64_bti, ARM_HWCAP2_A64_BTI); + GET_FEATURE_ID(aa64_mte, ARM_HWCAP2_A64_MTE); + + return hwcaps; +} + +#undef GET_FEATURE_ID + +#endif /* TARGET_ARCH_ELF_H */ diff --git a/bsd-user/aarch64/target_arch_vmparam.h b/bsd-user/aarch64/target_arch_vmparam.h index dc66e1289b5..0c354919708 100644 --- a/bsd-user/aarch64/target_arch_vmparam.h +++ b/bsd-user/aarch64/target_arch_vmparam.h @@ -65,4 +65,10 @@ static inline void set_second_rval(CPUARMState *state, abi_ulong retval2) { state->xregs[1] = retval2; /* XXX not really used on 64-bit arch */ } + +static inline abi_ulong get_second_rval(CPUARMState *state) +{ + return state->xregs[1]; +} + #endif /* TARGET_ARCH_VMPARAM_H */ From patchwork Mon Jul 22 21:43:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 669C4C3DA5D for ; Mon, 22 Jul 2024 21:47:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0q8-0005YI-VA; Mon, 22 Jul 2024 17:45:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0py-00052u-BO for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pt-0004JK-BY for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:54 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-8076cee8607so187339139f.1 for ; Mon, 22 Jul 2024 14:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684687; x=1722289487; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W3XlKNMv+/RjVBRuGDBQWo+adXw6lKr/2b70+lGZd98=; b=ihEaJ8WYzg5Y2hA7H0SnRhB2UWxrXfl+A37SudlDv4KzVjerFf30o08M9RX1/NjawL TjlU7Q6PTVNYG1+CofEI8hVdGI9EdDXIpRht3+TMTG2te7cMoKwEa3FhYLqWouhdyU+0 ha736t6QKoQ+zN6CArbqdytO/d9eVNf7QpLMniGeKpViRtATQSFd+7GRah6Bb/7Ur84N gdgX2vH4eTqlv0qOKWzAHCnDgvp2vQiuyUSSWHDlXEURtspCmY8nqXgpBnTwalUyMb/E mgcvlLZPLACL9yJviNxqmxyc9cR33j1yiMvRjySnfU4rd0W89rrY08R5nKaJmc8P9U/H wZCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684687; x=1722289487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W3XlKNMv+/RjVBRuGDBQWo+adXw6lKr/2b70+lGZd98=; b=nQXxMQekDEDuifG3W1aZD+DdJ72mh/eyF0UyuGuyxkasSsi3SyooM51sEW2xjs+jYF gh2N4k9lA2g86HnKvhaKy5tsfzi49s6i8KwN6PgCrDzYbdo/qeIjhYjGyzPVsY6znYqC bObq7qzXpXbcx376NbmSqyubU2a0bDNtcm4cmr76ZUkhbvPOibKy5EL5OHGs9Dqlsg0G c+j5E54T74qPyYuufZp0u8l9M0DP0cH0wcJhJh+ZAVKOkgBxUjRSBUkfPGacFQGXsDPx +doncRa+s6KLJ6Q4pfiDLWyvoZWyfKTNtoUevRrpAEpdYOsz3AcuwsDgdcY7FHTJuqwo j94Q== X-Gm-Message-State: AOJu0YxUlnKwi+c50EP48SXk8xzY5jRxnGqy6NMc30oGXt5jhDcj9c5e CpdaEdFB1IBp/wOhRsEUiMtr+h0BznnTRVkCFGQ3ywzamc2P/MszNrekVu0TwJPRrW7WWhH155Z g09I= X-Google-Smtp-Source: AGHT+IFLRWZtjPPVCHQMops76WOqugv56agD1sdefR5GPJ2ZQfmb27VRYKYSh6ZDtC5F1/89bHvc7A== X-Received: by 2002:a05:6602:640d:b0:80f:81f5:b46c with SMTP id ca18e2360f4ac-81aab6d5260mr1017056039f.15.1721684687032; Mon, 22 Jul 2024 14:44:47 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:46 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Richard Henderson Subject: [PATCH 04/14] bsd-user:Add ARM AArch64 signal handling support Date: Mon, 22 Jul 2024 15:43:03 -0600 Message-ID: <20240722214313.89503-5-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Added sigcode setup function for signal trampoline which initializes a sequence of instructions to handle signal returns and exits, copying this code to the target offset. Defined ARM AArch64 specific signal definitions including register indices and sizes, and introduced structures to represent general purpose registers, floating point registers, and machine context. Added function to set up signal handler arguments, populating register values in `CPUARMState` based on the provided signal, signal frame, signal action, and frame address. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Co-authored-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-5-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/signal.c | 53 ++++++++++++++++ bsd-user/aarch64/target_arch_signal.h | 80 +++++++++++++++++++++++++ bsd-user/aarch64/target_arch_sigtramp.h | 48 +++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 bsd-user/aarch64/signal.c create mode 100644 bsd-user/aarch64/target_arch_signal.h create mode 100644 bsd-user/aarch64/target_arch_sigtramp.h diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c new file mode 100644 index 00000000000..98861f9ab3b --- /dev/null +++ b/bsd-user/aarch64/signal.c @@ -0,0 +1,53 @@ +/* + * ARM AArch64 specific signal definitions for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ +#include "qemu/osdep.h" + +#include "qemu.h" + +/* + * Compare to sendsig() in sys/arm64/arm64/machdep.c + * Assumes that target stack frame memory is locked. + */ +abi_long set_sigtramp_args(CPUARMState *regs, int sig, + struct target_sigframe *frame, + abi_ulong frame_addr, + struct target_sigaction *ka) +{ + /* + * Arguments to signal handler: + * x0 = signal number + * x1 = siginfo pointer + * x2 = ucontext pointer + * pc/elr = signal handler pointer + * sp = sigframe struct pointer + * lr = sigtramp at base of user stack + */ + + regs->xregs[0] = sig; + regs->xregs[1] = frame_addr + + offsetof(struct target_sigframe, sf_si); + regs->xregs[2] = frame_addr + + offsetof(struct target_sigframe, sf_uc); + + regs->pc = ka->_sa_handler; + regs->xregs[TARGET_REG_SP] = frame_addr; + regs->xregs[TARGET_REG_LR] = TARGET_PS_STRINGS - TARGET_SZSIGCODE; + + return 0; +} diff --git a/bsd-user/aarch64/target_arch_signal.h b/bsd-user/aarch64/target_arch_signal.h new file mode 100644 index 00000000000..df171733166 --- /dev/null +++ b/bsd-user/aarch64/target_arch_signal.h @@ -0,0 +1,80 @@ +/* + * ARM AArch64 specific signal definitions for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_SIGNAL_H +#define TARGET_ARCH_SIGNAL_H + +#include "cpu.h" + +#define TARGET_REG_X0 0 +#define TARGET_REG_X30 30 +#define TARGET_REG_X31 31 +#define TARGET_REG_LR TARGET_REG_X30 +#define TARGET_REG_SP TARGET_REG_X31 + +#define TARGET_INSN_SIZE 4 /* arm64 instruction size */ + +/* Size of the signal trampolin code. See _sigtramp(). */ +#define TARGET_SZSIGCODE ((abi_ulong)(9 * TARGET_INSN_SIZE)) + +/* compare to sys/arm64/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (1024 * 4) /* min sig stack size */ +#define TARGET_SIGSTKSZ (TARGET_MINSIGSTKSZ + 32768) /* recommended size */ + +/* struct __mcontext in sys/arm64/include/ucontext.h */ + +struct target_gpregs { + uint64_t gp_x[30]; + uint64_t gp_lr; + uint64_t gp_sp; + uint64_t gp_elr; + uint32_t gp_spsr; + uint32_t gp_pad; +}; + +struct target_fpregs { + __uint128_t fp_q[32]; + uint32_t fp_sr; + uint32_t fp_cr; + uint32_t fp_flags; + uint32_t fp_pad; +}; + +struct target__mcontext { + struct target_gpregs mc_gpregs; + struct target_fpregs mc_fpregs; + uint32_t mc_flags; +#define TARGET_MC_FP_VALID 0x1 + uint32_t mc_pad; + uint64_t mc_spare[8]; +}; + +typedef struct target__mcontext target_mcontext_t; + +#define TARGET_MCONTEXT_SIZE 880 +#define TARGET_UCONTEXT_SIZE 960 + +#include "target_os_ucontext.h" + +struct target_sigframe { + target_siginfo_t sf_si; /* saved siginfo */ + target_ucontext_t sf_uc; /* saved ucontext */ +}; + +#endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/aarch64/target_arch_sigtramp.h b/bsd-user/aarch64/target_arch_sigtramp.h new file mode 100644 index 00000000000..8cdd33b621d --- /dev/null +++ b/bsd-user/aarch64/target_arch_sigtramp.h @@ -0,0 +1,48 @@ +/* + * ARM AArch64 sigcode for bsd-user + * + * Copyright (c) 2015 Stacey D. Son + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#ifndef TARGET_ARCH_SIGTRAMP_H +#define TARGET_ARCH_SIGTRAMP_H + +/* Compare to ENTRY(sigcode) in arm64/arm64/locore.S */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, + unsigned sys_sigreturn) +{ + int i; + uint32_t sys_exit = TARGET_FREEBSD_NR_exit; + + uint32_t sigtramp_code[] = { + /* 1 */ 0x910003e0, /* mov x0, sp */ + /* 2 */ 0x91000000 + (sigf_uc << 10), /* add x0, x0, #SIGF_UC */ + /* 3 */ 0xd2800000 + (sys_sigreturn << 5) + 0x8, /* mov x8, #SYS_sigreturn */ + /* 4 */ 0xd4000001, /* svc #0 */ + /* 5 */ 0xd2800028 + (sys_exit << 5) + 0x8, /* mov x8, #SYS_exit */ + /* 6 */ 0xd4000001, /* svc #0 */ + /* 7 */ 0x17fffffc, /* b -4 */ + /* 8 */ sys_sigreturn, + /* 9 */ sys_exit + }; + + for (i = 0; i < 9; i++) { + tswap32s(&sigtramp_code[i]); + } + + return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* TARGET_ARCH_SIGTRAMP_H */ From patchwork Mon Jul 22 21:43:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2ADFC3DA59 for ; Mon, 22 Jul 2024 21:47:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qY-0007H7-Sa; Mon, 22 Jul 2024 17:45:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0py-00052n-1t for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pt-0004JY-Lb for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:53 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-808a8c90f5bso187017239f.2 for ; Mon, 22 Jul 2024 14:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684688; x=1722289488; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6l2giQ2DgrY0GVfdS/Z1DlHyLIcTuXalMYf+UrzR91E=; b=KiujD1ooZD027gZetN1OzZnkXhKtxtr5sUZZDYK+tq3F/J5lTvzwMbBs9rd7+XMcBY ZY/xDJS6hsA3XHC4NXZL4Ul8y8L8azF6LwnVRWn/I40AqZ/wiw0IyCarfDP1rXu4dH34 y7uNOOtKFMAAe5/jWzGJ0bIrLAZOi4zKPkEk4EfCr+vQZwGukXbh8hUu/JiiaqjSLzfE 0HdrkXpIqcnuA6Vc7AvPmu0W03EUObygsjlvOkTyczzIwGsOjwHroJCQnrSznM3v4IJQ rENiJkii5jBMqQFSMTVdHKOPtnmgBu4pKEOM/Hwhx+aqDZdWIB6fEi9uOke/7fUaFjQB C+ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684688; x=1722289488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6l2giQ2DgrY0GVfdS/Z1DlHyLIcTuXalMYf+UrzR91E=; b=FY1xR2OYjgC92dwNxRaTTQW1KbQeuOc324A9XL+DozaoS9ceNeQ3EHu1/hqbRW4zMc QavVAx2shV+ypaetJbJcr5hcxt+ije+pIeooQpp/5OWkWV8dhcsWiXoMapyD/eiYbKna s+wOlrJ9LS4qfncePsa2IEXKNHtr0a4RbEqxMIs9/HO7dJ27mDYXyiNJCjDU+vIU1vjW wy6g5kz7AJxn7LHj0inw/sEkNRC4VxijOLIdez0wyLlYWsMoxYYK7YG2QzCAO0CPuOEI ar9b0X3zb903W+X6knRA4B2bttCvyyi9Vmbu0IzO6dtqzdD24pgcRKnsAxyZnMT8P6X0 AoRA== X-Gm-Message-State: AOJu0Yy7lo0yQzCvGmiFEaGZvqhsDPrRtlxA/0qiqL+g9HAjpJFxAVqC PKbvLwI8Eg3m3XVpclTMjAlX4V1BInL5prJmJaJ3x5v+ZL9/w4aIHUhrjqSDUCXw/SrvhYr/sv4 kdIs= X-Google-Smtp-Source: AGHT+IGcRMGjtNEgsWxBLsdkW6NYzKwCKPI1HCCAaJovVoKMfl9zfqSbr7hJY0JUJqfBcPiHwl3XBw== X-Received: by 2002:a05:6602:2d93:b0:803:85ba:3cf9 with SMTP id ca18e2360f4ac-81b33a0ca27mr1026733139f.10.1721684688327; Mon, 22 Jul 2024 14:44:48 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:47 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Kyle Evans , Richard Henderson Subject: [PATCH 05/14] bsd-user:Add get_mcontext function for ARM AArch64 Date: Mon, 22 Jul 2024 15:43:04 -0600 Message-ID: <20240722214313.89503-6-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son function to retrieve machine context,it populates the provided target_mcontext_t structure with information from the CPUARMState registers. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Co-authored-by: Kyle Evans Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-6-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/signal.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c index 98861f9ab3b..ab3bf8558ab 100644 --- a/bsd-user/aarch64/signal.c +++ b/bsd-user/aarch64/signal.c @@ -51,3 +51,33 @@ abi_long set_sigtramp_args(CPUARMState *regs, int sig, return 0; } + +/* + * Compare to get_mcontext() in arm64/arm64/machdep.c + * Assumes that the memory is locked if mcp points to user memory. + */ +abi_long get_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int flags) +{ + int err = 0, i; + uint64_t *gr = mcp->mc_gpregs.gp_x; + + mcp->mc_gpregs.gp_spsr = pstate_read(regs); + if (flags & TARGET_MC_GET_CLEAR_RET) { + gr[0] = 0UL; + mcp->mc_gpregs.gp_spsr &= ~CPSR_C; + } else { + gr[0] = tswap64(regs->xregs[0]); + } + + for (i = 1; i < 30; i++) { + gr[i] = tswap64(regs->xregs[i]); + } + + mcp->mc_gpregs.gp_sp = tswap64(regs->xregs[TARGET_REG_SP]); + mcp->mc_gpregs.gp_lr = tswap64(regs->xregs[TARGET_REG_LR]); + mcp->mc_gpregs.gp_elr = tswap64(regs->pc); + + /* XXX FP? */ + + return err; +} From patchwork Mon Jul 22 21:43:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABF36C3DA59 for ; Mon, 22 Jul 2024 21:46:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qA-0005cj-5k; Mon, 22 Jul 2024 17:45:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0py-00052t-BO for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: from mail-io1-xd36.google.com ([2607:f8b0:4864:20::d36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pv-0004Jv-4u for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:54 -0400 Received: by mail-io1-xd36.google.com with SMTP id ca18e2360f4ac-8036ce6631bso192165939f.1 for ; Mon, 22 Jul 2024 14:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684689; x=1722289489; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TXCw0+RJXjXO156yoRFr2t5+0iBs33zwi5q8sWmsNWs=; b=mGImdnD6NnY2fiyMxfff6bzdmMsZ4PCTGUG0fv4jw0BaE7TjCSWTxxe17AgcFVxlnD nqjo/ezwe0hhuwsnbyosVFuFfJ6bov0zchrm6ufpsmCHgRJsBGGR6AHtFCR0JrW0GT5X QlPsn+ph3iauhRZDpDUT7YJNPv9tPrZM3+q/PomNq8K5CZFDYyHuNdOIZcBpgEa1tGMg GHrVjAt/5JcEWfT0j2O82G5TCmtiHoeL5DcYuXSEpz46srNn5kzgzuqcq/zjYSSP3wao 6SHjJFWRFtgQTmde3CThIDA8lLXuFzYKYArPrJx+XPIXzFjXRW26A/oDuQS9i6B1YF94 hzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684689; x=1722289489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TXCw0+RJXjXO156yoRFr2t5+0iBs33zwi5q8sWmsNWs=; b=AmqZp/5LMfU+ClvejZLQDuQMbN46CZFJt3LvHDrLpItjvvQy9/eYWC3+lJA/18SqHM LBlsrp9+s9zlUb5vXlTxNkvJ7RSdj0k2FrSlcSZI5bXYs8sjGKw56AEvep5pWImeJ8WS 0ZIu8IkOscWTD3Mz3ABKqf78InEOUMEAjuhany7KLOEVQNM2JuC07n5V8dOBifN43DnK 6ZyDfcHqZjHJVDJQag11ToNwn+npHPXeDdaSq6aQSoiAX00ScvbFNpLP7vSgqz+SUIo1 AoJCo8hDyaCVTAo7UBhZb4CzwONGhLUUOq5gsx5/HaV8IgISkwhcYERKRMroUThK2l+B VZEQ== X-Gm-Message-State: AOJu0YyrhbQT3ieXfBUZZd0sW/Jo5Juo4c1kO+HRGkblYBKB+eawxUY2 zz8R1uMCzJZ0djUxFrZzr32aRluzgN+bxnSNpSYdjvrcSMiej8+YtgGCJqZp67XaGJKqY1M1LgH 8wIY= X-Google-Smtp-Source: AGHT+IEE7ofsla5+qarLZe2qwNUP8j1KYkTYoknhXr7sHyAtMVrKF+Ne0JSP6eDG9jUdcBflGLgryQ== X-Received: by 2002:a05:6602:6003:b0:804:9972:2f8c with SMTP id ca18e2360f4ac-81ea375ce88mr139197139f.8.1721684689326; Mon, 22 Jul 2024 14:44:49 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:48 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Ajeet Singh , Richard Henderson Subject: [PATCH 06/14] bsd-user:Add setup_sigframe_arch function for ARM AArch64 Date: Mon, 22 Jul 2024 15:43:05 -0600 Message-ID: <20240722214313.89503-7-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d36; envelope-from=imp@bsdimp.com; helo=mail-io1-xd36.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The function utilizes the `get_mcontext` function to retrieve the machine context for the current CPUARMState Signed-off-by: Warner Losh Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-7-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/signal.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c index ab3bf8558ab..43c886e6036 100644 --- a/bsd-user/aarch64/signal.c +++ b/bsd-user/aarch64/signal.c @@ -81,3 +81,17 @@ abi_long get_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int flags) return err; } + +/* + * Compare to arm64/arm64/exec_machdep.c sendsig() + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr, + struct target_sigframe *frame, int flags) +{ + target_mcontext_t *mcp = &frame->sf_uc.uc_mcontext; + + get_mcontext(env, mcp, flags); + return 0; +} + From patchwork Mon Jul 22 21:43:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C182C3DA59 for ; Mon, 22 Jul 2024 21:47:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qN-0006UV-Mg; Mon, 22 Jul 2024 17:45:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0pz-00054K-VU for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:56 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0px-0004KR-Q3 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:55 -0400 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-396db51d140so20196025ab.0 for ; Mon, 22 Jul 2024 14:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684690; x=1722289490; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=htzmk2/K+pRyHcINVlqMN9Cf2KcnbziuOXxz3Bx5eFI=; b=Q7p7BXAe99KQR4PifoFNy572eoP/uNChEYLfdhfjT9M8iPyW08+kt/i5jZOJLAKVsk p1aAuQP9bQB6ZGWqU27oUySryDP9tzU3gXtYCU031kBzqeHfc0NVaN2MIuj4AnAtZqQh IaWqs5LG9FiPX1aQbumFIjN0ZbCpZ+3YtQe0oKk7sExyPT/arnBD7Qoy3BXgUuIanwq9 9NIlpKKclnlio3oqKy6v6pEAyo+bsTK9VbsPhJi0v+PayMHVY2/A7eoKGLoyObxp2arM Fj4c6iBByDqGvzz5CJ6QnlfwanDZyDt/icF/fD1EBq1ezO/tnaG2muIu4Y4gCl8Q/b+3 Uabw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684690; x=1722289490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=htzmk2/K+pRyHcINVlqMN9Cf2KcnbziuOXxz3Bx5eFI=; b=g4Q+HB7UD3+hIyKykDTvgN/JBg/qD1x6YdZ5Y/FoCtZEH/ab1fp8VL0LlOyeXvQqJm FHR+FVe4YvgK92guuMQrkDCqjRNQlCIS7VGQ94e2Xgc3IGemv9rC3zksWHvwH4dPA3pZ wb0/lqiubQEAGjwHCN8RhLG+Nks+y7A0zp7KKGyxknxmrruiRjRMrpAQRwB0HfKjjNjz aIvI6o9AvXWPTAiXtlaaxX1/mqwoEio49/1n7GA4prYXV8eztxeMvh0yqeTorpdnifml t17FF/jd3AO8A8VXetLwvsomFWkzLfuWMg+f8g82GP5+/RMl9t8fJMJB+1/XCG892ine sVRQ== X-Gm-Message-State: AOJu0YzC/8ktLB387cDJ0uWajIDQJrCoZTzItDLRkhQgj0y3+vd2dYG/ GjOLzqczBcStTcPfItLLf80liV4li3cIPpw4THI6GQ4KrJBd9+92se3M8DnPzbEWkC7f3YNT2th q3aI= X-Google-Smtp-Source: AGHT+IExN1016SDsl3c0PDoDU6AihToztpkSgd5my0DyuLi0BgU3j+f5i53o6mDuTu8nD7qVKnOxCw== X-Received: by 2002:a05:6e02:1a8c:b0:383:6af0:eb08 with SMTP id e9e14a558f8ab-398e420f849mr117635995ab.1.1721684690581; Mon, 22 Jul 2024 14:44:50 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:49 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Richard Henderson Subject: [PATCH 07/14] bsd-user:Add set_mcontext function for ARM AArch64 Date: Mon, 22 Jul 2024 15:43:06 -0600 Message-ID: <20240722214313.89503-8-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::135; envelope-from=imp@bsdimp.com; helo=mail-il1-x135.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son The function copies register values from the provided target_mcontext_t structure to the CPUARMState registers. Note:FP is unfinished upstream but will be a separate commit coming soon. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-8-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c index 43c886e6036..13faac8ce60 100644 --- a/bsd-user/aarch64/signal.c +++ b/bsd-user/aarch64/signal.c @@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr, return 0; } +/* + * Compare to set_mcontext() in arm64/arm64/machdep.c + * Assumes that the memory is locked if frame points to user memory. + */ +abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag) +{ + int err = 0, i; + const uint64_t *gr = mcp->mc_gpregs.gp_x; + + for (i = 0; i < 30; i++) { + regs->xregs[i] = tswap64(gr[i]); + } + + regs->xregs[TARGET_REG_SP] = tswap64(mcp->mc_gpregs.gp_sp); + regs->xregs[TARGET_REG_LR] = tswap64(mcp->mc_gpregs.gp_lr); + regs->pc = mcp->mc_gpregs.gp_elr; + pstate_write(regs, mcp->mc_gpregs.gp_spsr); + + /* XXX FP? */ + + return err; +} From patchwork Mon Jul 22 21:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 459A2C3DA5D for ; Mon, 22 Jul 2024 21:45:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qB-0005dL-91; Mon, 22 Jul 2024 17:45:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q0-00056h-DY for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:56 -0400 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0px-0004Kj-Q9 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:56 -0400 Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-8152f0c63c1so187726839f.1 for ; Mon, 22 Jul 2024 14:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684692; x=1722289492; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iERzhBKroDxEdhIs7F3pdJn/htP75xFz5hRc3MKZk4Y=; b=H1cLCdtVoiqoH+MpH5b/fzvvPI3crrtcGxT85rHtUb1FpFUEDXEbl7OPBuCorRvuNT 0QTRB34ivL4ffB7UMiFa7P5Ehf4ZgVt9xIT18tTRx25LsSPkM1vA+u0dtm5GHVhV0SVc WZLRoDLI6RUv3z4QpXERruMkamM82YqAvBORo/5Yr5LmrniQFDAtiB3Zn635pH1JrIG7 /sD14vRSKE72C0QmUsZ36WLqnoVZhvX7hMCiJVW0ZEPo0kI71Z3pt0eJSZ0QaeirwsyX f5CodWEOrEoGGi51xRil1Mpz7ZoDPhUeeyj12EpQLvET8DKiL/M4jVtWvI6llW9lh4pr xcrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684692; x=1722289492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iERzhBKroDxEdhIs7F3pdJn/htP75xFz5hRc3MKZk4Y=; b=FtbQ1ByoNkWaeo64st1/WfiopY2xyr7sNEBHQ2woKDVMBTe4iycNgCkIYwbmaqQLwF qo0wTySU7N12JWxcqjbZ4fzJAV/EMrI52xGgKfacBORyLYRSeB9vrNjtQ+yaDNZkolka yZw/NLEGY0bVnk2y7MYTC3ff5bOqM8jYyN+7T6PsSd+gmDmi+5HOMIcRXoZ2njxjrNiP 7CxiyrO2jkMCQyzJQvtO/c4qXfMRlk1ekAxi8nGBVnrLulAbU9B4Iyjk9zeRR9CD9ch9 DAx+P1Hy56TKO11VpouUY2d9E56TcjWZ9UGETV/XykRHHfoBsmgWtcflkjfupk7gIpHA BVjA== X-Gm-Message-State: AOJu0YxPHNJEyda9Nnbs+OxvExIir88IGB1FtjCIBrwaxO3OuWk2iWkk iYDoZEoAk0Ayr3aBQ6E1A05D3DrmePFm39YMBh0iLXr7CzkpyrIfHTFTEyvYp2t8iiNxeWZsMx1 SCus= X-Google-Smtp-Source: AGHT+IF+pM79W/+yxi2cfrLz8Mbnqb5WjL9O4G1JD8Yoy46NXP0enK/nJpEcF2NcjIS40X+aQ9ywnA== X-Received: by 2002:a05:6602:341b:b0:803:cc64:e0d4 with SMTP id ca18e2360f4ac-81ea30a2dedmr155466039f.3.1721684691856; Mon, 22 Jul 2024 14:44:51 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:51 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Stacey Son , Ajeet Singh , Richard Henderson Subject: [PATCH 08/14] bsd-user:Add AArch64 improvements and signal handling functions Date: Mon, 22 Jul 2024 15:43:07 -0600 Message-ID: <20240722214313.89503-9-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2f; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stacey Son Added get_ucontext_sigreturn function to check processor state ensuring current execution mode is EL0 and no flags indicating interrupts or exceptions are set. Updated AArch64 code to use CF directly without reading/writing the entire processor state, improving efficiency. Changed FP data structures to use Int128 instead of __uint128_t, leveraging QEMU's generic mechanism for referencing this type. Signed-off-by: Stacey Son Signed-off-by: Ajeet Singh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Message-Id: <20240707191128.10509-9-itachis@FreeBSD.org> Signed-off-by: Warner Losh --- bsd-user/aarch64/signal.c | 20 +++++++++++++++++++- bsd-user/aarch64/target_arch_cpu.h | 7 ++----- bsd-user/aarch64/target_arch_reg.h | 2 +- bsd-user/aarch64/target_arch_signal.h | 2 +- bsd-user/qemu.h | 3 +++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c index 13faac8ce60..6bc73a798f3 100644 --- a/bsd-user/aarch64/signal.c +++ b/bsd-user/aarch64/signal.c @@ -21,7 +21,7 @@ #include "qemu.h" /* - * Compare to sendsig() in sys/arm64/arm64/machdep.c + * Compare to sendsig() in sys/arm64/arm64/exec_machdep.c * Assumes that target stack frame memory is locked. */ abi_long set_sigtramp_args(CPUARMState *regs, int sig, @@ -117,3 +117,21 @@ abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag) return err; } + +/* Compare to sys_sigreturn() in arm64/arm64/machdep.c */ +abi_long get_ucontext_sigreturn(CPUARMState *regs, abi_ulong target_sf, + abi_ulong *target_uc) +{ + uint32_t pstate = pstate_read(regs); + + *target_uc = 0; + + if ((pstate & PSTATE_M) != PSTATE_MODE_EL0t || + (pstate & (PSTATE_F | PSTATE_I | PSTATE_A | PSTATE_D)) != 0) { + return -TARGET_EINVAL; + } + + *target_uc = target_sf; + + return 0; +} diff --git a/bsd-user/aarch64/target_arch_cpu.h b/bsd-user/aarch64/target_arch_cpu.h index 5c150bb7e9c..b288e0d069b 100644 --- a/bsd-user/aarch64/target_arch_cpu.h +++ b/bsd-user/aarch64/target_arch_cpu.h @@ -48,7 +48,6 @@ static inline void target_cpu_loop(CPUARMState *env) CPUState *cs = env_cpu(env); int trapnr, ec, fsc, si_code, si_signo; uint64_t code, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; - uint32_t pstate; abi_long ret; for (;;) { @@ -88,18 +87,16 @@ static inline void target_cpu_loop(CPUARMState *env) * The carry bit is cleared for no error; set for error. * See arm64/arm64/vm_machdep.c cpu_set_syscall_retval() */ - pstate = pstate_read(env); if (ret >= 0) { - pstate &= ~PSTATE_C; + env->CF = 0; env->xregs[0] = ret; } else if (ret == -TARGET_ERESTART) { env->pc -= 4; break; } else if (ret != -TARGET_EJUSTRETURN) { - pstate |= PSTATE_C; + env->CF = 1; env->xregs[0] = -ret; } - pstate_write(env, pstate); break; case EXCP_INTERRUPT: diff --git a/bsd-user/aarch64/target_arch_reg.h b/bsd-user/aarch64/target_arch_reg.h index 5c7154f0c18..b53302e7f7a 100644 --- a/bsd-user/aarch64/target_arch_reg.h +++ b/bsd-user/aarch64/target_arch_reg.h @@ -31,7 +31,7 @@ typedef struct target_reg { } target_reg_t; typedef struct target_fpreg { - __uint128_t fp_q[32]; + Int128 fp_q[32]; uint32_t fp_sr; uint32_t fp_cr; } target_fpreg_t; diff --git a/bsd-user/aarch64/target_arch_signal.h b/bsd-user/aarch64/target_arch_signal.h index df171733166..bff752a67ab 100644 --- a/bsd-user/aarch64/target_arch_signal.h +++ b/bsd-user/aarch64/target_arch_signal.h @@ -49,7 +49,7 @@ struct target_gpregs { }; struct target_fpregs { - __uint128_t fp_q[32]; + Int128 fp_q[32]; uint32_t fp_sr; uint32_t fp_cr; uint32_t fp_flags; diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index 9d2fc7148eb..3736c417860 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -17,6 +17,9 @@ #ifndef QEMU_H #define QEMU_H +#include + +#include "qemu/int128.h" #include "cpu.h" #include "qemu/units.h" #include "exec/cpu_ldst.h" From patchwork Mon Jul 22 21:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0C12C3DA5D for ; Mon, 22 Jul 2024 21:46:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qo-0000B6-74; Mon, 22 Jul 2024 17:45:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q3-00059j-0X for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:59 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pz-0004Kz-N5 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:58 -0400 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-81a90913cc3so123676539f.3 for ; Mon, 22 Jul 2024 14:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684693; x=1722289493; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mgzDiYKfsY/Li6vjyAqG/iPshllKaXou8dGmZQHJOII=; b=RbBAMAtmW69XA+qkqXVibg752LBkB/nh3PQTUKR7MYLXQInmFACqe3i81tRug42cMN P78PQOyFX3rWbpXDMPS3n03yT57RJUFZmLn4wiiDamuQ5KTM1ROC9B30YvrZAmHei/ir uwmSXA9xTrgItUcLEzEmYn2RYfZHDPNwI1CFglpmM/QfxXquwxenhPtjO2fRUzMnXjo9 LfJceZ5DONw3Kd/ZH1c+st8FaFwRcDoFqwpQgyHGZpqEBMgIOiJDGpE7B/7dl+9/sjxX mx0t38LpUNG4VZrk5PtcLvmqGR+gVKL/u368DO+TlTNLLHdZQtBDAYFAGB48HhXk+aKp QqJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684693; x=1722289493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mgzDiYKfsY/Li6vjyAqG/iPshllKaXou8dGmZQHJOII=; b=NF3vsTnymQIWSyUXJhtZiod1cmncn9B8gpAqdznzqm3TaGCopkNVLKVirN+s61R/hk Xoxrbq65P0Ab9G/dHS0jvrFi9meIgWNnBWYgF6p6pj+XjwLCqmy7EkZ7zhdUaH97VPec ivRQDTA2JnyfISSg7SdYsoMXmIuhmKZyg/6gmycS8s1k3ByEy8gQ3N7+ALOxfUwuymAi pDMig7K4LQpxuGivlHc3Vk0wBE3xo1xOmxnh9BJaCiD7TT4OCNZmrLflYHbWw4bzm0c2 mWkrO0GfS/LjR1gfA6bW2rnQBM7E0pVZX1L9JkguKRdex6euplm8zQax2vsWwKGJeOmG WBmg== X-Gm-Message-State: AOJu0Yz2s21lUpq/0dNgBXxP3n4HIUXDSGNVIlyv7xHjGTYfK3963sCF D3uL5bQLUNk64Ter7EcdDzvqGLy92+1xFb4o4zU1AlevYcRntZgPLBagOHPhApuzj6D7jp6m7K0 nIxE= X-Google-Smtp-Source: AGHT+IFwUdu8QXrO2+4kNpj0l/HONvedqc6ttzn26WJLiGQvjO8vUsTpRc61caVKOijaTXiEXUdCeQ== X-Received: by 2002:a05:6602:3406:b0:806:6b24:ee1e with SMTP id ca18e2360f4ac-81b35904d20mr994217739f.15.1721684692836; Mon, 22 Jul 2024 14:44:52 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:52 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Doug Rabson Subject: [PATCH 09/14] bsd-user: Simplify the implementation of execve Date: Mon, 22 Jul 2024 15:43:08 -0600 Message-ID: <20240722214313.89503-10-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Doug Rabson This removes the logic which prepends the emulator to each call to execve and fexecve. This is not necessary with the existing imgact_binmisc support and it avoids the need to install the emulator binary into jail environments when using 'binmiscctl --pre-open'. Signed-off-by: Doug Rabson Reviewed-by: Warner Losh Signed-off-by: Warner Losh Acked-by: Richard Henderson --- bsd-user/freebsd/os-proc.c | 118 +------------------------------------ bsd-user/main.c | 18 ------ 2 files changed, 3 insertions(+), 133 deletions(-) diff --git a/bsd-user/freebsd/os-proc.c b/bsd-user/freebsd/os-proc.c index e0203e259b0..bf993f1b662 100644 --- a/bsd-user/freebsd/os-proc.c +++ b/bsd-user/freebsd/os-proc.c @@ -26,65 +26,13 @@ struct kinfo_proc; #include "qemu.h" -/* - * Get the filename for the given file descriptor. - * Note that this may return NULL (fail) if no longer cached in the kernel. - */ -static char * -get_filename_from_fd(pid_t pid, int fd, char *filename, size_t len) -{ - char *ret = NULL; - unsigned int cnt; - struct procstat *procstat = NULL; - struct kinfo_proc *kp = NULL; - struct filestat_list *head = NULL; - struct filestat *fst; - - procstat = procstat_open_sysctl(); - if (procstat == NULL) { - goto out; - } - - kp = procstat_getprocs(procstat, KERN_PROC_PID, pid, &cnt); - if (kp == NULL) { - goto out; - } - - head = procstat_getfiles(procstat, kp, 0); - if (head == NULL) { - goto out; - } - - STAILQ_FOREACH(fst, head, next) { - if (fd == fst->fs_fd) { - if (fst->fs_path != NULL) { - (void)strlcpy(filename, fst->fs_path, len); - ret = filename; - } - break; - } - } - -out: - if (head != NULL) { - procstat_freefiles(procstat, head); - } - if (kp != NULL) { - procstat_freeprocs(procstat, kp); - } - if (procstat != NULL) { - procstat_close(procstat); - } - return ret; -} - /* * execve/fexecve */ abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, abi_ulong guest_envp, int do_fexec) { - char **argp, **envp, **qargp, **qarg1, **qarg0, **qargend; + char **argp, **envp, **qarg0; int argc, envc; abi_ulong gp; abi_ulong addr; @@ -117,9 +65,7 @@ abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, qarg0 = argp = g_new0(char *, argc + 9); /* save the first argument for the emulator */ *argp++ = (char *)getprogname(); - qargp = argp; *argp++ = (char *)getprogname(); - qarg1 = argp; envp = g_new0(char *, envc + 1); for (gp = guest_argp, q = argp; gp; gp += sizeof(abi_ulong), q++) { if (get_user_ual(addr, gp)) { @@ -137,7 +83,6 @@ abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, total_size += strlen(*q) + 1; } *q++ = NULL; - qargend = q; for (gp = guest_envp, q = envp; gp; gp += sizeof(abi_ulong), q++) { if (get_user_ual(addr, gp)) { @@ -166,71 +111,14 @@ abi_long freebsd_exec_common(abi_ulong path_or_fd, abi_ulong guest_argp, } if (do_fexec) { - if (((int)path_or_fd > 0 && - is_target_elf_binary((int)path_or_fd)) == 1) { - char execpath[PATH_MAX]; - - /* - * The executable is an elf binary for the target - * arch. execve() it using the emulator if we can - * determine the filename path from the fd. - */ - if (get_filename_from_fd(getpid(), (int)path_or_fd, execpath, - sizeof(execpath)) != NULL) { - memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); - qarg1[1] = qarg1[0]; - qarg1[0] = (char *)"-0"; - qarg1 += 2; - qargend += 2; - *qarg1 = execpath; -#ifndef DONT_INHERIT_INTERP_PREFIX - memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); - *qarg1++ = (char *)"-L"; - *qarg1++ = (char *)interp_prefix; -#endif - ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); - } else { - /* Getting the filename path failed. */ - ret = -TARGET_EBADF; - goto execve_end; - } - } else { - ret = get_errno(fexecve((int)path_or_fd, argp, envp)); - } + ret = get_errno(fexecve((int)path_or_fd, argp, envp)); } else { - int fd; - p = lock_user_string(path_or_fd); if (p == NULL) { ret = -TARGET_EFAULT; goto execve_end; } - - /* - * Check the header and see if it a target elf binary. If so - * then execute using qemu user mode emulator. - */ - fd = open(p, O_RDONLY | O_CLOEXEC); - if (fd > 0 && is_target_elf_binary(fd) == 1) { - close(fd); - /* execve() as a target binary using emulator. */ - memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); - qarg1[1] = qarg1[0]; - qarg1[0] = (char *)"-0"; - qarg1 += 2; - qargend += 2; - *qarg1 = (char *)p; -#ifndef DONT_INHERIT_INTERP_PREFIX - memmove(qarg1 + 2, qarg1, (qargend - qarg1) * sizeof(*qarg1)); - *qarg1++ = (char *)"-L"; - *qarg1++ = (char *)interp_prefix; -#endif - ret = get_errno(execve(qemu_proc_pathname, qargp, envp)); - } else { - close(fd); - /* Execve() as a host native binary. */ - ret = get_errno(execve(p, argp, envp)); - } + ret = get_errno(execve(p, argp, envp)); unlock_user(p, path_or_fd, 0); } diff --git a/bsd-user/main.c b/bsd-user/main.c index dcad266c2c9..82e94a03160 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -90,7 +90,6 @@ unsigned long reserved_va; const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; const char *qemu_uname_release; -char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */ unsigned long target_maxtsiz = TARGET_MAXTSIZ; /* max text size */ unsigned long target_dfldsiz = TARGET_DFLDSIZ; /* initial data size limit */ @@ -247,22 +246,6 @@ adjust_ssize(void) setrlimit(RLIMIT_STACK, &rl); } -static void save_proc_pathname(char *argv0) -{ - int mib[4]; - size_t len; - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PATHNAME; - mib[3] = -1; - - len = sizeof(qemu_proc_pathname); - if (sysctl(mib, 4, qemu_proc_pathname, &len, NULL, 0)) { - perror("sysctl"); - } -} - int main(int argc, char **argv) { const char *filename; @@ -292,7 +275,6 @@ int main(int argc, char **argv) usage(); } - save_proc_pathname(argv[0]); error_init(argv[0]); module_call_init(MODULE_INIT_TRACE); From patchwork Mon Jul 22 21:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CABA8C3DA59 for ; Mon, 22 Jul 2024 21:46:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qU-0006xc-3O; Mon, 22 Jul 2024 17:45:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q3-00059c-0R for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:59 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0pz-0004Lm-N2 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:57 -0400 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-8063553b837so202065939f.1 for ; Mon, 22 Jul 2024 14:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684694; x=1722289494; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VTuJWAM1/9aYMqyRTEKTG2Hu5YYuT8G1Kl37sm47X4c=; b=3NxBcAqAjFsobLQ9SNIZE5tSm2TyNu7ZE92K1qSljfxvq6ToZS2sMSInOiiNR8YG9G VLWxUgXyAcH2/cf7CcZiPnhPGrhDRWN1i+F3CtIbvLerjrjC3iOp32F95ZnrWlBWZPuR oyW0OsM99+4/q4+ZvqDnpHufSKK4fu+Ll6vvzTwA9tf7PG2o2KHFPChGmJ1uyr3EZhvh bzu78DJFVXsTyB/pHPBz7NMgdljpUFQYT+AsPSqm4EsdRg92s9JG2Q2DseLCFBi/iOls 6QXxsmzq9Hw7d0uGiU1VJGzlNuC80wywlZBZXMugYLc+gQWemG3F2UXUx9AWL4mNVVdr tjBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684694; x=1722289494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VTuJWAM1/9aYMqyRTEKTG2Hu5YYuT8G1Kl37sm47X4c=; b=Ph93g58uPWybYwGioHD5kO7wz8vPAmpULkoAT9VUOmD0WzOr6QCbboa0AyaR74y3nW Pfy0tWf+ejpDNMsTGBfTwKkB5PxGb5Vj2bNFnTopKi7mmNDHqNXXvDwNaTC8Ymeuo8hY pE/lQADajM1xE/xXxJd6D6LY+4eC67UnxaMW5i8CcfjeYNlV7GolV2/lA5MFnB+ZZYNP DpbganJ2R24LwRHXBAkUi/HaKyk8cGJc3bn9uGNFGcUyyqAAQwYwah3v4+f/mEwD2WF9 Q1DEanhdB5qakaoZVznSLdNlMHOWEY2rZ/aHzwxI8gRY5z5/zccM1RI5G/HyX+Pb4k1m wikg== X-Gm-Message-State: AOJu0Yy96ZS1xY1bX84LN4gtQeo6GWphyvPnDS6JIYq0+WMBiaoDSQZu 8uAiEOxKnLnhltZusmOXWyqlfEROoYeg3QN1xT2H7uXszIUWZWIELVWk6gu8zM5z/RK5AFOm1Wc m5O8= X-Google-Smtp-Source: AGHT+IFzpibUGs/6NIlMeAp0AkPbK/oG98xX355HT4vW/40bYSzBC5yUifP2a3d11P8qgJn5lq09kg== X-Received: by 2002:a05:6602:6196:b0:81e:23c9:3f69 with SMTP id ca18e2360f4ac-81e23c94004mr286704839f.7.1721684693926; Mon, 22 Jul 2024 14:44:53 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:53 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell Subject: [PATCH 10/14] bsd-user: Hard wire aarch64 to be 4k pages only Date: Mon, 22 Jul 2024 15:43:09 -0600 Message-ID: <20240722214313.89503-11-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d33; envelope-from=imp@bsdimp.com; helo=mail-io1-xd33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Only support 4k pages for aarch64 binaries. The variable page size stuff isn't working just yet, so put in this lessor-of-evils kludge until that is complete. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- target/arm/cpu-param.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h index 2d5f3aa312c..fa6cae0e3aa 100644 --- a/target/arm/cpu-param.h +++ b/target/arm/cpu-param.h @@ -21,9 +21,13 @@ #ifdef CONFIG_USER_ONLY # ifdef TARGET_AARCH64 # define TARGET_TAGGED_ADDRESSES +# ifdef __FreeBSD__ +# define TARGET_PAGE_BITS 12 +# else /* Allow user-only to vary page size from 4k */ # define TARGET_PAGE_BITS_VARY # define TARGET_PAGE_BITS_MIN 12 +# endif # else # define TARGET_PAGE_BITS 12 # endif From patchwork Mon Jul 22 21:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9CCD8C3DA5D for ; Mon, 22 Jul 2024 21:47:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qY-0007FQ-7A; Mon, 22 Jul 2024 17:45:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q3-00059p-1W for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:59 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0q0-0004M8-GA for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:44:58 -0400 Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7f70a708f8aso195020139f.2 for ; Mon, 22 Jul 2024 14:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684695; x=1722289495; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aHdwiFgOy2Fjg9UYOTxrcvwQ73WzjeLsq+08Td07FKw=; b=KPevLR8Kw4G164GOnNtCGX1RWEy1dsq8PUT327Xyx6s4tFHQlpVPFH4XIIPX/heX24 WXLvuyk3IeLSPwcedL/yUWVZIoH8daWF48nGYuisqLpxZbaIrzcvUIOs29ZYSafonNmy TttxDCChL0dOgwzoLi1Gkyggtnus+6nZmOaeqX8UK24Ar/K0MCylm+YfOqGkcA7omcP9 0c1cSK/3zhDhVYXivvajBb+4mlsS+SEcfE0DThdsHk9jd043ulIljrVZzr0gBh/T2Cb0 PhD36ghsItzQazl22gT3/GJHKQsjqd5wZ8C3Mj+9l4J9TOxWVyD515wvo677PnOJ7+I5 8LeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684695; x=1722289495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aHdwiFgOy2Fjg9UYOTxrcvwQ73WzjeLsq+08Td07FKw=; b=RMvteNeTexC5AVfUKzoU5I6GQFSmBOFr8nV/CLYthh85XD07wyM3m/aZpS3Q3BYW4q aUOTlBFTVrXi7+X8Tz7g0eg3kOL8OqCae7UGWRlxhQqILiJDG7QvPdnEnxqtF5cqLKR+ rEfDkuim8B+wHW3kPMY7vczYLBCkBySo5nNWi6Y0vf654172W6C6sxdmlFeDHcTWtxrB OvkvYHRcE6uMpRFDZcUghSnHYn1QO6YkYiLSBBMesbbpnWSOU3xNALwxT2UI214L++9g T5a7lh5PLMPp28r0QeqmmoVD+cwwprOetd9wxH/RFHsvtgGeEvik6Zujy0TxGDf0rjWV 03xA== X-Gm-Message-State: AOJu0YzoQsb19yEw8ym0RI4B1myJEeTZYajvyMdLAKLX+7qmNRmYW9GI Pww9UbjoaeEli7TrqTauflZEJzXUv2NKv+w5u1i+dRuih9zyZaJaLCzt3myeVBMosXqhrKuSUD8 WCgE= X-Google-Smtp-Source: AGHT+IGfir1cHY9fvKV4XCC+2AhM8lT91fFGpISvwjfXREMglYLs1mFfcWdBGNGURyVi7f6aITVrGQ== X-Received: by 2002:a05:6602:3fc1:b0:807:82c2:5247 with SMTP id ca18e2360f4ac-81ea3573c05mr132581439f.6.1721684694897; Mon, 22 Jul 2024 14:44:54 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:54 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell , Jessica Clarke Subject: [PATCH 11/14] bsd-user: Sync fork_start/fork_end with linux-user Date: Mon, 22 Jul 2024 15:43:10 -0600 Message-ID: <20240722214313.89503-12-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Jessica Clarke This reorders some of the calls, deduplicates code between branches and, most importantly, fixes a double end_exclusive call in the parent that will cause exclusive_context_count to go negative. Signed-off-by: Jessica Clarke Pull-Request: https://github.com/qemu-bsd-user/qemu-bsd-user/pull/52 Reviewed-by: Warner Losh Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/main.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 82e94a03160..6d81452e51a 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -35,6 +35,7 @@ #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h" +#include "qemu/plugin.h" #include "exec/exec-all.h" #include "user/guest-base.h" #include "tcg/startup.h" @@ -103,8 +104,9 @@ unsigned long target_sgrowsiz = TARGET_SGROWSIZ; /* amount to grow stack */ void fork_start(void) { start_exclusive(); - cpu_list_lock(); mmap_fork_start(); + cpu_list_lock(); + qemu_plugin_user_prefork_lock(); gdbserver_fork_start(); } @@ -112,31 +114,29 @@ void fork_end(pid_t pid) { bool child = pid == 0; + qemu_plugin_user_postfork(child); + mmap_fork_end(child); if (child) { CPUState *cpu, *next_cpu; - /* - * Child processes created by fork() only have a single thread. Discard - * information about the parent threads. - */ + /* Child processes created by fork() only have a single thread. + Discard information about the parent threads. */ CPU_FOREACH_SAFE(cpu, next_cpu) { if (cpu != thread_cpu) { QTAILQ_REMOVE_RCU(&cpus_queue, cpu, node); } } - mmap_fork_end(child); - /* - * qemu_init_cpu_list() takes care of reinitializing the exclusive - * state, so we don't need to end_exclusive() here. - */ qemu_init_cpu_list(); get_task_state(thread_cpu)->ts_tid = qemu_get_thread_id(); - gdbserver_fork_end(thread_cpu, pid); } else { - mmap_fork_end(child); cpu_list_unlock(); - gdbserver_fork_end(thread_cpu, pid); - end_exclusive(); } + gdbserver_fork_end(thread_cpu, pid); + /* + * qemu_init_cpu_list() reinitialized the child exclusive state, but we + * also need to keep current_cpu consistent, so call end_exclusive() for + * both child and parent. + */ + end_exclusive(); } void cpu_loop(CPUArchState *env) From patchwork Mon Jul 22 21:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97212C3DA5D for ; Mon, 22 Jul 2024 21:46:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qY-0007GY-Ry; Mon, 22 Jul 2024 17:45:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q4-0005H6-NU for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:00 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0q2-0004Mh-OL for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:00 -0400 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-8036ce66164so177241339f.3 for ; Mon, 22 Jul 2024 14:44:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684697; x=1722289497; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hCvhmJN00xwcYiXq7RTqO6TEMMCZZhNjKEbh12HQDEc=; b=VyhdupqQ+cX4VSbfik4e9CVQFKVpteszoRJsDLtLNWdE/Qq/0s6NAkBuC8ccnItcWU beFhKn7kPDyedFkafzklwjDY3YWfCtB1ElTVQdsVRCjog5EprzsMQWApPqHzLCNHq/5f Ouoc8f7b3c4cQUUZt9m0YNDlqNyc6VKbfuwbCr6Wwl6r7jDsCGZlSNCtneIcPH4+L5aW hoHjmVHIYjELWN6rFc3NuHXudIkcDh4c9YIW9OMWcJ+Y2o0ls4uokAn5DeYnYvT3aho8 kEe7auZhbfSXXY1HrRXZwSLdIhXITAYuoktirxQRxA13ZBHR3d8QvA/qO8knAjCj2vfZ FAiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684697; x=1722289497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hCvhmJN00xwcYiXq7RTqO6TEMMCZZhNjKEbh12HQDEc=; b=AOFgDodNGWnwB0w6bhCcv4YX3s+InCtLgMrfcQ3qYRaVKNPrMHkmBsO2OWc8AVH+dQ rEfRkv4qsfhNdoKZSzZgU6HqwR9Ol2THZJ154Ka60H87lhjak2PUXUfgnL1khjB2211E X9/frVW26dsv7lNVMT32pp8ilY/lzUueFUlGp/jLAr6P/BtU4jyRmIrMcyuSV2++aUDq XiWSL+lnp0KE9K36wPCuvK3uYW7q/eKO5RWZqWkidYBivT+aD43Qzzta3R63W1SqtGHU +o0K9mUgFQ/a9WaV1zNuIY6GU8JX9GjuoMi9CESWT1tkXF1MQmvMSswU3P44us7ly3JL cTjQ== X-Gm-Message-State: AOJu0Ywv26f/MIzSrf588BDqALIvl1ktflFOQ1vcltvMW3urNME6tuB9 kr7AfUjTe5KiuDhDvTvuN59sEIRyoE1fvrWrowm+nIKdFRCro42eG4lZBoKsiRdVPHLNs0kyXm7 1eN4= X-Google-Smtp-Source: AGHT+IGpEuG4vRJSOCX1daB2CYFJ3JOfGGyPjkmnyZCnupN+q+vnODLcM9N0VLZhvatfvWXw/ghR4w== X-Received: by 2002:a05:6602:2cd5:b0:804:8a79:2c77 with SMTP id ca18e2360f4ac-81b3372d7bemr1015322739f.8.1721684696087; Mon, 22 Jul 2024 14:44:56 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:55 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell Subject: [PATCH 12/14] bsd-user: Define TARGET_SIGSTACK_ALIGN and use it to round stack Date: Mon, 22 Jul 2024 15:43:11 -0600 Message-ID: <20240722214313.89503-13-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Most (all?) targets require stacks to be properly aligned. Rather than a series of ifdefs in bsd-user/signal.h, instead use a manditory #define for all architectures. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/aarch64/target_arch_signal.h | 2 ++ bsd-user/arm/target_arch_signal.h | 2 ++ bsd-user/i386/target_arch_signal.h | 2 ++ bsd-user/signal.c | 9 +-------- bsd-user/x86_64/target_arch_signal.h | 2 ++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bsd-user/aarch64/target_arch_signal.h b/bsd-user/aarch64/target_arch_signal.h index bff752a67ab..b72ba7aa504 100644 --- a/bsd-user/aarch64/target_arch_signal.h +++ b/bsd-user/aarch64/target_arch_signal.h @@ -77,4 +77,6 @@ struct target_sigframe { target_ucontext_t sf_uc; /* saved ucontext */ }; +#define TARGET_SIGSTACK_ALIGN 16 + #endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/arm/target_arch_signal.h b/bsd-user/arm/target_arch_signal.h index 02b2b33e07a..10f96b8bfc9 100644 --- a/bsd-user/arm/target_arch_signal.h +++ b/bsd-user/arm/target_arch_signal.h @@ -86,4 +86,6 @@ struct target_sigframe { target_mcontext_vfp_t sf_vfp; /* actual saved VFP context */ }; +#define TARGET_SIGSTACK_ALIGN 8 + #endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/i386/target_arch_signal.h b/bsd-user/i386/target_arch_signal.h index 279dadc22c7..2c14153ab6b 100644 --- a/bsd-user/i386/target_arch_signal.h +++ b/bsd-user/i386/target_arch_signal.h @@ -88,4 +88,6 @@ struct target_sigframe { uint32_t __spare__[2]; }; +#define TARGET_SIGSTACK_ALIGN 8 + #endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/signal.c b/bsd-user/signal.c index 8b6654b91da..da49b9bffc1 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -728,14 +728,7 @@ static inline abi_ulong get_sigframe(struct target_sigaction *ka, sp = ts->sigaltstack_used.ss_sp + ts->sigaltstack_used.ss_size; } -/* TODO: make this a target_arch function / define */ -#if defined(TARGET_ARM) - return (sp - frame_size) & ~7; -#elif defined(TARGET_AARCH64) - return (sp - frame_size) & ~15; -#else - return sp - frame_size; -#endif + return ROUND_DOWN(sp - frame_size, TARGET_SIGSTACK_ALIGN); } /* compare to $M/$M/exec_machdep.c sendsig and sys/kern/kern_sig.c sigexit */ diff --git a/bsd-user/x86_64/target_arch_signal.h b/bsd-user/x86_64/target_arch_signal.h index ca24bf1e7f7..f833ee66cef 100644 --- a/bsd-user/x86_64/target_arch_signal.h +++ b/bsd-user/x86_64/target_arch_signal.h @@ -97,4 +97,6 @@ struct target_sigframe { uint32_t __spare__[2]; }; +#define TARGET_SIGSTACK_ALIGN 16 + #endif /* TARGET_ARCH_SIGNAL_H */ From patchwork Mon Jul 22 21:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E13F1C3DA5D for ; Mon, 22 Jul 2024 21:46:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qT-0006cx-G6; Mon, 22 Jul 2024 17:45:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q5-0005Lx-Vf for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:02 -0400 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0q3-0004Mr-TR for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:01 -0400 Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-397580fa3bcso10961375ab.1 for ; Mon, 22 Jul 2024 14:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684698; x=1722289498; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t9VX1qTliZmCA4rGJoDFFHTihIbFxaJR/Jp9RTUGPRo=; b=cB9WxR23KMftJMKH8norVcvqRLOZjji8duMPUZ6WZGrVYA9/7UN70qs9h9W84V1pTD wAy3UbdzaSgwyX/vq3XPIN85yXB4lMMBFdS/0tlwhBOcmj6PAhEBAamCiLNuPeBmfxEd /7luOY7cLFpLAuEXHYSd5PuMP8w2AVc7PTKdGZiBpLdM1nDg80qzDIfnES9bclRmH1X8 baPnPZR6s9DhZLeVPMG4T5IyGib5Rk9t92Yrug2XN5sJEjRTQpoesCJFskwiDs5dpwzp z/w2Yhftt5UWG5iOQTdDvXgQiepuVjY4aB1QJLhSuvoCaccaF9pOPeqYjeIzQGl1SJGa 9zFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684698; x=1722289498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t9VX1qTliZmCA4rGJoDFFHTihIbFxaJR/Jp9RTUGPRo=; b=tjWUZr6IIukagucFme1dnD1gdWosFNz7bMxOfAJihmK49Eali78NTQT4RjNkO8QrEl xZ1ikvFh18ECQiuK9R9zhSnJrGG4uYfR1ir3FSxIt+lS68NopwAHgaMFBr6NKyy/3jY7 6CyM9AnjVZNZvk+OET5nnCSd0l1t4ycV0QJntGtBhdJbHW49QIwNlr21Z27AI1KIye4y biNXdqIW+v3TfKGY64O8dAeOjSwtR7tokJKhYqIJl/lCIZsxb/T3PKewHjOSDlVqvLTH Q7YavwPKdWSShBhg505zJya7pO5IUdYrKjyOS7ii8XTaSqf3rSBev8mG/UUf5ODMSNJO oMKg== X-Gm-Message-State: AOJu0YwydiRfulYdDumQt4WiheC4IiB9FPPGesh8rH2V3a2ohPBSuqV0 9ACgloJ4y/wl+EAJw78HfT+i0auZ0YYGNf4GIoyLAHDyZn5eAn+j1MZwvEZNk6p/VtVloMz44tR /Bv4= X-Google-Smtp-Source: AGHT+IF+cSzMZVgs3oOl9JYy6lFyV7l46bbgP9Ut4Pb6hKdSMG8AqtiBBNDWjQFJxPZXLXxk+hjChw== X-Received: by 2002:a05:6e02:1a43:b0:375:a37c:14b6 with SMTP id e9e14a558f8ab-3993ffd5902mr114438415ab.23.1721684698096; Mon, 22 Jul 2024 14:44:58 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:57 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell Subject: [PATCH 13/14] bsd-user: Make compile for non-linux user-mode stuff Date: Mon, 22 Jul 2024 15:43:12 -0600 Message-ID: <20240722214313.89503-14-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::132; envelope-from=imp@bsdimp.com; helo=mail-il1-x132.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We include the files that define PR_MTE_TCF_SHIFT only on Linux, but use them unconditionally. Restrict its use to Linux-only. Signed-off-by: Warner Losh Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/arm/gdbstub64.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index 2e2bc2700b8..6dc81aecb2a 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -404,6 +404,7 @@ int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg) int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) { +#if defined(CONFIG_LINUX) ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; @@ -425,6 +426,9 @@ int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) arm_set_mte_tcf0(env, tcf); return 1; +#else + return 0; +#endif } static void handle_q_memtag(GArray *params, void *user_ctx) From patchwork Mon Jul 22 21:43:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 13739132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10576C3DA5D for ; Mon, 22 Jul 2024 21:47:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW0qU-0006yU-9A; Mon, 22 Jul 2024 17:45:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW0q6-0005QD-Uk for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:03 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW0q4-0004Na-I9 for qemu-devel@nongnu.org; Mon, 22 Jul 2024 17:45:02 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-81a90913cc3so123678839f.3 for ; Mon, 22 Jul 2024 14:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1721684699; x=1722289499; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x//+WoaO7Dn+k8eyr+KqgxuGF53Mml0Sq9XIPzmFBuA=; b=1hRQ6M5FtQxdbEfOnQ4HYyEAwt/YZDR4d5xUArTWqT5pP6kBh3yDidcED/d9zsVnh0 wH8bBZH9zoI7EoDclIJ43/5yBdHN1UmIqJy6kA3e3E/1BrO/ZHcHJrkQw5bXDlLrxMXp 6UWxZwmmj3FwkMCoJCTmLztvdA/mlMtxx7MBFsQVl/QtnHVt4yVEdD76JCMeqYEDXOfE w2Hk9sRnKwevAGMZehQ2RZ6AS1OneZ13r0kz+lnVCehzj6Mpa9KmOX1Oi3r+x932XGYv iw7ba+fEdTptdWpTV9wJZQu6o/alyTZt1V6kVhMkqD1XQIfn79WWQqm3B59nHBXC1KUw K5Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721684699; x=1722289499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x//+WoaO7Dn+k8eyr+KqgxuGF53Mml0Sq9XIPzmFBuA=; b=bN2lo0OBGFAABNqqSMqxrTDBicknMA9bLRi7NXNbC320U6mSDI9mfaLfqpUCspJxxU 1xC0xbm7csz/BAWdftNtyV3MHKenzAWhdldH2+65JYqiye4ZManCHB6lmaRgcH3S2Psj AvpXy6UhLfHUQyUUqEdfIxeHFwjHeKWUDF74vVq/ty4/xBa28OVkXJlQxdzt+krki57A sfZFsWgs2n9WTpdW3bimDmxZpVKPbUQHMoI61UXciE7EvH6ChnJ1T6wYoAvWXIqHZLwd 0jcOfwM82NY/JK/WonHljwyyyu5P5An2cDn3LlSMJ3DY/jSzzq/mjtC5nw7dZ2eumF53 FsrA== X-Gm-Message-State: AOJu0Ywru6Ea4l4I20totOR0pJ1UIRF7wmF9UQa1l+I5S12U0PSXu0rW n0sz0I0/Q50OrRGo6+iHKaD7Qti4byzNU+X3aVq7uwTDBBwPfRqWu2pOJA7rhIxlekArIBBfLcP FGuE= X-Google-Smtp-Source: AGHT+IFaAOo6Sk/ZctkoR1YnXWNYBYCD6WfGAXV7paBpQmTybnbVUergi31F4i9WnVNYRWvFG9EouA== X-Received: by 2002:a05:6602:482:b0:7f6:1cd3:9659 with SMTP id ca18e2360f4ac-81b33edfba6mr1400411139f.6.1721684699006; Mon, 22 Jul 2024 14:44:59 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c2343d2ff3sm1816830173.128.2024.07.22.14.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 14:44:58 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , qemu-arm@nongnu.org, Warner Losh , Peter Maydell Subject: [PATCH 14/14] bsd-user: Add aarch64 build to tree Date: Mon, 22 Jul 2024 15:43:13 -0600 Message-ID: <20240722214313.89503-15-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240722214313.89503-1-imp@bsdimp.com> References: <20240722214313.89503-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=unavailable 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add the aarch64 bsd-user fragments needed to build the new aarch64 code. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- configs/targets/aarch64-bsd-user.mak | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 configs/targets/aarch64-bsd-user.mak diff --git a/configs/targets/aarch64-bsd-user.mak b/configs/targets/aarch64-bsd-user.mak new file mode 100644 index 00000000000..8aaa5d8c802 --- /dev/null +++ b/configs/targets/aarch64-bsd-user.mak @@ -0,0 +1,3 @@ +TARGET_ARCH=aarch64 +TARGET_BASE_ARCH=arm +TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-xml/aarch64-pauth.xml