From patchwork Tue Dec 12 19:35:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 753121 Delivered-To: patch@linaro.org Received: by 2002:adf:e406:0:b0:336:3749:476e with SMTP id g6csp74352wrm; Tue, 12 Dec 2023 11:36:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHtqSL7xWxl3cqdN9Rq4tnME6LmfVRaat4J5XzvdBrrRzaLObmiEwtAyFJ8jRoQhIIpC1+1 X-Received: by 2002:a05:620a:371a:b0:778:9ae9:c1cd with SMTP id de26-20020a05620a371a00b007789ae9c1cdmr8556928qkb.77.1702409808958; Tue, 12 Dec 2023 11:36:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702409808; cv=none; d=google.com; s=arc-20160816; b=mMdglSGLzREeECdlbhQICrUT96Y8JTfmKEaDMV7/BsVovGOt3+Y/tMFZPPmpyS7mVu ytZ9TYOsfq0tsh1X9S10VHkzUMoUbr4RCs5R49A4YoN7iEMGiLZw7C/O7ddFiZVE2eOC i7SlCTc1IZJ+t1qsPPT+Rn9irjlnXvU0d7OBgf7t3/hpzDFsHfGLlbe3hqQMuH9lHY4D WkclPwUriRwXBVrfocZGEHQIfMG7G2xEhB8x9pEEsgK+HnHLHusjzgQplTh393aYzkgS 63pCLPVhelmuhYksyw2WuDOrsWYapsf3Ja9PSZVO8pJ0DYVrgVRUj9SABWiSMqtxczQv ZWqQ== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=/qtpDzmC2fPWyklxZL3CGK81+89kWbTA62dfbpXj/Vw=; fh=Vvliz9ENSk/yCY42nG87aL5dW+Zo0lduSx74U3lH2V8=; b=EeakmXYTqXYnwTuR3KG1yNUhp5WgTNWG4EQQbbBmE2Ia0pF+Y7O/S2E3fgDVROr+EL 182UZNGrwdkymkWtN8g8cFR0uAoU7n06L2SjKF4hkem08CkxDHr003Tg+Rf26+7HFJql 3VZ9TKK/zGfUoNobS2CS1dp9Hl9IrWGaAyFTJQrcYqKAxaHPoAXzNj0G5IrqpxcAHDPG NN2azuvsS6/AjbyWCzsQgAvUKDSABv+qHD4+TdRQpuQWFhj800WIMg+ofX7ooLnOXtAh BkASTmjTrrm8UYHL+WMXObXJXqjc6sFS3bzYw1irMz8xiJe+GyZEBLD0bFRP/kvqc+o4 rWpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bVxNW40A; 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 a6-20020a05620a438600b007759f94727asi11261708qkp.271.2023.12.12.11.36.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Dec 2023 11:36:48 -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=bVxNW40A; 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 1rD8Xo-0000rk-Oi; Tue, 12 Dec 2023 14:35:52 -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 1rD8Xm-0000qR-SO for qemu-devel@nongnu.org; Tue, 12 Dec 2023 14:35:50 -0500 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rD8Xh-00067j-PQ for qemu-devel@nongnu.org; Tue, 12 Dec 2023 14:35:50 -0500 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5c68da9d639so3474099a12.3 for ; Tue, 12 Dec 2023 11:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702409744; x=1703014544; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=/qtpDzmC2fPWyklxZL3CGK81+89kWbTA62dfbpXj/Vw=; b=bVxNW40ALTm8Y3NvR+a/KKBApd4H9VvodffBEyWrmtMzw0DriD1iCUb61Ijbb0pH/1 Kl+I/tFc8NNsHKYdpoLsDsqwugi2f2n57mLW1rmO1OfbE6ndpUPkFkCo4SSok1gaPN7t 62Sje6kqAr8zIrKh9IKXRIaG8nN5QTFvYNQ6iEJ0sKf1x/kC5KLFvnxl2mbm8XoQoxzZ X9DaDmAbsT/R+bYamIRHz3C83XLy75jRg9GZUl4TQnmHgRPEdEe02WhRuNPiTL228Xnn wFLZvawFJfAhOL3ni+2uAmmAFrGuIQCoyq47CWcUw8/FfTYUE4PPlfs9Ib+awWDdkKuT sVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702409744; x=1703014544; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/qtpDzmC2fPWyklxZL3CGK81+89kWbTA62dfbpXj/Vw=; b=XfaZETROgcYJOacP/XJe6194Zjhx8JoqLw08cutCMHLnkN2PqnTmV2/4VeJfU9FqBr dGPsGjuxbv2fOCnllT8+JmlL8UZ6eLZE3EPr5L4uO1M7KDnOgojs8a4bJug/VtQ/rDVd 2K3X5h06vvk9PHvmv8Dqzo/kWZXMV/wa71uMOR8LKnInkz/Lohq2kboOstV6WXeD+b4V sQc41HZfgedF2gzyulgdtJY/W+xoIgyklztXCdS5XJNPNTRMj8BHs7l4gvBWAkRS9A+G Q29Lia+XOoENKbeDXGgA1NJY65qk/4biecU+Q28sbiPL5Iu73/IkQrVIKmhq0yxanIov LSbg== X-Gm-Message-State: AOJu0Yxezs5Tj0EFwIImGEmzlbsbFcvUbPhmOUN57B0j7n8ekDWU9Fe2 Qae8TnMAqFJbSq8jd1gEHm0W1gyLCySxYqSOgs9DQg== X-Received: by 2002:a05:6a20:f397:b0:18f:c875:6b3b with SMTP id qr23-20020a056a20f39700b0018fc8756b3bmr3559231pzb.100.1702409743969; Tue, 12 Dec 2023 11:35:43 -0800 (PST) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id x6-20020aa784c6000000b006c8b14f3f0asm8495582pfn.117.2023.12.12.11.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:35:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH] tcg: Reduce serial context atomicity earlier Date: Tue, 12 Dec 2023 11:35:42 -0800 Message-Id: <20231212193542.149117-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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 Reduce atomicity while emitting opcodes, instead of later during code generation. This ensures that any helper called also sees the reduced atomicity requirement. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2034 Signed-off-by: Richard Henderson Tested-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- tcg/tcg-op-ldst.c | 28 ++++++++++++++++++++++++---- tcg/tcg.c | 9 +-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tcg/tcg-op-ldst.c b/tcg/tcg-op-ldst.c index e2c55df217..f11043b449 100644 --- a/tcg/tcg-op-ldst.c +++ b/tcg/tcg-op-ldst.c @@ -77,6 +77,13 @@ static MemOp tcg_canonicalize_memop(MemOp op, bool is64, bool st) if (st) { op &= ~MO_SIGN; } + + /* In serial mode, reduce atomicity. */ + if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) { + op &= ~MO_ATOM_MASK; + op |= MO_ATOM_NONE; + } + return op; } @@ -428,8 +435,7 @@ static bool use_two_i64_for_i128(MemOp mop) case MO_ATOM_SUBALIGN: case MO_ATOM_WITHIN16: case MO_ATOM_WITHIN16_PAIR: - /* In a serialized context, no atomicity is required. */ - return !(tcg_ctx->gen_tb->cflags & CF_PARALLEL); + return false; default: g_assert_not_reached(); } @@ -499,13 +505,20 @@ static void maybe_free_addr64(TCGv_i64 a64) static void tcg_gen_qemu_ld_i128_int(TCGv_i128 val, TCGTemp *addr, TCGArg idx, MemOp memop) { - const MemOpIdx orig_oi = make_memop_idx(memop, idx); + MemOpIdx orig_oi; TCGv_i64 ext_addr = NULL; TCGOpcode opc; check_max_alignment(get_alignment_bits(memop)); tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); + /* In serial mode, reduce atomicity. */ + if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) { + memop &= ~MO_ATOM_MASK; + memop |= MO_ATOM_NONE; + } + orig_oi = make_memop_idx(memop, idx); + /* TODO: For now, force 32-bit hosts to use the helper. */ if (TCG_TARGET_HAS_qemu_ldst_i128 && TCG_TARGET_REG_BITS == 64) { TCGv_i64 lo, hi; @@ -608,13 +621,20 @@ void tcg_gen_qemu_ld_i128_chk(TCGv_i128 val, TCGTemp *addr, TCGArg idx, static void tcg_gen_qemu_st_i128_int(TCGv_i128 val, TCGTemp *addr, TCGArg idx, MemOp memop) { - const MemOpIdx orig_oi = make_memop_idx(memop, idx); + MemOpIdx orig_oi; TCGv_i64 ext_addr = NULL; TCGOpcode opc; check_max_alignment(get_alignment_bits(memop)); tcg_gen_req_mo(TCG_MO_ST_LD | TCG_MO_ST_ST); + /* In serial mode, reduce atomicity. */ + if (!(tcg_ctx->gen_tb->cflags & CF_PARALLEL)) { + memop &= ~MO_ATOM_MASK; + memop |= MO_ATOM_NONE; + } + orig_oi = make_memop_idx(memop, idx); + /* TODO: For now, force 32-bit hosts to use the helper. */ if (TCG_TARGET_HAS_qemu_ldst_i128 && TCG_TARGET_REG_BITS == 64) { diff --git a/tcg/tcg.c b/tcg/tcg.c index d2ea22b397..896a36caeb 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -5440,15 +5440,8 @@ static TCGAtomAlign atom_and_align_for_opc(TCGContext *s, MemOp opc, MemOp align = get_alignment_bits(opc); MemOp size = opc & MO_SIZE; MemOp half = size ? size - 1 : 0; + MemOp atom = opc & MO_ATOM_MASK; MemOp atmax; - MemOp atom; - - /* When serialized, no further atomicity required. */ - if (s->gen_tb->cflags & CF_PARALLEL) { - atom = opc & MO_ATOM_MASK; - } else { - atom = MO_ATOM_NONE; - } switch (atom) { case MO_ATOM_NONE: