From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841144; cv=none; d=zohomail.com; s=zohoarc; b=lmRBVxqXKZl/0+UJkldjRqW8EjX1doNu0Ugqq8hUIpnwDyyNXz/9owwAgH++JBjnHe4fWEXC0GlhLt+XismM+hMG4gWiev2bCWYj56+BvXMa9NEycSJ/QpQS3GWx0pJVLsp8k0i4ny/7cWWIOY77yULdg8/JvAALo18DmEKXbfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841144; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SZokrjayKiS1ulA/9qnPoBKc5DedE8QybE5mhesGm2A=; b=E23RlDrtzTp2AWCIljliAg80PBHyGnZmVmPImzknAsY9fu75kdojA+a5U4YEkOZ/4vzecq7Uzr2cgAprULlyuuBq/oSEFFcbckHiSzIZteRrAxuDafeAXZ/m42PbDZ8HjR2CuMuEUE+PNxTt6IkhR90m8Z3Zkt8xhCLO4a9S/u0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841144131584.753851557765; Sun, 7 Jun 2026 07:05:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6h-0004Ip-6Z; Sun, 07 Jun 2026 10:04:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6f-0004IK-9t for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:05 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6d-0007zE-KD for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:05 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8DD5443857; Sun, 7 Jun 2026 14:04:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0843C1F00893; Sun, 7 Jun 2026 14:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841042; bh=SZokrjayKiS1ulA/9qnPoBKc5DedE8QybE5mhesGm2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eidsL1rgl/IuYZGGGN30ksXyTH8LS5jBlAvKZF7Z5CZ8JF+0g14REminHI0TOEB/U ZNa2J8T2G+IIQJu1ZuO5FnLd00h2EE2tr+qenMGU3NLXfpk+YwKGI6SfJ6kWWOTgye yqT2o26l3Ppja9rjP7CdPkbr1BOzvO/w0ybPpggokEGloXBJ83ZsUog5rS7l8bHA9V fs/IfK/2LNIWaEHIj8y65bKJRyik43oEc4bVswKeG2pTXcpKrVZrFiPeoMlIMOtvTZ xCqTR+b5FKgUvHXJ1wf6/dtGYbddi/bwE0SB3V4lFh8I6DMNJulwO8NFA7KF/vRZMw pX+XQkpbJ+Xow== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Xinhui Yang Subject: [PATCH 01/10] linux-user: implement fsmount(2) series of syscalls Date: Sun, 7 Jun 2026 16:03:47 +0200 Message-ID: <20260607140356.10702-2-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841144816158500 Content-Type: text/plain; charset="utf-8" From: Xinhui Yang This series of syscalls replaces the old mount(2) syscall with a series of syscalls that operates around a filesystem context. This series of syscalls is available since Linux 5.2 and glibc 2.36+. Their users include systemd since v259 and libmount from util-linux, and possibly other widely used projects. Preliminary checks are implemented to ensure the validity of the interface. Signed-off-by: Xinhui Yang Reviewed-by: Pierrick Bouvier Signed-off-by: Helge Deller --- linux-user/syscall.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7d7a7b489c..c5c2aa80ec 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -14412,6 +14412,97 @@ static abi_long do_syscall1(CPUArchState *cpu_env,= int num, abi_long arg1, return do_map_shadow_stack(cpu_env, arg1, arg2, arg3); #endif =20 +#if defined(TARGET_NR_fsopen) + case TARGET_NR_fsopen: + { + p =3D lock_user_string(arg1); + if (!p) { + return -TARGET_EFAULT; + } + ret =3D get_errno(fsopen(p, arg2)); + unlock_user(p, arg1, 0); + } + return ret; + case TARGET_NR_fsconfig: + { + /* + * fsconfig(int, int, char *, void *, int) + * NOTE: p4 is nullable and its type might not be a string. + */ + void *p3, *p4; + int cmd =3D (int) arg2; + switch (cmd) { + case FSCONFIG_SET_BINARY: + case FSCONFIG_SET_STRING: + case FSCONFIG_SET_PATH: + case FSCONFIG_SET_PATH_EMPTY: + p3 =3D lock_user_string(arg3); + if (!p3) { + return -TARGET_EFAULT; + } + if (cmd !=3D FSCONFIG_SET_BINARY) { + /* key and value must be strings. */ + p4 =3D lock_user_string(arg4); + } else { + /* + * Otherwise the value must be a raw buffer with its + * length specified in arg5 (aux). + */ + p4 =3D lock_user(VERIFY_READ, arg4, arg5, 1); + } + if (!p4) { + unlock_user(p3, arg3, 0); + return -TARGET_EFAULT; + } + ret =3D get_errno(fsconfig(arg1, arg2, p3, p4, arg5)); + unlock_user(p3, arg3, 0); + unlock_user(p4, arg4, 0); + break; + + case FSCONFIG_SET_FLAG: + case FSCONFIG_SET_FD: + /* arg4 (value) must be NULL. */ + if (arg4) { + return -TARGET_EFAULT; + } + p3 =3D lock_user_string(arg3); + if (!p3) { + return -TARGET_EFAULT; + } + ret =3D get_errno(fsconfig(arg1, arg2, p3, NULL, arg5)); + unlock_user(p3, arg3, 0); + break; + case FSCONFIG_CMD_CREATE: + case FSCONFIG_CMD_RECONFIGURE: +#ifdef FSCONFIG_CMD_CREATE_EXCL + /* + * FSCONFIG_CMD_CREATE_EXCL is only available since Linux + * 6.6. Guarding it to allow building with pre-6.6 headers. + */ + case FSCONFIG_CMD_CREATE_EXCL: +#endif + /* key and value must be NULL, aux must be 0. */ + if (arg3 || arg4 || arg5) { + return -TARGET_EFAULT; + } + ret =3D get_errno(fsconfig(arg1, arg2, NULL, NULL, 0)); + break; + default: + return -TARGET_EFAULT; + } + } + return ret; + case TARGET_NR_fsmount: + ret =3D get_errno(fsmount(arg1, arg2, arg3)); + return ret; + case TARGET_NR_fspick: + { + p =3D lock_user_string(arg2); + ret =3D get_errno(fspick(arg1, p, arg3)); + unlock_user(p, arg2, 0); + } + return ret; +#endif default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); return -TARGET_ENOSYS; --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841091; cv=none; d=zohomail.com; s=zohoarc; b=NhEvU8fOn+bIagSIMWy065WKfHrlFWiu2N3MZQoE1lEzo9FOmBfVUuGK6yvRWUZKE0ApyQweTf6vDKNbA4iRxj3JBzTY44sxO6Xt4DjzHyfReLtxf7Ur/5Key6KZuXQL8y5shbcVkaPZnbL6rlr3TtEgdcoOwLpVHNyHC2f2XJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841091; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MqB7UL4fPRYcru3EnbnH7S5G3PK67/sx3b0o2FxbdEo=; b=OJcdJdV7IBzTjPv2k6a9yQwhsKeSFAnvHMHcdv+HQOGK1kgK0Gri95a7odr8s59fW4iMEFtqrV8RFsOafq1SgE1MGHBk86vuobBZlKOVoy+jd0m0SVI6RGAnfRjR8jzwsOLxLSoHGTkr6cyLcW/KBcO478CPetH+OIpdPQb+wm0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841091556170.2599394738878; Sun, 7 Jun 2026 07:04:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6i-0004JC-L1; Sun, 07 Jun 2026 10:04:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6h-0004J4-NA for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:07 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6f-00082e-Q9 for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:07 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 9DA2E41524; Sun, 7 Jun 2026 14:04:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2A861F00893; Sun, 7 Jun 2026 14:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841044; bh=MqB7UL4fPRYcru3EnbnH7S5G3PK67/sx3b0o2FxbdEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U4jUhRS73PFNo+za7JCnvkmtbzOeigDze0yAvX/3DLjjOFT5E2vq/sJZjXdJcTWRd epJ6xUO+nhLcLeMdqqtKotv/F2Grs4fqosYjb/I/ky3rvRBqt2beaT4L/DysYgA4Qh USVFaNpXjWzTUmvi+nPCRNOSVj59Itfw6drbwQ06bT/mq19BMd0qSf+o3m43+tbhfm S99kKQ2GjSuBZXIe/fW2IK3B2nY5bfe1yv2rwFJO4VoSW4hU7G5m8q2m/3vn4oPkSd lzdmODizncoF6zTYm24/PIqspEwjbXmLDpuc6XTGJ4oESjUC29loxRXze49TCKZzgG rDH/6+aVzFqjw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Xinhui Yang Subject: [PATCH 02/10] linux-user/strace: add fsmount series of syscalls Date: Sun, 7 Jun 2026 16:03:48 +0200 Message-ID: <20260607140356.10702-3-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841094547154100 Content-Type: text/plain; charset="utf-8" From: Xinhui Yang Following the addition of fsmount(2) series of syscalls in the syscall handler, strace support is added, with a dedicated function to print the parameters of fsconfig(2), which contains parameters that can be interpreted as multiple types. Snippet of the strace dump when running `mount -t tmpfs tmpfs /media`: 18 fsopen(tmpfs,1) =3D 3 18 read(3,0x407fcf1c,8191) =3D -1 errno=3D61 (No data available) 18 fsconfig(3,FSCONFIG_SET_STRING,"source","tmpfs",0) =3D 0 18 read(3,0x407fce3c,8191) =3D -1 errno=3D61 (No data available) 18 fsconfig(3,FSCONFIG_CMD_CREATE,NULL,NULL,0) =3D 0 18 read(3,0x407fce3c,8191) =3D -1 errno=3D61 (No data available) 18 fsmount(3,1,0) =3D 4 18 read(3,0x407fce3c,8191) =3D -1 errno=3D61 (No data available) 18 statx(4,"",AT_EMPTY_PATH|AT_STATX_SYNC_AS_STAT,0x1000,0x407fee98) =3D 0 18 move_mount(4,,-100,/media,4) =3D 0 18 read(3,0x407fcfcc,8191) =3D -1 errno=3D61 (No data available) 18 close(3) =3D 0 18 close(4) =3D 0 Signed-off-by: Xinhui Yang Reviewed-by: Pierrick Bouvier Signed-off-by: Helge Deller --- linux-user/strace.c | 105 +++++++++++++++++++++++++++++++++++++++++ linux-user/strace.list | 15 ++++++ 2 files changed, 120 insertions(+) diff --git a/linux-user/strace.c b/linux-user/strace.c index 2cbaf94c89..d861f311f6 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -4344,6 +4344,111 @@ print_statx(CPUArchState *cpu_env, const struct sys= callname *name, } #endif =20 +#ifdef TARGET_NR_fsconfig +static void +print_fsconfig_cmd_name(int cmd) +{ + switch (cmd) { + case FSCONFIG_SET_FLAG: + qemu_log("%s%s", "FSCONFIG_SET_FLAG", get_comma(0)); + break; + case FSCONFIG_SET_STRING: + qemu_log("%s%s", "FSCONFIG_SET_STRING", get_comma(0)); + break; + case FSCONFIG_SET_BINARY: + qemu_log("%s%s", "FSCONFIG_SET_BINARY", get_comma(0)); + break; + case FSCONFIG_SET_PATH: + qemu_log("%s%s", "FSCONFIG_SET_PATH", get_comma(0)); + break; + case FSCONFIG_SET_PATH_EMPTY: + qemu_log("%s%s", "FSCONFIG_SET_PATH_EMPTY", get_comma(0)); + break; + case FSCONFIG_SET_FD: + qemu_log("%s%s", "FSCONFIG_SET_FD", get_comma(0)); + break; + case FSCONFIG_CMD_CREATE: + qemu_log("%s%s", "FSCONFIG_CMD_CREATE", get_comma(0)); + break; + case FSCONFIG_CMD_RECONFIGURE: + qemu_log("%s%s", "FSCONFIG_CMD_RECONFIGURE", get_comma(0)); + break; +#ifdef FSCONFIG_CMD_CREATE_EXCL + case FSCONFIG_CMD_CREATE_EXCL: + /* Only available since Linux 6.6. */ + qemu_log("%s%s", "FSCONFIG_CMD_CREATE_EXCL", get_comma(0)); + break; +#endif + default: + qemu_log("%s (%d)%s", "UNKNOWN_CMD", cmd, get_comma(0)); + break; + } +} + +static void +print_fsconfig(CPUArchState *cpu_env, const struct syscallname *name, + abi_long arg0, abi_long arg1, abi_long arg2, + abi_long arg3, abi_long arg4, abi_long arg5) +{ + /* + * fsconfig(int fd, int cmd, char* key, void* value, int aux) + * Where: + * fd: file descriptor returned by fsopen(). + * cmd: integer constant specifying a command. + * key: a string, can be NULL on certain commands. + * value: any data in a buffer, can be NULL, raw buffer or a string. + * aux: axillary values such as flags for FSCONFIG_SET_PATH. + */ + int cmd =3D (int) arg1; + print_syscall_prologue(name); + print_raw_param("%d", arg0, 0); + print_fsconfig_cmd_name(cmd); + /* Process arg2 (key). */ + switch (cmd) { + case FSCONFIG_SET_FLAG: + case FSCONFIG_SET_STRING: + case FSCONFIG_SET_BINARY: + case FSCONFIG_SET_PATH: + case FSCONFIG_SET_PATH_EMPTY: + case FSCONFIG_SET_FD: + print_string(arg2, 0); + break; + default: + print_pointer(arg2, 0); + break; + } + /* Process arg3 (value). */ + switch (cmd) { + case FSCONFIG_SET_STRING: + case FSCONFIG_SET_PATH: + case FSCONFIG_SET_PATH_EMPTY: + print_string(arg3, 0); + break; + default: + print_pointer(arg3, 0); + break; + } + /* + * Process arg4 (aux). + * On FSCONFIG_SET_PATH and FSCONFIG_SET_PATH_EMPTY, aux can + * be either 0 or AT_FDCWD. + * On FSCONFIG_SET_BINARY, aux is an integer to state the length + * of the buffer pointed by arg3. + * Otherwise, it must be 0. + */ + switch (cmd) { + case FSCONFIG_SET_PATH: + case FSCONFIG_SET_PATH_EMPTY: + print_at_dirfd(arg4, 1); + break; + default: + print_raw_param("%d", arg4, 1); + break; + } + print_syscall_epilogue(name); +} +#endif + #ifdef TARGET_NR_ioctl static void print_ioctl(CPUArchState *cpu_env, const struct syscallname *name, diff --git a/linux-user/strace.list b/linux-user/strace.list index 6162a407f9..3a366b8cac 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1722,3 +1722,18 @@ #ifdef TARGET_NR_rseq { TARGET_NR_rseq, "rseq" , "%s(%p,%u,%d,%#x)", NULL, NULL }, #endif +#ifdef TARGET_NR_fsopen +{ TARGET_NR_fsopen, "fsopen", "%s(%s,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_fsconfig +{ TARGET_NR_fsconfig, "fsconfig", NULL, print_fsconfig, NULL }, +#endif +#ifdef TARGET_NR_fsmount +{ TARGET_NR_fsmount, "fsmount", "%s(%d,%d,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_move_mount +{ TARGET_NR_move_mount, "move_mount", "%s(%d,%s,%d,%s,%d)", NULL, NULL }, +#endif +#ifdef TARGET_NR_fspick +{ TARGET_NR_fspick, "fspick", "%s(%d,%s,%d)", NULL, NULL }, +#endif --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841112; cv=none; d=zohomail.com; s=zohoarc; b=MkSPTug0bmfxWM7OgC6mgz2wB6a0dE607wZFSo0/324MRBjr+5xiOPxv/DSYv8WAThRcRxlD5/pIVqPFVQ76NE01qiWQLfZGE4lWjfMl/kwMTJsi91otOo8Eb+ICKisa62N6XeMWeAp3CnaUJNoO1iy3mrM9NlYPDBSz42dKDyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=et5eLMegT6ampsfftjXOFLTcAsoi2sO/Rg/7dQphinA=; b=UwUh6rEFmezPHF2S9WQXT5X7Z0VBE70hbMhY2mYJ3wby4N4KPyIj4QW1O+YaFdj1rDsMD7viKu4TLwhjRBCjE2rzxjJL/SBVPpG/b+FOs0Sngf8Emk2nTnz9GtPQ7+UKU07MyVLneL9QskdbmezsU4ZFJq8BpFehNv+k2XguquA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841112488812.6499128250503; Sun, 7 Jun 2026 07:05:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6l-0004Jj-Lm; Sun, 07 Jun 2026 10:04:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6j-0004JS-Ks for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:09 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6i-00084f-5O for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:09 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id DBAE160018; Sun, 7 Jun 2026 14:04:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22D41F00893; Sun, 7 Jun 2026 14:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841046; bh=et5eLMegT6ampsfftjXOFLTcAsoi2sO/Rg/7dQphinA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KPFXJUCAG2rQ2GNEwIT2U/vFxY8VU0WzMXxWhqYlLkStLrj3VlGgHZ3fQL7sMT8J7 TpXRwBuhTGr4FVM0fJQfHyVXTO9yFnJ+o5TQzmKJryumQRkJy9Ixwwz8AIO3NGZLCc zJSagyRh6fhO7qaQlMyPBjvdu8h9mutkVg5slGMytwxXXivaHZEe/aOXGSvGeo/+ij T5zCyBYLzjFzqLWtDeYSf1lgotUE2UtdXYCo8RJoG4uXAR5x4Vo+kPPE5tCDWuo2FV BbIhzAZs0dDE8JxX6usf6xLYanbDb4qzdc2j2nzQmQ3UEATT9u1Ul9D1ruPfBHhUXg Jpup91KTrffuQ== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner Subject: [PATCH 03/10] linux-user/alpha: add coredump support Date: Sun, 7 Jun 2026 16:03:49 +0200 Message-ID: <20260607140356.10702-4-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841114782158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h, mirroring the kernel's elf_gregset_t (ELF_NGREG =3D 66): r0-r31 [0..31], f0-f31 [32..63], pc [64], unique [65]. Implement elf_core_copy_regs() in elfload.c to populate the gregset from CPUAlphaState. Without this, bprm->core_dump is NULL for Alpha targets. When a guest signal goes unhandled, dump_core_and_abort() skips the core write and falls through to die_with_signal(), which re-raises the signal to the host. The host kernel then writes an x86-64 core file for the qemu-alpha process instead of an Alpha guest core. v2: Store thread unique field, same as in Linux kernel. Added by Helge & suggested by Richard. Signed-off-by: Matt Turner Signed-off-by: Helge Deller Reviewed-by: Richard Henderson --- linux-user/alpha/elfload.c | 12 ++++++++++++ linux-user/alpha/target_elf.h | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/linux-user/alpha/elfload.c b/linux-user/alpha/elfload.c index 1e44475c47..d2aed15ce5 100644 --- a/linux-user/alpha/elfload.c +++ b/linux-user/alpha/elfload.c @@ -3,8 +3,20 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "target_elf.h" =20 =20 +void elf_core_copy_regs(target_elf_gregset_t *r, const CPUAlphaState *env) +{ + int i; + + for (i =3D 0; i < 31; i++) { + r->regs[i] =3D tswap64(env->ir[i]); + } + r->pc =3D tswap64(env->pc); + r->unique =3D env->unique; +} + const char *get_elf_cpu_model(uint32_t eflags) { return "ev67"; diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h index 864dc6e2e6..4987ae3944 100644 --- a/linux-user/alpha/target_elf.h +++ b/linux-user/alpha/target_elf.h @@ -11,4 +11,17 @@ #define ELF_CLASS ELFCLASS64 #define ELF_MACHINE EM_ALPHA =20 +#define HAVE_ELF_CORE_DUMP 1 + +/* + * Matches the kernel's elf_gregset_t (ELF_NGREG =3D 33): + * r0-r30 at indices 0-30, pc at 31, ps at 32. + * r31 (hardwired zero) is not stored; pc occupies index 31. + */ +typedef struct target_elf_gregset_t { + abi_ulong regs[31]; /* integer registers r0-r30 [0..30] */ + abi_ulong pc; /* program counter [31] */ + abi_ulong unique; /* thread's UNIQUE field [32] */ +} target_elf_gregset_t; + #endif --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841133; cv=none; d=zohomail.com; s=zohoarc; b=bxUIMlVYXyzatNiByoeZiNiqTH8xd+Dm08Q1jgk10mhQg7R7YiNoWq2Ohhhpv4S8ZsbonRaI7+au9ceMr1oxVMxsljHZI3KBKADDnIFNFQYxov2aRqzRcXF5ySbxHK/jEzCWXiZDiua+Ccgsi5kVnstMk+JBOezo6Zrk++Cpulg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841133; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UPeXJIlKzbTxaer6fjTxCLj0ISR2mmzL0SNT7pcKTJM=; b=UpOvdxKviD7aNy3AX4QJloJtKVKfFa25LuoUSFQG1iOxKpP8nZvGFtaBLtxcSL7/Z3cRwAOi4LW6nLT6yGwB+rPlEmmzckyeDQrZj4mNHRxL3XaJlb0sdYhZld8q3zjkQwD4tgarB9UPLNLrbIWSfeH1quvUwYvnTwcmnr1iGJg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841133031228.43548218351464; Sun, 7 Jun 2026 07:05:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6n-0004K8-4n; Sun, 07 Jun 2026 10:04:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6m-0004Jv-0r for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:12 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6k-00085D-Ag for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:11 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 24A7C6001D; Sun, 7 Jun 2026 14:04:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EC211F00893; Sun, 7 Jun 2026 14:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841048; bh=UPeXJIlKzbTxaer6fjTxCLj0ISR2mmzL0SNT7pcKTJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d/zOE8eyOmGdEz0rOm0YRmFwuJb0ajzqJvnfcJjlo6eIVf3rRhUZFiqDpvWXMryQ4 /pDG49/mLb/aR8NiJmjWFc9uRhfwXlVFTxftpywsm/jP5MzJkyCaODJt89PmIhlK/5 xgqs1h6F96mkwMMbmy9ikEkg7RAJ9dWSpFrEAyo/VpaAgwPOouolwsAfO4ZoMlpSwj MWviV3E6YsbltLDpRfXnDHIpoGuBcApg2JOEF38YsLea9Am563YREWL04NV9E8UgOU ai3QgcD9M+0KWQ9pLVpGx4SMSvFs1UiskXPPye+fd13bJGel3Zym6+d9oy/Rtp5on5 G1I6qn77U/BNw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner , Mark Cave-Ayland Subject: [PATCH 04/10] linux-user/sparc: add coredump support Date: Sun, 7 Jun 2026 16:03:50 +0200 Message-ID: <20260607140356.10702-5-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c04:e001:324:0:1991:8:25; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841134846158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h sized to match the kernel's elf_gregset_t: sparc32/sparc32plus (ELF_NGREG =3D 38): [0] PSR [1] PC [2] NPC [3] Y [4..11] G0-G7 [12..19] O0-O7 [20..27] L0-L7 [28..35] I0-I7 [36..37] reserved (stack_check) sparc64 (ELF_NGREG =3D 36): [0..7] G0-G7 [8..15] O0-O7 [16..23] L0-L7 [24..31] I0-I7 [32] TSTATE [33] TPC [34] TNPC [35] Y Also define ELF_MACHINE as EM_SPARC32PLUS for TARGET_ABI32 builds, matching the kernel and ensuring the correct machine type appears in the core file. Implement elf_core_copy_regs() in elfload.c to populate the gregset from CPUSPARCState, including L0-L7 and I0-I7 from env->regwptr. A memset() at entry zeros the trailing reserved slots. Without this, bprm->core_dump is NULL for SPARC targets. When a guest signal goes unhandled, dump_core_and_abort() skips the core write and falls through to die_with_signal(), which re-raises the signal to the host. The host kernel then writes an x86-64 core file for the qemu-sparc process instead of a SPARC guest core. Populating the full register layout is required for tools like libunwind-coredump, which reads pr_reg[33] for the trap PC and pr_reg[16..31] for the windowed registers. Signed-off-by: Matt Turner Cc: Mark Cave-Ayland Signed-off-by: Helge Deller --- linux-user/sparc/elfload.c | 27 +++++++++++++++++++++++++++ linux-user/sparc/target_elf.h | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/linux-user/sparc/elfload.c b/linux-user/sparc/elfload.c index 32ca1b05b1..e6387ec891 100644 --- a/linux-user/sparc/elfload.c +++ b/linux-user/sparc/elfload.c @@ -4,8 +4,35 @@ #include "qemu.h" #include "loader.h" #include "elf.h" +#include "target_elf.h" =20 =20 +void elf_core_copy_regs(target_elf_gregset_t *r, const CPUArchState *env) +{ + CPUSPARCState *e =3D (CPUSPARCState *)env; + int i; + +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) + for (i =3D 0; i < 8; i++) { + r->regs[i] =3D tswap64(env->gregs[i]); + r->regs[8 + i] =3D tswap64(env->regwptr[WREG_O0 + i]); + } + r->regs[16] =3D tswap64(sparc64_tstate(e)); + r->regs[17] =3D tswap64(env->pc); + r->regs[18] =3D tswap64(env->npc); + r->regs[19] =3D tswap64(env->y); +#else + r->regs[0] =3D tswap32(cpu_get_psr(e)); + r->regs[1] =3D tswap32(env->pc); + r->regs[2] =3D tswap32(env->npc); + r->regs[3] =3D tswap32(env->y); + for (i =3D 0; i < 8; i++) { + r->regs[4 + i] =3D tswap32(env->gregs[i]); + r->regs[12 + i] =3D tswap32(env->regwptr[WREG_O0 + i]); + } +#endif +} + const char *get_elf_cpu_model(uint32_t eflags) { #ifdef TARGET_SPARC64 diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h index 7827767bcb..edb0b3103c 100644 --- a/linux-user/sparc/target_elf.h +++ b/linux-user/sparc/target_elf.h @@ -13,6 +13,7 @@ # define ELF_MACHINE EM_SPARC #elif defined(TARGET_ABI32) # define ELF_CLASS ELFCLASS32 +# define ELF_MACHINE EM_SPARC32PLUS # define elf_check_machine(x) ((x) =3D=3D EM_SPARC32PLUS || (x) =3D=3D E= M_SPARC) #else # define ELF_CLASS ELFCLASS64 @@ -20,5 +21,15 @@ #endif =20 #define HAVE_ELF_HWCAP 1 +#define HAVE_ELF_CORE_DUMP 1 + +/* + * Matches the kernel's elf_gregset_t (ELF_NGREG =3D 20). + * sparc32/sparc32plus: psr, pc, npc, y, u_regs[16] (g0-g7, o0-o7) + * sparc64: u_regs[16] (g0-g7, o0-o7), tstate, pc, npc, y + */ +typedef struct target_elf_gregset_t { + abi_ulong regs[20]; +} target_elf_gregset_t; =20 #endif --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841106; cv=none; d=zohomail.com; s=zohoarc; b=jywGxc1sf9xm3VWWmMLvbpT9l7PDGD2wq/R89o9yTc6rc+mvk5G08mO5gicJqCamyl2RSmFFlD/c+8yJ7RYek0zzgFLFrBr/r8ZdKYr3BVomeeXx9fIEHqIhBvifigiGLnecNM8UqrsabMzr7pgMY4Ya8Uf9NLyed2K/H1Cn4zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841106; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J1AWjYZU/hD53VPk5IiZ2Jz6nUV+3nPhEWHBfOxyoTE=; b=knmFL2ZxgjTT5X30R5dteDG2mp8EGKr5jRNafNbfGMoKzIbsX53y9SCL/hUeec+7nZ1NZuAoRjBGAXlP51wIgZGHEh+2tO3xVN/mmjYmY8YZsHl5Km1mKUxIh787N44TyejYA4bhHX+Xrh/ies9Q609lYIC4AwzgoSm2nH0Xcug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841106718807.7568655449736; Sun, 7 Jun 2026 07:05:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6p-0004Kn-2H; Sun, 07 Jun 2026 10:04:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6n-0004KP-NX for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:13 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6m-00085h-5j for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:13 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 487D241B73; Sun, 7 Jun 2026 14:04:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C52D1F00893; Sun, 7 Jun 2026 14:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841051; bh=J1AWjYZU/hD53VPk5IiZ2Jz6nUV+3nPhEWHBfOxyoTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U+GPrPTKNQAKBXYb/dChj93Zr03RwQAYY2B2K2hgxSslrSkKKwPYzS77XTMhaCMFd O9vVyKKjlxJ/0q33dCkWmhLRELojdyUa6JuYRY21Luxdg9nCLBP9ZQcAwQd4qB4ZIh QVtwfuZkxmm0hPbNvj0kxj+MkwkeDjU9AcpU34PN34UK4P/cfGCSHtf/ZZm2B1Ll4w myg4jymZmF/44Z+5W2gsU9lyWStBdDISh6cOOwbVDoTKuimIGcTpy/INxqOC2EZJwi 1KKTcxj0Qd7YLGwGbQC+t4PHoS+rQf20scjnD0JtVmwybdj89W0dR3Wn2X/hQgIXKf /iGoameZ8RJQA== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner , Mark Cave-Ayland Subject: [PATCH 05/10] linux-user/sparc: restore L/I registers from RSA in sparc64_set_context Date: Sun, 7 Jun 2026 16:03:51 +0200 Message-ID: <20260607140356.10702-6-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841107778154100 Content-Type: text/plain; charset="utf-8" From: Matt Turner The kernel's do_rt_sigreturn loads L and I registers from the register save area (RSA) at the restored O6+STACK_BIAS. QEMU lacks the kernel's window-fill path, so restore L0-L7 and I0-I5 explicitly from the RSA. I6 and I7 are already restored from mc_fp/mc_i7. Signed-off-by: Matt Turner Cc: Mark Cave-Ayland Signed-off-by: Helge Deller --- linux-user/sparc/signal.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c index d339f89928..fda5508c48 100644 --- a/linux-user/sparc/signal.c +++ b/linux-user/sparc/signal.c @@ -656,6 +656,24 @@ void sparc64_set_context(CPUSPARCState *env) __get_user(env->regwptr[WREG_FP], &(ucp->tuc_mcontext.mc_fp)); __get_user(env->regwptr[WREG_I7], &(ucp->tuc_mcontext.mc_i7)); =20 + /* + * The kernel's do_rt_sigreturn loads L and I registers from the + * register save area (RSA) at the new O6+STACK_BIAS. Unlike the + * kernel, QEMU has no kernel-mode path that triggers a window fill, + * so we must do it explicitly here. I6 and I7 are already restored + * from mc_fp and mc_i7 above; restore L0-L7 and I0-I5 from the RSA. + */ + { + abi_ulong sp_ptr =3D env->regwptr[WREG_O6]; + /* LP64 O6 is biased (8-byte-aligned - 2047); low bit set. ILP32 O= 6 is 4-byte-aligned. */ + if (sp_ptr & 3) + sp_ptr +=3D TARGET_STACK_BIAS; + for (i =3D 0; i < 8; i++) + get_user_ual(env->regwptr[WREG_L0 + i], sp_ptr + i * 8); + for (i =3D 0; i < 6; i++) /* I0-I5; I6=3DFP and I7 already restor= ed */ + get_user_ual(env->regwptr[WREG_I0 + i], sp_ptr + 64 + i * 8); + } + fpup =3D &ucp->tuc_mcontext.mc_fpregs; =20 __get_user(fenab, &(fpup->mcfpu_enab)); --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841141; cv=none; d=zohomail.com; s=zohoarc; b=PIedkb7WasEPkXrMTHMJYkExbe/HWXSFP9Fe8g4/XV0+1cHKcPJZ3cqX2t2WAa3husP4a6k2qrYJh0iDCjNuuy6xuzzYZub1RYbMD6a+A9fOC5EsyzYGPu4D7gMpQG+gJeXaQwiIfQ8r1iMOm/12Sz0IquMKJzgL3hDWGdD8rXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841141; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z1dfaMdDG1BHIABJPuyTvw9aGXsVucAwD1oVosQ69OE=; b=emgmVYnXiX/0zxZYG15Zf5NR7VvXxZDr2RomCKF/SY7UrLoQ0AzLe68+9uSGpHfV0TLZkJMKJYdrhKJdniMr7JDkDDHfC7oqUnOr53QeB7Xgrj0PU0csJODxWPGXTgiXhWmnafu+erD/LQl1i3FBULM9pefLNd/SV8XNy+u0pLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178084114178618.98550632962838; Sun, 7 Jun 2026 07:05:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6r-0004L9-44; Sun, 07 Jun 2026 10:04:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6q-0004Kv-1P for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:16 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6o-00085z-Cl for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:15 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 84CAE44353; Sun, 7 Jun 2026 14:04:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DE491F00893; Sun, 7 Jun 2026 14:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841053; bh=Z1dfaMdDG1BHIABJPuyTvw9aGXsVucAwD1oVosQ69OE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E7FXUhiOzubVp01t2baeApImLVVoIYzPJ2rtL0TcVHFN5Txrz40XcZtBEb477A05B UCLjWA2h/QAwYe38CDc/vQR+E5QxbnQvCfS1Vs/Hkoeakz7HvmP1P5Yyc89yMeLZmV ZmjsWi+wLA1a1TAnjOywEVXE7BK5hFVGLbXKTf549g/dIwALnJ40cW+mBqkssiCVN/ x9oza8uw/Tz/abN0g9V3tyaXVFLjdlWkHiJTvCh9jDOJJwQli2LuO5/L66RZXqOHlM HvsH0EYQDmK+Pv6UnPxgLu1ANrS5H05qlBxrTKPbiNSUQ+Lz1rqUcm/UYw/8aJvrH3 7lD1zRgPZUvhQ== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner , Mark Cave-Ayland Subject: [PATCH 06/10] linux-user/sparc: call block_signals() before set_sigmask() in setcontext Date: Sun, 7 Jun 2026 16:03:52 +0200 Message-ID: <20260607140356.10702-7-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841143038158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner sparc64_set_context() emulates the kernel's `ta 0x6f` trap by calling set_sigmask() to install the mask supplied via the user's ucontext_t. The contract of set_sigmask() (see its comment in linux-user/signal.c) is that the caller must have first called block_signals(), which sets TaskState::signal_pending. Without block_signals(), if a guest signal is pending-and-blocked at the time setcontext is invoked and the new mask unblocks it, signal_pending stays 0 and the post-trap process_pending_signals() call in linux-user/sparc/cpu_loop.c never enters its while loop, so the now-deliverable signal is left undelivered indefinitely. This affects programs that use getcontext/setcontext to swap signal masks, including libunwind's unw_resume() out of a signal handler: without this fix, the test program below loops forever printing "calling setcontext" instead of delivering the pending SIGUSR2. #define _GNU_SOURCE #include #include #include #include static int got; static void h(int s) { got =3D 1; } int main(void) { signal(SIGUSR2, h); sigset_t m; sigemptyset(&m); sigaddset(&m, SIGUSR2); sigprocmask(SIG_BLOCK, &m, NULL); kill(getpid(), SIGUSR2); ucontext_t uc; getcontext(&uc); if (got) return 0; uc.uc_sigmask.__val[0] =3D 0; setcontext(&uc); return 1; } The 32-bit sparc do_sigreturn / do_rt_sigreturn paths already get block_signals() from the rt_sigreturn syscall wrapper in linux-user/syscall.c, so only sparc64_set_context (invoked directly from cpu_loop) needs the addition. Signed-off-by: Matt Turner Cc: Mark Cave-Ayland Signed-off-by: Helge Deller --- linux-user/sparc/signal.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c index fda5508c48..ba692c3123 100644 --- a/linux-user/sparc/signal.c +++ b/linux-user/sparc/signal.c @@ -619,6 +619,15 @@ void sparc64_set_context(CPUSPARCState *env) } } target_to_host_sigset_internal(&set, &target_set); + /* + * set_sigmask() requires the caller to have first called + * block_signals() so that process_pending_signals() is guaranteed + * to run after the mask change. Without this, a guest signal that + * is pending-and-blocked at setcontext time is left undelivered + * even after its mask bit is cleared, because signal_pending stays + * 0 and the post-trap process_pending_signals() loop never enters. + */ + block_signals(); set_sigmask(&set); } env->pc =3D pc; --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841091; cv=none; d=zohomail.com; s=zohoarc; b=k5ul1ZGoubcSFaCSoaUHlH8RTa/DyjTemf4B/GhupaR8co+tD0zPquOdLg672CWIX/kB7/sa1ohRQLOUXAeehFv56g22PBAk+xKeV9nuPlZMoVQRImPXMI8b828aR7TeenI5nH+OGBs9/lbFKCOa/DnvHSxPMoR7+d+48PG/9qA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841091; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gEmpbKVD9hDcSZqLWrik9HtYpOvGlKu3Ri0bvNo/FQk=; b=dgnz225wESeBrB1fSI4R+x5p2A9005vhHRyqs7IUVJKyv45Fz1Usqi/xKH2pXWO6u1BuJQ3id1rMPdyNJQ5NDfK7FHBDxNYGyNQHaIcN7CcQtRs/SyvKkG6xagKKVstBvdWN6ecN1SZSYAuxClPXhN6YIFVzqUzhpcw+Yr4gG0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841091796190.64439606263943; Sun, 7 Jun 2026 07:04:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6t-0004Lf-Mz; Sun, 07 Jun 2026 10:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6s-0004LJ-LL for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:18 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6q-00086L-KY for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:18 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id EE8A560018; Sun, 7 Jun 2026 14:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9FCB1F00893; Sun, 7 Jun 2026 14:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841055; bh=gEmpbKVD9hDcSZqLWrik9HtYpOvGlKu3Ri0bvNo/FQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fVBxOEV4CTtlMUmoDf4OgKZzSZUUMyRlAOsL/8LwBjLu2fYQUkb5G0m34c38P9f6G PovWQMq5MDP4mmKwvxZGVUalhN+C6hDKs3MDy46T4aNze6UK6FZ0QalrdVtV4ol5lu ku05mCoJirlMPzYhCZDWKx4LajKdUTCZg47m+QPrHVHvDesQQrkaKfeiK+JKkb01dR o/U16v5CXyMnrb3x34BFL76IHrtC7ahbb1IZjfRgSYtVT98HVy4E1JjEjTeN2orx/5 jZGMMudyxCTzQBZ7Go3TTyajX+/ZtL3sJE8g4ZPswcIX9v06u1avb2chBBd36jd6d1 IUgEXmpyiIwoA== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner , Mark Cave-Ayland Subject: [PATCH 07/10] linux-user/sparc: flush register windows before core dump Date: Sun, 7 Jun 2026 16:03:53 +0200 Message-ID: <20260607140356.10702-8-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841093383158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner Without this, only the crash frame's window is spilled to the stack; all deeper call frames remain in the register file and are absent from the core's memory segments. Stack unwinding fails past the first DWARF step because the callers' register save areas contain stale/garbage data. The real kernel calls flush_all_user_windows() at the top of do_coredump(). Mirror that via a weak target_flush_windows() hook called from dump_core_and_abort(), with the SPARC override calling the existing flush_windows() in cpu_loop.c. Signed-off-by: Matt Turner Cc: Mark Cave-Ayland Signed-off-by: Helge Deller --- linux-user/elfload.c | 9 ++++++++ linux-user/sparc/cpu_loop.c | 3 ++- linux-user/sparc/cpu_loop.h | 7 +++++++ linux-user/sparc/elfload.c | 39 +++++++++++++++++++++++++++++------ linux-user/sparc/target_elf.h | 17 +++++++++++---- 5 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 linux-user/sparc/cpu_loop.h diff --git a/linux-user/elfload.c b/linux-user/elfload.c index f7625c0952..b05b8b0c6b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2445,6 +2445,9 @@ static int wmr_write_region(void *opaque, vaddr start, * handler (provided that target process haven't registered * handler for that) that does the dump when signal is received. */ +#ifdef TARGET_SPARC +#include "sparc/cpu_loop.h" +#endif static int elf_core_dump(int signr, const CPUArchState *env) { const CPUState *cpu =3D env_cpu_const(env); @@ -2468,6 +2471,12 @@ static int elf_core_dump(int signr, const CPUArchSta= te *env) cpu_list_lock(); mmap_lock(); =20 +#ifdef TARGET_SPARC + CPU_FOREACH(cpu_iter) { + flush_windows(cpu_env(cpu_iter)); + } +#endif + /* By unprotecting, we merge vmas that might be split. */ walk_memory_regions(NULL, wmr_page_unprotect_regions); =20 diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c index ab633eeae3..0aacda9448 100644 --- a/linux-user/sparc/cpu_loop.c +++ b/linux-user/sparc/cpu_loop.c @@ -22,6 +22,7 @@ #include "user-internals.h" #include "user/cpu_loop.h" #include "signal-common.h" +#include "sparc/cpu_loop.h" =20 #define SPARC64_STACK_BIAS 2047 =20 @@ -119,7 +120,7 @@ static void restore_window(CPUSPARCState *env) #endif } =20 -static void flush_windows(CPUSPARCState *env) +void flush_windows(CPUSPARCState *env) { int offset, cwp1; =20 diff --git a/linux-user/sparc/cpu_loop.h b/linux-user/sparc/cpu_loop.h new file mode 100644 index 0000000000..fb6e82d372 --- /dev/null +++ b/linux-user/sparc/cpu_loop.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef SPARC_CPU_LOOP_H +#define SPARC_CPU_LOOP_H + +void flush_windows(CPUSPARCState *env); + +#endif diff --git a/linux-user/sparc/elfload.c b/linux-user/sparc/elfload.c index e6387ec891..181f1e00b5 100644 --- a/linux-user/sparc/elfload.c +++ b/linux-user/sparc/elfload.c @@ -12,16 +12,41 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const = CPUArchState *env) CPUSPARCState *e =3D (CPUSPARCState *)env; int i; =20 + memset(r, 0, sizeof(*r)); + #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) + /* Linux kernel layout for sparc64 (arch/sparc/include/asm/elf_64.h): + * [0..7] G0-G7 + * [8..15] O0-O7 + * [16..23] L0-L7 + * [24..31] I0-I7 + * [32] TSTATE + * [33] TPC + * [34] TNPC + * [35] Y + */ for (i =3D 0; i < 8; i++) { - r->regs[i] =3D tswap64(env->gregs[i]); - r->regs[8 + i] =3D tswap64(env->regwptr[WREG_O0 + i]); + r->regs[i] =3D tswap64(env->gregs[i]); + r->regs[8 + i] =3D tswap64(env->regwptr[WREG_O0 + i]); + r->regs[16 + i] =3D tswap64(env->regwptr[WREG_L0 + i]); + r->regs[24 + i] =3D tswap64(env->regwptr[WREG_I0 + i]); } - r->regs[16] =3D tswap64(sparc64_tstate(e)); - r->regs[17] =3D tswap64(env->pc); - r->regs[18] =3D tswap64(env->npc); - r->regs[19] =3D tswap64(env->y); + r->regs[32] =3D tswap64(sparc64_tstate(e)); + r->regs[33] =3D tswap64(env->pc); + r->regs[34] =3D tswap64(env->npc); + r->regs[35] =3D tswap64(env->y); #else + /* Linux kernel layout for sparc32 (arch/sparc/include/asm/elf_32.h): + * [0] PSR + * [1] PC + * [2] NPC + * [3] Y + * [4..11] G0-G7 + * [12..19] O0-O7 + * [20..27] L0-L7 + * [28..35] I0-I7 + * [36..37] reserved (stack_check) + */ r->regs[0] =3D tswap32(cpu_get_psr(e)); r->regs[1] =3D tswap32(env->pc); r->regs[2] =3D tswap32(env->npc); @@ -29,6 +54,8 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CP= UArchState *env) for (i =3D 0; i < 8; i++) { r->regs[4 + i] =3D tswap32(env->gregs[i]); r->regs[12 + i] =3D tswap32(env->regwptr[WREG_O0 + i]); + r->regs[20 + i] =3D tswap32(env->regwptr[WREG_L0 + i]); + r->regs[28 + i] =3D tswap32(env->regwptr[WREG_I0 + i]); } #endif } diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h index edb0b3103c..365af864b0 100644 --- a/linux-user/sparc/target_elf.h +++ b/linux-user/sparc/target_elf.h @@ -24,12 +24,21 @@ #define HAVE_ELF_CORE_DUMP 1 =20 /* - * Matches the kernel's elf_gregset_t (ELF_NGREG =3D 20). - * sparc32/sparc32plus: psr, pc, npc, y, u_regs[16] (g0-g7, o0-o7) - * sparc64: u_regs[16] (g0-g7, o0-o7), tstate, pc, npc, y + * Matches the kernel's elf_gregset_t. + * sparc32/sparc32plus (ELF_NGREG =3D 38): + * psr, pc, npc, y, u_regs[16] (g0-g7, o0-o7), + * reg_window[16] (l0-l7, i0-i7), stack_check[2] + * sparc64 (ELF_NGREG =3D 36): + * u_regs[16] (g0-g7, o0-o7), reg_window[16] (l0-l7, i0-i7), + * tstate, tpc, tnpc, y */ +#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) +# define TARGET_ELF_NGREG 36 +#else +# define TARGET_ELF_NGREG 38 +#endif typedef struct target_elf_gregset_t { - abi_ulong regs[20]; + abi_ulong regs[TARGET_ELF_NGREG]; } target_elf_gregset_t; =20 #endif --=20 2.54.0 From nobody Sun Jun 7 22:17:41 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841136; cv=none; d=zohomail.com; s=zohoarc; b=dLWkALt2Mwt5V64ch1l+beYcZyNK0fMdzjLlnrdItBq9Lqmn8FerJy2ED4oQaphiY1q06tBnQV0BaNKU7KIP/rSkRR9Wa/7nDPLwsQg0g5vR/nKrlGk2zn/DTlrRFwO0D/+CB+LoxSitv+DLJ2G5XRDJ1sgAjOLRAb/AVf9s0Dc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841136; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jX18zqXFA+LNSDjlxcNAVPph0zpvwfV3CNTKM9znobo=; b=hS/CqGO+VgPJ5X/KrlhNbxyMtokNJgr9zcluajX0DYsZn8jD78Iat+Hn2lglbuRSEVgKCPSJWUQZunlidGBvFWty1HOauqAaOYN0o32oaZ0p9KRuJrgxpM/aLjXvIF4P8W+q6Bl9mGbB9Mn5bkDuyAlUhAZvrxqTvZUA7SPt+as= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841136121454.2399414549467; Sun, 7 Jun 2026 07:05:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6v-0004M9-Jf; Sun, 07 Jun 2026 10:04:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6u-0004M0-Er for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:20 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6s-00086t-VD for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:20 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 0917843688; Sun, 7 Jun 2026 14:04:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21C2E1F00893; Sun, 7 Jun 2026 14:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841057; bh=jX18zqXFA+LNSDjlxcNAVPph0zpvwfV3CNTKM9znobo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BCP9ldpq/Cad+rp8Dys2X92OYmtVQsR+21UTrdZLs9JGKe1TSkajp0OI2duEzQBto aRjmFUfoz5U51F14flmvVq3Mlw/71vYIqCNzPPnRVCA20CQg90617g2fw58b5nA3Jh tI6tc6U8foDWaE8xZmwymvhhInngFC6OP7I7bMb8vPe6679feNsqYBhCrjN7OueIwS GoAnriW3odiCTbSpoY8MCDxTgQDhfdrQ2tzVysUc6BEOW7EHmA/f9cd2AASfOwC2cb ScbN5MCuDJVp+qJVx0g2MD6crj2T+sgZjLIscdx40wTT0honNbKh7EXD2m18UBiAiT 6Y2WSE9wrK19w== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner , Richard Henderson Subject: [PATCH 08/10] target/sh4: decode_gusa: recognize add#imm with prior mov Rm, Rn Date: Sun, 7 Jun 2026 16:03:54 +0200 Message-ID: <20260607140356.10702-9-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841136748158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner The gUSA pattern matcher rejected `add #imm, Rn` whenever any prior `mov Rm, Rn` appeared (mv_src >=3D 0), forcing a fallback to cpu_exec_step_atomic for sequences like: mov.l @r2, r3 ; load mov r3, r7 ; save old value (mv_src =3D=3D ld_dst) add #1, r7 ; increment copy mov.l r7, @r2 ; store When mv_src =3D=3D ld_dst the move merely copies the loaded value to preserve it -- exactly the situation already accepted for the `add Rm, Rn` form. The immediate form can be handled identically with tcg_gen_atomic_fetch_add_i32 + tcg_gen_add_i32, so translate it inline instead of taking the slower single-step atomic fallback. Signed-off-by: Matt Turner Cc: Yoshinori Sato Cc: Richard Henderson Signed-off-by: Helge Deller --- target/sh4/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/sh4/translate.c b/target/sh4/translate.c index 5adf650744..d38a6bd352 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -1974,7 +1974,7 @@ static void decode_gusa(DisasContext *ctx, CPUSH4Stat= e *env) break; =20 case 0x7000 ... 0x700f: /* add #imm,Rn */ - if (op_dst !=3D B11_8 || mv_src >=3D 0) { + if (op_dst !=3D B11_8 || (mv_src >=3D 0 && mv_src !=3D ld_dst)) { goto fail; } op_opc =3D INDEX_op_add; --=20 2.54.0 From nobody Sun Jun 7 22:17:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841127; cv=none; d=zohomail.com; s=zohoarc; b=T9lpB7MLk+8iQRV1iAbs9vqHY/4mhp7ysAyJIMmRUzJg2h98REq4yzfelQstkWyGkOKpP8u2KuDFmn63vG4kwGAqowfOdk0HXM0SM9kDkczQxqYa20Z9CK6Ak6DWOdcjWp5Ux1F3CUE8+JwDNMfpZfSfb1n2Yc2OD/M+TZ+qqS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841127; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7LLRWlYl4f50tTS2x2GJ/eFkVK++jmXZ/i6kKIARBlk=; b=PLjPxBkAkOPMM7TMPK5O4wMdglErLdrwdLZTHVTNXoH762gBCVXdEWOr6qvjT6oODxex3yQ3xAz8I5XFz3aX3n3F6iUUAluaTpxIsKQaSx5EuFJBfZHfYelrdSsdC2V6HZryxHhB3r3v8wGMBj6wxkJNvs/V+G11IarKHBVvrWw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841127814502.4759620309427; Sun, 7 Jun 2026 07:05:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE6y-0004MX-1y; Sun, 07 Jun 2026 10:04:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6w-0004MP-Ir for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:22 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6u-00087J-TF for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:22 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 45E5160018; Sun, 7 Jun 2026 14:04:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DF3C1F00893; Sun, 7 Jun 2026 14:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841060; bh=7LLRWlYl4f50tTS2x2GJ/eFkVK++jmXZ/i6kKIARBlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i+htPQebVybQqK5/xMve51dnxXppeqheHJ0LhRbOJIfvP2/g1DeQGSmJ3Spz4KLso J7ZR48V+9re+nA2seLz1df7Q/rg1u6oNHJjRyb60q3WnACDsp9tHgZmeqMOUOi1d8g ew8YNYmEYUvbo0hZ+xAALPctEKX+ELrNwgKWpCK3DosCsr0fPdToq4dnHIflLcs9TJ X19BnA9SeQ2XxBEMAg4HEn4ofdW2CTSjJkE+OeZ1O6xOtVq+bWuKJFZex6yFy7adVl oV6SCOvNAlrOyFpaS85YnkldRsFV/I/vqATTYtuZYTBivACmTFMqAm0LgoCe1udd2O mOvnuV+7MOL/g== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner Subject: [PATCH 09/10] linux-user/xtensa: restore FP rounding mode on sigreturn Date: Sun, 7 Jun 2026 16:03:55 +0200 Message-ID: <20260607140356.10702-10-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c04:e001:324:0:1991:8:25; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841130020154100 Content-Type: text/plain; charset="utf-8" From: Matt Turner The Xtensa FCR rounding-mode (RM) bits are not held only in env->uregs[FCR]: they are also reflected into env->fp_status via set_float_rounding_mode(). Similarly, FSR exception flags are mirrored into env->fp_status. Every write to FCR/FSR goes through helper_wur_fpu{2k,}_fcr / helper_wur_fpu_fsr which keep the two in sync. restore_sigcontext() previously wrote nothing back for xtregs, leaving env->fp_status with whatever rounding mode and exception flags the signal handler last installed. Any FP instruction in the interrupted code could then operate with the wrong mode. Add a minimal target_xtensa_xtregs sub-frame carrying FCR and FSR. setup_sigcontext() saves the current values and points sc_xtregs at the sub-frame when XTENSA_OPTION_FP_COPROCESSOR or XTENSA_OPTION_DFP_COPROCESSOR is present (both use env->fp_status driven by FCR/FSR). restore_sigcontext() reads sc_xtregs; if non-zero it restores FCR and FSR through cpu_set_fcr()/cpu_set_fsr() so fp_status round-trips correctly across signal delivery. Signed-off-by: Matt Turner Cc: Max Filippov Signed-off-by: Helge Deller --- linux-user/xtensa/signal.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/linux-user/xtensa/signal.c b/linux-user/xtensa/signal.c index ef8b0c3a27..fef23952b7 100644 --- a/linux-user/xtensa/signal.c +++ b/linux-user/xtensa/signal.c @@ -21,6 +21,7 @@ #include "user-internals.h" #include "signal-common.h" #include "linux-user/trace.h" +#include "target/xtensa/cpu.h" =20 struct target_sigcontext { abi_ulong sc_pc; @@ -43,10 +44,15 @@ struct target_ucontext { target_sigset_t tuc_sigmask; }; =20 +struct target_xtensa_xtregs { + uint32_t fcr; + uint32_t fsr; +}; + struct target_rt_sigframe { target_siginfo_t info; struct target_ucontext uc; - /* TODO: xtregs */ + struct target_xtensa_xtregs xtregs; uint8_t retcode[6]; abi_ulong window[4]; }; @@ -107,6 +113,7 @@ static int flush_window_regs(CPUXtensaState *env) } =20 static int setup_sigcontext(struct target_rt_sigframe *frame, + abi_ulong frame_addr, CPUXtensaState *env) { struct target_sigcontext *sc =3D &frame->uc.tuc_mcontext; @@ -123,8 +130,15 @@ static int setup_sigcontext(struct target_rt_sigframe = *frame, for (i =3D 0; i < 16; ++i) { __put_user(env->regs[i], sc->sc_a + i); } - __put_user(0, &sc->sc_xtregs); - /* TODO: xtregs */ + if (xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR) || + xtensa_option_enabled(env->config, XTENSA_OPTION_DFP_COPROCESSOR))= { + __put_user(env->uregs[FCR], &frame->xtregs.fcr); + __put_user(cpu_get_fsr(env), &frame->xtregs.fsr); + __put_user(frame_addr + offsetof(struct target_rt_sigframe, xtregs= ), + &sc->sc_xtregs); + } else { + __put_user(0, &sc->sc_xtregs); + } return 1; } =20 @@ -190,7 +204,7 @@ void setup_rt_frame(int sig, struct target_sigaction *k= a, __put_user(0, &frame->uc.tuc_flags); __put_user(0, &frame->uc.tuc_link); target_save_altstack(&frame->uc.tuc_stack, env); - if (!setup_sigcontext(frame, env)) { + if (!setup_sigcontext(frame, frame_addr, env)) { unlock_user_struct(frame, frame_addr, 0); goto give_sigsegv; } @@ -266,7 +280,19 @@ static void restore_sigcontext(CPUXtensaState *env, for (i =3D 0; i < 16; ++i) { __get_user(env->regs[i], sc->sc_a + i); } - /* TODO: xtregs */ + { + abi_ulong xtregs_addr; + + __get_user(xtregs_addr, &sc->sc_xtregs); + if (xtregs_addr) { + uint32_t fcr, fsr; + + __get_user(fcr, &frame->xtregs.fcr); + __get_user(fsr, &frame->xtregs.fsr); + cpu_set_fcr(env, fcr); + cpu_set_fsr(env, fsr); + } + } } =20 long do_rt_sigreturn(CPUXtensaState *env) --=20 2.54.0 From nobody Sun Jun 7 22:17:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1780841140; cv=none; d=zohomail.com; s=zohoarc; b=DlfmTAUfJZw3J85K8+z945KUr8ONFeaTi25RvVowxhy2Xpd2+X0NNJgbRhBs7r8QSbtmU1dAagotUnhoYS3YJ9SHR0gexKqQaERz9Hp3Hk8ci8rxlThFSNxYPEu12hPWf5Awzb9TogfBQQ8bFvJApNO/sjFSw1UEECqgRy8yyDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1780841140; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RfxlUwNU/48O+8PvYhYcsgantRKLa0A2pRTtbB1enaY=; b=R3FqW8vWsvLit7pKdu0XHNkv8KnlVIp1NCv2hAR55GCUsZf7QU6/YSYG4rfQ6lyfZcr3dcp6MbMG6UyoQycVD7ayHrMCebRRbEwTDZNNO1J8MK8br1E3N2gtE1JJWbOx5zVy908GfhUCgoyjZL4VpLcGcc9XlapE+12gfkqKQWI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1780841140426286.01036840691677; Sun, 7 Jun 2026 07:05:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wWE71-0004NG-4P; Sun, 07 Jun 2026 10:04:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6z-0004Mt-S4 for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:25 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wWE6y-00088C-6n for qemu-devel@nongnu.org; Sun, 07 Jun 2026 10:04:25 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 551156001D; Sun, 7 Jun 2026 14:04:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CD6B1F00893; Sun, 7 Jun 2026 14:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780841062; bh=RfxlUwNU/48O+8PvYhYcsgantRKLa0A2pRTtbB1enaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gyJ1sjVf47+a6UHesFQWUc96tB54KHrcEUHMG2rg/9qHFYhgYjDN0+FIhGlyie7fw UicBLFluopap1G6/QTGnscVcbOy15p869mC7aeU/7jLTofemKipKoYuxmUH2lY+fqq lZ6ZhoWQ0lAJla4xU0RVJ7ladpMtwKbVcHFPZQewq+Qr+XZwsqIqXPAQ4hlBz8OdRz OcjsPQBfj+TclXHUB/tm1CnYLo4UZK8hjLAHGw3cxCsgNgiuBXCEpINk8WsKuO9Bfl KrenkjFmIgdsuwAuJSIYZc+tcyNL9b4iEzAMo2A9HbkxnBi6VnfnvGtBkDaEcuJrK2 Qjeai4TGy/aTw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Laurent Vivier , Yoshinori Sato , Max Filippov , Helge Deller , Matt Turner Subject: [PATCH 10/10] target/xtensa: add cpu_set_fcr/fsr helpers to sync fp_status Date: Sun, 7 Jun 2026 16:03:56 +0200 Message-ID: <20260607140356.10702-11-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260607140356.10702-1-deller@kernel.org> References: <20260607140356.10702-1-deller@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c04:e001:324:0:1991:8:25; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1780841142230154100 From: Matt Turner Factor FCR=E2=86=92fp_status and FSR=E2=86=92fp_status synchronisation out = of the wur_fpu{2k,}_fcr/wur_fpu_fsr helpers into cpu_set_fcr(), cpu_set_fsr(), and cpu_get_fsr(). Signal delivery code needs to restore the FP rounding mode and exception flags without duplicating the flag-mapping tables. cpu_set_fcr() applies the union mask 0xfffff07f (superset of the wur_fpu_fcr mask 0x0000007f and the wur_fpu2k_fcr mask 0xfffff07f) so that FCR bits valid only on fpu2k configs are preserved while MBZ bits 7-11 are always cleared. v2: Use FloatRoundMode as suggested by Richard. Signed-off-by: Matt Turner Cc: Max Filippov Signed-off-by: Helge Deller --- target/xtensa/cpu.h | 4 ++++ target/xtensa/fpu_helper.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index 75cfeee6e3..442e98bd1b 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -642,6 +642,10 @@ static inline void xtensa_select_static_vectors(CPUXte= nsaState *env, } void xtensa_runstall(CPUXtensaState *env, bool runstall); =20 +uint32_t cpu_get_fsr(CPUXtensaState *env); +void cpu_set_fcr(CPUXtensaState *env, uint32_t v); +void cpu_set_fsr(CPUXtensaState *env, uint32_t v); + #define XTENSA_OPTION_BIT(opt) (((uint64_t)1) << (opt)) #define XTENSA_OPTION_ALL (~(uint64_t)0) =20 diff --git a/target/xtensa/fpu_helper.c b/target/xtensa/fpu_helper.c index 5358060c50..9f1256f677 100644 --- a/target/xtensa/fpu_helper.c +++ b/target/xtensa/fpu_helper.c @@ -64,6 +64,48 @@ void xtensa_use_first_nan(CPUXtensaState *env, bool use_= first) &env->fp_status); } =20 +uint32_t cpu_get_fsr(CPUXtensaState *env) +{ + uint32_t flags =3D 0; + int fef =3D get_float_exception_flags(&env->fp_status); + unsigned i; + + for (i =3D 0; i < ARRAY_SIZE(xtensa_fp_flag_map); ++i) { + if (fef & xtensa_fp_flag_map[i].softfloat_fp_flag) { + flags |=3D xtensa_fp_flag_map[i].xtensa_fp_flag; + } + } + return flags << XTENSA_FSR_FLAGS_SHIFT; +} + +void cpu_set_fcr(CPUXtensaState *env, uint32_t v) +{ + static const FloatRoundMode rounding_mode[] =3D { + float_round_nearest_even, + float_round_to_zero, + float_round_up, + float_round_down, + }; + + env->uregs[FCR] =3D v & 0xfffff07f; + set_float_rounding_mode(rounding_mode[v & 3], &env->fp_status); +} + +void cpu_set_fsr(CPUXtensaState *env, uint32_t v) +{ + uint32_t flags =3D v >> XTENSA_FSR_FLAGS_SHIFT; + int fef =3D 0; + unsigned i; + + env->uregs[FSR] =3D v & 0x00000f80; + for (i =3D 0; i < ARRAY_SIZE(xtensa_fp_flag_map); ++i) { + if (flags & xtensa_fp_flag_map[i].xtensa_fp_flag) { + fef |=3D xtensa_fp_flag_map[i].softfloat_fp_flag; + } + } + set_float_exception_flags(fef, &env->fp_status); +} + void HELPER(wur_fpu2k_fcr)(CPUXtensaState *env, uint32_t v) { static const int rounding_mode[] =3D { --=20 2.54.0