From patchwork Wed May 17 09:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 682920 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp252354wrt; Wed, 17 May 2023 02:16:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DYg63skQrrLfmK20JISbC4+9Yf1/eK5Zc/HmCZ0Y0+CUlnGM9WdWraDa/bvs8hVCN7EgM X-Received: by 2002:a05:6214:501b:b0:623:883a:3137 with SMTP id jo27-20020a056214501b00b00623883a3137mr1188559qvb.51.1684314976694; Wed, 17 May 2023 02:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684314976; cv=none; d=google.com; s=arc-20160816; b=iuG4KDR7ec81ExQlbOdSd8g5H3/ombfiBuLafKw5M4BJZb7t+nTFKWTE9TRX1y/mAg IJsOtsU9YjnfS+V2P96TQhdZ6rr3zNfvi/XHqh+XGP7PgT/L0H7ZPK/Ym1gU4G4x1ugK WnsB4qVjhH6z+rHYfZDlV5FP7FvH9cvqPjrYlCKcIBTRgpOeGAJRWMRNZHorIRnWa2RD dw+uaJRiXeYeeDL7CvFhj4L/Cuj77Ih4lx+osndnwYY+itxQNwvkL7xD8AIaOcl69LNe poFcSrlzePMqQrt3oElyUgfl34aYF1OMNfqA5/pnhlexpcYDoCryJsEs5zjIuHkJfrE9 Udfg== 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; bh=UpHyG11s3oMQohGH0wgKOXPPxD7U4upHzL3xArjhCwk=; b=EKvnwhxl2LlAUKZyc7ebOxp8icq7bKzeThV4y3z5ga4Xw8HpNf+hJX2CEnV/RYU/wS QyfkZNckYA3zRzx1akRNLyC21KrQ8Yt9G5Bx8AE9n/71W82fP50vIKLRCGoClAlJAHdR gl0s4RgsZjjLQ5Xz/5Lzy++KAwmC0TRVd/rRzf4b3+aCpGZk8GbqjELCzoG0fnvyakl0 AnLAq9x3Rf5DGGArKU+Tf/J61ZG+l7It+2ly0cbdkefMDZwrzxlnhaQO5BzodvW3ubkV g3LHpcE9i9nEtLm67jQhWx8t69dxMvRX/M8o+kvC3sdkl6H1pVISPG8fDzysCAKEJVwW CNVA== ARC-Authentication-Results: i=1; mx.google.com; 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" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a6-20020a0562140c2600b005dd590e0b2fsi6662583qvd.157.2023.05.17.02.16.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 May 2023 02:16:16 -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; 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" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzDBj-0000vO-72; Wed, 17 May 2023 05:11:15 -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 1pzDBi-0000u9-6J; Wed, 17 May 2023 05:11:14 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzDBg-0006OT-B6; Wed, 17 May 2023 05:11:13 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id C4F076832; Wed, 17 May 2023 12:10:44 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 399035F03; Wed, 17 May 2023 12:10:44 +0300 (MSK) Received: (nullmailer pid 3626702 invoked by uid 1000); Wed, 17 May 2023 09:10:42 -0000 From: Michael Tokarev To: qemu-stable@nongnu.org Cc: qemu-devel@nongnu.org, Peter Maydell , Richard Henderson Subject: [PATCH v7.2.3 12/30] target/arm: Define and use new load_cpu_field_low32() Date: Wed, 17 May 2023 12:10:24 +0300 Message-Id: <20230517091042.3626593-12-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 From: Peter Maydell In several places in the 32-bit Arm translate.c, we try to use load_cpu_field() to load from a CPUARMState field into a TCGv_i32 where the field is actually 64-bit. This works on little-endian hosts, but gives the wrong half of the register on big-endian. Add a new load_cpu_field_low32() which loads the low 32 bits of a 64-bit field into a TCGv_i32. The new macro includes a compile-time check against accidentally using it on a field of the wrong size. Use it to fix the two places in the code where we were using load_cpu_field() on a 64-bit field. This fixes a bug where on big-endian hosts the guest would crash after executing an ERET instruction, and a more corner case one where some UNDEFs for attempted accesses to MSR banked registers from Secure EL1 might go to the wrong EL. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20230424153909.1419369-2-peter.maydell@linaro.org (cherry picked from commit 7f3a3d3dc433dc06c0adb480729af80f9c8e3739) Signed-off-by: Michael Tokarev --- target/arm/translate-a32.h | 7 +++++++ target/arm/translate.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/target/arm/translate-a32.h b/target/arm/translate-a32.h index 5339c22f1e..99eea85fa8 100644 --- a/target/arm/translate-a32.h +++ b/target/arm/translate-a32.h @@ -61,6 +61,13 @@ static inline TCGv_i32 load_cpu_offset(int offset) #define load_cpu_field(name) load_cpu_offset(offsetof(CPUARMState, name)) +/* Load from the low half of a 64-bit field to a TCGv_i32 */ +#define load_cpu_field_low32(name) \ + ({ \ + QEMU_BUILD_BUG_ON(sizeof_field(CPUARMState, name) != 8); \ + load_cpu_offset(offsetoflow32(CPUARMState, name)); \ + }) + void store_cpu_offset(TCGv_i32 var, int offset, int size); #define store_cpu_field(var, name) \ diff --git a/target/arm/translate.c b/target/arm/translate.c index 1dcaefb8e7..a06da05640 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -2886,7 +2886,7 @@ static bool msr_banked_access_decode(DisasContext *s, int r, int sysm, int rn, if (arm_dc_feature(s, ARM_FEATURE_AARCH64) && dc_isar_feature(aa64_sel2, s)) { /* Target EL is EL<3 minus SCR_EL3.EEL2> */ - tcg_el = load_cpu_field(cp15.scr_el3); + tcg_el = load_cpu_field_low32(cp15.scr_el3); tcg_gen_sextract_i32(tcg_el, tcg_el, ctz32(SCR_EEL2), 1); tcg_gen_addi_i32(tcg_el, tcg_el, 3); } else { @@ -6558,7 +6558,7 @@ static bool trans_ERET(DisasContext *s, arg_ERET *a) } if (s->current_el == 2) { /* ERET from Hyp uses ELR_Hyp, not LR */ - tmp = load_cpu_field(elr_el[2]); + tmp = load_cpu_field_low32(elr_el[2]); } else { tmp = load_reg(s, 14); }