From patchwork Wed Jun 1 08:23:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Fleytman X-Patchwork-Id: 9146349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9D5960761 for ; Wed, 1 Jun 2016 08:24:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B916E2654B for ; Wed, 1 Jun 2016 08:24:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADF242679B; Wed, 1 Jun 2016 08:24:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8A1E42654B for ; Wed, 1 Jun 2016 08:24:37 +0000 (UTC) Received: from localhost ([::1]:40828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81S7-0000iC-RX for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Jun 2016 04:24:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81Rc-0000hc-7M for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:24:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b81RW-00007B-Gj for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:24:03 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b81RW-000073-9b for qemu-devel@nongnu.org; Wed, 01 Jun 2016 04:23:58 -0400 Received: by mail-wm0-x241.google.com with SMTP id a136so4498965wme.0 for ; Wed, 01 Jun 2016 01:23:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QHu5C4AdtC0wLxxMbaBpoH8G9/jFEJj9l4jMsHAsjVY=; b=fNbJqaj3WyTnfyRQPDcvjWHYrLUECKwetLl1LxHtlqCGw98/2Ukt0Ax9Gb8+lX2tdp c6NjV4mLp998/tBHP49hpI60WRIYYnXhTGKz/9oCeCikptL13p3C6moElo52Akivodzi 514dtHNc9qAFugLgsuICEor8A8ilMt6MSq3Ek7+tMZflEWQg9/CO+KPrBrASnkIeVRCk gCoF25zoj05WVBxiywSU9PBvueqi46KQw+PBAwCSNeoeSYnK/jIP5rfwYYzwoBJDeSZL /KviMK75ddga2RUYu7S2Ty8R6VNbXUheklMYlyOtubmmlJ5RROnjQJU4i1TAHr0MWYkX G7ug== 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=QHu5C4AdtC0wLxxMbaBpoH8G9/jFEJj9l4jMsHAsjVY=; b=kgMIRCPCEz2a6xpgZSltnboHvW/+dv/UgeaJU+EZyGJYyHQe+bJf7wqBHeDsZRW0pN 5kpH6elBXamhJm3/Bh5yoJ95mzz/iViDI8DdlemF7+ZTz7XXCq8rh/YQcL7ARZqimzqi d6vc2+GF5XCrUabe93i4WTEWDDBb7UgqtkIdqW43QNW9AfP+M1JF6kqSq8zRLJBFgWCO Cdir91+f5U6SVXrSoFcJ6lsTBf82WgM+lySGvZ1GGPF+rGUsZBIvFBu4gU3QA1hMEpFK NOc1uUZNahamXa1l/e556exZIEU8kCrNAYCW5nsHst62813DFNDnnjL1CG0DsD3hYBzq 3x4Q== X-Gm-Message-State: ALyK8tKIxgfjx/WyLMfKHw7fzf/RNH9pSpfwMqgMtCKHBROZOSFpI9ULM63rjuljkPXsXQ== X-Received: by 10.28.165.193 with SMTP id o184mr1135348wme.97.1464769437673; Wed, 01 Jun 2016 01:23:57 -0700 (PDT) Received: from bark.daynix ([5.102.236.99]) by smtp.gmail.com with ESMTPSA id o10sm29242719wjz.37.2016.06.01.01.23.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2016 01:23:56 -0700 (PDT) From: Dmitry Fleytman To: qemu-devel@nongnu.org Date: Wed, 1 Jun 2016 11:23:30 +0300 Message-Id: <1464769426-22276-2-git-send-email-dmitry@daynix.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464769426-22276-1-git-send-email-dmitry@daynix.com> References: <1464769426-22276-1-git-send-email-dmitry@daynix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH v8 01/17] pci: fix unaligned access in pci_xxx_quad() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yan Vugenfirer , Jason Wang , Leonid Bloch , Shmulik Ladkani , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Fleytman Replace legacy cpu_to_le64w()/le64_to_cpup() calls with stq_le_p()/ldq_le_p(). Motivation for this modification is that follow up patches add utility function pcie_dev_ser_num_init() for PCIe DSN capability creation which uses pci_set_quad() with a misaligned offset. Signed-off-by: Dmitry Fleytman Signed-off-by: Leonid Bloch Reviewed-by: Michael S. Tsirkin --- include/hw/pci/pci.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index ef6ba51..4420f47 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -465,16 +465,23 @@ pci_get_long(const uint8_t *config) return ldl_le_p(config); } +/* + * PCI capabilities and/or their fields + * are generally DWORD aligned only so + * mechanism used by pci_set/get_quad() + * must be tolerant to unaligned pointers + * + */ static inline void pci_set_quad(uint8_t *config, uint64_t val) { - cpu_to_le64w((uint64_t *)config, val); + stq_le_p(config, val); } static inline uint64_t pci_get_quad(const uint8_t *config) { - return le64_to_cpup((const uint64_t *)config); + return ldq_le_p(config); } static inline void