From patchwork Thu Jun 2 06:47:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 629047 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rKykW2GxWz9t3h for ; Thu, 2 Jun 2016 16:58:59 +1000 (AEST) Received: from localhost ([::1]:45637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Man-0004HZ-2w for incoming@patchwork.ozlabs.org; Thu, 02 Jun 2016 02:58:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8MQv-0003WW-HQ for qemu-devel@nongnu.org; Thu, 02 Jun 2016 02:48:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8MQt-0005FB-Ac for qemu-devel@nongnu.org; Thu, 02 Jun 2016 02:48:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53392) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8MQt-0005F6-4v for qemu-devel@nongnu.org; Thu, 02 Jun 2016 02:48:43 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0659C00C8FC; Thu, 2 Jun 2016 06:48:42 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (vpn1-4-234.pek2.redhat.com [10.72.4.234]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u526mQFp005724; Thu, 2 Jun 2016 02:48:40 -0400 From: Jason Wang To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 14:47:56 +0800 Message-Id: <1464850102-17829-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1464850102-17829-1-git-send-email-jasowang@redhat.com> References: <1464850102-17829-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 02 Jun 2016 06:48:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL V4 05/31] 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: Leonid Bloch , Jason Wang , Dmitry Fleytman Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Jason Wang --- 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