All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] intel_iommu: fix and simplify size calculation in process_device_iotlb_desc()
@ 2017-01-20  6:35 Jason Wang
  2017-01-20 13:38 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Wang @ 2017-01-20  6:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, Jason Wang, Paolo Bonzini

We don't use 1ULL which is wrong during size calculation. Fix it, and
while at it, switch to use cto64() and adds a comments to make it
simpler and easier to be understood.

Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/i386/intel_iommu.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index ec62239..3270fb9 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1485,8 +1485,16 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
         goto done;
     }
 
+    /* According to ATS spec table 2.4:
+     * S = 0, bits 15:12 = xxxx     range size: 4K
+     * S = 1, bits 15:12 = xxx0     range size: 8K
+     * S = 1, bits 15:12 = xx01     range size: 16K
+     * S = 1, bits 15:12 = x011     range size: 32K
+     * S = 1, bits 15:12 = 0111     range size: 64K
+     * ...
+     */
     if (size) {
-        sz = 1 << (ctz64(~(addr | (VTD_PAGE_MASK_4K - 1))) + 1);
+        sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT);
         addr &= ~(sz - 1);
     } else {
         sz = VTD_PAGE_SIZE;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] intel_iommu: fix and simplify size calculation in process_device_iotlb_desc()
  2017-01-20  6:35 [Qemu-devel] [PATCH] intel_iommu: fix and simplify size calculation in process_device_iotlb_desc() Jason Wang
@ 2017-01-20 13:38 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2017-01-20 13:38 UTC (permalink / raw)
  To: Jason Wang, qemu-devel; +Cc: mst



On 20/01/2017 07:35, Jason Wang wrote:
> We don't use 1ULL which is wrong during size calculation. Fix it, and
> while at it, switch to use cto64() and adds a comments to make it
> simpler and easier to be understood.
> 
> Reported-by: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  hw/i386/intel_iommu.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index ec62239..3270fb9 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -1485,8 +1485,16 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
>          goto done;
>      }
>  
> +    /* According to ATS spec table 2.4:
> +     * S = 0, bits 15:12 = xxxx     range size: 4K
> +     * S = 1, bits 15:12 = xxx0     range size: 8K
> +     * S = 1, bits 15:12 = xx01     range size: 16K
> +     * S = 1, bits 15:12 = x011     range size: 32K
> +     * S = 1, bits 15:12 = 0111     range size: 64K
> +     * ...
> +     */
>      if (size) {
> -        sz = 1 << (ctz64(~(addr | (VTD_PAGE_MASK_4K - 1))) + 1);
> +        sz = (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT);
>          addr &= ~(sz - 1);
>      } else {
>          sz = VTD_PAGE_SIZE;
> 


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-20 13:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-20  6:35 [Qemu-devel] [PATCH] intel_iommu: fix and simplify size calculation in process_device_iotlb_desc() Jason Wang
2017-01-20 13:38 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.