From patchwork Fri May 13 00:13:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9087051 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4A177BF29F for ; Fri, 13 May 2016 00:21:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A238F20204 for ; Fri, 13 May 2016 00:21:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECF48200D0 for ; Fri, 13 May 2016 00:21:27 +0000 (UTC) Received: from localhost ([::1]:60359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10r8-0003qr-9f for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 20:21:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10kg-0000Yq-Aj for qemu-devel@nongnu.org; Thu, 12 May 2016 20:14:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b10kb-0002jP-EF for qemu-devel@nongnu.org; Thu, 12 May 2016 20:14:46 -0400 Received: from mail-qg0-x242.google.com ([2607:f8b0:400d:c04::242]:33284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b10kb-0002jD-Av for qemu-devel@nongnu.org; Thu, 12 May 2016 20:14:41 -0400 Received: by mail-qg0-x242.google.com with SMTP id 90so6865545qgz.0 for ; Thu, 12 May 2016 17:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2UB2HXISnbqCekXD7f0j/0vldWgUB4bcQI7wLyGiK+w=; b=tKBQ/lUCWe+Pjq7DnVHyH3w5mR5l+qwsquXchtNYTS2wQTrNc7+qe/j+9MnDRu7Xn4 QvKPFJigr/AufjI2yt5vk+E+Anrl+ChwcrQVJFGh5Hdj8mIog3FEf8PpeTSOaK4HTFc1 wj6X+aX1HuqwjYN4ZFamHg4yITJQo+2ouIGjHP2E/F/F9gKnbBviypc6tX5lNcftC+us 8MEOASfwR2OUprHkUfDcNa0IaFtJ6x8OUUSgaOnTQCjK+vdUoISnqiAuhHnRMGXWvlr8 6btgvzk9LkHiCV3tycnEIR9qeR+RL7GjodlzCo88jq2xoRGtr/pYZpZyoVBxlbi7Nd2s ZnYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2UB2HXISnbqCekXD7f0j/0vldWgUB4bcQI7wLyGiK+w=; b=AZXBkYifFyW9RfaUN5bpkvRkIiTQnYJJMKkIWhlwRzx9km1RPZs5qLp4KtCdtW7MMI PVa+5RP5oHTwmUdfa59viU4Kioa8cp07/WTtqVydAkiNumE8psayukjXqYRjGX9QKrdl MdiiQfeiHOLNqtAiEnB4SgBrQyloHH2QIj28ZeMJT6tAjaSW9UwuNAuwSd2elUNDpM+l QzDS5tYVtDQpJimooDif2itYuWlI4eHN02wsi0Y5+hZ5hrUBmiZAB+a5M2BlYDMGLUqJ ILirWo3tgZJCCjB8UMv6KCoM4dprBKdZ+tb5cEV8S0Y7zDcJZLlJyKylnlCchWUZr2Ye Z5Cw== X-Gm-Message-State: AOPr4FWmqJ/++MqjO4SLVTYWR6WqBwCEF1Bw8S+tqu9ohYzJ1Cy/JgZJcofOsuKOIKc2/Q== X-Received: by 10.140.91.194 with SMTP id z60mr12570823qgd.70.1463098481112; Thu, 12 May 2016 17:14:41 -0700 (PDT) Received: from bigtime.com ([172.56.44.137]) by smtp.gmail.com with ESMTPSA id w16sm7171321qka.35.2016.05.12.17.14.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 17:14:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 12 May 2016 14:13:10 -1000 Message-Id: <1463098420-29113-10-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1463098420-29113-1-git-send-email-rth@twiddle.net> References: <1463098420-29113-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::242 Subject: [Qemu-devel] [PULL 09/39] tcg/aarch64: Make direct jump patching thread-safe 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, Sergey Fedorov , Sergey Fedorov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sergey Fedorov Ensure direct jump patching in AArch64 is atomic by using atomic_read()/atomic_set() for code patching. Signed-off-by: Sergey Fedorov Signed-off-by: Sergey Fedorov Message-Id: <1461341333-19646-9-git-send-email-sergey.fedorov@linaro.org> Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.inc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index a8fb442..88183c8 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -73,6 +73,18 @@ static inline void reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target) *code_ptr = deposit32(*code_ptr, 0, 26, offset); } +static inline void reloc_pc26_atomic(tcg_insn_unit *code_ptr, + tcg_insn_unit *target) +{ + ptrdiff_t offset = target - code_ptr; + tcg_insn_unit insn; + tcg_debug_assert(offset == sextract64(offset, 0, 26)); + /* read instruction, mask away previous PC_REL26 parameter contents, + set the proper offset, then write back the instruction. */ + insn = atomic_read(code_ptr); + atomic_set(code_ptr, deposit32(insn, 0, 26, offset)); +} + static inline void reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = target - code_ptr; @@ -835,7 +847,7 @@ void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) tcg_insn_unit *code_ptr = (tcg_insn_unit *)jmp_addr; tcg_insn_unit *target = (tcg_insn_unit *)addr; - reloc_pc26(code_ptr, target); + reloc_pc26_atomic(code_ptr, target); flush_icache_range(jmp_addr, jmp_addr + 4); }