From patchwork Fri Mar 28 15:29:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 27307 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qg0-f69.google.com (mail-qg0-f69.google.com [209.85.192.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D88D20545 for ; Fri, 28 Mar 2014 15:29:51 +0000 (UTC) Received: by mail-qg0-f69.google.com with SMTP id a108sf6026014qge.4 for ; Fri, 28 Mar 2014 08:29:51 -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:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=mKhvWl2v9MtAbDjD1id91rJYErgTGyVbfMmPB24I+GY=; b=PrqUS/9giw7dmRb3bGmkATeG88zxt1z1WSfCJcE2UzfVCefHbauL9xDlqYY2/KAb2z 4KZ4LevOT/bNcrvIfXKewJeQfqMz7Yr8hcdMrrAVMbQIXSevZSMKr0nB2fANjs79TZyI V8rG5ZK/cCrmBZBB4LOuEtd6hKivxN1OCOIDLPf5a2sASgSWQ9eFPrsebxFYUiLTm0wd limo0zG8p3CmzXZgOIv3Zzt+JVyeApkK1MAE3YlBwerp7jtD6TLw+q43Qi5caQkK64O9 kIzHzDPUS6qoq35nIFdLgzh4R2LLnA+h+vX5S4oFZx3IqieyGH04qqZSywCupiW3vlgp l1RA== X-Gm-Message-State: ALoCoQlOH2w5pv2khaFGQq+scjvjlOyA1fcJPODcN5FhzcFgCDPhAZlspQRfCC/GoTqvfbEqI6HH X-Received: by 10.236.70.202 with SMTP id p50mr2854835yhd.18.1396020591818; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.163 with SMTP id b32ls1270989qge.22.gmail; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) X-Received: by 10.58.57.42 with SMTP id f10mr7761879veq.1.1396020591685; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id tv3si1298877vdc.108.2014.03.28.08.29.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 08:29:51 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id oy12so5797205veb.4 for ; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) X-Received: by 10.52.6.162 with SMTP id c2mr6472604vda.6.1396020591558; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.12.8 with SMTP id v8csp17446vcv; Fri, 28 Mar 2014 08:29:51 -0700 (PDT) X-Received: by 10.180.73.173 with SMTP id m13mr48706713wiv.52.1396020590783; Fri, 28 Mar 2014 08:29:50 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id p14si2381756wie.124.2014.03.28.08.29.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Mar 2014 08:29:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WTYj6-0000Yz-R1; Fri, 28 Mar 2014 15:29:48 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson Subject: [RFC 1/3] exec-all.h: Use stl_p to avoid undefined behaviour patching x86 jumps Date: Fri, 28 Mar 2014 15:29:46 +0000 Message-Id: <1396020588-2137-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396020588-2137-1-git-send-email-peter.maydell@linaro.org> References: <1396020588-2137-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.173 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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__)