From patchwork Fri Mar 7 15:07:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 871193 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp809949wri; Fri, 7 Mar 2025 07:10:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVC2sxt3LkKA1ejMY7DqNDwUsJEk/wnIfSt1MAPHe8i2JlRbmi8/t7vB5+IyH2RcUqbaXiQLA==@linaro.org X-Google-Smtp-Source: AGHT+IFru3EmTXL1krkTKcEOFNYRqBZAyKvZhHMgXv8B54QmhwdOxoSn/hes3/lZRb6cSwOd53Z5 X-Received: by 2002:ac8:59d0:0:b0:471:ef27:a313 with SMTP id d75a77b69052e-476109bbc16mr52179201cf.23.1741360237195; Fri, 07 Mar 2025 07:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741360237; cv=none; d=google.com; s=arc-20240605; b=OiozBIvQTkj3wl1tr5pE4W7+jF1/OtHH/jV+/NF3x51JDSRNbzPm++98SXqT0tPcmt vKsTIp3QxjbijNsFpujBqiEefnS4/hI5scGDx+dAuKw1+xsfcOPQ1OCsm+OvH0WBC+69 4yujuYc/nq2k6KDNkeF7bJdqL/KubqswCjcMVRbabLRcvhXW3y63u6JXRPnRLCNgo+O4 jRq3tOlyr6ErGNwYngigRaG4U/q0ovOjFkdeNoC+dB/+4r/lxSf4Tg7uuRuTVasNPa0a TOHKmgNJkjieEEJTNgESbcMiu4uAOA2tZwuDjTjf3jGbnVa0y9icg6H+BnZisfWtOSM8 JF7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:to:from :dkim-signature; bh=saDmTi5qBVoivSppj4pMAPptghWgJB1RwsIGgVuCH9w=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=P1ZtoXowX7rY6SkK1km0c5j82KbZOML1WwqKCBdj1Y4I3wNHbWT+eJ/0n9i18FCNBB BJw1FdeXN7pq18Jhrtc7CL1DhfRjCXaRBh9peg227IZoSWX1oOzkhOw8W62rxydUsTSs EczfQE9P53dqNRpCQpPyk5Bj7QNILKfzfvo8FlTmiEZctzg1sPDIHOttvEjYEMHCh5H6 o4pmnzaafruHe12yb4ZOGk9+UoPUw/TPwGJBZb8VTB0rxs/pvJpIvuQKq1B3F5bXAB8a I7aLKBQpb3gqR0d3K8PKL8vpGZOIM89Ur9tCQ0pTV/iSKxEwnP3yOf+Vgmb0aZL1vy90 yOkw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xa6cvBcf; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4751d983754si36621631cf.115.2025.03.07.07.10.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 07:10:37 -0800 (PST) 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=xa6cvBcf; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tqZIW-00013Q-SS; Fri, 07 Mar 2025 10:07:36 -0500 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 1tqZIS-00010k-Po for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:32 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqZIQ-0008Jv-Sh for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:32 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-390effd3e85so1772573f8f.0 for ; Fri, 07 Mar 2025 07:07:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741360049; x=1741964849; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=saDmTi5qBVoivSppj4pMAPptghWgJB1RwsIGgVuCH9w=; b=xa6cvBcf72XiZXwn2004RbZmRnn2fp6RbDCQzLNp/uC9DAGuLGAVUZe8MzqX6gq5Hb s4nvJQ609Um4KfTIF7Ym3m3QkmelHVaCrFllMgzNIMEWuEB+/QhG8hBqmiNzS7jaBVe5 dZoWAeFKoVJp2lwgcC+qpPnBIxOyju0iIFd0P7dt6yLp9y/+RjmZWwp0doDEPB9nwBjU 1GR3MBI5lswZ3SkRiAVGaG4KyEBOsDMIiIlEtY54cJhsh6B21XDv5KDhXITdM44nG1GV DyP4oz9gcLFSAGskQnO66Qtqm+74EJgicvitocsvdYEquzmHooaqPj5N6zGNB8u4xTwz 5azw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741360049; x=1741964849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=saDmTi5qBVoivSppj4pMAPptghWgJB1RwsIGgVuCH9w=; b=OR31881FQ0Q+OrztEDywNo7vm80vBpIa21kn75tCGSQYb0Sm/0vA4zijSG2E8BvWfX nK9q54ArJhHhjY+AaLxtTkiz2gMSPzWc1Npe0FrxFVSmWGWsbsdU3ABcVDN3Nv2UyoYQ wOfQeFFiflIzyjZ9OPDhqJIyhYrZBz8WJN8nNfdcCLYsDda9VbD0hUDQ7+e9i/6Y17Mx IlRFjrOpAsJTT8qfiR9pcuNKKc8GJeqr7qY0LNpa2hXgLhAdFhaGIRhX3+HRKtqPNvmY BJWsrwZKgMlZIWXgu3tEHTVqqnxmxfpjZNT3GOu+o8XkezRTGKe908MWOlcSZywKqh3Z ry3g== X-Gm-Message-State: AOJu0YwAzpWd4bR/hiWKbqnyFob9qWCN2jw8/1+A4rfm8iSkxjNfHTqj uy4DCgTrx10TeNx5tyI3zr6IHO712iUZpnf5k4esD9oTGrV7GxbDljWDwtrdUz8me5/s1zSvv6a K X-Gm-Gg: ASbGncs1q5e4Hm8nwABFtNvd9IUB83rNfD5bb0cbrALCX25YzrKqouRQwoDU2zp7uW8 oHPmG0/IjoJASI/cPgs9u/pQaYP3up1jSzbgSQIQ5jxqYdQaBfDjFsk/SRhq4RzthCYR5MxRnrB /+HIM2pPcIOJItww/Vj4RUpXPnaq4uWUGCCNKK92i8H0wZsfk6oKDKwTVUIzMXzHJ2wx5JOwas1 1g/dAtm2x1SgB+OsCeUdxfcBxJ/LTKARnwTM5J/Imf56poTosUAG4eDfLka3WHfZlgQ1KgGe3WK Cyi6vmZvzURdIZykPA1OIp6l8xrWKI1Jr9pfDC72/5VUcYoZz7g= X-Received: by 2002:a05:6000:1862:b0:390:fe4b:70b9 with SMTP id ffacd0b85a97d-39132d6c5demr3031096f8f.21.1741360047696; Fri, 07 Mar 2025 07:07:27 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c1031fdsm5443627f8f.89.2025.03.07.07.07.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 07:07:27 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 14/21] target/arm: Correct STRD atomicity Date: Fri, 7 Mar 2025 15:07:01 +0000 Message-ID: <20250307150708.3222813-15-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307150708.3222813-1-peter.maydell@linaro.org> References: <20250307150708.3222813-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.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 Our STRD implementation doesn't correctly implement the requirement: * if the address is 8-aligned the access must be a 64-bit single-copy atomic access, not two 32-bit accesses Rewrite the handling of STRD to use a single tcg_gen_qemu_st_i64() of a value produced by concatenating the two 32 bit source registers. This allows us to get the atomicity right. As with the LDRD change, now that we don't update 'addr' in the course of performing the store we need to adjust the offset we pass to op_addr_ri_post() and op_addr_rr_post(). Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20250227142746.1698904-3-peter.maydell@linaro.org --- target/arm/tcg/translate.c | 59 +++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c index 93772da39a4..404a254678a 100644 --- a/target/arm/tcg/translate.c +++ b/target/arm/tcg/translate.c @@ -5063,10 +5063,42 @@ static bool trans_LDRD_rr(DisasContext *s, arg_ldst_rr *a) return true; } +static void do_strd_store(DisasContext *s, TCGv_i32 addr, int rt, int rt2) +{ + /* + * STRD is required to be an atomic 64-bit access if the + * address is 8-aligned, two atomic 32-bit accesses if + * it's only 4-aligned, and to give an alignment fault + * if it's not 4-aligned. + * Rt is always the word from the lower address, and Rt2 the + * data from the higher address, regardless of endianness. + * So (like gen_store_exclusive) we avoid gen_aa32_ld_i64() + * so we don't get its SCTLR_B check, and instead do a 64-bit access + * using MO_BE if appropriate, using a value constructed + * by putting the two halves together in the right order. + * + * As with LDRD, the 64-bit atomicity is not required for + * M-profile, or for A-profile before LPAE, and we provide + * the higher guarantee always for simplicity. + */ + int mem_idx = get_mem_index(s); + MemOp opc = MO_64 | MO_ALIGN_4 | MO_ATOM_SUBALIGN | s->be_data; + TCGv taddr = gen_aa32_addr(s, addr, opc); + TCGv_i32 t1 = load_reg(s, rt); + TCGv_i32 t2 = load_reg(s, rt2); + TCGv_i64 t64 = tcg_temp_new_i64(); + + if (s->be_data == MO_BE) { + tcg_gen_concat_i32_i64(t64, t2, t1); + } else { + tcg_gen_concat_i32_i64(t64, t1, t2); + } + tcg_gen_qemu_st_i64(t64, taddr, mem_idx, opc); +} + static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) { - int mem_idx = get_mem_index(s); - TCGv_i32 addr, tmp; + TCGv_i32 addr; if (!ENABLE_ARCH_5TE) { return false; @@ -5077,15 +5109,9 @@ static bool trans_STRD_rr(DisasContext *s, arg_ldst_rr *a) } addr = op_addr_rr_pre(s, a); - tmp = load_reg(s, a->rt); - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); + do_strd_store(s, addr, a->rt, a->rt + 1); - tcg_gen_addi_i32(addr, addr, 4); - - tmp = load_reg(s, a->rt + 1); - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); - - op_addr_rr_post(s, a, addr, -4); + op_addr_rr_post(s, a, addr, 0); return true; } @@ -5213,20 +5239,13 @@ static bool trans_LDRD_ri_t32(DisasContext *s, arg_ldst_ri2 *a) static bool op_strd_ri(DisasContext *s, arg_ldst_ri *a, int rt2) { - int mem_idx = get_mem_index(s); - TCGv_i32 addr, tmp; + TCGv_i32 addr; addr = op_addr_ri_pre(s, a); - tmp = load_reg(s, a->rt); - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); + do_strd_store(s, addr, a->rt, rt2); - tcg_gen_addi_i32(addr, addr, 4); - - tmp = load_reg(s, rt2); - gen_aa32_st_i32(s, tmp, addr, mem_idx, MO_UL | MO_ALIGN); - - op_addr_ri_post(s, a, addr, -4); + op_addr_ri_post(s, a, addr, 0); return true; }