From nobody Fri May 17 23:42:27 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1694877224; cv=none; d=zohomail.com; s=zohoarc; b=CGLVLbN8DBlbK99tNXsRpRCPBVQZZ71FDm37uMMDpVXvkhI9qdnn87CaDHmgjOwuWlMp7jw6KN13qTdmzwHPx42bXEXcN07XEYlETvF1pXuLs6KcP4KOwNRTMMMYDD6NpG/4I5EV8J1LnJcrvTEwqqHKL/jV2aJYRtU+eZObt1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694877224; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=V5Ps3a4lJ+EI3U+7BofjCe0p/UZQX+zLEOiygSYpzvo=; b=ISEGIGJaelgMm7Jl5jmrwuvHs4Hzzp3N86bmZnuiUTHTNsbuf3WkuZ601VhMUNNEGjNrYLJUlO6LTImcFsk+wVV8/ecLA38nOsz19Iutp4tj6JicJQ4bT2ySCK/F7IhA/MwqQ1J/OYf/ydO1EPIisf+fXcLurePcHetekymt0xk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694877224286187.79840765845472; Sat, 16 Sep 2023 08:13:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhWyT-0005Ry-Bm; Sat, 16 Sep 2023 11:12:45 -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 1qhVhR-0005GF-PG for qemu-devel@nongnu.org; Sat, 16 Sep 2023 09:51:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qhVhO-00022U-N7 for qemu-devel@nongnu.org; Sat, 16 Sep 2023 09:51:05 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-120-D1xesqKoMZSNQ706M3z0Pg-1; Sat, 16 Sep 2023 09:49:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 79D00101A529; Sat, 16 Sep 2023 13:49:42 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5BCFA28FE; Sat, 16 Sep 2023 13:49:42 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id 4249730C1C0A; Sat, 16 Sep 2023 13:49:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id 3E2EA3FB77; Sat, 16 Sep 2023 15:49:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694872260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=V5Ps3a4lJ+EI3U+7BofjCe0p/UZQX+zLEOiygSYpzvo=; b=EV1sEhh0Kkya5YU+tB6u6bmvNQHRUBrlUmeL5JlYa/UK7VGxW7neGbkpdrx0Neug+RGqHK sxtzo0gMuubqUnaVohlh+63IYM3eL28c7shkkp88CF5mVD/Vn2cJMZXTVs/6/2OX/6O4M3 1YnYqwJiEdtQbYJGhOYTDiBHly1VYxk= X-MC-Unique: D1xesqKoMZSNQ706M3z0Pg-1 Date: Sat, 16 Sep 2023 15:49:42 +0200 (CEST) From: Mikulas Patocka To: Richard Henderson , Helge Deller , John David Anglin cc: qemu-devel@nongnu.org, linux-parisc@vger.kernel.org Subject: [PATCH] target/hppa: clear the PSW 'N' bit when delivering signals Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mpatocka@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 16 Sep 2023 11:12:44 -0400 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694877226361100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" qemu-hppa may crash when delivering a signal. It can be demonstrated with=20 this program. Compile the program with "hppa-linux-gnu-gcc -O2 signal.c"=20 and run it with "qemu-hppa -one-insn-per-tb a.out". It reports that the=20 address of the flag is 0xb4 and it crashes when attempting to touch it. #include #include #include #include sig_atomic_t flag; void sig(int n) { printf("&flag: %p\n", &flag); flag =3D 1; } int main(void) { struct sigaction sa; struct itimerval it; sa.sa_handler =3D sig; sigemptyset(&sa.sa_mask); sa.sa_flags =3D SA_RESTART; if (sigaction(SIGALRM, &sa, NULL)) perror("sigaction"), exit(1); it.it_interval.tv_sec =3D 0; it.it_interval.tv_usec =3D 100; it.it_value.tv_sec =3D it.it_interval.tv_sec; it.it_value.tv_usec =3D it.it_interval.tv_usec; if (setitimer(ITIMER_REAL, &it, NULL)) perror("setitimer"), exit(1); while (1) { } } The reason for the crash is that the signal handling routine doesn't clear=20 the 'N' flag in the PSW. If the signal interrupts a thread when the 'N'=20 flag is set, the flag remains set at the beginning of the signal handler=20 and the first instruction of the signal handler is skipped. Signed-off-by: Mikulas Patocka Acked-by: Helge Deller --- linux-user/hppa/signal.c | 1 + 1 file changed, 1 insertion(+) Index: qemu/linux-user/hppa/signal.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- qemu.orig/linux-user/hppa/signal.c +++ qemu/linux-user/hppa/signal.c @@ -159,6 +159,7 @@ void setup_rt_frame(int sig, struct targ } env->iaoq_f =3D haddr; env->iaoq_b =3D haddr + 4; + env->psw_n =3D 0; return; =20 give_sigsegv: