From patchwork Tue Jul 2 23:41:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 809141 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp442429wru; Tue, 2 Jul 2024 16:43:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXezngNc/8pcLt6SmJxVyyyEkFwHdYHRKtHLr77Mrg7C0JY4+uw+woMQY3eZY9naGNRH+LDmODV2VSOI1Y0ly83 X-Google-Smtp-Source: AGHT+IEguqzZ0ALGzZ/D2rU1ew+aQgQ0xdwh9DocZKrkDPVa40/++S5a7FhgTr6MIKqqR4MBmCsA X-Received: by 2002:a67:e909:0:b0:48f:5343:dea7 with SMTP id ada2fe7eead31-48faf132d22mr11012196137.22.1719963784186; Tue, 02 Jul 2024 16:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719963784; cv=none; d=google.com; s=arc-20160816; b=GioziQcbL1+4gYVilqesZmXmYY7dVXNsyqRf8vRzWcnPRaF5z4LGULywtP/q3S0zDv gEkRrD2o1bcU1sZ0++vT4dquYq+h5FUq2beqHnMjkg01RJ9tcA4QymnZz4LViI6v3Hw1 GMiBgfjWNdu5izD+Bnyt2q5UAwKqQWq56OMA7/2XQUikEX3rNh282yxDKGosHVDf/G5K DPWd3kjdpnBxpokRnPfpUJjLYcSsA5VM14pVMtjndyz3y5ZBgadB31PADCx9wKzLzIwt 0PkWBYRp316qwBSDKGaVDJUtaUV9X0Czg/vff79IKaVFsgSJRzvz3MtRQY9jrsLlGRmG 4jzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GwtkDEQSe1rF7ol2hwOawpAhY63WerL1vNoE65OHhNw=; fh=Fz3OM3AGXo6S/XDNq12jK+U+cl8IKdGchX/2GB3YVy0=; b=TQnso3m/w6XoNn2Lk4Ul9YUaYcwGv6Nr9Tk3ybbQY0r4p86EhfCS9TsPH8jUmVj421 sUJwp8K7rB3UaA6NIcXVSOXVaoZn4KT3l1LIy3/mq+URuteqaWyj4osjgSz0Dp7OaNCY hBd33K5UpPOIvP5otUotC98WNgELlZaY/jixCB4J6NI20Mc9Ioyhz0IV8hyoKbMLIhhn Npl84UDvWjKKn/V6fu0LXnr7/frBggyrqA7V5YXmA6mE99wdBDzfHgwTLezk923M0Ydo 4XMcSkN1fimVoIRRsOtAHKLQ37t1FLjC0/g8kbdwoKFwK4/CT6N8guGs3/q5vDw7BQQn 5Hyg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ysXTxB4b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79d692f08d4si1253239585a.334.2024.07.02.16.43.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 16:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ysXTxB4b; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOn8g-0007q0-0N; Tue, 02 Jul 2024 19:42:23 -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 1sOn8V-0007mc-Rp for qemu-devel@nongnu.org; Tue, 02 Jul 2024 19:42:13 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOn8L-0006N1-8d for qemu-devel@nongnu.org; Tue, 02 Jul 2024 19:42:11 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1f6a837e9a3so20790785ad.1 for ; Tue, 02 Jul 2024 16:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719963719; x=1720568519; 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=GwtkDEQSe1rF7ol2hwOawpAhY63WerL1vNoE65OHhNw=; b=ysXTxB4bkgw0sR27syT0Hz/gco+NJBS3zOKv0hTKunkISc6Qqa7PLnrq8eG8TDJfY+ dYekmK0/u7GTpif7C1tIVRIC931mZ/8i/idZDPYDDZ06ox46+FE81hyjzsII79yeyXLw Z25lKm6Py1BHWyVRYwzYldXODh+rstujVWyYIBMggwgnKeLdzJK+EKfWCMNZYa4O39fT MNVfUgwCWdariqVwmhYugDZgfNPKi2g87joqnOi7L16OY5MNChx1ly+V+8trvoyeoieR 4Se3lmdNpm51wNpP9SbyQSZvtiOr+ZLbuQ+5tf1G1zu2PKgNFPg+7WFbgiufAK+uTZlG miLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719963719; x=1720568519; 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=GwtkDEQSe1rF7ol2hwOawpAhY63WerL1vNoE65OHhNw=; b=KbZrGMjGGxStiRsssNJ3N0jldFDrpiZpEH8X6n21E0AhvYwGbbgbeaJysLoPEkvtFG tKaR1RhTzHylBTyxGWtxeGV5jirN0wz7hib10x6rtIXL2LFGcCOBhU8axoWun9OeH/m7 6MIJf1yqVOr5CWeIAGhOYuouM5BXWaNDxBGC/OUODiti/TGCIkQWP9iShd6N1VIakfJ8 UjZVhZhjl4A7NXLgX0W6MB2dnq7AQ7JnKgLZsaZZJA/YPPyAa0VImiblrBv1wEYXwzsA Z2JLKNZCwDtLp0rEJ79amXIKol6YRqjQL2lCwb0zpfDhfyj812pP2J8DecOgL1cfk9DX iq1Q== X-Gm-Message-State: AOJu0YwoOQ8j0FPTVAVGvlVA5nuS2+p2D2hzNIvGc0MOt3aFVekP8ppE l326OXc7AmP+TmYviqT13DXfYuC5h0JLzoKFVwnHK9V7v4ZCUbYrZBOlzNFTquGfrDVxlpv0gvq 4 X-Received: by 2002:a17:902:e54f:b0:1f7:1655:825c with SMTP id d9443c01a7336-1fadbca1794mr82220985ad.36.1719963718703; Tue, 02 Jul 2024 16:41:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 16:41:58 -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 1/2] accel/tcg: Introduce memset_ra, memmove_ra Date: Tue, 2 Jul 2024 16:41:54 -0700 Message-Id: <20240702234155.2106399-2-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 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add wrappers that set and clear helper_retaddr around the host memory operation. This cannot fail for system mode, but might raise SIGSEGV for user mode. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/exec/cpu_ldst.h | 40 ++++++++++++++++++++++++++++++++++++++++ accel/tcg/user-exec.c | 22 ++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 71009f84f5..baf4f9367d 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -379,4 +379,44 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, MMUAccessType access_type, int mmu_idx); #endif +/** + * memset_ra: + * @p: host pointer + * @c: data + * @n: length + * @ra: unwind return address + * + * Like system memset(p,c,n), except manages @ra for the calling + * helper in the event of a signal. To be used with the result + * of tlb_vaddr_to_host to resolve the host pointer. + */ +#ifdef CONFIG_USER_ONLY +void *memset_ra(void *p, int c, size_t n, uintptr_t ra); +#else +static inline void *memset_ra(void *p, int c, size_t n, uintptr_t ra) +{ + return memset(p, c, n); +} +#endif + +/** + * memmove_ra: + * @d: host destination pointer + * @s: host source pointer + * @n: length + * @ra: unwind return address + * + * Like system memmove(d,s,n), except manages @ra for the calling + * helper in the event of a signal. To be used with the result of + * tlb_vaddr_to_host to resolve the host pointer. + */ +#ifdef CONFIG_USER_ONLY +void *memmove_ra(void *d, const void *s, size_t n, uintptr_t ra); +#else +static inline void *memmove_ra(void *d, const void *s, size_t n, uintptr_t ra) +{ + return memmove(d, s, n); +} +#endif + #endif /* CPU_LDST_H */ diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 80d24540ed..a73da42e3a 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -1289,3 +1289,25 @@ static void *atomic_mmu_lookup(CPUState *cpu, vaddr addr, MemOpIdx oi, #define DATA_SIZE 16 #include "atomic_template.h" #endif + +void *memset_ra(void *p, int c, size_t n, uintptr_t ra) +{ + void *r; + + set_helper_retaddr(ra); + r = memset(p, c, n); + clear_helper_retaddr(); + + return r; +} + +void *memmove_ra(void *d, const void *s, size_t n, uintptr_t ra) +{ + void *r; + + set_helper_retaddr(ra); + r = memmove(d, s, n); + clear_helper_retaddr(); + + return r; +} From patchwork Tue Jul 2 23:41:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 809142 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp442430wru; Tue, 2 Jul 2024 16:43:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWYpWYmaCMsj1lNN1vqNXFuxr4LGKkDbASMb0b4MlDFOCUVrPWTxnAqtm/s+BmQRrvpFa9wkdBtTt2/g1BhA3mq X-Google-Smtp-Source: AGHT+IH+XVk7Enym1lgdeFbkagoNU2Z2NNZhfOOcEbSJdAxqtOcLg843MqwE6ybfCEMW9RR4sePW X-Received: by 2002:a81:a24e:0:b0:62f:b04c:2442 with SMTP id 00721157ae682-64c70c76533mr102367297b3.7.1719963784178; Tue, 02 Jul 2024 16:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719963784; cv=none; d=google.com; s=arc-20160816; b=eV1a21Ml6B5u37VfUFQYLOTWqkNS4QFsZL2ioRTFrGDqr+OnNDMdVYJIjuaRRqYjvX K8Y8BgJEkNNfVZ88tLy24O3pQ71ZT1DlnP89nV3N70IePmKikMG1ylBjbfrhtca789ks lJ9Z5ZEfY1bEbv1icXF3tXsJBdrfAVro2U2RdY2hATR0tqRutuiR0jDdDmJlorlqhsi0 HHNk94v11rpXme4Ye40f/pgkc7vfEAB3UDxiEIgiJVLKSLDQ7gs6gU21o0uJIkfjozxV akw76ocZBX2eHYXGNhww3F+owDOWYqNLc+tek3v6hQIYpJSwCvY2jnB72ZhDr4cGz37x SCDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C86LL5Jjwnhff3U2J7Sfodi1QBdh0ARwqCfrj06rmAw=; fh=Fz3OM3AGXo6S/XDNq12jK+U+cl8IKdGchX/2GB3YVy0=; b=RvfSetecHGPPtBCxfYGswuieuyDvCWbsJf3adavj1dfv46W37G/1x5klLPN4YehDcY u6JqVhyrtpDI8D25ZDcT7f/1/nIZrvuWjQlnx5q2u/69OH0aTslYKD7t8BPaan9uUQXX 17L/I5GAMopqj2Hw1FnhgJdWCHC8B21cTl7u2iPy4vfHfO+zgyVVIhKIMsvh/AjzsuzB cWQqLkyWQIqat1p9RmYBHerfXIqt+WvRS+hu/PrJXEjmds+dTZarRSHRehTDFn/tyosQ fbGTgVpGCnp9QHCrulxaG7hr0t6QJ0khAs5PFY4AJNG2Lz1tRRYi5zC1ZRBhYhZteDYT M2fA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YC+fdWrH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-446889570e2si22230881cf.13.2024.07.02.16.43.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 16:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YC+fdWrH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Without this, qemu user will not unwind from the SIGSEGV properly and die with qemu-aarch64: QEMU internal SIGSEGV {code=ACCERR, addr=0x7d1b36ec2000} 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 - memset(mem, 0, blocklen); + memset_ra(mem, 0, blocklen, GETPC()); } void HELPER(unaligned_access)(CPUARMState *env, uint64_t addr, @@ -1120,7 +1120,7 @@ static uint64_t set_step(CPUARMState *env, uint64_t toaddr, } #endif /* Easy case: just memset the host memory */ - memset(mem, data, setsize); + memset_ra(mem, data, setsize, ra); return setsize; } @@ -1163,7 +1163,7 @@ static uint64_t set_step_tags(CPUARMState *env, uint64_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; } @@ -1572,7 +1572,7 @@ static uint64_t copy_step_rev(CPUARMState *env, uint64_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; } diff --git a/tests/tcg/multiarch/memset-fault.c b/tests/tcg/multiarch/memset-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" + : "=&r"(t), "=m"(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" + : "=&r"(t), "=m"(pc) : "r"(ptr) : "lr"); +#elif defined(__s390x__) + void *t; + asm("larl %0,1f; stg %0,%1; 1: xc 0(256,%2),0(%2)" + : "=&r"(t), "=m"(pc) : "r"(ptr)); +#else + *(int *)ptr = 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 == ptr); + assert(host_signal_pc(uc) == pc); + exit(0); +} + +int main(void) +{ + static const struct sigaction sa = { + .sa_flags = SA_SIGINFO, + .sa_sigaction = sigsegv + }; + size_t size; + int r; + + size = getpagesize(); + ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + assert(ptr != MAP_FAILED); + + test(); + + r = sigaction(SIGSEGV, &sa, NULL); + assert(r == 0); + r = mprotect(ptr, size, PROT_NONE); + assert(r == 0); + + test(); + abort(); +}