From: Peter Xu Subject: [kvm-unit-tests PATCH] intel_iommu: fix an incorrect address translation Date: Tue, 3 Jan 2017 19:22:39 +0800 Message-ID: <1483442559-1428-1-git-send-email-peterx@redhat.com> Cc: Paolo Bonzini , Alexander Gordeev , peterx@redhat.com, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:49944 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932457AbdACLWo (ORCPT ); Tue, 3 Jan 2017 06:22:44 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 C1F52C04B332 for ; Tue, 3 Jan 2017 11:22:44 +0000 (UTC) Sender: kvm-owner@vger.kernel.org List-ID: Reported-by: Alexander Gordeev Signed-off-by: Peter Xu --- Tests: map one page twice and see whether dmar work Alex, do you mind I add your s-o-b as well in this patch above mine? :) Signed-off-by: Peter Xu --- lib/x86/intel-iommu.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/x86/intel-iommu.c b/lib/x86/intel-iommu.c index 20b9240..7a3f324 100644 --- a/lib/x86/intel-iommu.c +++ b/lib/x86/intel-iommu.c @@ -166,9 +166,6 @@ static void vtd_install_pte(vtd_pte_t *root, iova_t iova, } } -#define VTD_PHYS_TO_VIRT(x) \ - ((void *)(((uint64_t)phys_to_virt(x)) >> VTD_PAGE_SHIFT)) - /** * vtd_map_range: setup IO address mapping for specific memory range * @@ -203,7 +200,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size) printf("allocated vt-d root entry for PCI bus %d\n", bus_n); } else - ce = VTD_PHYS_TO_VIRT(re->context_table_p); + ce = phys_to_virt(re->context_table_p << VTD_PAGE_SHIFT); /* Point to the correct context entry */ ce += devfn; @@ -224,7 +221,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size) printf("allocated vt-d context entry for devfn 0x%x\n", devfn); } else - slptptr = VTD_PHYS_TO_VIRT(ce->slptptr); + slptptr = phys_to_virt(ce->slptptr << VTD_PAGE_SHIFT); while (size) { /* TODO: currently we only map 4K pages (level = 1) */ -- 2.7.4