From nobody Fri May 3 21:58:37 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162407877774755.51448409984596; Fri, 18 Jun 2021 21:59:37 -0700 (PDT) Received: from localhost ([::1]:37052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luT4y-000758-MT for importer2@patchew.org; Sat, 19 Jun 2021 00:59:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luT2X-0002uM-GZ for qemu-devel@nongnu.org; Sat, 19 Jun 2021 00:57:05 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:41524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luT2V-0000MR-Kr for qemu-devel@nongnu.org; Sat, 19 Jun 2021 00:57:05 -0400 Received: by mail-pl1-x62d.google.com with SMTP id e1so5716404plh.8 for ; Fri, 18 Jun 2021 21:57:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id i6sm11581378pgg.50.2021.06.18.21.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 21:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=081mKzQdRF4YARgfGLG8Cn+s1WSek62UMz6C8qKQ5eA=; b=KkTRfWFHbYbK9Nh6qnnR/nByASUhzG45TT2Ft/qdTeDlSyVToocTuYC3FLGi1Vrh00 arrgKBFzfvXKLgZc/ThF5qHnNicoSQmdoROSUxmBvu8Sh9hBALfIwFfb1vBSnoqe6P07 DEY/SZ/qMHR+q8xW/JOcYjYt0ujdmXKObgzHBD45hYf6Ys2sD//FjK9IpEt3TkXRab3i GtJLK6XrcCA97vNJtybJe8W5lZMBs3/3SEbyGl27a1hWkJKRCuO4UVP0s8QFMRi5CUdZ kct3+au6D5cCp9jiqL8qH6jzwi3M+6IHtBUvtgf+tE6mA9uDwIyrOle5TSzoKgb6QmVY u45g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=081mKzQdRF4YARgfGLG8Cn+s1WSek62UMz6C8qKQ5eA=; b=DTemQYPjppJYhg8I2K2THUmD4gohv1Riw40+Aujzbx7oPeECCrYbG1CODHSyxZu/kt jXgvG3cFoDAPOfZnCx0VxPXcfCCSj7HXX5UfoqFvN2k2t03olZdyPLw+hvfhh/1SUO+q 2Ohl127q9eCWRNQF4hxsDfGLLJ7NqTjVDUtQ+Vx5l9ag1VWzMOkPLr4G+50CRVn8Zb/I sV36VeIgATdLpPek2A1Hzn5kaJcMyOMiC0UPI2WM12I3B+/m1ztQ1KLnv7FUKqvkMI/M YvrFxNHO0GXmbvq6MQgzW0AhKtRtjyXL/6qoTGAL3aNjDsZCuOvXeMV2BHVme8nnJBRr umgQ== X-Gm-Message-State: AOAM532IRREAZQJKuHGlNg8eQUEY9kn0uUVChOcekBL5UtgiMyZr4qeA 0W+nPkvGBrPMRhks8V6o/V3y9s6GattvPg== X-Google-Smtp-Source: ABdhPJxmHp+L7/X7BktQtYVS04HFGBFf02oYv80mkoPr5v9MK9GUeOKZFc8Pbw4aVfYeswj+7Q9K/A== X-Received: by 2002:a17:902:e8c2:b029:123:25ba:e443 with SMTP id v2-20020a170902e8c2b029012325bae443mr145957plg.29.1624078622136; Fri, 18 Jun 2021 21:57:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 1/2] tcg/sparc: Fix temp_allocate_frame vs sparc stack bias Date: Fri, 18 Jun 2021 21:56:59 -0700 Message-Id: <20210619045700.46907-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619045700.46907-1-richard.henderson@linaro.org> References: <20210619045700.46907-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::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sw@weilnetz.de, mark.cave-ayland@ilande.co.uk, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We should not be aligning the offset in temp_allocate_frame, because the odd offset produces an aligned address in the end. Instead, pass the logical offset into tcg_set_frame and add the stack bias last. Cc: qemu-stable@nongnu.org Cc: mark.cave-ayland@ilande.co.uk Signed-off-by: Richard Henderson Tested-by: Stefan Weil --- tcg/tcg.c | 9 +++------ tcg/sparc/tcg-target.c.inc | 16 ++++++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index dd584f3bba..52e858523c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3015,17 +3015,14 @@ static void check_regs(TCGContext *s) =20 static void temp_allocate_frame(TCGContext *s, TCGTemp *ts) { -#if !(defined(__sparc__) && TCG_TARGET_REG_BITS =3D=3D 64) - /* Sparc64 stack is accessed with offset of 2047 */ - s->current_frame_offset =3D (s->current_frame_offset + - (tcg_target_long)sizeof(tcg_target_long) - = 1) & - ~(sizeof(tcg_target_long) - 1); -#endif if (s->current_frame_offset + (tcg_target_long)sizeof(tcg_target_long)= > s->frame_end) { tcg_abort(); } ts->mem_offset =3D s->current_frame_offset; +#if defined(__sparc__) + ts->mem_offset +=3D TCG_TARGET_STACK_BIAS; +#endif ts->mem_base =3D s->frame_temp; ts->mem_allocated =3D 1; s->current_frame_offset +=3D sizeof(tcg_target_long); diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc index ce39ac2d86..a6ec94a094 100644 --- a/tcg/sparc/tcg-target.c.inc +++ b/tcg/sparc/tcg-target.c.inc @@ -984,14 +984,18 @@ static void tcg_target_qemu_prologue(TCGContext *s) { int tmp_buf_size, frame_size; =20 - /* The TCG temp buffer is at the top of the frame, immediately - below the frame pointer. */ + /* + * The TCG temp buffer is at the top of the frame, immediately + * below the frame pointer. Use the logical (aligned) offset here; + * the stack bias is applied in temp_allocate_frame(). + */ tmp_buf_size =3D CPU_TEMP_BUF_NLONGS * (int)sizeof(long); - tcg_set_frame(s, TCG_REG_I6, TCG_TARGET_STACK_BIAS - tmp_buf_size, - tmp_buf_size); + tcg_set_frame(s, TCG_REG_I6, -tmp_buf_size, tmp_buf_size); =20 - /* TCG_TARGET_CALL_STACK_OFFSET includes the stack bias, but is - otherwise the minimal frame usable by callees. */ + /* + * TCG_TARGET_CALL_STACK_OFFSET includes the stack bias, but is + * otherwise the minimal frame usable by callees. + */ frame_size =3D TCG_TARGET_CALL_STACK_OFFSET - TCG_TARGET_STACK_BIAS; frame_size +=3D TCG_STATIC_CALL_ARGS_SIZE + tmp_buf_size; frame_size +=3D TCG_TARGET_STACK_ALIGN - 1; --=20 2.25.1 From nobody Fri May 3 21:58:37 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=1624078754; cv=none; d=zohomail.com; s=zohoarc; b=USkEWVC10kUqITWNnpxwuKdUSqeEcwcn9xFGPkB17vQRlLiWCrD4Bow5XMIDU4Q6g4GR5t/8SrQqOvwKy0IkJgU2NOKvp4Jm+uTXrzlhD7XcDREbX8BAyAwypV9doE9ToLpqeBL5qrebQU2Twpmwbuc/f2urp1wMY+YtbY0Megw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624078754; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tEW/fJi/hH3gdu+mIHV/IgnrMMh/sh6iojGv1lBJoQk=; b=VmUlKRFfl0neGI9+ow5PoZfN8hdfisKJ/CFYSTN7fZAHLnhlk6AgYPBdTJ4V/zZ1OvK0WDr7eW71tHqheXDBumiJ6u2MAtSBZ6gUg0EYLLDPDjSKkog5SIUFtQuVBNgC0IFeRPAXDmbrtoxnXQJmPJOsYu9V377YoIRhGz3d4w8= 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 1624078754519966.2295529359371; Fri, 18 Jun 2021 21:59:14 -0700 (PDT) Received: from localhost ([::1]:35516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luT4b-000635-Hr for importer2@patchew.org; Sat, 19 Jun 2021 00:59:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luT2a-0002xf-QG for qemu-devel@nongnu.org; Sat, 19 Jun 2021 00:57:08 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:35384) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luT2V-0000Mo-PX for qemu-devel@nongnu.org; Sat, 19 Jun 2021 00:57:08 -0400 Received: by mail-pg1-x530.google.com with SMTP id v7so9560771pgl.2 for ; Fri, 18 Jun 2021 21:57:03 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id i6sm11581378pgg.50.2021.06.18.21.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 21:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tEW/fJi/hH3gdu+mIHV/IgnrMMh/sh6iojGv1lBJoQk=; b=CUPdDWoGJOfx0NJdc+uSpOJ/Ji4BtWT15K+WmsyHsXxPPNbawMVTINcAaL8fJaXnZ4 RvfEB08SiHkbZsrkbrqcDiojVL+myRTtKQUWH0vdyWyxkkwsxvZ9thJ3xWYw3fXxI4RP MDRNyCJ3a3zMWc24vmArjk9/CyajIgg+vZDe++VtKK5sa9nEMAp5nXdc5MpPp5FhvkEo r0tdXdv6sTPB/7Pgg/GsKgUkUZwWjHIINeigjBqYvp5R9VBAMf1FWajlmwIb6lzqxA3W Q+WY0s3hQbgP/NxgLECvHkKNtjEc597gw7AwTxM7SPRRCs1rhZoHzwO0Dc8imi0usIDf Mt6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tEW/fJi/hH3gdu+mIHV/IgnrMMh/sh6iojGv1lBJoQk=; b=LMXHPb2JmF4QF7maYHDsoY1VXmBzm7V+PlqDPi9f5Hs+bWrsogutZbtGzq8mFXpBhy hikOG+9kdJmBfzOPnWJJg6/zSVBuz2gaHMAfrjYKYijJ1gkvVObZvICMpPOl5fy6YK4A ESbeU4SD1T+igfOB762pDmeDCAXFYd0ia90MGarwnfNb6TkzY+OwN+yDlpTNLIt1vwNw MLYB1orSxLMZ/a6IVXsPfRXyY2XoThvyjQZJVNd+fR/cpvbwJYpfgdyQGa5SN4UVyE8r yS19jlgZ+8RYvvjJ9wUpt48FSc/0zgV63VJUGNElbBGYpboL6kSnpSteqUMFYYk+0b37 UAAA== X-Gm-Message-State: AOAM532QtVTGChjxWntmA64h8IL6ARFEAOI+SoZTS51tLyRV9noH0hdN 0sh3VH6CXS0Vqjm7DhxJxM/Wk3m/zeeWlA== X-Google-Smtp-Source: ABdhPJz9GSal/2dK6CHAa3Pg8hjx4AoZg7gZ61fPQahpVP/jTuWIlbLu0jqdj1rDnP7yJ7Abov+jjA== X-Received: by 2002:a65:5c87:: with SMTP id a7mr13189799pgt.312.1624078622567; Fri, 18 Jun 2021 21:57:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 2/2] tcg: Allocate sufficient storage in temp_allocate_frame Date: Fri, 18 Jun 2021 21:57:00 -0700 Message-Id: <20210619045700.46907-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619045700.46907-1-richard.henderson@linaro.org> References: <20210619045700.46907-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::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sw@weilnetz.de, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" This function should have been updated for vector types when they were introduced. Cc: qemu-stable@nongnu.org Fixes: d2fd745fe8b Resolves: https://gitlab.com/qemu-project/qemu/-/issues/367 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Stefan Weil --- tcg/tcg.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index 52e858523c..1bad423bde 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3015,17 +3015,39 @@ static void check_regs(TCGContext *s) =20 static void temp_allocate_frame(TCGContext *s, TCGTemp *ts) { - if (s->current_frame_offset + (tcg_target_long)sizeof(tcg_target_long)= > - s->frame_end) { - tcg_abort(); + size_t size, align; + intptr_t off; + + switch (ts->type) { + case TCG_TYPE_I32: + size =3D align =3D 4; + break; + case TCG_TYPE_I64: + case TCG_TYPE_V64: + size =3D align =3D 8; + break; + case TCG_TYPE_V128: + size =3D align =3D 16; + break; + case TCG_TYPE_V256: + /* Note that we do not require aligned storage for V256. */ + size =3D 32, align =3D TCG_TARGET_STACK_ALIGN; + break; + default: + g_assert_not_reached(); } - ts->mem_offset =3D s->current_frame_offset; + + assert(align <=3D TCG_TARGET_STACK_ALIGN); + off =3D ROUND_UP(s->current_frame_offset, align); + assert(off + size <=3D s->frame_end); + s->current_frame_offset =3D off + size; + + ts->mem_offset =3D off; #if defined(__sparc__) ts->mem_offset +=3D TCG_TARGET_STACK_BIAS; #endif ts->mem_base =3D s->frame_temp; ts->mem_allocated =3D 1; - s->current_frame_offset +=3D sizeof(tcg_target_long); } =20 static void temp_load(TCGContext *, TCGTemp *, TCGRegSet, TCGRegSet, TCGRe= gSet); --=20 2.25.1