From patchwork Tue Apr 1 20:53:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 27573 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8F95320553 for ; Tue, 1 Apr 2014 20:54:49 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id s7sf18765630lbd.4 for ; Tue, 01 Apr 2014 13:54:47 -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=V1vS2JWO8CvdrLaMntBZx7i9ftJxZY8nkO9EaEYFvh96oAWK8XlfEzuBMKMrqBMjSW VnP5CP5uek0voYKvtZ4nixeBNy0mMl9r9dBFqu5gObY2qgdUaA+U0zop6PlbtHVnqqha Sac/wWZWAQgxyIK0PPg6ADUxOtc64nJpUBd2RuX/rlxAW+JnaE53r2r7CcRXNfuK8oni pZYH9gc8jFwl/L7gzHQNQVT4OYgBYhiA7s2iCOKyKH8czFkyiOBDKEecH12Nx9mlCpW3 8FRR7J/TAsfeMC2kuf7nzfh2UtKT2GejSfvB4j9LclQNfVrFZkeFZNwHUPEstfxgk9NB MsvA== X-Gm-Message-State: ALoCoQl8pi0SH44no3TxA1kIocaKx4GPmnvwt+dalV47Q9VOlFGeeF5L5sTWl+CFvw8z8fz0eJna X-Received: by 10.14.219.194 with SMTP id m42mr31479eep.7.1396385687957; Tue, 01 Apr 2014 13:54:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.81 with SMTP id r75ls122517qga.71.gmail; Tue, 01 Apr 2014 13:54:47 -0700 (PDT) X-Received: by 10.52.78.231 with SMTP id e7mr2723611vdx.28.1396385687844; Tue, 01 Apr 2014 13:54:47 -0700 (PDT) Received: from mail-vc0-x232.google.com (mail-vc0-x232.google.com [2607:f8b0:400c:c03::232]) by mx.google.com with ESMTPS id sn5si3944353vdc.65.2014.04.01.13.54.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 01 Apr 2014 13:54:47 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::232 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:c03::232; Received: by mail-vc0-f178.google.com with SMTP id im17so10498793vcb.37 for ; Tue, 01 Apr 2014 13:54:47 -0700 (PDT) X-Received: by 10.52.95.135 with SMTP id dk7mr2710417vdb.32.1396385687742; Tue, 01 Apr 2014 13:54:47 -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 v8csp269384vcv; Tue, 1 Apr 2014 13:54:47 -0700 (PDT) X-Received: by 10.140.88.85 with SMTP id s79mr17671383qgd.70.1396385687103; Tue, 01 Apr 2014 13:54:47 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p59si8198342qga.75.2014.04.01.13.54.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 01 Apr 2014 13:54:47 -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]:34338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5hm-0001dG-MC for patch@linaro.org; Tue, 01 Apr 2014 16:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gq-0000pW-WD for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WV5gm-0007VB-7W for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:48 -0400 Received: from mail-qc0-x22a.google.com ([2607:f8b0:400d:c01::22a]:55979) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WV5gm-0007V5-2U for qemu-devel@nongnu.org; Tue, 01 Apr 2014 16:53:44 -0400 Received: by mail-qc0-f170.google.com with SMTP id x13so1459234qcv.29 for ; Tue, 01 Apr 2014 13:53:43 -0700 (PDT) X-Received: by 10.224.3.5 with SMTP id 5mr13256407qal.45.1396385623582; Tue, 01 Apr 2014 13:53:43 -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 g20sm36923963qaq.4.2014.04.01.13.53.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Apr 2014 13:53:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 1 Apr 2014 13:53:26 -0700 Message-Id: <1396385614-19267-2-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396385614-19267-1-git-send-email-rth@twiddle.net> References: <1396385614-19267-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:c01::22a Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH v2 1/9] 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:c03::232 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) 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__)