From patchwork Mon Jul 6 18:52:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 234882 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp229687ilg; Mon, 6 Jul 2020 11:53:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpOMlLGtAwTMifKHBBjxenMAOEfRFlnyNijbhECgq2f66IjTQcLu3IZPjosr4NnwZ69kkQ X-Received: by 2002:a5b:3c5:: with SMTP id t5mr83137630ybp.224.1594061612197; Mon, 06 Jul 2020 11:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594061612; cv=none; d=google.com; s=arc-20160816; b=bJOcd3kOhXR4XryQMoToQyb9jDs7YU/HQ7wUY2uW0qvqAJuPXvDBdM5ZYCZn0sapzm 5XOsNcm75CYbnHlhszQduMiU7Sc49+YpkqeqpYqoY8iLQF21/Kcch/gP/6+cPxuYj0ds a1SwTWeTlTWaJEb/QJvXa7nYQ3J4gTeWrPdW/Kon6fgC7WC02j9lEacnegWg4cAQnK4W ikQoyHYYxTSMykgDDECHMU1CPU2Nv/SKXrAfC9WuCgpd0OB7adHxqIu9S3q6bmezF9W6 Z/jzGgZmaV9kWHWAA7xxp3cmWRmrOnZ0XmIxHpPt2If1YIWxpPKx/95/Yadq4uMCuMIX 5wkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=dze7h0yL3teb5d5LdaXuOfe8lki/JtcylrnNf9X+FXAf4kKcVSXWikY2gBGmivWojP 6KWIz+24HEOEDJQc6h4ikvIRpfOGX834H7zrRtmHvrUSThcnHL/MM3TI3Rr9G1Oh+aJF a0fdvPC8xjEzRCLMJDqrH+wr4CoPd/DTDxdcja1W3byG/iDhR5IO2fnWpjBk7ZdUfkjW rNbZxuTPJRVqnjyBQmlFsxMaS5X+rob/Mf4wCNeguHpXgibLtkccQ0Or6beeuvNO0UYh fjb6SmlNG2rKUvJU55z7JODZbuk8wX+aoc1KshJmdfdW91BWlk/qcZ2K/IQfIP/lHWE0 3mXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pNU0nljl; 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 n63si20184871ybg.244.2020.07.06.11.53.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jul 2020 11:53:32 -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=pNU0nljl; 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]:43770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsWF9-0000uC-NB for patch@linaro.org; Mon, 06 Jul 2020 14:53:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsWEZ-0000sW-0i for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:55 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:42739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jsWEX-0000fG-Dv for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:54 -0400 Received: by mail-pl1-x644.google.com with SMTP id q17so1258107pls.9 for ; Mon, 06 Jul 2020 11:52:53 -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=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=pNU0nljlJvQBpMLL55zd66qH8go5yYWCvaF62nl2w1i2j+hYsbJEgXj0R5HB4rysHT cIpy1OZ2+sLPbkGU0p9cx+V+WzIcusl9NRWthv2XyJ5ELXI6c8jRwh8TWtNsYOJlMP7C hp0/PWMtyYdiAz6ju3mAGiFHPBT640KjS4lyX+VvLo/9cSzCgR+zMeQsI1j/ZQYHFAq3 iJm7tdcZeFe6Ydi9sg4VAhgyrXy7TjqX0m86aJSp+69+dQKjPelK1HytAf6ChdDOQPC9 iD6cpqIsobvZ/FlbdFyp9+7FmogOlfGyzK/B29wshdNepH/x53Q5vEML1vXpyuwOgy4Q bYNQ== 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=rQZd24S5VU+V/cof+qwhVwm+IKJe+Jz5EkBoSd9tflA=; b=dfqtwm3ReEXv3D9diyVuYfDcOVpxg+hAE3UwPoIKZYRWOeg1B/s2uFw4S2Nz794VSO 64+h0/V8lsp5lHaL8yKplDcpBMNDVJyDxmOpMFKcDOAV9dF/e48Bx7ySkhhMBMxLMEPP 6abmEMuL6RB4sJ6l+uaICEfDZiAYF5rg0/1ZxyHNAuEKBnKocVbjU7I5KYFoYnCmpVgs PuuBF9gjmWtUxvF1Ov/Qdni7qJ6OXccIZs8Bxn4JgeUc6XFvxGDTceXdvAk/YeiOM9D7 e/1UAK5FwVLl7Sqf/8SAHxo28fxeDDsEAYynF/ET6eknwv3GNIg9KS0QXgtEF/s4cVu/ 9WBg== X-Gm-Message-State: AOAM532lEO8wezcxj82tJhZ7BUqX70JU0R7y+CSOf6kKjp2S3HIerguj //5YSBPgwxL+qFtZLox6hzSmmSwWETo= X-Received: by 2002:a17:90a:c592:: with SMTP id l18mr568352pjt.119.1594061571479; Mon, 06 Jul 2020 11:52:51 -0700 (PDT) Received: from localhost.localdomain (097-090-106-114.biz.spectrum.com. [97.90.106.114]) by smtp.gmail.com with ESMTPSA id q6sm19988179pfg.76.2020.07.06.11.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 11:52:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] target/arm: Fix temp double-free in sve ldr/str Date: Mon, 6 Jul 2020 11:52:46 -0700 Message-Id: <20200706185248.118447-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706185248.118447-1-richard.henderson@linaro.org> References: <20200706185248.118447-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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=_AUTOLEARN 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: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The temp that gets assigned to clean_addr has been allocated with new_tmp_a64, which means that it will be freed at the end of the instruction. Freeing it earlier leads to assertion failure. The loop creates a complication, in which we allocate a new local temp, which does need freeing, and the final code path is shared between the loop and non-loop. Fix this complication by adding new_tmp_a64_local so that the new local temp is freed at the end, and can be treated exactly like the non-loop path. Fixes: bba87d0a0f4 Signed-off-by: Richard Henderson --- target/arm/translate-a64.h | 1 + target/arm/translate-a64.c | 6 ++++++ target/arm/translate-sve.c | 8 ++------ 3 files changed, 9 insertions(+), 6 deletions(-) -- 2.25.1 diff --git a/target/arm/translate-a64.h b/target/arm/translate-a64.h index 49e4865918..647f0c74f6 100644 --- a/target/arm/translate-a64.h +++ b/target/arm/translate-a64.h @@ -30,6 +30,7 @@ void unallocated_encoding(DisasContext *s); } while (0) TCGv_i64 new_tmp_a64(DisasContext *s); +TCGv_i64 new_tmp_a64_local(DisasContext *s); TCGv_i64 new_tmp_a64_zero(DisasContext *s); TCGv_i64 cpu_reg(DisasContext *s, int reg); TCGv_i64 cpu_reg_sp(DisasContext *s, int reg); diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 73d753f11f..8c0764957c 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -461,6 +461,12 @@ TCGv_i64 new_tmp_a64(DisasContext *s) return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64(); } +TCGv_i64 new_tmp_a64_local(DisasContext *s) +{ + assert(s->tmp_a64_count < TMP_A64_MAX); + return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_local_new_i64(); +} + TCGv_i64 new_tmp_a64_zero(DisasContext *s) { TCGv_i64 t = new_tmp_a64(s); diff --git a/target/arm/translate-sve.c b/target/arm/translate-sve.c index f318ca265f..08f0fd15b2 100644 --- a/target/arm/translate-sve.c +++ b/target/arm/translate-sve.c @@ -4372,9 +4372,8 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) /* Copy the clean address into a local temp, live across the loop. */ t0 = clean_addr; - clean_addr = tcg_temp_local_new_i64(); + clean_addr = new_tmp_a64_local(s); tcg_gen_mov_i64(clean_addr, t0); - tcg_temp_free_i64(t0); gen_set_label(loop); @@ -4422,7 +4421,6 @@ static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm) tcg_gen_st_i64(t0, cpu_env, vofs + len_align); tcg_temp_free_i64(t0); } - tcg_temp_free_i64(clean_addr); } /* Similarly for stores. */ @@ -4463,9 +4461,8 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm) /* Copy the clean address into a local temp, live across the loop. */ t0 = clean_addr; - clean_addr = tcg_temp_local_new_i64(); + clean_addr = new_tmp_a64_local(s); tcg_gen_mov_i64(clean_addr, t0); - tcg_temp_free_i64(t0); gen_set_label(loop); @@ -4509,7 +4506,6 @@ static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm) } tcg_temp_free_i64(t0); } - tcg_temp_free_i64(clean_addr); } static bool trans_LDR_zri(DisasContext *s, arg_rri *a)