From patchwork Sat Mar 29 00:27:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 27383 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2F52220062 for ; Sat, 29 Mar 2014 00:28:30 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf14048401pab.1 for ; Fri, 28 Mar 2014 17:28:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references: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; bh=uRZuPqiRxJ+etVoqCRYqffPZHz6NTRmLXaukMMUxT4w=; b=Lty3dS4Rstkd5M/MFc4qm2qaoq4WNBblom9dI0q36P8SDkSbcDmeL20KtmhpP/wgML C2Ke06N3DMTOisp7Y4YHf3+4sTPIiFe62BLureX9N3BjDMADKPVWt1FRkCNcF5MA90cU ZPgfv0hkTdjZ8AfH7rmnRauZt7v/Q3d4OOWDhtgLfhSfRHnbIpwyyxKoz81TgRmV1Kg9 AZVooilXq3d5Dz6QqcFAneWuVPQVxo8mQy6LXJKBxop2GI+8kbnIOwvdyFfCy6jszJWB oOblS7lMtFnYTATWt+Ndvf26qQwrrJCMRMxDtPMJuxU+hTVfa9vEzpMeEPCh1CoJA6Fn QLfQ== X-Gm-Message-State: ALoCoQlzYIZZ7JLK5OJebJoBNhS21RrUpICIyvoN4PGntXa2ODpyxSJAo025kLy8S+WWRwYPnJzf X-Received: by 10.66.122.69 with SMTP id lq5mr4445035pab.17.1396052909084; Fri, 28 Mar 2014 17:28:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.37.84 with SMTP id q78ls87613qgq.69.gmail; Fri, 28 Mar 2014 17:28:28 -0700 (PDT) X-Received: by 10.52.34.137 with SMTP id z9mr8035084vdi.12.1396052908947; Fri, 28 Mar 2014 17:28:28 -0700 (PDT) Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f]) by mx.google.com with ESMTPS id sc7si1590034vdc.13.2014.03.28.17.28.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 17:28:28 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22f; Received: by mail-ve0-f175.google.com with SMTP id oz11so6394552veb.34 for ; Fri, 28 Mar 2014 17:28:28 -0700 (PDT) X-Received: by 10.58.4.68 with SMTP id i4mr9871474vei.8.1396052908830; Fri, 28 Mar 2014 17:28:28 -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.12.8 with SMTP id v8csp48409vcv; Fri, 28 Mar 2014 17:28:28 -0700 (PDT) X-Received: by 10.140.91.105 with SMTP id y96mr12163666qgd.3.1396052908249; Fri, 28 Mar 2014 17:28:28 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f91si3279252qga.178.2014.03.28.17.28.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 28 Mar 2014 17:28:28 -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]:36560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTh8N-0007Up-MW for patch@linaro.org; Fri, 28 Mar 2014 20:28:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTh7Q-0006bW-Bu for qemu-devel@nongnu.org; Fri, 28 Mar 2014 20:27:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTh7L-0006hl-FJ for qemu-devel@nongnu.org; Fri, 28 Mar 2014 20:27:28 -0400 Received: from mail-qg0-x22f.google.com ([2607:f8b0:400d:c04::22f]:40417) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTh7L-0006hg-Ao for qemu-devel@nongnu.org; Fri, 28 Mar 2014 20:27:23 -0400 Received: by mail-qg0-f47.google.com with SMTP id 63so5180240qgz.34 for ; Fri, 28 Mar 2014 17:27:22 -0700 (PDT) X-Received: by 10.224.165.1 with SMTP id g1mr5713686qay.16.1396052842863; Fri, 28 Mar 2014 17:27:22 -0700 (PDT) Received: from pike.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPSA id x5sm13105906qaj.9.2014.03.28.17.27.21 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Mar 2014 17:27:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 28 Mar 2014 17:27:07 -0700 Message-Id: <1396052834-26834-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396052834-26834-1-git-send-email-rth@twiddle.net> References: <1396052834-26834-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::22f Cc: peter.maydell@linaro.org, aurelien@aurel32.net Subject: [Qemu-devel] [PATCH 1/8] 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=neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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) Signed-off-by: Peter Maydell Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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__)