From patchwork Thu Apr 7 15:53:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sergey.fedorov@linaro.org X-Patchwork-Id: 8774341 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 C199EC0553 for ; Thu, 7 Apr 2016 15:59:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B4AB2017D for ; Thu, 7 Apr 2016 15:59:13 +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 5CED42010B for ; Thu, 7 Apr 2016 15:59:12 +0000 (UTC) Received: from localhost ([::1]:50852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCKt-0000Dq-Ie for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 11:59:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCH2-0001PY-44 for qemu-devel@nongnu.org; Thu, 07 Apr 2016 11:55:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoCGz-0002tZ-4w for qemu-devel@nongnu.org; Thu, 07 Apr 2016 11:55:12 -0400 Received: from mail-lb0-x236.google.com ([2a00:1450:4010:c04::236]:36549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoCGy-0002sA-UI for qemu-devel@nongnu.org; Thu, 07 Apr 2016 11:55:09 -0400 Received: by mail-lb0-x236.google.com with SMTP id bk9so25579527lbc.3 for ; Thu, 07 Apr 2016 08:55:08 -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=v0rCcQDDjsSRyDe1Rc/IdlqxcSxVrWKrC9sl3btWlio=; b=XIHfjwzNeTrmIySDZtLRWLB3OLUGJ6yyLnZzXIAkCnofZusLm+IPKTB/gVmIZOtfWK BMT4Kp57cH98c/UyQc6vxsUi8ndkaQ55STuNuJkz/IvPbCvBNFAcTIKhpHN0qRT5DLer 8smyvy1FlLD82AciYcM+/7Kf/RSBz1O5YP8Y4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v0rCcQDDjsSRyDe1Rc/IdlqxcSxVrWKrC9sl3btWlio=; b=DxDUtolQgUowiKCiFb2WeB+VkvE4JyIFVqyb/ivb9apixnRg2JohXDg9xVBFeuWB2q L28IcUD1LuVgo/kOW/Ly5xKWcHiqvnZZKajSBJIPGh+89O78oIluyUHb9xjN38Mgq8JQ 6g5BbuRNk6I4GFZlWge1Ps1IMItUlc9lRQtTthiWwU2kBzhsq87aEdah4fbryjC9k2Xx PHnodiJSyxWek0ftAHXqqBdPoUWob/hxxmtNNAKeTCG9W+5J6d1sIh1ooh8GoUR5xvzI R04PtU/wnvKWu+s7D9oJskVG4ltyUpeb43zsJxzxw59CotnrdNa0vGuQNdzVNcp8/o7l 0bxA== X-Gm-Message-State: AD7BkJIsjS1F/turhnU3vnhtyL2J4md7x+SRgJP79Cbn37pM8k9DoJym868oeepwb1Hx1j63 X-Received: by 10.112.137.41 with SMTP id qf9mr1706922lbb.140.1460044506768; Thu, 07 Apr 2016 08:55:06 -0700 (PDT) Received: from localhost.localdomain ([195.91.132.170]) by smtp.gmail.com with ESMTPSA id p195sm1316255lfd.11.2016.04.07.08.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Apr 2016 08:55:06 -0700 (PDT) From: Sergey Fedorov To: qemu-devel@nongnu.org Date: Thu, 7 Apr 2016 18:53:50 +0300 Message-Id: <1460044433-19282-9-git-send-email-sergey.fedorov@linaro.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1460044433-19282-1-git-send-email-sergey.fedorov@linaro.org> References: <1460044433-19282-1-git-send-email-sergey.fedorov@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c04::236 Cc: Sergey Fedorov , Peter Crosthwaite , Claudio Fontana , qemu-arm@nongnu.org, Paolo Bonzini , Sergey Fedorov , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [Qemu-devel] [PATCH 08/11] tcg/aarch64: Make direct jump patching thread-safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org 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 Reviewed-by: Alex Bennée --- 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 0ed10a974121..15fdebec921f 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; + 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); }