Received: by 10.213.65.68 with SMTP id h4csp4065imn; Thu, 15 Mar 2018 14:33:11 -0700 (PDT) X-Google-Smtp-Source: AG47ELvRWMm0OL340qni4XybsaXr7cxO5BfJjE8rWzQ6XZ4d+/iMznGaGSBeMbalTfFU+AAPkJTw X-Received: by 2002:a17:902:6103:: with SMTP id t3-v6mr9722997plj.76.1521149591500; Thu, 15 Mar 2018 14:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521149591; cv=none; d=google.com; s=arc-20160816; b=mR2Pb/kNwKLawEOFdU38ndjKtdKzYuzeHf1k2iUGsD8xOetIjS8LgLqfTTwgoEQ6+e /9+Qsb2n7diOttOfmD37iVMgvekhPee/JG8vaBdDD9Q31JGchOV7oZIBeTzHwp54h1Co zKklWzXiEOxAllCYleJds3ekprR6NDvOvcPuh9u1xNvVrYhVWipD02Xh/i+w/6oaEnf7 dUvmyTnDnN5j7bOwOPBTnQkm9P3o51IHLJYyp7G73LBxizw/1x08JcpUf8+BzC+yGuue +wDOc0fpKgRBhxiUvdpwUQtecvJmyysDfgjab4LgZI8L3xjpeqfJ9GP1hJMjSFJwLfxd 0txg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=nfq8l89iUJ4RrWwMRiAOO/XLLtamPQ9/LKSONX0pV24=; b=YRUFMFouR4V1UwXwF5vcdcilqyEsdaTyKma5FRjtgPsdfL91Qerxq2HjiI9ir7hUTD scHRdIitrob/lhB5PSK9URShpfnMCvvmbwuqcungOfAEHWrEep9xI6NstZZbXkISOckt x6vB9HHi/+/qHgNXk604Fg6OFboaGCZEV4wuiKttDxVUOKK+nu/jVDXl/7XvCWgJM/bC J9GWdxRRI/AAWSDPUE9w/0wi+hdD90UVGpCoQUP+YfDpWJMZLG0ExUdd8AH4MOzEU4rR ak4+M97oMVZHFGet4D2urjJfTo+m0Kdz30IzanCDprMQhI9EIC7RgpGOgJeZ9F0g3OHT HSQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2-v6si4792129plm.3.2018.03.15.14.32.56; Thu, 15 Mar 2018 14:33:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932539AbeCOVbz (ORCPT + 99 others); Thu, 15 Mar 2018 17:31:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57104 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932451AbeCOVbx (ORCPT ); Thu, 15 Mar 2018 17:31:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C64D476FB9; Thu, 15 Mar 2018 21:31:52 +0000 (UTC) Received: from gimli.home (ovpn-117-203.phx2.redhat.com [10.3.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C85BB2026980; Thu, 15 Mar 2018 21:31:51 +0000 (UTC) Subject: [PATCH v2 2/3] vfio/pci: Use endian neutral helpers From: Alex Williamson To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peterx@redhat.com, eric.auger@redhat.com, aik@ozlabs.ru Date: Thu, 15 Mar 2018 15:31:51 -0600 Message-ID: <20180315213151.15150.70257.stgit@gimli.home> In-Reply-To: <20180315212634.15150.88094.stgit@gimli.home> References: <20180315212634.15150.88094.stgit@gimli.home> User-Agent: StGit/0.18-102-gdf9f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 15 Mar 2018 21:31:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 15 Mar 2018 21:31:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'alex.williamson@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The iowriteXX/ioreadXX functions assume little endian hardware and convert to little endian on a write and from little endian on a read. We currently do our own explicit conversion to negate this. Instead, add some endian dependent defines to avoid all byte swaps. There should be no functional change other than big endian systems aren't penalized with wasted swaps. Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci_rdwr.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c index 5f2b376dcebd..925419e0f459 100644 --- a/drivers/vfio/pci/vfio_pci_rdwr.c +++ b/drivers/vfio/pci/vfio_pci_rdwr.c @@ -21,6 +21,24 @@ #include "vfio_pci_private.h" +#ifdef __LITTLE_ENDIAN +#define vfio_ioread64 ioread64 +#define vfio_iowrite64 iowrite64 +#define vfio_ioread32 ioread32 +#define vfio_iowrite32 iowrite32 +#define vfio_ioread16 ioread16 +#define vfio_iowrite16 iowrite16 +#else +#define vfio_ioread64 ioread64be +#define vfio_iowrite64 iowrite64be +#define vfio_ioread32 ioread32be +#define vfio_iowrite32 iowrite32be +#define vfio_ioread16 ioread16be +#define vfio_iowrite16 iowrite16be +#endif +#define vfio_ioread8 ioread8 +#define vfio_iowrite8 iowrite8 + /* * Read or write from an __iomem region (MMIO or I/O port) with an excluded * range which is inaccessible. The excluded range drops writes and fills @@ -44,15 +62,15 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf, fillable = 0; if (fillable >= 4 && !(off % 4)) { - __le32 val; + u32 val; if (iswrite) { if (copy_from_user(&val, buf, 4)) return -EFAULT; - iowrite32(le32_to_cpu(val), io + off); + vfio_iowrite32(val, io + off); } else { - val = cpu_to_le32(ioread32(io + off)); + val = vfio_ioread32(io + off); if (copy_to_user(buf, &val, 4)) return -EFAULT; @@ -60,15 +78,15 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf, filled = 4; } else if (fillable >= 2 && !(off % 2)) { - __le16 val; + u16 val; if (iswrite) { if (copy_from_user(&val, buf, 2)) return -EFAULT; - iowrite16(le16_to_cpu(val), io + off); + vfio_iowrite16(val, io + off); } else { - val = cpu_to_le16(ioread16(io + off)); + val = vfio_ioread16(io + off); if (copy_to_user(buf, &val, 2)) return -EFAULT; @@ -82,9 +100,9 @@ static ssize_t do_io_rw(void __iomem *io, char __user *buf, if (copy_from_user(&val, buf, 1)) return -EFAULT; - iowrite8(val, io + off); + vfio_iowrite8(val, io + off); } else { - val = ioread8(io + off); + val = vfio_ioread8(io + off); if (copy_to_user(buf, &val, 1)) return -EFAULT;