From nobody Sun Dec 29 19:31:47 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1719963784; cv=none; d=zohomail.com; s=zohoarc; b=MCROVWn3AymarElX4pxWkiHq8nZ0AOlhj1skSVoJZazI577zRGzIZzr28dSlEdbPb00UeEqEQdclUxLKrhF7QYO1dx6MD4OIgOa0cH38VDsqE4yz3Oy5PQCE3keEk5vBQCNmdoS7KhDPBH5D9h9OhST+wRZUPqwOy8hnbuNXoMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719963784; 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=C86LL5Jjwnhff3U2J7Sfodi1QBdh0ARwqCfrj06rmAw=; b=iMX6xwlP4WQ9t2rfwT8Lf4rc58EzFeMRCc66icEdTAlCM8JJi/L6VtSdm5LBVW7eqr+lyIMll8dVEhCvlQeomrwGgDMMonoOflivBsFGmxq4M5y+vJdm+fr5UKLzWKE6fCmFYdH94Fu2rUxvaoLB7le8r517vrfQl4vpC92DKSM= 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+importer2=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 1719963784654507.00836553906584; Tue, 2 Jul 2024 16:43:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOn8f-0007pw-VA; Tue, 02 Jul 2024 19:42:21 -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 1sOn8O-0007lF-LM for qemu-devel@nongnu.org; Tue, 02 Jul 2024 19:42:05 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOn8L-0006NJ-9c for qemu-devel@nongnu.org; Tue, 02 Jul 2024 19:42:04 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f9e2affc8cso30183265ad.2 for ; Tue, 02 Jul 2024 16:42:00 -0700 (PDT) Received: from stoup.. (174-21-76-141.tukw.qwest.net. [174.21.76.141]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac15993c5sm90403755ad.244.2024.07.02.16.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 16:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719963720; x=1720568520; 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=C86LL5Jjwnhff3U2J7Sfodi1QBdh0ARwqCfrj06rmAw=; b=YC+fdWrHeqfKXDFSvjD7hHFs9c6tj3WG4Ys/PZzSFFfS98M5wiVkUxsmJe/KeuzdFS NfZyQgnHpoGzhffqoTD+3DXVebR8ZJ0RIEsUbGYw75KvnbikNyz8Wstu8N3XxToIQ/S/ jygS2e8CBBeid9hJQDQHeE4fWKL5F9Yv86elXF/UYENCAkjPCcGgx6RmPjWSV5C9XT7m 463XHtQtvu/aOvjkh3JXJQDhffPAuBkITMJAunEeAo83kO3ca+FjcMC+E0xFTQ2+aYuZ pYcE/NcX14FrnCViFMPMq5eTxZRnUkc5/fuUoYAoFY2hnRBganWlm2w1K/+OiyEYWTWL 7cZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719963720; x=1720568520; 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=C86LL5Jjwnhff3U2J7Sfodi1QBdh0ARwqCfrj06rmAw=; b=pvUfjKMoRTbtl5w5PtkkvLJZwBILeJVLfjY70UvfhsfWugiO028IckwxwH1j5kmRW+ GvSpK/anr1LLmYJbfToPctA7gNz8BP1q/qlli7fXqEEaSEct/iGxvXy866L+ceAmiRyO EKDOjh/RKLDsRROD5fZC4nnbiY5b5WphHuSsUmNZ/rsT9/b3QG+/b6snNHt8ReeJsDf0 UD1LngH21mBz4dtjabqeH8mVki1iJIqSuGd/mx3WFCs1VxnJSW+l4KdyORPcBYeGR9Bk 1kLQKX6ZWywO221Z36HjbCs2OaFZJ4SS5f6zKYJTCUKmTIOthd9yLi3M9iukk27PZ2QV fiCA== X-Gm-Message-State: AOJu0Yz7KB35dH2dIQyohJygbBQjSO9x0rVMr0gJyrVX9QmxF5fZtVQJ vuo/PDH9codWvULxR6uMw3TYJfTzgL9OwbkSq232TQhyoBhjsIV0jGkIZ9W7OAkf1+k8e0oiD0n I X-Google-Smtp-Source: AGHT+IHw7kNsK9w8JLVq5wc4q+FM54V2vahUJgbw13ReisVcVk6Pv8aIcjS2xFhmLeuk4naJCPPszQ== X-Received: by 2002:a17:902:f682:b0:1f9:ddea:451d with SMTP id d9443c01a7336-1fadbc73712mr58478065ad.3.1719963719711; Tue, 02 Jul 2024 16:41:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, iii@linux.ibm.com, david@redhat.com, balaton@eik.bme.hu Subject: [PATCH 2/2] target/arm: Use memset_ra, memmove_ra in helper-a64.c Date: Tue, 2 Jul 2024 16:41:55 -0700 Message-Id: <20240702234155.2106399-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702234155.2106399-1-richard.henderson@linaro.org> References: <20240702234155.2106399-1-richard.henderson@linaro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1719963787155100006 Content-Type: text/plain; charset="utf-8" Without this, qemu user will not unwind from the SIGSEGV properly and die with qemu-aarch64: QEMU internal SIGSEGV {code=3DACCERR, addr=3D0x7d1b36ec2000} Segmentation fault Fill in the test case for ppc and s390x, which also use memset from within a helper (but don't currently crash fwiw). Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- target/arm/tcg/helper-a64.c | 10 ++-- tests/tcg/multiarch/memset-fault.c | 77 ++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 tests/tcg/multiarch/memset-fault.c diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c index 0ea8668ab4..666bdb7c1a 100644 --- a/target/arm/tcg/helper-a64.c +++ b/target/arm/tcg/helper-a64.c @@ -971,7 +971,7 @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in) } #endif =20 - memset(mem, 0, blocklen); + memset_ra(mem, 0, blocklen, GETPC()); } =20 void HELPER(unaligned_access)(CPUARMState *env, uint64_t addr, @@ -1120,7 +1120,7 @@ static uint64_t set_step(CPUARMState *env, uint64_t t= oaddr, } #endif /* Easy case: just memset the host memory */ - memset(mem, data, setsize); + memset_ra(mem, data, setsize, ra); return setsize; } =20 @@ -1163,7 +1163,7 @@ static uint64_t set_step_tags(CPUARMState *env, uint6= 4_t toaddr, } #endif /* Easy case: just memset the host memory */ - memset(mem, data, setsize); + memset_ra(mem, data, setsize, ra); mte_mops_set_tags(env, toaddr, setsize, *mtedesc); return setsize; } @@ -1497,7 +1497,7 @@ static uint64_t copy_step(CPUARMState *env, uint64_t = toaddr, uint64_t fromaddr, } #endif /* Easy case: just memmove the host memory */ - memmove(wmem, rmem, copysize); + memmove_ra(wmem, rmem, copysize, ra); return copysize; } =20 @@ -1572,7 +1572,7 @@ static uint64_t copy_step_rev(CPUARMState *env, uint6= 4_t toaddr, * Easy case: just memmove the host memory. Note that wmem and * rmem here point to the *last* byte to copy. */ - memmove(wmem - (copysize - 1), rmem - (copysize - 1), copysize); + memmove_ra(wmem - (copysize - 1), rmem - (copysize - 1), copysize, ra); return copysize; } =20 diff --git a/tests/tcg/multiarch/memset-fault.c b/tests/tcg/multiarch/memse= t-fault.c new file mode 100644 index 0000000000..0e8258a88f --- /dev/null +++ b/tests/tcg/multiarch/memset-fault.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include + +#if defined(__powerpc64__) +/* Needed for PT_* constants */ +#include +#endif + +static void *ptr; +static void *pc; + +static void test(void) +{ +#ifdef __aarch64__ + void *t; + asm("adr %0,1f; str %0,%1; 1: dc zva,%2" + : "=3D&r"(t), "=3Dm"(pc) : "r"(ptr)); +#elif defined(__powerpc64__) + void *t; + asm("bl 0f; 0: mflr %0; addi %0,%0,1f-0b; std %0,%1; 1: dcbz 0,%2" + : "=3D&r"(t), "=3Dm"(pc) : "r"(ptr) : "lr"); +#elif defined(__s390x__) + void *t; + asm("larl %0,1f; stg %0,%1; 1: xc 0(256,%2),0(%2)" + : "=3D&r"(t), "=3Dm"(pc) : "r"(ptr)); +#else + *(int *)ptr =3D 0; +#endif +} + +static void *host_signal_pc(ucontext_t *uc) +{ +#ifdef __aarch64__ + return (void *)uc->uc_mcontext.pc; +#elif defined(__powerpc64__) + return (void *)uc->uc_mcontext.gp_regs[PT_NIP]; +#elif defined(__s390x__) + return (void *)uc->uc_mcontext.psw.addr; +#else + return NULL; +#endif +} + +static void sigsegv(int sig, siginfo_t *info, void *uc) +{ + assert(info->si_addr =3D=3D ptr); + assert(host_signal_pc(uc) =3D=3D pc); + exit(0); +} + +int main(void) +{ + static const struct sigaction sa =3D { + .sa_flags =3D SA_SIGINFO, + .sa_sigaction =3D sigsegv + }; + size_t size; + int r; + + size =3D getpagesize(); + ptr =3D mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + assert(ptr !=3D MAP_FAILED); + + test(); + + r =3D sigaction(SIGSEGV, &sa, NULL); + assert(r =3D=3D 0); + r =3D mprotect(ptr, size, PROT_NONE); + assert(r =3D=3D 0); + + test(); + abort(); +} --=20 2.34.1