From mboxrd@z Thu Jan 1 00:00:00 1970 From: Blue Swirl Subject: Re: [PATCH 3/7] AMD IOMMU emulation Date: Sun, 29 Aug 2010 20:37:14 +0000 Message-ID: References: <1283007298-10942-1-git-send-email-eduard.munteanu@linux360.ro> <1283007298-10942-4-git-send-email-eduard.munteanu@linux360.ro> <20100828215333.GA7270@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Cc: mst@redhat.com, joro@8bytes.org, paul@codesourcery.com, avi@redhat.com, anthony@codemonkey.ws, av1474@comtv.ru, yamahata@valinux.co.jp, kvm@vger.kernel.org, qemu-devel@nongnu.org To: Eduard - Gabriel Munteanu Return-path: Received: from mail-qw0-f46.google.com ([209.85.216.46]:54721 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753238Ab0H2Uhn (ORCPT ); Sun, 29 Aug 2010 16:37:43 -0400 Received: by qwh6 with SMTP id 6so4324520qwh.19 for ; Sun, 29 Aug 2010 13:37:42 -0700 (PDT) In-Reply-To: <20100828215333.GA7270@localhost> Sender: kvm-owner@vger.kernel.org List-ID: On Sat, Aug 28, 2010 at 9:53 PM, Eduard - Gabriel Munteanu wrote: > On Sat, Aug 28, 2010 at 03:58:23PM +0000, Blue Swirl wrote: >> On Sat, Aug 28, 2010 at 2:54 PM, Eduard - Gabriel Munteanu >> wrote: >> > This introduces emulation for the AMD IOMMU, described in "AMD I/O >> > Virtualization Technology (IOMMU) Specification". >> > >> > Signed-off-by: Eduard - Gabriel Munteanu >> > --- > > [snip] > >> > diff --git a/hw/amd_iommu.c b/hw/amd_iommu.c >> > new file mode 100644 >> > index 0000000..43e0426 >> > --- /dev/null >> > +++ b/hw/amd_iommu.c > > [snip] > >> > +static void amd_iommu_update_mmio(AMDIOMMUState *st, >> > + ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??target_phys_addr_t addr) >> > +{ >> > + ?? ??size_t reg = addr & ~0x07; >> > + ?? ??uint64_t *base = (uint64_t *) &st->mmio_buf[reg]; >> >> This is still buggy. >> >> > + ?? ??uint64_t val = le64_to_cpu(*base); > > mmio_buf is always LE, so a BE host will have *base in reversed > byteorder. But look at the next line, where I did the le64_to_cpu(). > That should swap the bytes on a BE host, yielding the correct byteorder. Sorry, I missed that one when comparing the patch to previous version. > On a LE host, *base is right the first time and le64_to_cpu() is a nop. > > In any case, I only use 'val', not '*base' directly. I suppose it could > be rewritten for clarity (i.e. ditch 'base'). Yes, someone could add more code later which accidentally uses 'base' directly. > Do you still think it's wrong? Or is it for another reason? I think it's OK for now. The rewrite can happen with a small patch later. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33505 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OpodN-0006Bu-Kg for qemu-devel@nongnu.org; Sun, 29 Aug 2010 16:37:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OpodL-000648-Ju for qemu-devel@nongnu.org; Sun, 29 Aug 2010 16:37:45 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:36836) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OpodL-000644-Hj for qemu-devel@nongnu.org; Sun, 29 Aug 2010 16:37:43 -0400 Received: by qwh5 with SMTP id 5so4556899qwh.4 for ; Sun, 29 Aug 2010 13:37:42 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20100828215333.GA7270@localhost> References: <1283007298-10942-1-git-send-email-eduard.munteanu@linux360.ro> <1283007298-10942-4-git-send-email-eduard.munteanu@linux360.ro> <20100828215333.GA7270@localhost> From: Blue Swirl Date: Sun, 29 Aug 2010 20:37:14 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: [Qemu-devel] Re: [PATCH 3/7] AMD IOMMU emulation List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduard - Gabriel Munteanu Cc: kvm@vger.kernel.org, mst@redhat.com, joro@8bytes.org, qemu-devel@nongnu.org, yamahata@valinux.co.jp, avi@redhat.com, paul@codesourcery.com On Sat, Aug 28, 2010 at 9:53 PM, Eduard - Gabriel Munteanu wrote: > On Sat, Aug 28, 2010 at 03:58:23PM +0000, Blue Swirl wrote: >> On Sat, Aug 28, 2010 at 2:54 PM, Eduard - Gabriel Munteanu >> wrote: >> > This introduces emulation for the AMD IOMMU, described in "AMD I/O >> > Virtualization Technology (IOMMU) Specification". >> > >> > Signed-off-by: Eduard - Gabriel Munteanu >> > --- > > [snip] > >> > diff --git a/hw/amd_iommu.c b/hw/amd_iommu.c >> > new file mode 100644 >> > index 0000000..43e0426 >> > --- /dev/null >> > +++ b/hw/amd_iommu.c > > [snip] > >> > +static void amd_iommu_update_mmio(AMDIOMMUState *st, >> > + ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??target_phys_addr_t addr) >> > +{ >> > + ?? ??size_t reg = addr & ~0x07; >> > + ?? ??uint64_t *base = (uint64_t *) &st->mmio_buf[reg]; >> >> This is still buggy. >> >> > + ?? ??uint64_t val = le64_to_cpu(*base); > > mmio_buf is always LE, so a BE host will have *base in reversed > byteorder. But look at the next line, where I did the le64_to_cpu(). > That should swap the bytes on a BE host, yielding the correct byteorder. Sorry, I missed that one when comparing the patch to previous version. > On a LE host, *base is right the first time and le64_to_cpu() is a nop. > > In any case, I only use 'val', not '*base' directly. I suppose it could > be rewritten for clarity (i.e. ditch 'base'). Yes, someone could add more code later which accidentally uses 'base' directly. > Do you still think it's wrong? Or is it for another reason? I think it's OK for now. The rewrite can happen with a small patch later.