From patchwork Wed Sep 6 14:49:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111783 Delivered-To: patch@linaro.org Received: by 10.140.94.166 with SMTP id g35csp994378qge; Wed, 6 Sep 2017 07:52:00 -0700 (PDT) X-Received: by 10.28.137.19 with SMTP id l19mr12095wmd.98.1504709520764; Wed, 06 Sep 2017 07:52:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504709520; cv=none; d=google.com; s=arc-20160816; b=snJmoCRZhsJ6frNswIdIdtL1Jifx6EqqZMcmt1VtqEVXG2A4cIQ5Af1/bhss3jRygH nVeVO7YMnfTfgc0IBPbh62nAmWCexR+XHoMwvLjxK2AOv9ov8/cuYYO7hiqLzBabFHXJ exMNkV91IwfRFCF+mdn5TFhjfB4EYvwi1ixbqKbWNRaNkllHnahA62CAdE910clh4hCb y0tJP0RofiyO+JpoUC+OPmQoKTm78qzKyuS9wDRxz+IK7ktj+JepInz+lK6M0jHXuZz5 +OuOQgWY4qEyKJWXQnHBcnVpeeYJp2M7xj/40ON939tzFs4XHvtuIuUpLZU1KUhBZDgx 2khg== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=RK/3SaYDnTtoPHuQstqpOcx+UbVMkRmtrESkuekKT5w=; b=QdPC+adohN9qi6DsFNT2JOxkwG7RUPrlvQIfLu3syQPUCyUGHiR1k4PDS2yjhjBCm2 q+HAmHH+clSNaFzmOFfj2TMOVZdJduWC+ok9rSEqXjxatfYYfDW6e14upIlamqjZGqw/ ExnzNs9ZajbSXQjwBz9aPq4asIFjkZh1eA2EZvRBfb3DDHMHJmurR1JHEDoVqP9rPdn5 jP6CsqWAA1ZwJdJtsfS/DvR/qG32gB7ko0wWNeAE6Ncm8yxG85RcbHFlKJvBD1UnHyZn mR04BKFHD1b/OQDGvtyGHdskxfq4J63gMQFAwAkKYsaU7215TqM7N+jhfRC7VIMVPhDz CEsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=atvvmcMz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g33si1634wrd.450.2017.09.06.07.52.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 06 Sep 2017 07:52:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=atvvmcMz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpbgN-0006cH-KP for patch@linaro.org; Wed, 06 Sep 2017 10:51:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpbeH-0005Nx-M8 for qemu-devel@nongnu.org; Wed, 06 Sep 2017 10:49:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpbeG-0000AL-IP for qemu-devel@nongnu.org; Wed, 06 Sep 2017 10:49:49 -0400 Received: from mail-pf0-x22d.google.com ([2607:f8b0:400e:c00::22d]:33430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpbeG-00009w-Ca for qemu-devel@nongnu.org; Wed, 06 Sep 2017 10:49:48 -0400 Received: by mail-pf0-x22d.google.com with SMTP id y68so13174869pfd.0 for ; Wed, 06 Sep 2017 07:49:48 -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; bh=RK/3SaYDnTtoPHuQstqpOcx+UbVMkRmtrESkuekKT5w=; b=atvvmcMz2LAhNeuCrDFxOB/ZrYcYojkaIDWDaYpybGoHm8wRwOPV4ralVAWaXtWe+5 gitlPDXLfQF7zE7D/eTPpAfvH+kX+FNhPDbfUHffSQB3wt6ubi9T7NxoxgVQcczph6/m 4fW9OhdjEwmuGHjaZiTDNobnhT9HEGftk6vVw= 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; bh=RK/3SaYDnTtoPHuQstqpOcx+UbVMkRmtrESkuekKT5w=; b=dpKrdpz4zoQ8CIpaDH6TOr97hcx6aiPYt1w1xS8U+Nv9dSY6POWXgj+zeT7vkxk7ie AA1Yw2R4DilVXGf/IxISJOiYGmOjWYah542xFjUNWJ1ucphXCdFgnvoxF/Ka11TQplIU XHWXC/IbcrAHi0JmdFrPKWnRTGDhIhaQC/J5GQCmCm8FCuxBR8/1ZfxO9A3C949tgff8 lxVfZAn8ZspTneZvob/vkLzkK1o70wsB2nTgDWcXDRGFWlkJZNg3wqbz+tVPtciWom16 RD/ihHaMchultB1zAlWTSCkoH2oQPc+FDFkXMCTtGp2cV5BnsiCg2xxprqVnWLOH+Vy8 c4Rg== X-Gm-Message-State: AHPjjUhAYGAYvomAmYNqMm53FK4fFIabpXTpy3p/bygyp3KoRh86kDPP X3hT/kJKNO4H4oSejY2nhg== X-Google-Smtp-Source: ADKCNb7Ng5tqETixcAYxa9yKG23vqhjlgyp5/cn1ior8iRCMr7dxPcImKiBSsFBudQxdL1NKhlLKxQ== X-Received: by 10.98.27.73 with SMTP id b70mr7390084pfb.21.1504709386982; Wed, 06 Sep 2017 07:49:46 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h1sm3467646pfg.153.2017.09.06.07.49.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Sep 2017 07:49:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 07:49:29 -0700 Message-Id: <20170906144940.30880-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170906144940.30880-1-richard.henderson@linaro.org> References: <20170906144940.30880-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22d Subject: [Qemu-devel] [PULL 03/14] tcg: Implement implicit ordering semantics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Pranith Kumar Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Pranith Kumar Currently, we cannot use mttcg for running strong memory model guests on weak memory model hosts due to missing ordering semantics. We implicitly generate fence instructions for stronger guests if an ordering mismatch is detected. We generate fences only for the orders for which fence instructions are necessary, for example a fence is not necessary between a store and a subsequent load on x86 since its absence in the guest binary tells that ordering need not be ensured. Also note that if we find multiple subsequent fence instructions in the generated IR, we combine them in the TCG optimization pass. This patch allows us to boot an x86 guest on ARM64 hosts using mttcg. Signed-off-by: Pranith Kumar Message-Id: <20170829063313.10237-4-bobby.prani@gmail.com> Signed-off-by: Richard Henderson --- tcg/tcg-op.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.13.5 diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index 87f673ef49..688d91755b 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -28,6 +28,7 @@ #include "exec/exec-all.h" #include "tcg.h" #include "tcg-op.h" +#include "tcg-mo.h" #include "trace-tcg.h" #include "trace/mem.h" @@ -2662,8 +2663,20 @@ static void gen_ldst_i64(TCGOpcode opc, TCGv_i64 val, TCGv addr, #endif } +static void tcg_gen_req_mo(TCGBar type) +{ +#ifdef TCG_GUEST_DEFAULT_MO + type &= TCG_GUEST_DEFAULT_MO; +#endif + type &= ~TCG_TARGET_DEFAULT_MO; + if (type) { + tcg_gen_mb(type | TCG_BAR_SC); + } +} + void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); memop = tcg_canonicalize_memop(memop, 0, 0); trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env, addr, trace_mem_get_info(memop, 0)); @@ -2672,6 +2685,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); memop = tcg_canonicalize_memop(memop, 0, 1); trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env, addr, trace_mem_get_info(memop, 1)); @@ -2680,6 +2694,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + tcg_gen_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_ld_i32(TCGV_LOW(val), addr, idx, memop); if (memop & MO_SIGN) { @@ -2698,6 +2713,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) { + tcg_gen_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); if (TCG_TARGET_REG_BITS == 32 && (memop & MO_SIZE) < MO_64) { tcg_gen_qemu_st_i32(TCGV_LOW(val), addr, idx, memop); return;