From patchwork Mon May 12 23:30:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 29998 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f200.google.com (mail-ie0-f200.google.com [209.85.223.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5C1A8203F3 for ; Mon, 12 May 2014 23:35:22 +0000 (UTC) Received: by mail-ie0-f200.google.com with SMTP id rd18sf19342567iec.7 for ; Mon, 12 May 2014 16:35:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=dd81uf89a+TjzCzRDEQzzUO6buIX4H/sHflcCD9eHIw=; b=T1N+jfkynrOnv5pAirHsVF0DvacSogokFFOf/ooyd2gn/nJNxzi/9er7B5xylvIcEI siE4jp02YYmgQ0L1dWtp8YT9c1LuLaYgx+ASFhTI45r6wD1dOBvbweSb9jZ0fPN+1shr SgQcg/lSYR0Y8M8LdiVliGTswIR1HXSw8M6tLxLyaF27juETueKQ2Zt3P/HTvY/t0Zlu px+iMyJ4Ltr9Ux3PBujqoyQaj83F/Nu28py5PIRgHXGKZeV127fInk3IBIq3PdGFO7IE hTXQmMLHC9u3uyHvcux17nJbOEJmB1DVYdpE+4AOj3Sq5UcqQgH7uJCZEsCqsBXjCGWB hEgQ== X-Gm-Message-State: ALoCoQm8u3o2tugZp1TSj2uiGoub/4keGc/izDxGr0u+7lD+0yw9PU46h41dAU6OrTwqBljmomj2 X-Received: by 10.42.206.77 with SMTP id ft13mr13287178icb.22.1399937721641; Mon, 12 May 2014 16:35:21 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.164 with SMTP id r33ls1672409qgr.2.gmail; Mon, 12 May 2014 16:35:21 -0700 (PDT) X-Received: by 10.52.0.193 with SMTP id 1mr21462982vdg.0.1399937721472; Mon, 12 May 2014 16:35:21 -0700 (PDT) Received: from mail-ve0-x233.google.com (mail-ve0-x233.google.com [2607:f8b0:400c:c01::233]) by mx.google.com with ESMTPS id s7si2336218vev.2.2014.05.12.16.35.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 16:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::233 as permitted sender) client-ip=2607:f8b0:400c:c01::233; Received: by mail-ve0-f179.google.com with SMTP id oy12so9653829veb.38 for ; Mon, 12 May 2014 16:35:21 -0700 (PDT) X-Received: by 10.58.123.71 with SMTP id ly7mr25579701veb.11.1399937721308; Mon, 12 May 2014 16:35:21 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp106502vcb; Mon, 12 May 2014 16:35:20 -0700 (PDT) X-Received: by 10.140.93.198 with SMTP id d64mr40607617qge.1.1399937720201; Mon, 12 May 2014 16:35:20 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p5si5243757qcn.8.2014.05.12.16.35.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 May 2014 16:35:20 -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; Received: from localhost ([::1]:40594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wjzkb-0007lz-9i for patch@linaro.org; Mon, 12 May 2014 19:35:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59101) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjzhJ-0004Ys-Ei for qemu-devel@nongnu.org; Mon, 12 May 2014 19:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WjzhE-0005lY-D0 for qemu-devel@nongnu.org; Mon, 12 May 2014 19:31:53 -0400 Received: from mail-qa0-x22b.google.com ([2607:f8b0:400d:c00::22b]:48742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WjzhE-0005lS-93 for qemu-devel@nongnu.org; Mon, 12 May 2014 19:31:48 -0400 Received: by mail-qa0-f43.google.com with SMTP id m5so7948447qaj.30 for ; Mon, 12 May 2014 16:31:47 -0700 (PDT) X-Received: by 10.224.151.82 with SMTP id b18mr42846690qaw.27.1399937507870; Mon, 12 May 2014 16:31:47 -0700 (PDT) Received: from anchor.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id m7sm23815931qae.35.2014.05.12.16.31.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 May 2014 16:31:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 12 May 2014 16:30:49 -0700 Message-Id: <1399937474-6530-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1399937474-6530-1-git-send-email-rth@twiddle.net> References: <1399937474-6530-1-git-send-email-rth@twiddle.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::22b Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PULL 01/26] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Original-Sender: rth@twiddle.net X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::233 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=fail header.i=@gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell The code which patches x86 jump instructions assumes it can do an unaligned write of a uint32_t. This is actually safe on x86, but it's still undefined behaviour. We have infrastructure for doing efficient unaligned accesses which doesn't engage in undefined behaviour, so use it. This is technically fractionally less efficient, at least with gcc 4.6; instead of one instruction: 7b2: 89 3e mov %edi,(%rsi) we get an extra spurious store to the stack slot: 7b2: 89 7c 24 64 mov %edi,0x64(%rsp) 7b6: 89 3e mov %edi,(%rsi) Reviewed-by: Alex Bennée Signed-off-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index f9ac332..1c49a21 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -229,7 +229,7 @@ void ppc_tb_set_jmp_target(unsigned long jmp_addr, unsigned long addr); static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) { /* patch the branch destination */ - *(uint32_t *)jmp_addr = addr - (jmp_addr + 4); + stl_p((void*)jmp_addr, addr - (jmp_addr + 4)); /* no need to flush icache explicitly */ } #elif defined(__aarch64__)